Skip to contentSkip to conversation

x86: use the correct function type for native_set_fixmap

PATCH Applied Sami Tolvanen 3 participants 5 messages Sep 13, 2019 – Oct 11, 2019

Subsystems (2)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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
index 9da8cccdf3fb..6a295acd3de6 100644
@@ -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
index 44816ff6411f..d0ad35e3de74 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Sami Tolvanen

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.

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
index 9da8cccdf3fb..6a295acd3de6 100644
@@ -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
index 44816ff6411f..d0ad35e3de74 100644
@@ -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
#2 lore raw
Quoted 2 lines · Kees Cook

Is it correct that pv_mmu_ops can'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

#3 lore raw
Quoted 3 lines · Sami Tolvanen

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.

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

merge bot Applied
#4 lore raw

[tip: x86/entry] x86/mm: Use the correct function type for native_set_fixmap()

In reply to Sami Tolvanen
The 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.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc H . Peter Anvin <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 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
index 0c47aa8..28183ee 100644
@@ -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
index 3e4b903..7bd2c3a 100644
@@ -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;