Skip to content

Commit 1ea300f

Browse files
committed
mm/sw_tags: add config for no longer checking for tags 0
When dynamically loading, the read-only data of arm64 architecture is accessed through PC offset. When opening the tag kasan, because the PC value does not have a tag, accessing the read-only data will be detected with a tag mismatch error. Signed-off-by: wangmingrong1 <[email protected]>
1 parent 2f26323 commit 1ea300f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

mm/Kconfig

+6
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ config MM_KASAN_DISABLE_WRITES_CHECK
326326
---help---
327327
This option disable kasan writes check.
328328

329+
config MM_KASAN_SKIP_ZERO_TAGS
330+
bool "Enable skip check zero tags"
331+
default LIBC_MODLIB
332+
---help---
333+
This option enables not checking for zero tags.
334+
329335
config MM_KASAN_GLOBAL
330336
bool "Enable global data check"
331337
depends on MM_KASAN_ALL

mm/kasan/sw_tags.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
(FAR void *)((((uint64_t)(addr)) & ~((uint64_t)0xff << KASAN_TAG_SHIFT)) | \
4444
(((uint64_t)(tag)) << KASAN_TAG_SHIFT))
4545

46-
#define kasan_random_tag() (rand() % ((1 << (64 - KASAN_TAG_SHIFT)) - 1))
46+
#define kasan_random_tag() (1 + rand() % ((1 << (64 - KASAN_TAG_SHIFT)) - 1))
4747

4848
#define KASAN_SHADOW_SCALE (sizeof(uintptr_t))
4949

@@ -103,6 +103,14 @@ kasan_is_poisoned(FAR const void *addr, size_t size)
103103
uint8_t tag;
104104

105105
tag = kasan_get_tag(addr);
106+
107+
#ifdef CONFIG_MM_KASAN_SKIP_ZERO_TAGS
108+
if (tag == 0)
109+
{
110+
return false;
111+
}
112+
#endif
113+
106114
p = kasan_mem_to_shadow(addr, size);
107115
if (p == NULL)
108116
{

0 commit comments

Comments
 (0)