Skip to content

Commit 56dd8f4

Browse files
authored
Merge branch 'AFLplusplus:master' into master
2 parents 05e870d + dc19175 commit 56dd8f4

File tree

3 files changed

+61
-16
lines changed

3 files changed

+61
-16
lines changed

accel/tcg/tcg-runtime.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -734,13 +734,13 @@ target_long qasan_actions_dispatcher(void *cpu_env,
734734
#ifdef ASAN_GIOVESE
735735
case QASAN_ACTION_CHECK_LOAD:
736736
if (asan_giovese_guest_loadN(arg1, arg2)) {
737-
asan_giovese_report_and_crash(ACCESS_TYPE_LOAD, arg1, arg2, PC_GET(env), BP_GET(env), SP_GET(env));
737+
asan_giovese_report_and_crash(ACCESS_TYPE_LOAD, arg1, arg2, env);
738738
}
739739
break;
740740

741741
case QASAN_ACTION_CHECK_STORE:
742742
if (asan_giovese_guest_storeN(arg1, arg2)) {
743-
asan_giovese_report_and_crash(ACCESS_TYPE_STORE, arg1, arg2, PC_GET(env), BP_GET(env), SP_GET(env));
743+
asan_giovese_report_and_crash(ACCESS_TYPE_STORE, arg1, arg2, env);
744744
}
745745
break;
746746

@@ -849,7 +849,7 @@ void HELPER(qasan_load1)(CPUArchState *env, target_ulong addr) {
849849

850850
#ifdef ASAN_GIOVESE
851851
if (asan_giovese_load1(ptr)) {
852-
asan_giovese_report_and_crash(ACCESS_TYPE_LOAD, addr, 1, PC_GET(env), BP_GET(env), SP_GET(env));
852+
asan_giovese_report_and_crash(ACCESS_TYPE_LOAD, addr, 1, env);
853853
}
854854
#else
855855
__asan_load1(ptr);
@@ -867,7 +867,7 @@ void HELPER(qasan_load2)(CPUArchState *env, target_ulong addr) {
867867

868868
#ifdef ASAN_GIOVESE
869869
if (asan_giovese_load2(ptr)) {
870-
asan_giovese_report_and_crash(ACCESS_TYPE_LOAD, addr, 2, PC_GET(env), BP_GET(env), SP_GET(env));
870+
asan_giovese_report_and_crash(ACCESS_TYPE_LOAD, addr, 2, env);
871871
}
872872
#else
873873
__asan_load2(ptr);
@@ -885,7 +885,7 @@ void HELPER(qasan_load4)(CPUArchState *env, target_ulong addr) {
885885

886886
#ifdef ASAN_GIOVESE
887887
if (asan_giovese_load4(ptr)) {
888-
asan_giovese_report_and_crash(ACCESS_TYPE_LOAD, addr, 4, PC_GET(env), BP_GET(env), SP_GET(env));
888+
asan_giovese_report_and_crash(ACCESS_TYPE_LOAD, addr, 4, env);
889889
}
890890
#else
891891
__asan_load4(ptr);
@@ -903,7 +903,7 @@ void HELPER(qasan_load8)(CPUArchState *env, target_ulong addr) {
903903

904904
#ifdef ASAN_GIOVESE
905905
if (asan_giovese_load8(ptr)) {
906-
asan_giovese_report_and_crash(ACCESS_TYPE_LOAD, addr, 8, PC_GET(env), BP_GET(env), SP_GET(env));
906+
asan_giovese_report_and_crash(ACCESS_TYPE_LOAD, addr, 8, env);
907907
}
908908
#else
909909
__asan_load8(ptr);
@@ -921,7 +921,7 @@ void HELPER(qasan_store1)(CPUArchState *env, target_ulong addr) {
921921

922922
#ifdef ASAN_GIOVESE
923923
if (asan_giovese_store1(ptr)) {
924-
asan_giovese_report_and_crash(ACCESS_TYPE_STORE, addr, 1, PC_GET(env), BP_GET(env), SP_GET(env));
924+
asan_giovese_report_and_crash(ACCESS_TYPE_STORE, addr, 1, env);
925925
}
926926
#else
927927
__asan_store1(ptr);
@@ -939,7 +939,7 @@ void HELPER(qasan_store2)(CPUArchState *env, target_ulong addr) {
939939

940940
#ifdef ASAN_GIOVESE
941941
if (asan_giovese_store2(ptr)) {
942-
asan_giovese_report_and_crash(ACCESS_TYPE_STORE, addr, 2, PC_GET(env), BP_GET(env), SP_GET(env));
942+
asan_giovese_report_and_crash(ACCESS_TYPE_STORE, addr, 2, env);
943943
}
944944
#else
945945
__asan_store2(ptr);
@@ -957,7 +957,7 @@ void HELPER(qasan_store4)(CPUArchState *env, target_ulong addr) {
957957

958958
#ifdef ASAN_GIOVESE
959959
if (asan_giovese_store4(ptr)) {
960-
asan_giovese_report_and_crash(ACCESS_TYPE_STORE, addr, 4, PC_GET(env), BP_GET(env), SP_GET(env));
960+
asan_giovese_report_and_crash(ACCESS_TYPE_STORE, addr, 4, env);
961961
}
962962
#else
963963
__asan_store4(ptr);
@@ -975,7 +975,7 @@ void HELPER(qasan_store8)(CPUArchState *env, target_ulong addr) {
975975

976976
#ifdef ASAN_GIOVESE
977977
if (asan_giovese_store8(ptr)) {
978-
asan_giovese_report_and_crash(ACCESS_TYPE_STORE, addr, 8, PC_GET(env), BP_GET(env), SP_GET(env));
978+
asan_giovese_report_and_crash(ACCESS_TYPE_STORE, addr, 8, env);
979979
}
980980
#else
981981
__asan_store8(ptr);

qemuafl/asan-giovese-inl.h

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,9 +1294,11 @@ static void print_alloc_location(target_ulong addr, target_ulong fault_addr) {
12941294
}
12951295

12961296
int asan_giovese_report_and_crash(int access_type, target_ulong addr, size_t n,
1297-
target_ulong pc, target_ulong bp,
1298-
target_ulong sp) {
1297+
CPUArchState *env) {
12991298

1299+
target_ulong pc= PC_GET(env);
1300+
target_ulong bp= BP_GET(env);
1301+
target_ulong sp= SP_GET(env);
13001302
struct call_context ctx;
13011303
asan_giovese_populate_context(&ctx, pc);
13021304
target_ulong fault_addr = 0;
@@ -1367,9 +1369,53 @@ int asan_giovese_report_and_crash(int access_type, target_ulong addr, size_t n,
13671369
"==%d==ABORTING\n",
13681370
getpid());
13691371

1370-
signal(SIGABRT, SIG_DFL);
1371-
abort();
1372+
/*
1373+
* Rather than aborting this host, we signal a DATA ABORT in the guest and
1374+
* abort the cpu_loop. This results in the generation of a SIGSEGV and
1375+
* subsequent generation (if configured) of a core-file for the guest which is
1376+
* much more useful for debugging purposes.
1377+
*
1378+
* However, it should be noted that there are a few limitations to these core
1379+
* files. Firstly the CPU program counter is set to the start of the basic
1380+
* block rather that to the faulting instruction (hence the context printed
1381+
* above and the core file do not have an up to date instruction pointer) and
1382+
* secondly the core file does not include the address of fault (this is a
1383+
* limitation of the core file format).
1384+
*
1385+
* When translating basic blocks the DisasContext structure carries the
1386+
* instruction pointer thereby allowing RIP-relative instructions to be
1387+
* properly translated. However, during execution, it is the CPUArchState
1388+
* state which carries the register context (including the instruction
1389+
* pointer). However, since the instruction pointer at the point of execution
1390+
* is fixed for any given instruction, its value can be incorporated at
1391+
* instrumentation time rather than execution. This therefore avoids the
1392+
* overhead of updating the CPUArchState at the completion of each
1393+
* instruction. However, this state is required to be updated at the start of
1394+
* each block to allow functionality such as execution tracing (the -d exec
1395+
* argument)to work properly.
1396+
*/
1397+
1398+
/*
1399+
* Queue a SIGSEGV representing our fault.
1400+
*/
1401+
target_siginfo_t info = {
1402+
.si_signo = TARGET_SIGSEGV,
1403+
.si_errno = 0,
1404+
.si_code = TARGET_SEGV_MAPERR,
1405+
._sifields._sigfault._addr = fault_addr
1406+
};
1407+
queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
1408+
1409+
/*
1410+
* Set the CPU state to represent an interrupt. This is suffient to cause the
1411+
* cpu_loop to break out and handle the queued exceptions.
1412+
*/
1413+
CPUState *cs = env_cpu(env);
1414+
cs->exception_index = EXCP_INTERRUPT;
1415+
cpu_loop_exit(cs);
13721416

1417+
1418+
return 0;
13731419
}
13741420

13751421
static const char* singal_to_string[] = {

qemuafl/asan-giovese.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ int asan_giovese_unpoison_guest_region(target_ulong addr, size_t n);
140140
// addr is a guest pointer
141141

142142
int asan_giovese_report_and_crash(int access_type, target_ulong addr, size_t n,
143-
target_ulong pc, target_ulong bp,
144-
target_ulong sp);
143+
CPUArchState *env);
145144

146145
int asan_giovese_deadly_signal(int signum, target_ulong addr, target_ulong pc,
147146
target_ulong bp, target_ulong sp);

0 commit comments

Comments
 (0)