llvm-project
77 строк · 2.1 Кб
1// Check that stores in signal handlers are not recorded in origin history.
2//
3// Origin tracking uses ChainedOriginDepot that is not async signal safe, so we
4// do not track origins inside signal handlers.
5//
6// RUN: %clang_dfsan -gmlt -DUSE_SIGNAL_ACTION -mllvm -dfsan-track-origins=1 %s -o %t && \
7// RUN: %run %t >%t.out 2>&1
8// RUN: FileCheck %s < %t.out
9//
10// RUN: %clang_dfsan -gmlt -DUSE_SIGNAL_ACTION -mllvm -dfsan-instrument-with-call-threshold=0 -mllvm -dfsan-track-origins=1 %s -o %t && \
11// RUN: %run %t >%t.out 2>&1
12// RUN: FileCheck %s < %t.out
13//
14// RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 %s -o %t && \
15// RUN: %run %t >%t.out 2>&1
16// RUN: FileCheck %s < %t.out
17//
18// RUN: %clang_dfsan -gmlt -mllvm -dfsan-instrument-with-call-threshold=0 -mllvm -dfsan-track-origins=1 %s -o %t && \
19// RUN: %run %t >%t.out 2>&1
20// RUN: FileCheck %s < %t.out
21
22#include <sanitizer/dfsan_interface.h>
23
24#include <assert.h>
25#include <signal.h>
26#include <string.h>
27#include <sys/types.h>
28#include <unistd.h>
29
30int x, y, u;
31
32void CopyXtoYtoU() {
33y = x;
34memcpy(&u, &y, sizeof(int));
35}
36
37void SignalHandler(int signo) {
38CopyXtoYtoU();
39}
40
41void SignalAction(int signo, siginfo_t *si, void *uc) {
42CopyXtoYtoU();
43}
44
45int main(int argc, char *argv[]) {
46int z = 1;
47dfsan_set_label(8, &z, sizeof(z));
48x = z;
49
50struct sigaction psa = {};
51#ifdef USE_SIGNAL_ACTION
52psa.sa_flags = SA_SIGINFO;
53psa.sa_sigaction = SignalAction;
54#else
55psa.sa_flags = 0;
56psa.sa_handler = SignalHandler;
57#endif
58sigaction(SIGHUP, &psa, NULL);
59kill(getpid(), SIGHUP);
60signal(SIGHUP, SIG_DFL);
61
62assert(x == 1);
63assert(y == 1);
64assert(u == 1);
65
66dfsan_print_origin_trace(&u, NULL);
67return 0;
68}
69
70// CHECK: Taint value 0x8 {{.*}} origin tracking ()
71// CHECK: Origin value: {{.*}}, Taint value was stored to memory at
72// CHECK-NOT: {{.*}} in CopyXtoYtoU.dfsan {{.*}}origin_with_sigactions.c{{.*}}
73
74// CHECK: #0 {{.*}} in main {{.*}}origin_with_sigactions.c:[[@LINE-26]]
75
76// CHECK: Origin value: {{.*}}, Taint value was created at
77// CHECK: #0 {{.*}} in main {{.*}}origin_with_sigactions.c:[[@LINE-30]]
78