Linux-stable backports for IOMMU CVE-2024-21963
Subsystems (2)
From: Joerg Roedel <[email protected]>
Hi,
Here are the stable backports to work around an IOMMU hardware issue on some AMD CPUs. The issue is tracked as CVE-2024-21963.
This posting only has the backports which can not be cherry-picked from upstream (all stable kernels except 7.3.y).
Please consider for inclusion into the Linux stable trees.
Thanks,
-Joerg
PATCH 1/1 iommu/amd: Force device table to maximum size
From: Suravee Suthikulpanit <[email protected]>
commit 6e2213dae78b41976c60133eb10cf99e81916638 upstream.
IOMMU can perform out-of-bounds read of the device table entry (DTE) that is adjacent to the last DTE and falls outside the device table. For example, if the device table can hold 0 to N-1 entries, then the IOMMU can be made to fetch the Nth entry, which falls outside the device table.
The device table is owned by the hypervisor (HV) and is assigned in 4KB pages that are contiguous in system physical address (SPA). If the out-of-bound DTE falls on a guest-owned page, then the guest can exploit this bug to setup malicious table walks to corrupt HV pages and/or bring down the system. Note that this bug does not manifest when the device table size is set to its maximum size of 2MB.
Therefore, force the device table size to the maximum 2MB on affected processors. These are CPU family 0x17 (Zen1/Zen2) through family 0x1a (Zen5/BRH).
This is a mitigation for CVE-2024-21963.
kdump reuses the previous kernel's device table only when the size encoded in the IOMMU device-table register matches pci_seg->dev_table_size. A mixed rollout disagrees: the unpatched kernel uses the IVRS-derived size and the patched kernel uses 2MB, so __reuse_device_table() rejects the table. On SNP-capable IOMMUs that rejection panics the kdump kernel. Kernels that both have this patch agree on 2MB and reuse succeeds. Update the production kernel and the crash kernel together.
Family 0x1a models 0xd8-0xef are Zen6. This kernel does not mark that range as X86_FEATURE_ZEN6, so those processors would still take the 2MB device table. Add the range to the existing Zen6 detection and exclude them from the workaround.
--- arch/x86/kernel/cpu/amd.c | 1 + drivers/iommu/amd/init.c | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/amd.c +1 -0
@@ -524,6 +524,7 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) case 0x50 ... 0x5f: case 0x80 ... 0xaf: case 0xc0 ... 0xcf: + case 0xd8 ... 0xef:setup_force_cpu_cap (X86_FEATURE_ZEN6 );break ;default :
drivers/iommu/amd/init.c +24 -3
@@ -1736,6 +1736,21 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,return 0 ; } +/* +* Apply workaround for Zen1 to Zen5(BRH) generation of processors. +* References: CVE-2024-21963 +*/ +static bool __init amd_iommu_force_max_dev_table (void ) +{ +if (boot_cpu_data.x86 >=0x17 && boot_cpu_data.x86 <=0x1a ) { +if (cpu_feature_enabled (X86_FEATURE_ZEN6 )) +return false; +else +return true; + } +return false; +} +/* Allocate PCI segment data structure */ static struct amd_iommu_pci_seg *__init alloc_pci_segment (u16 id,struct acpi_table_header *ivrs_base)
@@ -1758,9 +1773,15 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id, pci_seg->last_bdf = last_bdf;DUMP_printk ("PCI segment : 0x%0x, last bdf : 0x%04x\n" , id, last_bdf); - pci_seg->dev_table_size = -max (roundup_pow_of_two ((last_bdf +1 ) *DEV_TABLE_ENTRY_SIZE ), -SZ_4K ); +if (amd_iommu_force_max_dev_table ()) { +pr_info ("Force device table to maximum size\n" ); + pci_seg->dev_table_size =SZ_2M ; + }else { + pci_seg->dev_table_size = +max (roundup_pow_of_two ((last_bdf +1 ) * +DEV_TABLE_ENTRY_SIZE ), +SZ_4K ); + } pci_seg->id = id;init_llist_head (&pci_seg->dev_data_list);
Signature · 1 line
2.53.0
PATCH 1/1 iommu/amd: Force device table to maximum size
In reply to Jörg RödelFrom: Suravee Suthikulpanit <[email protected]>
commit 6e2213dae78b41976c60133eb10cf99e81916638 upstream.
IOMMU can perform out-of-bounds read of the device table entry (DTE) that is adjacent to the last DTE and falls outside the device table. For example, if the device table can hold 0 to N-1 entries, then the IOMMU can be made to fetch the Nth entry, which falls outside the device table.
The device table is owned by the hypervisor (HV) and is assigned in 4KB pages that are contiguous in system physical address (SPA). If the out-of-bound DTE falls on a guest-owned page, then the guest can exploit this bug to setup malicious table walks to corrupt HV pages and/or bring down the system. Note that this bug does not manifest when the device table size is set to its maximum size of 2MB.
Therefore, force the device table size to the maximum 2MB on affected processors. These are CPU family 0x17 (Zen1/Zen2) through family 0x1a (Zen5/BRH).
This is a mitigation for CVE-2024-21963.
kdump copies the previous kernel's device table only when the size encoded in the IOMMU device-table register matches pci_seg->dev_table_size. A mixed rollout disagrees: the unpatched kernel uses the IVRS-derived size and the patched kernel uses 2MB, so copy_device_table() rejects the table and reinitializes translation. Kernels that both have this patch agree on 2MB and the copy succeeds. Update the production kernel and the crash kernel together.
This backport adds X86_FEATURE_ZEN6. Bit 3*32+6 is still X86_FEATURE_P3 here, so the new flag uses free bit 21*32+7. Family 0x1a models 0x50-0x5f, 0x80-0xaf, 0xc0-0xcf, and 0xd8-0xef are Zen6 and are excluded from the workaround.
--- arch/x86/include/asm/cpufeatures.h | 5 +++++ arch/x86/kernel/cpu/amd.c | 6 ++++++ drivers/iommu/amd/init.c | 23 ++++++++++++++++++++++- tools/arch/x86/include/asm/cpufeatures.h | 5 +++++ 4 files changed, 38 insertions(+), 1 deletion(-)
arch/x86/include/asm/cpufeatures.h +5 -0
@@ -483,6 +483,11 @@#define X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT (21*32+ 4)/* Clear branch history at vmexit using SW loop */ #define X86_FEATURE_FAST_CPPC (21*32 + 5)/* AMD Fast CPPC */ #define X86_FEATURE_INDIRECT_THUNK_ITS (21*32 + 6)/* Use thunk for indirect branches in lower half of cacheline */ +/* +* Upstream defines X86_FEATURE_ZEN6 as (3*32+6). That bit is still +* X86_FEATURE_P3 in this kernel, so use a free bit in this word. +*/ +#define X86_FEATURE_ZEN6 (21*32+7)/* CPU based on Zen6 microarchitecture */ #define X86_FEATURE_TSA_SQ_NO (21*32+11)/* AMD CPU not vulnerable to TSA-SQ */ #define X86_FEATURE_TSA_L1_NO (21*32+12)/* AMD CPU not vulnerable to TSA-L1 */
arch/x86/kernel/cpu/amd.c +6 -0
@@ -531,6 +531,12 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) case 0xd0 ... 0xd7:setup_force_cpu_cap (X86_FEATURE_ZEN5 );break ; + case 0x50 ... 0x5f: + case 0x80 ... 0xaf: + case 0xc0 ... 0xcf: + case 0xd8 ... 0xef: +setup_force_cpu_cap (X86_FEATURE_ZEN6 ); +break ;default : goto warn; }
drivers/iommu/amd/init.c +22 -1
@@ -1579,6 +1579,21 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,return 0 ; } +/* +* Apply workaround for Zen1 to Zen5(BRH) generation of processors. +* References: CVE-2024-21963 +*/ +static bool __init amd_iommu_force_max_dev_table (void ) +{ +if (boot_cpu_data.x86 >=0x17 && boot_cpu_data.x86 <=0x1a ) { +if (cpu_feature_enabled (X86_FEATURE_ZEN6 )) +return false; +else +return true; + } +return false; +} +/* Allocate PCI segment data structure */ static struct amd_iommu_pci_seg *__init alloc_pci_segment (u16 id,struct acpi_table_header *ivrs_base)
@@ -1601,7 +1616,13 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id, pci_seg->last_bdf = last_bdf;DUMP_printk ("PCI segment : 0x%0x, last bdf : 0x%04x\n" , id, last_bdf); - pci_seg->dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE , last_bdf); +if (amd_iommu_force_max_dev_table ()) { +pr_info ("Force device table to maximum size\n" ); + pci_seg->dev_table_size =SZ_2M ; + }else { + pci_seg->dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE , + last_bdf); + } pci_seg->alias_table_size =tbl_size (ALIAS_TABLE_ENTRY_SIZE , last_bdf); pci_seg->rlookup_table_size =tbl_size (RLOOKUP_TABLE_ENTRY_SIZE , last_bdf);
tools/arch/x86/include/asm/cpufeatures.h +5 -0
@@ -473,6 +473,11 @@#define X86_FEATURE_CLEAR_BHB_HW (21*32+ 3)/* BHI_DIS_S HW control enabled */ #define X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT (21*32+ 4)/* Clear branch history at vmexit using SW loop */ #define X86_FEATURE_FAST_CPPC (21*32 + 5)/* AMD Fast CPPC */ +/* +* Upstream defines X86_FEATURE_ZEN6 as (3*32+6). That bit is still +* X86_FEATURE_P3 in this kernel, so use a free bit in this word. +*/ +#define X86_FEATURE_ZEN6 (21*32+7)/* CPU based on Zen6 microarchitecture */ /* * BUG word(s)
Signature · 1 line
2.53.0
PATCH 1/1 iommu/amd: Force device table to maximum size
In reply to Jörg RödelFrom: Suravee Suthikulpanit <[email protected]>
commit 6e2213dae78b41976c60133eb10cf99e81916638 upstream.
IOMMU can perform out-of-bounds read of the device table entry (DTE) that is adjacent to the last DTE and falls outside the device table. For example, if the device table can hold 0 to N-1 entries, then the IOMMU can be made to fetch the Nth entry, which falls outside the device table.
The device table is owned by the hypervisor (HV) and is assigned in 4KB pages that are contiguous in system physical address (SPA). If the out-of-bound DTE falls on a guest-owned page, then the guest can exploit this bug to setup malicious table walks to corrupt HV pages and/or bring down the system. Note that this bug does not manifest when the device table size is set to its maximum size of 2MB.
Therefore, force the device table size to the maximum 2MB on affected processors. These are CPU family 0x17 (Zen1/Zen2) through family 0x1a (Zen5/BRH).
This is a mitigation for CVE-2024-21963.
kdump copies the previous kernel's device table only when the size encoded in the IOMMU device-table register matches pci_seg->dev_table_size. A mixed rollout disagrees: the unpatched kernel uses the IVRS-derived size and the patched kernel uses 2MB, so copy_device_table() rejects the table and reinitializes translation. Kernels that both have this patch agree on 2MB and the copy succeeds. Update the production kernel and the crash kernel together.
This backport adds X86_FEATURE_ZEN6. Bit 3*32+6 is still X86_FEATURE_P3 here, so the new flag uses free bit 21*32+7. Family 0x1a models 0x50-0x5f, 0x80-0xaf, 0xc0-0xcf, and 0xd8-0xef are Zen6 and are excluded from the workaround.
--- arch/x86/include/asm/cpufeatures.h | 5 +++++ arch/x86/kernel/cpu/amd.c | 6 ++++++ drivers/iommu/amd/init.c | 23 ++++++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-)
arch/x86/include/asm/cpufeatures.h +5 -0
@@ -469,6 +469,11 @@#define X86_FEATURE_CLEAR_BHB_HW (21*32+ 3)/* "" BHI_DIS_S HW control enabled */ #define X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT (21*32+ 4)/* "" Clear branch history at vmexit using SW loop */ #define X86_FEATURE_INDIRECT_THUNK_ITS (21*32 + 5)/* "" Use thunk for indirect branches in lower half of cacheline */ +/* +* Upstream defines X86_FEATURE_ZEN6 as (3*32+6). That bit is still +* X86_FEATURE_P3 in this kernel, so use a free bit in this word. +*/ +#define X86_FEATURE_ZEN6 (21*32+7)/* "" CPU based on Zen6 microarchitecture */ #define X86_FEATURE_TSA_SQ_NO (21*32+11)/* "" AMD CPU not vulnerable to TSA-SQ */ #define X86_FEATURE_TSA_L1_NO (21*32+12)/* "" AMD CPU not vulnerable to TSA-L1 */
arch/x86/kernel/cpu/amd.c +6 -0
@@ -709,6 +709,12 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) case 0xd0 ... 0xd7:setup_force_cpu_cap (X86_FEATURE_ZEN5 );break ; + case 0x50 ... 0x5f: + case 0x80 ... 0xaf: + case 0xc0 ... 0xcf: + case 0xd8 ... 0xef: +setup_force_cpu_cap (X86_FEATURE_ZEN6 ); +break ;default : goto warn; }
drivers/iommu/amd/init.c +22 -1
@@ -1629,6 +1629,21 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,return 0 ; } +/* +* Apply workaround for Zen1 to Zen5(BRH) generation of processors. +* References: CVE-2024-21963 +*/ +static bool __init amd_iommu_force_max_dev_table (void ) +{ +if (boot_cpu_data.x86 >=0x17 && boot_cpu_data.x86 <=0x1a ) { +if (cpu_feature_enabled (X86_FEATURE_ZEN6 )) +return false; +else +return true; + } +return false; +} +/* Allocate PCI segment data structure */ static struct amd_iommu_pci_seg *__init alloc_pci_segment (u16 id,struct acpi_table_header *ivrs_base)
@@ -1651,7 +1666,13 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id, pci_seg->last_bdf = last_bdf;DUMP_printk ("PCI segment : 0x%0x, last bdf : 0x%04x\n" , id, last_bdf); - pci_seg->dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE , last_bdf); +if (amd_iommu_force_max_dev_table ()) { +pr_info ("Force device table to maximum size\n" ); + pci_seg->dev_table_size =SZ_2M ; + }else { + pci_seg->dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE , + last_bdf); + } pci_seg->alias_table_size =tbl_size (ALIAS_TABLE_ENTRY_SIZE , last_bdf); pci_seg->rlookup_table_size =tbl_size (RLOOKUP_TABLE_ENTRY_SIZE , last_bdf);
Signature · 1 line
2.53.0
PATCH 1/1 iommu/amd: Force device table to maximum size
In reply to Jörg RödelFrom: Suravee Suthikulpanit <[email protected]>
commit 6e2213dae78b41976c60133eb10cf99e81916638 upstream.
IOMMU can perform out-of-bounds read of the device table entry (DTE) that is adjacent to the last DTE and falls outside the device table. For example, if the device table can hold 0 to N-1 entries, then the IOMMU can be made to fetch the Nth entry, which falls outside the device table.
The device table is owned by the hypervisor (HV) and is assigned in 4KB pages that are contiguous in system physical address (SPA). If the out-of-bound DTE falls on a guest-owned page, then the guest can exploit this bug to setup malicious table walks to corrupt HV pages and/or bring down the system. Note that this bug does not manifest when the device table size is set to its maximum size of 2MB.
Therefore, force the device table size to the maximum 2MB on affected processors. These are CPU family 0x17 (Zen1/Zen2) through family 0x1a (Zen5/BRH).
This is a mitigation for CVE-2024-21963.
kdump copies the previous kernel's device table only when the size encoded in the IOMMU device-table register matches pci_seg->dev_table_size. A mixed rollout disagrees: the unpatched kernel uses the IVRS-derived size and the patched kernel uses 2MB, so copy_device_table() rejects the table and reinitializes translation. Kernels that both have this patch agree on 2MB and the copy succeeds. Update the production kernel and the crash kernel together.
This backport adds X86_FEATURE_ZEN6. Bit 3*32+6 is still X86_FEATURE_P3 here, so the new flag uses free bit 21*32+7. Family 0x1a models 0x50-0x5f, 0x80-0xaf, 0xc0-0xcf, and 0xd8-0xef are Zen6 and are excluded from the workaround. This kernel has no X86_FEATURE_ZEN5. Other family 0x1a models stay unmarked and still take the 2MB device table.
--- arch/x86/include/asm/cpufeatures.h | 5 +++++ arch/x86/kernel/cpu/amd.c | 18 ++++++++++++++++++ drivers/iommu/amd/init.c | 23 ++++++++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-)
arch/x86/include/asm/cpufeatures.h +5 -0
@@ -452,6 +452,11 @@#define X86_FEATURE_CLEAR_BHB_HW (21*32+ 3)/* "" BHI_DIS_S HW control enabled */ #define X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT (21*32+ 4)/* "" Clear branch history at vmexit using SW loop */ #define X86_FEATURE_INDIRECT_THUNK_ITS (21*32 + 5)/* "" Use thunk for indirect branches in lower half of cacheline */ +/* +* Upstream defines X86_FEATURE_ZEN6 as (3*32+6). That bit is still +* X86_FEATURE_P3 in this kernel, so use a free bit in this word. +*/ +#define X86_FEATURE_ZEN6 (21*32+7)/* "" CPU based on Zen6 microarchitecture */ #define X86_FEATURE_TSA_SQ_NO (21*32+11)/* "" AMD CPU not vulnerable to TSA-SQ */ #define X86_FEATURE_TSA_L1_NO (21*32+12)/* "" AMD CPU not vulnerable to TSA-L1 */
arch/x86/kernel/cpu/amd.c +18 -0
@@ -713,6 +713,24 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) }break ; } +case 0x1a : { +switch (c->x86_model) { + case 0x50 ... 0x5f: + case 0x80 ... 0xaf: + case 0xc0 ... 0xcf: + case 0xd8 ... 0xef: +setup_force_cpu_cap (X86_FEATURE_ZEN6 ); +break ; +default : +/* +* Zen5 models in family 0x1a have no feature bit +* in this kernel. Leave them unmarked so the +* device-table workaround still applies. +*/ +break ; + } +break ; + }default :break ; }
drivers/iommu/amd/init.c +22 -1
@@ -1587,6 +1587,21 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,return 0 ; } +/* +* Apply workaround for Zen1 to Zen5(BRH) generation of processors. +* References: CVE-2024-21963 +*/ +static bool __init amd_iommu_force_max_dev_table (void ) +{ +if (boot_cpu_data.x86 >=0x17 && boot_cpu_data.x86 <=0x1a ) { +if (cpu_feature_enabled (X86_FEATURE_ZEN6 )) +return false; +else +return true; + } +return false; +} +/* Allocate PCI segment data structure */ static struct amd_iommu_pci_seg *__init alloc_pci_segment (u16 id,struct acpi_table_header *ivrs_base)
@@ -1609,7 +1624,13 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id, pci_seg->last_bdf = last_bdf;DUMP_printk ("PCI segment : 0x%0x, last bdf : 0x%04x\n" , id, last_bdf); - pci_seg->dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE , last_bdf); +if (amd_iommu_force_max_dev_table ()) { +pr_info ("Force device table to maximum size\n" ); + pci_seg->dev_table_size =SZ_2M ; + }else { + pci_seg->dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE , + last_bdf); + } pci_seg->alias_table_size =tbl_size (ALIAS_TABLE_ENTRY_SIZE , last_bdf); pci_seg->rlookup_table_size =tbl_size (RLOOKUP_TABLE_ENTRY_SIZE , last_bdf);
Signature · 1 line
2.53.0
PATCH 1/1 iommu/amd: Force device table to maximum size
In reply to Jörg RödelFrom: Suravee Suthikulpanit <[email protected]>
commit 6e2213dae78b41976c60133eb10cf99e81916638 upstream.
IOMMU can perform out-of-bounds read of the device table entry (DTE) that is adjacent to the last DTE and falls outside the device table. For example, if the device table can hold 0 to N-1 entries, then the IOMMU can be made to fetch the Nth entry, which falls outside the device table.
The device table is owned by the hypervisor (HV) and is assigned in 4KB pages that are contiguous in system physical address (SPA). If the out-of-bound DTE falls on a guest-owned page, then the guest can exploit this bug to setup malicious table walks to corrupt HV pages and/or bring down the system. Note that this bug does not manifest when the device table size is set to its maximum size of 2MB.
Therefore, force the device table size to the maximum 2MB on affected processors. These are CPU family 0x17 (Zen1/Zen2) through family 0x1a (Zen5/BRH).
This is a mitigation for CVE-2024-21963.
kdump copies the previous kernel's device table only when the size encoded in the IOMMU device-table register matches dev_table_size. A mixed rollout disagrees: the unpatched kernel uses the IVRS-derived size and the patched kernel uses 2MB, so copy_device_table() rejects the table and reinitializes translation. Kernels that both have this patch agree on 2MB and the copy succeeds. Update the production kernel and the crash kernel together.
This kernel has one global device table. Only that size is forced to 2MB. Alias and rlookup sizes stay derived from the IVRS.
This backport adds X86_FEATURE_ZEN6. Bit 3*32+6 is still X86_FEATURE_P3 here, so the new flag uses free bit 21*32+7. Family 0x1a models 0x50-0x5f, 0x80-0xaf, 0xc0-0xcf, and 0xd8-0xef are Zen6 and are excluded from the workaround. This kernel has no X86_FEATURE_ZEN5. Other family 0x1a models stay unmarked and still take the 2MB device table.
--- arch/x86/include/asm/cpufeatures.h | 5 +++++ arch/x86/kernel/cpu/amd.c | 18 ++++++++++++++++++ drivers/iommu/amd/init.c | 23 ++++++++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-)
arch/x86/include/asm/cpufeatures.h +5 -0
@@ -439,6 +439,11 @@#define X86_FEATURE_CLEAR_BHB_HW (21*32+ 3)/* "" BHI_DIS_S HW control enabled */ #define X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT (21*32+ 4)/* "" Clear branch history at vmexit using SW loop */ #define X86_FEATURE_INDIRECT_THUNK_ITS (21*32 + 5)/* "" Use thunk for indirect branches in lower half of cacheline */ +/* +* Upstream defines X86_FEATURE_ZEN6 as (3*32+6). That bit is still +* X86_FEATURE_P3 in this kernel, so use a free bit in this word. +*/ +#define X86_FEATURE_ZEN6 (21*32+7)/* "" CPU based on Zen6 microarchitecture */ #define X86_FEATURE_TSA_SQ_NO (21*32+11)/* "" AMD CPU not vulnerable to TSA-SQ */ #define X86_FEATURE_TSA_L1_NO (21*32+12)/* "" AMD CPU not vulnerable to TSA-L1 */
arch/x86/kernel/cpu/amd.c +18 -0
@@ -742,6 +742,24 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) }break ; } +case 0x1a : { +switch (c->x86_model) { + case 0x50 ... 0x5f: + case 0x80 ... 0xaf: + case 0xc0 ... 0xcf: + case 0xd8 ... 0xef: +setup_force_cpu_cap (X86_FEATURE_ZEN6 ); +break ; +default : +/* +* Zen5 models in family 0x1a have no feature bit +* in this kernel. Leave them unmarked so the +* device-table workaround still applies. +*/ +break ; + } +break ; + }default :break ; }
drivers/iommu/amd/init.c +22 -1
@@ -22,6 +22,7 @@#include <linux/kmemleak.h> #include <linux/mem_encrypt.h> #include <linux/iopoll.h> +#include <linux/sizes.h> #include <asm/pci-direct.h> #include <asm/iommu.h> #include <asm/apic.h>
@@ -2757,6 +2758,21 @@ static void __init ivinfo_init(void *ivrs) amd_iommu_ivinfo = *((u32 *)(ivrs +IOMMU_IVINFO_OFFSET )); } +/* +* Apply workaround for Zen1 to Zen5(BRH) generation of processors. +* References: CVE-2024-21963 +*/ +static bool __init amd_iommu_force_max_dev_table (void ) +{ +if (boot_cpu_data.x86 >=0x17 && boot_cpu_data.x86 <=0x1a ) { +if (cpu_feature_enabled (X86_FEATURE_ZEN6 )) +return false; +else +return true; + } +return false; +} +/* * This is the hardware init function for AMD IOMMU in the system. * This function is called either from amd_iommu_init or from the interrupt
@@ -2824,7 +2840,12 @@ static int __init early_amd_iommu_init(void)if (ret) goto out; - dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE ); +if (amd_iommu_force_max_dev_table ()) { +pr_info ("Force device table to maximum size\n" ); + dev_table_size =SZ_2M ; + }else { + dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE ); + } alias_table_size =tbl_size (ALIAS_TABLE_ENTRY_SIZE ); rlookup_table_size =tbl_size (RLOOKUP_TABLE_ENTRY_SIZE );
Signature · 1 line
2.53.0
PATCH 1/1 iommu/amd: Force device table to maximum size
In reply to Jörg RödelFrom: Suravee Suthikulpanit <[email protected]>
commit 6e2213dae78b41976c60133eb10cf99e81916638 upstream.
IOMMU can perform out-of-bounds read of the device table entry (DTE) that is adjacent to the last DTE and falls outside the device table. For example, if the device table can hold 0 to N-1 entries, then the IOMMU can be made to fetch the Nth entry, which falls outside the device table.
The device table is owned by the hypervisor (HV) and is assigned in 4KB pages that are contiguous in system physical address (SPA). If the out-of-bound DTE falls on a guest-owned page, then the guest can exploit this bug to setup malicious table walks to corrupt HV pages and/or bring down the system. Note that this bug does not manifest when the device table size is set to its maximum size of 2MB.
Therefore, force the device table size to the maximum 2MB on affected processors. These are CPU family 0x17 (Zen1/Zen2) through family 0x1a (Zen5/BRH).
This is a mitigation for CVE-2024-21963.
kdump copies the previous kernel's device table only when the size encoded in the IOMMU device-table register matches dev_table_size. A mixed rollout disagrees: the unpatched kernel uses the IVRS-derived size and the patched kernel uses 2MB, so copy_device_table() rejects the table and reinitializes translation. Kernels that both have this patch agree on 2MB and the copy succeeds. Update the production kernel and the crash kernel together.
This kernel has one global device table. Only that size is forced to 2MB. Alias and rlookup sizes stay derived from the IVRS.
This backport adds X86_FEATURE_ZEN6. Bit 3*32+6 is still X86_FEATURE_P3 here, so the new flag uses free bit 21*32+7. Family 0x1a models 0x50-0x5f, 0x80-0xaf, 0xc0-0xcf, and 0xd8-0xef are Zen6 and are excluded from the workaround. This kernel has no X86_FEATURE_ZEN5. Other family 0x1a models stay unmarked and still take the 2MB device table.
--- arch/x86/include/asm/cpufeatures.h | 6 ++++++ arch/x86/kernel/cpu/amd.c | 18 ++++++++++++++++++ drivers/iommu/amd/init.c | 23 ++++++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-)
arch/x86/include/asm/cpufeatures.h +6 -0
@@ -416,6 +416,12 @@#define X86_FEATURE_IBPB_BRTYPE (20*32+28)/* "" MSR_PRED_CMD[IBPB] flushes all branch type predictions */ #define X86_FEATURE_SRSO_NO (20*32+29)/* "" CPU is not affected by SRSO */ +/* +* Upstream defines X86_FEATURE_ZEN6 as (3*32+6). That bit is still +* X86_FEATURE_P3 in this kernel, so use a free bit in this word. +*/ +#define X86_FEATURE_ZEN6 (21*32+7)/* "" CPU based on Zen6 microarchitecture */ +#define X86_FEATURE_TSA_SQ_NO (22*32+11)/* "" AMD CPU not vulnerable to TSA-SQ */ #define X86_FEATURE_TSA_L1_NO (22*32+12)/* "" AMD CPU not vulnerable to TSA-L1 */ #define X86_FEATURE_CLEAR_CPU_BUF_VM (22*32+13)/* "" Clear CPU buffers using VERW before VMRUN */
arch/x86/kernel/cpu/amd.c +18 -0
@@ -769,6 +769,24 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) }break ; } +case 0x1a : { +switch (c->x86_model) { + case 0x50 ... 0x5f: + case 0x80 ... 0xaf: + case 0xc0 ... 0xcf: + case 0xd8 ... 0xef: +setup_force_cpu_cap (X86_FEATURE_ZEN6 ); +break ; +default : +/* +* Zen5 models in family 0x1a have no feature bit +* in this kernel. Leave them unmarked so the +* device-table workaround still applies. +*/ +break ; + } +break ; + }default :break ; }
drivers/iommu/amd/init.c +22 -1
@@ -21,6 +21,7 @@#include <linux/kmemleak.h> #include <linux/mem_encrypt.h> #include <linux/iopoll.h> +#include <linux/sizes.h> #include <asm/pci-direct.h> #include <asm/iommu.h> #include <asm/apic.h>
@@ -2664,6 +2665,21 @@ static void __init ivinfo_init(void *ivrs) amd_iommu_ivinfo = *((u32 *)(ivrs +IOMMU_IVINFO_OFFSET )); } +/* +* Apply workaround for Zen1 to Zen5(BRH) generation of processors. +* References: CVE-2024-21963 +*/ +static bool __init amd_iommu_force_max_dev_table (void ) +{ +if (boot_cpu_data.x86 >=0x17 && boot_cpu_data.x86 <=0x1a ) { +if (cpu_feature_enabled (X86_FEATURE_ZEN6 )) +return false; +else +return true; + } +return false; +} +/* * This is the hardware init function for AMD IOMMU in the system. * This function is called either from amd_iommu_init or from the interrupt
@@ -2732,7 +2748,12 @@ static int __init early_amd_iommu_init(void)if (ret) goto out; - dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE ); +if (amd_iommu_force_max_dev_table ()) { +pr_info ("Force device table to maximum size\n" ); + dev_table_size =SZ_2M ; + }else { + dev_table_size =tbl_size (DEV_TABLE_ENTRY_SIZE ); + } alias_table_size =tbl_size (ALIAS_TABLE_ENTRY_SIZE ); rlookup_table_size =tbl_size (RLOOKUP_TABLE_ENTRY_SIZE );
Signature · 1 line
2.53.0
Quoted 1 line
Linux-stable backports for IOMMU CVE-2024-21963
Queued for 6.12, 6.6, 6.1, 5.15 and 5.10, thanks.
6.18 already carries the mainline commit, so the 6.18.y patch does not apply on top of it. What 6.18 is missing is the one-line Zen6 model-range hunk in arch/x86/kernel/cpu/amd.c. Could you send that as a separate 6.18.y patch?
Signature · 2 lines
Thanks, Sasha
PATCH 1/1 Update 212c2020833b ("iommu/amd: Force device table to maximum size")
From: Joerg Roedel <[email protected]>
commit 6e2213dae78b41976c60133eb10cf99e81916638 upstream.
The stable backport for the commit in the subject line lacks a hunk to match the fix on all relevant hardware generations. Add the missing hunk.
--- arch/x86/kernel/cpu/amd.c | 1 + 1 file changed, 1 insertion(+)
arch/x86/kernel/cpu/amd.c +1 -0
@@ -524,6 +524,7 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) case 0x50 ... 0x5f: case 0x80 ... 0xaf: case 0xc0 ... 0xcf: + case 0xd8 ... 0xef:setup_force_cpu_cap (X86_FEATURE_ZEN6 );break ;default :
Signature · 1 line
2.53.0
Sasha Levin
maintainerRe: [PATCH] Update 212c2020833b ("iommu/amd: Force device table to maximum size")
Quoted 3 lines
The stable backport for the commit in the subject line lacks a hunk to match the fix on all relevant hardware generations. Add the missing hunk.
Thanks. Since the 6.18 backport of 6e2213dae78b ("iommu/amd: Force device table to maximum size") is still only queued, I folded the 0xd8 ... 0xef case into it rather than adding a separate commit.
Signature · 2 lines
Thanks, Sasha