Re: [RFC] CDC-NCM: avoid overflow in sanity checking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/10/22 16:54, Oliver Neukum wrote:
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. It needs to be
rewritten as a subtraction and the variables should be
unsigned.


Hi Oliver,

First of all I'd like to update:

Hans Petter Selasky <hans.petter.selasky@xxxxxxxxxxxxxx>

To:

Hans Petter Selasky <hselasky@xxxxxxxxxxx>

Secondly,

"int" variables are 32-bit, so 0xFFF0 won't overflow.

The initial driver code written by me did only support 16-bit lengths and offset. Then integer overflow is not possible.

It looks like somebody else introduced this integer overflow :-(

commit 0fa81b304a7973a499f844176ca031109487dd31
Author: Alexander Bersenev <bay@xxxxxxxxxxxx>
Date:   Fri Mar 6 01:33:16 2020 +0500

    cdc_ncm: Implement the 32-bit version of NCM Transfer Block

The NCM specification defines two formats of transfer blocks: with 16-bit fields (NTB-16) and with 32-bit fields (NTB-32). Currently only NTB-16 is
    implemented.

....

With NCM 32, both "len" and "offset" must be checked, because these are now 32-bit and stored into regular "int".

The fix you propose is not fully correct!

--HPS

Signed-off-by: Oliver Neukum <oneukum@xxxxxxxx>
---
  drivers/net/usb/cdc_ncm.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index e303b522efb5..f78fccbc4b93 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -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;
@@ -1791,7 +1791,7 @@ int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)
  		}
/* sanity checking */
-		if (((offset + len) > skb_in->len) ||
+		if ((offset > skb_in->len - len) ||
  				(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",




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux