[PATCH v3 0/5] Improve kernel section protections
Palmer Dabbelt
palmer at dabbelt.com
Wed Nov 25 19:07:15 EST 2020
On Mon, 23 Nov 2020 23:21:08 PST (-0800), greentime.hu at sifive.com wrote:
> Atish Patra <atish.patra at wdc.com> 於 2020年11月5日 週四 上午8:05寫道:
>>
>> This series aims at improving kernel permissions by doing following things.
>>
>> 1. Protect kernel sections early instead of after /init.
>> 2. Protect .init.text & .init.data sections with appropriate permissions.
>> 3. Move dynamic relocation section to _init.
>> 4. Moved .init sections after .text. This is what most of the other archs
>> are also doing.
>>
>> After applying this patch, here are the linear mapped sections with non-uefi boot.
>>
>> ---[ Linear mapping ]---
>> 0xffffffe000000000-0xffffffe000800000 0x0000000080200000 8M PMD D A . . X . R V
>> 0xffffffe000800000-0xffffffe000c00000 0x0000000080a00000 4M PMD D A . . . W R V
>> 0xffffffe000c00000-0xffffffe001200000 0x0000000080e00000 6M PMD D A . . . . R V
>> 0xffffffe001200000-0xffffffe03fe00000 0x0000000081400000 1004M PMD D A . . . W R V
>>
>> Linear mapping with uefi boot.
>>
>> ---[ Linear mapping ]---
>> 0xffffffe000000000-0xffffffe000800000 0x0000000080200000 8M PTE D A . . X . R V
>> 0xffffffe000800000-0xffffffe000c00000 0x0000000080a00000 4M PTE D A . . . W R V
>> 0xffffffe000c00000-0xffffffe001200000 0x0000000080e00000 6M PTE D A . . . . R V
>> 0xffffffe001200000-0xffffffe03e534000 0x0000000081400000 1002704K PTE D A . . . W R V
>> 0xffffffe03e538000-0xffffffe03e539000 0x00000000be738000 4K PTE D A . . . W R V
>> 0xffffffe03e53a000-0xffffffe03e53c000 0x00000000be73a000 8K PTE D A . . . W R V
>> 0xffffffe03e540000-0xffffffe03e541000 0x00000000be740000 4K PTE D A . . . W R V
>> 0xffffffe03e545000-0xffffffe03e546000 0x00000000be745000 4K PTE D A . . . W R V
>> 0xffffffe03e549000-0xffffffe03e54a000 0x00000000be749000 4K PTE D A . . . W R V
>> 0xffffffe03e54b000-0xffffffe03fd6d000 0x00000000be74b000 24712K PTE D A . . . W R V
>> 0xffffffe03fd6e000-0xffffffe03fdee000 0x00000000bff6e000 512K PTE D A . . . W R V
>>
>>
>> Changes from v2->v3:
>> 1. Added few extra comments to clarify rodata permissions.
>> 2. Changed the name of the functions set_memory_default to set_memory_rw_nx.
>> 3. Squashed patch 3&5 together as they depend on each other to allow
>> bisectability.
>> 4. Removed redundant arguments in protect_kernel_text_data.
>>
>> Changes from v1->v2:
>> 1. .init.text section is aligned with SECTION_ALIGN.
>> 2. .init.text is moved to below of .text so that .head.text & .text are in
>> one section.
>> 3. We don't need Guo's fix for static object issue.
>> 4. Rebased on 5.10-rc1.
>>
>> Atish Patra (5):
>> RISC-V: Move __start_kernel to .head.text
>> RISC-V: Initialize SBI early
>> RISC-V: Align the .init.text section
>> RISC-V: Protect all kernel sections including init early
>> RISC-V: Move dynamic relocation section under __init
>>
>> arch/riscv/include/asm/sections.h | 2 +
>> arch/riscv/include/asm/set_memory.h | 4 ++
>> arch/riscv/kernel/head.S | 1 -
>> arch/riscv/kernel/setup.c | 19 +++++++--
>> arch/riscv/kernel/vmlinux.lds.S | 63 +++++++++++++++++------------
>> arch/riscv/mm/init.c | 21 +++++++---
>> arch/riscv/mm/pageattr.c | 6 +++
>> 7 files changed, 80 insertions(+), 36 deletions(-)
>>
>
> Test this series in v5.10-rc3 in Qemu and it works.
> Tested-by: Greentime Hu <greentime.hu at sifive.com>
>
> Thank you. :)
Thanks, this is on for-next.
More information about the linux-riscv
mailing list