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=1796221429; b=r+reoaTQV96p8aPYgZu44j9mIuAyqEH8ietXQ8DK5jsWcdUQaOuH+qod72zgbcsa5Ey9 WSXpPoTWSXq4tDN3zpv+fvjZteuLcW+PWUn6bvqN262BASRsKiTI8ulAysWFVXe6ERxbo 2mMI7nQMH1vJ691LGE3S60+v5lsupQ73RkQdQ2iN2XXSmKloleV5eIKS7mPqOFi98KVPR 9UHcis7hWm3gdz6h/TfO1cFdL8e/lNKY/obimJ7QrOGfNEstZgeOF05doUG70mrN2rBKK u5hszULnRHVyDG3TRDDrT75hcHgKzqLmf/BS6/ydM8hcURC3hiSqQucAwNOR4VI29aQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221429; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=ZOtIvTTgiHisj1Zliy/le4pGbFh/wngvgL6Ranyg8Ws=; b=JLAl0ea0GqQ8fWV0oYY7+QTfgHQ05EkoK7lzXl68jrI9VX5auAvy9E7iAblfNZdKl+Sf idxCn+Xmh7CpkSbcVRXEYvnUWeJ/RB1A5d+qckYs/FXoF0DAeFV23VFhsb/knKnrV05l6 KyE8nuPty23uHrsmsSIyLT5HVISpATIlNt1h1ZjZH1I6817KT4SRUgKx0o4VZDjNTvyYg FmvSoHYBK+IYmXDAkKVMMQf0aW46VxfpK31aF3BpVC9eaQTbtB0qf6NOfoZgcI9Vr6U6h WclvsJU1gpP04uXwDBCIlB71jRmH4DrXWg0KWF6Fa70w4EN17Xuy0D4xZJ0gOH/fPmg== 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=GwtwjAIy; 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 69F90606A31A for ; Wed, 2 Dec 2026 14:23:49 +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=GwtwjAIy Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC4261F00893; Wed, 2 Dec 2026 14:23:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796221429; bh=ZOtIvTTgiHisj1Zliy/le4pGbFh/wngvgL6Ranyg8Ws=; h=Subject:To:Cc:From:Date; b=GwtwjAIyDzjLtv1UITSFVpzX0hAzpo3tHAnablIBlalQYTeVMqqhn4pF6HwizTVIK EdgpiwcHFR8iSujHLrNrkwzqHx8HFMIMWfc9mey9HVKJtP9lrOmHQ3D0RPRw+AngNd QK0CKq7/ldEybVPuxx2uuc6RkQa9Y7G8BliKYVI8= Subject: FAILED: patch "[PATCH] virtiofs: fix use-after-free of fs->tag on device removal" failed to apply to 6.1-stable tree To: mszeredi@redhat.com,sashiko-bot@kernel.org,stable@vger.kernel.org Cc: From: Date: Wed, 02 Dec 2026 14:46:39 +0100 Message-ID: <2026120239-worrisome-slapping-a032@gregkh> 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-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.1-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y git checkout FETCH_HEAD git cherry-pick -x 6df984631391616dafd9b989a3505d93ca4fd235 # git commit -s git send-email --to '' --in-reply-to '2026120239-worrisome-slapping-a032@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..' Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 6df984631391616dafd9b989a3505d93ca4fd235 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Tue, 3 Nov 2026 17:19:10 +0100 Subject: [PATCH] virtiofs: fix use-after-free of fs->tag on device removal 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 diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c index ba8d79c4bcac..ef58bedc3941 100644 --- a/fs/fuse/virtio_fs.c +++ b/fs/fuse/virtio_fs.c @@ -193,6 +193,7 @@ static void virtio_fs_ktype_release(struct kobject *kobj) { 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 virtio_fs *fs) } } -/* 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 virtio_device *vdev, struct virtio_fs *fs) 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);