Skip to content

Commit 6ff9b09

Browse files
author
Andreas Gruenbacher
committed
gfs2: Get rid of potential double-freeing in gfs2_create_inode
In gfs2_create_inode, after setting and releasing the acl / default_acl, the acl / default_acl pointers are not set to NULL as they should be. In that state, when the function reaches label fail_free_acls, gfs2_create_inode will try to release the same acls again. Fix that by setting the pointers to NULL after releasing the acls. Slightly simplify the logic. Also, posix_acl_release checks for NULL already, so there is no need to duplicate those checks here. Fixes: e01580b ("gfs2: use generic posix ACL infrastructure") Reported-by: Pan Bian <bianpan2016@163.com> Cc: Christoph Hellwig <hch@lst.de> Cc: stable@vger.kernel.org # v4.9+ Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Bob Peterson <rpeterso@redhat.com>
1 parent cbbe76c commit 6ff9b09

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

fs/gfs2/inode.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -744,17 +744,19 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
744744
the gfs2 structures. */
745745
if (default_acl) {
746746
error = __gfs2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
747+
if (error)
748+
goto fail_gunlock3;
747749
posix_acl_release(default_acl);
750+
default_acl = NULL;
748751
}
749752
if (acl) {
750-
if (!error)
751-
error = __gfs2_set_acl(inode, acl, ACL_TYPE_ACCESS);
753+
error = __gfs2_set_acl(inode, acl, ACL_TYPE_ACCESS);
754+
if (error)
755+
goto fail_gunlock3;
752756
posix_acl_release(acl);
757+
acl = NULL;
753758
}
754759

755-
if (error)
756-
goto fail_gunlock3;
757-
758760
error = security_inode_init_security(&ip->i_inode, &dip->i_inode, name,
759761
&gfs2_initxattrs, NULL);
760762
if (error)
@@ -789,10 +791,8 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
789791
}
790792
gfs2_rsqa_delete(ip, NULL);
791793
fail_free_acls:
792-
if (default_acl)
793-
posix_acl_release(default_acl);
794-
if (acl)
795-
posix_acl_release(acl);
794+
posix_acl_release(default_acl);
795+
posix_acl_release(acl);
796796
fail_gunlock:
797797
gfs2_dir_no_add(&da);
798798
gfs2_glock_dq_uninit(ghs);

0 commit comments

Comments
 (0)