Skip to contentSkip to conversation

wifi: carl9170: reject mismatched command response lengths

PATCH In review Yousef Alhouseen 2 participants 3 messages Jun 28 – Jul 6

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: carl9170: reject mismatched command response lengths

The firmware response length is controlled by the USB device. Although carl9170_cmd_callback() detects when it differs from the output buffer length, the function falls through and copies the entire response into that buffer. Callers commonly provide stack objects, so a malformed response can overwrite the kernel stack.

Return after scheduling device recovery. This also preserves the stated behavior of leaving the command incomplete so that its waiter times out and clears the pending output buffer.

Fixes a84fab3cbfdc ("carl9170: 802.11 rx/tx processing and usb backend")
Reported-by [email protected]
---
 drivers/net/wireless/ath/carl9170/rx.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/wireless/ath/carl9170/rx.c +1 -0
index 6833430130f4..ea3f435fb64c 100644
@@ -145,6 +145,7 @@ 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);
Signature · 1 line
2.54.0
#1 lore raw

Hi,

Quoted 10 lines · Yousef Alhouseen

The firmware response length is controlled by the USB device. Although carl9170_cmd_callback() detects when it differs from the output buffer length, the function falls through and copies the entire response into that buffer. Callers commonly provide stack objects, so a malformed response can overwrite the kernel stack.

Return after scheduling device recovery. This also preserves the stated behavior of leaving the command incomplete so that its waiter times out and clears the pending output buffer.

Quoted 5 lines
Fixes a84fab3cbfdc ("carl9170: 802.11 rx/tx processing and usb backend")
Reported-by [email protected]

This was posted earlier too:
https://lore.kernel.org/linux-wireless/[email protected]/

In fact, there was even a mail before that that was sent to [email protected]. I told Tristan that I would much rather not return and instead fix the memcpy. carl9170_restart can completely unbind the device, so it's unlikely that one would see a timeout.

Cheers,
Christian

Quoted 16 lines
---
  drivers/net/wireless/ath/carl9170/rx.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/wireless/ath/carl9170/rx.c +1 -0
index 6833430130f4..ea3f435fb64c 100644
@@ -145,6 +145,7 @@ 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);
#2 lore raw

Hi Christian,

Thanks for pointing out Tristan's earlier patch and the prior security discussion. I had not found that submission before sending mine.

I agree that returning after carl9170_restart() is not the right fix if the restart can unbind the device, and that the copy itself should be bounded instead. Please drop my patch; I will defer to the existing discussion and will not send a v2.

Thanks,
Yousef

Quoted 46 lines · Christian Lamparter

Hi,

Quoted 10 lines · Yousef Alhouseen

The firmware response length is controlled by the USB device. Although carl9170_cmd_callback() detects when it differs from the output buffer length, the function falls through and copies the entire response into that buffer. Callers commonly provide stack objects, so a malformed response can overwrite the kernel stack.

Return after scheduling device recovery. This also preserves the stated behavior of leaving the command incomplete so that its waiter times out and clears the pending output buffer.

Quoted 5 lines
Fixes a84fab3cbfdc ("carl9170: 802.11 rx/tx processing and usb backend")
Reported-by [email protected]

This was posted earlier too:
https://lore.kernel.org/linux-wireless/[email protected]/

In fact, there was even a mail before that that was sent to [email protected]. I told Tristan that I would much rather not return and instead fix the memcpy. carl9170_restart can completely unbind the device, so it's unlikely that one would see a timeout.

Cheers,
Christian

Quoted 16 lines

---
drivers/net/wireless/ath/carl9170/rx.c | 1 +

1 file changed, 1 insertion(+)
drivers/net/wireless/ath/carl9170/rx.c +1 -0
index 6833430130f4..ea3f435fb64c 100644
@@ -145,6 +145,7 @@ 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);