Skip to contentSkip to conversation

build: enable ASan for arm64

PATCH In review Volodymyr Fialko 4 participants 7 messages Nov 8, 2021 – Nov 12, 2021 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build: enable ASan for arm64

This patch defines ASAN_SHADOW_OFFSET for arm64 according to the ASan documentation. This offset should cover all arm64 VMAs supported by ASan.

---
 config/meson.build             | 2 +-
 doc/guides/prog_guide/asan.rst | 2 +-
 lib/eal/common/malloc_elem.h   | 3 +++
 3 files changed, 5 insertions(+), 2 deletions(-)
config/meson.build +1 -1
index 17b5bec406..7eb710c08d 100644
@@ -428,7 +428,7 @@ if get_option('b_sanitize') == 'address' or get_option('b_sanitize') == 'address
         dpdk_extra_ldflags += '-lasan'
     endif
 
-    if is_linux and arch_subdir == 'x86' and dpdk_conf.get('RTE_ARCH_64')
+    if is_linux and arch_subdir in ['x86', 'arm'] and dpdk_conf.get('RTE_ARCH_64')
         dpdk_conf.set10('RTE_MALLOC_ASAN', true)
     endif
 endif
doc/guides/prog_guide/asan.rst +1 -1
index 6d1b871c93..7a584427dd 100644
@@ -33,7 +33,7 @@ Example::
     "stty echo" command when an error occurs.
 
 ASan is aware of DPDK memory allocations, thanks to added instrumentation.
-This is only enabled on x86_64 at the moment.
+This is only enabled on x86_64 and arm64 at the moment.
 Other architectures may have to define ASAN_SHADOW_OFFSET.
 
 Example heap-buffer-overflow error
lib/eal/common/malloc_elem.h +3 -0
index 262d69bb3e..c00c7845ab 100644
@@ -107,6 +107,9 @@ malloc_elem_cookies_ok(const struct malloc_elem *elem)
 #ifdef RTE_ARCH_X86_64
 #define ASAN_SHADOW_OFFSET    0x00007fff8000
 #endif
+#ifdef RTE_ARCH_ARM64
+#define ASAN_SHADOW_OFFSET    0x001000000000
+#endif
 
 #define ASAN_SHADOW_GRAIN_SIZE	8
 #define ASAN_MEM_FREE_FLAG	0xfd
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Volodymyr Fialko

This patch defines ASAN_SHADOW_OFFSET for arm64 according to the ASan documentation. This offset should cover all arm64 VMAs supported by ASan.

---
 config/meson.build             | 2 +-
 doc/guides/prog_guide/asan.rst | 2 +-
 lib/eal/common/malloc_elem.h   | 3 +++
 3 files changed, 5 insertions(+), 2 deletions(-)
config/meson.build +1 -1
index 17b5bec406..7eb710c08d 100644
@@ -428,7 +428,7 @@ if get_option('b_sanitize') == 'address' or get_option('b_sanitize') == 'address
         dpdk_extra_ldflags += '-lasan'
     endif
 
-    if is_linux and arch_subdir == 'x86' and dpdk_conf.get('RTE_ARCH_64')
+    if is_linux and arch_subdir in ['x86', 'arm'] and dpdk_conf.get('RTE_ARCH_64')
         dpdk_conf.set10('RTE_MALLOC_ASAN', true)
     endif
 endif
doc/guides/prog_guide/asan.rst +0 -0
index 6d1b871c93..7a584427dd 100644

doc/guides/prog_guide/asan.rst Example:: · line 36

Quoted 5 lines
doc/guides/prog_guide/asan.rst +1 -1
@@ -33,7 +33,7 @@ Example::
     "stty echo" command when an error occurs.
 
 ASan is aware of DPDK memory allocations, thanks to added instrumentation.
-This is only enabled on x86_64 at the moment.
+This is only enabled on x86_64 and arm64 at the moment.

Nit: "only" can be removed now.

Quoted 8 lines
doc/guides/prog_guide/asan.rst +0 -0
 Other architectures may have to define ASAN_SHADOW_OFFSET.
 
 Example heap-buffer-overflow error
lib/eal/common/malloc_elem.h +0 -0
index 262d69bb3e..c00c7845ab 100644

lib/eal/common/malloc_elem.h malloc_elem_cookies_ok(const struct malloc_elem *elem) · line 112

Quoted 6 lines
lib/eal/common/malloc_elem.h +3 -0
@@ -107,6 +107,9 @@ malloc_elem_cookies_ok(const struct malloc_elem *elem)
 #ifdef RTE_ARCH_X86_64
 #define ASAN_SHADOW_OFFSET    0x00007fff8000
 #endif
+#ifdef RTE_ARCH_ARM64
+#define ASAN_SHADOW_OFFSET    0x001000000000
+#endif

The value lgtm, from gcc:
libsanitizer/asan/asan_mapping.h:static const u64
kAArch64_ShadowOffset64 = 1ULL << 36;
libsanitizer/asan/asan_mapping.h:# define SHADOW_OFFSET
kAArch64_ShadowOffset64

Quoted 6 lines
lib/eal/common/malloc_elem.h +0 -1
 #define ASAN_SHADOW_GRAIN_SIZE 8
 #define ASAN_MEM_FREE_FLAG     0xfd
--

2.25.1

I hope ppc will follow soon :-).

Signature · 1 line
David Marchand
Acked-by on v1 1/1
#2 lore raw
In reply to Volodymyr Fialko
Quoted 6 lines · Volodymyr Fialko

This patch defines ASAN_SHADOW_OFFSET for arm64 according to the ASan documentation. This offset should cover all arm64 VMAs supported by ASan.

++ Arm maintainers

Prefer to change the subject to eal/arm64: support ASan

Quoted 37 lines
---
 config/meson.build             | 2 +-
 doc/guides/prog_guide/asan.rst | 2 +-
 lib/eal/common/malloc_elem.h   | 3 +++
 3 files changed, 5 insertions(+), 2 deletions(-)
config/meson.build +1 -1
index 17b5bec406..7eb710c08d 100644
@@ -428,7 +428,7 @@ if get_option('b_sanitize') == 'address' or get_option('b_sanitize') == 'address
         dpdk_extra_ldflags += '-lasan'
     endif
 
-    if is_linux and arch_subdir == 'x86' and dpdk_conf.get('RTE_ARCH_64')
+    if is_linux and arch_subdir in ['x86', 'arm'] and dpdk_conf.get('RTE_ARCH_64')
         dpdk_conf.set10('RTE_MALLOC_ASAN', true)
     endif
 endif
doc/guides/prog_guide/asan.rst +1 -1
index 6d1b871c93..7a584427dd 100644
@@ -33,7 +33,7 @@ Example::
     "stty echo" command when an error occurs.
 
 ASan is aware of DPDK memory allocations, thanks to added instrumentation.
-This is only enabled on x86_64 at the moment.
+This is only enabled on x86_64 and arm64 at the moment.
 Other architectures may have to define ASAN_SHADOW_OFFSET.
 
 Example heap-buffer-overflow error
lib/eal/common/malloc_elem.h +0 -0
index 262d69bb3e..c00c7845ab 100644

lib/eal/common/malloc_elem.h malloc_elem_cookies_ok(const struct malloc_elem *elem) · line 110

Quoted 4 lines
lib/eal/common/malloc_elem.h +1 -0
@@ -107,6 +107,9 @@ malloc_elem_cookies_ok(const struct malloc_elem *elem)
 #ifdef RTE_ARCH_X86_64
 #define ASAN_SHADOW_OFFSET    0x00007fff8000
 #endif
+#ifdef RTE_ARCH_ARM64

Better to change to "else if" to be more foolproof

lib/eal/common/malloc_elem.h malloc_elem_cookies_ok(const struct malloc_elem *elem) · line 111

Quoted 1 line
lib/eal/common/malloc_elem.h +1 -0
+#define ASAN_SHADOW_OFFSET    0x001000000000

Add a minimal comment on why this value was selected instead of x86 value of 0x00007fff8000

With the above change,

Quoted 9 lines
lib/eal/common/malloc_elem.h +1 -0
+#endif
 
 
 

#define ASAN_SHADOW_GRAIN_SIZE 8
#define ASAN_MEM_FREE_FLAG 0xfd
--
2.25.1

#3 lore raw

PATCH v2 1/1 eal/arm64: support ASan

In reply to Volodymyr Fialko

This patch defines ASAN_SHADOW_OFFSET for arm64 according to the ASan documentation. This offset should cover all arm64 VMAs supported by ASan.

---
Changes since v1:
- changed the subject
- rewrite checks in "elif" manner

---
 config/meson.build             | 2 +-
 doc/guides/prog_guide/asan.rst | 2 +-
 lib/eal/common/malloc_elem.h   | 2 ++
 3 files changed, 4 insertions(+), 2 deletions(-)
config/meson.build +1 -1
index 17b5bec406..7eb710c08d 100644
@@ -428,7 +428,7 @@ if get_option('b_sanitize') == 'address' or get_option('b_sanitize') == 'address
         dpdk_extra_ldflags += '-lasan'
     endif
 
-    if is_linux and arch_subdir == 'x86' and dpdk_conf.get('RTE_ARCH_64')
+    if is_linux and arch_subdir in ['x86', 'arm'] and dpdk_conf.get('RTE_ARCH_64')
         dpdk_conf.set10('RTE_MALLOC_ASAN', true)
     endif
 endif
doc/guides/prog_guide/asan.rst +1 -1
index 6d1b871c93..28b2382fc7 100644
@@ -33,7 +33,7 @@ Example::
     "stty echo" command when an error occurs.
 
 ASan is aware of DPDK memory allocations, thanks to added instrumentation.
-This is only enabled on x86_64 at the moment.
+This is enabled on x86_64 and arm64 at the moment.
 Other architectures may have to define ASAN_SHADOW_OFFSET.
 
 Example heap-buffer-overflow error
lib/eal/common/malloc_elem.h +2 -0
index 262d69bb3e..26e937cea0 100644
@@ -106,6 +106,8 @@ malloc_elem_cookies_ok(const struct malloc_elem *elem)
 
 #ifdef RTE_ARCH_X86_64
 #define ASAN_SHADOW_OFFSET    0x00007fff8000
+#elif defined(RTE_ARCH_ARM64)
+#define ASAN_SHADOW_OFFSET    0x001000000000
 #endif
 
 #define ASAN_SHADOW_GRAIN_SIZE	8
Signature · 1 line
2.25.1
Acked-by on v2 1/1
#4 lore raw

Re: [dpdk-dev] [PATCH v2] eal/arm64: support ASan

Quoted 58 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Volodymyr Fialko
Sent: Tuesday, November 9, 2021 6:46 AM
To: [email protected]; Bruce Richardson <[email protected]>; Anatoly Burakov <[email protected]>
Cc: [email protected]; Volodymyr Fialko <[email protected]>; David Marchand <[email protected]>
Subject: [dpdk-dev] [PATCH v2] eal/arm64: support ASan

This patch defines ASAN_SHADOW_OFFSET for arm64 according to the ASan documentation. This offset should cover all arm64 VMAs supported by ASan.

---
Changes since v1:
- changed the subject
- rewrite checks in "elif" manner

---
 config/meson.build             | 2 +-
 doc/guides/prog_guide/asan.rst | 2 +-
 lib/eal/common/malloc_elem.h   | 2 ++
 3 files changed, 4 insertions(+), 2 deletions(-)
config/meson.build index renamed from config/meson.build +0 -0

17b5bec406..7eb710c08d 100644

config/meson.build +0 -0
@@ -428,7 +428,7 @@ if get_option('b_sanitize') == 'address' or

get_option('b_sanitize') == 'address

         dpdk_extra_ldflags += '-lasan'
     endif
config/meson.build +2 -1
-    if is_linux and arch_subdir == 'x86' and dpdk_conf.get('RTE_ARCH_64')
+    if is_linux and arch_subdir in ['x86', 'arm'] and
+ dpdk_conf.get('RTE_ARCH_64')
         dpdk_conf.set10('RTE_MALLOC_ASAN', true)
     endif
 endif
(quoted diff) +0 -0

b/doc/guides/prog_guide/asan.rst index 6d1b871c93..28b2382fc7 100644

doc/guides/prog_guide/asan.rst +1 -1
@@ -33,7 +33,7 @@ Example::
     "stty echo" command when an error occurs.
 
 ASan is aware of DPDK memory allocations, thanks to added instrumentation.
-This is only enabled on x86_64 at the moment.
+This is enabled on x86_64 and arm64 at the moment.
 Other architectures may have to define ASAN_SHADOW_OFFSET.
 
 Example heap-buffer-overflow error
lib/eal/common/malloc_elem.h +0 -0
index 262d69bb3e..26e937cea0 100644

lib/eal/common/malloc_elem.h malloc_elem_cookies_ok(const struct malloc_elem · line 111

Quoted 6 lines
lib/eal/common/malloc_elem.h +2 -0
@@ -106,6 +106,8 @@ malloc_elem_cookies_ok(const struct malloc_elem
 *elem)
 
 #ifdef RTE_ARCH_X86_64
 #define ASAN_SHADOW_OFFSET    0x00007fff8000
+#elif defined(RTE_ARCH_ARM64)
+#define ASAN_SHADOW_OFFSET    0x001000000000

As Jerin mentioned, it is better to add a comment on why this value was selected. My search told me that "this value has to match kAArch64_ShadowOffset64 as defined in libsanitizer/asan/asan_mapping.h".

With the change,

Quoted 5 lines
lib/eal/common/malloc_elem.h +0 -0
 #endif
 

#define ASAN_SHADOW_GRAIN_SIZE 8
--
2.25.1

#5 lore raw

PATCH v3 1/1 eal/arm64: support ASan

In reply to Volodymyr Fialko

This patch defines ASAN_SHADOW_OFFSET for arm64 according to the ASan documentation. This offset should cover all arm64 VMAs supported by ASan.

---
Changes since v2:
- added a comment that describes origin of the ASan shadow offset

Changes since v1:
- changed the subject
- rewrite checks in "elif" manner

---
 config/meson.build             | 2 +-
 doc/guides/prog_guide/asan.rst | 2 +-
 lib/eal/common/malloc_elem.h   | 6 ++++++
 3 files changed, 8 insertions(+), 2 deletions(-)
config/meson.build +1 -1
index 17b5bec406..7eb710c08d 100644
@@ -428,7 +428,7 @@ if get_option('b_sanitize') == 'address' or get_option('b_sanitize') == 'address
         dpdk_extra_ldflags += '-lasan'
     endif
 
-    if is_linux and arch_subdir == 'x86' and dpdk_conf.get('RTE_ARCH_64')
+    if is_linux and arch_subdir in ['x86', 'arm'] and dpdk_conf.get('RTE_ARCH_64')
         dpdk_conf.set10('RTE_MALLOC_ASAN', true)
     endif
 endif
doc/guides/prog_guide/asan.rst +1 -1
index 6d1b871c93..28b2382fc7 100644
@@ -33,7 +33,7 @@ Example::
     "stty echo" command when an error occurs.
 
 ASan is aware of DPDK memory allocations, thanks to added instrumentation.
-This is only enabled on x86_64 at the moment.
+This is enabled on x86_64 and arm64 at the moment.
 Other architectures may have to define ASAN_SHADOW_OFFSET.
 
 Example heap-buffer-overflow error
lib/eal/common/malloc_elem.h +6 -0
index 262d69bb3e..de14d22a62 100644
@@ -104,8 +104,14 @@ malloc_elem_cookies_ok(const struct malloc_elem *elem)
 
 #ifdef RTE_MALLOC_ASAN
 
+/*
+ * ASAN_SHADOW_OFFSET should match to the corresponding
+ * value defined in gcc/libsanitizer/asan/asan_mapping.h
+ */
 #ifdef RTE_ARCH_X86_64
 #define ASAN_SHADOW_OFFSET    0x00007fff8000
+#elif defined(RTE_ARCH_ARM64)
+#define ASAN_SHADOW_OFFSET    0x001000000000
 #endif
 
 #define ASAN_SHADOW_GRAIN_SIZE	8
Signature · 1 line
2.25.1
#6 lore raw

Re: [PATCH v3] eal/arm64: support ASan

Quoted 9 lines · Volodymyr Fialko

This patch defines ASAN_SHADOW_OFFSET for arm64 according to the ASan documentation. This offset should cover all arm64 VMAs supported by ASan.

Applied, thanks.

Signature · 1 line
David Marchand