Skip to contentSkip to conversation

catch acl==NULL in __jfs_set_acl (fixed null pointer dereference)

PATCH In review Marco Munderloh 3 participants 5 messages Apr 29, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 catch acl==NULL in __jfs_set_acl (fixed null pointer dereference)

changes V2: I forgot to set rc = 0, leaving it uninitialized if acl was NULL.

fs/jfs/acl.c +10 -7
@@ -83,13 +83,16 @@
 	switch (type) {
 	case ACL_TYPE_ACCESS:
 		ea_name = POSIX_ACL_XATTR_ACCESS;
-		rc = posix_acl_equiv_mode(acl, &inode->i_mode);
-		if (rc < 0)
-			return rc;
-		inode->i_ctime = CURRENT_TIME;
-		mark_inode_dirty(inode);
-		if (rc == 0)
-			acl = NULL;
+		if( acl ) {
+			rc = posix_acl_equiv_mode(acl, &inode->i_mode);
+			if (rc < 0)
+				return rc;
+			inode->i_ctime = CURRENT_TIME;
+			mark_inode_dirty(inode);
+			if (rc == 0)
+				acl = NULL;
+		}
+		rc = 0;
 		break;
 	case ACL_TYPE_DEFAULT:
 		ea_name = POSIX_ACL_XATTR_DEFAULT;
#1 lore raw
Quoted 1 line · Marco Munderloh

changes V2: I forgot to set rc = 0, leaving it uninitialized if acl was NULL.

You don't need to initialise rc here. But why not, more simply:

+++ b/fs/jfs/acl.c
@@ -83,6 +83,8 @@ static int __jfs_set_acl(tid_t tid, struct inode *inode, int t

        switch (type) {
        case ACL_TYPE_ACCESS:
                ea_name = POSIX_ACL_XATTR_ACCESS;
+               if (!acl)
+                       break;
                rc = posix_acl_equiv_mode(acl, &inode->i_mode);
                if (rc < 0)
                        return rc;
#2 lore raw
Quoted 4 lines · Matthew Wilcox
Quoted 1 line · Marco Munderloh

changes V2: I forgot to set rc = 0, leaving it uninitialized if acl was NULL.

You don't need to initialise rc here. But why not, more simply:

I'm pretty sure there's a patch queued up somewhere to make posix_acl_equiv_mode handle the NULL ACL. I think this was first reportd on gfs2.

#3 lore raw
Quoted 3 lines

I'm pretty sure there's a patch queued up somewhere to make posix_acl_equiv_mode handle the NULL ACL. I think this was first reportd on gfs2.

That might be a better solution, posix_acl_equiv is used at several places (e.g. tmpfs, where the bug is also triggered). However, in e.g. the ext4 or the btrfs acl implementation, acl == NULL is catched.

#4 lore raw
In reply to Matthew Wilcox
Quoted 1 line

You don't need to initialise rc here.

Yes, you are true. I missed the __jfs_setxattr before the set_cached_acl.

But why not, more simply:

Review static int __jfs_set_acl(tid_t tid, struct inode *inode, int t · line 90

Quoted 11 lines

+++ b/fs/jfs/acl.c

(quoted diff) +2 -0
@@ -83,6 +83,8 @@ static int __jfs_set_acl(tid_t tid, struct inode *inode, int t
        switch (type) {
        case ACL_TYPE_ACCESS:
                ea_name = POSIX_ACL_XATTR_ACCESS;
+               if (!acl)
+                       break;
                rc = posix_acl_equiv_mode(acl, &inode->i_mode);
                if (rc < 0)
                        return rc;

I could have done it like this, but I copied the way it was done in btrfs/acl.c, where the jfs implementation seems to come from.