Skip to content

Commit

Permalink
bthread: disable ASan accounting for fibers on 32-bit sandbox
Browse files Browse the repository at this point in the history
For the sandbox architecture, we use __sanitizer_start_switch_fiber
and __sanitizer_finish_switch_fiber to tell ASan when we switch stacks.

If we don't, ASan complains that:

  ==2472828==WARNING: ASan is ignoring requested __asan_handle_no_return:
    stack top: 0xff9fc000; bottom 0xf3be8000; size: 0x0be14000 (199311360)
  False positive error reports may follow
  For details see google/sanitizers#189

This works on 64-bit sandbox, but 32-bit sandbox currently crashes on
bthread -v:

==2469590==AddressSanitizer CHECK failed: ../../../../../src/libsanitizer/asan/asan_poisoning.cpp:37 "((AddrIsAlignedByGranularity(addr + size))) != (0)" (0x0, 0x0)
    #0 0xf7a4aa46 in AsanCheckFailed ../../../../../src/libsanitizer/asan/asan_rtl.cpp:73
    #1 0xf7a6b5cf in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) ../../../../../src/libsanitizer/sanitizer_common/sanitizer_termination.cpp:78
    #2 0xf7a4489f in __asan::PoisonShadow(unsigned long, unsigned long, unsigned char) ../../../../../src/libsanitizer/asan/asan_poisoning.cpp:37
    #3 0xf7a4c81b in __asan_handle_no_return ../../../../../src/libsanitizer/asan/asan_rtl.cpp:595
    #4 0x566a1ce7 in bthread_schedule /home/a3f/dl/barebox-stm32mp/common/bthread.c:178
    #5 0x566a1d54 in bthread_reschedule /home/a3f/dl/barebox-stm32mp/common/bthread.c:165
    #6 0x566a1d80 in bthread_trampoline /home/a3f/dl/barebox-stm32mp/common/bthread.c:56
    #7 0x567f5bfb in coroutine_bootstrap (/home/a3f/dl/build/barebox/sandbox/barebox+0x1bdbfb)
    #8 0x567f5c4b in coroutine_trampoline (/home/a3f/dl/build/barebox/sandbox/barebox+0x1bdc4b)
    #9 0xf7f7056f  (linux-gate.so.1+0x56f)
    #10 0xf7f70558  (linux-gate.so.1+0x558)
    #11 0x56892fff  (/home/a3f/dl/build/barebox/sandbox/barebox+0x25afff)

Just disable the special ASan accounting there until this is figured
out. bthreads still function there, but ASan may yield false positives
according to the message. This does not affect non-sandbox platforms.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
  • Loading branch information
a3f authored and saschahauer committed Mar 22, 2021
1 parent ce45167 commit 4128066
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions arch/sandbox/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ config 64BIT
select ARCH_DMA_ADDR_T_64BIT
select PHYS_ADDR_T_64BIT

config 32BIT
def_bool !64BIT

config SANDBOX_LINUX_I386
bool "32-bit x86 barebox" if CC_HAS_LINUX_I386_SUPPORT

Expand Down
8 changes: 6 additions & 2 deletions common/bthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include <asm/setjmp.h>
#include <linux/overflow.h>

#if defined CONFIG_ASAN && !defined CONFIG_32BIT
#define HAVE_FIBER_SANITIZER
#endif

static struct bthread {
int (*threadfn)(void *);
union {
Expand All @@ -26,7 +30,7 @@ static struct bthread {
void *stack;
u32 stack_size;
struct list_head list;
#ifdef CONFIG_ASAN
#ifdef HAVE_FIBER_SANITIZER
void *fake_stack_save;
#endif
u8 awake :1;
Expand Down Expand Up @@ -178,7 +182,7 @@ void bthread_schedule(struct bthread *to)
finish_switch_fiber(from);
}

#ifdef CONFIG_ASAN
#ifdef HAVE_FIBER_SANITIZER

void __sanitizer_start_switch_fiber(void **fake_stack_save, const void *bottom, size_t size);
void __sanitizer_finish_switch_fiber(void *fake_stack_save, const void **bottom_old, size_t *size_old);
Expand Down

0 comments on commit 4128066

Please sign in to comment.