Re: [PATCH v2] rtl8187: Fix potential buffer underflow in rtl8187_rx_cb()

From: Markus Elfring
Date: Mon Nov 17 2025 - 13:56:10 EST



> +++ b/drivers/net/wireless/realtek/rtl818x/rtl8187/dev.c
> @@ -344,8 +344,13 @@ static void rtl8187_rx_cb(struct urb *urb)
> }
>
> if (!priv->is_rtl8187b) {
> - struct rtl8187_rx_hdr *hdr =
> - (typeof(hdr))(skb_tail_pointer(skb) - sizeof(*hdr));
> + struct rtl8187_rx_hdr *hdr;
> +
> + if (skb->len < sizeof(struct rtl8187_rx_hdr)) {
> + dev_kfree_skb_irq(skb);
> + return;
> + }


You may avoid duplicate exception handling code by using a corresponding goto statement.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.18-rc5#n526

Regards,
Markus