linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH 05/32] brcmfmac: Use mem_to_flex_dup() with struct brcmf_fweh_queue_item
       [not found] ` <20220504014440.3697851-6-keescook@chromium.org>
@ 2022-05-16 12:49   ` Arend van Spriel
  2022-05-17  3:57     ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Arend van Spriel @ 2022-05-16 12:49 UTC (permalink / raw)
  To: Kees Cook, Gustavo A . R . Silva
  Cc: linux-wireless, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 2603 bytes --]

On 5/4/2022 3:44 AM, Kees Cook wrote:
> As part of the work to perform bounds checking on all memcpy() uses,
> replace the open-coded a deserialization of bytes out of memory into a
> trailing flexible array by using a flex_array.h helper to perform the
> allocation, bounds checking, and copying.
> 
Reviewed-by: Arend van Spriel <aspriel@gmail.com>
> Cc: Franky Lin <franky.lin@broadcom.com>
> Cc: Hante Meuleman <hante.meuleman@broadcom.com>
> Cc: Kalle Valo <kvalo@kernel.org>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: linux-wireless@vger.kernel.org
> Cc: brcm80211-dev-list.pdl@broadcom.com
> Cc: SHA-cyfmac-dev-list@infineon.com
> Cc: netdev@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>   .../net/wireless/broadcom/brcm80211/brcmfmac/fweh.c   | 11 ++++-------
>   1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
> index bc3f4e4edcdf..bea798ca6466 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
> @@ -32,8 +32,8 @@ struct brcmf_fweh_queue_item {
>   	u8 ifidx;
>   	u8 ifaddr[ETH_ALEN];
>   	struct brcmf_event_msg_be emsg;
> -	u32 datalen;
> -	u8 data[];
> +	DECLARE_FLEX_ARRAY_ELEMENTS_COUNT(u32, datalen);
> +	DECLARE_FLEX_ARRAY_ELEMENTS(u8, data);
>   };
>   
>   /*
> @@ -395,7 +395,7 @@ void brcmf_fweh_process_event(struct brcmf_pub *drvr,
>   {
>   	enum brcmf_fweh_event_code code;
>   	struct brcmf_fweh_info *fweh = &drvr->fweh;
> -	struct brcmf_fweh_queue_item *event;
> +	struct brcmf_fweh_queue_item *event = NULL;
>   	void *data;
>   	u32 datalen;
>   
> @@ -414,8 +414,7 @@ void brcmf_fweh_process_event(struct brcmf_pub *drvr,
>   	    datalen + sizeof(*event_packet) > packet_len)
>   		return;
>   
> -	event = kzalloc(sizeof(*event) + datalen, gfp);
> -	if (!event)
> +	if (mem_to_flex_dup(&event, data, datalen, gfp))
>   		return;
>   
>   	event->code = code;
> @@ -423,8 +422,6 @@ void brcmf_fweh_process_event(struct brcmf_pub *drvr,
>   
>   	/* use memcpy to get aligned event message */
>   	memcpy(&event->emsg, &event_packet->msg, sizeof(event->emsg));
> -	memcpy(event->data, data, datalen);
> -	event->datalen = datalen;

So does mem_to_flex_dup() store event->datalen?

Don't have the entire thread so missing bits and pieces, but at least 
this raises questions for me.

Thanks,
Arend

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4219 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 05/32] brcmfmac: Use mem_to_flex_dup() with struct brcmf_fweh_queue_item
  2022-05-16 12:49   ` [PATCH 05/32] brcmfmac: Use mem_to_flex_dup() with struct brcmf_fweh_queue_item Arend van Spriel
@ 2022-05-17  3:57     ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2022-05-17  3:57 UTC (permalink / raw)
  To: Arend van Spriel
  Cc: Gustavo A . R . Silva, linux-wireless, Linux Kernel Mailing List

On Mon, May 16, 2022 at 02:49:21PM +0200, Arend van Spriel wrote:
> On 5/4/2022 3:44 AM, Kees Cook wrote:
> > As part of the work to perform bounds checking on all memcpy() uses,
> > replace the open-coded a deserialization of bytes out of memory into a
> > trailing flexible array by using a flex_array.h helper to perform the
> > allocation, bounds checking, and copying.
> > 
> Reviewed-by: Arend van Spriel <aspriel@gmail.com>

Thanks!

> > [...]
> > diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
> > index bc3f4e4edcdf..bea798ca6466 100644
> > --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
> > +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
> > @@ -32,8 +32,8 @@ struct brcmf_fweh_queue_item {
> >   	u8 ifidx;
> >   	u8 ifaddr[ETH_ALEN];
> >   	struct brcmf_event_msg_be emsg;
> > -	u32 datalen;
> > -	u8 data[];
> > +	DECLARE_FLEX_ARRAY_ELEMENTS_COUNT(u32, datalen);
> > +	DECLARE_FLEX_ARRAY_ELEMENTS(u8, data);
> >   };
> > [...]
> > @@ -414,8 +414,7 @@ void brcmf_fweh_process_event(struct brcmf_pub *drvr,
> >   	    datalen + sizeof(*event_packet) > packet_len)
> >   		return;
> > -	event = kzalloc(sizeof(*event) + datalen, gfp);
> > -	if (!event)
> > +	if (mem_to_flex_dup(&event, data, datalen, gfp))
> >   		return;
> >   	event->code = code;
> > @@ -423,8 +422,6 @@ void brcmf_fweh_process_event(struct brcmf_pub *drvr,
> >   	/* use memcpy to get aligned event message */
> >   	memcpy(&event->emsg, &event_packet->msg, sizeof(event->emsg));
> > -	memcpy(event->data, data, datalen);
> > -	event->datalen = datalen;
> 
> So does mem_to_flex_dup() store event->datalen?
> 
> Don't have the entire thread so missing bits and pieces, but at least this
> raises questions for me.

Yes, that's part of the internal workings here -- the flex array counter
is declared and will be set as part of the copy.

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-17  3:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20220504014440.3697851-1-keescook@chromium.org>
     [not found] ` <20220504014440.3697851-6-keescook@chromium.org>
2022-05-16 12:49   ` [PATCH 05/32] brcmfmac: Use mem_to_flex_dup() with struct brcmf_fweh_queue_item Arend van Spriel
2022-05-17  3:57     ` Kees Cook

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).