Skip to content

Commit 052ea5b

Browse files
anchaoxiaoxiang781216
authored andcommitted
mm/kasan: extern kasan API only MM_KASAN is enabled
this PR will fix g_region_init is incorrectly linked to the image if MM_KASAN is not enabled. Signed-off-by: chao an <[email protected]>
1 parent 6a2e21d commit 052ea5b

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

include/nuttx/mm/kasan.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,20 @@
3636
* Pre-processor Definitions
3737
****************************************************************************/
3838

39-
#define kasan_init_early() kasan_stop()
40-
4139
#ifndef CONFIG_MM_KASAN
4240
# define kasan_poison(addr, size)
4341
# define kasan_unpoison(addr, size) addr
4442
# define kasan_register(addr, size)
4543
# define kasan_unregister(addr)
4644
# define kasan_reset_tag(addr) addr
45+
# define kasan_start()
46+
# define kasan_stop()
47+
# define kasan_debugpoint(t,a,s) 0
48+
# define kasan_init_early()
4749
#else
4850

51+
# define kasan_init_early() kasan_stop()
52+
4953
/****************************************************************************
5054
* Public Function Prototypes
5155
****************************************************************************/
@@ -141,8 +145,6 @@ void kasan_unregister(FAR void *addr);
141145

142146
FAR void *kasan_reset_tag(FAR const void *addr);
143147

144-
#endif /* CONFIG_MM_KASAN */
145-
146148
/****************************************************************************
147149
* Name: kasan_start
148150
*
@@ -204,4 +206,6 @@ int kasan_debugpoint(int type, FAR void *addr, size_t size);
204206
}
205207
#endif
206208

209+
#endif /* CONFIG_MM_KASAN */
210+
207211
#endif /* __INCLUDE_NUTTX_MM_KASAN_H */

mm/kasan/hook.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ struct kasan_watchpoint_s
115115
static struct kasan_watchpoint_s g_watchpoint[MM_KASAN_WATCHPOINT];
116116
#endif
117117

118+
#ifdef CONFIG_MM_KASAN
118119
static uint32_t g_region_init;
120+
#endif
119121

120122
/****************************************************************************
121123
* Private Functions
@@ -225,34 +227,37 @@ static inline void kasan_check_report(FAR const void *addr, size_t size,
225227
bool is_write,
226228
FAR void *return_address)
227229
{
230+
#ifdef CONFIG_MM_KASAN
228231
if (predict_false(size == 0 || g_region_init != KASAN_INIT_VALUE))
229232
{
230233
return;
231234
}
232235

233-
#ifndef CONFIG_MM_KASAN_DISABLE_NULL_POINTER_CHECK
236+
# ifndef CONFIG_MM_KASAN_DISABLE_NULL_POINTER_CHECK
234237
if (predict_false(addr == NULL))
235238
{
236239
kasan_report(addr, size, is_write, return_address);
237240
}
238-
#endif
241+
# endif
239242

240-
#ifndef CONFIG_MM_KASAN_NONE
243+
# ifndef CONFIG_MM_KASAN_NONE
241244
if (predict_false(kasan_is_poisoned(addr, size)))
242245
{
243246
kasan_report(addr, size, is_write, return_address);
244247
}
245-
#endif
248+
# endif
246249

247-
#if MM_KASAN_WATCHPOINT > 0
250+
# if MM_KASAN_WATCHPOINT > 0
248251
kasan_check_watchpoint(addr, size, is_write, return_address);
252+
# endif
249253
#endif
250254
}
251255

252256
/****************************************************************************
253257
* Public Functions
254258
****************************************************************************/
255259

260+
#ifdef CONFIG_MM_KASAN
256261
void kasan_start(void)
257262
{
258263
g_region_init = KASAN_INIT_VALUE;
@@ -262,6 +267,7 @@ void kasan_stop(void)
262267
{
263268
g_region_init = 0;
264269
}
270+
#endif
265271

266272
/****************************************************************************
267273
* Name: kasan_debugpoint

0 commit comments

Comments
 (0)