From: Samuel Holland <samuel.holland@sifive.com> To: Palmer Dabbelt <palmer@dabbelt.com>, linux-riscv@lists.infradead.org, Andrey Ryabinin <ryabinin.a.a@gmail.com>, Alexander Potapenko <glider@google.com>, Andrey Konovalov <andreyknvl@gmail.com>, Dmitry Vyukov <dvyukov@google.com>, Vincenzo Frascino <vincenzo.frascino@arm.com>, kasan-dev@googlegroups.com Cc: llvm@lists.linux.dev, Catalin Marinas <catalin.marinas@arm.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti <alexghiti@rivosinc.com>, Will Deacon <will@kernel.org>, Evgenii Stepanov <eugenis@google.com>, Andrew Morton <akpm@linux-foundation.org>, linux-arm-kernel@lists.infradead.org, Samuel Holland <samuel.holland@sifive.com> Subject: [PATCH v2 0/9] kasan: RISC-V support for KASAN_SW_TAGS using pointer masking Date: Mon, 21 Oct 2024 18:57:08 -0700 [thread overview] Message-ID: <20241022015913.3524425-1-samuel.holland@sifive.com> (raw) This series implements support for software tag-based KASAN using the RISC-V pointer masking extension[1], which supports 7 and/or 16-bit tags. This implementation uses 7-bit tags, so it is compatible with either hardware mode. Patch 4 adds supports for KASAN_SW_TAGS with tag widths other than 8 bits. Pointer masking is an optional ISA extension, and it must be enabled using an SBI call to firmware on each CPU. If the SBI call fails on the boot CPU, KASAN is globally disabled. Patch 2 adds support for boot-time disabling of KASAN_SW_TAGS, and patch 3 adds support for runtime control of stack tagging. Patch 1 is an optimization that could be applied separately. It is included here because it affects the selection of KASAN_SHADOW_OFFSET. This implementation currently passes the KASAN KUnit test suite: # kasan: pass:64 fail:0 skip:9 total:73 # Totals: pass:64 fail:0 skip:9 total:73 ok 1 kasan One workaround is required to pass the vmalloc_percpu test. I have to shrink the initial percpu area to force the use of a KASAN-tagged percpu area in the test (depending on .config, this workaround is also needed on arm64 without this series applied, so it is not a new issue): diff --git a/include/linux/percpu.h b/include/linux/percpu.h index b6321fc49159..26b97c79ad7c 100644 --- a/include/linux/percpu.h +++ b/include/linux/percpu.h @@ -43,7 +43,7 @@ #ifdef CONFIG_RANDOM_KMALLOC_CACHES #define PERCPU_DYNAMIC_SIZE_SHIFT 12 #else -#define PERCPU_DYNAMIC_SIZE_SHIFT 10 +#define PERCPU_DYNAMIC_SIZE_SHIFT 8 #endif When running with hardware or firmware that doesn't support pointer masking, the kernel still boots successfully: kasan: test: Can't run KASAN tests with KASAN disabled # kasan: # failed to initialize (-1) not ok 1 kasan This series can be tested by applying patch series to LLVM[2] and QEMU[3], and using the master branch of OpenSBI[4]. [1]: https://github.com/riscv/riscv-j-extension/raw/d70011dde6c2/zjpm-spec.pdf [2]: https://github.com/SiFiveHolland/llvm-project/commits/up/riscv64-kernel-hwasan [3]: https://lore.kernel.org/qemu-devel/20240511101053.1875596-1-me@deliversmonkey.space/ [4]: https://github.com/riscv-software-src/opensbi/commit/1cb234b1c9ed Changes in v2: - Improve the explanation for how KASAN_SHADOW_END is derived - Update the range check in kasan_non_canonical_hook() - Split the generic and RISC-V parts of stack tag generation control to avoid breaking bisectability - Add a patch to call kasan_non_canonical_hook() on riscv - Fix build error with KASAN_GENERIC - Use symbolic definitons for SBI firmware features call - Update indentation in scripts/Makefile.kasan - Use kasan_params to set hwasan-generate-tags-with-calls=1 Clément Léger (1): riscv: Add SBI Firmware Features extension definitions Samuel Holland (8): kasan: sw_tags: Use arithmetic shift for shadow computation kasan: sw_tags: Check kasan_flag_enabled at runtime kasan: sw_tags: Support outline stack tag generation kasan: sw_tags: Support tag widths less than 8 bits riscv: mm: Log potential KASAN shadow alias riscv: Do not rely on KASAN to define the memory layout riscv: Align the sv39 linear map to 16 GiB riscv: Implement KASAN_SW_TAGS Documentation/arch/riscv/vm-layout.rst | 10 ++--- Documentation/dev-tools/kasan.rst | 14 +++--- arch/arm64/Kconfig | 10 ++--- arch/arm64/include/asm/kasan.h | 6 ++- arch/arm64/include/asm/memory.h | 17 ++++++- arch/arm64/include/asm/uaccess.h | 1 + arch/arm64/mm/kasan_init.c | 7 ++- arch/riscv/Kconfig | 4 +- arch/riscv/include/asm/cache.h | 4 ++ arch/riscv/include/asm/kasan.h | 29 +++++++++++- arch/riscv/include/asm/page.h | 21 +++++++-- arch/riscv/include/asm/pgtable.h | 6 +++ arch/riscv/include/asm/sbi.h | 28 ++++++++++++ arch/riscv/include/asm/tlbflush.h | 4 +- arch/riscv/kernel/setup.c | 6 +++ arch/riscv/kernel/smpboot.c | 8 +++- arch/riscv/lib/Makefile | 2 + arch/riscv/lib/kasan_sw_tags.S | 61 ++++++++++++++++++++++++++ arch/riscv/mm/fault.c | 3 ++ arch/riscv/mm/init.c | 2 +- arch/riscv/mm/kasan_init.c | 32 +++++++++++++- arch/riscv/mm/physaddr.c | 4 ++ include/linux/kasan-enabled.h | 15 +++---- include/linux/kasan-tags.h | 13 +++--- include/linux/kasan.h | 10 ++++- mm/kasan/hw_tags.c | 10 ----- mm/kasan/kasan.h | 2 + mm/kasan/report.c | 22 ++++++++-- mm/kasan/sw_tags.c | 9 ++++ mm/kasan/tags.c | 10 +++++ scripts/Makefile.kasan | 5 +++ scripts/gdb/linux/mm.py | 5 ++- 32 files changed, 313 insertions(+), 67 deletions(-) create mode 100644 arch/riscv/lib/kasan_sw_tags.S -- 2.45.1
WARNING: multiple messages have this Message-ID (diff)
From: Samuel Holland <samuel.holland@sifive.com> To: Palmer Dabbelt <palmer@dabbelt.com>, linux-riscv@lists.infradead.org, Andrey Ryabinin <ryabinin.a.a@gmail.com>, Alexander Potapenko <glider@google.com>, Andrey Konovalov <andreyknvl@gmail.com>, Dmitry Vyukov <dvyukov@google.com>, Vincenzo Frascino <vincenzo.frascino@arm.com>, kasan-dev@googlegroups.com Cc: llvm@lists.linux.dev, Catalin Marinas <catalin.marinas@arm.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti <alexghiti@rivosinc.com>, Will Deacon <will@kernel.org>, Evgenii Stepanov <eugenis@google.com>, Andrew Morton <akpm@linux-foundation.org>, linux-arm-kernel@lists.infradead.org, Samuel Holland <samuel.holland@sifive.com> Subject: [PATCH v2 0/9] kasan: RISC-V support for KASAN_SW_TAGS using pointer masking Date: Mon, 21 Oct 2024 18:57:08 -0700 [thread overview] Message-ID: <20241022015913.3524425-1-samuel.holland@sifive.com> (raw) This series implements support for software tag-based KASAN using the RISC-V pointer masking extension[1], which supports 7 and/or 16-bit tags. This implementation uses 7-bit tags, so it is compatible with either hardware mode. Patch 4 adds supports for KASAN_SW_TAGS with tag widths other than 8 bits. Pointer masking is an optional ISA extension, and it must be enabled using an SBI call to firmware on each CPU. If the SBI call fails on the boot CPU, KASAN is globally disabled. Patch 2 adds support for boot-time disabling of KASAN_SW_TAGS, and patch 3 adds support for runtime control of stack tagging. Patch 1 is an optimization that could be applied separately. It is included here because it affects the selection of KASAN_SHADOW_OFFSET. This implementation currently passes the KASAN KUnit test suite: # kasan: pass:64 fail:0 skip:9 total:73 # Totals: pass:64 fail:0 skip:9 total:73 ok 1 kasan One workaround is required to pass the vmalloc_percpu test. I have to shrink the initial percpu area to force the use of a KASAN-tagged percpu area in the test (depending on .config, this workaround is also needed on arm64 without this series applied, so it is not a new issue): diff --git a/include/linux/percpu.h b/include/linux/percpu.h index b6321fc49159..26b97c79ad7c 100644 --- a/include/linux/percpu.h +++ b/include/linux/percpu.h @@ -43,7 +43,7 @@ #ifdef CONFIG_RANDOM_KMALLOC_CACHES #define PERCPU_DYNAMIC_SIZE_SHIFT 12 #else -#define PERCPU_DYNAMIC_SIZE_SHIFT 10 +#define PERCPU_DYNAMIC_SIZE_SHIFT 8 #endif When running with hardware or firmware that doesn't support pointer masking, the kernel still boots successfully: kasan: test: Can't run KASAN tests with KASAN disabled # kasan: # failed to initialize (-1) not ok 1 kasan This series can be tested by applying patch series to LLVM[2] and QEMU[3], and using the master branch of OpenSBI[4]. [1]: https://github.com/riscv/riscv-j-extension/raw/d70011dde6c2/zjpm-spec.pdf [2]: https://github.com/SiFiveHolland/llvm-project/commits/up/riscv64-kernel-hwasan [3]: https://lore.kernel.org/qemu-devel/20240511101053.1875596-1-me@deliversmonkey.space/ [4]: https://github.com/riscv-software-src/opensbi/commit/1cb234b1c9ed Changes in v2: - Improve the explanation for how KASAN_SHADOW_END is derived - Update the range check in kasan_non_canonical_hook() - Split the generic and RISC-V parts of stack tag generation control to avoid breaking bisectability - Add a patch to call kasan_non_canonical_hook() on riscv - Fix build error with KASAN_GENERIC - Use symbolic definitons for SBI firmware features call - Update indentation in scripts/Makefile.kasan - Use kasan_params to set hwasan-generate-tags-with-calls=1 Clément Léger (1): riscv: Add SBI Firmware Features extension definitions Samuel Holland (8): kasan: sw_tags: Use arithmetic shift for shadow computation kasan: sw_tags: Check kasan_flag_enabled at runtime kasan: sw_tags: Support outline stack tag generation kasan: sw_tags: Support tag widths less than 8 bits riscv: mm: Log potential KASAN shadow alias riscv: Do not rely on KASAN to define the memory layout riscv: Align the sv39 linear map to 16 GiB riscv: Implement KASAN_SW_TAGS Documentation/arch/riscv/vm-layout.rst | 10 ++--- Documentation/dev-tools/kasan.rst | 14 +++--- arch/arm64/Kconfig | 10 ++--- arch/arm64/include/asm/kasan.h | 6 ++- arch/arm64/include/asm/memory.h | 17 ++++++- arch/arm64/include/asm/uaccess.h | 1 + arch/arm64/mm/kasan_init.c | 7 ++- arch/riscv/Kconfig | 4 +- arch/riscv/include/asm/cache.h | 4 ++ arch/riscv/include/asm/kasan.h | 29 +++++++++++- arch/riscv/include/asm/page.h | 21 +++++++-- arch/riscv/include/asm/pgtable.h | 6 +++ arch/riscv/include/asm/sbi.h | 28 ++++++++++++ arch/riscv/include/asm/tlbflush.h | 4 +- arch/riscv/kernel/setup.c | 6 +++ arch/riscv/kernel/smpboot.c | 8 +++- arch/riscv/lib/Makefile | 2 + arch/riscv/lib/kasan_sw_tags.S | 61 ++++++++++++++++++++++++++ arch/riscv/mm/fault.c | 3 ++ arch/riscv/mm/init.c | 2 +- arch/riscv/mm/kasan_init.c | 32 +++++++++++++- arch/riscv/mm/physaddr.c | 4 ++ include/linux/kasan-enabled.h | 15 +++---- include/linux/kasan-tags.h | 13 +++--- include/linux/kasan.h | 10 ++++- mm/kasan/hw_tags.c | 10 ----- mm/kasan/kasan.h | 2 + mm/kasan/report.c | 22 ++++++++-- mm/kasan/sw_tags.c | 9 ++++ mm/kasan/tags.c | 10 +++++ scripts/Makefile.kasan | 5 +++ scripts/gdb/linux/mm.py | 5 ++- 32 files changed, 313 insertions(+), 67 deletions(-) create mode 100644 arch/riscv/lib/kasan_sw_tags.S -- 2.45.1 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv
next reply other threads:[~2024-10-22 1:59 UTC|newest] Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-10-22 1:57 Samuel Holland [this message] 2024-10-22 1:57 ` [PATCH v2 0/9] kasan: RISC-V support for KASAN_SW_TAGS using pointer masking Samuel Holland 2024-10-22 1:57 ` [PATCH v2 1/9] kasan: sw_tags: Use arithmetic shift for shadow computation Samuel Holland 2024-10-22 1:57 ` Samuel Holland 2024-10-23 18:41 ` Andrey Konovalov 2024-10-23 18:41 ` Andrey Konovalov 2025-02-10 15:22 ` Maciej Wieczor-Retman 2025-02-10 15:22 ` Maciej Wieczor-Retman 2025-02-10 15:52 ` Maciej Wieczor-Retman 2025-02-10 15:52 ` Maciej Wieczor-Retman 2025-02-10 22:57 ` Andrey Konovalov 2025-02-10 22:57 ` Andrey Konovalov 2025-02-11 8:58 ` Maciej Wieczor-Retman 2025-02-11 8:58 ` Maciej Wieczor-Retman 2025-02-11 13:42 ` Maciej Wieczor-Retman 2025-02-11 13:42 ` Maciej Wieczor-Retman 2025-02-11 18:06 ` Maciej Wieczor-Retman 2025-02-11 18:06 ` Maciej Wieczor-Retman 2025-02-13 1:21 ` Andrey Konovalov 2025-02-13 1:21 ` Andrey Konovalov 2025-02-13 1:28 ` Andrey Konovalov 2025-02-13 1:28 ` Andrey Konovalov 2025-02-13 16:20 ` Maciej Wieczor-Retman 2025-02-13 16:20 ` Maciej Wieczor-Retman 2025-02-14 8:20 ` Maciej Wieczor-Retman 2025-02-14 8:20 ` Maciej Wieczor-Retman 2025-02-17 16:13 ` Andrey Konovalov 2025-02-17 16:13 ` Andrey Konovalov 2025-02-17 18:37 ` Maciej Wieczor-Retman 2025-02-17 18:37 ` Maciej Wieczor-Retman 2025-02-17 19:00 ` Andrey Konovalov 2025-02-17 19:00 ` Andrey Konovalov 2024-10-22 1:57 ` [PATCH v2 2/9] kasan: sw_tags: Check kasan_flag_enabled at runtime Samuel Holland 2024-10-22 1:57 ` Samuel Holland 2024-10-22 1:57 ` [PATCH v2 3/9] kasan: sw_tags: Support outline stack tag generation Samuel Holland 2024-10-22 1:57 ` Samuel Holland 2024-10-23 18:42 ` Andrey Konovalov 2024-10-23 18:42 ` Andrey Konovalov 2024-10-22 1:57 ` [PATCH v2 4/9] kasan: sw_tags: Support tag widths less than 8 bits Samuel Holland 2024-10-22 1:57 ` Samuel Holland 2024-10-22 19:30 ` kernel test robot 2024-10-22 19:30 ` kernel test robot 2024-10-22 19:51 ` kernel test robot 2024-10-22 19:51 ` kernel test robot 2024-10-22 1:57 ` [PATCH v2 5/9] riscv: mm: Log potential KASAN shadow alias Samuel Holland 2024-10-22 1:57 ` Samuel Holland 2024-11-05 13:44 ` Alexandre Ghiti 2024-11-05 13:44 ` Alexandre Ghiti 2024-10-22 1:57 ` [PATCH v2 6/9] riscv: Do not rely on KASAN to define the memory layout Samuel Holland 2024-10-22 1:57 ` Samuel Holland 2024-11-05 13:47 ` Alexandre Ghiti 2024-11-05 13:47 ` Alexandre Ghiti 2024-10-22 1:57 ` [PATCH v2 7/9] riscv: Align the sv39 linear map to 16 GiB Samuel Holland 2024-10-22 1:57 ` Samuel Holland 2024-11-05 13:55 ` Alexandre Ghiti 2024-11-05 13:55 ` Alexandre Ghiti 2024-10-22 1:57 ` [PATCH v2 8/9] riscv: Add SBI Firmware Features extension definitions Samuel Holland 2024-10-22 1:57 ` Samuel Holland 2024-10-22 1:57 ` [PATCH v2 9/9] riscv: Implement KASAN_SW_TAGS Samuel Holland 2024-10-22 1:57 ` Samuel Holland 2024-10-23 18:42 ` Andrey Konovalov 2024-10-23 18:42 ` Andrey Konovalov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20241022015913.3524425-1-samuel.holland@sifive.com \ --to=samuel.holland@sifive.com \ --cc=akpm@linux-foundation.org \ --cc=alexghiti@rivosinc.com \ --cc=andreyknvl@gmail.com \ --cc=catalin.marinas@arm.com \ --cc=dvyukov@google.com \ --cc=eugenis@google.com \ --cc=glider@google.com \ --cc=kasan-dev@googlegroups.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=linux-riscv@lists.infradead.org \ --cc=llvm@lists.linux.dev \ --cc=palmer@dabbelt.com \ --cc=ryabinin.a.a@gmail.com \ --cc=vincenzo.frascino@arm.com \ --cc=will@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.