• Nenhum resultado encontrado

Detection of undefined behavior using KLEE

N/A
N/A
Protected

Academic year: 2024

Share "Detection of undefined behavior using KLEE"

Copied!
11
0
0

Texto

(1)

Detection of undefined behavior using KLEE

Pavel Iatchenii

(2)

What is undefined behavior?

Not unspecified behavior

Not implementation-defined behavior

”Behavior, upon the use of a non-portable or erroneous program construct or of erroneous data, for which International Standard imposes no requirements”

(C99 standard)

“Anything at all can happen; the Standard imposes no requirements. The program may fail to compile, or it may execute incorrectly…” (comp.lang.c)

(3)

UB in symbolic execution

● Injection of checks by KLEE

Division by zero

Overshift overflow

● Natural processing by KLEE

Dereferencing a nullptr

Reaching an unreachable program point

● Cases that are hard to catch without code instrumentation

Integer overflow

Load of invalid enum value

Use of a misaligned pointer

(4)

Motivating examples

Signed integer overflow

Undefined Behavior

Implicit conversion with data loss

Unintentional behavior

int abs(int x) {

if (x <= 0) { return −x;

}

return x;

unsigned char convert(signed int x){

// some optional code return x;

}

(5)

UndefinedBehaviorSanitizer (LLVM)

Code generator, uses compile-time instrumentation to insert certain checks along with handlers

Runtime, implements those handlers and exits the program if so configured

(6)

UndefinedBehaviorSanitizer (KLEE)

● LLVM code generator as is, adding -fsanitize=* flags to Clang compiler is sufficient to instrument bitcode

Adopted LLVM runtime, to accurately analyse the passed arguments containing source location, kind of check, and values

(7)

Default compilation

int abs(int x) {

if (x <= 0) { return -x;

}

return x;

}

6:

%7 = load i32, i32* %3, align 4 %8 = sub nsw i32 0, %7

store i32 %8, i32* %2, align 4 br label %11

(8)

Compilation using UBSan

int abs(int x) {

if (x <= 0) { return -x;

}

return x;

}

6:

%7 = load i32, i32* %3, align 4

%8 = call { i32, i1 } @llvm.ssub.with.overflow.i32 (i32 0, i32

%7)

%9 = extractvalue { i32, i1 } %8, 0 %10 = extractvalue { i32, i1 } %8, 1 %11 = xor i1 %10, true

br i1 %11, label %14, label %12

12:

%13 = zext i32 %7 to i64, !nosanitize !5

(9)

Runtime adoption

Common diagnostic emission

static void handleNegateOverflowImpl(

OverflowData *Data,

ValueHandle /*OldVal*/) { bool IsSigned =

Data->Type.isSignedIntegerTy();

ErrorType ET = IsSigned ?

SignedIntegerOverflow : UnsignedIntegerOverflow;

Handler

extern "C" void

__ubsan_handle_negate_overflow(

OverflowData *Data, ValueHandle OldVal) { handleNegateOverflowImpl(

Data, OldVal );

}

(10)

Results

KLEE extension as an effort to get better in the detection of undefined behavior and unintentional issues

● The relevant test cases from LLVM sources resulted in error tests, both for symbolic and concrete values

● Actively used in UTBotCpp and succeeds in finding issues on critical projects

(11)

References

● Pull request ”Support UBSan-enabled binaries” to KLEE mainline github.com/klee/klee/pull/1378

● UndefinedBehaviorSanitizer documentation

clang.llvm.org/docs/UndefinedBehaviorSanitizer.html

● UTBotCpp documentation utbot.org

Referências

Documentos relacionados

This does not negate the role of haematuria as a sign of schistosome infection or detection of parasite eggs as a diagnostic, but it provides a secure additional test for specific

The other seven indicators showed differences between the pair of evaluators who did not use operational de fi nitions, except for the indicator, Uses bed or ham- mock safely,

BioUnits are often not available, are duplicates of the Asymmetric Unit with little justification for that assignment, or are specified for non-native interactions as in the case

Viral RNA positive mosquito pools would then be PCR amplified using the GSPs for the genus (or genera) of interest and analyzed using the microarray platform. These PCR assays

The aim of this study was to use three-dimensional nonlinear finite element analysis to evaluate the mechanical behavior of ceramic veneers, partially debonded or

List of mRNAs that were down-regulated or up-regulated at least 3- fold, compared to similarly staged WT embryos in cycle 14, upon ablation of each chromosome, and that were

Use of tool or not (‘‘Tool’’), number of previous trials of the same type (either with or without the tool, [‘‘Learning’’], for learning-phase testing only), field

A reliable diagnosis of PCT via HPLC urinary analysis seems to be more complex because all porphyrin - URO, HEPTA, HEXA, PENTA, or total COPRO - levels do not appear to follow