From: Greg KH <gregkh@linuxfoundation.org>
To: Rafael Alejandro Diaz Cruz <rafad900@gmail.com>
Cc: linux-usb@vger.kernel.org, stable@vger.kernel.org,
linux-kernel@vger.kernel.org,
syzbot+4a5c87a01894ca37f25c@syzkaller.appspotmail.com,
Alan Stern <stern@rowland.harvard.edu>
Subject: Re: [PATCH usb-next v2] USB: gadget: Fix UAF on refcount inside gadgetfs_bind()
Date: Sun, 18 Oct 2026 10:19:13 +0200 [thread overview]
Message-ID: <2026101857-transform-hazelnut-4715@gregkh> (raw)
In-Reply-To: <20260905003607.1686172-1-rafad900@gmail.com>
On Fri, Sep 04, 2026 at 05:36:07PM -0700, Rafael Alejandro Diaz Cruz wrote:
> When usb_ep_alloc_request() fails, gadgetfs_bind() takes
> the following error path:
>
> if (!dev->req)
> goto enomem;
> // ...
>
> enomem:
> gadgetfs_unbind (gadget);
> return -ENOMEM;
>
> In normal case, get_dev() will be called to increment
> refcounter from gadget->dev->count but in error case,
> this increment is skipped and gadgetfs_unbind() will
> decrement it via put_dev().
>
> Going down the error path leads to a refcount imbalance
> which will cause UAF in close()/umount() operations
> due to refcount dropping below 0.
>
> Fix this by moving get_dev() above the error paths so
> that refcounter is incremented before the put_dev()
> call.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Reported-by: syzbot+4a5c87a01894ca37f25c@syzkaller.appspotmail.com
> Link: https://syzkaller.appspot.com/bug?extid=4a5c87a01894ca37f25c
> Signed-off-by: Rafael Alejandro Diaz Cruz <rafad900@gmail.com>
> Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
> ---
> Changes from v1:
> Removed syzkaller reference in description
>
> Added Reviewed-by: tag.
>
> drivers/usb/gadget/legacy/inode.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
> index 3e2bce7543d4..181b19e7fc2f 100644
> --- a/drivers/usb/gadget/legacy/inode.c
> +++ b/drivers/usb/gadget/legacy/inode.c
> @@ -1679,6 +1679,7 @@ static int gadgetfs_bind(struct usb_gadget *gadget,
> }
>
> set_gadget_data (gadget, dev);
> + get_dev(dev);
> dev->gadget = gadget;
> gadget->ep0->driver_data = dev;
>
> @@ -1696,7 +1697,6 @@ static int gadgetfs_bind(struct usb_gadget *gadget,
> spin_lock_irq(&dev->lock);
> dev->state = STATE_DEV_UNCONNECTED;
> spin_unlock_irq(&dev->lock);
> - get_dev (dev);
> return 0;
>
> enomem:
> --
> 2.43.0
>
>
I think
https://lore.kernel.org/r/20260811060810.295666-1-khiemtranzo532001@gmail.com
was send before yours.
thanks,
greg k-h
prev parent reply other threads:[~2026-10-18 8:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-05 0:36 [PATCH usb-next v2] USB: gadget: Fix UAF on refcount inside gadgetfs_bind() Rafael Alejandro Diaz Cruz
2026-10-18 8:19 ` Greg KH [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=2026101857-transform-hazelnut-4715@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=rafad900@gmail.com \
--cc=stable@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=syzbot+4a5c87a01894ca37f25c@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