JFS: Implement jfs_init_security

This atomically initializes the security xattr when an object is created

Signed-off-by: Dave Kleikamp <shaggy@austin.ibm.com>

+68
+10
fs/jfs/jfs_xattr.h
··· 61 extern ssize_t jfs_listxattr(struct dentry *, char *, size_t); 62 extern int jfs_removexattr(struct dentry *, const char *); 63 64 #endif /* H_JFS_XATTR */
··· 61 extern ssize_t jfs_listxattr(struct dentry *, char *, size_t); 62 extern int jfs_removexattr(struct dentry *, const char *); 63 64 + #ifdef CONFIG_JFS_SECURITY 65 + extern int jfs_init_security(tid_t, struct inode *, struct inode *); 66 + #else 67 + static inline int jfs_init_security(tid_t tid, struct inode *inode, 68 + struct inode *dir) 69 + { 70 + return 0; 71 + } 72 + #endif 73 + 74 #endif /* H_JFS_XATTR */
+22
fs/jfs/namei.c
··· 111 if (rc) 112 goto out3; 113 114 if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) { 115 jfs_err("jfs_create: dtSearch returned %d", rc); 116 txAbort(tid, 0); ··· 244 rc = jfs_init_acl(tid, ip, dip); 245 if (rc) 246 goto out3; 247 248 if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) { 249 jfs_err("jfs_mkdir: dtSearch returned %d", rc); ··· 918 down(&JFS_IP(dip)->commit_sem); 919 down(&JFS_IP(ip)->commit_sem); 920 921 tblk = tid_to_tblock(tid); 922 tblk->xflag |= COMMIT_CREATE; 923 tblk->ino = ip->i_ino; ··· 1364 rc = jfs_init_acl(tid, ip, dir); 1365 if (rc) 1366 goto out3; 1367 1368 if ((rc = dtSearch(dir, &dname, &ino, &btstack, JFS_CREATE))) { 1369 txAbort(tid, 0);
··· 111 if (rc) 112 goto out3; 113 114 + rc = jfs_init_security(tid, ip, dip); 115 + if (rc) { 116 + txAbort(tid, 0); 117 + goto out3; 118 + } 119 + 120 if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) { 121 jfs_err("jfs_create: dtSearch returned %d", rc); 122 txAbort(tid, 0); ··· 238 rc = jfs_init_acl(tid, ip, dip); 239 if (rc) 240 goto out3; 241 + 242 + rc = jfs_init_security(tid, ip, dip); 243 + if (rc) { 244 + txAbort(tid, 0); 245 + goto out3; 246 + } 247 248 if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) { 249 jfs_err("jfs_mkdir: dtSearch returned %d", rc); ··· 906 down(&JFS_IP(dip)->commit_sem); 907 down(&JFS_IP(ip)->commit_sem); 908 909 + rc = jfs_init_security(tid, ip, dip); 910 + if (rc) 911 + goto out3; 912 + 913 tblk = tid_to_tblock(tid); 914 tblk->xflag |= COMMIT_CREATE; 915 tblk->ino = ip->i_ino; ··· 1348 rc = jfs_init_acl(tid, ip, dir); 1349 if (rc) 1350 goto out3; 1351 + 1352 + rc = jfs_init_security(tid, ip, dir); 1353 + if (rc) { 1354 + txAbort(tid, 0); 1355 + goto out3; 1356 + } 1357 1358 if ((rc = dtSearch(dir, &dname, &ino, &btstack, JFS_CREATE))) { 1359 txAbort(tid, 0);
+36
fs/jfs/xattr.c
··· 21 #include <linux/xattr.h> 22 #include <linux/posix_acl_xattr.h> 23 #include <linux/quotaops.h> 24 #include "jfs_incore.h" 25 #include "jfs_superblock.h" 26 #include "jfs_dmap.h" ··· 1149 1150 return rc; 1151 }
··· 21 #include <linux/xattr.h> 22 #include <linux/posix_acl_xattr.h> 23 #include <linux/quotaops.h> 24 + #include <linux/security.h> 25 #include "jfs_incore.h" 26 #include "jfs_superblock.h" 27 #include "jfs_dmap.h" ··· 1148 1149 return rc; 1150 } 1151 + 1152 + #ifdef CONFIG_JFS_SECURITY 1153 + int jfs_init_security(tid_t tid, struct inode *inode, struct inode *dir) 1154 + { 1155 + int rc; 1156 + size_t len; 1157 + void *value; 1158 + char *suffix; 1159 + char *name; 1160 + 1161 + rc = security_inode_init_security(inode, dir, &suffix, &value, &len); 1162 + if (rc) { 1163 + if (rc == -EOPNOTSUPP) 1164 + return 0; 1165 + return rc; 1166 + } 1167 + name = kmalloc(XATTR_SECURITY_PREFIX_LEN + 1 + strlen(suffix), 1168 + GFP_NOFS); 1169 + if (!name) { 1170 + rc = -ENOMEM; 1171 + goto kmalloc_failed; 1172 + } 1173 + strcpy(name, XATTR_SECURITY_PREFIX); 1174 + strcpy(name + XATTR_SECURITY_PREFIX_LEN, suffix); 1175 + 1176 + rc = __jfs_setxattr(tid, inode, name, value, len, 0); 1177 + 1178 + kfree(name); 1179 + kmalloc_failed: 1180 + kfree(suffix); 1181 + kfree(value); 1182 + 1183 + return rc; 1184 + } 1185 + #endif