Re: [PATCH 04/33] xfs: fix misuse of the XFS_ATTR_INCOMPLETE flag

Darrick J. Wong
2019-12-18T21:33:11Z

On Thu, Dec 12, 2019 at 11:54:04AM +0100, Christoph Hellwig wrote:
> XFS_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.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks ok,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
> 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(-)
>
> diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
> index 0d7fcc983b3d..2368a1bfe7e8 100644
> --- a/fs/xfs/libxfs/xfs_attr.c
> +++ b/fs/xfs/libxfs/xfs_attr.c
> @@ -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;
> diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
> index 08d4b10ae2d5..fed537a4353d 100644
> --- a/fs/xfs/libxfs/xfs_attr_leaf.c
> +++ b/fs/xfs/libxfs/xfs_attr_leaf.c
> @@ -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) {
> diff --git a/fs/xfs/libxfs/xfs_da_btree.h b/fs/xfs/libxfs/xfs_da_btree.h
> index e16610d1c14f..0f4fbb0889ff 100644
> --- a/fs/xfs/libxfs/xfs_da_btree.h
> +++ b/fs/xfs/libxfs/xfs_da_btree.h
> @@ -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.
> diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h
> index 3dee33043e09..05615d1f4113 100644
> --- a/fs/xfs/libxfs/xfs_da_format.h
> +++ b/fs/xfs/libxfs/xfs_da_format.h
> @@ -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 */
> --
> 2.20.1
>