usb: gadget: ncm: validate NDP length against the NTB
Subsystems (2)
PATCH 1/1 usb: gadget: ncm: validate NDP length against the NTB
The NDP length is validated for its minimum size and alignment, but not against the containing NTB. A host can provide an NDP near the end of the block with an oversized length, causing the datagram parser to read beyond the block.
The NDP index has already been checked against block_len, so compare the length with the remaining bytes using an overflow-safe subtraction.
Fixes 9f6ce4240a2b ("usb: gadget: f_ncm.c added")
Reported-by Guangshuo Li <[email protected]>
Signed-off-by Aldo Ariel Panzardo <[email protected]>
--- drivers/usb/gadget/function/f_ncm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/gadget/function/f_ncm.c +2 -1
@@ -1262,7 +1262,8 @@ static int ncm_unwrap_ntb(struct gether *port,*/ if ((ndp_len < opts->ndp_size +2 *2 * (opts->dgram_item_len *2 )) || - (ndp_len % opts->ndplen_align !=0 )) { + (ndp_len % opts->ndplen_align !=0 ) || + (ndp_len > block_len - ndp_index)) {INFO (port->func.config->cdev,"Bad NDP length: %#X\n" , ndp_len); goto err;
Signature · 1 line
2.43.0