From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Thorsten Blum <thorsten.blum@toblux.com>,
chuck.lever@oracle.com, jlayton@kernel.org, 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 17:58:56 -0600 [thread overview]
Message-ID: <bde519c9-c95d-4275-a89b-50e628446206@embeddedor.com> (raw)
In-Reply-To: <20240828214254.2407-2-thorsten.blum@toblux.com>
On 28/08/24 15:42, 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>
Looks good --`nr_volumes` is updated just before accessing `volumes[]`.
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> 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,
next prev parent reply other threads:[~2024-08-28 23:59 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
2024-08-28 23:58 ` Gustavo A. R. Silva [this message]
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=bde519c9-c95d-4275-a89b-50e628446206@embeddedor.com \
--to=gustavo@embeddedor.com \
--cc=Dai.Ngo@oracle.com \
--cc=chuck.lever@oracle.com \
--cc=gustavoars@kernel.org \
--cc=jlayton@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®