Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Thorsten Blum <thorsten.blum@toblux.com>
Cc: tytso@mit.edu, adilger.kernel@dilger.ca, kees@kernel.org,
	gustavoars@kernel.org, linux-ext4@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] ext4: Annotate struct fname with __counted_by()
Date: Tue, 17 Sep 2024 14:25:29 +0200	[thread overview]
Message-ID: <20240917122529.lmikh56cfbjr3lsz@quack3> (raw)
In-Reply-To: <20240913110013.151331-2-thorsten.blum@toblux.com>

On Fri 13-09-24 13:00:14, Thorsten Blum wrote:
> Add the __counted_by compiler attribute to the flexible array member
> name to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
> CONFIG_FORTIFY_SOURCE.
> 
> Inline and use struct_size() to calculate the number of bytes to
> allocate for new_fn and remove the local variable len.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ext4/dir.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
> index ff4514e4626b..8e7df15bb971 100644
> --- a/fs/ext4/dir.c
> +++ b/fs/ext4/dir.c
> @@ -408,7 +408,7 @@ struct fname {
>  	__u32		inode;
>  	__u8		name_len;
>  	__u8		file_type;
> -	char		name[];
> +	char		name[] __counted_by(name_len);
>  };
>  
>  /*
> @@ -464,14 +464,13 @@ int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
>  	struct rb_node **p, *parent = NULL;
>  	struct fname *fname, *new_fn;
>  	struct dir_private_info *info;
> -	int len;
>  
>  	info = dir_file->private_data;
>  	p = &info->root.rb_node;
>  
>  	/* Create and allocate the fname structure */
> -	len = sizeof(struct fname) + ent_name->len + 1;
> -	new_fn = kzalloc(len, GFP_KERNEL);
> +	new_fn = kzalloc(struct_size(new_fn, name, ent_name->len + 1),
> +			 GFP_KERNEL);
>  	if (!new_fn)
>  		return -ENOMEM;
>  	new_fn->hash = hash;
> -- 
> 2.46.0
> 
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

      reply	other threads:[~2024-09-17 12:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-13 11:00 [PATCH] ext4: Annotate struct fname with __counted_by() Thorsten Blum
2024-09-17 12:25 ` Jan Kara [this message]

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=20240917122529.lmikh56cfbjr3lsz@quack3 \
    --to=jack@suse.cz \
    --cc=adilger.kernel@dilger.ca \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thorsten.blum@toblux.com \
    --cc=tytso@mit.edu \
    /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