Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH v4 2/2] wifi: rtw89: fix u32 overflow in board element seek
@ 2026-11-23 18:23 Falconet3
  2026-11-27  6:47 ` Ping-Ke Shih
  0 siblings, 1 reply; 2+ messages in thread
From: Falconet3 @ 2026-11-23 18:23 UTC (permalink / raw)
  To: linux-wireless@vger.kernel.org; +Cc: pkshih@realtek.com

rtw89_board_elm_seek() validates the selected entry against the board
element file with

	if (unlikely(board_elm->size < ofst + size))

where ofst and size are u32 values read from the file. The addition
wraps in u32, so a crafted file with, for example,
ofst = 0xffffff00 and size = 0x200 passes the check and
pseudo_fw->data is set to board_elm->data + 0xffffff00 with
pseudo_fw->size = 0x200. The element walk then dereferences that
pointer and reads out of bounds.

Use remainder arithmetic against board_elm->size, which cannot wrap on
any architecture. The helper is new in v7.4-rc1, so only the current
cycle is affected.

Fixes: af5905e22a43 ("wifi: rtw89: support variants of FW elements")
Assisted-by: LLM Mistral Vibe
Signed-off-by: Falconet3 <Falconet3@proton.me>
---
v4: resend as a new thread at the maintainer's request; no code change
    since v3.
v3: resend of the series with the correct subjects and version label; no
    code change since v2.
v2: new. Found while fixing the element walk bounds check; split out as
    an independent caller. Compile- and sparse-tested on x86_64; no
    reproducer available.

 drivers/net/wireless/realtek/rtw89/fw.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c
--- a/drivers/net/wireless/realtek/rtw89/fw.c
+++ b/drivers/net/wireless/realtek/rtw89/fw.c
@@ -1739,7 +1739,8 @@
 	ofst = le32_to_cpu(ent->ofst);
 	size = le32_to_cpu(ent->size);
 
-	if (unlikely(board_elm->size < ofst + size))
+	if (unlikely(ofst > board_elm->size ||
+		     size > board_elm->size - ofst))
 		return -EFAULT;
 
 	memset(pseudo_fw, 0, sizeof(*pseudo_fw));
-- 
2.53.0

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

* RE: [PATCH v4 2/2] wifi: rtw89: fix u32 overflow in board element seek
  2026-11-23 18:23 [PATCH v4 2/2] wifi: rtw89: fix u32 overflow in board element seek Falconet3
@ 2026-11-27  6:47 ` Ping-Ke Shih
  0 siblings, 0 replies; 2+ messages in thread
From: Ping-Ke Shih @ 2026-11-27  6:47 UTC (permalink / raw)
  To: Falconet3, linux-wireless@vger.kernel.org

Falconet3 <Falconet3@proton.me> wrote:
> rtw89_board_elm_seek() validates the selected entry against the board
> element file with
> 
>         if (unlikely(board_elm->size < ofst + size))
> 
> where ofst and size are u32 values read from the file. The addition
> wraps in u32, so a crafted file with, for example,
> ofst = 0xffffff00 and size = 0x200 passes the check and
> pseudo_fw->data is set to board_elm->data + 0xffffff00 with
> pseudo_fw->size = 0x200. The element walk then dereferences that
> pointer and reads out of bounds.
> 
> Use remainder arithmetic against board_elm->size, which cannot wrap on
> any architecture. The helper is new in v7.4-rc1, so only the current
> cycle is affected.

The same comment as patch 1/2.

> 
> Fixes: af5905e22a43 ("wifi: rtw89: support variants of FW elements")
> Assisted-by: LLM Mistral Vibe
> Signed-off-by: Falconet3 <Falconet3@proton.me>
> ---
> v4: resend as a new thread at the maintainer's request; no code change
>     since v3.
> v3: resend of the series with the correct subjects and version label; no
>     code change since v2.
> v2: new. Found while fixing the element walk bounds check; split out as
>     an independent caller. Compile- and sparse-tested on x86_64; no
>     reproducer available.
> 
>  drivers/net/wireless/realtek/rtw89/fw.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c
> --- a/drivers/net/wireless/realtek/rtw89/fw.c
> +++ b/drivers/net/wireless/realtek/rtw89/fw.c
> @@ -1739,7 +1739,8 @@
>         ofst = le32_to_cpu(ent->ofst);
>         size = le32_to_cpu(ent->size);
> 
> -       if (unlikely(board_elm->size < ofst + size))
> +       if (unlikely(ofst > board_elm->size ||
> +                    size > board_elm->size - ofst))

The same comment as patch 1/2.

>                 return -EFAULT;
> 
>         memset(pseudo_fw, 0, sizeof(*pseudo_fw));

pw-bot: cr


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

end of thread, other threads:[~2026-11-27  6:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 18:23 [PATCH v4 2/2] wifi: rtw89: fix u32 overflow in board element seek Falconet3
2026-11-27  6:47 ` Ping-Ke Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox