78 lines · c
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 we4// 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>&18// RUN: FileCheck %s < %t.out9//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>&112// RUN: FileCheck %s < %t.out13//14// RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 %s -o %t && \15// RUN: %run %t >%t.out 2>&116// RUN: FileCheck %s < %t.out17//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>&120// RUN: FileCheck %s < %t.out21 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() {33 y = x;34 memcpy(&u, &y, sizeof(int));35}36 37void SignalHandler(int signo) {38 CopyXtoYtoU();39}40 41void SignalAction(int signo, siginfo_t *si, void *uc) {42 CopyXtoYtoU();43}44 45int main(int argc, char *argv[]) {46 int z = 1;47 dfsan_set_label(8, &z, sizeof(z));48 x = z;49 50 struct sigaction psa = {};51#ifdef USE_SIGNAL_ACTION52 psa.sa_flags = SA_SIGINFO;53 psa.sa_sigaction = SignalAction;54#else55 psa.sa_flags = 0;56 psa.sa_handler = SignalHandler;57#endif58 sigaction(SIGHUP, &psa, NULL);59 kill(getpid(), SIGHUP);60 signal(SIGHUP, SIG_DFL);61 62 assert(x == 1);63 assert(y == 1);64 assert(u == 1);65 66 dfsan_print_origin_trace(&u, NULL);67 return 0;68}69 70// CHECK: Taint value 0x8 {{.*}} origin tracking ()71// CHECK: Origin value: {{.*}}, Taint value was stored to memory at72// 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 at77// CHECK: #0 {{.*}} in main {{.*}}origin_with_sigactions.c:[[@LINE-30]]78