Skip to content

Commit 1d3636f

Browse files
kgodara912Kshitiz Godara
andauthored
Patch qemu for CVE-2024-26327, CVE-2024-26328 [MEDIUM] (#13714)
Co-authored-by: Kshitiz Godara <kgodara@microsoft.com>
1 parent 3e3afc8 commit 1d3636f

3 files changed

Lines changed: 132 additions & 1 deletion

File tree

SPECS/qemu/CVE-2024-26327.patch

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
From 313e746958967a4b941ad4bbb80726727318edfa Mon Sep 17 00:00:00 2001
2+
From: Akihiko Odaki <akihiko.odaki@daynix.com>
3+
Date: Wed, 28 Feb 2024 20:33:13 +0900
4+
Subject: [PATCH] pcie_sriov: Validate NumVFs
5+
6+
The guest may write NumVFs greater than TotalVFs and that can lead
7+
to buffer overflow in VF implementations.
8+
9+
Cc: qemu-stable@nongnu.org
10+
Fixes: CVE-2024-26327
11+
Fixes: 7c0fa8dff811 ("pcie: Add support for Single Root I/O Virtualization (SR/IOV)")
12+
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
13+
Message-Id: <20240228-reuse-v8-2-282660281e60@daynix.com>
14+
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
15+
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
16+
Reviewed-by: Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>
17+
(cherry picked from commit 6081b4243cd64dff1b2cf5b0c215c71e9d7e753b)
18+
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
19+
---
20+
hw/pci/pcie_sriov.c | 3 +++
21+
1 file changed, 3 insertions(+)
22+
23+
diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c
24+
index a1fe65f5d80..da209b7f47f 100644
25+
--- a/hw/pci/pcie_sriov.c
26+
+++ b/hw/pci/pcie_sriov.c
27+
@@ -176,6 +176,9 @@ static void register_vfs(PCIDevice *dev)
28+
29+
assert(sriov_cap > 0);
30+
num_vfs = pci_get_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF);
31+
+ if (num_vfs > pci_get_word(dev->config + sriov_cap + PCI_SRIOV_TOTAL_VF)) {
32+
+ return;
33+
+ }
34+
35+
dev->exp.sriov_pf.vf = g_new(PCIDevice *, num_vfs);
36+
37+
--
38+
GitLab
39+

SPECS/qemu/CVE-2024-26328.patch

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
From 98f3488c1b6090024299f8d6362aa6aac03fe26d Mon Sep 17 00:00:00 2001
2+
From: Akihiko Odaki <akihiko.odaki@daynix.com>
3+
Date: Wed, 28 Feb 2024 20:33:12 +0900
4+
Subject: [PATCH] hw/nvme: Use pcie_sriov_num_vfs()
5+
6+
nvme_sriov_pre_write_ctrl() used to directly inspect SR-IOV
7+
configurations to know the number of VFs being disabled due to SR-IOV
8+
configuration writes, but the logic was flawed and resulted in
9+
out-of-bound memory access.
10+
11+
It assumed PCI_SRIOV_NUM_VF always has the number of currently enabled
12+
VFs, but it actually doesn't in the following cases:
13+
- PCI_SRIOV_NUM_VF has been set but PCI_SRIOV_CTRL_VFE has never been.
14+
- PCI_SRIOV_NUM_VF was written after PCI_SRIOV_CTRL_VFE was set.
15+
- VFs were only partially enabled because of realization failure.
16+
17+
It is a responsibility of pcie_sriov to interpret SR-IOV configurations
18+
and pcie_sriov does it correctly, so use pcie_sriov_num_vfs(), which it
19+
provides, to get the number of enabled VFs before and after SR-IOV
20+
configuration writes.
21+
22+
Cc: qemu-stable@nongnu.org
23+
Fixes: CVE-2024-26328
24+
Fixes: 11871f53ef8e ("hw/nvme: Add support for the Virtualization Management command")
25+
Suggested-by: Michael S. Tsirkin <mst@redhat.com>
26+
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
27+
Message-Id: <20240228-reuse-v8-1-282660281e60@daynix.com>
28+
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
29+
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
30+
(cherry picked from commit 91bb64a8d2014fda33a81fcf0fce37340f0d3b0c)
31+
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
32+
---
33+
hw/nvme/ctrl.c | 26 ++++++++------------------
34+
1 file changed, 8 insertions(+), 18 deletions(-)
35+
36+
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
37+
index 585bd3b397d..eaa6946604d 100644
38+
--- a/hw/nvme/ctrl.c
39+
+++ b/hw/nvme/ctrl.c
40+
@@ -8497,36 +8497,26 @@ static void nvme_pci_reset(DeviceState *qdev)
41+
nvme_ctrl_reset(n, NVME_RESET_FUNCTION);
42+
}
43+
44+
-static void nvme_sriov_pre_write_ctrl(PCIDevice *dev, uint32_t address,
45+
- uint32_t val, int len)
46+
+static void nvme_sriov_post_write_config(PCIDevice *dev, uint16_t old_num_vfs)
47+
{
48+
NvmeCtrl *n = NVME(dev);
49+
NvmeSecCtrlEntry *sctrl;
50+
- uint16_t sriov_cap = dev->exp.sriov_cap;
51+
- uint32_t off = address - sriov_cap;
52+
- int i, num_vfs;
53+
+ int i;
54+
55+
- if (!sriov_cap) {
56+
- return;
57+
- }
58+
-
59+
- if (range_covers_byte(off, len, PCI_SRIOV_CTRL)) {
60+
- if (!(val & PCI_SRIOV_CTRL_VFE)) {
61+
- num_vfs = pci_get_word(dev->config + sriov_cap + PCI_SRIOV_NUM_VF);
62+
- for (i = 0; i < num_vfs; i++) {
63+
- sctrl = &n->sec_ctrl_list.sec[i];
64+
- nvme_virt_set_state(n, le16_to_cpu(sctrl->scid), false);
65+
- }
66+
- }
67+
+ for (i = pcie_sriov_num_vfs(dev); i < old_num_vfs; i++) {
68+
+ sctrl = &n->sec_ctrl_list.sec[i];
69+
+ nvme_virt_set_state(n, le16_to_cpu(sctrl->scid), false);
70+
}
71+
}
72+
73+
static void nvme_pci_write_config(PCIDevice *dev, uint32_t address,
74+
uint32_t val, int len)
75+
{
76+
- nvme_sriov_pre_write_ctrl(dev, address, val, len);
77+
+ uint16_t old_num_vfs = pcie_sriov_num_vfs(dev);
78+
+
79+
pci_default_write_config(dev, address, val, len);
80+
pcie_cap_flr_write_config(dev, address, val, len);
81+
+ nvme_sriov_post_write_config(dev, old_num_vfs);
82+
}
83+
84+
static const VMStateDescription nvme_vmstate = {
85+
--
86+
GitLab
87+

SPECS/qemu/qemu.spec

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ Obsoletes: sgabios-bin <= 1:0.20180715git-10.fc38
428428
Summary: QEMU is a FAST! processor emulator
429429
Name: qemu
430430
Version: 8.2.0
431-
Release: 14%{?dist}
431+
Release: 15%{?dist}
432432
License: Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND FSFAP AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-2.0-or-later WITH GCC-exception-2.0 AND LGPL-2.0-only AND LGPL-2.0-or-later AND LGPL-2.1-only AND LGPL-2.1-or-later AND MIT AND LicenseRef-Fedora-Public-Domain AND CC-BY-3.0
433433
URL: http://www.qemu.org/
434434

@@ -447,6 +447,8 @@ Patch8: CVE-2024-6505.patch
447447
Patch9: CVE-2024-4693.patch
448448
Patch10: CVE-2024-7730.patch
449449
Patch11: CVE-2024-3567.patch
450+
Patch12: CVE-2024-26327.patch
451+
Patch13: CVE-2024-26328.patch
450452

451453
Source10: qemu-guest-agent.service
452454
Source11: 99-qemu-guest-agent.rules
@@ -3430,6 +3432,9 @@ useradd -r -u 107 -g qemu -G kvm -d / -s /sbin/nologin \
34303432

34313433

34323434
%changelog
3435+
* Thu May 08 2025 Kshitiz Godara <kgodara@microsoft.com> - 8.2.0-15
3436+
- Added patch for CVE-2024-26327 CVE-2024-26328
3437+
34333438
* Mon May 05 2025 Kshitiz Godara <kgodara@microsoft.com> - 8.2.0-14
34343439
- Added patch for CVE-2024-6505 CVE-2024-4467 CVE-2024-4693 CVE-2024-7730 CVE-2024-3447 CVE-2024-3567
34353440

0 commit comments

Comments
 (0)