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, linux-kernel@vger.kernel.org,
Alexandre Ghiti <alexghiti@rivosinc.com>,
Evgenii Stepanov <eugenis@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-arm-kernel@lists.infradead.org,
Samuel Holland <samuel.holland@sifive.com>
Subject: [RFC PATCH 7/7] kasan: sw_tags: Support runtime stack tagging control for RISC-V
Date: Wed, 14 Aug 2024 01:55:35 -0700 [thread overview]
Message-ID: <20240814085618.968833-8-samuel.holland@sifive.com> (raw)
In-Reply-To: <20240814085618.968833-1-samuel.holland@sifive.com>
This allows the kernel to boot on systems without pointer masking
support when stack tagging is enabled.
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
---
mm/kasan/kasan.h | 2 ++
mm/kasan/sw_tags.c | 9 +++++++++
scripts/Makefile.kasan | 5 +++++
3 files changed, 16 insertions(+)
diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
index fb2b9ac0659a..01e945cb111d 100644
--- a/mm/kasan/kasan.h
+++ b/mm/kasan/kasan.h
@@ -630,6 +630,8 @@ void *__asan_memset(void *addr, int c, ssize_t len);
void *__asan_memmove(void *dest, const void *src, ssize_t len);
void *__asan_memcpy(void *dest, const void *src, ssize_t len);
+u8 __hwasan_generate_tag(void);
+
void __hwasan_load1_noabort(void *);
void __hwasan_store1_noabort(void *);
void __hwasan_load2_noabort(void *);
diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c
index 220b5d4c6876..32435d33583a 100644
--- a/mm/kasan/sw_tags.c
+++ b/mm/kasan/sw_tags.c
@@ -70,6 +70,15 @@ u8 kasan_random_tag(void)
return (u8)(state % (KASAN_TAG_MAX + 1));
}
+u8 __hwasan_generate_tag(void)
+{
+ if (!kasan_enabled())
+ return KASAN_TAG_KERNEL;
+
+ return kasan_random_tag();
+}
+EXPORT_SYMBOL(__hwasan_generate_tag);
+
bool kasan_check_range(const void *addr, size_t size, bool write,
unsigned long ret_ip)
{
diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan
index 390658a2d5b7..f64c1aca3e97 100644
--- a/scripts/Makefile.kasan
+++ b/scripts/Makefile.kasan
@@ -73,6 +73,11 @@ ifeq ($(call clang-min-version, 150000)$(call gcc-min-version, 130000),y)
CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1)
endif
+# RISC-V requires dynamically determining if stack tagging can be enabled.
+ifdef CONFIG_RISCV
+CFLAGS_KASAN += $(call cc-param,hwasan-generate-tags-with-calls=1)
+endif
+
endif # CONFIG_KASAN_SW_TAGS
export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE
--
2.45.1
next prev parent reply other threads:[~2024-08-14 8:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-14 8:55 [RFC PATCH 0/7] kasan: RISC-V support for KASAN_SW_TAGS using pointer masking Samuel Holland
2024-08-14 8:55 ` [RFC PATCH 1/7] kasan: sw_tags: Use arithmetic shift for shadow computation Samuel Holland
2024-08-14 16:03 ` Andrey Konovalov
2024-10-21 20:26 ` Samuel Holland
2024-08-14 8:55 ` [RFC PATCH 2/7] kasan: sw_tags: Check kasan_flag_enabled at runtime Samuel Holland
2024-08-14 16:03 ` Andrey Konovalov
2024-08-14 8:55 ` [RFC PATCH 3/7] kasan: sw_tags: Support tag widths less than 8 bits Samuel Holland
2024-08-14 16:03 ` Andrey Konovalov
2024-08-14 8:55 ` [RFC PATCH 4/7] riscv: Do not rely on KASAN to define the memory layout Samuel Holland
2024-08-14 8:55 ` [RFC PATCH 5/7] riscv: Align the sv39 linear map to 16 GiB Samuel Holland
2024-08-14 8:55 ` [RFC PATCH 6/7] riscv: Implement KASAN_SW_TAGS Samuel Holland
2024-08-14 8:55 ` Samuel Holland [this message]
2024-08-14 16:04 ` [RFC PATCH 7/7] kasan: sw_tags: Support runtime stack tagging control for RISC-V Andrey Konovalov
2024-08-14 16:03 ` [RFC PATCH 0/7] kasan: RISC-V support for KASAN_SW_TAGS using pointer masking Andrey Konovalov
2024-10-22 1:13 ` Samuel Holland
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=20240814085618.968833-8-samuel.holland@sifive.com \
--to=samuel.holland@sifive.com \
--cc=akpm@linux-foundation.org \
--cc=alexghiti@rivosinc.com \
--cc=andreyknvl@gmail.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-riscv@lists.infradead.org \
--cc=llvm@lists.linux.dev \
--cc=palmer@dabbelt.com \
--cc=ryabinin.a.a@gmail.com \
--cc=vincenzo.frascino@arm.com \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®