wifi: carl9170: fix stack-out-of-bounds in carl9170_cmd_callback
PATCH 1/1 wifi: carl9170: fix stack-out-of-bounds in carl9170_cmd_callback
carl9170_cmd_callback() does not return after calling carl9170_restart() when an invalid command response is detected. This causes a fall-through into the memcpy block below, where ar->readbuf is written with a device-controlled length (len - 4) instead of the expected ar->readlen bytes.
A malicious or fuzzing USB device can send an oversized response (e.g. 60 bytes) causing a stack-out-of-bounds write into ar->readbuf, as detected by KASAN.
Fix this by adding a return after carl9170_restart() to match the original intent stated in the comment ("Do not complete"). Also cap the memcpy with min_t() as defense-in-depth to prevent overflow even if the control flow changes in future.
The bug has been present since the initial driver submission in 2010.
--- drivers/net/wireless/ath/carl9170/rx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/carl9170/rx.c +3 -1
@@ -145,12 +145,14 @@ static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)* and we get a stack trace from there. */ carl9170_restart (ar,CARL9170_RR_INVALID_RSP ); +return ; }spin_lock (&ar->cmd_lock);if (ar->readbuf) {if (len >=4 ) -memcpy (ar->readbuf, buffer +4 , len -4 ); +memcpy (ar->readbuf, buffer +4 , +min_t (u32, len -4 , ar->readlen)); ar->readbuf =NULL ; }
Signature · 1 line
2.43.0
Hi,
Quoted 10 lines · Deepanshu Kartikey
carl9170_cmd_callback()does not return after callingcarl9170_restart()when an invalid command response is detected. This causes a fall-through into the memcpy block below, wherear->readbufis written with a device-controlled length (len - 4) instead of the expectedar->readlenbytes.A malicious or fuzzing USB device can send an oversized response (e.g. 60 bytes) causing a stack-out-of-bounds write into
ar->readbuf, as detected by KASAN.
Quoted 6 lines
Fix this by adding a return after
carl9170_restart()to match the original intent stated in the comment ("Do not complete"). Also cap the memcpy withmin_t()as defense-in-depth to prevent overflow even if the control flow changes in future.The bug has been present since the initial driver submission in 2010.
I've seen this before in a mail from Tristan Madani (CC'd) on the 13th of April 2026. Unfortunately, he didn't post this to the linux-wireless mailing-list. Instead
he went for the Security Officers <[email protected]> , so I can't provide any link to it. That said, he since changed it because of the notes I had about the driver actually want to process further so only the memcpy that caused the overflow was modified with the same "min_t(u32, len - 4, ar->readlen)" instead of "len -4" as the length:
"[PATCH v3 1/3] wifi: carl9170: bound memcpy length in cmd callback to prevent OOB read"
https://lore.kernel.org/linux-wireless/[email protected]/
So, who should get the credit? Maybe another person will post a patch soon too? Who knows.
Note: if you used any assistents. Please also check out the (new) guide-lines:
https://docs.kernel.org/process/coding-assistants.html and give proper attributions to the used tools.
Quoted 16 lines
Fixes a84fab3cbfdc ("carl9170: 802.11 rx/tx processing and usb backend")Reported-by [email protected]Tested-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>--- drivers/net/wireless/ath/carl9170/rx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/net/wireless/ath/carl9170/rx.c +0
-0
drivers/net/wireless/ath/carl9170/rx.c static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer) · line 148
Quoted 4 lines
drivers/net/wireless/ath/carl9170/rx.c +1
-0@@ -145,12 +145,14 @@ static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)* and we get a stack trace from there. */ carl9170_restart (ar,CARL9170_RR_INVALID_RSP ); +return ;
It does happen that the driver receives garbage from the device. To remain bug-to-bug compatible with the rest of the driver should just handle it gracefully. (It's more like the comment above the carl9170_restart outdated and could be removed. Because carl9170_restart can start an async process that nukes the whole driver with a full usb_reset which will unbind the device... And if its too far gone it won't be able to rebind - then it requires the user to either physically unplugged and reinserted the wifi stick or reboot (only if it helps) or shutdown the machine)
drivers/net/wireless/ath/carl9170/rx.c static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer) · line 155
Quoted 8 lines
drivers/net/wireless/ath/carl9170/rx.c +2
-1}spin_lock (&ar->cmd_lock);if (ar->readbuf) {if (len >=4 ) -memcpy (ar->readbuf, buffer +4 , len -4 ); +memcpy (ar->readbuf, buffer +4 , +min_t (u32, len -4 , ar->readlen));
yes.
drivers/net/wireless/ath/carl9170/rx.c static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer) · line 158
Quoted 3 lines
drivers/net/wireless/ath/carl9170/rx.c +0
-0ar->readbuf =NULL ; }
Cheers,
Christian
Quoted 29 lines · Christian Lamparter
Hi,
Quoted 10 lines · Deepanshu Kartikey
carl9170_cmd_callback()does not return after callingcarl9170_restart()when an invalid command response is detected. This causes a fall-through into the memcpy block below, wherear->readbufis written with a device-controlled length (len - 4) instead of the expectedar->readlenbytes.A malicious or fuzzing USB device can send an oversized response (e.g. 60 bytes) causing a stack-out-of-bounds write into
ar->readbuf, as detected by KASAN.Quoted 6 lines
Fix this by adding a return after
carl9170_restart()to match the original intent stated in the comment ("Do not complete"). Also cap the memcpy withmin_t()as defense-in-depth to prevent overflow even if the control flow changes in future.The bug has been present since the initial driver submission in 2010.
I've seen this before in a mail from Tristan Madani (CC'd) on the 13th of April 2026. Unfortunately, he didn't post this to the linux-wireless mailing-list. Instead
he went for the Security Officers <[email protected]> , so I can't provide any link to it. That said, he since changed it because of the notes I had about the driver actually want to process further so only the memcpy that caused the overflow was modified with the same "min_t(u32, len - 4, ar->readlen)" instead of "len -4" as the length:
"[PATCH v3 1/3] wifi: carl9170: bound memcpy length in cmd callback to prevent OOB read"
Quoted 3 lines
https://lore.kernel.org/linux-wireless/[email protected]/
So, who should get the credit? Maybe another person will post a patch soon too? Who knows.
My plan is to take Tristan's series once I get ACKs. Any other contributions that conflict with his will be dropped.
/jeff