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 61 extern ssize_t jfs_listxattr(struct dentry *, char *, size_t); 62 62 extern int jfs_removexattr(struct dentry *, const char *); 63 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 + 64 74 #endif /* H_JFS_XATTR */
+22
fs/jfs/namei.c
··· 111 111 if (rc) 112 112 goto out3; 113 113 114 + rc = jfs_init_security(tid, ip, dip); 115 + if (rc) { 116 + txAbort(tid, 0); 117 + goto out3; 118 + } 119 + 114 120 if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) { 115 121 jfs_err("jfs_create: dtSearch returned %d", rc); 116 122 txAbort(tid, 0); ··· 244 238 rc = jfs_init_acl(tid, ip, dip); 245 239 if (rc) 246 240 goto out3; 241 + 242 + rc = jfs_init_security(tid, ip, dip); 243 + if (rc) { 244 + txAbort(tid, 0); 245 + goto out3; 246 + } 247 247 248 248 if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) { 249 249 jfs_err("jfs_mkdir: dtSearch returned %d", rc); ··· 918 906 down(&JFS_IP(dip)->commit_sem); 919 907 down(&JFS_IP(ip)->commit_sem); 920 908 909 + rc = jfs_init_security(tid, ip, dip); 910 + if (rc) 911 + goto out3; 912 + 921 913 tblk = tid_to_tblock(tid); 922 914 tblk->xflag |= COMMIT_CREATE; 923 915 tblk->ino = ip->i_ino; ··· 1364 1348 rc = jfs_init_acl(tid, ip, dir); 1365 1349 if (rc) 1366 1350 goto out3; 1351 + 1352 + rc = jfs_init_security(tid, ip, dir); 1353 + if (rc) { 1354 + txAbort(tid, 0); 1355 + goto out3; 1356 + } 1367 1357 1368 1358 if ((rc = dtSearch(dir, &dname, &ino, &btstack, JFS_CREATE))) { 1369 1359 txAbort(tid, 0);
+36
fs/jfs/xattr.c
··· 21 21 #include <linux/xattr.h> 22 22 #include <linux/posix_acl_xattr.h> 23 23 #include <linux/quotaops.h> 24 + #include <linux/security.h> 24 25 #include "jfs_incore.h" 25 26 #include "jfs_superblock.h" 26 27 #include "jfs_dmap.h" ··· 1149 1148 1150 1149 return rc; 1151 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