mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Justin Tee <justintee8345@gmail.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: James Smart <james.smart@broadcom.com>,
	Dick Kennedy <dick.kennedy@broadcom.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org,
	Kees Cook <keescook@chromium.org>,
	Justin Tee <justin.tee@broadcom.com>
Subject: Re: [PATCH v2][next] scsi: lpfc: Use struct_size() helper
Date: Tue, 23 May 2023 22:25:20 -0700	[thread overview]
Message-ID: <CABPRKS9ykHvaOGUboDXZ261LLPS78+YFpOZAcJEeLKGfEUe21g@mail.gmail.com> (raw)
In-Reply-To: <ZG0fDdY/PPQ/ijlt@work>

no_of_objects may be hardcoded to 1 right now, but does it make more
sense to use?

struct_size(rap, obj, be32_to_cpu(rap->no_of_objects));

We probably should have declared no_of_objects as __be32 to have
avoided this confusion.

On Tue, May 23, 2023 at 1:33 PM Gustavo A. R. Silva
<gustavoars@kernel.org> 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
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> Changes in 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 | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
> index e880d127d7f5..f52aeb73af8d 100644
> --- a/drivers/scsi/lpfc/lpfc_ct.c
> +++ b/drivers/scsi/lpfc/lpfc_ct.c
> @@ -3747,9 +3747,7 @@ lpfc_vmid_cmd(struct lpfc_vport *vport,
>                 rap->no_of_objects = cpu_to_be32(1);
>                 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);
> +               size = RAPP_IDENT_OFFSET + struct_size(rap, obj, 1);
>                 retry = 1;
>                 break;
>
> @@ -3767,9 +3765,7 @@ lpfc_vmid_cmd(struct lpfc_vport *vport,
>                 dap->no_of_objects = cpu_to_be32(1);
>                 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);
> +               size = DAPP_IDENT_OFFSET + struct_size(dap, obj, 1);
>                 write_lock(&vport->vmid_lock);
>                 vmid->flag &= ~LPFC_VMID_REGISTERED;
>                 write_unlock(&vport->vmid_lock);
> --
> 2.34.1
>

  reply	other threads:[~2023-05-24  5:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-23 20:16 Gustavo A. R. Silva
2023-05-24  5:25 ` Justin Tee [this message]
2023-05-26 17:41   ` Kees Cook
2023-05-26 18:06     ` Justin Tee
2023-05-31 15:26       ` Martin K. Petersen
2023-05-31 21:59         ` Justin Tee

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=CABPRKS9ykHvaOGUboDXZ261LLPS78+YFpOZAcJEeLKGfEUe21g@mail.gmail.com \
    --to=justintee8345@gmail.com \
    --cc=dick.kennedy@broadcom.com \
    --cc=gustavoars@kernel.org \
    --cc=james.smart@broadcom.com \
    --cc=jejb@linux.ibm.com \
    --cc=justin.tee@broadcom.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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®