linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ath9k: fix OOB read ar9300_eeprom_restore_internal
@ 2021-06-19 13:29 Zekun Shen
  2021-08-29  7:12 ` Kalle Valo
  0 siblings, 1 reply; 3+ messages in thread
From: Zekun Shen @ 2021-06-19 13:29 UTC (permalink / raw)
  To: bruceshenzk
  Cc: linux-wireless, ath9k-devel, Kalle Valo, David S. Miller, Jakub Kicinski

Bad header can have large length field which can cause OOB.
cptr is the last bytes for read, and the eeprom is parsed
from high to low address. The OOB, triggered by the condition
length > cptr could cause memory error with a read on
negative index.

There are some sanity check around length, but it is not
compared with cptr (the remaining bytes). Here, the
corrupted/bad EEPROM can cause panic.

I was able to reproduce the crash, but I cannot find the
log and the reproducer now. After I applied the patch, the
bug is no longer reproducible.

Signed-off-by: Zekun Shen <bruceshenzk@gmail.com>
---
 drivers/net/wireless/ath/ath9k/ar9003_eeprom.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
index b4885a700296..b0a4ca3559fd 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
@@ -3351,7 +3351,8 @@ static int ar9300_eeprom_restore_internal(struct ath_hw *ah,
 			"Found block at %x: code=%d ref=%d length=%d major=%d minor=%d\n",
 			cptr, code, reference, length, major, minor);
 		if ((!AR_SREV_9485(ah) && length >= 1024) ||
-		    (AR_SREV_9485(ah) && length > EEPROM_DATA_LEN_9485)) {
+		    (AR_SREV_9485(ah) && length > EEPROM_DATA_LEN_9485) ||
+		    (length > cptr)) {
 			ath_dbg(common, EEPROM, "Skipping bad header\n");
 			cptr -= COMP_HDR_LEN;
 			continue;
-- 
2.23.0.rc1


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

* Re: [PATCH] ath9k: fix OOB read ar9300_eeprom_restore_internal
  2021-06-19 13:29 [PATCH] ath9k: fix OOB read ar9300_eeprom_restore_internal Zekun Shen
@ 2021-08-29  7:12 ` Kalle Valo
  0 siblings, 0 replies; 3+ messages in thread
From: Kalle Valo @ 2021-08-29  7:12 UTC (permalink / raw)
  To: Zekun Shen
  Cc: bruceshenzk, linux-wireless, ath9k-devel, David S. Miller,
	Jakub Kicinski

Zekun Shen <bruceshenzk@gmail.com> wrote:

> Bad header can have large length field which can cause OOB.
> cptr is the last bytes for read, and the eeprom is parsed
> from high to low address. The OOB, triggered by the condition
> length > cptr could cause memory error with a read on
> negative index.
> 
> There are some sanity check around length, but it is not
> compared with cptr (the remaining bytes). Here, the
> corrupted/bad EEPROM can cause panic.
> 
> I was able to reproduce the crash, but I cannot find the
> log and the reproducer now. After I applied the patch, the
> bug is no longer reproducible.
> 
> Signed-off-by: Zekun Shen <bruceshenzk@gmail.com>
> Signed-off-by: Kalle Valo <kvalo@codeaurora.org>

Patch applied to ath-next branch of ath.git, thanks.

23151b9ae79e ath9k: fix OOB read ar9300_eeprom_restore_internal

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/YM3xKsQJ0Hw2hjrc@Zekuns-MBP-16.fios-router.home/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


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

* Re: [PATCH] ath9k: fix OOB read ar9300_eeprom_restore_internal
       [not found] <YM1ajkPk+7ve4Ls9@Zekuns-MBP-16.fios-router.home>
@ 2021-06-19  8:48 ` Kalle Valo
  0 siblings, 0 replies; 3+ messages in thread
From: Kalle Valo @ 2021-06-19  8:48 UTC (permalink / raw)
  To: Zekun Shen; +Cc: ath9k-devel, David S. Miller, Jakub Kicinski, linux-wireless

+ linux-wireless

Zekun Shen <bruceshenzk@gmail.com> writes:

> Bad header can have large length field which can cause OOB.
> cptr is the last bytes for read, and the eeprom is parsed
> from high to low address. The OOB, triggered by the condition
> length > cptr could cause memory error with a read on
> negative index.
>
> There are some sanity check around length, but it is not
> compared with cptr (the remaining bytes). Here, the
> corrupted/bad EEPROM can cause panic.
>
> I was able to reproduce the crash, but I cannot find the
> log and the reproducer now. After I applied the patch, the
> bug is no longer reproducible.
>
> Signed-off-by: Zekun Shen <bruceshenzk@gmail.com>

Please resubmit and cc linux-wireless list, otherwise patchwork won't
see the patch and then it will be out of my radar.

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

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

end of thread, other threads:[~2021-08-29  7:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-19 13:29 [PATCH] ath9k: fix OOB read ar9300_eeprom_restore_internal Zekun Shen
2021-08-29  7:12 ` Kalle Valo
     [not found] <YM1ajkPk+7ve4Ls9@Zekuns-MBP-16.fios-router.home>
2021-06-19  8:48 ` Kalle Valo

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