From: Kees Cook <keescook@chromium.org>
To: Justin Tee <justintee8345@gmail.com>
Cc: linux-scsi@vger.kernel.org, jsmart2021@gmail.com,
justin.tee@broadcom.com,
"Gustavo A . R . Silva" <gustavoars@kernel.org>
Subject: Re: [PATCH v3][next] scsi: lpfc: Use struct_size() helper
Date: Thu, 1 Jun 2023 07:14:08 -0700 [thread overview]
Message-ID: <202306010712.71318C84E@keescook> (raw)
In-Reply-To: <20230531223319.24328-1-justintee8345@gmail.com>
On Wed, May 31, 2023 at 03:33:19PM -0700, Justin Tee wrote:
> Prefer struct_size() over open-coded versions of idiom:
>
> sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count
>
> where count is the max number of items the flexible array is supposed to
> contain.
>
> Link: https://github.com/KSPP/linux/issues/160
The SoB chain here looks weird -- I think this should include the C-d-b
tags as well:
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Co-developed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> Signed-off-by: Kees Cook <keescook@chromium.org>
Co-developed-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Justin Tee <justin.tee@broadcom.com>
But regardless, thank you -- looks good!
Reviewed-by: Kees Cook <keescook@chromium.org>
-Kees
> ---
> Changes in v3:
> - Instead of hardcode to 1, use be32_to_cpu(rap->no_of_objects).
> (Justin Tee).
>
> v2:
> - Use literal 1 in call to struct_size(), instead of rap->no_of_objects
> (Kees Cook).
>
> v1:
> - Link:
> https://lore.kernel.org/linux-hardening/99e06733f5f35c6cd62e05f530b93107bfd03362.1684358315.git.gustavoars@kernel.org/
> ---
> drivers/scsi/lpfc/lpfc_ct.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
> index e880d127d7f5..703429512ead 100644
> --- a/drivers/scsi/lpfc/lpfc_ct.c
> +++ b/drivers/scsi/lpfc/lpfc_ct.c
> @@ -3748,8 +3748,7 @@ lpfc_vmid_cmd(struct lpfc_vport *vport,
> rap->obj[0].entity_id_len = vmid->vmid_len;
> memcpy(rap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len);
> size = RAPP_IDENT_OFFSET +
> - sizeof(struct lpfc_vmid_rapp_ident_list) +
> - sizeof(struct entity_id_object);
> + struct_size(rap, obj, be32_to_cpu(rap->no_of_objects));
> retry = 1;
> break;
>
> @@ -3768,8 +3767,7 @@ lpfc_vmid_cmd(struct lpfc_vport *vport,
> dap->obj[0].entity_id_len = vmid->vmid_len;
> memcpy(dap->obj[0].entity_id, vmid->host_vmid, vmid->vmid_len);
> size = DAPP_IDENT_OFFSET +
> - sizeof(struct lpfc_vmid_dapp_ident_list) +
> - sizeof(struct entity_id_object);
> + struct_size(dap, obj, be32_to_cpu(dap->no_of_objects));
> write_lock(&vport->vmid_lock);
> vmid->flag &= ~LPFC_VMID_REGISTERED;
> write_unlock(&vport->vmid_lock);
> --
> 2.38.0
>
--
Kees Cook
next prev parent reply other threads:[~2023-06-01 14:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-31 22:33 [PATCH v3][next] scsi: lpfc: Use struct_size() helper Justin Tee
2023-06-01 14:14 ` Kees Cook [this message]
2023-06-08 1:03 ` Martin K. Petersen
2023-06-15 2:16 ` Martin K. Petersen
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=202306010712.71318C84E@keescook \
--to=keescook@chromium.org \
--cc=gustavoars@kernel.org \
--cc=jsmart2021@gmail.com \
--cc=justin.tee@broadcom.com \
--cc=justintee8345@gmail.com \
--cc=linux-scsi@vger.kernel.org \
/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