From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 770C13AFB1C; Fri, 4 Sep 2026 05:41:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788500505; cv=none; b=rjY3SotNdWLEV8VbVV4y0SoVKEdoS7kd7bcV53bgD3d0YvnqjTC0eCVsj5k0dE6hTR176KB8refMqq5cTtxBKRRGVbqdh/hpkpWFl6QHGKZ3YZ1zvv7hSSXj6H6g9iQ68f56mmx1cCEiZFjY9mtmUugwz4vofYuMG+BR7IQtoeY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788500505; c=relaxed/simple; bh=6l1VEKrZ0iCqgwu6R5jCmwCdD8NOGbuvdtgtR3pHHG8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g6Hquu89WIewfo8BG61BIdGIvXrNLBCe+j4R5yrhv5Nx1BocFIBxP05XAZT4QeolJdPFjaRF4Q2MsBhOyCXjq5rtrS8HPW/pjD/GEaNHK9k9s/V4HohrckuLpzFJ/GzsEGZ/MZqsZqrhGr+MJz/XmhnI1P/89Y4nDtY5sr+xreI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ornEqSq7; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ornEqSq7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE8B01F00A3D; Fri, 4 Sep 2026 05:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788500504; bh=szy0sA+By/vcJTp8zsqu/mz6Eqzaa7Jwx1RmeVkbQlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ornEqSq7vzLJV+ZPZCjQPDVw47YA/zl/z47DpLNME1eeswaJRVn+FkgoFtg5vKrVA 4w+t56HefZAopuG8z7/WCHnZBfcmsI0z5tF8vbuKaHpf5iuKgYiZB9fkTn9sh+kJ70 k/hDsakdBddg2D0wPuif/VivRpUIXA9CkRCWsHyc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+c9f9d646b08f3b6032fe@syzkaller.appspotmail.com, Yun Zhou Subject: [PATCH 6.18 081/552] usb: gadget: f_tcm: fix deadlock in usbg_make_tpg() Date: Fri, 4 Sep 2026 06:53:58 +0200 Message-ID: <20260904045749.703047391@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904045747.813364717@linuxfoundation.org> References: <20260904045747.813364717@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yun Zhou commit 9dbf74f4022f80f7669d2b3c22c5deb46c1b5674 upstream. usbg_make_tpg() held dep_lock while calling configfs_depend_item_unlocked(), which acquires the configfs root inode lock when operating across subsystems. This creates a circular lock dependency with configfs_rmdir(): dep_lock -> configfs root inode lock -> su_mutex -> dep_lock In usbg_make_tpg(), dep_lock only serialized the read of opts->ready, which is a monotonic flag that transitions from false to true exactly once (in tcm_set_name()) and never reverts. Remove dep_lock from usbg_make_tpg() entirely and use READ_ONCE/WRITE_ONCE to access opts->ready locklessly instead. Reported-by: syzbot+c9f9d646b08f3b6032fe@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=c9f9d646b08f3b6032fe Fixes: 4bb8548df632 ("usb: gadget: f_tcm: add configfs support") Cc: stable@vger.kernel.org Signed-off-by: Yun Zhou Link: https://patch.msgid.link/20260731081151.285599-1-yun.zhou@windriver.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_tcm.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1674,19 +1674,25 @@ static struct se_portal_group *usbg_make opts = container_of(tpg_instances[i].func_inst, struct f_tcm_opts, func_inst); - mutex_lock(&opts->dep_lock); - if (!opts->ready) - goto unlock_dep; + if (!READ_ONCE(opts->ready)) + goto unlock_inst; if (opts->has_dep) { if (!try_module_get(opts->dependent)) - goto unlock_dep; + goto unlock_inst; } else { + /* + * configfs_depend_item_unlocked() may acquire the configfs + * root inode lock when the target belongs to a different + * subsystem. Calling it under dep_lock would create a + * circular dependency: + * dep_lock -> configfs inode lock -> su_mutex -> dep_lock + */ ret = configfs_depend_item_unlocked( wwn->wwn_group.cg_subsys, &opts->func_inst.group.cg_item); if (ret) - goto unlock_dep; + goto unlock_inst; } tpg = kzalloc(sizeof(struct usbg_tpg), GFP_KERNEL); @@ -1713,7 +1719,6 @@ static struct se_portal_group *usbg_make tpg_instances[i].tpg = tpg; tpg->fi = tpg_instances[i].func_inst; - mutex_unlock(&opts->dep_lock); mutex_unlock(&tpg_instances_lock); return &tpg->se_tpg; @@ -1726,8 +1731,6 @@ unref_dep: module_put(opts->dependent); else configfs_undepend_item_unlocked(&opts->func_inst.group.cg_item); -unlock_dep: - mutex_unlock(&opts->dep_lock); unlock_inst: mutex_unlock(&tpg_instances_lock); @@ -2664,9 +2667,7 @@ static int tcm_set_name(struct usb_funct pr_debug("tcm: Activating %s\n", name); - mutex_lock(&opts->dep_lock); - opts->ready = true; - mutex_unlock(&opts->dep_lock); + WRITE_ONCE(opts->ready, true); return 0; }