linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Szymon Heidrich <szymon.heidrich@gmail.com>
Cc: steve.glendinning@shawell.net, UNGLinuxDriver@microchip.com,
	davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
	linux-usb@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: usb: smsc95xx: Limit packet length to skb->len
Date: Wed, 15 Mar 2023 21:24:25 -0700	[thread overview]
Message-ID: <20230315212425.12cb48ca@kernel.org> (raw)
In-Reply-To: <20230313220124.52437-1-szymon.heidrich@gmail.com>

On Mon, 13 Mar 2023 23:01:24 +0100 Szymon Heidrich wrote:
> Packet length retrieved from skb data may be larger than

nit: s/skb data/descriptor/ may be better in terms of terminology

> the actual socket buffer length (up to 1526 bytes). In such

nit: the "up to 1526 bytes" is a bit confusing, I'd remove it.

> case the cloned skb passed up the network stack will leak
> kernel memory contents.



> Fixes: 2f7ca802bdae ("net: Add SMSC LAN9500 USB2.0 10/100 ethernet adapter driver")
> Signed-off-by: Szymon Heidrich <szymon.heidrich@gmail.com>
> ---
>  drivers/net/usb/smsc95xx.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
> index 32d2c60d3..ba766bdb2 100644
> --- a/drivers/net/usb/smsc95xx.c
> +++ b/drivers/net/usb/smsc95xx.c
> @@ -1851,7 +1851,8 @@ static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
>  			}
>  		} else {
>  			/* ETH_FRAME_LEN + 4(CRC) + 2(COE) + 4(Vlan) */
> -			if (unlikely(size > (ETH_FRAME_LEN + 12))) {
> +			if (unlikely(size > (ETH_FRAME_LEN + 12) ||
> +				     size > skb->len)) {

We need this check on both sides of the big if {} statement.

In case the error bit is set and we drop the packet we still
end up in skb_pull() which if size > skb->len will panic the
kernel.

So let's do this check right after size and align are calculated?
The patch for smsc75xx has sadly already been applied so you'll
need to prepare a fix to the fix :(

>  				netif_dbg(dev, rx_err, dev->net,
>  					  "size err header=0x%08x\n", header);
>  				return 0;


  reply	other threads:[~2023-03-16  4:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-13 22:01 [PATCH] net: usb: smsc95xx: Limit packet length to skb->len Szymon Heidrich
2023-03-16  4:24 ` Jakub Kicinski [this message]
2023-03-16 10:19   ` [PATCH v2] " Szymon Heidrich
2023-03-16 20:52     ` Jakub Kicinski
2023-03-18  5:10     ` patchwork-bot+netdevbpf
2023-03-16 11:13   ` [PATCH] " Szymon Heidrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230315212425.12cb48ca@kernel.org \
    --to=kuba@kernel.org \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=steve.glendinning@shawell.net \
    --cc=szymon.heidrich@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).