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=1796066662; b=QbpvHw0EDzA2bz1o9WqMBqvw/YjhHH7i/NJscXdYbpCIz4gOaB3F4isZ3/1dmmJHaDL6 a2hVzajonIaG3+B1/KI+HzI26AWVF+o2s9eSIapWJNp17VgTlgfQsqbXRHFo3dA0r9Z+e H/hWl9p93cOhdBvHz7wU2nMAaKm+6hf0Yl6OzDDkYf3aixLDNlHWfvDaj6/eTdnQV8ZYc CQJ+IoTeQAspgTPuXIegepOMGCfue23l9CE7508qSAyECzJSISWcHjysnFN9qkb8kFRoa jfV/h9PFz9fLWp8Ni1/wPlAiOFjeHWoUq8hdChcyc9h+ya/J5B4LO/7Fk7SmQbkIhcA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796066662; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=T/Qa0vp+SUcvKJ7AKNLQpGbWPp+yhAMkbo1w1oxo8Zc=; b=UaFztzjLN/nxqr/jxAiN1XRjgr9C7gamv9IbAy6dJo7aUbVo0+oDFyzwGty7ZRbbc+tN wnUXHX4BEvPEqSRdxXQ1IxpxtrysORuHINRA7WIpFvzRFIE68OAtAM5xJQcc+nld0XAHY V+a9jBTbPDD5HCqMmUkKyZgWQ1g9UBUSjSxk+w9hb7JVKfdptGZYIcg8BqNWRZ+ZFApSG TQep6fTTrfcW36un5b1FhwZy0Lx3Yoz4gPotrQ9hHCF7V7k23zqHXOKpMyIZ7DIhYCSro sDXF06tREsL4s/f70V+qTDCcB3gEDWTUCVWHk4ebV0faW8yQbBqE7Ij/jWBwcNFRiwQ== 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=PavtOTeE; 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 ED1B7606A31C for ; Mon, 30 Nov 2026 19:24:21 +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=PavtOTeE Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88C781F000C1; Mon, 30 Nov 2026 19:24:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796066661; bh=T/Qa0vp+SUcvKJ7AKNLQpGbWPp+yhAMkbo1w1oxo8Zc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=PavtOTeEga+20dAkDAU1HR4BsjBbFjzpQHdZo+VByFM8KGaqhSp/9Gov/sCKNYUbZ v3SYY+lSP6B7r6dv5HTdMpjeBYH0Nn4tbu3k0YDlGKG9xAcfwhu/U9QU04p0KznYBR Ao9UK8gWfCR2gFaazlL60IoT9EH94h2SnQKqrwKu1ioWSC/lxXqt7+8GJB+nbkpQl9 8msPo59/qV3aZIzV4oq+rGNyOi7wyzHHCnY/D3NYGARMVjuBdnrWrkLYIJ0ky2bCmN bXs23KRQYQxAHQKyeGneA6JOK+qxf5p4w6t0V5j0QwOPUuwbnF8FkprEONJ62zQuXU URjz+AOX+PjKQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] virtio: Remove debugfs entries when device_add() fails Reply-To: sashiko-reviews@lists.linux.dev To: "Stjepan Poljak" Cc: virtualization@lists.linux.dev, "Michael S. Tsirkin" , "Eugenio Perez" In-Reply-To: <20261130192040.1931044-1-stjepan.poljak@gmail.com> References: <20261130192040.1931044-1-stjepan.poljak@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 19:24:21 +0000 X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list > register_virtio_device() creates the device's debugfs directory before > calling device_add(), but the device_add() error path does not remove > it. The files in that directory keep the virtio device as their private > data, and the caller is required to drop its reference with put_device() > on failure, which frees the device. Reading any of the leftover files > afterwards dereferences freed memory. >=20 > The device index is also returned to the IDA, so the next device to > reuse it fails to create its "virtioN" debugfs directory because the > stale one still exists. >=20 > Commit 3f9a0fceb730 ("virtio: fix use-after-free in > unregister_virtio_device()") fixed the same kind of lifetime problem on > the unregister side. Remove the debugfs entries on the device_add() > failure path as well, before the caller can free the device. >=20 > Reproduced on x86_64 with CONFIG_KASAN and CONFIG_VIRTIO_DEBUG by > rebinding a virtio-mmio balloon device with fail-nth slab fault > injection: once an allocation inside device_add() fails, the stale > debugfs directory remains, and reading its device_features file > triggers a slab-use-after-free in vm_get_features(). With this patch > applied, no directory is left behind and no report occurs. >=20 > Fixes: 96a8326d69ff ("virtio: add debugfs infrastructure to allow to debu= g virtio features") > Cc: stable@vger.kernel.org > Signed-off-by: Stjepan Poljak Sashiko has reviewed this patch and found no issues. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130192040.1931= 044-1-stjepan.poljak@gmail.com?part=3D1