[PATCH] Fix user.* xattr permission check for sticky dirs

The user.* extended attributes are only allowed on regular files and
directories. Sticky directories further restrict write access to the owner
and privileged users. (See the attr(5) man page for an explanation.)

The original check in ext2/ext3 when user.* xattrs were merged was more
restrictive than intended, and when the xattr permission checks were moved
into the VFS, read access to user.* attributes on sticky directores ended
up being denied in addition.

Originally-from: Gerard Neil <xyzzy@devferret.org>
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
Cc: Dave Kleikamp <shaggy@austin.ibm.com>
Cc: Jan Engelhardt <jengelh@linux01.gwdg.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Andreas Gruenbacher and committed by Linus Torvalds f1f2d871 8ce08464

+10 -3
+10 -3
fs/xattr.c
··· 48 48 return 0; 49 49 50 50 /* 51 - * The trusted.* namespace can only accessed by a privilegued user. 51 + * The trusted.* namespace can only be accessed by a privileged user. 52 52 */ 53 53 if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) 54 54 return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM); 55 55 56 + /* In user.* namespace, only regular files and directories can have 57 + * extended attributes. For sticky directories, only the owner and 58 + * privileged user can write attributes. 59 + */ 56 60 if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) { 57 - if (!S_ISREG(inode->i_mode) && 58 - (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX)) 61 + if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode)) 62 + return -EPERM; 63 + if (S_ISDIR(inode->i_mode) && (inode->i_mode & S_ISVTX) && 64 + (mask & MAY_WRITE) && (current->fsuid != inode->i_uid) && 65 + !capable(CAP_FOWNER)) 59 66 return -EPERM; 60 67 } 61 68