From: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Aldo Ariel Panzardo <qwe.aldo@gmail.com>,
Guangshuo Li <lgs201920130244@gmail.com>
Subject: [PATCH] usb: gadget: ncm: validate NDP length against the NTB
Date: Tue, 15 Sep 2026 01:11:42 -0300 [thread overview]
Message-ID: <20260915041142.2430163-1-qwe.aldo@gmail.com> (raw)
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 <lgs201920130244@gmail.com>
Link: https://lore.kernel.org/r/20260708123048.760209-1-lgs201920130244@gmail.com
Cc: stable@vger.kernel.org
Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
---
drivers/usb/gadget/function/f_ncm.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c
index 64eabda2f..1ff05eb0f 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -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;
--
2.43.0
reply other threads:[~2026-09-15 4:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260915041142.2430163-1-qwe.aldo@gmail.com \
--to=qwe.aldo@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=lgs201920130244@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®