From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Zhenghang Xiao <kipreyyy@gmail.com>
Cc: Paul Cercueil <paul@crapouillou.net>,
security@kernel.org, linux-usb@vger.kernel.org
Subject: Re: [PATCH usb-gadget] usb: gadget: f_fs: clear stale priv->req/ep on DMA-BUF transfer completion
Date: Fri, 10 Jul 2026 16:01:20 +0200 [thread overview]
Message-ID: <2026071030-skedaddle-camisole-6295@gregkh> (raw)
In-Reply-To: <20260523152739.66340-1-kipreyyy@gmail.com>
On Sat, May 23, 2026 at 11:27:39PM +0800, Zhenghang Xiao wrote:
> ffs_epfile_dmabuf_io_complete() frees the usb_request via
> usb_ep_free_request() but never clears priv->req or priv->ep. When the
> host later triggers endpoint disable (via SET_INTERFACE, disconnect, or
> gadget unbind), the completion fires and frees req, leaving priv->req as
> a dangling pointer. A subsequent close() or FUNCTIONFS_DMABUF_DETACH
> ioctl then passes the stale pointer to usb_ep_dequeue(), resulting in a
> use-after-free on the freed kmalloc-128 object.
>
> Walk back from req->context to the ffs_dma_fence and its priv, then
> clear priv->req and priv->ep before freeing the request. The cleanup
> paths in ffs_epfile_release() and ffs_dmabuf_detach() already check for
> NULL under eps_lock before calling usb_ep_dequeue().
>
> Fixes: 7b07a2a7ca02 ("usb: gadget: functionfs: Add DMABUF import interface")
> Signed-off-by: Zhenghang Xiao <kipreyyy@gmail.com>
> ---
> drivers/usb/gadget/function/f_fs.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 002c3441bea3..88d3e89c21b7 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -1413,8 +1413,13 @@ static void ffs_dmabuf_signal_done(struct ffs_dma_fence *dma_fence, int ret)
> static void ffs_epfile_dmabuf_io_complete(struct usb_ep *ep,
> struct usb_request *req)
> {
> + struct ffs_dma_fence *fence = req->context;
> + struct ffs_dmabuf_priv *priv = fence->priv;
> +
> pr_vdebug("FFS: DMABUF transfer complete, status=%d\n", req->status);
> - ffs_dmabuf_signal_done(req->context, req->status);
> + ffs_dmabuf_signal_done(fence, req->status);
> + priv->req = NULL;
> + priv->ep = NULL;
> usb_ep_free_request(ep, req);
> }
>
> --
> 2.50.1 (Apple Git-155)
>
>
Does not apply to the latest usb-linus tree, are you sure this is still
an issue on the latest release?
thanks,
greg k-h
prev parent reply other threads:[~2026-07-10 14:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-23 15:27 [PATCH usb-gadget] usb: gadget: f_fs: clear stale priv->req/ep on DMA-BUF transfer completion Zhenghang Xiao
2026-07-10 14:01 ` Greg Kroah-Hartman [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=2026071030-skedaddle-camisole-6295@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=kipreyyy@gmail.com \
--cc=linux-usb@vger.kernel.org \
--cc=paul@crapouillou.net \
--cc=security@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