SlideShare a Scribd company logo
1 of 30
Download to read offline
a look into the sanitizer family
by Akul Pillai
>_ whoami
● Akul Pillai (Twitter: @akulpillai)
● 2nd year CSE BTech Student @ Amrita School of
Engineering, Amritapuri
● aka k4iz3n, CTF Player @teambi0s
● Reverse Engineering and Binary Exploitation
● Organizing team @ InCTF and InCTFj
>_ Agenda
● What are Sanitizers?
○ Overview
○ Characteristics
● Address Sanitizer (ASan)
○ Usage & Working
● Undefined Behaviour Sanitizer (UBSan)
○ Usage & Working
● Sanitizers in Action (demos)
>_ What are Sanitizers?
● A family of dynamic testing tools available in Clang, GCC
and Xcode that allows you to perform runtime analysis on
your code.
● Detects bugs such as
○ buffer overflows
○ signed integer overflows
○ uninitialized memory reads
○ data races, etc
● An amazing fuzzer aid
>_ Types of Sanitizers
There are fundamentally 4 types of Sanitizers:
>_ Address Sanitizer
detects invalid address usage
bugs
>_ Undefined Behaviour Sanitizer
finds unspecified code semantic
bugs
>_ Thread Sanitizer
detects threading bugs
>_ Memory Sanitizer
finds uninitialized memory access
bugs
>_ Characteristics of Sanitizers
● Compiler Instrumented
○ The compiler adds checks inlined into the generated code
● Checks are performed dynamically during runtime
● A detailed report is created and outputted
Meaning only bugs that are encountered during execution
are reported.
>_ Agenda
● What are Sanitizers?
○ Types
○ Characteristics
● Address Sanitizer (ASan)
○ Usage & Working
● Undefined Behaviour Sanitizer (UBSan)
○ Usage & Working
● Sanitizers in Action (demos)
>_ Address Sanitizer (ASan)
● Open source tool developed by Google.
● Is a fast memory corruption bug detector
● ASan can detect:
○ Use after free (dangling pointer dereference)
○ Heap buffer overflow
○ Stack buffer overflow
○ Global buffer overflow
○ Use after return
○ Use after scope
>_ ASan - Usage
Ships with the following compilers, and can be enabled using
the following flags:
○ GCC & Clang: -fsanitize=address
○ Xcode : Runtime Sanitization > Enable Address Sanitizer
>_ ASan - Working
*address = ...; // or: ... = *address;
if (IsPoisoned(address)) {
ReportError(address, kAccessSize, kIsWrite);
}
*address = ...; // or: ... = *address;
after instrumentation:
>_ ASan - Memory Mapping
● Uses memory mapping in a way to optimize performance
● The virtual address space is divided into 2 disjoint
classes:
○ Main application memory (Mem): this memory is used by the regular
application code.
○ Shadow memory (Shadow): This memory contains the shadow values (or
metadata).
>_ ASan - Memory Mapping
0
7
6
5
4
3
2
1
-1
addressable
unaddressable/poisoned
shadow
8 bytes of main memory is
mapped to 1 byte of shadow
memory
>_ ASan - Instrumentation
shadow_address = MemToShadow(address);
if (ShadowIsPoisoned(shadow_address)) {
ReportError(address, kAccessSize, kIsWrite);
}
if (IsPoisoned(address)) {
ReportError(address, kAccessSize, kIsWrite);
}
*address = ...; // or: ... = *address;
using shadow memory:
>_ ASan - buffer overflow
>_ ASan - use after free
>_ Agenda
● What are Sanitizers?
○ Types
○ Characteristics
● Address Sanitizer (ASan)
○ Usage & Working
● Undefined Behaviour Sanitizer (UBSan)
○ Usage & Working
● Sanitizers in Action (demos)
>_ Undefined Behaviour Sanitizer (UBSan)
● Undefined Behavior describes the result of any operation
with unspecified semantics, such as
○ dividing by zero
○ loading memory from a misaligned pointer
○ dereferencing a null pointer.
● UBSan detects:
○ out-of-bounds access of arrays
○ integer overflow
○ out-of-range casts to, from, or between floating-point types and
other types.
>_ UBSan - Usage
Ships with the following compilers, and can be enabled using
the following flags:
○ GCC & Clang: -fsanitize=undefined
○ Xcode : Runtime Sanitization > Enable Undefined Behaviour
Sanitizer
>_ UBSan - integer overflow
>_ UBSan - Working
demo
>_ UBSan - Working
-fsanitize=alignment
-fsanitize=bool
-fsanitize=builtin
-fsanitize=bounds
-fsanitize=enum
-fsanitize=float-cast-overflow
-fsanitize=nullability-arg
-fsanitize=object-size
-fsanitize=pointer-overflow
-fsanitize=return
-fsanitize=shift
-fsanitize=vptr
>_ UBSan - array out of bounds
>_ UBSan - Working
demo
>_ questions?

More Related Content

What's hot

What's hot (20)

What Can Compilers Do for Us?
What Can Compilers Do for Us?What Can Compilers Do for Us?
What Can Compilers Do for Us?
 
The Internals of "Hello World" Program
The Internals of "Hello World" ProgramThe Internals of "Hello World" Program
The Internals of "Hello World" Program
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux System
 
Block I/O Layer Tracing: blktrace
Block I/O Layer Tracing: blktraceBlock I/O Layer Tracing: blktrace
Block I/O Layer Tracing: blktrace
 
Microkernel Evolution
Microkernel EvolutionMicrokernel Evolution
Microkernel Evolution
 
from Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Worksfrom Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Works
 
MCC CTF講習会 pwn編
MCC CTF講習会 pwn編MCC CTF講習会 pwn編
MCC CTF講習会 pwn編
 
GNU ld的linker script簡介
GNU ld的linker script簡介GNU ld的linker script簡介
GNU ld的linker script簡介
 
CyberChefの使い方(HamaCTF2019 WriteUp編)
CyberChefの使い方(HamaCTF2019 WriteUp編)CyberChefの使い方(HamaCTF2019 WriteUp編)
CyberChefの使い方(HamaCTF2019 WriteUp編)
 
ARM Trusted FirmwareのBL31を単体で使う!
ARM Trusted FirmwareのBL31を単体で使う!ARM Trusted FirmwareのBL31を単体で使う!
ARM Trusted FirmwareのBL31を単体で使う!
 
Velocity 2015 linux perf tools
Velocity 2015 linux perf toolsVelocity 2015 linux perf tools
Velocity 2015 linux perf tools
 
CXL_説明_公開用.pdf
CXL_説明_公開用.pdfCXL_説明_公開用.pdf
CXL_説明_公開用.pdf
 
競技プログラミングにおけるコードの書き方とその利便性
競技プログラミングにおけるコードの書き方とその利便性競技プログラミングにおけるコードの書き方とその利便性
競技プログラミングにおけるコードの書き方とその利便性
 
The Forefront of the Development for NVDIMM on Linux Kernel (Linux Plumbers c...
The Forefront of the Development for NVDIMM on Linux Kernel (Linux Plumbers c...The Forefront of the Development for NVDIMM on Linux Kernel (Linux Plumbers c...
The Forefront of the Development for NVDIMM on Linux Kernel (Linux Plumbers c...
 
Virtual Machine Constructions for Dummies
Virtual Machine Constructions for DummiesVirtual Machine Constructions for Dummies
Virtual Machine Constructions for Dummies
 
淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道 淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道
 
仮想化技術によるマルウェア対策とその問題点
仮想化技術によるマルウェア対策とその問題点仮想化技術によるマルウェア対策とその問題点
仮想化技術によるマルウェア対策とその問題点
 
Master Canary Forging by Yuki Koike - CODE BLUE 2015
Master Canary Forging by Yuki Koike - CODE BLUE 2015Master Canary Forging by Yuki Koike - CODE BLUE 2015
Master Canary Forging by Yuki Koike - CODE BLUE 2015
 
Valgrind tutorial
Valgrind tutorialValgrind tutorial
Valgrind tutorial
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machine
 

Similar to A look into the sanitizer family (ASAN & UBSAN) by Akul Pillai

Analytics tools and Instruments
Analytics tools and InstrumentsAnalytics tools and Instruments
Analytics tools and Instruments
Krunal Soni
 
Performance analysis of sobel edge filter on heterogeneous system using opencl
Performance analysis of sobel edge filter on heterogeneous system using openclPerformance analysis of sobel edge filter on heterogeneous system using opencl
Performance analysis of sobel edge filter on heterogeneous system using opencl
eSAT Publishing House
 

Similar to A look into the sanitizer family (ASAN & UBSAN) by Akul Pillai (20)

0507 057 01 98 * Adana Cukurova Klima Servisleri
0507 057 01 98 * Adana Cukurova Klima Servisleri0507 057 01 98 * Adana Cukurova Klima Servisleri
0507 057 01 98 * Adana Cukurova Klima Servisleri
 
Optimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark HarknessOptimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark Harkness
 
Manticore 6.pdf
Manticore 6.pdfManticore 6.pdf
Manticore 6.pdf
 
Analytics tools and Instruments
Analytics tools and InstrumentsAnalytics tools and Instruments
Analytics tools and Instruments
 
Microprocessors - 80386DX
Microprocessors - 80386DXMicroprocessors - 80386DX
Microprocessors - 80386DX
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
 
Introducing Parameter Sensitivity to Dynamic Code-Clone Analysis Methods
Introducing Parameter Sensitivity to Dynamic Code-Clone Analysis MethodsIntroducing Parameter Sensitivity to Dynamic Code-Clone Analysis Methods
Introducing Parameter Sensitivity to Dynamic Code-Clone Analysis Methods
 
Server-Side Development for the Cloud
Server-Side Developmentfor the CloudServer-Side Developmentfor the Cloud
Server-Side Development for the Cloud
 
Pointer
PointerPointer
Pointer
 
Computer Architecture and Organization
Computer Architecture and OrganizationComputer Architecture and Organization
Computer Architecture and Organization
 
Introduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimizationIntroduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimization
 
Writing Applications for Scylla
Writing Applications for ScyllaWriting Applications for Scylla
Writing Applications for Scylla
 
grsecurity and PaX
grsecurity and PaXgrsecurity and PaX
grsecurity and PaX
 
Introduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimizationIntroduction to Parallelization ans performance optimization
Introduction to Parallelization ans performance optimization
 
Valgrind
ValgrindValgrind
Valgrind
 
Performance analysis of sobel edge filter on heterogeneous system using opencl
Performance analysis of sobel edge filter on heterogeneous system using openclPerformance analysis of sobel edge filter on heterogeneous system using opencl
Performance analysis of sobel edge filter on heterogeneous system using opencl
 
PPT DMA.pptx
PPT  DMA.pptxPPT  DMA.pptx
PPT DMA.pptx
 
memory
memorymemory
memory
 
SOSCON 2016 JerryScript
SOSCON 2016 JerryScriptSOSCON 2016 JerryScript
SOSCON 2016 JerryScript
 
Symbolic Execution (introduction and hands-on)
Symbolic Execution (introduction and hands-on)Symbolic Execution (introduction and hands-on)
Symbolic Execution (introduction and hands-on)
 

More from Cysinfo Cyber Security Community

More from Cysinfo Cyber Security Community (20)

Understanding Malware Persistence Techniques by Monnappa K A
Understanding Malware Persistence Techniques by Monnappa K AUnderstanding Malware Persistence Techniques by Monnappa K A
Understanding Malware Persistence Techniques by Monnappa K A
 
Understanding & analyzing obfuscated malicious web scripts by Vikram Kharvi
Understanding & analyzing obfuscated malicious web scripts by Vikram KharviUnderstanding & analyzing obfuscated malicious web scripts by Vikram Kharvi
Understanding & analyzing obfuscated malicious web scripts by Vikram Kharvi
 
Getting started with cybersecurity through CTFs by Shruti Dixit & Geethna TK
Getting started with cybersecurity through CTFs by Shruti Dixit & Geethna TKGetting started with cybersecurity through CTFs by Shruti Dixit & Geethna TK
Getting started with cybersecurity through CTFs by Shruti Dixit & Geethna TK
 
Emerging Trends in Cybersecurity by Amar Prusty
Emerging Trends in Cybersecurity by Amar PrustyEmerging Trends in Cybersecurity by Amar Prusty
Emerging Trends in Cybersecurity by Amar Prusty
 
Closer look at PHP Unserialization by Ashwin Shenoi
Closer look at PHP Unserialization by Ashwin ShenoiCloser look at PHP Unserialization by Ashwin Shenoi
Closer look at PHP Unserialization by Ashwin Shenoi
 
Unicorn: The Ultimate CPU Emulator by Akshay Ajayan
Unicorn: The Ultimate CPU Emulator by Akshay AjayanUnicorn: The Ultimate CPU Emulator by Akshay Ajayan
Unicorn: The Ultimate CPU Emulator by Akshay Ajayan
 
The Art of Executing JavaScript by Akhil Mahendra
The Art of Executing JavaScript by Akhil MahendraThe Art of Executing JavaScript by Akhil Mahendra
The Art of Executing JavaScript by Akhil Mahendra
 
Reversing and Decrypting Malware Communications by Monnappa
Reversing and Decrypting Malware Communications by MonnappaReversing and Decrypting Malware Communications by Monnappa
Reversing and Decrypting Malware Communications by Monnappa
 
DeViL - Detect Virtual Machine in Linux by Sreelakshmi
DeViL - Detect Virtual Machine in Linux by SreelakshmiDeViL - Detect Virtual Machine in Linux by Sreelakshmi
DeViL - Detect Virtual Machine in Linux by Sreelakshmi
 
Analysis of android apk using adhrit by Abhishek J.M
 Analysis of android apk using adhrit by Abhishek J.M Analysis of android apk using adhrit by Abhishek J.M
Analysis of android apk using adhrit by Abhishek J.M
 
Understanding evasive hollow process injection techniques monnappa k a
Understanding evasive hollow process injection techniques   	monnappa k aUnderstanding evasive hollow process injection techniques   	monnappa k a
Understanding evasive hollow process injection techniques monnappa k a
 
Security challenges in d2d communication by ajithkumar vyasarao
Security challenges in d2d communication  by ajithkumar vyasaraoSecurity challenges in d2d communication  by ajithkumar vyasarao
Security challenges in d2d communication by ajithkumar vyasarao
 
S2 e (selective symbolic execution) -shivkrishna a
S2 e (selective symbolic execution) -shivkrishna aS2 e (selective symbolic execution) -shivkrishna a
S2 e (selective symbolic execution) -shivkrishna a
 
Dynamic binary analysis using angr siddharth muralee
Dynamic binary analysis using angr   siddharth muraleeDynamic binary analysis using angr   siddharth muralee
Dynamic binary analysis using angr siddharth muralee
 
Bit flipping attack on aes cbc - ashutosh ahelleya
Bit flipping attack on aes cbc -	ashutosh ahelleyaBit flipping attack on aes cbc -	ashutosh ahelleya
Bit flipping attack on aes cbc - ashutosh ahelleya
 
Security Analytics using ELK stack
Security Analytics using ELK stack	Security Analytics using ELK stack
Security Analytics using ELK stack
 
Linux Malware Analysis
Linux Malware Analysis	Linux Malware Analysis
Linux Malware Analysis
 
Introduction to Binary Exploitation
Introduction to Binary Exploitation	Introduction to Binary Exploitation
Introduction to Binary Exploitation
 
ATM Malware: Understanding the threat
ATM Malware: Understanding the threat	ATM Malware: Understanding the threat
ATM Malware: Understanding the threat
 
XXE - XML External Entity Attack
XXE - XML External Entity Attack	XXE - XML External Entity Attack
XXE - XML External Entity Attack
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

A look into the sanitizer family (ASAN & UBSAN) by Akul Pillai

  • 1. a look into the sanitizer family by Akul Pillai
  • 2. >_ whoami ● Akul Pillai (Twitter: @akulpillai) ● 2nd year CSE BTech Student @ Amrita School of Engineering, Amritapuri ● aka k4iz3n, CTF Player @teambi0s ● Reverse Engineering and Binary Exploitation ● Organizing team @ InCTF and InCTFj
  • 3. >_ Agenda ● What are Sanitizers? ○ Overview ○ Characteristics ● Address Sanitizer (ASan) ○ Usage & Working ● Undefined Behaviour Sanitizer (UBSan) ○ Usage & Working ● Sanitizers in Action (demos)
  • 4. >_ What are Sanitizers? ● A family of dynamic testing tools available in Clang, GCC and Xcode that allows you to perform runtime analysis on your code. ● Detects bugs such as ○ buffer overflows ○ signed integer overflows ○ uninitialized memory reads ○ data races, etc ● An amazing fuzzer aid
  • 5. >_ Types of Sanitizers There are fundamentally 4 types of Sanitizers: >_ Address Sanitizer detects invalid address usage bugs >_ Undefined Behaviour Sanitizer finds unspecified code semantic bugs >_ Thread Sanitizer detects threading bugs >_ Memory Sanitizer finds uninitialized memory access bugs
  • 6. >_ Characteristics of Sanitizers ● Compiler Instrumented ○ The compiler adds checks inlined into the generated code ● Checks are performed dynamically during runtime ● A detailed report is created and outputted Meaning only bugs that are encountered during execution are reported.
  • 7. >_ Agenda ● What are Sanitizers? ○ Types ○ Characteristics ● Address Sanitizer (ASan) ○ Usage & Working ● Undefined Behaviour Sanitizer (UBSan) ○ Usage & Working ● Sanitizers in Action (demos)
  • 8. >_ Address Sanitizer (ASan) ● Open source tool developed by Google. ● Is a fast memory corruption bug detector ● ASan can detect: ○ Use after free (dangling pointer dereference) ○ Heap buffer overflow ○ Stack buffer overflow ○ Global buffer overflow ○ Use after return ○ Use after scope
  • 9. >_ ASan - Usage Ships with the following compilers, and can be enabled using the following flags: ○ GCC & Clang: -fsanitize=address ○ Xcode : Runtime Sanitization > Enable Address Sanitizer
  • 10. >_ ASan - Working *address = ...; // or: ... = *address; if (IsPoisoned(address)) { ReportError(address, kAccessSize, kIsWrite); } *address = ...; // or: ... = *address; after instrumentation:
  • 11. >_ ASan - Memory Mapping ● Uses memory mapping in a way to optimize performance ● The virtual address space is divided into 2 disjoint classes: ○ Main application memory (Mem): this memory is used by the regular application code. ○ Shadow memory (Shadow): This memory contains the shadow values (or metadata).
  • 12. >_ ASan - Memory Mapping 0 7 6 5 4 3 2 1 -1 addressable unaddressable/poisoned shadow 8 bytes of main memory is mapped to 1 byte of shadow memory
  • 13. >_ ASan - Instrumentation shadow_address = MemToShadow(address); if (ShadowIsPoisoned(shadow_address)) { ReportError(address, kAccessSize, kIsWrite); } if (IsPoisoned(address)) { ReportError(address, kAccessSize, kIsWrite); } *address = ...; // or: ... = *address; using shadow memory:
  • 14. >_ ASan - buffer overflow
  • 15.
  • 16.
  • 17. >_ ASan - use after free
  • 18.
  • 19.
  • 20. >_ Agenda ● What are Sanitizers? ○ Types ○ Characteristics ● Address Sanitizer (ASan) ○ Usage & Working ● Undefined Behaviour Sanitizer (UBSan) ○ Usage & Working ● Sanitizers in Action (demos)
  • 21. >_ Undefined Behaviour Sanitizer (UBSan) ● Undefined Behavior describes the result of any operation with unspecified semantics, such as ○ dividing by zero ○ loading memory from a misaligned pointer ○ dereferencing a null pointer. ● UBSan detects: ○ out-of-bounds access of arrays ○ integer overflow ○ out-of-range casts to, from, or between floating-point types and other types.
  • 22. >_ UBSan - Usage Ships with the following compilers, and can be enabled using the following flags: ○ GCC & Clang: -fsanitize=undefined ○ Xcode : Runtime Sanitization > Enable Undefined Behaviour Sanitizer
  • 23. >_ UBSan - integer overflow
  • 24.
  • 25. >_ UBSan - Working demo
  • 26. >_ UBSan - Working -fsanitize=alignment -fsanitize=bool -fsanitize=builtin -fsanitize=bounds -fsanitize=enum -fsanitize=float-cast-overflow -fsanitize=nullability-arg -fsanitize=object-size -fsanitize=pointer-overflow -fsanitize=return -fsanitize=shift -fsanitize=vptr
  • 27. >_ UBSan - array out of bounds
  • 28.
  • 29. >_ UBSan - Working demo