Linux XFS filesystem development
 help / color / mirror / Atom feed
From: Andrey Albershteyn <aalbersh@kernel.org>
To: linux-xfs@vger.kernel.org
Cc: cem@kernel.org, djwong@kernel.org, hch@lst.de,
	leo.lilong@huawei.com, morbo@google.com,
	Andrey Albershteyn <aalbersh@kernel.org>
Subject: [PATCH 1/3] xfs: annotate struct xfs_attr_list_context with __counted_by_ptr
Date: Mon, 27 Apr 2026 14:09:06 +0200	[thread overview]
Message-ID: <20260427120908.52254-2-aalbersh@kernel.org> (raw)
In-Reply-To: <20260427120908.52254-1-aalbersh@kernel.org>

From: Bill Wendling <morbo@google.com>

Source kernel commit: e5966096d0856d071269cb5928d6bc33342d2dfd

Add the `__counted_by_ptr` attribute to the `buffer` field of `struct
xfs_attr_list_context`. This field is used to point to a buffer of
size `bufsize`.

The `buffer` field is assigned in:
1. `xfs_ioc_attr_list` in `fs/xfs/xfs_handle.c`
2. `xfs_xattr_list` in `fs/xfs/xfs_xattr.c`
3. `xfs_getparents` in `fs/xfs/xfs_handle.c` (implicitly initialized to NULL)

In `xfs_ioc_attr_list`, `buffer` was assigned before `bufsize`. Reorder
them to ensure `bufsize` is set before `buffer` is assigned, although
no access happens between them.

In `xfs_xattr_list`, `buffer` was assigned before `bufsize`. Reorder
them to ensure `bufsize` is set before `buffer` is assigned.

In `xfs_getparents`, `buffer` is NULL (from zero initialization) and
remains NULL. `bufsize` is set to a non-zero value, but since `buffer`
is NULL, no access occurs.

In all cases, the pointer `buffer` is not accessed before `bufsize` is set.

This patch was generated by CodeMender and reviewed by Bill Wendling.
Tested by running xfstests.

Signed-off-by: Bill Wendling <morbo@google.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>
---
 include/platform_defs.h | 3 +++
 libxfs/xfs_attr.h       | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/platform_defs.h b/include/platform_defs.h
index b2d80597a83a..5a829db66e08 100644
--- a/include/platform_defs.h
+++ b/include/platform_defs.h
@@ -330,4 +330,7 @@ struct kvec {
 #define BLK_ZONE_COND_ACTIVE	0xff
 #endif
 
+/* xfs_attr.h */
+#define __counted_by_ptr(member)
+
 #endif	/* __XFS_PLATFORM_DEFS_H__ */
diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h
index 8244305949de..67fd9c75ac3f 100644
--- a/libxfs/xfs_attr.h
+++ b/libxfs/xfs_attr.h
@@ -55,7 +55,8 @@ struct xfs_attr_list_context {
 	struct xfs_trans	*tp;
 	struct xfs_inode	*dp;		/* inode */
 	struct xfs_attrlist_cursor_kern cursor;	/* position in list */
-	void			*buffer;	/* output buffer */
+	/* output buffer */
+	void			*buffer __counted_by_ptr(bufsize);
 
 	/*
 	 * Abort attribute list iteration if non-zero.  Can be used to pass
-- 
2.51.2


  reply	other threads:[~2026-04-27 12:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-27 12:09 [PATCH 0/3] xfsprogs: libxfs-v7.0-sync Andrey Albershteyn
2026-04-27 12:09 ` Andrey Albershteyn [this message]
2026-04-27 12:09 ` [PATCH 2/3] xfs: factor out xfs_attr3_node_entry_remove Andrey Albershteyn
2026-04-27 12:09 ` [PATCH 3/3] xfs: factor out xfs_attr3_leaf_init Andrey Albershteyn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260427120908.52254-2-aalbersh@kernel.org \
    --to=aalbersh@kernel.org \
    --cc=cem@kernel.org \
    --cc=djwong@kernel.org \
    --cc=hch@lst.de \
    --cc=leo.lilong@huawei.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=morbo@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox