attr fixes
Hi all,
this series contains a bunch of fixes for nasty bugs in the attr interface.
PATCH 1/4 xfs: clear kernel only flags in XFS_IOC_ATTRMULTI_BY_HANDLE
Don't allow passing arbitrary flags as they change behavior including memory allocation that the call stack is not prepared for.
--- fs/xfs/libxfs/xfs_attr.h | 7 +++++-- fs/xfs/xfs_ioctl.c | 2 ++ fs/xfs/xfs_ioctl32.c | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_attr.h +5 -2
@@ -26,7 +26,7 @@ struct xfs_attr_list_context;*========================================================================*/ -#define ATTR_DONTFOLLOW 0x0001/* -- unused, from IRIX -- */ +#define ATTR_DONTFOLLOW 0x0001/* -- ignored, from IRIX -- */ #define ATTR_ROOT 0x0002/* use attrs in root (trusted) namespace */ #define ATTR_TRUST 0x0004/* -- unused, from IRIX -- */ #define ATTR_SECURE 0x0008/* use attrs in security namespace */
@@ -37,7 +37,10 @@ struct xfs_attr_list_context;#define ATTR_KERNOVAL 0x2000/* [kernel] get attr size only, not value */ #define ATTR_INCOMPLETE 0x4000/* [kernel] return INCOMPLETE attr keys */ -#define ATTR_ALLOC 0x8000/* allocate xattr buffer on demand */ +#define ATTR_ALLOC 0x8000/* [kernel] allocate xattr buffer on demand */ + +#define ATTR_KERNEL_FLAGS \ + (ATTR_KERNOTIME | ATTR_KERNOVAL | ATTR_INCOMPLETE | ATTR_ALLOC)#define XFS_ATTR_FLAGS \ { ATTR_DONTFOLLOW, "DONTFOLLOW" }, \
fs/xfs/xfs_ioctl.c +2 -0
@@ -462,6 +462,8 @@ xfs_attrmulti_by_handle( error =0 ;for (i =0 ; i < am_hreq.opcount; i++) { + ops[i].am_flags &= ~ATTR_KERNEL_FLAGS ; + ops[i].am_error =strncpy_from_user ((char *)attr_name, ops[i].am_attrname,MAXNAMELEN );if (ops[i].am_error ==0 || ops[i].am_error ==MAXNAMELEN )
fs/xfs/xfs_ioctl32.c +2 -0
@@ -450,6 +450,8 @@ xfs_compat_attrmulti_by_handle( error =0 ;for (i =0 ; i < am_hreq.opcount; i++) { + ops[i].am_flags &= ~ATTR_KERNEL_FLAGS ; + ops[i].am_error =strncpy_from_user ((char *)attr_name,compat_ptr (ops[i].am_attrname),MAXNAMELEN );
Signature · 1 line
2.24.1
Re: [PATCH 1/4] xfs: clear kernel only flags in XFS_IOC_ATTRMULTI_BY_HANDLE
Quoted 5 lines · Christoph Hellwig
Don't allow passing arbitrary flags as they change behavior including memory allocation that the call stack is not prepared for.
Fixes ddbca70cc45c ("xfs: allocate xattr buffer on demand")Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
--D
Quoted 60 lines
--- fs/xfs/libxfs/xfs_attr.h | 7 +++++-- fs/xfs/xfs_ioctl.c | 2 ++ fs/xfs/xfs_ioctl32.c | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-)fs/xfs/libxfs/xfs_attr.h +5
-2@@ -26,7 +26,7 @@ struct xfs_attr_list_context;*========================================================================*/ -#define ATTR_DONTFOLLOW 0x0001/* -- unused, from IRIX -- */ +#define ATTR_DONTFOLLOW 0x0001/* -- ignored, from IRIX -- */ #define ATTR_ROOT 0x0002/* use attrs in root (trusted) namespace */ #define ATTR_TRUST 0x0004/* -- unused, from IRIX -- */ #define ATTR_SECURE 0x0008/* use attrs in security namespace */ @@ -37,7 +37,10 @@ struct xfs_attr_list_context;#define ATTR_KERNOVAL 0x2000/* [kernel] get attr size only, not value */ #define ATTR_INCOMPLETE 0x4000/* [kernel] return INCOMPLETE attr keys */ -#define ATTR_ALLOC 0x8000/* allocate xattr buffer on demand */ +#define ATTR_ALLOC 0x8000/* [kernel] allocate xattr buffer on demand */ + +#define ATTR_KERNEL_FLAGS \ + (ATTR_KERNOTIME | ATTR_KERNOVAL | ATTR_INCOMPLETE | ATTR_ALLOC)#define XFS_ATTR_FLAGS \ { ATTR_DONTFOLLOW, "DONTFOLLOW" }, \fs/xfs/xfs_ioctl.c +2
-0@@ -462,6 +462,8 @@ xfs_attrmulti_by_handle( error =0 ;for (i =0 ; i < am_hreq.opcount; i++) { + ops[i].am_flags &= ~ATTR_KERNEL_FLAGS ; + ops[i].am_error =strncpy_from_user ((char *)attr_name, ops[i].am_attrname,MAXNAMELEN );if (ops[i].am_error ==0 || ops[i].am_error ==MAXNAMELEN )fs/xfs/xfs_ioctl32.c +2
-0@@ -450,6 +450,8 @@ xfs_compat_attrmulti_by_handle( error =0 ;for (i =0 ; i < am_hreq.opcount; i++) { + ops[i].am_flags &= ~ATTR_KERNEL_FLAGS ; + ops[i].am_error =strncpy_from_user ((char *)attr_name,compat_ptr (ops[i].am_attrname),MAXNAMELEN );Signature · 1 line
2.24.1
PATCH 2/4 xfs: reject invalid flags combinations in XFS_IOC_ATTRMULTI_BY_HANDLE
In reply to Christoph HellwigWhile the flags field in the ABI and the on-disk format allows for multiple namespace flags, that is a logically invalid combination that scrub complains about. Reject it at the ioctl level, as all other interface already get this right at higher levels.
--- fs/xfs/xfs_ioctl.c | 5 +++++ fs/xfs/xfs_ioctl32.c | 5 +++++ 2 files changed, 10 insertions(+)
fs/xfs/xfs_ioctl.c +5 -0
@@ -462,6 +462,11 @@ xfs_attrmulti_by_handle( error =0 ;for (i =0 ; i < am_hreq.opcount; i++) { +if ((ops[i].am_flags &ATTR_ROOT ) && + (ops[i].am_flags &ATTR_SECURE )) { + ops[i].am_error = -EINVAL ; +continue ; + } ops[i].am_flags &= ~ATTR_KERNEL_FLAGS ; ops[i].am_error = strncpy_from_user((char *)attr_name,
fs/xfs/xfs_ioctl32.c +5 -0
@@ -450,6 +450,11 @@ xfs_compat_attrmulti_by_handle( error =0 ;for (i =0 ; i < am_hreq.opcount; i++) { +if ((ops[i].am_flags &ATTR_ROOT ) && + (ops[i].am_flags &ATTR_SECURE )) { + ops[i].am_error = -EINVAL ; +continue ; + } ops[i].am_flags &= ~ATTR_KERNEL_FLAGS ; ops[i].am_error = strncpy_from_user((char *)attr_name,
Signature · 1 line
2.24.1
PATCH 3/4 xfs: also remove cached ACLs when removing the underlying attr
In reply to Christoph HellwigWe should not just invalidate the ACL when setting the underlying attribute, but also when removing it. The ioctl interface gets that right, but the normal xattr inteface skipped the xfs_forget_acl due to an early return.
--- fs/xfs/xfs_xattr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/xfs/xfs_xattr.c +4 -3
@@ -74,10 +74,11 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused,if (flags &XATTR_REPLACE ) xflags |=ATTR_REPLACE ; -if (!value) -return xfs_attr_remove (ip, (unsigned char *)name, xflags); - error =xfs_attr_set (ip, (unsigned char *)name, +if (value) + error =xfs_attr_set (ip, (unsigned char *)name, (void *)value, size, xflags); +else + error =xfs_attr_remove (ip, (unsigned char *)name, xflags);if (!error)xfs_forget_acl (inode, name, xflags);
Signature · 1 line
2.24.1
Re: [PATCH 3/4] xfs: also remove cached ACLs when removing the underlying attr
Quoted 6 lines · Christoph Hellwig
We should not just invalidate the ACL when setting the underlying attribute, but also when removing it. The ioctl interface gets that right, but the normal xattr inteface skipped the
xfs_forget_acldue to an early return.Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
--D
Quoted 26 lines
--- fs/xfs/xfs_xattr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/xfs/xfs_xattr.c +4
-3@@ -74,10 +74,11 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused,if (flags &XATTR_REPLACE ) xflags |=ATTR_REPLACE ; -if (!value) -return xfs_attr_remove (ip, (unsigned char *)name, xflags); - error =xfs_attr_set (ip, (unsigned char *)name, +if (value) + error =xfs_attr_set (ip, (unsigned char *)name, (void *)value, size, xflags); +else + error =xfs_attr_remove (ip, (unsigned char *)name, xflags);if (!error)xfs_forget_acl (inode, name, xflags);Signature · 1 line
2.24.1
PATCH 4/4 xfs: fix misuse of the XFS_ATTR_INCOMPLETE flag
In reply to Christoph HellwigXFS_ATTR_INCOMPLETE is a flag in the on-disk attribute format, and thus in a different namespace as the ATTR_* flags in xfs_da_args.flags. Switch to using a XFS_DA_OP_INCOMPLETE flag in op_flags instead. Without this users might be able to inject this flag into operations using the attr by handle ioctl.
--- fs/xfs/libxfs/xfs_attr.c | 2 +- fs/xfs/libxfs/xfs_attr_leaf.c | 4 ++-- fs/xfs/libxfs/xfs_da_btree.h | 4 +++- fs/xfs/libxfs/xfs_da_format.h | 2 -- 4 files changed, 6 insertions(+), 6 deletions(-)
fs/xfs/libxfs/xfs_attr.c +1 -1
@@ -1007,7 +1007,7 @@ xfs_attr_node_addname(* The INCOMPLETE flag means that we will find the "old" * attr, not the "new" one. */ - args->flags |=XFS_ATTR_INCOMPLETE ; + args->op_flags |=XFS_DA_OP_INCOMPLETE ; state =xfs_da_state_alloc (); state->args = args; state->mp = mp;
fs/xfs/libxfs/xfs_attr_leaf.c +2 -2
@@ -2403,8 +2403,8 @@ xfs_attr3_leaf_lookup_int(* If we are looking for INCOMPLETE entries, show only those. * If we are looking for complete entries, show only those. */ -if ((args->flags &XFS_ATTR_INCOMPLETE ) != - (entry->flags &XFS_ATTR_INCOMPLETE )) { +if (!!(args->op_flags &XFS_DA_OP_INCOMPLETE ) != + !!(entry->flags &XFS_ATTR_INCOMPLETE )) {continue ; }if (entry->flags &XFS_ATTR_LOCAL ) {
fs/xfs/libxfs/xfs_da_btree.h +3 -1
@@ -89,6 +89,7 @@ typedef struct xfs_da_args {#define XFS_DA_OP_OKNOENT 0x0008/* lookup/add op, ENOENT ok, else die */ #define XFS_DA_OP_CILOOKUP 0x0010/* lookup to return CI name if found */ #define XFS_DA_OP_ALLOCVAL 0x0020/* lookup to alloc buffer if found */ +#define XFS_DA_OP_INCOMPLETE 0x0040/* lookup INCOMPLETE attr keys */ #define XFS_DA_OP_FLAGS \ { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \
@@ -96,7 +97,8 @@ typedef struct xfs_da_args { { XFS_DA_OP_ADDNAME, "ADDNAME" }, \ { XFS_DA_OP_OKNOENT, "OKNOENT" }, \ { XFS_DA_OP_CILOOKUP, "CILOOKUP" }, \ - { XFS_DA_OP_ALLOCVAL, "ALLOCVAL" } + { XFS_DA_OP_ALLOCVAL, "ALLOCVAL" }, \ + { XFS_DA_OP_INCOMPLETE, "INCOMPLETE" }/* * Storage for holding state during Btree searches and split/join ops.
fs/xfs/libxfs/xfs_da_format.h +0 -2
@@ -683,8 +683,6 @@ struct xfs_attr3_leafblock {/* * Flags used in the leaf_entry[i].flags field. -* NOTE: the INCOMPLETE bit must not collide with the flags bits specified -* on the system call, they are "or"ed together for various operations. */ #define XFS_ATTR_LOCAL_BIT 0/* attr is stored locally */ #define XFS_ATTR_ROOT_BIT 1/* limit access to trusted attrs */
Signature · 1 line
2.24.1
Quoted 3 lines · Christoph Hellwig
Hi all,
this series contains a bunch of fixes for nasty bugs in the attr interface.
Hm, do you want to throw in the ATTR_INCOMPLETE killing patch (#5 in the old series) too?
--D
Quoted 7 lines · Darrick J. Wong
Quoted 3 lines · Christoph Hellwig
Hi all,
this series contains a bunch of fixes for nasty bugs in the attr interface.
Hm, do you want to throw in the
ATTR_INCOMPLETEkilling patch (#5 in the old series) too?
That isn't really an urgent fix. With the kernel-only flags clearing it can't cause any harm.