From: Jisheng Zhang <jszhang@kernel.org>
They are not needed after booting, so mark them as __init to move them
to the __init section.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
arch/riscv/kernel/traps.c | 2 +-
arch/riscv/mm/init.c | 6 +++---
arch/riscv/mm/kasan_init.c | 6 +++---
arch/riscv/mm/ptdump.c | 2 +-
4 files changed, 8 insertions(+), 8 deletions(-)
@@ -197,6 +197,6 @@ int is_valid_bugaddr(unsigned long pc)#endif /* CONFIG_GENERIC_BUG *//* stvec & scratch is already set from head.S */-voidtrap_init(void)+void__inittrap_init(void){}
From: Jisheng Zhang <jszhang@kernel.org>
All of these are never modified after init, so they can be
__ro_after_init.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
arch/riscv/kernel/sbi.c | 8 ++++----
arch/riscv/kernel/smp.c | 4 ++--
arch/riscv/kernel/time.c | 2 +-
arch/riscv/kernel/vdso.c | 4 ++--
arch/riscv/mm/init.c | 6 +++---
5 files changed, 12 insertions(+), 12 deletions(-)
@@ -11,14 +11,14 @@#include<asm/smp.h>/* default SBI version is 0.1 */-unsignedlongsbi_spec_version=SBI_SPEC_VERSION_DEFAULT;+unsignedlongsbi_spec_version__ro_after_init=SBI_SPEC_VERSION_DEFAULT;EXPORT_SYMBOL(sbi_spec_version);-staticvoid(*__sbi_set_timer)(uint64_tstime);-staticint(*__sbi_send_ipi)(constunsignedlong*hart_mask);+staticvoid(*__sbi_set_timer)(uint64_tstime)__ro_after_init;+staticint(*__sbi_send_ipi)(constunsignedlong*hart_mask)__ro_after_init;staticint(*__sbi_rfence)(intfid,constunsignedlong*hart_mask,unsignedlongstart,unsignedlongsize,-unsignedlongarg4,unsignedlongarg5);+unsignedlongarg4,unsignedlongarg5)__ro_after_init;structsbiretsbi_ecall(intext,intfid,unsignedlongarg0,unsignedlongarg1,unsignedlongarg2,
From: Jisheng Zhang <jszhang@kernel.org>
Constify the sys_call_table so that it will be placed in the .rodata
section. This will cause attempts to modify the table to fail when
strict page permissions are in place.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
arch/riscv/include/asm/syscall.h | 2 +-
arch/riscv/kernel/syscall_table.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
@@ -15,7 +15,7 @@#include<linux/err.h>/* The array of function pointers for syscalls. */-externvoid*sys_call_table[];+externvoid*constsys_call_table[];/**Onlythelow32bitsoforig_r0aremeaningful,sowereturnint.
From: Jisheng Zhang <jszhang@kernel.org>
Constify the sbi_ipi_ops so that it will be placed in the .rodata
section. This will cause attempts to modify it to fail when strict
page permissions are in place.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
arch/riscv/include/asm/smp.h | 4 ++--
arch/riscv/kernel/sbi.c | 2 +-
arch/riscv/kernel/smp.c | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
@@ -46,7 +46,7 @@ int riscv_hartid_to_cpuid(int hartid);voidriscv_cpuid_to_hartid_mask(conststructcpumask*in,structcpumask*out);/* Set custom IPI operations */-voidriscv_set_ipi_ops(structriscv_ipi_ops*ops);+voidriscv_set_ipi_ops(conststructriscv_ipi_ops*ops);/* Clear IPI for current CPU */voidriscv_clear_ipi(void);
@@ -84,6 +84,14 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)return0;}+void*alloc_insn_page(void)+{+return__vmalloc_node_range(PAGE_SIZE,1,VMALLOC_START,VMALLOC_END,+GFP_KERNEL,PAGE_KERNEL_READ_EXEC,+VM_FLUSH_RESET_PERMS,NUMA_NO_NODE,+__builtin_return_address(0));+}+/* install breakpoint in text */void__kprobesarch_arm_kprobe(structkprobe*p){
From: Jisheng Zhang <jszhang@kernel.org>
bpf_jit_binary_lock_ro() in core not only set RO but also set EXEC
permission when JIT is done, so no need to allocate RWX from the
beginning, and it's not safe.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
arch/riscv/net/bpf_jit_comp64.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Jisheng Zhang <jszhang@kernel.org>
The core code manages the executable permissions of code regions of
modules explicitly, it is not necessary to create the module vmalloc
regions with RWX permissions. Create them with RW- permissions instead.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
arch/riscv/kernel/module.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
From: Jisheng Zhang <jszhang@kernel.org>
Now we can set ARCH_HAS_STRICT_MODULE_RWX for MMU riscv platforms, this
is good from security perspective.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
arch/riscv/Kconfig | 1 +
1 file changed, 1 insertion(+)
On Wed, Mar 31, 2021 at 10:00 PM Jisheng Zhang
[off-list ref] wrote:
quoted hunk
From: Jisheng Zhang <jszhang@kernel.org>
They are not needed after booting, so mark them as __init to move them
to the __init section.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
arch/riscv/kernel/traps.c | 2 +-
arch/riscv/mm/init.c | 6 +++---
arch/riscv/mm/kasan_init.c | 6 +++---
arch/riscv/mm/ptdump.c | 2 +-
4 files changed, 8 insertions(+), 8 deletions(-)
@@ -197,6 +197,6 @@ int is_valid_bugaddr(unsigned long pc)#endif /* CONFIG_GENERIC_BUG *//* stvec & scratch is already set from head.S */-voidtrap_init(void)+void__inittrap_init(void){}
The trap_init() is unused currently so you can drop this change
and remove trap_init() as a separate patch.
On Wed, Mar 31, 2021 at 10:01 PM Jisheng Zhang
[off-list ref] wrote:
From: Jisheng Zhang <jszhang@kernel.org>
All of these are never modified after init, so they can be
__ro_after_init.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Looks good to me.
Reviewed-by: Anup Patel <anup@brainfault.org>
Regards,
Anup
@@ -11,14 +11,14 @@#include<asm/smp.h>/* default SBI version is 0.1 */-unsignedlongsbi_spec_version=SBI_SPEC_VERSION_DEFAULT;+unsignedlongsbi_spec_version__ro_after_init=SBI_SPEC_VERSION_DEFAULT;EXPORT_SYMBOL(sbi_spec_version);-staticvoid(*__sbi_set_timer)(uint64_tstime);-staticint(*__sbi_send_ipi)(constunsignedlong*hart_mask);+staticvoid(*__sbi_set_timer)(uint64_tstime)__ro_after_init;+staticint(*__sbi_send_ipi)(constunsignedlong*hart_mask)__ro_after_init;staticint(*__sbi_rfence)(intfid,constunsignedlong*hart_mask,unsignedlongstart,unsignedlongsize,-unsignedlongarg4,unsignedlongarg5);+unsignedlongarg4,unsignedlongarg5)__ro_after_init;structsbiretsbi_ecall(intext,intfid,unsignedlongarg0,unsignedlongarg1,unsignedlongarg2,
On Wed, Mar 31, 2021 at 10:01 PM Jisheng Zhang
[off-list ref] wrote:
From: Jisheng Zhang <jszhang@kernel.org>
Constify the sys_call_table so that it will be placed in the .rodata
section. This will cause attempts to modify the table to fail when
strict page permissions are in place.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Looks good to me.
Reviewed-by: Anup Patel <anup@brainfault.org>
Regards,
Anup
@@ -15,7 +15,7 @@#include<linux/err.h>/* The array of function pointers for syscalls. */-externvoid*sys_call_table[];+externvoid*constsys_call_table[];/**Onlythelow32bitsoforig_r0aremeaningful,sowereturnint.
On Wed, Mar 31, 2021 at 10:02 PM Jisheng Zhang
[off-list ref] wrote:
From: Jisheng Zhang <jszhang@kernel.org>
Constify the sbi_ipi_ops so that it will be placed in the .rodata
section. This will cause attempts to modify it to fail when strict
page permissions are in place.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Looks good to me.
Reviewed-by: Anup Patel <anup@brainfault.org>
Regards,
Anup
@@ -46,7 +46,7 @@ int riscv_hartid_to_cpuid(int hartid);voidriscv_cpuid_to_hartid_mask(conststructcpumask*in,structcpumask*out);/* Set custom IPI operations */-voidriscv_set_ipi_ops(structriscv_ipi_ops*ops);+voidriscv_set_ipi_ops(conststructriscv_ipi_ops*ops);/* Clear IPI for current CPU */voidriscv_clear_ipi(void);
On Wed, Mar 31, 2021 at 10:05 PM Jisheng Zhang
[off-list ref] wrote:
From: Jisheng Zhang <jszhang@kernel.org>
Now we can set ARCH_HAS_STRICT_MODULE_RWX for MMU riscv platforms, this
is good from security perspective.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Looks good to me.
Reviewed-by: Anup Patel <anup@brainfault.org>
Regards,
Anup
On Wed, Mar 31, 2021 at 10:02 PM Jisheng Zhang
[off-list ref] wrote:
From: Jisheng Zhang <jszhang@kernel.org>
Allocate PAGE_KERNEL_READ_EXEC(read only, executable) page for kprobes
insn page. This is to prepare for STRICT_MODULE_RWX.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Looks good to me.
Reviewed-by: Anup Patel <anup@brainfault.org>
Regards,
Anup
@@ -84,6 +84,14 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)return0;}+void*alloc_insn_page(void)+{+return__vmalloc_node_range(PAGE_SIZE,1,VMALLOC_START,VMALLOC_END,+GFP_KERNEL,PAGE_KERNEL_READ_EXEC,+VM_FLUSH_RESET_PERMS,NUMA_NO_NODE,+__builtin_return_address(0));+}+/* install breakpoint in text */void__kprobesarch_arm_kprobe(structkprobe*p){--
On Wed, Mar 31, 2021 at 10:04 PM Jisheng Zhang
[off-list ref] wrote:
From: Jisheng Zhang <jszhang@kernel.org>
The core code manages the executable permissions of code regions of
modules explicitly, it is not necessary to create the module vmalloc
regions with RWX permissions. Create them with RW- permissions instead.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Looks good to me.
Reviewed-by: Anup Patel <anup@brainfault.org>
Regards,
Anup
On Wed, Mar 31, 2021 at 10:00 PM Jisheng Zhang
[off-list ref] wrote:
quoted
From: Jisheng Zhang <jszhang@kernel.org>
They are not needed after booting, so mark them as __init to move them
to the __init section.
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
arch/riscv/kernel/traps.c | 2 +-
arch/riscv/mm/init.c | 6 +++---
arch/riscv/mm/kasan_init.c | 6 +++---
arch/riscv/mm/ptdump.c | 2 +-
4 files changed, 8 insertions(+), 8 deletions(-)
@@ -197,6 +197,6 @@ int is_valid_bugaddr(unsigned long pc)#endif /* CONFIG_GENERIC_BUG *//* stvec & scratch is already set from head.S */-voidtrap_init(void)+void__inittrap_init(void){}
The trap_init() is unused currently so you can drop this change
and remove trap_init() as a separate patch.
the kernel init/main.c expects a trap_init() implementation in architecture
code. Some architecture's implementation is NULL, similar as riscv, for example,
arm, powerpc and so on. However I think you are right, the trap_init() can be
removed, we need a trivial series to provide a __weak but NULL trap_init()
implementation in init/main.c then remove all NULL implementation from
all arch. I can take the task to do the clean up.
I think the zero page is already initialized as "0" because empty_zero_page
sits in .bss section. So this setup_zero_page() function can be removed. I
will send a newer version later.
thanks