]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfsprogs-dev.git/commitdiff
xfs: annotate struct xfs_attr_list_context with __counted_by_ptr
authorBill Wendling <morbo@google.com>
Fri, 24 Apr 2026 14:13:03 +0000 (16:13 +0200)
committerAndrey Albershteyn <aalbersh@kernel.org>
Fri, 24 Apr 2026 16:17:35 +0000 (18:17 +0200)
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
libxfs/xfs_attr.h

index b2d80597a83aa4fc0d30b6827cb6ce8d76f17be0..5a829db66e0899259ef44c48b2f857748a04297c 100644 (file)
@@ -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__ */
index 8244305949deb9f19004554c8619ece0c03ffe44..67fd9c75ac3fb3f6ffd14c9fa69cf7f91fc2c8f2 100644 (file)
@@ -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