diff mbox series

[23/32] xfs: Filter XFS_ATTR_PARENT for getfattr

Message ID 171270969941.3631889.11060276222007768999.stgit@frogsfrogsfrogs (mailing list archive)
State New
Headers show
Series [01/32] xfs: rearrange xfs_attr_match parameters | expand

Commit Message

Darrick J. Wong April 10, 2024, 12:59 a.m. UTC
From: Allison Henderson <allison.henderson@oracle.com>

Parent pointers returned to the get_fattr tool cause errors since
the tool cannot parse parent pointers.  Fix this by filtering parent
parent pointers from xfs_xattr_put_listent.

Signed-off-by: Allison Henderson <allison.henderson@oracle.com>
Inspired-by: Andrey Albershteyn <aalbersh@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
[djwong: change this to XFS_ATTR_PRIVATE_NSP_MASK per fsverity patchset]
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_da_format.h |    3 +++
 fs/xfs/xfs_xattr.c            |   10 ++++++++++
 2 files changed, 13 insertions(+)

Comments

Christoph Hellwig April 10, 2024, 5:51 a.m. UTC | #1
On Tue, Apr 09, 2024 at 05:59:30PM -0700, Darrick J. Wong wrote:
> From: Allison Henderson <allison.henderson@oracle.com>
> 
> Parent pointers returned to the get_fattr tool cause errors since
> the tool cannot parse parent pointers.  Fix this by filtering parent
> parent pointers from xfs_xattr_put_listent.

With the new format returning the attrs should not cause parsing errors.
OTOH we now have duplicate names, which means a get operation based on
the name can't actually work in that case.

I'd also argue that parent pointers are internal enough that they
should not be exposed through the normal xattr interfaces.

> +/*
> + * This file defines functions to work with externally visible extended
> + * attributes, such as those in user, system, or security namespaces.  They
> + * should not be used for internally used attributes.  Consider xfs_attr.c.
> + */

As long as xfs_attr_change and xfs_attr_grab_log_assist are xfs_xattr.c
that is not actually true.  However I think they should be moved to
xfs_attr.c (and in case of xfs_attr_change merged into xfs_attr_set)
to make this comment true.

However I'd make it part of the top of file comment above the include
statements.  And please add it in a separate commit as it has nothing
to do with the other changes here.
Darrick J. Wong April 10, 2024, 9:58 p.m. UTC | #2
On Tue, Apr 09, 2024 at 10:51:18PM -0700, Christoph Hellwig wrote:
> On Tue, Apr 09, 2024 at 05:59:30PM -0700, Darrick J. Wong wrote:
> > From: Allison Henderson <allison.henderson@oracle.com>
> > 
> > Parent pointers returned to the get_fattr tool cause errors since
> > the tool cannot parse parent pointers.  Fix this by filtering parent
> > parent pointers from xfs_xattr_put_listent.
> 
> With the new format returning the attrs should not cause parsing errors.
> OTOH we now have duplicate names, which means a get operation based on
> the name can't actually work in that case.
> 
> I'd also argue that parent pointers are internal enough that they
> should not be exposed through the normal xattr interfaces.

Yeah, I probably should change the commit message to:

"xfs: don't return XFS_ATTR_PARENT attributes via listxattr

"Parent pointers are internal filesystem metadata.  They're not intended
to be directly visible to userspace, so filter them out of
xfs_xattr_put_listent so that they don't appear in listxattr."

> > +/*
> > + * This file defines functions to work with externally visible extended
> > + * attributes, such as those in user, system, or security namespaces.  They
> > + * should not be used for internally used attributes.  Consider xfs_attr.c.
> > + */
> 
> As long as xfs_attr_change and xfs_attr_grab_log_assist are xfs_xattr.c
> that is not actually true.  However I think they should be moved to
> xfs_attr.c (and in case of xfs_attr_change merged into xfs_attr_set)
> to make this comment true.

I don't want to hoist all the larp enabling jun^Wmachinery to libxfs and
then have to stub that out in userspace.  I'd rather get rid of larp
mode entirely, after which point xfs_attr_change becomes a trivial
helper that can be collapsed.

> However I'd make it part of the top of file comment above the include
> statements.  And please add it in a separate commit as it has nothing
> to do with the other changes here.

Or just get rid of the comment entirely?  It came from the verity
series.

--D
Christoph Hellwig April 11, 2024, 3:29 a.m. UTC | #3
On Wed, Apr 10, 2024 at 02:58:27PM -0700, Darrick J. Wong wrote:
> "xfs: don't return XFS_ATTR_PARENT attributes via listxattr
> 
> "Parent pointers are internal filesystem metadata.  They're not intended
> to be directly visible to userspace, so filter them out of
> xfs_xattr_put_listent so that they don't appear in listxattr."

Looks good.

> > However I'd make it part of the top of file comment above the include
> > statements.  And please add it in a separate commit as it has nothing
> > to do with the other changes here.
> 
> Or just get rid of the comment entirely?  It came from the verity
> series.

Fine with me.
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h
index 1395ad1937c53..ebde6eb1da65d 100644
--- a/fs/xfs/libxfs/xfs_da_format.h
+++ b/fs/xfs/libxfs/xfs_da_format.h
@@ -726,6 +726,9 @@  struct xfs_attr3_leafblock {
 					 XFS_ATTR_SECURE | \
 					 XFS_ATTR_PARENT)
 
+/* Private attr namespaces not exposed to userspace */
+#define XFS_ATTR_PRIVATE_NSP_MASK	(XFS_ATTR_PARENT)
+
 #define XFS_ATTR_ONDISK_MASK	(XFS_ATTR_NSP_ONDISK_MASK | \
 				 XFS_ATTR_LOCAL | \
 				 XFS_ATTR_INCOMPLETE)
diff --git a/fs/xfs/xfs_xattr.c b/fs/xfs/xfs_xattr.c
index 85e886ee20e03..00b591f6c5ca1 100644
--- a/fs/xfs/xfs_xattr.c
+++ b/fs/xfs/xfs_xattr.c
@@ -20,6 +20,12 @@ 
 
 #include <linux/posix_acl_xattr.h>
 
+/*
+ * This file defines functions to work with externally visible extended
+ * attributes, such as those in user, system, or security namespaces.  They
+ * should not be used for internally used attributes.  Consider xfs_attr.c.
+ */
+
 /*
  * Get permission to use log-assisted atomic exchange of file extents.
  * Callers must not be running any transactions or hold any ILOCKs.
@@ -215,6 +221,10 @@  xfs_xattr_put_listent(
 
 	ASSERT(context->count >= 0);
 
+	/* Don't expose private xattr namespaces. */
+	if (flags & XFS_ATTR_PRIVATE_NSP_MASK)
+		return;
+
 	if (flags & XFS_ATTR_ROOT) {
 #ifdef CONFIG_XFS_POSIX_ACL
 		if (namelen == SGI_ACL_FILE_SIZE &&