From: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
To: kees@kernel.org, julian.stecklina@cyberus-technology.de,
kevinloughlin@google.com, peterz@infradead.org,
tglx@linutronix.de, justinstitt@google.com,
catalin.marinas@arm.com, wangkefeng.wang@huawei.com,
bhe@redhat.com, ryabinin.a.a@gmail.com,
kirill.shutemov@linux.intel.com, will@kernel.org,
ardb@kernel.org, jason.andryuk@amd.com,
dave.hansen@linux.intel.com, pasha.tatashin@soleen.com,
ndesaulniers@google.com, guoweikang.kernel@gmail.com,
dwmw@amazon.co.uk, mark.rutland@arm.com, broonie@kernel.org,
apopple@nvidia.com, bp@alien8.de, rppt@kernel.org,
kaleshsingh@google.com, richard.weiyang@gmail.com,
luto@kernel.org, glider@google.com, pankaj.gupta@amd.com,
andreyknvl@gmail.com, pawan.kumar.gupta@linux.intel.com,
kuan-ying.lee@canonical.com, tony.luck@intel.com, tj@kernel.org,
jgross@suse.com, dvyukov@google.com, baohua@kernel.org,
samuel.holland@sifive.com, dennis@kernel.org,
akpm@linux-foundation.org, thomas.weissschuh@linutronix.de,
surenb@google.com, kbingham@kernel.org, ankita@nvidia.com,
nathan@kernel.org, maciej.wieczor-retman@intel.com,
ziy@nvidia.com, xin@zytor.com, rafael.j.wysocki@intel.com,
andriy.shevchenko@linux.intel.com, cl@linux.com,
jhubbard@nvidia.com, hpa@zytor.com, scott@os.amperecomputing.com,
david@redhat.com, jan.kiszka@siemens.com,
vincenzo.frascino@arm.com, corbet@lwn.net, maz@kernel.org,
mingo@redhat.com, arnd@arndb.de, ytcoode@gmail.com,
xur@google.com, morbo@google.com, thiago.bauermann@linaro.org
Cc: linux-doc@vger.kernel.org, kasan-dev@googlegroups.com,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev,
linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org,
x86@kernel.org
Subject: [PATCH v2 05/14] kasan: arm64: x86: Make special tags arch specific
Date: Tue, 18 Feb 2025 09:15:21 +0100 [thread overview]
Message-ID: <e1cffdd3ec7aac6c047650141ba3be96888cb817.1739866028.git.maciej.wieczor-retman@intel.com> (raw)
In-Reply-To: <cover.1739866028.git.maciej.wieczor-retman@intel.com>
KASAN's tag-based mode defines multiple special tag values. They're
reserved for:
- Native kernel value. On arm64 it's 0xFF and it causes an early return
in the tag checking function.
- Invalid value. 0xFE marks an area as freed / unallocated. It's also
the value that is used to initialize regions of shadow memory.
- Max value. 0xFD is the highest value that can be randomly generated
for a new tag.
Metadata macro is also defined:
- Tag width equal to 8.
Tag-based mode on x86 is going to use 4 bit wide tags so all the above
values need to be changed accordingly.
Make native kernel tag arch specific for x86 and arm64.
Replace hardcoded kernel tag value and tag width with macros in KASAN's
non-arch specific code.
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
---
Changelog v2:
- Remove risc-v from the patch.
MAINTAINERS | 2 +-
arch/arm64/include/asm/kasan-tags.h | 9 +++++++++
arch/x86/include/asm/kasan-tags.h | 9 +++++++++
include/linux/kasan-tags.h | 8 +++++++-
include/linux/kasan.h | 4 +++-
include/linux/mm.h | 6 +++---
include/linux/page-flags-layout.h | 7 +------
7 files changed, 33 insertions(+), 12 deletions(-)
create mode 100644 arch/arm64/include/asm/kasan-tags.h
create mode 100644 arch/x86/include/asm/kasan-tags.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 896a307fa065..37971952c24b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12478,7 +12478,7 @@ L: kasan-dev@googlegroups.com
S: Maintained
B: https://bugzilla.kernel.org/buglist.cgi?component=Sanitizers&product=Memory%20Management
F: Documentation/dev-tools/kasan.rst
-F: arch/*/include/asm/*kasan.h
+F: arch/*/include/asm/*kasan*.h
F: arch/*/mm/kasan_init*
F: include/linux/kasan*.h
F: lib/Kconfig.kasan
diff --git a/arch/arm64/include/asm/kasan-tags.h b/arch/arm64/include/asm/kasan-tags.h
new file mode 100644
index 000000000000..9e835da95f6b
--- /dev/null
+++ b/arch/arm64/include/asm/kasan-tags.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_KASAN_TAGS_H
+#define __ASM_KASAN_TAGS_H
+
+#define KASAN_TAG_KERNEL 0xFF /* native kernel pointers tag */
+
+#define KASAN_TAG_WIDTH 8
+
+#endif /* ASM_KASAN_TAGS_H */
diff --git a/arch/x86/include/asm/kasan-tags.h b/arch/x86/include/asm/kasan-tags.h
new file mode 100644
index 000000000000..68ba385bc75c
--- /dev/null
+++ b/arch/x86/include/asm/kasan-tags.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ASM_KASAN_TAGS_H
+#define __ASM_KASAN_TAGS_H
+
+#define KASAN_TAG_KERNEL 0xF /* native kernel pointers tag */
+
+#define KASAN_TAG_WIDTH 4
+
+#endif /* ASM_KASAN_TAGS_H */
diff --git a/include/linux/kasan-tags.h b/include/linux/kasan-tags.h
index e07c896f95d3..ad5c11950233 100644
--- a/include/linux/kasan-tags.h
+++ b/include/linux/kasan-tags.h
@@ -2,7 +2,13 @@
#ifndef _LINUX_KASAN_TAGS_H
#define _LINUX_KASAN_TAGS_H
-#include <asm/kasan.h>
+#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)
+#include <asm/kasan-tags.h>
+#endif
+
+#ifndef KASAN_TAG_WIDTH
+#define KASAN_TAG_WIDTH 0
+#endif
#ifndef KASAN_TAG_KERNEL
#define KASAN_TAG_KERNEL 0xFF /* native kernel pointers tag */
diff --git a/include/linux/kasan.h b/include/linux/kasan.h
index b396feca714f..54481f8c30c5 100644
--- a/include/linux/kasan.h
+++ b/include/linux/kasan.h
@@ -40,7 +40,9 @@ typedef unsigned int __bitwise kasan_vmalloc_flags_t;
#ifdef CONFIG_KASAN_SW_TAGS
/* This matches KASAN_TAG_INVALID. */
-#define KASAN_SHADOW_INIT 0xFE
+#ifndef KASAN_SHADOW_INIT
+#define KASAN_SHADOW_INIT KASAN_TAG_INVALID
+#endif
#else
#define KASAN_SHADOW_INIT 0
#endif
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 7b1068ddcbb7..0b1d21864294 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1824,7 +1824,7 @@ static inline u8 page_kasan_tag(const struct page *page)
if (kasan_enabled()) {
tag = (page->flags >> KASAN_TAG_PGSHIFT) & KASAN_TAG_MASK;
- tag ^= 0xff;
+ tag ^= KASAN_TAG_KERNEL;
}
return tag;
@@ -1837,7 +1837,7 @@ static inline void page_kasan_tag_set(struct page *page, u8 tag)
if (!kasan_enabled())
return;
- tag ^= 0xff;
+ tag ^= KASAN_TAG_KERNEL;
old_flags = READ_ONCE(page->flags);
do {
flags = old_flags;
@@ -1856,7 +1856,7 @@ static inline void page_kasan_tag_reset(struct page *page)
static inline u8 page_kasan_tag(const struct page *page)
{
- return 0xff;
+ return KASAN_TAG_KERNEL;
}
static inline void page_kasan_tag_set(struct page *page, u8 tag) { }
diff --git a/include/linux/page-flags-layout.h b/include/linux/page-flags-layout.h
index 4f5c9e979bb9..b2cc4cb870e0 100644
--- a/include/linux/page-flags-layout.h
+++ b/include/linux/page-flags-layout.h
@@ -3,6 +3,7 @@
#define PAGE_FLAGS_LAYOUT_H
#include <linux/numa.h>
+#include <linux/kasan-tags.h>
#include <generated/bounds.h>
/*
@@ -72,12 +73,6 @@
#define NODE_NOT_IN_PAGE_FLAGS 1
#endif
-#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)
-#define KASAN_TAG_WIDTH 8
-#else
-#define KASAN_TAG_WIDTH 0
-#endif
-
#ifdef CONFIG_NUMA_BALANCING
#define LAST__PID_SHIFT 8
#define LAST__PID_MASK ((1 << LAST__PID_SHIFT)-1)
--
2.47.1
next prev parent reply other threads:[~2025-02-18 8:17 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-18 8:15 [PATCH v2 00/14] kasan: x86: arm64: KASAN tag-based mode for x86 Maciej Wieczor-Retman
2025-02-18 8:15 ` [PATCH v2 01/14] kasan: sw_tags: Use arithmetic shift for shadow computation Maciej Wieczor-Retman
2025-02-19 23:29 ` Andrey Konovalov
2025-02-21 13:11 ` Maciej Wieczor-Retman
2025-02-22 15:06 ` Andrey Konovalov
2025-02-25 17:20 ` Maciej Wieczor-Retman
2025-02-25 19:12 ` Maciej Wieczor-Retman
2025-02-25 20:12 ` Maciej Wieczor-Retman
2025-02-25 21:38 ` Andrey Konovalov
2025-02-26 16:42 ` Maciej Wieczor-Retman
2025-02-26 19:44 ` Andrey Konovalov
2025-02-27 12:27 ` Maciej Wieczor-Retman
2025-02-28 16:12 ` Maciej Wieczor-Retman
2025-03-01 0:21 ` Andrey Konovalov
2025-03-04 14:06 ` Maciej Wieczor-Retman
2025-03-07 1:10 ` Andrey Konovalov
2025-03-13 14:56 ` Maciej Wieczor-Retman
2025-03-18 15:31 ` Andrey Konovalov
2025-02-25 21:37 ` Andrey Konovalov
2025-02-27 12:33 ` Maciej Wieczor-Retman
2025-03-01 0:22 ` Andrey Konovalov
2025-03-04 12:29 ` Maciej Wieczor-Retman
2025-03-07 1:10 ` Andrey Konovalov
2025-03-14 15:57 ` Maciej Wieczor-Retman
2025-03-18 15:32 ` Andrey Konovalov
2025-02-18 8:15 ` [PATCH v2 02/14] kasan: sw_tags: Check kasan_flag_enabled at runtime Maciej Wieczor-Retman
2025-02-19 23:30 ` Andrey Konovalov
2025-02-21 14:35 ` Maciej Wieczor-Retman
2025-02-18 8:15 ` [PATCH v2 03/14] kasan: sw_tags: Support outline stack tag generation Maciej Wieczor-Retman
2025-02-19 23:30 ` Andrey Konovalov
2025-02-18 8:15 ` [PATCH v2 04/14] kasan: sw_tags: Support tag widths less than 8 bits Maciej Wieczor-Retman
2025-02-18 8:15 ` Maciej Wieczor-Retman [this message]
2025-02-18 8:15 ` [PATCH v2 06/14] x86: Add arch specific kasan functions Maciej Wieczor-Retman
2025-02-19 23:30 ` Andrey Konovalov
2025-02-21 8:40 ` Maciej Wieczor-Retman
2025-02-18 8:15 ` [PATCH v2 07/14] x86: Reset tag for virtual to physical address conversions Maciej Wieczor-Retman
2025-02-18 8:15 ` [PATCH v2 08/14] x86: Physical address comparisons in fill_p*d/pte Maciej Wieczor-Retman
2025-02-18 8:15 ` [PATCH v2 09/14] mm: Pcpu chunk address tag reset Maciej Wieczor-Retman
2025-03-20 17:39 ` Andrey Ryabinin
2025-03-20 17:47 ` Andrey Konovalov
2025-03-21 10:40 ` Maciej Wieczor-Retman
2025-02-18 8:15 ` [PATCH v2 10/14] x86: KASAN raw shadow memory PTE init Maciej Wieczor-Retman
2025-02-18 8:15 ` [PATCH v2 11/14] x86: LAM initialization Maciej Wieczor-Retman
2025-02-18 8:15 ` [PATCH v2 12/14] x86: Minimal SLAB alignment Maciej Wieczor-Retman
2025-02-19 23:30 ` Andrey Konovalov
2025-02-21 7:24 ` Maciej Wieczor-Retman
2025-02-18 8:15 ` [PATCH v2 13/14] x86: runtime_const used for KASAN_SHADOW_END Maciej Wieczor-Retman
2025-02-19 23:31 ` Andrey Konovalov
2025-02-21 15:10 ` Maciej Wieczor-Retman
2025-02-21 15:27 ` Maciej Wieczor-Retman
2025-02-22 15:08 ` Andrey Konovalov
2025-02-22 15:07 ` Andrey Konovalov
2025-02-25 17:15 ` Maciej Wieczor-Retman
2025-02-25 21:37 ` Andrey Konovalov
2025-02-26 11:52 ` Maciej Wieczor-Retman
2025-02-26 15:24 ` Andrey Konovalov
2025-02-26 17:03 ` Maciej Wieczor-Retman
2025-03-21 19:20 ` Maciej Wieczor-Retman
2025-03-21 20:16 ` Andrey Konovalov
2025-03-24 10:43 ` Maciej Wieczor-Retman
2025-03-24 10:50 ` Maciej Wieczor-Retman
2025-03-24 21:58 ` Andrey Konovalov
2025-02-18 8:15 ` [PATCH v2 14/14] x86: Make software tag-based kasan available Maciej Wieczor-Retman
2025-02-19 23:31 ` Andrey Konovalov
2025-02-20 16:32 ` Andrey Konovalov
2025-02-21 14:44 ` Maciej Wieczor-Retman
2025-02-22 15:06 ` Andrey Konovalov
2025-02-25 15:39 ` Maciej Wieczor-Retman
2025-02-20 2:49 ` kernel test robot
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=e1cffdd3ec7aac6c047650141ba3be96888cb817.1739866028.git.maciej.wieczor-retman@intel.com \
--to=maciej.wieczor-retman@intel.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=ankita@nvidia.com \
--cc=apopple@nvidia.com \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=baohua@kernel.org \
--cc=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=cl@linux.com \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=david@redhat.com \
--cc=dennis@kernel.org \
--cc=dvyukov@google.com \
--cc=dwmw@amazon.co.uk \
--cc=glider@google.com \
--cc=guoweikang.kernel@gmail.com \
--cc=hpa@zytor.com \
--cc=jan.kiszka@siemens.com \
--cc=jason.andryuk@amd.com \
--cc=jgross@suse.com \
--cc=jhubbard@nvidia.com \
--cc=julian.stecklina@cyberus-technology.de \
--cc=justinstitt@google.com \
--cc=kaleshsingh@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=kbingham@kernel.org \
--cc=kees@kernel.org \
--cc=kevinloughlin@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=kuan-ying.lee@canonical.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=llvm@lists.linux.dev \
--cc=luto@kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=pankaj.gupta@amd.com \
--cc=pasha.tatashin@soleen.com \
--cc=pawan.kumar.gupta@linux.intel.com \
--cc=peterz@infradead.org \
--cc=rafael.j.wysocki@intel.com \
--cc=richard.weiyang@gmail.com \
--cc=rppt@kernel.org \
--cc=ryabinin.a.a@gmail.com \
--cc=samuel.holland@sifive.com \
--cc=scott@os.amperecomputing.com \
--cc=surenb@google.com \
--cc=tglx@linutronix.de \
--cc=thiago.bauermann@linaro.org \
--cc=thomas.weissschuh@linutronix.de \
--cc=tj@kernel.org \
--cc=tony.luck@intel.com \
--cc=vincenzo.frascino@arm.com \
--cc=wangkefeng.wang@huawei.com \
--cc=will@kernel.org \
--cc=x86@kernel.org \
--cc=xin@zytor.com \
--cc=xur@google.com \
--cc=ytcoode@gmail.com \
--cc=ziy@nvidia.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