* [PATCH] net: usb: smsc95xx: Limit packet length to skb->len
@ 2023-03-13 22:01 Szymon Heidrich
2023-03-16 4:24 ` Jakub Kicinski
0 siblings, 1 reply; 6+ messages in thread
From: Szymon Heidrich @ 2023-03-13 22:01 UTC (permalink / raw)
To: steve.glendinning, UNGLinuxDriver, davem, edumazet
Cc: kuba, pabeni, szymon.heidrich, linux-usb, netdev, linux-kernel
Packet length retrieved from skb data may be larger than
the actual socket buffer length (up to 1526 bytes). In such
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)) {
netif_dbg(dev, rx_err, dev->net,
"size err header=0x%08x\n", header);
return 0;
--
2.39.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] net: usb: smsc95xx: Limit packet length to skb->len
2023-03-13 22:01 [PATCH] net: usb: smsc95xx: Limit packet length to skb->len Szymon Heidrich
@ 2023-03-16 4:24 ` Jakub Kicinski
2023-03-16 10:19 ` [PATCH v2] " Szymon Heidrich
2023-03-16 11:13 ` [PATCH] " Szymon Heidrich
0 siblings, 2 replies; 6+ messages in thread
From: Jakub Kicinski @ 2023-03-16 4:24 UTC (permalink / raw)
To: Szymon Heidrich
Cc: steve.glendinning, UNGLinuxDriver, davem, edumazet, pabeni,
linux-usb, netdev, linux-kernel
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;
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] net: usb: smsc95xx: Limit packet length to skb->len
2023-03-16 4:24 ` Jakub Kicinski
@ 2023-03-16 10:19 ` 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
1 sibling, 2 replies; 6+ messages in thread
From: Szymon Heidrich @ 2023-03-16 10:19 UTC (permalink / raw)
To: kuba, steve.glendinning, UNGLinuxDriver, davem, edumazet
Cc: pabeni, szymon.heidrich, linux-usb, netdev, linux-kernel
Packet length retrieved from descriptor may be larger than
the actual socket buffer length. In such 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>
---
V1 -> V2: Move packet length check to prevent kernel panic in skb_pull
drivers/net/usb/smsc95xx.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 32d2c60d3..563ecd27b 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -1833,6 +1833,12 @@ static int smsc95xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
size = (u16)((header & RX_STS_FL_) >> 16);
align_count = (4 - ((size + NET_IP_ALIGN) % 4)) % 4;
+ if (unlikely(size > skb->len)) {
+ netif_dbg(dev, rx_err, dev->net,
+ "size err header=0x%08x\n", header);
+ return 0;
+ }
+
if (unlikely(header & RX_STS_ES_)) {
netif_dbg(dev, rx_err, dev->net,
"Error header=0x%08x\n", header);
--
2.40.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] net: usb: smsc95xx: Limit packet length to skb->len
2023-03-16 10:19 ` [PATCH v2] " Szymon Heidrich
@ 2023-03-16 20:52 ` Jakub Kicinski
2023-03-18 5:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2023-03-16 20:52 UTC (permalink / raw)
To: Szymon Heidrich
Cc: steve.glendinning, UNGLinuxDriver, davem, edumazet, pabeni,
linux-usb, netdev, linux-kernel
On Thu, 16 Mar 2023 11:19:54 +0100 Szymon Heidrich wrote:
> Packet length retrieved from descriptor may be larger than
> the actual socket buffer length. In such 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>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] net: usb: smsc95xx: Limit packet length to skb->len
2023-03-16 10:19 ` [PATCH v2] " Szymon Heidrich
2023-03-16 20:52 ` Jakub Kicinski
@ 2023-03-18 5:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-03-18 5:10 UTC (permalink / raw)
To: Szymon Heidrich
Cc: kuba, steve.glendinning, UNGLinuxDriver, davem, edumazet, pabeni,
linux-usb, netdev, linux-kernel
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 16 Mar 2023 11:19:54 +0100 you wrote:
> Packet length retrieved from descriptor may be larger than
> the actual socket buffer length. In such 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>
>
> [...]
Here is the summary with links:
- [v2] net: usb: smsc95xx: Limit packet length to skb->len
https://git.kernel.org/netdev/net/c/ff821092cf02
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] net: usb: smsc95xx: Limit packet length to skb->len
2023-03-16 4:24 ` Jakub Kicinski
2023-03-16 10:19 ` [PATCH v2] " Szymon Heidrich
@ 2023-03-16 11:13 ` Szymon Heidrich
1 sibling, 0 replies; 6+ messages in thread
From: Szymon Heidrich @ 2023-03-16 11:13 UTC (permalink / raw)
To: Jakub Kicinski
Cc: steve.glendinning, UNGLinuxDriver, davem, edumazet, pabeni,
linux-usb, netdev, linux-kernel
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-03-18 5:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-13 22:01 [PATCH] net: usb: smsc95xx: Limit packet length to skb->len 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 ` [PATCH] " Szymon Heidrich
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.