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=1796384053; b=KCOdF9TOgAw+V6SpghQzzwNLzx9UJuL89efhnOofzY1t2CFgR3ffFdOCu7SsaoxDur32 R0ha5jWoxGuaB/9zs2xt3cQtJiOUW6NvrN8AwoIQ5T8koPQ25xdkwEBeiZZZqmD7TeQ3v JcjLLTMAZzA046JdPUIvhg4mMk3oa3UrGIP6u8x9NX3cIZeDakc3Y9vWlSmJadFl95Q7V yOihl5q54hxjsCw25Qm8Xxk1pkpLt4F4HbPtUzdkjIuqNIMJD4e2KpJd/uyjEKs/1+ij5 UOLEAoL+cSoTKTK3glpsV22VKXz713AzEyuq5rNro79YzvG5ToacWZA8Z9+Pabamvuw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384053; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=QbpDJSVm8Xd6eIHaBItdsT95y2b96tiAgLesEhrtca4=; b=nHpzt3D79pD6mvRMKRips3zI1Yu4VVgggR1h/pZ9TdwBj015ya61VFkxnPxtxxInlJlN 7IAKq9/BlpHlEOlisWBkM2XxJqpPltU8HHmE5w3Z1FSX5eEtD4tqljaP0bxovLxamFppF BTOgsPMWj8VntoZU8wnbO2aSrNAbjZaIertpuQsPYmW0F8NNvx32FPq/hZ4kcFXHdqPL4 a7FhrVwfINVarE5xSMFBAVqNNhwLpsJBRbD2WKggLYBh0hUdUQ2YdN8Wv+rzHWauSdsX8 TIRsKNZDru/J0BfMg5Flspy4GIBrDVPyiH4PgTVwhqoIL2QOG9qvWOl032USaTn5Cqw== 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=GPGFDtfv; 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 7ED0D606A336; Fri, 4 Dec 2026 11:34:13 +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=GPGFDtfv Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC5F61F00931; Fri, 4 Dec 2026 11:34:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384053; bh=QbpDJSVm8Xd6eIHaBItdsT95y2b96tiAgLesEhrtca4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GPGFDtfvKdrNZgGzOToueGlMfyq+Lwatt30VnEld0RoWfs2sY9g/sRTfYlVY9NXbe Ii2m1BJqMjEytknqJMXpfN+jgBuxcdn+PSBAcBpDNALT4/jhNqmkeVukrYVoTNzgOk bCYcxtTyef4x1eCz5tF5a3xF7VSrxhGBNLYbyE8E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Miklos Szeredi Subject: [PATCH 6.12 458/555] virtiofs: fix use-after-free of fs->tag on device removal Date: Fri, 4 Dec 2026 19:08:21 +0900 Message-ID: <20261204100626.852601879@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Miklos Szeredi commit 6df984631391616dafd9b989a3505d93ca4fd235 upstream. The virtio_fs object is refcounted via its kobject, so a mount can keep it alive well beyond the lifetime of the virtio device binding. The tag string, however, was allocated with devm_kmalloc() and is therefore freed by devres_release_all() as soon as the device is unbound, i.e. right after virtio_fs_remove() returns (see device_unbind_cleanup() in drivers/base/dd.c). virtio_fs_get_tree() looks up the instance, takes a kobject reference and then drops virtio_fs_mutex before doing the sleepable part of the mount (allocations, fuse_conn_init(), sget_fc()). A concurrent device removal can complete in that window: CPU 0 (mount) CPU 1 (remove) ------------- -------------- virtio_fs_get_tree() virtio_fs_find_instance() // reference taken, mutex dropped virtio_fs_remove() list_del_init(&fs->list); // driver core unbinds device // devres frees fs->tag virtio_fs_fill_super() mutex_lock(&virtio_fs_mutex); if (list_empty(&fs->list)) pr_info(... fs->tag); <-- use-after-free The virtio_fs object itself is still valid here, only its tag has been freed behind its back. Fix the lifetime mismatch at the source: allocate the tag with kmalloc() and free it from virtio_fs_ktype_release(), so that it lives exactly as long as the object embedding it. All probe error paths already drop the final kobject reference, so they are covered. Merely dropping the tag from the error message would paper over this instance while leaving a devres pointer embedded in an object that routinely outlives its device. The other readers of fs->tag are unaffected: tag_show() is fenced off by the kobject_del() in virtio_fs_remove(), the automatic KOBJ_REMOVE uevent is emitted from __kobject_del() while the device is still bound, and both virtio_fs_add_instance() and virtio_fs_find_instance() only walk instances still on virtio_fs_instances. Fixes: a62a8ef9d97d ("virtio-fs: add virtiofs filesystem") Cc: Reported-by: Sashiko Closes: https://sashiko.dev/#/bug/linux-0328b3a1-043b-468e-8425-6a613d91b5ef Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/fuse/virtio_fs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -191,6 +191,7 @@ static void virtio_fs_ktype_release(stru { struct virtio_fs *vfs = container_of(kobj, struct virtio_fs, kobj); + kfree(vfs->tag); kfree(vfs->mq_map); kfree(vfs->vqs); kfree(vfs); @@ -487,7 +488,11 @@ static void virtio_fs_free_devs(struct v } } -/* Read filesystem name from virtio config into fs->tag (must kfree()). */ +/* + * Read filesystem name from virtio config into fs->tag. Freed by + * virtio_fs_ktype_release() so that it stays valid for as long as the + * virtio_fs object itself, which may outlive the virtio device. + */ static int virtio_fs_read_tag(struct virtio_device *vdev, struct virtio_fs *fs) { char tag_buf[sizeof_field(struct virtio_fs_config, tag)]; @@ -503,7 +508,7 @@ static int virtio_fs_read_tag(struct vir end = &tag_buf[sizeof(tag_buf)]; len = end - tag_buf; - fs->tag = devm_kmalloc(&vdev->dev, len + 1, GFP_KERNEL); + fs->tag = kmalloc(len + 1, GFP_KERNEL); if (!fs->tag) return -ENOMEM; memcpy(fs->tag, tag_buf, len);