Patch "btrfs: don't accept bare namespace as a valid xattr" has been added to the 3.19-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
btrfs: don't accept bare namespace as a valid xattr
to the 3.19-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
btrfs-don-t-accept-bare-namespace-as-a-valid-xattr.patch
and it can be found in the queue-3.19 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
3c3b04d10ff1811a27f86684ccd2f5ba6983211dMon Sep 17 00:00:00 2001
From: David Sterba <[email protected]>
Date: Wed, 25 Mar 2015 19:26:41 +0100
Subject: btrfs: don't accept bare namespace as a valid xattr
From: David Sterba <[email protected]>
commit 3c3b04d10ff1811a27f86684ccd2f5ba6983211d upstream.
Due to insufficient check in btrfs_is_valid_xattr, this unexpectedly works:
$ touch file $ setfattr -n user. -v 1 file $ getfattr -d file user.="1"
ie. the missing attribute name after the namespace.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=94291
--- fs/btrfs/xattr.c | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-)
fs/btrfs/xattr.c +39 -14
@@ -360,22 +360,42 @@ const struct xattr_handler *btrfs_xattr_/* * Check if the attribute is in a supported namespace. * -* This applied after the check for the synthetic attributes in the system +* This is applied after the check for the synthetic attributes in the system * namespace. */ -static bool btrfs_is_valid_xattr (const char *name) +static int btrfs_is_valid_xattr (const char *name) { -return !strncmp (name,XATTR_SECURITY_PREFIX , -XATTR_SECURITY_PREFIX_LEN ) || - !strncmp (name,XATTR_SYSTEM_PREFIX ,XATTR_SYSTEM_PREFIX_LEN ) || - !strncmp (name,XATTR_TRUSTED_PREFIX ,XATTR_TRUSTED_PREFIX_LEN ) || - !strncmp (name,XATTR_USER_PREFIX ,XATTR_USER_PREFIX_LEN ) || - !strncmp (name,XATTR_BTRFS_PREFIX ,XATTR_BTRFS_PREFIX_LEN ); +int len =strlen (name); +int prefixlen =0 ; + +if (!strncmp (name,XATTR_SECURITY_PREFIX , +XATTR_SECURITY_PREFIX_LEN )) + prefixlen =XATTR_SECURITY_PREFIX_LEN ; +else if (!strncmp (name,XATTR_SYSTEM_PREFIX ,XATTR_SYSTEM_PREFIX_LEN )) + prefixlen =XATTR_SYSTEM_PREFIX_LEN ; +else if (!strncmp (name,XATTR_TRUSTED_PREFIX ,XATTR_TRUSTED_PREFIX_LEN )) + prefixlen =XATTR_TRUSTED_PREFIX_LEN ; +else if (!strncmp (name,XATTR_USER_PREFIX ,XATTR_USER_PREFIX_LEN )) + prefixlen =XATTR_USER_PREFIX_LEN ; +else if (!strncmp (name,XATTR_BTRFS_PREFIX ,XATTR_BTRFS_PREFIX_LEN )) + prefixlen =XATTR_BTRFS_PREFIX_LEN ; +else +return -EOPNOTSUPP ; + +/* +* The name cannot consist of just prefix +*/ +if (len <= prefixlen) +return -EINVAL ; + +return 0 ; }ssize_t btrfs_getxattr (struct dentry *dentry,const char *name,void *buffer,size_t size) { +int ret; +/* * If this is a request for a synthetic attribute in the system.* * namespace use the generic infrastructure to resolve a handler
@@ -384,8 +404,9 @@ ssize_t btrfs_getxattr(struct dentry *deif (!strncmp (name,XATTR_SYSTEM_PREFIX ,XATTR_SYSTEM_PREFIX_LEN ))return generic_getxattr (dentry, name, buffer, size); -if (!btrfs_is_valid_xattr (name)) -return -EOPNOTSUPP ; + ret =btrfs_is_valid_xattr (name); +if (ret) +return ret;return __btrfs_getxattr (dentry->d_inode, name, buffer, size); }
@@ -393,6 +414,7 @@ int btrfs_setxattr(struct dentry *dentry size_t size, int flags) {struct btrfs_root *root =BTRFS_I (dentry->d_inode)->root; +int ret;/* * The permission on security.* and system.* is not checked
@@ -409,8 +431,9 @@ int btrfs_setxattr(struct dentry *dentryif (!strncmp (name,XATTR_SYSTEM_PREFIX ,XATTR_SYSTEM_PREFIX_LEN ))return generic_setxattr (dentry, name, value, size, flags); -if (!btrfs_is_valid_xattr (name)) -return -EOPNOTSUPP ; + ret =btrfs_is_valid_xattr (name); +if (ret) +return ret;if (!strncmp (name,XATTR_BTRFS_PREFIX ,XATTR_BTRFS_PREFIX_LEN )) return btrfs_set_prop(dentry->d_inode, name,
@@ -426,6 +449,7 @@ int btrfs_setxattr(struct dentry *dentryint btrfs_removexattr (struct dentry *dentry,const char *name) {struct btrfs_root *root =BTRFS_I (dentry->d_inode)->root; +int ret;/* * The permission on security.* and system.* is not checked
@@ -442,8 +466,9 @@ int btrfs_removexattr(struct dentry *denif (!strncmp (name,XATTR_SYSTEM_PREFIX ,XATTR_SYSTEM_PREFIX_LEN ))return generic_removexattr (dentry, name); -if (!btrfs_is_valid_xattr (name)) -return -EOPNOTSUPP ; + ret =btrfs_is_valid_xattr (name); +if (ret) +return ret;if (!strncmp (name,XATTR_BTRFS_PREFIX ,XATTR_BTRFS_PREFIX_LEN )) return btrfs_set_prop(dentry->d_inode, name,
Patches currently in stable-queue which might be from [email protected] are
queue-3.19/btrfs-don-t-accept-bare-namespace-as-a-valid-xattr.patch