From: Szymon Heidrich <szymon.heidrich@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>
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: Thu, 16 Mar 2023 12:13:56 +0100 [thread overview]
Message-ID: <9e84b812-d32d-14fc-d2ae-0c8e82d6cdc5@gmail.com> (raw)
In-Reply-To: <20230315212425.12cb48ca@kernel.org>
On 16/03/2023 05:24, Jakub Kicinski wrote:
> 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;
>
Thank you very much for you suggestions Kuba, I provided an updated patch for
smsc95xx and a new patch addressing smsc75xx. Please let me know in case additional
amendments are required.
prev parent reply other threads:[~2023-03-16 11:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-13 22:01 Szymon Heidrich
2023-03-16 4:24 ` Jakub Kicinski
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 ` Szymon Heidrich [this message]
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=9e84b812-d32d-14fc-d2ae-0c8e82d6cdc5@gmail.com \
--to=szymon.heidrich@gmail.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--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 \
/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
all inboxes | Powered by JetHome®