]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
usb: gadget: f_ncm: Use unsigned int for ndp_index
authorSonali Pradhan <sonalipradhan@google.com>
Mon, 20 Jul 2026 16:56:54 +0000 (16:56 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 3 Aug 2026 15:23:51 +0000 (17:23 +0200)
The variable ndp_index is declared as a signed integer, but it stores
the return value of get_ncm(), which is unsigned.

A malicious host can supply a large offset that overflows the signed
ndp_index, making it negative. Because ndp_index is compared against
unsigned bounds, this negative value bypasses sanity checks and leads
to an out-of-bounds read when calculating the address of the NDP
block (ntb_ptr + ndp_index).

Fix this by changing ndp_index to unsigned int to ensure consistent
unsigned comparisons throughout the function.

Fixes: 370af734dfaf ("usb: gadget: NCM: RX function support multiple NDPs")
Cc: stable <stable@kernel.org>
Signed-off-by: Sonali Pradhan <sonalipradhan@google.com>
Link: https://patch.msgid.link/20260720165654.2224591-1-sonalipradhan@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/f_ncm.c

index 64eabda2f54696248785189182ea61aefcca28c1..bf02545b37a22b0008783199f2cd046d509acbea 100644 (file)
@@ -1171,7 +1171,7 @@ static int ncm_unwrap_ntb(struct gether *port,
        unsigned char   *ntb_ptr = skb->data;
        __le16          *tmp;
        unsigned        index, index2;
-       int             ndp_index;
+       unsigned int    ndp_index;
        unsigned        dg_len, dg_len2;
        unsigned        ndp_len;
        unsigned        block_len;