* [PATCH] usb: gadget: f_ncm: Use unsigned int for ndp_index
@ 2026-07-20 16:56 Sonali Pradhan
0 siblings, 0 replies; only message in thread
From: Sonali Pradhan @ 2026-07-20 16:56 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Kuen-Han Tsai, Kees Cook, raub camaioni, Jim Baxter,
Felipe Balbi, linux-usb, linux-kernel, Sonali Pradhan, stable
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@vger.kernel.org
Signed-off-by: Sonali Pradhan <sonalipradhan@google.com>
---
drivers/usb/gadget/function/f_ncm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c
index 64eabda2f546..bf02545b37a2 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -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;
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-20 16:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-20 16:56 [PATCH] usb: gadget: f_ncm: Use unsigned int for ndp_index Sonali Pradhan
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®