wifi: brcmfmac: fweh: Fix boot crash on Raspberry Pi 4
PATCH 1/1 wifi: brcmfmac: fweh: Fix boot crash on Raspberry Pi 4
Fix boot crash on Raspberry Pi by moving the update to event->datalen before data is copied into flexible-array member data via memcpy().
Flexible-array member data was annotated with __counted_by(datalen) in commit 62d19b358088 ("wifi: brcmfmac: fweh: Add __counted_by for struct brcmf_fweh_queue_item and use struct_size()"). The intention of this is to gain visibility into the size of data at run-time through its _counter_ (in this case datalen), and with this have its accesses bounds-checked at run-time via CONFIG_FORTIFY_SOURCE and CONFIG_UBSAN_BOUNDS.
To effectively accomplish the above, we shall update the counter (datalen), before the first access to the flexible array (data), which was also done in the mentioned commit.
However, commit edec42821911 ("wifi: brcmfmac: allow per-vendor event handling") inadvertently caused a buffer overflow, detected by FORTIFY_SOURCE. It moved the event->datalen = datalen; update to after the first data access, at which point event->datalen was not yet updated from zero (after calling kzalloc()), leading to the overflow issue.
This fix repositions the event->datalen = datalen; update before accessing data, restoring the intended buffer overflow protection. :)
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c +1 -1
@@ -497,12 +497,12 @@ void brcmf_fweh_process_event(struct brcmf_pub *drvr,return ; event->code = fwevt_idx; + event->datalen = datalen; event->ifidx = event_packet->msg.ifidx;/* use memcpy to get aligned event message */ memcpy (&event->emsg, &event_packet->msg,sizeof (event->emsg));memcpy (event->data, data, datalen); - event->datalen = datalen;memcpy (event->ifaddr, event_packet->eth.h_dest,ETH_ALEN );brcmf_fweh_queue_event (fweh, event);
Signature · 1 line
2.34.1
Quoted 22 lines · Gustavo A. R. Silva
Fix boot crash on Raspberry Pi by moving the update to
event->datalenbefore data is copied into flexible-array memberdataviamemcpy().Flexible-array member
datawas annotated with__counted_by(datalen)in commit62d19b358088("wifi: brcmfmac: fweh: Add__counted_byfor structbrcmf_fweh_queue_itemand usestruct_size()"). The intention of this is to gain visibility into the size ofdataat run-time through its _counter_ (in this casedatalen), and with this have its accesses bounds-checked at run-time viaCONFIG_FORTIFY_SOURCEandCONFIG_UBSAN_BOUNDS.To effectively accomplish the above, we shall update the counter (
datalen), before the first access to the flexible array (data), which was also done in the mentioned commit.However, commit
edec42821911("wifi: brcmfmac: allow per-vendor event handling") inadvertently caused a buffer overflow, detected byFORTIFY_SOURCE. It moved theevent->datalen = datalen;update to after the firstdataaccess, at which pointevent->datalenwas not yet updated from zero (after callingkzalloc()), leading to the overflow issue.
Quoted 8 lines
This fix repositions the
event->datalen = datalen;update before accessingdata, restoring the intended buffer overflow protection. :)Fixes edec42821911 ("wifi: brcmfmac: allow per-vendor event handling")Reported-by Nathan Chancellor <[email protected]>Tested-by Nathan Chancellor <[email protected]>Signed-off-by Gustavo A. R. Silva <[email protected]>
Yup, this looks correct. Thanks!
Signature · 1 line
Kees Cook
Quoted 25 lines · Gustavo A. R. Silva
Fix boot crash on Raspberry Pi by moving the update to
event->datalenbefore data is copied into flexible-array memberdataviamemcpy().Flexible-array member
datawas annotated with__counted_by(datalen)in commit62d19b358088("wifi: brcmfmac: fweh: Add__counted_byfor structbrcmf_fweh_queue_itemand usestruct_size()"). The intention of this is to gain visibility into the size ofdataat run-time through its _counter_ (in this casedatalen), and with this have its accesses bounds-checked at run-time viaCONFIG_FORTIFY_SOURCEandCONFIG_UBSAN_BOUNDS.To effectively accomplish the above, we shall update the counter (
datalen), before the first access to the flexible array (data), which was also done in the mentioned commit.However, commit
edec42821911("wifi: brcmfmac: allow per-vendor event handling") inadvertently caused a buffer overflow, detected byFORTIFY_SOURCE. It moved theevent->datalen = datalen;update to after the firstdataaccess, at which pointevent->datalenwas not yet updated from zero (after callingkzalloc()), leading to the overflow issue.This fix repositions the
event->datalen = datalen;update before accessingdata, restoring the intended buffer overflow protection. :)
Quoted 6 lines
Fixes edec42821911 ("wifi: brcmfmac: allow per-vendor event handling")Reported-by Nathan Chancellor <[email protected]>Tested-by Nathan Chancellor <[email protected]>Signed-off-by Gustavo A. R. Silva <[email protected]>Reviewed-by Kees Cook <[email protected]>
Arend, ack?
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/Zc+3PFCUvLoVlpg8@neat/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Quoted 27 lines · Kalle Valo
Quoted 25 lines · Gustavo A. R. Silva
Fix boot crash on Raspberry Pi by moving the update to
event->datalenbefore data is copied into flexible-array memberdataviamemcpy().Flexible-array member
datawas annotated with__counted_by(datalen)in commit62d19b358088("wifi: brcmfmac: fweh: Add__counted_byfor structbrcmf_fweh_queue_itemand usestruct_size()"). The intention of this is to gain visibility into the size ofdataat run-time through its _counter_ (in this casedatalen), and with this have its accesses bounds-checked at run-time viaCONFIG_FORTIFY_SOURCEandCONFIG_UBSAN_BOUNDS.To effectively accomplish the above, we shall update the counter (
datalen), before the first access to the flexible array (data), which was also done in the mentioned commit.However, commit
edec42821911("wifi: brcmfmac: allow per-vendor event handling") inadvertently caused a buffer overflow, detected byFORTIFY_SOURCE. It moved theevent->datalen = datalen;update to after the firstdataaccess, at which pointevent->datalenwas not yet updated from zero (after callingkzalloc()), leading to the overflow issue.This fix repositions the
event->datalen = datalen;update before accessingdata, restoring the intended buffer overflow protection. :)
Quoted 8 lines
Quoted 6 lines
Fixes edec42821911 ("wifi: brcmfmac: allow per-vendor event handling")Reported-by Nathan Chancellor <[email protected]>Tested-by Nathan Chancellor <[email protected]>Signed-off-by Gustavo A. R. Silva <[email protected]>Reviewed-by Kees Cook <[email protected]>Arend, ack?
Figured Kees Cook was the trumping authority here, but here it is:
Gr. AvS
Quoted 25 lines · Gustavo A. R. Silva
Fix boot crash on Raspberry Pi by moving the update to
event->datalenbefore data is copied into flexible-array memberdataviamemcpy().Flexible-array member
datawas annotated with__counted_by(datalen)in commit62d19b358088("wifi: brcmfmac: fweh: Add__counted_byfor structbrcmf_fweh_queue_itemand usestruct_size()"). The intention of this is to gain visibility into the size ofdataat run-time through its _counter_ (in this casedatalen), and with this have its accesses bounds-checked at run-time viaCONFIG_FORTIFY_SOURCEandCONFIG_UBSAN_BOUNDS.To effectively accomplish the above, we shall update the counter (
datalen), before the first access to the flexible array (data), which was also done in the mentioned commit.However, commit
edec42821911("wifi: brcmfmac: allow per-vendor event handling") inadvertently caused a buffer overflow, detected byFORTIFY_SOURCE. It moved theevent->datalen = datalen;update to after the firstdataaccess, at which pointevent->datalenwas not yet updated from zero (after callingkzalloc()), leading to the overflow issue.This fix repositions the
event->datalen = datalen;update before accessingdata, restoring the intended buffer overflow protection. :)
Quoted 7 lines
Fixes edec42821911 ("wifi: brcmfmac: allow per-vendor event handling")Reported-by Nathan Chancellor <[email protected]>Tested-by Nathan Chancellor <[email protected]>Signed-off-by Gustavo A. R. Silva <[email protected]>Reviewed-by Kees Cook <[email protected]>Acked-by Arend van Spriel <[email protected]>
Patch applied to wireless-next.git, thanks.
ec1aae190c77 wifi: brcmfmac: fweh: Fix boot crash on Raspberry Pi 4
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/Zc+3PFCUvLoVlpg8@neat/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches