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=1796381214; b=EtIanEkY+BaTudW6p0O0KsLAxd8CRjLKGLk4VcZZ7gdvPUHdZPxB5GLDOBNwyDoZ6Q2I PQHsP/XJh8FuEbyjSjc0aZvsy87Qdzkg1eGRgGxX5Zswn1QWi4bPk9SnNPiMUTu6DkRQn oKrLCfb7yQGQ3VchFmrsnI8RiKELFPqAjPYwXZcl/0lnLbFPWJZ8lOOs8fuPt7XLu4UwZ XBmRfNs2dXog+2XWAFNynUEIGys+jpSmat6WSe5w4JX7GMO7WJjPAxiary7wKOsCoh2DS Sk6718vqEywp9n3UOhbMe+4H5G4MAXoVw8emYc1RarDbkxcwUOnkm09wTMgzTZf4Ijw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381214; 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=2ETUZGJbufuaPgZ4loB5XuvHehIOh7MRpmS+0jseo0g=; b=0pPyy38RJyWEPLBob55qu4Fv2QTUf/+Pomv+9VbvouTjW1jJYzRCxKP36LsrYFf37iZQ H3GGNV+NhqVYdzTxXT2OxFpMTtOxCf1X2o1yJXnokPYXjju1+r1P7FrelyyPBwKW1KVja KngF/icqPdIlu5DOXiA9g0yunUm7JC4JpxcoDloxVgj24x2yXs4SFXcAIPmvBWnr+7Hrn mWT/E98kHtZ5SDRl1xRx67uWgTnD9zodD5BA8cFQHPtfQBQ6yrLuXLFdJ3vUKtzTgnW7O emxTmZ7u7NR6jGSwMW1cFHbDrb0P+KP9PpkRLAd37CDchkpn8HvywbKgZMuYNawecjw== 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=zpNg6z9E; 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 BB06C606A322; Fri, 4 Dec 2026 10:46:54 +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=zpNg6z9E Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2ED961F000CE; Fri, 4 Dec 2026 10:46:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381214; bh=2ETUZGJbufuaPgZ4loB5XuvHehIOh7MRpmS+0jseo0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zpNg6z9EpM4zOnoP9rx53XPMhbckwEljvvlpHD6WFBa22S8SabJQD/4LnvYC5eDUm lvZWbKKpjumJWdshdW0HHYNEiRBu6hW7ZnlRaS6sSq6oN40VuynsQMt53JByHhtF+j WKIXyrOKi6N96KaDyvjW6cktwl3/vc9MJci3oLiU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Miklos Szeredi Subject: [PATCH 7.3 607/742] virtiofs: fix use-after-free of fs->tag on device removal Date: Fri, 4 Dec 2026 19:07:51 +0900 Message-ID: <20261204100651.242458435@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 @@ -193,6 +193,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); @@ -489,7 +490,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)]; @@ -505,7 +510,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);