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=1796382635; b=arQPB+7UzIGBXG9SqZ9+IzSZh/RXB3cAre5VAHuN7ulPK/ZeNqSM36VV7r1+JYIj8YqG cizuXjsx/7t4dLF7EVSv68HbTL5h+QVLrFQkYZQxdanrW971Sc+PKHJFIdepP9yxiz12U DtCqGbrmrTKbB2Lpk53dPLGKCDrAfCsf/S60vTcOq0FNYP2e79GbjsSk1N4NbAZY7Qti9 exv+Q7zZDOnuHn9fUx6X1tvYCKqc8VwNQ1xxsLsAqwJZPLguPevBdSwB+sfyvtOkGNMf9 WieEuVbpiRx1IiDlUU16qxC09rAGkTNquWm1d84RfjBncy6ymIsKudyy5KVOTg6SAdw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382635; 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=jqwR2zcpMQjZ7QncRnvKNMe2LC6oFp3Pw5Ws9Qg18Jk=; b=e4FbQIThH1y5jcKseeJxBeCcgVl1M4nbgrak0iGKSEL9A1RzxWkkomqG0Pg4m+L9lnY7 QPSPzcr4Af4vfrNEfkzrT1xP3g4WQ8XRD//WbQjKNRGwH2YllH8KsAqFZchRcpPUm9zku /6XPZjBxLfpNDmVO4qT3jIjootBXdJslcu6BGfXLJnSNXVUSsEQvkILfl4CP1nOlTxiyw C8uy0wxXHTE4L0cu7yOvM1rn96tfV0nekNS2jU7U/Lj1xxMSaVZD+9SprhZT1c823DgFK DuLBH5sVlrOommUvAb1zQsZzuJpH3QmGyqT0Qvj/e3nUq0hYFxvkIHbUG7WE4H8fk1A== 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=f5OD5fY1; 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 EC8CE606A322; Fri, 4 Dec 2026 11:10:34 +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=f5OD5fY1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12F511F00897; Fri, 4 Dec 2026 11:10:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382634; bh=jqwR2zcpMQjZ7QncRnvKNMe2LC6oFp3Pw5Ws9Qg18Jk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=f5OD5fY1Z/k9vJe+SyPKGS0nKZIYm7BldHS9o3nGGyUhHCUDcl3+j/Gr3qGNMgmjM 5k4EFauitizgWwLfu5PM3/ooWPfF+/rbFWnErNkdRCyhFyc4NPYbISQFEDx+uOTenv otLgGOdf1eYw312eQCbOcMD3U64RdGd1PvJaslmk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Miklos Szeredi Subject: [PATCH 6.18 536/703] virtiofs: fix use-after-free of fs->tag on device removal Date: Fri, 4 Dec 2026 19:07:15 +0900 Message-ID: <20261204100642.048781805@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-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 @@ -192,6 +192,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); @@ -488,7 +489,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)]; @@ -504,7 +509,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);