Commit 96d20889 authored by Philip Chen's avatar Philip Chen Committed by Jinjie Ruan
Browse files

virtio_pmem: Check device status before requesting flush

stable inclusion
from stable-v5.10.227
commit 4ce662fe4be6fbc2595d9ef4888b2b6e778c99ed
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IB2YUI
CVE: CVE-2024-50184

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=4ce662fe4be6fbc2595d9ef4888b2b6e778c99ed



-------------------------------------------------

[ Upstream commit e25fbcd97cf52c3c9824d44b5c56c19673c3dd50 ]

If a pmem device is in a bad status, the driver side could wait for
host ack forever in virtio_pmem_flush(), causing the system to hang.

So add a status check in the beginning of virtio_pmem_flush() to return
early if the device is not activated.

Signed-off-by: default avatarPhilip Chen <philipchen@chromium.org>
Message-Id: <20240826215313.2673566-1-philipchen@chromium.org>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Acked-by: default avatarPankaj Gupta <pankaj.gupta.linux@gmail.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarJinjie Ruan <ruanjinjie@huawei.com>
parent 400fd9cc
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -44,6 +44,15 @@ static int virtio_pmem_flush(struct nd_region *nd_region)
	unsigned long flags;
	int err, err1;

	/*
	 * Don't bother to submit the request to the device if the device is
	 * not activated.
	 */
	if (vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_NEEDS_RESET) {
		dev_info(&vdev->dev, "virtio pmem device needs a reset\n");
		return -EIO;
	}

	might_sleep();
	req_data = kmalloc(sizeof(*req_data), GFP_KERNEL);
	if (!req_data)