AddressSanitizer for Windows Timur Iskhodzhanov Google - - PowerPoint PPT Presentation

addresssanitizer for windows
SMART_READER_LITE
LIVE PREVIEW

AddressSanitizer for Windows Timur Iskhodzhanov Google - - PowerPoint PPT Presentation

AddressSanitizer for Windows Timur Iskhodzhanov Google AddressSanitizer (a.k.a. ASan) High performance Uses compile-time instrumentation Lightweight algorithm Multi-threaded Focuses on severe bugs buffer


slide-1
SLIDE 1

AddressSanitizer for Windows

Timur Iskhodzhanov Google

slide-2
SLIDE 2

AddressSanitizer (a.k.a. ASan)

  • High performance

○ Uses compile-time instrumentation ○ Lightweight algorithm ○ Multi-threaded

  • Focuses on severe bugs

○ buffer overflows ○ uses of freed / unavailable memory ○ and more

  • Supports Linux, Mac OS; more in development
slide-3
SLIDE 3

ASan overview follows

A more complete version: Konstantin Serebryany, Derek Bruening, Alexander Potapenko, Dmitry Vyukov, AddressSanitizer: a fast address sanity checker, Proceedings of the 2012 USENIX conference on Annual Technical Conference, 2012

slide-4
SLIDE 4

ASan code instrumentation

Original code: *addr = 42; Instrumented pseudocode: if (!is_ok_to_use(addr)) print_report_and_crash(); // memory is ok to use: *addr = 42;

slide-5
SLIDE 5

ASan shadow memory

A state of every aligned 8 bytes of memory is stored in a single shadow byte Simple shadow address calculation shadow_addr = addr / 8 + offset Allows very simple instrumentation, performed at LLVM IR level

slide-6
SLIDE 6

ASan shadow memory

  • Easy to allocate memory

for the shadow

  • Fixed address range
  • Have to do it early

Memory: 0x7fffffff 0x40000000 Shadow: 0x2fffffff 0x20000000 Memory: 0x1fffffff 0x00000000

slide-7
SLIDE 7

Function interception

Have to intercept some functions:

  • malloc, free, etc. – to track memory
  • strlen, memcpy, etc. – to detect more errors
  • pthread_create, etc. – to understand the app
slide-8
SLIDE 8

Error reporting

  • Grab the current stack trace
  • Pinpoint the (mis)accessed memory allocation
  • Get extra info from allocation metadata
  • Print out everything
  • Terminate the process
slide-9
SLIDE 9
slide-10
SLIDE 10
slide-11
SLIDE 11

ASan for Windows – overview

  • Goal: find nasty Chromium bugs on Windows
  • Started in 2012 after ASan success on Linux
  • “Beta” experience available mid-2014
slide-12
SLIDE 12

Progress overview

  • Instrumentation – no changes needed, thanks IR!
  • Significant changes to the ASan run-time library (RTL)
  • Massive effort on Clang C++ ABI support
  • clang-cl bonus: can mix MSVC & Clang .obj files,

supports automatic fallback (e.g. code with exceptions)

slide-13
SLIDE 13

C run-time support

  • Multiple C run-time (CRT) implementations:

○ /MT (static linkage) ○ /MTd (static linkage, debug) ○ /MD (DLL linkage) ○ /MDd (DLL linkage, debug)

  • Each CRT requires different handling
  • Currently supported: /MT, /MD
  • Each DLL might have its own copy of /MT CRT,

i.e. malloc, heap, CRT global state etc.

slide-14
SLIDE 14

/MT CRT support

EXE

  • Just define malloc, etc. to intercept them
  • dllimport’ed functions like CreateThread

need to be hot-patched at start-up

  • Init ASan RTL as part of the first calloc

early in CRT init

DLL

  • Redirect calls to intercepted functions from DLL

to the interceptor implementations in the EXE

slide-15
SLIDE 15

/MD CRT support

  • Also need to hot-patch MSVCR*.dll early
  • RTL is a DLL without dependencies to CRT,

gets initialized earlier

slide-16
SLIDE 16

Report symbolization and debug info

ASan requires line tables to be useful. Added COFF line table debug info support to LLVM

  • Almost-free bonus: can step line by line in debuggers

(VS, windbg)

  • Can’t look up variable values though
slide-17
SLIDE 17

Deployment

  • Can build and run Chromium
  • Deployed to ClusterFuzz,

found 50+ security bugs in 3 months

  • We’re working with Mozilla Firefox and
  • ther OSS developers
slide-18
SLIDE 18
slide-19
SLIDE 19

Please try AddressSanitizer on your Windows app p.s. tests and patches are welcome Timur Iskhodzhanov timurrrr@google.com

Thanks for listening!