From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796354931; b=B9p97JnyvqQuTDiKfX6s+TWeifo+EByPWHx7HhVcCxx+Fk0bOpGV+P9U23DbyodX/RJm sdJaFSk/DAMHvh7/NYwhcKwC8ULans+sVbIaMYC2484QqpVNCvoH6ahOznKU7DLKjRBgY D/2zn1QhbD7SWqTK9eRPBwqyI2S2wVl/IGYqMHASF93k5qjjoucaZPGmjKtMmJ9SU47V8 zHkrbr9tNQwUkH0zEaWO11MPqNwBzCXzweFwzfptG5tOMce8Y/xZZpgJzuq3yaBVsY8vW AvpTH3q9MO4tt74zZknJ4whcypJxDd0I36jGClJqyU+DdGZI8/8jV2D0BE7e8YZgdAQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796354931; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=ZqLdAsNbrnXRDpopsSNgNOPJVVyCcHSkkduwZPR/hwI=; b=W54Kt594+U7AC4leCdEb3d7g3RFqRSns6keCo5mpI7bhXHwxiRS+fUT+ZQugAlqSEFC9 tcp/CnJ3r4mWCyJYsOB1KeQakzPpWewbpCAgON6g19A8yAsPp6nMlEQOwLCRviq4M6/Se b/iSTgZj34H5w/HzC+7q0fBIUR5IlBrvL9pOeKpTg/6HYYiGzfD1elVHtoXYSmvPeiwhE 4ffFC7rz4JZsMPKm+AXqTbU/XN9bbssyVW2nodykTPNF11fKFHKdWn2PXW45A1nlQcyOr nWs0V/OAlkQQuQMmGYJTt9xhwBfkkhxt9w0VsbQeuQ3pl9YzCKjxThDPSVmkMp1b6YQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=fTiDkG6X; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4DA9606A322; Fri, 4 Dec 2026 03:28:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=fTiDkG6X Received: by smtp.kernel.org (Postfix) with ESMTPSA id 468CD1F0092C; Fri, 4 Dec 2026 03:28:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796354931; bh=ZqLdAsNbrnXRDpopsSNgNOPJVVyCcHSkkduwZPR/hwI=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=fTiDkG6XF6tJ71d6c/3gT89NuKikZGFElx0PgSO1mKxMAiiOCuJbNidj+yT9w3ImC 7aFjRVM4LW0BJCuCNyroZxkuho4QJJ7ObyrvlIyDOAScDrySy8t7r36/An5VdNMRFH alVnee2iAMlpXNy8hrOGPI1BGE7TD2OOOKDt7Vx4= Date: Thu, 3 Dec 2026 22:00:24 +0100 From: Greg KH To: Slawomir Stepien 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() Message-ID: <2026120307-debatable-unburned-a562@gregkh> References: <20261123142513.204652-1-sst@poczta.fm> <20261123142513.204652-4-sst@poczta.fm> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 > --- > 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