Skip to contentSkip to conversation

x86/e820: fix the function type for e820__mapped_all

PATCH Superseded Sami Tolvanen 3 participants 6 messages Nov 13, 2020 – Nov 30, 2020 x86

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/e820: fix the function type for e820__mapped_all

e820__mapped_all is passed as a callback to is_mmconf_reserved, which expects a function of type:

typedef bool (*check_reserved_t)(u64 start, u64 end, unsigned type);

This trips indirect call checking with Clang's Control-Flow Integrity (CFI). Change the last argument from enum e820_type to unsigned to fix the type mismatch.

---
 arch/x86/include/asm/e820/api.h | 2 +-
 arch/x86/kernel/e820.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/e820/api.h +1 -1
index e8f58ddd06d9..e872a796619d 100644
@@ -12,7 +12,7 @@ extern unsigned long pci_mem_start;
 
 extern bool e820__mapped_raw_any(u64 start, u64 end, enum e820_type type);
 extern bool e820__mapped_any(u64 start, u64 end, enum e820_type type);
-extern bool e820__mapped_all(u64 start, u64 end, enum e820_type type);
+extern bool e820__mapped_all(u64 start, u64 end, unsigned type);
 
 extern void e820__range_add   (u64 start, u64 size, enum e820_type type);
 extern u64  e820__range_update(u64 start, u64 size, enum e820_type old_type, enum e820_type new_type);
arch/x86/kernel/e820.c +1 -1
index 22aad412f965..9f6a4e9bca4c 100644
@@ -145,7 +145,7 @@ static struct e820_entry *__e820__mapped_all(u64 start, u64 end,
 /*
  * This function checks if the entire range <start,end> is mapped with type.
  */
-bool __init e820__mapped_all(u64 start, u64 end, enum e820_type type)
+bool __init e820__mapped_all(u64 start, u64 end, unsigned type)
 {
 	return __e820__mapped_all(start, end, type);
 }

base-commit: 585e5b17b92dead8a3aca4e3c9876fbca5f7e0ba

Signature · 1 line
2.29.2.299.gdc1121823c-goog
#1 lore raw
Quoted 8 lines · Sami Tolvanen

e820__mapped_all is passed as a callback to is_mmconf_reserved, which expects a function of type:

typedef bool (*check_reserved_t)(u64 start, u64 end, unsigned type);

This trips indirect call checking with Clang's Control-Flow Integrity (CFI). Change the last argument from enum e820_type to unsigned to fix the type mismatch.

Hi,

Kernel style is no raw unsigned -- use unsigned int or unsigned long, please.

checkpatch should or could have found that issue.

Quoted 36 lines
---
 arch/x86/include/asm/e820/api.h | 2 +-
 arch/x86/kernel/e820.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/e820/api.h +1 -1
index e8f58ddd06d9..e872a796619d 100644
@@ -12,7 +12,7 @@ extern unsigned long pci_mem_start;
 
 extern bool e820__mapped_raw_any(u64 start, u64 end, enum e820_type type);
 extern bool e820__mapped_any(u64 start, u64 end, enum e820_type type);
-extern bool e820__mapped_all(u64 start, u64 end, enum e820_type type);
+extern bool e820__mapped_all(u64 start, u64 end, unsigned type);
 
 extern void e820__range_add   (u64 start, u64 size, enum e820_type type);
 extern u64  e820__range_update(u64 start, u64 size, enum e820_type old_type, enum e820_type new_type);
arch/x86/kernel/e820.c +1 -1
index 22aad412f965..9f6a4e9bca4c 100644
@@ -145,7 +145,7 @@ static struct e820_entry *__e820__mapped_all(u64 start, u64 end,
 /*
  * This function checks if the entire range <start,end> is mapped with type.
  */
-bool __init e820__mapped_all(u64 start, u64 end, enum e820_type type)
+bool __init e820__mapped_all(u64 start, u64 end, unsigned type)
 {
 	return __e820__mapped_all(start, end, type);
 }

base-commit: 585e5b17b92dead8a3aca4e3c9876fbca5f7e0ba

Signature · 1 line
~Randy
#2 lore raw
Quoted 11 lines · Randy Dunlap
Quoted 8 lines · Sami Tolvanen

e820__mapped_all is passed as a callback to is_mmconf_reserved, which expects a function of type:

typedef bool (*check_reserved_t)(u64 start, u64 end, unsigned type);

This trips indirect call checking with Clang's Control-Flow Integrity (CFI). Change the last argument from enum e820_type to unsigned to fix the type mismatch.

Quoted 5 lines

Hi,

Kernel style is no raw unsigned -- use unsigned int or unsigned long, please.

checkpatch should or could have found that issue.

It did, but the existing type definition for the callback in pci/mmconfig-shared.c uses raw unsigned. I can add a patch to change that to unsigned int as well, if you prefer.

Sami

#3 lore raw
Quoted 14 lines · Sami Tolvanen
Quoted 13 lines · Randy Dunlap
Quoted 8 lines · Sami Tolvanen

e820__mapped_all is passed as a callback to is_mmconf_reserved, which expects a function of type:

typedef bool (*check_reserved_t)(u64 start, u64 end, unsigned type);

This trips indirect call checking with Clang's Control-Flow Integrity (CFI). Change the last argument from enum e820_type to unsigned to fix the type mismatch.

Hi,

Quoted 7 lines
Quoted 3 lines

Kernel style is no raw unsigned -- use unsigned int or unsigned long, please.

checkpatch should or could have found that issue.

It did, but the existing type definition for the callback in pci/mmconfig-shared.c uses raw unsigned. I can add a patch to change that to unsigned int as well, if you prefer.

Hm. :)
Well, yes, I prefer, but I can't require it.

thanks for the explanation.

Signature · 1 line
~Randy
maintainer
#4 lore raw
In reply to Sami Tolvanen
Quoted 21 lines · Sami Tolvanen

e820__mapped_all is passed as a callback to is_mmconf_reserved, which expects a function of type:

typedef bool (*check_reserved_t)(u64 start, u64 end, unsigned type);

This trips indirect call checking with Clang's Control-Flow Integrity (CFI). Change the last argument from enum e820_type to unsigned to fix the type mismatch.

---
 arch/x86/include/asm/e820/api.h | 2 +-
 arch/x86/kernel/e820.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/e820/api.h +0 -0
index e8f58ddd06d9..e872a796619d 100644

arch/x86/include/asm/e820/api.h extern unsigned long pci_mem_start; · line 15

Quoted 5 lines
arch/x86/include/asm/e820/api.h +1 -1
@@ -12,7 +12,7 @@ extern unsigned long pci_mem_start;
 
 extern bool e820__mapped_raw_any(u64 start, u64 end, enum e820_type type);
 extern bool e820__mapped_any(u64 start, u64 end, enum e820_type type);
-extern bool e820__mapped_all(u64 start, u64 end, enum e820_type type);
+extern bool e820__mapped_all(u64 start, u64 end, unsigned type);

I think the proper fix is to fix the typedef to:

	typedef bool (*check_reserved_t)(u64 start, u64 end, enum e820_type type);

because

* is_mmconf_reserved() is passing in E820_TYPE_RESERVED which is enum e820_type

* is_acpi_reserved() is the other check_reserved_t function ptr and the last arg type there is unused so it can just as well be enum e820_type.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#5 lore raw
Quoted 10 lines · Borislav Petkov

I think the proper fix is to fix the typedef to:

        typedef bool (*check_reserved_t)(u64 start, u64 end, enum e820_type type);

because

* is_mmconf_reserved() is passing in E820_TYPE_RESERVED which is enum e820_type

* is_acpi_reserved() is the other check_reserved_t function ptr and the last arg type there is unused so it can just as well be enum e820_type.

Sure, sounds good. I'll send out v3 to change the type argument to enum e820_type.

Sami