The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: syzbot <syzbot+56962eb32ba0136cd330@syzkaller.appspotmail.com>
Cc: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Re: Forwarded: [PATCH] usb: misc: uss720: fix memory leak by replacing usb_unlink_urb with usb_kill_urb
Date: Thu, 16 Jul 2026 14:06:32 +0100	[thread overview]
Message-ID: <20260716140632.0a9249fe@pumpkin> (raw)
In-Reply-To: <6a58c9f2.577457d1.8bd2.0021.GAE@google.com>

On Thu, 16 Jul 2026 05:09:22 -0700
syzbot <syzbot+56962eb32ba0136cd330@syzkaller.appspotmail.com> wrote:

> For archival purposes, forwarding an incoming command email to
> linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
> 
> ***
> 
> Subject: [PATCH] usb: misc: uss720: fix memory leak by replacing usb_unlink_urb with usb_kill_urb
> Author: kartikey406@gmail.com
> 
> #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> 
> 
> kmemleak reported memory leaks in uss720_probe() during device
> initialization. The leaks occur because kill_all_async_requests_priv()
> was using usb_unlink_urb() which is asynchronous and returns immediately
> without waiting for the URB completion callbacks to finish.
> 
> This caused a race condition where kref_put() in the probe_abort path
> would run before async_complete() had a chance to call destroy_async(),
> leaving the URB, request struct (uss720_async_request), and transfer
> buffer (dr) unreferenced and leaked.
> 
> Fix this by replacing usb_unlink_urb() with usb_kill_urb() which blocks
> until the completion callback has finished, ensuring destroy_async()
> runs and frees all associated memory before kref_put() is called on
> priv.
> 
> Since usb_kill_urb() may sleep, it cannot be called while holding a
> spinlock. Drop and reacquire the spinlock around each usb_kill_urb()
> call. Also switch to list_for_each_entry_safe() to safely handle list
> modification during iteration, as destroy_async() calls list_del_init()
> on the current entry.
> 
> Reported-by: syzbot+56962eb32ba0136cd330@syzkaller.appspotmail.com
> Closes: http://syzkaller.appspot.com/bug?extid=56962eb32ba0136cd330
> Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
> ---
>  drivers/usb/misc/uss720.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/misc/uss720.c b/drivers/usb/misc/uss720.c
> index 1ce48f5832d7..f43fbb28044b 100644
> --- a/drivers/usb/misc/uss720.c
> +++ b/drivers/usb/misc/uss720.c
> @@ -175,13 +175,15 @@ static struct uss720_async_request *submit_async_request(struct parport_uss720_p
>  
>  static unsigned int kill_all_async_requests_priv(struct parport_uss720_private *priv)
>  {
> -	struct uss720_async_request *rq;
> +	struct uss720_async_request *rq, *tmp;
>  	unsigned long flags;
>  	unsigned int ret = 0;
>  
>  	spin_lock_irqsave(&priv->asynclock, flags);
> -	list_for_each_entry(rq, &priv->asynclist, asynclist) {
> -		usb_unlink_urb(rq->urb);
> +	list_for_each_entry_safe(rq, tmp, &priv->asynclist, asynclist) {
> +		spin_unlock_irqrestore(&priv->asynclock, flags);
> +		usb_kill_urb(rq->urb);
> +		spin_lock_irqsave(&priv->asynclock, flags);

I'll take a bet on that not being correct.
The _safe() only lets you remove the current item.
So if the list can be changed by someone else it doesn't help.
Possibly this is tidy up code and the lock just isn't needed?
Maybe the head of the list should be removed under the lock?
(and the rest of the tidy up done at the same time.)

	David

>  		ret++;
>  	}
>  	spin_unlock_irqrestore(&priv->asynclock, flags);


      reply	other threads:[~2026-07-16 13:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16  7:50 [syzbot] [usb?] memory leak in uss720_probe syzbot
2026-07-16 11:38 ` Forwarded: [PATCH] Fix leak in get_1284_register reported by syzbot syzbot
2026-07-16 12:09 ` Forwarded: [PATCH] usb: misc: uss720: fix memory leak by replacing usb_unlink_urb with usb_kill_urb syzbot
2026-07-16 13:06   ` David Laight [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=20260716140632.0a9249fe@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+56962eb32ba0136cd330@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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