Linux USB
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org,
	syzbot <syzbot+de553c19cb054f174a35@syzkaller.appspotmail.com>,
	Felipe Balbi <felipe.balbi@linux.intel.com>
Subject: Re: [PATCH REPOST] usb: udc: Make tracing aware that usb_ep_alloc_request() can return NULL
Date: Mon, 12 Oct 2026 18:29:46 +0200	[thread overview]
Message-ID: <20261012162946.xydo0fxw@linutronix.de> (raw)
In-Reply-To: <2026101222-retention-pecan-0061@gregkh>

- Felipe (bounce)

On 2026-10-12 13:26:18 [+0200], Greg KH wrote:
> On Mon, Oct 12, 2026 at 11:49:11AM +0200, Sebastian Andrzej Siewior wrote:
> > The alloc_request callback of the EP can return NULL if it was not able
> > to allocate a request. This NULL pointer will then be dereferenced by
> > tracing in order to show details about it.
> 
> When does that happen?

In usb_ep_alloc_request() when ep->ops->alloc_request() return NULL.

> > Let tracing check the req pointer and if NULL just write 0.
> 
> Why not fix up the calling point and if req is NULL, not call the
> tracepoint as odds are something went really wrong at that point in
> time, right?

usb_ep_alloc_request() uses it as:
	trace_usb_ep_alloc_request(ep, req, req ? 0 : -ENOMEM);

so if the allocations fails the entry in the trace buffer will be 
"EPNAME: req NULL … --> -12" aka ENOMEM.
If that trace point is skipped then we have nothing.

Now sashiko pointed out that in usb_ep_queue() that request can be
completed immediately (instead queueing it) and then
usb_gadget_giveback_request() could release it before the tracepoint is
using `req'.

"Immediate" completion could happen for ep0 handling/
composite_setup_complete() but this does not do it. 
loopback_complete() does free `req' for error case (such as
-ECONNABORTED) but this should not happen on enqueue. And if it does,
that memory is still mapped but maybe with bogus content.

This makes me think that it would be better to have copy of `req' on
stack for the tracing case.

> thanks,
> 
> greg k-h

Sebastian

      reply	other threads:[~2026-10-12 16:29 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
2026-10-12 11:26 ` Greg KH
2026-10-12 16:29   ` Sebastian Andrzej Siewior [this message]

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=20261012162946.xydo0fxw@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=felipe.balbi@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=syzbot+de553c19cb054f174a35@syzkaller.appspotmail.com \
    /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