From: sashiko-bot@kernel.org
To: "Sebastian Andrzej Siewior" <bigeasy@linutronix.de>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH REPOST] usb: udc: Make tracing aware that usb_ep_alloc_request() can return NULL
Date: Mon, 12 Oct 2026 10:00:22 +0000 [thread overview]
Message-ID: <sashiko-outbox-167925@kernel.org> (raw)
In-Reply-To: <20261012094911.wHPc_9lJ@linutronix.de>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] usb: use-after-free in usb_ep_queue() and usb_ep_dequeue() tracepoints
--
commit 1373e903abc2252ba5340f5231a6fb6306db9019
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
usb: udc: Make tracing aware that usb_ep_alloc_request() can return NULL
This commit updates the udc_log_req trace event class to handle NULL
request pointers by checking the pointer before accessing its fields. This
prevents a NULL pointer dereference when usb_ep_alloc_request() fails and
returns NULL.
Link: https://lore.kernel.org/all/6aab0160.e91c2013.3bdb06.0005.GAE@google.com/
> diff --git a/drivers/usb/gadget/udc/trace.h b/drivers/usb/gadget/udc/trace.h
> index fa3e6ddf0a128..05533eb1bae0c 100644
> --- a/drivers/usb/gadget/udc/trace.h
> +++ b/drivers/usb/gadget/udc/trace.h
> @@ -239,15 +239,15 @@ DECLARE_EVENT_CLASS(udc_log_req,
> ),
> TP_fast_assign(
> __assign_str(name);
> - __entry->length = req->length;
> - __entry->actual = req->actual;
> - __entry->num_sgs = req->num_sgs;
> - __entry->num_mapped_sgs = req->num_mapped_sgs;
> - __entry->stream_id = req->stream_id;
> - __entry->no_interrupt = req->no_interrupt;
> - __entry->zero = req->zero;
> - __entry->short_not_ok = req->short_not_ok;
> - __entry->status = req->status;
> + __entry->length = req ? req->length : 0;
> + __entry->actual = req ? req->actual : 0;
[Severity: High]
While this successfully avoids a dereference when req is NULL, does this
still leave a use-after-free when tracing usb_ep_queue() or
usb_ep_dequeue()?
If a gadget driver submits a request via usb_ep_queue(), the UDC driver can
complete it synchronously and return ownership to the gadget driver. For
instance, in dummy_queue():
usb_gadget_giveback_request(_ep, _req);
If the gadget driver's completion handler then frees the request, control
eventually returns to usb_ep_queue() which invokes the tracepoint:
ret = ep->ops->queue(ep, req, gfp_flags);
out:
trace_usb_ep_queue(ep, req, ret);
Since trace_usb_ep_queue() shares this udc_log_req event class, won't req
point to freed memory, causing a use-after-free when evaluating
req->length? A similar scenario can occur in usb_ep_dequeue().
> + __entry->num_sgs = req ? req->num_sgs : 0;
> + __entry->num_mapped_sgs = req ? req->num_mapped_sgs : 0;
> + __entry->stream_id = req ? req->stream_id : 0;
> + __entry->no_interrupt = req ? req->no_interrupt : 0;
> + __entry->zero = req ? req->zero : 0;
> + __entry->short_not_ok = req ? req->short_not_ok : 0;
> + __entry->status = req ? req->status : 0;
> __entry->ret = ret;
> __entry->req = req;
> ),
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261012094911.wHPc_9lJ@linutronix.de?part=1
next prev parent reply other threads:[~2026-10-12 10:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 9:49 [PATCH REPOST] usb: udc: Make tracing aware that usb_ep_alloc_request() can return NULL Sebastian Andrzej Siewior
2026-10-12 10:00 ` sashiko-bot [this message]
2026-10-12 11:26 ` Greg KH
2026-10-12 16:29 ` Sebastian Andrzej Siewior
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=sashiko-outbox-167925@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.