All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Slawomir Stepien <sst@poczta.fm>
Cc: jiashengjiangcool@gmail.com, yun.zhou@windriver.com,
	zzzccc427@gmail.com, bigeasy@linutronix.de, nab@linux-iscsi.org,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+2799146a53c356f8017d@syzkaller.appspotmail.com,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 3/3] usb: gadget: f_tcm: take the TPG in tcm_bind() instead of tcm_alloc()
Date: Thu, 3 Dec 2026 22:00:24 +0100	[thread overview]
Message-ID: <2026120307-debatable-unburned-a562@gregkh> (raw)
In-Reply-To: <20261123142513.204652-4-sst@poczta.fm>

On Mon, Nov 23, 2026 at 03:25:13PM +0100, Slawomir Stepien wrote:
> tcm_alloc() runs when a TCM function is symlinked into a gadget
> configuration. It searches tpg_instances[] for the function instance
> and copies the TPG pointer into fu->tpg at that point, under
> tpg_instances_lock, and fu->tpg is never updated afterwards.
> 
> The function and the TPG can be set up in either order. If the
> function is linked into a configuration before the TPG directory is
> created, fu->tpg stays NULL. Creating and enabling the TPG afterwards
> lets tcm_bind() succeed, and the first USB request that reaches the
> target code dereferences the NULL fu->tpg. Likewise, if the TPG is
> removed (the previous patch detaches the gadget first) and a new one
> is created and enabled, the next bind keeps using the freed TPG.
> 
> Store the TPG in struct f_tcm_opts instead: set it in usbg_make_tpg(),
> clear it in usbg_drop_tpg() and copy it into fu->tpg in tcm_bind().
> opts->tpg cannot change while the function is bound: tcm_bind() only
> runs for an enabled TPG, and usbg_drop_tpg() detaches the gadget before
> clearing it. No extra locking or reference counting is needed.
> 
> With fu->tpg no longer set in tcm_alloc(), the tpg_instances[] lookup
> there serves no purpose: f->fi already identifies the instance for the
> item's whole lifetime. Drop it, and with it the tpg_instances_lock
> acquisition. config_usb_cfg_link() calls tcm_alloc() with gi->lock
> held, so this also removes the gi->lock -> tpg_instances_lock edge
> from the following lockdep report:
> 
>   WARNING: possible circular locking dependency detected
>   task is trying to acquire lock:
>    (tpg_instances_lock){+.+.}-{4:4}, at: tcm_alloc
>   but task is already holding lock:
>    (&gi->lock){+.+.}-{4:4}, at: config_usb_cfg_link
> 
>   the existing dependency chain (in reverse order) is:
>   -> #2 (&gi->lock):
>          config_usb_cfg_link
>          configfs_symlink
>   -> #1 (&sb->s_type->i_mutex_key#24):
>          configfs_depend_item_unlocked
>          usbg_make_tpg
>          target_fabric_make_tpg
>          configfs_mkdir
>   -> #0 (tpg_instances_lock):
>          tcm_alloc
>          usb_get_function
>          config_usb_cfg_link
>          configfs_symlink
> 
> Fixes: 4bb8548df632 ("usb: gadget: f_tcm: add configfs support")
> Cc: stable@vger.kernel.org
> Reported-by: syzbot+2799146a53c356f8017d@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=2799146a53c356f8017d
> Link: https://syzkaller.appspot.com/ai_job?id=51e1f189-6d91-4321-a6ba-07d4eb3cd8cd
> Signed-off-by: Slawomir Stepien <sst@poczta.fm>
> ---
>  drivers/usb/gadget/function/f_tcm.c | 23 ++++++++---------------
>  drivers/usb/gadget/function/u_tcm.h |  6 ++++++
>  2 files changed, 14 insertions(+), 15 deletions(-)

This no longer applies to my usb-testing branch.  Can you rebase and
resend?

thanks,

greg k-h

  reply	other threads:[~2026-12-04  3:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 14:25 [PATCH v2 0/3] usb: gadget: f_tcm: fix TPG lifetime and lock ordering Slawomir Stepien
2026-11-23 14:25 ` [PATCH v2 1/3] usb: gadget: f_tcm: don't hold dep_lock across unregister_gadget_item() Slawomir Stepien
2026-11-23 14:25 ` [PATCH v2 2/3] usb: gadget: f_tcm: detach gadget when dropping an enabled TPG Slawomir Stepien
2026-11-23 14:25 ` [PATCH v2 3/3] usb: gadget: f_tcm: take the TPG in tcm_bind() instead of tcm_alloc() Slawomir Stepien
2026-12-03 21:00   ` Greg KH [this message]
2026-11-23 14:38 ` [PATCH v2 0/3] usb: gadget: f_tcm: fix TPG lifetime and lock ordering sashiko-bot

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=2026120307-debatable-unburned-a562@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=jiashengjiangcool@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nab@linux-iscsi.org \
    --cc=sst@poczta.fm \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+2799146a53c356f8017d@syzkaller.appspotmail.com \
    --cc=yun.zhou@windriver.com \
    --cc=zzzccc427@gmail.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 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.