Skip to content

Commit 4c9d078

Browse files
theihorAlexei Starovoitov
authored andcommitted
selftests/bpf: Don't override SIGSEGV handler with ASAN
test_progs has custom SIGSEGV handler, which interferes with the address sanitizer [1]. Add an #ifndef to avoid this. Additionally, declare an __asan_on_error() to dump the test logs in the same way it happens in the custom SIGSEGV handler. [1] https://lore.kernel.org/bpf/73d832948b01dbc0ebc60d85574bdf8537f3a810.camel@gmail.com/ Acked-by: Mykyta Yatsenko <yatsenko@meta.com> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://lore.kernel.org/r/20260223191118.655185-3-ihor.solodrai@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent a2714e7 commit 4c9d078

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

tools/testing/selftests/bpf/test_progs.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,14 +1261,8 @@ int get_bpf_max_tramp_links(void)
12611261
return ret;
12621262
}
12631263

1264-
#define MAX_BACKTRACE_SZ 128
1265-
void crash_handler(int signum)
1264+
static void dump_crash_log(void)
12661265
{
1267-
void *bt[MAX_BACKTRACE_SZ];
1268-
size_t sz;
1269-
1270-
sz = backtrace(bt, ARRAY_SIZE(bt));
1271-
12721266
fflush(stdout);
12731267
stdout = env.stdout_saved;
12741268
stderr = env.stderr_saved;
@@ -1277,12 +1271,32 @@ void crash_handler(int signum)
12771271
env.test_state->error_cnt++;
12781272
dump_test_log(env.test, env.test_state, true, false, NULL);
12791273
}
1274+
}
1275+
1276+
#define MAX_BACKTRACE_SZ 128
1277+
1278+
void crash_handler(int signum)
1279+
{
1280+
void *bt[MAX_BACKTRACE_SZ];
1281+
size_t sz;
1282+
1283+
sz = backtrace(bt, ARRAY_SIZE(bt));
1284+
1285+
dump_crash_log();
1286+
12801287
if (env.worker_id != -1)
12811288
fprintf(stderr, "[%d]: ", env.worker_id);
12821289
fprintf(stderr, "Caught signal #%d!\nStack trace:\n", signum);
12831290
backtrace_symbols_fd(bt, sz, STDERR_FILENO);
12841291
}
12851292

1293+
#ifdef __SANITIZE_ADDRESS__
1294+
void __asan_on_error(void)
1295+
{
1296+
dump_crash_log();
1297+
}
1298+
#endif
1299+
12861300
void hexdump(const char *prefix, const void *buf, size_t len)
12871301
{
12881302
for (int i = 0; i < len; i++) {
@@ -1944,13 +1958,15 @@ int main(int argc, char **argv)
19441958
.parser = parse_arg,
19451959
.doc = argp_program_doc,
19461960
};
1961+
int err, i;
1962+
1963+
#ifndef __SANITIZE_ADDRESS__
19471964
struct sigaction sigact = {
19481965
.sa_handler = crash_handler,
19491966
.sa_flags = SA_RESETHAND,
1950-
};
1951-
int err, i;
1952-
1967+
};
19531968
sigaction(SIGSEGV, &sigact, NULL);
1969+
#endif
19541970

19551971
env.stdout_saved = stdout;
19561972
env.stderr_saved = stderr;

0 commit comments

Comments
 (0)