From dd76695778b23a2b199ce518c5e17b19f1cff008 Mon Sep 17 00:00:00 2001
From: Dave Kleikamp <shaggy@austin.ibm.com>
Date: Wed, 26 May 2004 06:12:55 -0500
Subject: [PATCH] JFS: check default acl for correctness before setting it

This patch was orignally submitted by Andreas Gruenbacher and modified
by me.
---
 fs/jfs/xattr.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c
index ad7498117f10..c786348cdb00 100644
--- a/fs/jfs/xattr.c
+++ b/fs/jfs/xattr.c
@@ -688,17 +688,26 @@ static int can_set_system_xattr(struct inode *inode, const char *name,
 			}
 			inode->i_mode = mode;
 			mark_inode_dirty(inode);
-			if (rc == 0)
-				value = NULL;
 		}
 		/*
 		 * We're changing the ACL.  Get rid of the cached one
 		 */
 		acl =JFS_IP(inode)->i_acl;
-		if (acl && (acl != JFS_ACL_NOT_CACHED))
+		if (acl != JFS_ACL_NOT_CACHED)
 			posix_acl_release(acl);
 		JFS_IP(inode)->i_acl = JFS_ACL_NOT_CACHED;
+
+		return 0;
 	} else if (strcmp(name, XATTR_NAME_ACL_DEFAULT) == 0) {
+		acl = posix_acl_from_xattr(value, value_len);
+		if (IS_ERR(acl)) {
+			rc = PTR_ERR(acl);
+			printk(KERN_ERR "posix_acl_from_xattr returned %d\n",
+			       rc);
+			return rc;
+		}
+		posix_acl_release(acl);
+
 		/*
 		 * We're changing the default ACL.  Get rid of the cached one
 		 */
@@ -706,13 +715,11 @@ static int can_set_system_xattr(struct inode *inode, const char *name,
 		if (acl && (acl != JFS_ACL_NOT_CACHED))
 			posix_acl_release(acl);
 		JFS_IP(inode)->i_default_acl = JFS_ACL_NOT_CACHED;
-	} else
-		/* Invalid xattr name */
-		return -EINVAL;
-	return 0;
-#else			/* CONFIG_JFS_POSIX_ACL */
-	return -EOPNOTSUPP;
+
+		return 0;
+	}
 #endif			/* CONFIG_JFS_POSIX_ACL */
+	return -EOPNOTSUPP;
 }
 
 static int can_set_xattr(struct inode *inode, const char *name,
-- 
2.30.9