const char *name)
> +{
> + /*
> +* Since all syscall functions have __riscv_ prefix, we must skip it.
> +* However, as we described above, we decided to ignore compat
> +* syscalls, so we don't care about __riscv_compat_ prefix here.
> +*/
> + return !strcmp(sym + 8, name);
> +}
Good catch, thanks for fixing this!
Reviewed-by: Sami Tolvanen
Sami
On Tue, Apr 20, 2021 at 12:48 PM Josh Poimboeuf wrote:
>
> On Fri, Apr 16, 2021 at 01:38:31PM -0700, Sami Tolvanen wrote:
> > +static int fix_cfi_relocs(const struct elf *elf)
> > +{
> > + struct section *sec, *tmpsec;
> > +
On Tue, Apr 20, 2021 at 11:14 AM Josh Poimboeuf wrote:
>
> On Fri, Apr 16, 2021 at 01:38:30PM -0700, Sami Tolvanen wrote:
> > With -ffunction-sections, Clang can generate a jump beyond the end of
> > a section when the section ends in an unreachable instruction.
>
> Why?
On Sat, Apr 17, 2021 at 4:37 AM Peter Zijlstra wrote:
>
> On Fri, Apr 16, 2021 at 01:38:38PM -0700, Sami Tolvanen wrote:
> > From: Kees Cook
> >
> > Instead of using inline asm for the int3 selftest (which confuses the
> > Clang's ThinLTO pass), this restores the
On Sun, Apr 18, 2021 at 3:57 PM Andy Lutomirski wrote:
>
> On Sun, Apr 18, 2021 at 9:17 AM Thomas Gleixner wrote:
> >
> > On Sat, Apr 17 2021 at 17:11, Andy Lutomirski wrote:
> > > On Sat, Apr 17, 2021 at 4:53 PM Thomas Gleixner
> > > wrote:
> > >> which works for
> > >>
> > >> foo =
On Sat, Apr 17, 2021 at 3:16 AM Thomas Gleixner wrote:
>
> On Sat, Apr 17 2021 at 01:02, Thomas Gleixner wrote:
> > On Fri, Apr 16 2021 at 15:37, Kees Cook wrote:
> >
> >> On Fri, Apr 16, 2021 at 03:20:17PM -0700, Andy Lutomirski wrote:
> >>> But obviously there is code that needs real function
On Fri, Apr 16, 2021 at 2:18 PM Borislav Petkov wrote:
>
> On Fri, Apr 16, 2021 at 01:38:34PM -0700, Sami Tolvanen wrote:
> > With CONFIG_CFI_CLANG, the compiler replaces function addresses in
> > instrumented C code with jump table addresses. This change implements
> > th
Select ARCH_SUPPORTS_CFI_CLANG to allow CFI to be enabled.
Signed-off-by: Sami Tolvanen
---
arch/x86/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index bf69d07e46b8..81d2dc568e56 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -106,6
-by: Sami Tolvanen
---
arch/x86/kernel/kprobes/opt.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index 71425ebba98a..95375ef5deee 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
Ignore the __typeid__ relocations generated with CONFIG_CFI_CLANG
when loading modules.
Signed-off-by: Sami Tolvanen
---
arch/x86/kernel/module.c | 4
1 file changed, 4 insertions(+)
diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
index 5e9a34b5bd74..c4aeba237eef 100644
Allow LTO to be used for cpu.c when CONFIG_CFI_CLANG is enabled to avoid
indirect call failures. CFI requires Clang >= 12, which doesn't have the
stack protector inlining bug.
Signed-off-by: Sami Tolvanen
---
arch/x86/power/Makefile | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/
From: Kees Cook
The __typeid__* symbols aren't actually relocations, so they can be
ignored during relocation generation.
Signed-off-by: Kees Cook
Signed-off-by: Sami Tolvanen
---
arch/x86/tools/relocs.c | 7 +++
1 file changed, 7 insertions(+)
diff --git a/arch/x86/tools/relocs.c b
Disable CONFIG_CFI_CLANG for the stand-alone purgatory.ro.
Signed-off-by: Sami Tolvanen
---
arch/x86/purgatory/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
index 95ea17a9d20c..ed46ad780130 100644
Signed-off-by: Sami Tolvanen
---
arch/x86/mm/extable.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index b93d6cd08a7f..a7eae1c4c59f 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -155,6 +155,7 @@ enum handler_type
ecc606103837 ("x86/alternatives: Fix int3_emulate_call() selftest stack
corruption") without using inline asm.
Signed-off-by: Kees Cook
Signed-off-by: Sami Tolvanen
---
arch/x86/kernel/alternative.c | 21 -
1 file changed, 4 insertions(+), 17 deletions(-)
diff --git
renaming them.
Signed-off-by: Sami Tolvanen
---
kernel/static_call.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/static_call.c b/kernel/static_call.c
index 723fcc9d20db..d09f500c2d2a 100644
--- a/kernel/static_call.c
+++ b/kernel/static_call.c
@@ -503,12 +503,12
-by: Sami Tolvanen
---
include/linux/objtool.h | 5 +
tools/include/linux/objtool.h | 5 +
2 files changed, 10 insertions(+)
diff --git a/include/linux/objtool.h b/include/linux/objtool.h
index 7e72d975cb76..2f29ce48ab5f 100644
--- a/include/linux/objtool.h
+++ b/include/linux
With CONFIG_CFI_CLANG, the compiler replaces the __fentry__ address in
MCOUNT_ADDR with the address of a CFI jump table. Use function_nocfi()
to get the actual function address.
Signed-off-by: Sami Tolvanen
---
arch/x86/include/asm/ftrace.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion
entry points.
Reported-by: Sedat Dilek
Signed-off-by: Sami Tolvanen
Tested-by: Sedat Dilek
---
arch/x86/include/asm/desc.h | 8 +++-
arch/x86/kernel/Makefile | 3 +++
arch/x86/kernel/cpu/common.c | 8
arch/x86/kernel/idt.c| 2 +-
arch/x86/kernel/traps.c | 2
With CONFIG_CFI_CLANG, the compiler replaces function addresses in
instrumented C code with jump table addresses. This change implements
the function_nocfi() macro, which returns the actual function address
instead.
Signed-off-by: Sami Tolvanen
---
arch/x86/include/asm/page.h | 14
://lore.kernel.org/r/d743f4b36e120c06506567a9f87a062ae03da47f.1611263462.git.jpoim...@redhat.com/
Reported-by: Sedat Dilek
Suggested-by: Josh Poimboeuf
Signed-off-by: Sami Tolvanen
---
tools/objtool/elf.c | 48 +
tools/objtool/include/objtool/elf.h | 2 +-
2
With -ffunction-sections, Clang can generate a jump beyond the end of
a section when the section ends in an unreachable instruction. If the
offset matches the section length, use the last instruction as the
jump destination.
Signed-off-by: Sami Tolvanen
---
tools/objtool/check.c | 4
1
/alternatives: Use C int3 selftest but disable KASAN
x86, relocs: Ignore __typeid__ relocations
Sami Tolvanen (12):
objtool: Find a destination for jumps beyond the section end
objtool: Add CONFIG_CFI_CLANG support
objtool: Add ASM_STACK_FRAME_NON_STANDARD
static_call: Use global functions
On Thu, Apr 15, 2021 at 7:02 AM Catalin Marinas wrote:
>
> On Thu, Apr 15, 2021 at 06:25:57AM -0700, Nathan Chancellor wrote:
> > On Thu, Apr 15, 2021 at 10:17:43AM +0100, Catalin Marinas wrote:
> > > On Tue, Apr 13, 2021 at 05:08:04PM -0700, Nathan Chancellor wrote:
> > > > After commit
.org. - (664b-663b) + (662b-661b)
> + .org. - (662b-661b) + (664b-663b)
> .if .Lasm_alt_mode==0
> .previous
> .endif
> - .org. - (664b-663b) + (662b-661b)
> - .org. - (662b-661b) + (664b-663b)
> .endm
>
> /*
Thank
Disable CFI for the nVHE code to avoid address space confusion.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Tested-by: Nathan Chancellor
---
arch/arm64/kvm/hyp/nvhe/Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b
Select ARCH_SUPPORTS_CFI_CLANG to allow CFI to be enabled.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Tested-by: Nathan Chancellor
---
arch/arm64/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index e4e1b6550115..d7395772b6b8
around the issue.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Tested-by: Nathan Chancellor
---
arch/arm64/kernel/alternative.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c
index 1184c44ea2c7
Signed-off-by: Sami Tolvanen
Acked-by: Mark Rutland
Tested-by: Nathan Chancellor
---
arch/arm64/kernel/ftrace.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c
index 86a5cf9bc19a..b5d3ddaf69d9 100644
--- a/arch/arm64
Disable CFI checking for functions that switch to linear mapping and
make an indirect call to a physical address, since the compiler only
understands virtual addresses and the CFI check for such indirect calls
would always fail.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Tested
to the function's virtual
address. Therefore, use the function_nocfi() macro to ensure we are
always taking the address of the actual function instead.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Acked-by: Mark Rutland
Tested-by: Nathan Chancellor
---
arch/arm64/include/asm/mmu_context.h
With CONFIG_CFI_CLANG, the compiler replaces function addresses in
instrumented C code with jump table addresses. This change implements
the function_nocfi() macro, which returns the actual function address
instead.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Acked-by: Mark Rutland
function_nocfi to get the actual address of
cpu_resume.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Acked-by: Mark Rutland
Tested-by: Nathan Chancellor
---
drivers/firmware/psci/psci.c | 7 +--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/firmware/psci/psci.c b
To ensure we take the actual address of a function in kernel text,
use function_nocfi. Otherwise, with CONFIG_CFI_CLANG, the compiler
replaces the address with a pointer to the CFI jump table, which is
actually in the module when compiled with CONFIG_LKDTM=m.
Signed-off-by: Sami Tolvanen
Acked
the
list_cmp_func_t type and changes the comparison function types of
all list_sort() callers to use const pointers, thus avoiding type
mismatches.
Suggested-by: Nick Desaulniers
Signed-off-by: Sami Tolvanen
Reviewed-by: Nick Desaulniers
Reviewed-by: Christoph Hellwig
Reviewed-by: Kees Cook
Tested
BPF dispatcher functions are patched at runtime to perform direct
instead of indirect calls. Disable CFI for the dispatcher functions to
avoid conflicts.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Tested-by: Nathan Chancellor
---
include/linux/bpf.h | 4 ++--
1 file changed, 2
With CONFIG_CFI_CLANG and ThinLTO, Clang appends a hash to the names
of all static functions not marked __used. This can break userspace
tools that don't expect the function name to change, so strip out the
hash from the output.
Suggested-by: Jack Pham
Signed-off-by: Sami Tolvanen
Reviewed
ion != ktead_delayed_work_timer_fn);
Use WARN_ON_FUNCTION_MISMATCH() instead to disable the warning
when CFI and modules are both enabled.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Tested-by: Nathan Chancellor
---
kernel/kthread.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/ker
_fn);
Use WARN_ON_FUNCTION_MISMATCH() instead to disable the warning
when CFI and modules are both enabled.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Tested-by: Nathan Chancellor
---
kernel/workqueue.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/workqueue.
and
alignment. It also discards the .eh_frame section, which Clang can
generate with certain sanitizers, such as CFI.
Link: https://bugs.llvm.org/show_bug.cgi?id=46293
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Acked-by: Jessica Yu
Tested-by: Nathan Chancellor
---
scripts/module.lds.S | 19
compiler instrumentation.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Acked-by: Mark Rutland
Tested-by: Nathan Chancellor
---
include/linux/mm.h | 10 ++
1 file changed, 10 insertions(+)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8ba434287387..22cce9c7dd05 100644
taken in assembly, or other non-instrumented
code always points to the jump table and therefore, can be used for
indirect calls in instrumented code without tripping CFI checks.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Acked-by: Bjorn Helgaas# pci.h
Tested-by: Nathan Chancellor
, where the
kernel prints out a rate-limited warning instead, and allows execution
to continue. This option is helpful for locating type mismatches, but
should only be enabled during development.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Tested-by: Nathan Chancellor
---
Makefile
/workqueue.c to use the macro instead.
Sami Tolvanen (18):
add support for Clang CFI
cfi: add __cficanonical
mm: add generic function_nocfi macro
module: ensure __cfi_check alignment
workqueue: use WARN_ON_FUNCTION_MISMATCH
kthread: use WARN_ON_FUNCTION_MISMATCH
kallsyms: strip ThinLTO hashes
On Tue, Apr 6, 2021 at 4:54 AM Mark Rutland wrote:
>
> [adding Ard for EFI runtime services bits]
>
> On Thu, Apr 01, 2021 at 04:32:12PM -0700, Sami Tolvanen wrote:
> > Disable CFI checking for functions that switch to linear mapping and
> > make an indirect call to a
On Tue, Apr 6, 2021 at 4:37 AM Mark Rutland wrote:
>
> On Thu, Apr 01, 2021 at 04:32:10PM -0700, Sami Tolvanen wrote:
> > With CONFIG_CFI_CLANG, the compiler replaces function addresses in
> > instrumented C code with jump table addresses. This change implements
> > th
On Fri, Apr 2, 2021 at 5:40 AM Alexander Lobakin wrote:
>
> When building with CONFIG_LD_DEAD_CODE_DATA_ELIMINATION,
> -fdata-sections and -ffunction-sections are being enabled by the
> top-level Makefile, and module section merging is also needed.
> Expand the ifdef (and the comment block) to
around the issue.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/kernel/alternative.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c
index 1184c44ea2c7..abc84636af07 100644
--- a/arch
Signed-off-by: Sami Tolvanen
---
arch/arm64/kernel/ftrace.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c
index 86a5cf9bc19a..b5d3ddaf69d9 100644
--- a/arch/arm64/kernel/ftrace.c
+++ b/arch/arm64/kernel/ftrace.c
@@ -55,7
Disable CFI for the nVHE code to avoid address space confusion.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/kvm/hyp/nvhe/Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile
Select ARCH_SUPPORTS_CFI_CLANG to allow CFI to be enabled.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index e4e1b6550115..d7395772b6b8 100644
--- a/arch/arm64/Kconfig
to the function's virtual
address. Therefore, use the function_nocfi() macro to ensure we are
always taking the address of the actual function instead.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/include/asm/mmu_context.h | 2 +-
arch/arm64/kernel/acpi_parking_protocol.c | 3
With CONFIG_CFI_CLANG, the compiler replaces function addresses in
instrumented C code with jump table addresses. This change implements
the function_nocfi() macro, which returns the actual function address
instead.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/include/asm
Disable CFI checking for functions that switch to linear mapping and
make an indirect call to a physical address, since the compiler only
understands virtual addresses and the CFI check for such indirect calls
would always fail.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch
function_nocfi to get the actual address of
cpu_resume.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
drivers/firmware/psci/psci.c | 7 +--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c
index f5fc429cae3f
To ensure we take the actual address of a function in kernel text,
use function_nocfi. Otherwise, with CONFIG_CFI_CLANG, the compiler
replaces the address with a pointer to the CFI jump table, which is
actually in the module when compiled with CONFIG_LKDTM=m.
Signed-off-by: Sami Tolvanen
Acked
With CONFIG_CFI_CLANG and ThinLTO, Clang appends a hash to the names
of all static functions not marked __used. This can break userspace
tools that don't expect the function name to change, so strip out the
hash from the output.
Suggested-by: Jack Pham
Signed-off-by: Sami Tolvanen
Reviewed
the
list_cmp_func_t type and changes the comparison function types of
all list_sort() callers to use const pointers, thus avoiding type
mismatches.
Suggested-by: Nick Desaulniers
Signed-off-by: Sami Tolvanen
Reviewed-by: Nick Desaulniers
Tested-by: Nick Desaulniers
Reviewed-by: Christoph Hellwig
BPF dispatcher functions are patched at runtime to perform direct
instead of indirect calls. Disable CFI for the dispatcher functions to
avoid conflicts.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
include/linux/bpf.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff
_fn);
Use WARN_ON_FUNCTION_MISMATCH() instead to disable the warning
when CFI and modules are both enabled.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
kernel/workqueue.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
in
ion != ktead_delayed_work_timer_fn);
Use WARN_ON_FUNCTION_MISMATCH() instead to disable the warning
when CFI and modules are both enabled.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
kernel/kthread.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/kthread.c b/kernel/kthrea
and
alignment. It also discards the .eh_frame section, which Clang can
generate with certain sanitizers, such as CFI.
Link: https://bugs.llvm.org/show_bug.cgi?id=46293
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Acked-by: Jessica Yu
---
scripts/module.lds.S | 19 ++-
1 file changed
compiler instrumentation.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
include/linux/mm.h | 10 ++
1 file changed, 10 insertions(+)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8ba434287387..22cce9c7dd05 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
taken in assembly, or other non-instrumented
code always points to the jump table and therefore, can be used for
indirect calls in instrumented code without tripping CFI checks.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Acked-by: Bjorn Helgaas# pci.h
---
include/linux/compiler
, where the
kernel prints out a rate-limited warning instead, and allows execution
to continue. This option is helpful for locating type mismatches, but
should only be enabled during development.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
Makefile | 17 ++
arch
to synchronize_rcu() in update_shadow().
Changes in v2:
- Fixed .text merging in module.lds.S.
- Added WARN_ON_FUNCTION_MISMATCH() and changed kernel/thread.c
and kernel/workqueue.c to use the macro instead.
Sami Tolvanen (18):
add support for Clang CFI
cfi: add __cficanonical
mm: add generic
Disable CFI for the nVHE code to avoid address space confusion.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/kvm/hyp/nvhe/Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile
around the issue.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/kernel/alternative.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c
index 1184c44ea2c7..abc84636af07 100644
--- a/arch
Select ARCH_SUPPORTS_CFI_CLANG to allow CFI to be enabled.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index e4e1b6550115..d7395772b6b8 100644
--- a/arch/arm64/Kconfig
To ensure we take the actual address of a function in kernel text,
use function_nocfi. Otherwise, with CONFIG_CFI_CLANG, the compiler
replaces the address with a pointer to the CFI jump table, which is
actually in the module when compiled with CONFIG_LKDTM=m.
Signed-off-by: Sami Tolvanen
Acked
Disable CFI checking for functions that switch to linear mapping and
make an indirect call to a physical address, since the compiler only
understands virtual addresses and the CFI check for such indirect calls
would always fail.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch
With CONFIG_CFI_CLANG, the compiler replaces function addresses in
instrumented C code with jump table addresses. This change implements
the function_nocfi() macro, which returns the actual function address
instead.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/include/asm
function_nocfi to get the actual address of
cpu_resume.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
drivers/firmware/psci/psci.c | 7 +--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c
index f5fc429cae3f
to the function's virtual
address. Therefore, use the function_nocfi() macro to ensure we are
always taking the address of the actual function instead.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/include/asm/mmu_context.h | 2 +-
arch/arm64/kernel/acpi_parking_protocol.c | 3
With CONFIG_CFI_CLANG and ThinLTO, Clang appends a hash to the names
of all static functions not marked __used. This can break userspace
tools that don't expect the function name to change, so strip out the
hash from the output.
Suggested-by: Jack Pham
Signed-off-by: Sami Tolvanen
Reviewed
the
list_cmp_func_t type and changes the comparison function types of
all list_sort() callers to use const pointers, thus avoiding type
mismatches.
Suggested-by: Nick Desaulniers
Signed-off-by: Sami Tolvanen
Reviewed-by: Nick Desaulniers
Tested-by: Nick Desaulniers
Reviewed-by: Christoph Hellwig
BPF dispatcher functions are patched at runtime to perform direct
instead of indirect calls. Disable CFI for the dispatcher functions to
avoid conflicts.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
include/linux/bpf.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff
ion != ktead_delayed_work_timer_fn);
Use WARN_ON_FUNCTION_MISMATCH() instead to disable the warning
when CFI and modules are both enabled.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
kernel/kthread.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/kthread.c b/kernel/kthrea
and
alignment. It also discards the .eh_frame section, which Clang can
generate with certain sanitizers, such as CFI.
Link: https://bugs.llvm.org/show_bug.cgi?id=46293
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Acked-by: Jessica Yu
---
scripts/module.lds.S | 20 +++-
1 file changed
compiler instrumentation.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
include/linux/mm.h | 10 ++
1 file changed, 10 insertions(+)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 8ba434287387..22cce9c7dd05 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
_fn);
Use WARN_ON_FUNCTION_MISMATCH() instead to disable the warning
when CFI and modules are both enabled.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
kernel/workqueue.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
in
taken in assembly, or other non-instrumented
code always points to the jump table and therefore, can be used for
indirect calls in instrumented code without tripping CFI checks.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
Acked-by: Bjorn Helgaas# pci.h
---
include/linux/compiler
, where the
kernel prints out a rate-limited warning instead, and allows execution
to continue. This option is helpful for locating type mismatches, but
should only be enabled during development.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
Makefile | 17 ++
arch
/workqueue.c to use the macro instead.
Sami Tolvanen (17):
add support for Clang CFI
cfi: add __cficanonical
mm: add generic function_nocfi macro
module: ensure __cfi_check alignment
workqueue: use WARN_ON_FUNCTION_MISMATCH
kthread: use WARN_ON_FUNCTION_MISMATCH
kallsyms: strip
On Thu, Mar 25, 2021 at 3:38 AM Mark Rutland wrote:
>
> On Tue, Mar 23, 2021 at 01:39:41PM -0700, Sami Tolvanen wrote:
> > With CONFIG_CFI_CLANG, the compiler replaces function addresses in
> > instrumented C code with jump table addresses. This change implements
> > t
On Thu, Mar 25, 2021 at 3:17 AM Mark Rutland wrote:
>
> On Wed, Mar 24, 2021 at 08:54:18AM -0700, Sami Tolvanen wrote:
> > On Wed, Mar 24, 2021 at 12:14 AM Christoph Hellwig
> > wrote:
> > >
> > > On Tue, Mar 23, 2021 at 01:39:32PM -0700, Sami Tolvanen
On Wed, Mar 24, 2021 at 3:53 PM Rasmus Villemoes
wrote:
>
> On 24/03/2021 23.34, Sami Tolvanen wrote:
> > On Wed, Mar 24, 2021 at 2:51 PM Rasmus Villemoes
> > wrote:
> >>
> >> On 24/03/2021 18.33, Peter Zijlstra wrote:
> >>> On Wed, Mar 24,
On Wed, Mar 24, 2021 at 2:51 PM Rasmus Villemoes
wrote:
>
> On 24/03/2021 18.33, Peter Zijlstra wrote:
> > On Wed, Mar 24, 2021 at 05:45:52PM +0100, Rasmus Villemoes wrote:
> >> Sorry, I think I misread the code. The static calls are indeed
> >> initialized with a function with the right
On Wed, Mar 24, 2021 at 8:31 AM Rasmus Villemoes
wrote:
>
> On 23/03/2021 21.39, Sami Tolvanen wrote:
> > With CONFIG_CFI_CLANG, the compiler replaces a function address taken
> > in C code with the address of a local jump table entry, which passes
> > runtime indir
On Wed, Mar 24, 2021 at 5:46 AM Rasmus Villemoes
wrote:
>
> On 23/03/2021 08.47, Peter Zijlstra wrote:
> > On Mon, Mar 22, 2021 at 05:29:21PM -0400, Steven Rostedt wrote:
> >> On Mon, 22 Mar 2021 22:18:17 +0100
> >> Arnd Bergmann wrote:
> >>
> >>> I think the code works correctly on all
On Wed, Mar 24, 2021 at 12:14 AM Christoph Hellwig wrote:
>
> On Tue, Mar 23, 2021 at 01:39:32PM -0700, Sami Tolvanen wrote:
> > With CONFIG_CFI_CLANG, the compiler replaces function addresses
> > in instrumented C code with jump table addresses. This means that
> > __pa_
__pa_function instead to get the address to
cpu_resume.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
drivers/firmware/psci/psci.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c
index f5fc429cae3f
With CONFIG_CFI_CLANG, the compiler replaces function addresses in
instrumented C code with jump table addresses. This change implements
the __va_function() macro, which returns the actual function address
instead.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/include/asm
With CONFIG_CFI_CLANG and ThinLTO, Clang appends a hash to the names
of all static functions not marked __used. This can break userspace
tools that don't expect the function name to change, so strip out the
hash from the output.
Suggested-by: Jack Pham
Signed-off-by: Sami Tolvanen
Reviewed
to the function's virtual
address. Therefore, use the __pa_function() macro to ensure we are
always taking the address of the actual function instead.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/include/asm/mmu_context.h | 2 +-
arch/arm64/kernel/acpi_parking_protocol.c | 2
Disable CFI for the nVHE code to avoid address space confusion.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/kvm/hyp/nvhe/Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile
Select ARCH_SUPPORTS_CFI_CLANG to allow CFI to be enabled.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 5656e7aacd69..2eefdbc3e3c9 100644
--- a/arch/arm64/Kconfig
Disable CFI checking for functions that switch to linear mapping and
make an indirect call to a physical address, since the compiler only
understands virtual addresses and the CFI check for such indirect calls
would always fail.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch
around the issue.
Signed-off-by: Sami Tolvanen
Reviewed-by: Kees Cook
---
arch/arm64/kernel/alternative.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c
index 1184c44ea2c7..abc84636af07 100644
--- a/arch
To ensure we take the actual address of a function in kernel text, use
__va_function. Otherwise, with CONFIG_CFI_CLANG, the compiler replaces
the address with a pointer to the CFI jump table, which is actually in
the module when compiled with CONFIG_LKDTM=m.
Signed-off-by: Sami Tolvanen
Acked
1 - 100 of 912 matches
Mail list logo