Skip to content

Commit e596609

Browse files
bwendlingcmaiolino
authored andcommitted
xfs: annotate struct xfs_attr_list_context with __counted_by_ptr
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>
1 parent 0c98524 commit e596609

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

fs/xfs/libxfs/xfs_attr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ struct xfs_attr_list_context {
5555
struct xfs_trans *tp;
5656
struct xfs_inode *dp; /* inode */
5757
struct xfs_attrlist_cursor_kern cursor; /* position in list */
58-
void *buffer; /* output buffer */
58+
/* output buffer */
59+
void *buffer __counted_by_ptr(bufsize);
5960

6061
/*
6162
* Abort attribute list iteration if non-zero. Can be used to pass

fs/xfs/xfs_handle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,8 @@ xfs_ioc_attr_list(
443443
context.dp = dp;
444444
context.resynch = 1;
445445
context.attr_filter = xfs_attr_filter(flags);
446-
context.buffer = buffer;
447446
context.bufsize = round_down(bufsize, sizeof(uint32_t));
447+
context.buffer = buffer;
448448
context.firstu = context.bufsize;
449449
context.put_listent = xfs_ioc_attr_put_listent;
450450

fs/xfs/xfs_xattr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ xfs_vn_listxattr(
332332
memset(&context, 0, sizeof(context));
333333
context.dp = XFS_I(inode);
334334
context.resynch = 1;
335-
context.buffer = size ? data : NULL;
336335
context.bufsize = size;
336+
context.buffer = size ? data : NULL;
337337
context.firstu = context.bufsize;
338338
context.put_listent = xfs_xattr_put_listent;
339339

0 commit comments

Comments
 (0)