mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Thorsten Blum <thorsten.blum@toblux.com>,
	chuck.lever@oracle.com,  neilb@suse.de, okorniev@redhat.com,
	Dai.Ngo@oracle.com, tom@talpey.com,  kees@kernel.org,
	gustavoars@kernel.org
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-hardening@vger.kernel.org
Subject: Re: [PATCH] NFSD: Annotate struct pnfs_block_deviceaddr with __counted_by()
Date: Wed, 28 Aug 2024 18:09:54 -0400	[thread overview]
Message-ID: <998d25a6ac673063fe1b0def62af90792379c4fe.camel@kernel.org> (raw)
In-Reply-To: <20240828214254.2407-2-thorsten.blum@toblux.com>

On Wed, 2024-08-28 at 23:42 +0200, Thorsten Blum wrote:
> Add the __counted_by compiler attribute to the flexible array member
> volumes to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
> CONFIG_FORTIFY_SOURCE.
> 
> Use struct_size() instead of manually calculating the number of bytes to
> allocate for a pnfs_block_deviceaddr with a single volume.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
>  fs/nfsd/blocklayout.c    | 6 ++----
>  fs/nfsd/blocklayoutxdr.h | 2 +-
>  2 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/nfsd/blocklayout.c b/fs/nfsd/blocklayout.c
> index 3c040c81c77d..08a20e5bcf7f 100644
> --- a/fs/nfsd/blocklayout.c
> +++ b/fs/nfsd/blocklayout.c
> @@ -147,8 +147,7 @@ nfsd4_block_get_device_info_simple(struct super_block *sb,
>  	struct pnfs_block_deviceaddr *dev;
>  	struct pnfs_block_volume *b;
>  
> -	dev = kzalloc(sizeof(struct pnfs_block_deviceaddr) +
> -		      sizeof(struct pnfs_block_volume), GFP_KERNEL);
> +	dev = kzalloc(struct_size(dev, volumes, 1), GFP_KERNEL);
>  	if (!dev)
>  		return -ENOMEM;
>  	gdp->gd_device = dev;
> @@ -255,8 +254,7 @@ nfsd4_block_get_device_info_scsi(struct super_block *sb,
>  	const struct pr_ops *ops;
>  	int ret;
>  
> -	dev = kzalloc(sizeof(struct pnfs_block_deviceaddr) +
> -		      sizeof(struct pnfs_block_volume), GFP_KERNEL);
> +	dev = kzalloc(struct_size(dev, volumes, 1), GFP_KERNEL);
>  	if (!dev)
>  		return -ENOMEM;
>  	gdp->gd_device = dev;
> diff --git a/fs/nfsd/blocklayoutxdr.h b/fs/nfsd/blocklayoutxdr.h
> index b0361e8aa9a7..4e28ac8f1127 100644
> --- a/fs/nfsd/blocklayoutxdr.h
> +++ b/fs/nfsd/blocklayoutxdr.h
> @@ -47,7 +47,7 @@ struct pnfs_block_volume {
>  
>  struct pnfs_block_deviceaddr {
>  	u32				nr_volumes;
> -	struct pnfs_block_volume	volumes[];
> +	struct pnfs_block_volume	volumes[] __counted_by(nr_volumes);
>  };
>  
>  __be32 nfsd4_block_encode_getdeviceinfo(struct xdr_stream *xdr,

Acked-by: Jeff Layton <jlayton@kernel.org>

  reply	other threads:[~2024-08-28 22:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-28 21:42 Thorsten Blum
2024-08-28 22:09 ` Jeff Layton [this message]
2024-08-28 23:58 ` Gustavo A. R. Silva
2024-08-29 14:37 ` Chuck Lever

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=998d25a6ac673063fe1b0def62af90792379c4fe.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=chuck.lever@oracle.com \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=okorniev@redhat.com \
    --cc=thorsten.blum@toblux.com \
    --cc=tom@talpey.com \
    /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

all inboxes | Powered by JetHome®