x86: use the correct function type for native_set_fixmap
PATCH 1/1 x86: use the correct function type for native_set_fixmap
We call native_set_fixmap indirectly through the function pointer struct pv_mmu_ops::set_fixmap, which expects the first parameter to be 'unsigned' instead of 'enum fixed_addresses'. This patch changes the function type for native_set_fixmap to match the pointer, which fixes indirect call mismatches with Control-Flow Integrity (CFI) checking.
--- arch/x86/include/asm/fixmap.h | 2 +- arch/x86/mm/pgtable.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/fixmap.h +1 -1
@@ -157,7 +157,7 @@ extern pte_t *kmap_pte;extern pte_t *pkmap_page_table;void __native_set_fixmap (enum fixed_addresses idx,pte_t pte); -void native_set_fixmap (enum fixed_addresses idx, +void native_set_fixmap (unsigned /* enum fixed_addresses */ idx,phys_addr_t phys,pgprot_t flags);#ifndef CONFIG_PARAVIRT_XXL
arch/x86/mm/pgtable.c +2 -2
@@ -647,8 +647,8 @@ void __native_set_fixmap(enum fixed_addresses idx, pte_t pte) fixmaps_set++; } -void native_set_fixmap (enum fixed_addresses idx,phys_addr_t phys, -pgprot_t flags) +void native_set_fixmap (unsigned /* enum fixed_addresses */ idx, +phys_addr_t phys,pgprot_t flags) {/* Sanitize 'prot' against any unsupported bits: */ pgprot_val (flags) &= __default_kernel_pte_mask;
Signature · 1 line
2.23.0.237.gc6a4ce50a0-goog
Quoted 7 lines · Sami Tolvanen
We call
native_set_fixmapindirectly through the function pointer structpv_mmu_ops::set_fixmap, which expects the first parameter to be 'unsigned' instead of 'enumfixed_addresses'. This patch changes the function type fornative_set_fixmapto match the pointer, which fixes indirect call mismatches with Control-Flow Integrity (CFI) checking.Signed-off-by Sami Tolvanen <[email protected]>
Is it correct that pv_mmu_ops can't be changed since this is an external API?
Assuming so, then:
-Kees
Quoted 36 lines
--- arch/x86/include/asm/fixmap.h | 2 +- arch/x86/mm/pgtable.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)arch/x86/include/asm/fixmap.h +1
-1@@ -157,7 +157,7 @@ extern pte_t *kmap_pte;extern pte_t *pkmap_page_table;void __native_set_fixmap (enum fixed_addresses idx,pte_t pte); -void native_set_fixmap (enum fixed_addresses idx, +void native_set_fixmap (unsigned /* enum fixed_addresses */ idx,phys_addr_t phys,pgprot_t flags);#ifndef CONFIG_PARAVIRT_XXL arch/x86/mm/pgtable.c +2
-2@@ -647,8 +647,8 @@ void __native_set_fixmap(enum fixed_addresses idx, pte_t pte) fixmaps_set++; } -void native_set_fixmap (enum fixed_addresses idx,phys_addr_t phys, -pgprot_t flags) +void native_set_fixmap (unsigned /* enum fixed_addresses */ idx, +phys_addr_t phys,pgprot_t flags) {/* Sanitize 'prot' against any unsupported bits: */ pgprot_val (flags) &= __default_kernel_pte_mask;Signature · 1 line
2.23.0.237.gc6a4ce50a0-goog
Signature · 1 line
Kees Cook
Quoted 2 lines · Kees Cook
Is it correct that
pv_mmu_opscan't be changed since this is an external API?
Someone else probably knows better, but yes, we could also fix this by changing set_fixmap to accept enum fixed_addresses as the first parameter, and changing the type of xen_set_fixmap instead.
Sami
Quoted 3 lines · Sami Tolvanen
Someone else probably knows better, but yes, we could also fix this by changing
set_fixmapto accept enumfixed_addressesas the first parameter, and changing the type ofxen_set_fixmapinstead.
This approach is actually more problematic since we cannot forward declare an enum in C and including <asm/fixmap.h> here results in a ton of other missing dependencies. I assume this is why the callback function accepts unsigned in the first place.
Sami
[tip: x86/entry] x86/mm: Use the correct function type for native_set_fixmap()
In reply to Sami TolvanenThe following commit has been merged into the x86/entry branch of tip:
The following commit has been merged into the x86/entry branch of tip:
Commit-ID: f53e2cd0b8ab7d9e390414470bdbd830f660133f Gitweb: https://git.kernel.org/tip/f53e2cd0b8ab7d9e390414470bdbd830f660133f Author: Sami Tolvanen <[email protected]> AuthorDate: Fri, 13 Sep 2019 14:14:02 -07:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 11 Oct 2019 12:52:32 +02:00
x86/mm: Use the correct function type for native_set_fixmap()
We call native_set_fixmap indirectly through the function pointer struct pv_mmu_ops::set_fixmap, which expects the first parameter to be 'unsigned' instead of 'enum fixed_addresses'. This patch changes the function type for native_set_fixmap to match the pointer, which fixes indirect call mismatches with Control-Flow Integrity (CFI) checking.
--- arch/x86/include/asm/fixmap.h | 2 +- arch/x86/mm/pgtable.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/fixmap.h +1 -1
@@ -156,7 +156,7 @@ extern pte_t *kmap_pte;extern pte_t *pkmap_page_table;void __native_set_fixmap (enum fixed_addresses idx,pte_t pte); -void native_set_fixmap (enum fixed_addresses idx, +void native_set_fixmap (unsigned /* enum fixed_addresses */ idx,phys_addr_t phys,pgprot_t flags);#ifndef CONFIG_PARAVIRT_XXL
arch/x86/mm/pgtable.c +2 -2
@@ -643,8 +643,8 @@ void __native_set_fixmap(enum fixed_addresses idx, pte_t pte) fixmaps_set++; } -void native_set_fixmap (enum fixed_addresses idx,phys_addr_t phys, -pgprot_t flags) +void native_set_fixmap (unsigned /* enum fixed_addresses */ idx, +phys_addr_t phys,pgprot_t flags) {/* Sanitize 'prot' against any unsupported bits: */ pgprot_val (flags) &= __default_kernel_pte_mask;