xfs: annotate struct xfs_attr_list_context with __counted_by_ptr
PATCH 1/1 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.
---
Cc: Carlos Maiolino <[email protected]>
Cc: "Darrick J. Wong" <[email protected]>
Cc: Gogul Balakrishnan <[email protected]>
Cc: Arman Hasanzadeh <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
--- fs/xfs/libxfs/xfs_attr.h | 2 +- fs/xfs/xfs_handle.c | 2 +- fs/xfs/xfs_xattr.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_attr.h +1 -1
@@ -55,7 +55,7 @@ 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 */ + void *buffer __counted_by_ptr(bufsize); /* output buffer *//* * Abort attribute list iteration if non-zero. Can be used to pass
fs/xfs/xfs_handle.c +1 -1
@@ -443,8 +443,8 @@ xfs_ioc_attr_list( context.dp = dp; context.resynch =1 ; context.attr_filter =xfs_attr_filter (flags); - context.buffer = buffer; context.bufsize =round_down (bufsize,sizeof (uint32_t )); + context.buffer = buffer; context.firstu = context.bufsize; context.put_listent = xfs_ioc_attr_put_listent;
fs/xfs/xfs_xattr.c +1 -1
@@ -332,8 +332,8 @@ xfs_vn_listxattr(memset (&context,0 ,sizeof (context)); context.dp =XFS_I (inode); context.resynch =1 ; - context.buffer = size ? data :NULL ; context.bufsize = size; + context.buffer = size ? data :NULL ; context.firstu = context.bufsize; context.put_listent = xfs_xattr_put_listent;
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
Quoted 47 lines · Bill Wendling
Add the
__counted_by_ptrattribute to thebufferfield ofstruct xfs_attr_list_context. This field is used to point to a buffer of sizebufsize.The
bufferfield is assigned in:
1.xfs_ioc_attr_listinfs/xfs/xfs_handle.c
2.xfs_xattr_listinfs/xfs/xfs_xattr.c
3.xfs_getparentsinfs/xfs/xfs_handle.c(implicitly initialized to NULL)In
xfs_ioc_attr_list,bufferwas assigned beforebufsize. Reorder them to ensurebufsizeis set beforebufferis assigned, although no access happens between them.In
xfs_xattr_list,bufferwas assigned beforebufsize. Reorder them to ensurebufsizeis set beforebufferis assigned.In
xfs_getparents,bufferis NULL (from zero initialization) and remains NULL.bufsizeis set to a non-zero value, but sincebufferis NULL, no access occurs.In all cases, the pointer
bufferis not accessed beforebufsizeis set.This patch was generated by CodeMender and reviewed by Bill Wendling. Tested by running xfstests.
Signed-off-by Bill Wendling <[email protected]>---
Cc: Carlos Maiolino <[email protected]>
Cc: "Darrick J. Wong" <[email protected]>
Cc: Gogul Balakrishnan <[email protected]>
Cc: Arman Hasanzadeh <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]--- fs/xfs/libxfs/xfs_attr.h | 2 +- fs/xfs/xfs_handle.c | 2 +- fs/xfs/xfs_xattr.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)fs/xfs/libxfs/xfs_attr.h +0
-0
fs/xfs/libxfs/xfs_attr.h struct xfs_attr_list_context { · line 58
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.h +1
-1@@ -55,7 +55,7 @@ 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 */ + void *buffer __counted_by_ptr(bufsize); /* output buffer */
Looks reasonable, but ... how hard will it be to port __counted_by_ptr to userspace? Files in fs/xfs/libxfs/ get ported to userspace xfs. I see that it maps to an __attribute__. Does that get us any new gcc typechecking magic?
--D
Quoted 35 lines
fs/xfs/libxfs/xfs_attr.h +0
-0/* * Abort attribute list iteration if non-zero. Can be used to pass fs/xfs/xfs_handle.c +1
-1@@ -443,8 +443,8 @@ xfs_ioc_attr_list( context.dp = dp; context.resynch =1 ; context.attr_filter =xfs_attr_filter (flags); - context.buffer = buffer; context.bufsize =round_down (bufsize,sizeof (uint32_t )); + context.buffer = buffer; context.firstu = context.bufsize; context.put_listent = xfs_ioc_attr_put_listent;fs/xfs/xfs_xattr.c +1
-1@@ -332,8 +332,8 @@ xfs_vn_listxattr(memset (&context,0 ,sizeof (context)); context.dp =XFS_I (inode); context.resynch =1 ; - context.buffer = size ? data :NULL ; context.bufsize = size; + context.buffer = size ? data :NULL ; context.firstu = context.bufsize; context.put_listent = xfs_xattr_put_listent;Signature · 1 line
2.53.0.473.g4a7958ca14-goog
Quoted 44 lines · Darrick J. Wong
Quoted 42 lines · Bill Wendling
Add the
__counted_by_ptrattribute to thebufferfield ofstruct xfs_attr_list_context. This field is used to point to a buffer of sizebufsize.The
bufferfield is assigned in:
1.xfs_ioc_attr_listinfs/xfs/xfs_handle.c
2.xfs_xattr_listinfs/xfs/xfs_xattr.c
3.xfs_getparentsinfs/xfs/xfs_handle.c(implicitly initialized to NULL)In
xfs_ioc_attr_list,bufferwas assigned beforebufsize. Reorder them to ensurebufsizeis set beforebufferis assigned, although no access happens between them.In
xfs_xattr_list,bufferwas assigned beforebufsize. Reorder them to ensurebufsizeis set beforebufferis assigned.In
xfs_getparents,bufferis NULL (from zero initialization) and remains NULL.bufsizeis set to a non-zero value, but sincebufferis NULL, no access occurs.In all cases, the pointer
bufferis not accessed beforebufsizeis set.This patch was generated by CodeMender and reviewed by Bill Wendling. Tested by running xfstests.
Signed-off-by Bill Wendling <[email protected]>---
Cc: Carlos Maiolino <[email protected]>
Cc: "Darrick J. Wong" <[email protected]>
Cc: Gogul Balakrishnan <[email protected]>
Cc: Arman Hasanzadeh <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]--- fs/xfs/libxfs/xfs_attr.h | 2 +- fs/xfs/xfs_handle.c | 2 +- fs/xfs/xfs_xattr.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
Quoted 16 lines
fs/xfs/libxfs/xfs_attr.h struct xfs_attr_list_context { · line 58
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.h +1
-1@@ -55,7 +55,7 @@ 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 */ + void *buffer __counted_by_ptr(bufsize); /* output buffer */Looks reasonable, but ... how hard will it be to port
__counted_by_ptrto userspace? Files infs/xfs/libxfs/get ported to userspace xfs. I see that it maps to an__attribute__. Does that get us any new gcc typechecking magic?
I'm not familiar with how the files are ported to user space. There are #defines in include/uapi/linux/stddef.h that turn this attribute (and other similarly named attributes) off. Please let me know if that's not sufficient, as it will most likely apply to other APIs.
As for new typechecking magic, Clang and GCC check to ensure that the "counter" has an integral type. Otherwise, nothing earth shattering. :-)
-bw
Quoted 37 lines
--D
Quoted 35 lines
fs/xfs/libxfs/xfs_attr.h +0
-0/* * Abort attribute list iteration if non-zero. Can be used to pass fs/xfs/xfs_handle.c +1
-1@@ -443,8 +443,8 @@ xfs_ioc_attr_list( context.dp = dp; context.resynch =1 ; context.attr_filter =xfs_attr_filter (flags); - context.buffer = buffer; context.bufsize =round_down (bufsize,sizeof (uint32_t )); + context.buffer = buffer; context.firstu = context.bufsize; context.put_listent = xfs_ioc_attr_put_listent;fs/xfs/xfs_xattr.c +1
-2@@ -332,8 +332,8 @@ xfs_vn_listxattr(memset (&context,0 ,sizeof (context)); context.dp =XFS_I (inode); context.resynch =1 ; - context.buffer = size ? data :NULL ; context.bufsize = size; + context.buffer = size ? data :NULL ; context.firstu = context.bufsize; context.put_listent = xfs_xattr_put_listent; --2.53.0.473.g4a7958ca14-goog
fs/xfs/libxfs/xfs_attr.h struct xfs_attr_list_context { · line 58
Quoted 2 lines
fs/xfs/libxfs/xfs_attr.h +1
-1-void *buffer;/* output buffer */ + void *buffer __counted_by_ptr(bufsize); /* output buffer */
Please split this up somehow to keep the line readable, e.g.
/* output buffer: */ void *buffer __counted_by_ptr(bufsize);
Otherwise looks good.
Quoted 10 lines · Christoph Hellwig
fs/xfs/libxfs/xfs_attr.h struct xfs_attr_list_context { · line 58
Quoted 3 lines
fs/xfs/libxfs/xfs_attr.h +1
-1-void *buffer;/* output buffer */ + void *buffer __counted_by_ptr(bufsize); /* output buffer */Please split this up somehow to keep the line readable, e.g.
/* output buffer: */ void *buffer __counted_by_ptr(bufsize);Otherwise looks good.
Done. Sorry for the delay. I was on vacation.
-bw
PATCH v2 1/1 xfs: annotate struct xfs_attr_list_context with __counted_by_ptr
In reply to Bill WendlingAdd 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.
---
Cc: Carlos Maiolino <[email protected]>
Cc: "Darrick J. Wong" <[email protected]>
Cc: Gogul Balakrishnan <[email protected]>
Cc: Arman Hasanzadeh <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
v2 - Place comment in a more readable spot.
--- fs/xfs/libxfs/xfs_attr.h | 3 ++- fs/xfs/xfs_handle.c | 2 +- fs/xfs/xfs_xattr.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_attr.h +2 -1
@@ -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
fs/xfs/xfs_handle.c +1 -1
@@ -443,8 +443,8 @@ xfs_ioc_attr_list( context.dp = dp; context.resynch =1 ; context.attr_filter =xfs_attr_filter (flags); - context.buffer = buffer; context.bufsize =round_down (bufsize,sizeof (uint32_t )); + context.buffer = buffer; context.firstu = context.bufsize; context.put_listent = xfs_ioc_attr_put_listent;
fs/xfs/xfs_xattr.c +1 -1
@@ -332,8 +332,8 @@ xfs_vn_listxattr(memset (&context,0 ,sizeof (context)); context.dp =XFS_I (inode); context.resynch =1 ; - context.buffer = size ? data :NULL ; context.bufsize = size; + context.buffer = size ? data :NULL ; context.firstu = context.bufsize; context.put_listent = xfs_xattr_put_listent;
Signature · 1 line
2.53.0.851.ga537e3e6e9-goog
Quoted 20 lines · Bill Wendling
Add the
__counted_by_ptrattribute to thebufferfield ofstruct xfs_attr_list_context. This field is used to point to a buffer of sizebufsize.The
bufferfield is assigned in:
1.xfs_ioc_attr_listinfs/xfs/xfs_handle.c
2.xfs_xattr_listinfs/xfs/xfs_xattr.c
3.xfs_getparentsinfs/xfs/xfs_handle.c(implicitly initialized to NULL)In
xfs_ioc_attr_list,bufferwas assigned beforebufsize. Reorder them to ensurebufsizeis set beforebufferis assigned, although no access happens between them.In
xfs_xattr_list,bufferwas assigned beforebufsize. Reorder them to ensurebufsizeis set beforebufferis assigned.In
xfs_getparents,bufferis NULL (from zero initialization) and remains NULL.bufsizeis set to a non-zero value, but sincebufferis NULL, no access occurs.
Quoted 6 lines
In all cases, the pointer
bufferis not accessed beforebufsizeis set.This patch was generated by CodeMender and reviewed by Bill Wendling. Tested by running xfstests.
Signed-off-by Bill Wendling <[email protected]>
Looks ok to me, even if it's nothing earthshattering ;)
--D
Quoted 63 lines
---
Cc: Carlos Maiolino <[email protected]>
Cc: "Darrick J. Wong" <[email protected]>
Cc: Gogul Balakrishnan <[email protected]>
Cc: Arman Hasanzadeh <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
v2 - Place comment in a more readable spot.--- fs/xfs/libxfs/xfs_attr.h | 3 ++- fs/xfs/xfs_handle.c | 2 +- fs/xfs/xfs_xattr.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-)fs/xfs/libxfs/xfs_attr.h +2
-1@@ -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 fs/xfs/xfs_handle.c +1
-1@@ -443,8 +443,8 @@ xfs_ioc_attr_list( context.dp = dp; context.resynch =1 ; context.attr_filter =xfs_attr_filter (flags); - context.buffer = buffer; context.bufsize =round_down (bufsize,sizeof (uint32_t )); + context.buffer = buffer; context.firstu = context.bufsize; context.put_listent = xfs_ioc_attr_put_listent;fs/xfs/xfs_xattr.c +1
-1@@ -332,8 +332,8 @@ xfs_vn_listxattr(memset (&context,0 ,sizeof (context)); context.dp =XFS_I (inode); context.resynch =1 ; - context.buffer = size ? data :NULL ; context.bufsize = size; + context.buffer = size ? data :NULL ; context.firstu = context.bufsize; context.put_listent = xfs_xattr_put_listent;Signature · 1 line
2.53.0.851.ga537e3e6e9-goog
Looks good:
Quoted 10 lines · Bill Wendling
Add the
__counted_by_ptrattribute to thebufferfield ofstruct xfs_attr_list_context. This field is used to point to a buffer of sizebufsize.The
bufferfield is assigned in:
1.xfs_ioc_attr_listinfs/xfs/xfs_handle.c
2.xfs_xattr_listinfs/xfs/xfs_xattr.c
3.xfs_getparentsinfs/xfs/xfs_handle.c(implicitly initialized to NULL)[...]
Applied to for-next, thanks!
[1/1] xfs: annotate struct xfs_attr_list_context with __counted_by_ptr
commit: e5966096d0856d071269cb5928d6bc33342d2dfd
Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>