diff --git a/BCB/Cheang et al/Example CV/exCV.c b/BCB/Cheang et al/Example CV/exCV.c index 819e81b3d046c714b795c144bfbd465e87845871..e7183d44b36646cabafc4ba9c5e8e55fe58e45b3 100644 --- a/BCB/Cheang et al/Example CV/exCV.c +++ b/BCB/Cheang et al/Example CV/exCV.c @@ -1,5 +1,6 @@ #include "../ex_main.h" +__declspec(dllexport) uint8_t foo(unsigned i) { if (i < array1_size) { uint8_t v = array1[0]; diff --git a/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.bil b/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.bil new file mode 100644 index 0000000000000000000000000000000000000000..5bd4ea6f13c823df1a1681a2c278c21ad6dd6154 Binary files /dev/null and b/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.bil differ diff --git a/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.bir b/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.bir new file mode 100644 index 0000000000000000000000000000000000000000..b5ea4cc34fe5d067b102293b5eee9ab0fdddc8fd Binary files /dev/null and b/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.bir differ diff --git a/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.cod b/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.cod index 87e152b5c5eecc0d709cb36a5251bf23c7465199..c1ac7a86b179c2de38a8ccf9aadab4ee1e3f8835 100644 --- a/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.cod +++ b/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.cod @@ -1,4 +1,4 @@ -; Listing generated by Microsoft (R) Optimizing Compiler Version 19.30.30706.0 +; Listing generated by Microsoft (R) Optimizing Compiler Version 19.35.32216.1 include listing.inc @@ -9,68 +9,45 @@ PUBLIC foo EXTRN array1_size:QWORD EXTRN array1:BYTE EXTRN array2:BYTE -pdata SEGMENT -$pdata$foo DD imagerel $LN6 - DD imagerel $LN6+83 - DD imagerel $unwind$foo -pdata ENDS -xdata SEGMENT -$unwind$foo DD 010801H - DD 02208H -xdata ENDS -; Function compile flags: /Odtp +; Function compile flags: /Ogtpy ; File B:\Users\Matt\Documents\scratch\spectre-db\BCB\Cheang et al\Example CV\exCV.c +; COMDAT foo _TEXT SEGMENT -v$1 = 0 -i$ = 32 -foo PROC +i$ = 8 +foo PROC ; COMDAT -; 3 : uint8_t foo(unsigned i) { +; 5 : if (i < array1_size) { -$LN6: - 00000 89 4c 24 08 mov DWORD PTR [rsp+8], ecx - 00004 48 83 ec 18 sub rsp, 24 - -; 4 : if (i < array1_size) { - - 00008 8b 44 24 20 mov eax, DWORD PTR i$[rsp] - 0000c 48 3b 05 00 00 + 00000 8b c1 mov eax, ecx + 00002 48 3b 05 00 00 00 00 cmp rax, QWORD PTR array1_size - 00013 73 37 jae SHORT $LN2@foo + 00009 73 1b jae SHORT $LN2@foo -; 5 : uint8_t v = array1[0]; +; 6 : uint8_t v = array1[0]; +; 7 : return array2[v*512]+i; - 00015 0f ae e8 lfence - 00018 b8 01 00 00 00 mov eax, 1 - 0001d 48 6b c0 00 imul rax, rax, 0 - 00021 48 8d 0d 00 00 - 00 00 lea rcx, OFFSET FLAT:array1 - 00028 0f b6 04 01 movzx eax, BYTE PTR [rcx+rax] - 0002c 88 04 24 mov BYTE PTR v$1[rsp], al + 0000b 0f ae e8 lfence + 0000e 0f b6 15 00 00 + 00 00 movzx edx, BYTE PTR array1 + 00015 48 8d 05 00 00 + 00 00 lea rax, OFFSET FLAT:array2 + 0001c c1 e2 09 shl edx, 9 + 0001f 02 0c 02 add cl, BYTE PTR [rdx+rax] + 00022 0f b6 c1 movzx eax, cl -; 6 : return array2[v*512]+i; +; 10 : } - 0002f 0f b6 04 24 movzx eax, BYTE PTR v$1[rsp] - 00033 69 c0 00 02 00 - 00 imul eax, eax, 512 ; 00000200H - 00039 48 98 cdqe - 0003b 48 8d 0d 00 00 - 00 00 lea rcx, OFFSET FLAT:array2 - 00042 0f b6 04 01 movzx eax, BYTE PTR [rcx+rax] - 00046 03 44 24 20 add eax, DWORD PTR i$[rsp] - 0004a eb 02 jmp SHORT $LN1@foo + 00025 c3 ret 0 $LN2@foo: -; 7 : } -; 8 : return 0; +; 8 : } +; 9 : return 0; - 0004c 32 c0 xor al, al -$LN1@foo: + 00026 32 c0 xor al, al -; 9 : } +; 10 : } - 0004e 48 83 c4 18 add rsp, 24 - 00052 c3 ret 0 + 00028 c3 ret 0 foo ENDP _TEXT ENDS END diff --git a/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.dll b/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.dll index 4c4377d50ae3c1db1ac8ada00f5fa52ee12e4151..8b677f2afd3da56faf700e201d1ee72aa7bf5224 100644 Binary files a/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.dll and b/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.dll differ diff --git a/BCB/Cheang et al/Example CV/msvc/exCV.bil b/BCB/Cheang et al/Example CV/msvc/exCV.bil new file mode 100644 index 0000000000000000000000000000000000000000..57720e579adc884bdac874709f15d6c80cf7a33b Binary files /dev/null and b/BCB/Cheang et al/Example CV/msvc/exCV.bil differ diff --git a/BCB/Cheang et al/Example CV/msvc/exCV.bir b/BCB/Cheang et al/Example CV/msvc/exCV.bir new file mode 100644 index 0000000000000000000000000000000000000000..f4f8d3d92c488320e393f5f2ea6dfcfe79a9df80 Binary files /dev/null and b/BCB/Cheang et al/Example CV/msvc/exCV.bir differ diff --git a/BCB/Cheang et al/Example CV/msvc/exCV.cod b/BCB/Cheang et al/Example CV/msvc/exCV.cod index c2cc6098e3583e8a8f03809d07dde3d01f1771f1..302c26002e55f5a847f1bf40daccd5998b79ce41 100644 --- a/BCB/Cheang et al/Example CV/msvc/exCV.cod +++ b/BCB/Cheang et al/Example CV/msvc/exCV.cod @@ -1,4 +1,4 @@ -; Listing generated by Microsoft (R) Optimizing Compiler Version 19.30.30706.0 +; Listing generated by Microsoft (R) Optimizing Compiler Version 19.35.32216.1 include listing.inc @@ -9,67 +9,44 @@ PUBLIC foo EXTRN array1_size:QWORD EXTRN array1:BYTE EXTRN array2:BYTE -pdata SEGMENT -$pdata$foo DD imagerel $LN4 - DD imagerel $LN4+80 - DD imagerel $unwind$foo -pdata ENDS -xdata SEGMENT -$unwind$foo DD 010801H - DD 02208H -xdata ENDS -; Function compile flags: /Odtp +; Function compile flags: /Ogtpy ; File B:\Users\Matt\Documents\scratch\spectre-db\BCB\Cheang et al\Example CV\exCV.c +; COMDAT foo _TEXT SEGMENT -v$1 = 0 -i$ = 32 -foo PROC +i$ = 8 +foo PROC ; COMDAT -; 3 : uint8_t foo(unsigned i) { +; 5 : if (i < array1_size) { -$LN4: - 00000 89 4c 24 08 mov DWORD PTR [rsp+8], ecx - 00004 48 83 ec 18 sub rsp, 24 - -; 4 : if (i < array1_size) { - - 00008 8b 44 24 20 mov eax, DWORD PTR i$[rsp] - 0000c 48 3b 05 00 00 + 00000 8b c1 mov eax, ecx + 00002 48 3b 05 00 00 00 00 cmp rax, QWORD PTR array1_size - 00013 73 34 jae SHORT $LN2@foo + 00009 73 18 jae SHORT $LN2@foo -; 5 : uint8_t v = array1[0]; +; 6 : uint8_t v = array1[0]; +; 7 : return array2[v*512]+i; - 00015 b8 01 00 00 00 mov eax, 1 - 0001a 48 6b c0 00 imul rax, rax, 0 - 0001e 48 8d 0d 00 00 - 00 00 lea rcx, OFFSET FLAT:array1 - 00025 0f b6 04 01 movzx eax, BYTE PTR [rcx+rax] - 00029 88 04 24 mov BYTE PTR v$1[rsp], al + 0000b 0f b6 15 00 00 + 00 00 movzx edx, BYTE PTR array1 + 00012 48 8d 05 00 00 + 00 00 lea rax, OFFSET FLAT:array2 + 00019 c1 e2 09 shl edx, 9 + 0001c 02 0c 02 add cl, BYTE PTR [rdx+rax] + 0001f 0f b6 c1 movzx eax, cl -; 6 : return array2[v*512]+i; +; 10 : } - 0002c 0f b6 04 24 movzx eax, BYTE PTR v$1[rsp] - 00030 69 c0 00 02 00 - 00 imul eax, eax, 512 ; 00000200H - 00036 48 98 cdqe - 00038 48 8d 0d 00 00 - 00 00 lea rcx, OFFSET FLAT:array2 - 0003f 0f b6 04 01 movzx eax, BYTE PTR [rcx+rax] - 00043 03 44 24 20 add eax, DWORD PTR i$[rsp] - 00047 eb 02 jmp SHORT $LN1@foo + 00022 c3 ret 0 $LN2@foo: -; 7 : } -; 8 : return 0; +; 8 : } +; 9 : return 0; - 00049 32 c0 xor al, al -$LN1@foo: + 00023 32 c0 xor al, al -; 9 : } +; 10 : } - 0004b 48 83 c4 18 add rsp, 24 - 0004f c3 ret 0 + 00025 c3 ret 0 foo ENDP _TEXT ENDS END diff --git a/BCB/Cheang et al/Example CV/msvc/exCV.dll b/BCB/Cheang et al/Example CV/msvc/exCV.dll index 0a443b1747b572de88c3e9f30bec604906ff7ad2..2527d8a23bda2200491a4d164f8128485e0cab37 100644 Binary files a/BCB/Cheang et al/Example CV/msvc/exCV.dll and b/BCB/Cheang et al/Example CV/msvc/exCV.dll differ diff --git a/README.md b/README.md index 82582cda67f8dea695fa990955b643562c3a4e39..b6d61026659b1daac65e90d36fcc38525cae7610 100644 --- a/README.md +++ b/README.md @@ -162,3 +162,9 @@ docker run 8183a414c77e06b5da95b8283dbf44c9ea96c27818c0c8ed824b26aa400f7a bap '/ docker run 8183a414c77e06b5da95b8283dbf44c9ea96c27818c0c8ed824b26aa400f7a bap '/home/BCB/Paul Kocher/Example 10/msvc/ex10_cheang.dll' -dbir --optimization-level=3 --bil-enable-intrinsics=llvm:lfence > 'BCB/Paul Kocher/Example 10/msvc/ex10_cheang.bir' docker run 8183a414c77e06b5da95b8283dbf44c9ea96c27818c0c8ed824b26aa400f7a bap '/home/BCB/Paul Kocher/Example 10/msvc/ex10_cheang.dll' -dbil --optimization-level=3 --bil-enable-intrinsics=llvm:lfence > 'BCB/Paul Kocher/Example 10/msvc/ex10_cheang.bil' +docker run 4be24b861ed8 bap '/home/BCB/Cheang et al/Example CV/msvc/exCV.dll' -dbir --optimization-level=3 --bil-enable-intrinsics=llvm:lfence > 'BCB/Cheang et al/Example CV/msvc/exCV.bir' +docker run 4be24b861ed8 bap '/home/BCB/Cheang et al/Example CV/msvc/exCV.dll' -dbil --optimization-level=3 --bil-enable-intrinsics=llvm:lfence > 'BCB/Cheang et al/Example CV/msvc/exCV.bil' + +docker run 4be24b861ed8 bap '/home/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.dll' -dbir --optimization-level=3 --bil-enable-intrinsics=llvm:lfence > 'BCB/Cheang et al/Example CV/msvc/exCV-mitigated.bir' +docker run 4be24b861ed8 bap '/home/BCB/Cheang et al/Example CV/msvc/exCV-mitigated.dll' -dbil --optimization-level=3 --bil-enable-intrinsics=llvm:lfence > 'BCB/Cheang et al/Example CV/msvc/exCV-mitigated.bil' +