* [PATCH] bfa: remove VLA
@ 2018-03-08 21:38 Stephen Kitt
2018-03-08 21:43 ` Kees Cook
2018-03-15 4:37 ` Martin K. Petersen
0 siblings, 2 replies; 5+ messages in thread
From: Stephen Kitt @ 2018-03-08 21:38 UTC (permalink / raw)
To: hare; +Cc: linux-scsi, kernel-hardening, linux-kernel, Stephen Kitt
In preparation to enabling -Wvla, remove VLAs and replace them with
fixed-length arrays instead.
bfad_bsg.c uses a variable-length array declaration to measure the
size of a putative array; this can be replaced by the product of the
size of an element and the number of elements, avoiding the VLA
altogether.
This was prompted by https://lkml.org/lkml/2018/3/7/621
Signed-off-by: Stephen Kitt <steve@sk2.org>
---
drivers/scsi/bfa/bfad_bsg.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index 3976e787ba64..7c884f881180 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -891,7 +891,7 @@ bfad_iocmd_fabric_get_lports(struct bfad_s *bfad, void *cmd,
if (bfad_chk_iocmd_sz(payload_len,
sizeof(struct bfa_bsg_fabric_get_lports_s),
- sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) {
+ sizeof(wwn_t) * iocmd->nports) != BFA_STATUS_OK) {
iocmd->status = BFA_STATUS_VERSION_FAIL;
goto out;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] bfa: remove VLA
2018-03-08 21:38 [PATCH] bfa: remove VLA Stephen Kitt
@ 2018-03-08 21:43 ` Kees Cook
2018-03-09 22:15 ` Stephen Kitt
2018-03-15 4:37 ` Martin K. Petersen
1 sibling, 1 reply; 5+ messages in thread
From: Kees Cook @ 2018-03-08 21:43 UTC (permalink / raw)
To: Stephen Kitt; +Cc: hare, linux-scsi, Kernel Hardening, LKML
On Thu, Mar 8, 2018 at 1:38 PM, Stephen Kitt <steve@sk2.org> wrote:
> In preparation to enabling -Wvla, remove VLAs and replace them with
> fixed-length arrays instead.
>
> bfad_bsg.c uses a variable-length array declaration to measure the
> size of a putative array; this can be replaced by the product of the
> size of an element and the number of elements, avoiding the VLA
> altogether.
>
> This was prompted by https://lkml.org/lkml/2018/3/7/621
>
> Signed-off-by: Stephen Kitt <steve@sk2.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
-Kees
> ---
> drivers/scsi/bfa/bfad_bsg.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
> index 3976e787ba64..7c884f881180 100644
> --- a/drivers/scsi/bfa/bfad_bsg.c
> +++ b/drivers/scsi/bfa/bfad_bsg.c
> @@ -891,7 +891,7 @@ bfad_iocmd_fabric_get_lports(struct bfad_s *bfad, void *cmd,
>
> if (bfad_chk_iocmd_sz(payload_len,
> sizeof(struct bfa_bsg_fabric_get_lports_s),
> - sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) {
> + sizeof(wwn_t) * iocmd->nports) != BFA_STATUS_OK) {
> iocmd->status = BFA_STATUS_VERSION_FAIL;
> goto out;
> }
> --
> 2.11.0
>
--
Kees Cook
Pixel Security
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] bfa: remove VLA
2018-03-08 21:43 ` Kees Cook
@ 2018-03-09 22:15 ` Stephen Kitt
0 siblings, 0 replies; 5+ messages in thread
From: Stephen Kitt @ 2018-03-09 22:15 UTC (permalink / raw)
To: Anil Gurumurthy, Sudarsana Kalluru; +Cc: linux-scsi, Kernel Hardening, LKML
[-- Attachment #1: Type: text/plain, Size: 1693 bytes --]
Hi,
I sent this to the wrong maintainers, sorry — you’ll find the original patch
on https://patchwork.kernel.org/patch/10269257/
Regards,
Stephen
On Thu, 8 Mar 2018 13:43:07 -0800, Kees Cook <keescook@chromium.org> wrote:
> On Thu, Mar 8, 2018 at 1:38 PM, Stephen Kitt <steve@sk2.org> wrote:
> > In preparation to enabling -Wvla, remove VLAs and replace them with
> > fixed-length arrays instead.
> >
> > bfad_bsg.c uses a variable-length array declaration to measure the
> > size of a putative array; this can be replaced by the product of the
> > size of an element and the number of elements, avoiding the VLA
> > altogether.
> >
> > This was prompted by https://lkml.org/lkml/2018/3/7/621
> >
> > Signed-off-by: Stephen Kitt <steve@sk2.org>
>
> Reviewed-by: Kees Cook <keescook@chromium.org>
>
> -Kees
>
> > ---
> > drivers/scsi/bfa/bfad_bsg.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
> > index 3976e787ba64..7c884f881180 100644
> > --- a/drivers/scsi/bfa/bfad_bsg.c
> > +++ b/drivers/scsi/bfa/bfad_bsg.c
> > @@ -891,7 +891,7 @@ bfad_iocmd_fabric_get_lports(struct bfad_s *bfad,
> > void *cmd,
> >
> > if (bfad_chk_iocmd_sz(payload_len,
> > sizeof(struct bfa_bsg_fabric_get_lports_s),
> > - sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) {
> > + sizeof(wwn_t) * iocmd->nports) != BFA_STATUS_OK) {
> > iocmd->status = BFA_STATUS_VERSION_FAIL;
> > goto out;
> > }
> > --
> > 2.11.0
> >
>
>
>
> --
> Kees Cook
> Pixel Security
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] bfa: remove VLA
2018-03-08 21:38 [PATCH] bfa: remove VLA Stephen Kitt
2018-03-08 21:43 ` Kees Cook
@ 2018-03-15 4:37 ` Martin K. Petersen
2018-03-15 11:40 ` David Laight
1 sibling, 1 reply; 5+ messages in thread
From: Martin K. Petersen @ 2018-03-15 4:37 UTC (permalink / raw)
To: Stephen Kitt; +Cc: hare, linux-scsi, kernel-hardening, linux-kernel
Stephen,
> bfad_bsg.c uses a variable-length array declaration to measure the
> size of a putative array; this can be replaced by the product of the
> size of an element and the number of elements, avoiding the VLA
> altogether.
>
> - sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) {
> + sizeof(wwn_t) * iocmd->nports) != BFA_STATUS_OK) {
These parentheses made me blurry eyed but it's actually OK.
Applied to 4.17/scsi-queue.
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH] bfa: remove VLA
2018-03-15 4:37 ` Martin K. Petersen
@ 2018-03-15 11:40 ` David Laight
0 siblings, 0 replies; 5+ messages in thread
From: David Laight @ 2018-03-15 11:40 UTC (permalink / raw)
To: 'Martin K. Petersen', Stephen Kitt
Cc: hare, linux-scsi, kernel-hardening, linux-kernel
> > - sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) {
> > + sizeof(wwn_t) * iocmd->nports) != BFA_STATUS_OK) {
>
> These parentheses made me blurry eyed but it's actually OK.
iocmd->nports * sizeof(wwn_t)) != BFA_STATUS_OK) {
is easier to focus on :-)
David
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-03-15 11:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-08 21:38 [PATCH] bfa: remove VLA Stephen Kitt
2018-03-08 21:43 ` Kees Cook
2018-03-09 22:15 ` Stephen Kitt
2018-03-15 4:37 ` Martin K. Petersen
2018-03-15 11:40 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).