Re: [PATCH v3 2/2] wifi: rtw89: fix u32 overflow in board element offset check
From: Falconet3
Date: Sun Nov 22 2026 - 06:22:06 EST
Note: 2/2 was posted as a standalone message ("[PATCH v3 2/2] wifi: rtw89:
fix u32 overflow in board element offset check") because my webmail client
does not preserve the In-Reply-To header when the subject is edited. Both
patches are independent and apply on top of v7.4-rc3.
Sorry for the confusion,
Falconet3
Enviado com um e-mail seguro do Proton Mail.
Em domingo, 22 de novembro de 2026 às 11:07, Falconet3 <Falconet3@xxxxxxxxx> escreveu:
> 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@xxxxxxxxx>
> ---
> 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
> index 0000000..0000000 100644
> --- a/drivers/net/wireless/realtek/rtw89/fw.c
> +++ b/drivers/net/wireless/realtek/rtw89/fw.c
> @@ -1734,12 +1734,13 @@ static int rtw89_board_elm_seek(const struct firmware *board_elm,
> if (num <= board_id)
> return -ENOENT;
>
> ent = &hdr->ents[board_id];
>
> 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