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=1796385125; b=2KtQnGZwXuaqdMoIH5Fha9jYBPUEv7xjdU5nL3iFcuRy/DZTdTs17QQ8fRFONGOazpZM WsQf1gHDzPsn4D06y2zSHnpzrc1AQOgyAFNzMq76W42jzVhALovVRzfTJeO88ReBNK1kP QWatY/x1FiM/ysbUIQfy3jIw5yUIF2yI1XDzWjiJaGmWcNNIBO0jOWkXkY/s6f1jOq9UQ tYLjb/FecySb8FrwM6YW7vtSkig7mZgAeAy7UzJ/tqJsOuhVhZGVmuYtuU/sHCdKJCk+W JWf5H9ZzI+fXB3HSh5VHDk6ZSfaImLSSgQd2dUqlHe1xRXVd45Jy2k1MqXIDHLtA9pQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385125; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=X/UcpDF7X4wSLc1nqf8gdkkwVsqvouY1mrLDvpKX0RE=; b=ykP8Q/qh21TOYjazUFhdZY+NWNi6hpr8SGQETkuiphJcJ+2BnVtxrxO/fnVR+fvZ7cLm j5luYnrUjgnh56Lr/zSKNxaQiy8LLs6X45qmu3Q4VYPdXDT2by2rlVM/pw6bns7KWm/S7 gdyHfkEAHK4DtwyEVmeDAgmRq1qpX5ChejuQOdKxbEhsfpgL2wNE2iF5zDkAMImplYKqD quGGuidW5Sz0mKpk45khk7Nmbp/5XzjCmaVZ3ieZm5UTo9FvMPUlV0fUhhmtRMlTzmwNf ODZBMuLE3DllIAn5HG3HzPGrlQpr1+5qMjJGzZIawGCN75et+/LUrXN2ZhmP23sbT6A== 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=iw1wz2ve; 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 97FFB606A32C for ; Fri, 4 Dec 2026 11:52:05 +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=iw1wz2ve Received: by smtp.kernel.org (Postfix) with ESMTPSA id 643921F000C2; Fri, 4 Dec 2026 11:52:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796385125; bh=X/UcpDF7X4wSLc1nqf8gdkkwVsqvouY1mrLDvpKX0RE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=iw1wz2veDP9qLIP2e1drsAknABnugx5Lh6bagPraxyA2z1Ro3T+N0pJY8bplN3MWT xT6eyzJAjyVwxURT+fRiFA/6XXxWJVQbL3la94uVkMi0dsFzm5LbK08jNmAEuBwm7C +N6nthMoqGf3M7MbrSbVvjx3Gssg36ZHIi2Mj7izQXjl8Ey8lJUa/rcULbXkCwCXOx 2KeELVwuNemx6mXck3EpgUhzDPVoapmMvdSS4ofqXpmD1soKK2U2fiTLq/C1yFkBkR ltGQdPvj8jTNHPqLqwV5oNrcOrNvZQHP7Ct67EYSZt7IjoS/SXumaBK1JsrzmNyv0X dOOhITlIzq2Kw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4] 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: <179638424483.1056529.4365760725322283852@gmail.com> References: <179638424483.1056529.4365760725322283852@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 11:52:05 +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 2afecf326e3fa3f1963a2c2a9789edfb44ab44a9 Author: Jaegyun Lee usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl This commit takes ffs->eps_lock around the ffs->func lookup and ffs_func_revmap_intf() walk in ffs_ep0_ioctl(), and around clearing ffs->func to NULL in ffs_func_unbind(). > diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/func= tion/f_fs.c > index 59afa7f2bce45..c3919f60cac7e 100644 > --- a/drivers/usb/gadget/function/f_fs.c > +++ b/drivers/usb/gadget/function/f_fs.c > @@ -689,8 +689,12 @@ static long ffs_ep0_ioctl(struct file *file, unsigne= d 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; > + struct ffs_function *func; > + > + scoped_guard(spinlock_irqsave, &ffs->eps_lock) { > + func =3D ffs->func; > + ret =3D func ? ffs_func_revmap_intf(func, value) : -ENODEV; > + } > } else if (gadget && gadget->ops->ioctl) { > ret =3D gadget->ops->ioctl(gadget, code, value); > } else { [Severity: Medium] Does ffs->func still race with ffs_func_set_alt() and ffs_func_disable() here? Only ffs_func_unbind() takes ffs->eps_lock when updating ffs->func. Both ffs_func_set_alt() and ffs_func_disable() still perform unlocked plain writes to ffs->func immediately after releasing ffs->eps_lock, leaving an unmarked data race (reportable by KCSAN) against this plain load. Because ffs_func_revmap_intf() is a small static helper in the same file, the compiler can inline it and reload ffs->func after the NULL check while a concurrent disconnect or reset clears it: CPU0 CPU1 ffs_ep0_ioctl() ffs_func_disable() lock(&ffs->eps_lock) lock(&ffs->eps_lock) func =3D ffs->func; ... if (func) unlock(&ffs->eps_lock) ffs->func =3D NULL; ffs_func_revmap_intf(...) /* reload ffs->func */ func->interfaces_nums <-- NULL pointer dereference Moving the ffs->func assignments in ffs_func_set_alt() and ffs_func_disable() into their existing ffs->eps_lock critical sections (while keeping ffs_event_add() outside the lock) would close the race. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/179638424483.105652= 9.4365760725322283852@gmail.com?part=3D1