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=1796383648; b=KQuKpaEkT93aSZ9JhLTKhDyS0n8gRHZhI+7y+Z3Oi2v/KikK9ny4soEoYJaHTgxQW03C +XmQCqq8v0qzHEEKovWyO8sn3S38kyPZ+yQvzivr6VTd+gp9jxfs2lV3XiGOMZ50Ce2D6 06cg6yEfJPUYNC5MH67zKNBI5FzHjNQMMEYFGtxD4TciqZ/mEOtlWlAawSsdYi08OXvQL zE6nXnBZYswJCKfwbyjIpnSX8266+wkc7d1k1xxm9v5lgzdCealmIthXTVUDQljYLsaR4 3phkOEvE9ZPZCMEnjyXBAqTDle2T5P6JtED8ROrFur8gUnSxFZJf4aWXHJ+rsv4TeTg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383648; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=HILSAc9J9R1C01S081FJrAxS7N/Sc9QTWqkZ6ssYo4s=; b=Xv1QkWVUWHGgVCoLHtLhL1oozoq0wcfk63BhDD55OsDJ/+1KG+3zj44mAGPwltCROQgH gG1g3IjaHxYAKWjRU/oumTQ1nGp30oVO1G6SZlctBNfiFIwekCXo4ok3TjVtHg6mOZujo Vniiiph6fnGV8ScfWaMnFDEmm5hwse5oloaBEffYtux1pUstrPh0DcdOXunstBM4wEmDY U7s9nASZiukwlPn5RdsMAbdQAfmHV4ocbCWYCRf3jLjYfSgvOngi1AuQBB1RMa4a617MS F9oyuJ/VMKmhCa3ULrH0ReaXR6MF2BQm2xZRRNDlk+7id6/haXy6ZqExQuBf7k2tbbA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Xx2yyQS2; 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 D8332606A32C for ; Fri, 4 Dec 2026 11:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Xx2yyQS2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B5671F000C2; Fri, 4 Dec 2026 11:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796383648; bh=HILSAc9J9R1C01S081FJrAxS7N/Sc9QTWqkZ6ssYo4s=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Xx2yyQS2lklPGJgYfgbbxNsqRCkpTES37RXvem+2qcaf0Lp6bzdznUr9pJTsPtDsk C6pXWuwSEcCPfigYKN0TVvWIzoc32es57r13wu3xNUVoYUKdLG7HF62kyjLIdT4zIh OVtPZJzaV5V+/adZQMnr4I163cwfEg7Lqtf3QNAPQiz+qo8s7KWpFCYIXjlt/l9zjW 10kwUl0C9EqqwiGv2RojZxutf3BE29ZRVCJ61pWPwYzRulM3z3FjL/8ZEZak4TOZbo 85BG1alCRkYtIu+HXcy+Py7oRcATy9korW4W/92sYqQedxLcPc2MOgV3NppsITnJ5Y xNhsrZD45pqdQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3] usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl Reply-To: sashiko-reviews@lists.linux.dev To: "Jaegyun Lee" Cc: linux-usb@vger.kernel.org In-Reply-To: <179638268904.917654.4905537541576241323@gmail.com> References: <2026120308-corset-mushroom-abb1@gregkh> <179638268904.917654.4905537541576241323@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 11:27:28 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] usb: gadget: f_fs: unlocked ffs->func writes race with ffs_ep0_ioctl() -- commit 749233c5ed0afea8fa48c7272c8471cf26bafee9 Author: Jaegyun Lee usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl This commit takes ffs->eps_lock around the ffs->func check and ffs_func_revmap_intf() walk in ffs_ep0_ioctl(), and protects the ffs->func =3D NULL store in ffs_func_unbind() with the same lock. > diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/func= tion/f_fs.c > index 59afa7f2bce45..8bb49407c728b 100644 > --- a/drivers/usb/gadget/function/f_fs.c > +++ b/drivers/usb/gadget/function/f_fs.c > @@ -689,8 +689,8 @@ static long ffs_ep0_ioctl(struct file *file, unsigned= code, unsigned long value) > long ret; > =20 > if (code =3D=3D FUNCTIONFS_INTERFACE_REVMAP) { > - struct ffs_function *func =3D ffs->func; > - ret =3D func ? ffs_func_revmap_intf(func, value) : -ENODEV; > + guard(spinlock_irqsave)(&ffs->eps_lock); > + ret =3D ffs->func ? ffs_func_revmap_intf(ffs->func, value) : -ENODEV; > } else if (gadget && gadget->ops->ioctl) { > ret =3D gadget->ops->ioctl(gadget, code, value); > } else { [Severity: Medium] Can unlocked writes to ffs->func in ffs_func_disable() and ffs_func_set_alt() still race with ffs_ep0_ioctl() and cause a NULL pointer dereference? Removing the local func snapshot causes ffs->func to be evaluated twice under ffs->eps_lock, assuming that lock excludes all writers. However, only ffs_func_unbind() was updated to hold ffs->eps_lock; both ffs_func_disable() and ffs_func_set_alt() still write ffs->func right after dropping ffs->eps_lock. During a USB disconnect or bus reset, ffs_func_disable() can clear ffs->func concurrently with an ioctl(FUNCTIONFS_INTERFACE_REVMAP): CPU0 CPU1 ffs_ep0_ioctl() guard(spinlock_irqsave)(&ffs->eps_lock) ffs->func !=3D NULL ffs_func_disable() spin_unlock_irqrestore(&ffs->eps_lock) ffs->func =3D NULL ffs_func_revmap_intf(ffs->func, ...) func->interfaces_nums <-- NULL pointer dereference If the compiler reloads ffs->func for the call to ffs_func_revmap_intf() (or inside an inlined copy), dereferencing func->interfaces_nums crashes with a NULL pointer dereference. ffs_func_set_alt() has the same data race on ffs->func during configuration or altsetting changes. Updating ffs->func while ffs->eps_lock is already held in ffs_func_disable() and ffs_func_set_alt() would close both races. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/179638268904.917654= .4905537541576241323@gmail.com?part=3D1