Skip to content

Commit 02b03b2

Browse files
Andreas Gruenbachergregkh
authored andcommitted
gfs2: Get rid of potential double-freeing in gfs2_create_inode
commit 6ff9b09e00a441599f3aacdf577254455a048bc9 upstream. 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 <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: [email protected] # v4.9+ Signed-off-by: Andreas Gruenbacher <[email protected]> Signed-off-by: Bob Peterson <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 579d0aa commit 02b03b2

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
@@ -740,17 +740,19 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
740740
the gfs2 structures. */
741741
if (default_acl) {
742742
error = __gfs2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
743+
if (error)
744+
goto fail_gunlock3;
743745
posix_acl_release(default_acl);
746+
default_acl = NULL;
744747
}
745748
if (acl) {
746-
if (!error)
747-
error = __gfs2_set_acl(inode, acl, ACL_TYPE_ACCESS);
749+
error = __gfs2_set_acl(inode, acl, ACL_TYPE_ACCESS);
750+
if (error)
751+
goto fail_gunlock3;
748752
posix_acl_release(acl);
753+
acl = NULL;
749754
}
750755

751-
if (error)
752-
goto fail_gunlock3;
753-
754756
error = security_inode_init_security(&ip->i_inode, &dip->i_inode, name,
755757
&gfs2_initxattrs, NULL);
756758
if (error)
@@ -783,10 +785,8 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
783785
gfs2_glock_put(ip->i_gl);
784786
gfs2_rsqa_delete(ip, NULL);
785787
fail_free_acls:
786-
if (default_acl)
787-
posix_acl_release(default_acl);
788-
if (acl)
789-
posix_acl_release(acl);
788+
posix_acl_release(default_acl);
789+
posix_acl_release(acl);
790790
fail_gunlock:
791791
gfs2_dir_no_add(&da);
792792
gfs2_glock_dq_uninit(ghs);

0 commit comments

Comments
 (0)