tools/x86/kcpuid: Check last token too
Borislav Petkov
maintainerPATCH 1/2 tools/x86/kcpuid: Check last token too
From: Borislav Petkov <[email protected]>
Input lines like
0x8000001E, 0, EAX, 31:0, Extended APIC ID
where the short name is missing lead to a segfault because the loop takes the long name for the short name and tokens[5] becomes NULL which explodes later in strcpy().
Check its value too before further processing.
--- tools/arch/x86/kcpuid/kcpuid.c | 2 ++ 1 file changed, 2 insertions(+)
tools/arch/x86/kcpuid/kcpuid.c +2 -0
@@ -324,6 +324,8 @@ static int parse_line(char *line) str =NULL ; } tokens[5 ] =strtok (str,"\n" ); +if (!tokens[5 ]) + goto err_exit;/* index/main-leaf */ index =strtoull (tokens[0 ],NULL ,0 );
Signature · 1 line
2.29.2
Borislav Petkov
maintainerPATCH 2/2 tools/x86/kcpuid: Add AMD leaf 0x8000001E
From: Borislav Petkov <[email protected]>
Contains core IDs, node IDs and other topology info.
--- tools/arch/x86/kcpuid/cpuid.csv | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
tools/arch/x86/kcpuid/cpuid.csv +18 -8
@@ -379,12 +379,22 @@ 0x80000008, 0, EAX, 15:8, lnr_adr_bits, Linear Address Bits 0x80000007, 0, EBX, 9, wbnoinvd, WBNOINVD +# 0x8000001E +# EAX: Extended APIC ID +0x8000001E, 0, EAX, 31:0, extended_apic_id, Extended APIC ID +# EBX: Core Identifiers +0x8000001E, 0, EBX, 7:0, core_id, Identifies the logical core ID +0x8000001E, 0, EBX, 15:8, threads_per_core, The number of threads per core is threads_per_core + 1 +# ECX: Node Identifiers +0x8000001E, 0, ECX, 7:0, node_id, Node ID +0x8000001E, 0, ECX, 10:8, nodes_per_processor, Nodes per processor { 0: 1 node, else reserved } + # 8000001F: AMD Secure Encryption -0x8000001F, 0, EAX, 0, sme, Secure Memory Encryption -0x8000001F, 0, EAX, 1, sev, Secure Encrypted Virtualization -0x8000001F, 0, EAX, 2, vmpgflush, VM Page Flush MSR -0x8000001F, 0, EAX, 3, seves, SEV Encrypted State -0x8000001F, 0, EBX, 5:0, c-bit, Page table bit number used to enable memory encryption -0x8000001F, 0, EBX, 11:6, mem_encrypt_physaddr_width, Reduction of physical address space in bits with SME enabled -0x8000001F, 0, ECX, 31:0, num_encrypted_guests, Maximum ASID value that may be used for an SEV-enabled guest -0x8000001F, 0, EDX, 31:0, minimum_sev_asid, Minimum ASID value that must be used for an SEV-enabled, SEV-ES-disabled guest +0x8000001F, 0, EAX, 0, sme, Secure Memory Encryption +0x8000001F, 0, EAX, 1, sev, Secure Encrypted Virtualization +0x8000001F, 0, EAX, 2, vmpgflush, VM Page Flush MSR +0x8000001F, 0, EAX, 3, seves, SEV Encrypted State +0x8000001F, 0, EBX, 5:0, c-bit, Page table bit number used to enable memory encryption +0x8000001F, 0, EBX, 11:6, mem_encrypt_physaddr_width, Reduction of physical address space in bits with SME enabled +0x8000001F, 0, ECX, 31:0, num_encrypted_guests, Maximum ASID value that may be used for an SEV-enabled guest +0x8000001F, 0, EDX, 31:0, minimum_sev_asid, Minimum ASID value that must be used for an SEV-enabled, SEV-ES-disabled guest
Signature · 1 line
2.29.2
Quoted 11 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
Input lines like
0x8000001E, 0, EAX, 31:0, Extended APIC IDwhere the short name is missing lead to a segfault because the loop takes the long name for the short name and tokens[5] becomes NULL which explodes later in
strcpy().Check its value too before further processing.
Thanks for the fix!
Quoted 20 lines
Signed-off-by Borislav Petkov <[email protected]>--- tools/arch/x86/kcpuid/kcpuid.c | 2 ++ 1 file changed, 2 insertions(+)tools/arch/x86/kcpuid/kcpuid.c +2
-0@@ -324,6 +324,8 @@ static int parse_line(char *line) str =NULL ; } tokens[5 ] =strtok (str,"\n" ); +if (!tokens[5 ]) + goto err_exit;/* index/main-leaf */ index =strtoull (tokens[0 ],NULL ,0 );Signature · 1 line
2.29.2
Re: [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E
In reply to Borislav PetkovQuoted 5 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
Contains core IDs, node IDs and other topology info.
Signed-off-by Borislav Petkov <[email protected]>
Also I'm wondering for some basic leaf and extended leaf which may has different definition for different vendors, do we need to seprate the csv to a general one and vendor specific ones.
Thanks,
Feng
Quoted 41 lines
--- tools/arch/x86/kcpuid/cpuid.csv | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)tools/arch/x86/kcpuid/cpuid.csv +18
-8@@ -379,12 +379,22 @@ 0x80000008, 0, EAX, 15:8, lnr_adr_bits, Linear Address Bits 0x80000007, 0, EBX, 9, wbnoinvd, WBNOINVD +# 0x8000001E +# EAX: Extended APIC ID +0x8000001E, 0, EAX, 31:0, extended_apic_id, Extended APIC ID +# EBX: Core Identifiers +0x8000001E, 0, EBX, 7:0, core_id, Identifies the logical core ID +0x8000001E, 0, EBX, 15:8, threads_per_core, The number of threads per core is threads_per_core + 1 +# ECX: Node Identifiers +0x8000001E, 0, ECX, 7:0, node_id, Node ID +0x8000001E, 0, ECX, 10:8, nodes_per_processor, Nodes per processor { 0: 1 node, else reserved } + # 8000001F: AMD Secure Encryption -0x8000001F, 0, EAX, 0, sme, Secure Memory Encryption -0x8000001F, 0, EAX, 1, sev, Secure Encrypted Virtualization -0x8000001F, 0, EAX, 2, vmpgflush, VM Page Flush MSR -0x8000001F, 0, EAX, 3, seves, SEV Encrypted State -0x8000001F, 0, EBX, 5:0, c-bit, Page table bit number used to enable memory encryption -0x8000001F, 0, EBX, 11:6, mem_encrypt_physaddr_width, Reduction of physical address space in bits with SME enabled -0x8000001F, 0, ECX, 31:0, num_encrypted_guests, Maximum ASID value that may be used for an SEV-enabled guest -0x8000001F, 0, EDX, 31:0, minimum_sev_asid, Minimum ASID value that must be used for an SEV-enabled, SEV-ES-disabled guest +0x8000001F, 0, EAX, 0, sme, Secure Memory Encryption +0x8000001F, 0, EAX, 1, sev, Secure Encrypted Virtualization +0x8000001F, 0, EAX, 2, vmpgflush, VM Page Flush MSR +0x8000001F, 0, EAX, 3, seves, SEV Encrypted State +0x8000001F, 0, EBX, 5:0, c-bit, Page table bit number used to enable memory encryption +0x8000001F, 0, EBX, 11:6, mem_encrypt_physaddr_width, Reduction of physical address space in bits with SME enabled +0x8000001F, 0, ECX, 31:0, num_encrypted_guests, Maximum ASID value that may be used for an SEV-enabled guest +0x8000001F, 0, EDX, 31:0, minimum_sev_asid, Minimum ASID value that must be used for an SEV-enabled, SEV-ES-disabled guestSignature · 1 line
2.29.2
Borislav Petkov
maintainerRe: [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E
Quoted 3 lines · Feng Tang
Also I'm wondering for some basic leaf and extended leaf which may has different definition for different vendors, do we need to seprate the csv to a general one and vendor specific ones.
Do you know of such?
Because AFAIK vendors own, more or less, each range. Like, Intel owns the base range and AMD the extended so there should be no conflicts actually...
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E
Quoted 10 lines · Borislav Petkov
Quoted 3 lines · Feng Tang
Also I'm wondering for some basic leaf and extended leaf which may has different definition for different vendors, do we need to seprate the csv to a general one and vendor specific ones.
Do you know of such?
Because AFAIK vendors own, more or less, each range. Like, Intel owns the base range and AMD the extended so there should be no conflicts actually...
There are no known conflicts, and all sorts of things would break horribly if any CPU vendor (or hypervsior) were careless enough to redefine a CPUID bit.
Re: [PATCH 2/2] tools/x86/kcpuid: Add AMD leaf 0x8000001E
Hi Boris and Sean,
Quoted 7 lines · Sean Christopherson
Quoted 6 lines · Borislav Petkov
Quoted 3 lines · Feng Tang
Also I'm wondering for some basic leaf and extended leaf which may has different definition for different vendors, do we need to seprate the csv to a general one and vendor specific ones.
Do you know of such?
No. When I read the patch, I googled some doc for the registers definition which I found different from Intel's manual.
Quoted 7 lines
Quoted 4 lines
Because AFAIK vendors own, more or less, each range. Like, Intel owns the base range and AMD the extended so there should be no conflicts actually...
There are no known conflicts, and all sorts of things would break horribly if any CPU vendor (or hypervsior) were careless enough to redefine a CPUID bit.
Great to know these sharing policy between vendors, which will save many troubles for us :)
Also I just took a look at code of cpuid, which has some functions like
print_leafX_vendorA
print_leafX_vendorB
print_leafX_vendorC
but as you mentioned, I didn't find obvious overlaps of specific bits.
Thanks,
Feng
[tip: x86/misc] tools/x86/kcpuid: Add AMD leaf 0x8000001E
In reply to Borislav PetkovThe following commit has been merged into the x86/misc branch of tip:
The following commit has been merged into the x86/misc branch of tip:
Commit-ID: f281854fa743f3474b2d0d69533301f48cf0e184 Gitweb: https://git.kernel.org/tip/f281854fa743f3474b2d0d69533301f48cf0e184 Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 15 Mar 2021 13:55:14 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 18 Mar 2021 11:36:14 +01:00
tools/x86/kcpuid: Add AMD leaf 0x8000001E
Contains core IDs, node IDs and other topology info.
--- tools/arch/x86/kcpuid/cpuid.csv | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
tools/arch/x86/kcpuid/cpuid.csv +18 -8
@@ -379,12 +379,22 @@ 0x80000008, 0, EAX, 15:8, lnr_adr_bits, Linear Address Bits 0x80000007, 0, EBX, 9, wbnoinvd, WBNOINVD +# 0x8000001E +# EAX: Extended APIC ID +0x8000001E, 0, EAX, 31:0, extended_apic_id, Extended APIC ID +# EBX: Core Identifiers +0x8000001E, 0, EBX, 7:0, core_id, Identifies the logical core ID +0x8000001E, 0, EBX, 15:8, threads_per_core, The number of threads per core is threads_per_core + 1 +# ECX: Node Identifiers +0x8000001E, 0, ECX, 7:0, node_id, Node ID +0x8000001E, 0, ECX, 10:8, nodes_per_processor, Nodes per processor { 0: 1 node, else reserved } + # 8000001F: AMD Secure Encryption -0x8000001F, 0, EAX, 0, sme, Secure Memory Encryption -0x8000001F, 0, EAX, 1, sev, Secure Encrypted Virtualization -0x8000001F, 0, EAX, 2, vmpgflush, VM Page Flush MSR -0x8000001F, 0, EAX, 3, seves, SEV Encrypted State -0x8000001F, 0, EBX, 5:0, c-bit, Page table bit number used to enable memory encryption -0x8000001F, 0, EBX, 11:6, mem_encrypt_physaddr_width, Reduction of physical address space in bits with SME enabled -0x8000001F, 0, ECX, 31:0, num_encrypted_guests, Maximum ASID value that may be used for an SEV-enabled guest -0x8000001F, 0, EDX, 31:0, minimum_sev_asid, Minimum ASID value that must be used for an SEV-enabled, SEV-ES-disabled guest +0x8000001F, 0, EAX, 0, sme, Secure Memory Encryption +0x8000001F, 0, EAX, 1, sev, Secure Encrypted Virtualization +0x8000001F, 0, EAX, 2, vmpgflush, VM Page Flush MSR +0x8000001F, 0, EAX, 3, seves, SEV Encrypted State +0x8000001F, 0, EBX, 5:0, c-bit, Page table bit number used to enable memory encryption +0x8000001F, 0, EBX, 11:6, mem_encrypt_physaddr_width, Reduction of physical address space in bits with SME enabled +0x8000001F, 0, ECX, 31:0, num_encrypted_guests, Maximum ASID value that may be used for an SEV-enabled guest +0x8000001F, 0, EDX, 31:0, minimum_sev_asid, Minimum ASID value that must be used for an SEV-enabled, SEV-ES-disabled guest
The following commit has been merged into the x86/misc branch of tip:
The following commit has been merged into the x86/misc branch of tip:
Commit-ID: e20f67026b5ead2afc5627e98b45e6b65e7fb38c Gitweb: https://git.kernel.org/tip/e20f67026b5ead2afc5627e98b45e6b65e7fb38c Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 15 Mar 2021 13:08:35 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 18 Mar 2021 11:36:01 +01:00
tools/x86/kcpuid: Check last token too
Input lines like
0x8000001E, 0, EAX, 31:0, Extended APIC ID
where the short name is missing lead to a segfault because the loop takes the long name for the short name and tokens[5] becomes NULL which explodes later in strcpy().
Check its value too before further processing.
--- tools/arch/x86/kcpuid/kcpuid.c | 2 ++ 1 file changed, 2 insertions(+)
tools/arch/x86/kcpuid/kcpuid.c +2 -0
@@ -324,6 +324,8 @@ static int parse_line(char *line) str =NULL ; } tokens[5 ] =strtok (str,"\n" ); +if (!tokens[5 ]) + goto err_exit;/* index/main-leaf */ index =strtoull (tokens[0 ],NULL ,0 );