CDC-NCM: avoid overflow in sanity checking
Subsystems (5)
PATCH 1/1 CDC-NCM: avoid overflow in sanity checking
A broken device may give an extreme offset like 0xFFF0 and a reasonable length for a fragment. In the sanity check as formulated now, this will create an integer overflow, defeating the sanity check. Both offset and offset + len need to be checked in such a manner that no overflow can occur.
And those quantities should be unsigned.
--- drivers/net/usb/cdc_ncm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/usb/cdc_ncm.c +4 -4
@@ -1715,10 +1715,10 @@ int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in) {struct sk_buff *skb;struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0 ]; -int len; +unsigned int len;int nframes;int x; -int offset; +unsigned int offset;union {struct usb_cdc_ncm_ndp16 *ndp16;struct usb_cdc_ncm_ndp32 *ndp32;
@@ -1790,8 +1790,8 @@ int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)break ; } -/* sanity checking */ -if (((offset + len) > skb_in->len) || +/* sanity checking - watch out for integer wrap*/ +if ((offset > skb_in->len) || (len > skb_in->len - offset) || (len > ctx->rx_max) || (len <ETH_HLEN )) { netif_dbg(dev, rx_err, dev->net, "invalid frame detected (ignored) offset[%u]=%u, length=%u, skb=%p\n",
Signature · 1 line
2.34.1
Quoted 44 lines · Oliver Neukum
A broken device may give an extreme offset like
0xFFF0and a reasonable length for a fragment. In the sanity check as formulated now, this will create an integer overflow, defeating the sanity check. Both offset and offset + len need to be checked in such a manner that no overflow can occur.
And those quantities should be unsigned.Signed-off-by Oliver Neukum <[email protected]>--- drivers/net/usb/cdc_ncm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/net/usb/cdc_ncm.c +4
-4@@ -1715,10 +1715,10 @@ int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in) {struct sk_buff *skb;struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0 ]; -int len; +unsigned int len;int nframes;int x; -int offset; +unsigned int offset;union {struct usb_cdc_ncm_ndp16 *ndp16;struct usb_cdc_ncm_ndp32 *ndp32;@@ -1790,8 +1790,8 @@ int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)break ; } -/* sanity checking */ -if (((offset + len) > skb_in->len) || +/* sanity checking - watch out for integer wrap*/ +if ((offset > skb_in->len) || (len > skb_in->len - offset) || (len > ctx->rx_max) || (len <ETH_HLEN )) { netif_dbg(dev, rx_err, dev->net, "invalid frame detected (ignored) offset[%u]=%u, length=%u, skb=%p\n",Signature · 1 line
2.34.1
This patch was applied to netdev/net.git (master) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <[email protected]>:
Quoted 9 lines · On Tue, 15 Feb 2022 11:35:47 +0100 you wrote:
A broken device may give an extreme offset like
0xFFF0and a reasonable length for a fragment. In the sanity check as formulated now, this will create an integer overflow, defeating the sanity check. Both offset and offset + len need to be checked in such a manner that no overflow can occur.
And those quantities should be unsigned.[...]
Here is the summary with links:
- CDC-NCM: avoid overflow in sanity checking
https://git.kernel.org/netdev/net/c/8d2b1a1ec9f5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html