Skip to content

Commit

Permalink
mm/sw_tags: add config for no longer checking for tags 0
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
W-M-R committed Oct 11, 2024
1 parent 2f26323 commit 0a25b45
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions mm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ config MM_KASAN_DISABLE_WRITES_CHECK
---help---
This option disable kasan writes check.

config MM_KASAN_SKIP_ZERO_TAGS
bool "Enable skip check zero tags"
default LIBC_MODLIB

config MM_KASAN_GLOBAL
bool "Enable global data check"
depends on MM_KASAN_ALL
Expand Down
10 changes: 9 additions & 1 deletion mm/kasan/sw_tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
(FAR void *)((((uint64_t)(addr)) & ~((uint64_t)0xff << KASAN_TAG_SHIFT)) | \
(((uint64_t)(tag)) << KASAN_TAG_SHIFT))

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

#define KASAN_SHADOW_SCALE (sizeof(uintptr_t))

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

tag = kasan_get_tag(addr);

#ifdef CONFIG_MM_KASAN_SKIP_ZERO_TAGS
if (tag == 0)
{
return false;
}
#endif

p = kasan_mem_to_shadow(addr, size);
if (p == NULL)
{
Expand Down

0 comments on commit 0a25b45

Please sign in to comment.