linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: Annotate struct ext4_xattr_inode_array with __counted_by()
@ 2024-07-29 11:04 Thorsten Blum
  2024-07-29 14:09 ` Gustavo A. R. Silva
  2024-07-30  1:21 ` yebin (H)
  0 siblings, 2 replies; 4+ messages in thread
From: Thorsten Blum @ 2024-07-29 11:04 UTC (permalink / raw)
  To: tytso, adilger.kernel, kees, gustavoars
  Cc: linux-ext4, linux-kernel, linux-hardening, Thorsten Blum

Add the __counted_by compiler attribute to the flexible array member
inodes to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
CONFIG_FORTIFY_SOURCE.

Remove the now obsolete comment on the count field.

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
 fs/ext4/xattr.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h
index bd97c4aa8177..e14fb19dc912 100644
--- a/fs/ext4/xattr.h
+++ b/fs/ext4/xattr.h
@@ -130,8 +130,8 @@ struct ext4_xattr_ibody_find {
 };
 
 struct ext4_xattr_inode_array {
-	unsigned int count;		/* # of used items in the array */
-	struct inode *inodes[];
+	unsigned int count;
+	struct inode *inodes[] __counted_by(count);
 };
 
 extern const struct xattr_handler ext4_xattr_user_handler;
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ext4: Annotate struct ext4_xattr_inode_array with __counted_by()
  2024-07-29 11:04 [PATCH] ext4: Annotate struct ext4_xattr_inode_array with __counted_by() Thorsten Blum
@ 2024-07-29 14:09 ` Gustavo A. R. Silva
  2024-07-30 17:10   ` Thorsten Blum
  2024-07-30  1:21 ` yebin (H)
  1 sibling, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2024-07-29 14:09 UTC (permalink / raw)
  To: Thorsten Blum, tytso, adilger.kernel, kees, gustavoars
  Cc: linux-ext4, linux-kernel, linux-hardening



On 29/07/24 05:04, Thorsten Blum wrote:
> Add the __counted_by compiler attribute to the flexible array member
> inodes to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
> CONFIG_FORTIFY_SOURCE.

This change seems to be incomplete. The relationship between `count` and
accesses to `inodes` should be adjusted at least in `ext4_expand_inode_array()`

See this for more details:

https://embeddedor.com/blog/2024/06/18/how-to-use-the-new-counted_by-attribute-in-c-and-linux/

Thanks
--
Gustavo

> 
> Remove the now obsolete comment on the count field.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
>   fs/ext4/xattr.h | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h
> index bd97c4aa8177..e14fb19dc912 100644
> --- a/fs/ext4/xattr.h
> +++ b/fs/ext4/xattr.h
> @@ -130,8 +130,8 @@ struct ext4_xattr_ibody_find {
>   };
>   
>   struct ext4_xattr_inode_array {
> -	unsigned int count;		/* # of used items in the array */
> -	struct inode *inodes[];
> +	unsigned int count;
> +	struct inode *inodes[] __counted_by(count);
>   };
>   
>   extern const struct xattr_handler ext4_xattr_user_handler;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ext4: Annotate struct ext4_xattr_inode_array with __counted_by()
  2024-07-29 11:04 [PATCH] ext4: Annotate struct ext4_xattr_inode_array with __counted_by() Thorsten Blum
  2024-07-29 14:09 ` Gustavo A. R. Silva
@ 2024-07-30  1:21 ` yebin (H)
  1 sibling, 0 replies; 4+ messages in thread
From: yebin (H) @ 2024-07-30  1:21 UTC (permalink / raw)
  To: Thorsten Blum, tytso, adilger.kernel, kees, gustavoars
  Cc: linux-ext4, linux-kernel, linux-hardening



On 2024/7/29 19:04, Thorsten Blum wrote:
> Add the __counted_by compiler attribute to the flexible array member
> inodes to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
> CONFIG_FORTIFY_SOURCE.
>
> Remove the now obsolete comment on the count field.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
>   fs/ext4/xattr.h | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h
> index bd97c4aa8177..e14fb19dc912 100644
> --- a/fs/ext4/xattr.h
> +++ b/fs/ext4/xattr.h
> @@ -130,8 +130,8 @@ struct ext4_xattr_ibody_find {
>   };
>   
>   struct ext4_xattr_inode_array {
> -	unsigned int count;		/* # of used items in the array */
> -	struct inode *inodes[];
> +	unsigned int count;
As the comment says, 'count' is the number of items in the array that 
have been used,
not the total number of items in the array. So I think this check was 
added incorrectly.
> +	struct inode *inodes[] __counted_by(count);
>   };
>   
>   extern const struct xattr_handler ext4_xattr_user_handler;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ext4: Annotate struct ext4_xattr_inode_array with __counted_by()
  2024-07-29 14:09 ` Gustavo A. R. Silva
@ 2024-07-30 17:10   ` Thorsten Blum
  0 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2024-07-30 17:10 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: tytso, adilger.kernel, kees, gustavoars, linux-ext4, linux-kernel,
	linux-hardening

On 29. Jul 2024, at 16:09, Gustavo A. R. Silva <gustavo@embeddedor.com> wrote:
> On 29/07/24 05:04, Thorsten Blum wrote:
>> Add the __counted_by compiler attribute to the flexible array member
>> inodes to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
>> CONFIG_FORTIFY_SOURCE.
> 
> This change seems to be incomplete. The relationship between `count` and
> accesses to `inodes` should be adjusted at least in `ext4_expand_inode_array()`
> 
> See this for more details:
> 
> https://embeddedor.com/blog/2024/06/18/how-to-use-the-new-counted_by-attribute-in-c-and-linux/

Thanks. I'll submit a v2 shortly.

Thorsten

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-30 17:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-29 11:04 [PATCH] ext4: Annotate struct ext4_xattr_inode_array with __counted_by() Thorsten Blum
2024-07-29 14:09 ` Gustavo A. R. Silva
2024-07-30 17:10   ` Thorsten Blum
2024-07-30  1:21 ` yebin (H)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).