SlideShare a Scribd company logo
The Silence of the Canaries
Gili Yankovitch, Nyx Software Security Solutions
Prerequisites
● A functioning brain
● A knowledge in the x86-x64 architectures
● Process loading
● Security attacks
● Operating system basics
Calling Convention
● foo() has something to tell bar()
● Presenting, our stack
● And the Assembly for the code
i = 42
RetAddr = 0x080483b6
EBP
Locals
Thread Stack
Lower Addr (0x00..)
Higher Addr (0xFF..)
Buffer Overflow
● Spot the vulnerability
argc, argv...
RetAddr
EBP
Locals
Thread Stack
Lower Addr (0x00..)
Higher Addr (0xFF..)
● What happens now?
RetAddr
EBP
Locals
“In computer security and programming, a buffer overflow, or buffer overrun, is an anomaly where a program, while writing data to a buffer,
overruns the buffer’s boundary and overwrites adjacent memory locations.”
Canaries
● A brief historical context
● Random value
○ Must be random for an attacker won’t be able to guess it.
● Stored before protected data
○ “Before” is relative to direction of overflow.
● Should be changed as much as possible
○ Heavy operation depending on the number of places the canaries are placed at.
Canaries
● gcc implements with -fstack protector
○ -fstack-protector-strong
○ -fstack-protector-all
i = 42
RetAddr = 0x080483b6
EBP
Locals
Thread Stack
Lower Addr (0x00..)
Higher Addr (0xFF..)
Canary
Canary == %gs:0x14
?
What is %gs?
● Segment register
○ Once used to partition the memory
○ Memory accesses were SEGMENT:OFFSET
○ i.e. %cs:0x0040 or %ds:0x0040 results different memory regions.
● Now used for special data storage
● %gs segment register used differently across architectures
● Canary values are stored
○ %gs:20 for 32 bit
Random
● execve() loads binary
● Transfers Auxiliary Vector to
usermode
○ binfmt_elf.c:load_elf_binary()
-> create_elf_tables()
● “Good” random numbers
ld.so init
● Every ELF process has an “interpreter”
● Its path is named in the ELF header
● ELF binary interpreter is the dynamic loader
readelf -a <elf_binary>
...
● Initializing internal members at startup
● The described ld.so is GlibC
○ Too much code complexity
○ Very widespread
Using the random
● During init phase (dl_main), calls security_init
● Initializes TLS (Thread Local Storage)
○ in x86_64 stored in %fs segment register
Offset
0
8
16
24
28
32
40
Check the canaries
● And again, validating the canaries (now x86_64)
Kernel canaries
● Compiling with CONFIG_CC_STACKPROTECTOR
○ General -> Stack Protector buffer overflow detection
○ Exists for quite some time in Linux
○ Even 2.6.32.68 in kernel.org supports it.
● When rebuilding, needs a clean build
○ Adds snippets for every function prologue and epilogue
● Adds a performance overhead
○ Sorry Linus :(
Kernel canaries
● Let’s say there’s a stack based BOF vulnerability in a system call
● Kernel compiled with CC_STACKPROTECTOR
● However, canary value stored at %gs.
● Malicious program can read value and bypass kernel protection!
Kernel canaries
● We call a system call
● From Intel x86_64 Instruction set
● %gs holds percpu kernel data structures.
○ So we have a different canary for the Kernel.
arch/x86/include/asm/stackprotector.h
● start_kernel() calls
boot_init_stack_canary()
● Canary saved on task_struct
○ Initialization of init process
kernel canary
● More important, percpu write
arch/x86/include/asm/percpu.h
● Lots of macros...
● Eventually it is something like:
○ movl %1, %%gs:%0
○ Using gcc inline assembly
Returning to canaries setup
● Let’s focus on the values we write.
64 bit
32 bit
32 Bit canary placement
● In x86 32 bit, Kernel uses %gs only for canaries. Setup GDT accordingly
● Reading stored canary from boot_init_stack_canary
● Reading GDT table
● Picking the GDT entry for stack canaries
● Writing to the specific GDT entry in its wierd encoding
● Flushing the GDT to the register
Kernel canary per process
● Not enough a single canary for kernel
● A kernel canary per user process
○ During fork() in dup_task_struct()
● Randomizes a new canary for Kernel
You get a canary, and you get a canary, and...
● We want a different kernel canary for
every process
● Need to swap the %gs segment
register in context switch
● Load per-process kernel canary
explicitly after task switch
● Kernel canary must be set explicitly
so stack unwinding will succeed after
context swapped in __switch_to()
LAZY_GS
● The top comment at
○ arch/x86/include/asm/stackprotector.h
LAZY_GS
● Returning to context switch.
○ This is __switch_to in
○ arch/x86/kernel/process_32.c
○ 64 bit isn’t lazy and saves the segment
32 bit System Call
● When we call 32 bit syscall, save all the registers
LAZY_GS Macros
● We can see that if %gs is not lazy
kernel changes the segment register
upon syscall entry.
● But when it’s lazy, it does nothing?
● Problem someone?
● If this is true, then a hostile usermode
process can overflow canaries
with no apparent problem
on x86 32 bit with
CONFIG_X86_32_LAZY_GS!
Can it be?
● Remember this comment at stackprotector.h?
● It seems to be the only place it is done, when kernel is LAZY_GS.
Look closer
● It seems the kernel holds logic not only in code:
● in arch/x86/Kconfig
● So actually we cannot have stack protection and LAZY_GS after all.
● (Well, obviously!)
“Buffer overflows are the poster child of why problems aren't getting better. They were discovered in the 1960s and were first used to attack
computers in the 1970s. The Morris worm in 1989 was a very public use of an overflow, which at the time knocked out 10 percent of the Internet--
6000 computers. Here we are 40 years later, and buffer overflows are the most common security problem. And that's an easy problem to fix. If you
are a software vendor, there is zero excuse for buffer overflows.”
-
Bruce Schneier
End to the Overflows
Questions?

More Related Content

What's hot

protothread and its usage in contiki OS
protothread and its usage in contiki OSprotothread and its usage in contiki OS
protothread and its usage in contiki OS
Salah Amean
 
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecksKernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Anne Nicolas
 
Kernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkKernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver framework
Anne Nicolas
 
Kernel Recipes 2015 - Porting Linux to a new processor architecture
Kernel Recipes 2015 - Porting Linux to a new processor architectureKernel Recipes 2015 - Porting Linux to a new processor architecture
Kernel Recipes 2015 - Porting Linux to a new processor architecture
Anne Nicolas
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
libfetion
 
Kqueue : Generic Event notification
Kqueue : Generic Event notificationKqueue : Generic Event notification
Kqueue : Generic Event notification
Mahendra M
 
Kernel Proc Connector and Containers
Kernel Proc Connector and ContainersKernel Proc Connector and Containers
Kernel Proc Connector and Containers
Kernel TLV
 
Introduction to RCU
Introduction to RCUIntroduction to RCU
Introduction to RCU
Kernel TLV
 
Concurrency bug identification through kernel panic log (english)
Concurrency bug identification through kernel panic log (english)Concurrency bug identification through kernel panic log (english)
Concurrency bug identification through kernel panic log (english)
Sneeker Yeh
 
Make Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance ToolsMake Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance Tools
Kernel TLV
 
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Kernel TLV
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
Adrien Mahieux
 
Linux Kernel Debugging
Linux Kernel DebuggingLinux Kernel Debugging
Linux Kernel Debugging
GlobalLogic Ukraine
 
The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421
Linaro
 
[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection
Moabi.com
 
Talk 160920 @ Cat System Workshop
Talk 160920 @ Cat System WorkshopTalk 160920 @ Cat System Workshop
Talk 160920 @ Cat System Workshop
Quey-Liang Kao
 
Hardware backdooring is practical : slides
Hardware backdooring is practical : slidesHardware backdooring is practical : slides
Hardware backdooring is practical : slides
Moabi.com
 
[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practical[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practical
Moabi.com
 
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Gavin Guo
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation
Jiann-Fuh Liaw
 

What's hot (20)

protothread and its usage in contiki OS
protothread and its usage in contiki OSprotothread and its usage in contiki OS
protothread and its usage in contiki OS
 
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecksKernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
 
Kernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver frameworkKernel Recipes 2015 - So you want to write a Linux driver framework
Kernel Recipes 2015 - So you want to write a Linux driver framework
 
Kernel Recipes 2015 - Porting Linux to a new processor architecture
Kernel Recipes 2015 - Porting Linux to a new processor architectureKernel Recipes 2015 - Porting Linux to a new processor architecture
Kernel Recipes 2015 - Porting Linux to a new processor architecture
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
 
Kqueue : Generic Event notification
Kqueue : Generic Event notificationKqueue : Generic Event notification
Kqueue : Generic Event notification
 
Kernel Proc Connector and Containers
Kernel Proc Connector and ContainersKernel Proc Connector and Containers
Kernel Proc Connector and Containers
 
Introduction to RCU
Introduction to RCUIntroduction to RCU
Introduction to RCU
 
Concurrency bug identification through kernel panic log (english)
Concurrency bug identification through kernel panic log (english)Concurrency bug identification through kernel panic log (english)
Concurrency bug identification through kernel panic log (english)
 
Make Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance ToolsMake Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance Tools
 
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
Linux Kernel Debugging
Linux Kernel DebuggingLinux Kernel Debugging
Linux Kernel Debugging
 
The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421The Linux Kernel Scheduler (For Beginners) - SFO17-421
The Linux Kernel Scheduler (For Beginners) - SFO17-421
 
[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection
 
Talk 160920 @ Cat System Workshop
Talk 160920 @ Cat System WorkshopTalk 160920 @ Cat System Workshop
Talk 160920 @ Cat System Workshop
 
Hardware backdooring is practical : slides
Hardware backdooring is practical : slidesHardware backdooring is practical : slides
Hardware backdooring is practical : slides
 
[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practical[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practical
 
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation
 

Similar to The Silence of the Canaries

Exploiting the Linux Kernel via Intel's SYSRET Implementation
Exploiting the Linux Kernel via Intel's SYSRET ImplementationExploiting the Linux Kernel via Intel's SYSRET Implementation
Exploiting the Linux Kernel via Intel's SYSRET Implementation
nkslides
 
LCU14 209- LLVM Linux
LCU14 209- LLVM LinuxLCU14 209- LLVM Linux
LCU14 209- LLVM Linux
Linaro
 
Memory model
Memory modelMemory model
Memory model
MingdongLiao
 
Address/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerAddress/Thread/Memory Sanitizer
Address/Thread/Memory Sanitizer
Platonov Sergey
 
Compromising Linux Virtual Machines with Debugging Mechanisms
Compromising Linux Virtual Machines with Debugging MechanismsCompromising Linux Virtual Machines with Debugging Mechanisms
Compromising Linux Virtual Machines with Debugging Mechanisms
Russell Sanford
 
Beneath the Linux Interrupt handling
Beneath the Linux Interrupt handlingBeneath the Linux Interrupt handling
Beneath the Linux Interrupt handling
Bhoomil Chavda
 
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
RootedCON
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)
shimosawa
 
LXC on Ganeti
LXC on GanetiLXC on Ganeti
LXC on Ganeti
kawamuray
 
Prerequisite knowledge for shared memory concurrency
Prerequisite knowledge for shared memory concurrencyPrerequisite knowledge for shared memory concurrency
Prerequisite knowledge for shared memory concurrency
Viller Hsiao
 
Basics_of_Kernel_Panic_Hang_and_ Kdump.pdf
Basics_of_Kernel_Panic_Hang_and_ Kdump.pdfBasics_of_Kernel_Panic_Hang_and_ Kdump.pdf
Basics_of_Kernel_Panic_Hang_and_ Kdump.pdf
stroganovboris
 
BlueHat v18 || A mitigation for kernel toctou vulnerabilities
BlueHat v18 || A mitigation for kernel toctou vulnerabilitiesBlueHat v18 || A mitigation for kernel toctou vulnerabilities
BlueHat v18 || A mitigation for kernel toctou vulnerabilities
BlueHat Security Conference
 
Java Memory Model
Java Memory ModelJava Memory Model
Java Memory Model
Łukasz Koniecki
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
Priyanka Aash
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
Priyanka Aash
 
Davide Berardi - Linux hardening and security measures against Memory corruption
Davide Berardi - Linux hardening and security measures against Memory corruptionDavide Berardi - Linux hardening and security measures against Memory corruption
Davide Berardi - Linux hardening and security measures against Memory corruption
linuxlab_conf
 
How Triton can help to reverse virtual machine based software protections
How Triton can help to reverse virtual machine based software protectionsHow Triton can help to reverse virtual machine based software protections
How Triton can help to reverse virtual machine based software protections
Jonathan Salwan
 
An Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux KernelAn Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux Kernel
SeongJae Park
 
Faster computation with matlab
Faster computation with matlabFaster computation with matlab
Faster computation with matlab
Muhammad Alli
 
VMworld 2016: vSphere 6.x Host Resource Deep Dive
VMworld 2016: vSphere 6.x Host Resource Deep DiveVMworld 2016: vSphere 6.x Host Resource Deep Dive
VMworld 2016: vSphere 6.x Host Resource Deep Dive
VMworld
 

Similar to The Silence of the Canaries (20)

Exploiting the Linux Kernel via Intel's SYSRET Implementation
Exploiting the Linux Kernel via Intel's SYSRET ImplementationExploiting the Linux Kernel via Intel's SYSRET Implementation
Exploiting the Linux Kernel via Intel's SYSRET Implementation
 
LCU14 209- LLVM Linux
LCU14 209- LLVM LinuxLCU14 209- LLVM Linux
LCU14 209- LLVM Linux
 
Memory model
Memory modelMemory model
Memory model
 
Address/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerAddress/Thread/Memory Sanitizer
Address/Thread/Memory Sanitizer
 
Compromising Linux Virtual Machines with Debugging Mechanisms
Compromising Linux Virtual Machines with Debugging MechanismsCompromising Linux Virtual Machines with Debugging Mechanisms
Compromising Linux Virtual Machines with Debugging Mechanisms
 
Beneath the Linux Interrupt handling
Beneath the Linux Interrupt handlingBeneath the Linux Interrupt handling
Beneath the Linux Interrupt handling
 
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)
 
LXC on Ganeti
LXC on GanetiLXC on Ganeti
LXC on Ganeti
 
Prerequisite knowledge for shared memory concurrency
Prerequisite knowledge for shared memory concurrencyPrerequisite knowledge for shared memory concurrency
Prerequisite knowledge for shared memory concurrency
 
Basics_of_Kernel_Panic_Hang_and_ Kdump.pdf
Basics_of_Kernel_Panic_Hang_and_ Kdump.pdfBasics_of_Kernel_Panic_Hang_and_ Kdump.pdf
Basics_of_Kernel_Panic_Hang_and_ Kdump.pdf
 
BlueHat v18 || A mitigation for kernel toctou vulnerabilities
BlueHat v18 || A mitigation for kernel toctou vulnerabilitiesBlueHat v18 || A mitigation for kernel toctou vulnerabilities
BlueHat v18 || A mitigation for kernel toctou vulnerabilities
 
Java Memory Model
Java Memory ModelJava Memory Model
Java Memory Model
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
 
Davide Berardi - Linux hardening and security measures against Memory corruption
Davide Berardi - Linux hardening and security measures against Memory corruptionDavide Berardi - Linux hardening and security measures against Memory corruption
Davide Berardi - Linux hardening and security measures against Memory corruption
 
How Triton can help to reverse virtual machine based software protections
How Triton can help to reverse virtual machine based software protectionsHow Triton can help to reverse virtual machine based software protections
How Triton can help to reverse virtual machine based software protections
 
An Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux KernelAn Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux Kernel
 
Faster computation with matlab
Faster computation with matlabFaster computation with matlab
Faster computation with matlab
 
VMworld 2016: vSphere 6.x Host Resource Deep Dive
VMworld 2016: vSphere 6.x Host Resource Deep DiveVMworld 2016: vSphere 6.x Host Resource Deep Dive
VMworld 2016: vSphere 6.x Host Resource Deep Dive
 

More from Kernel TLV

DPDK In Depth
DPDK In DepthDPDK In Depth
DPDK In Depth
Kernel TLV
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
Kernel TLV
 
SGX Trusted Execution Environment
SGX Trusted Execution EnvironmentSGX Trusted Execution Environment
SGX Trusted Execution Environment
Kernel TLV
 
Fun with FUSE
Fun with FUSEFun with FUSE
Fun with FUSE
Kernel TLV
 
Present Absence of Linux Filesystem Security
Present Absence of Linux Filesystem SecurityPresent Absence of Linux Filesystem Security
Present Absence of Linux Filesystem Security
Kernel TLV
 
OpenWrt From Top to Bottom
OpenWrt From Top to BottomOpenWrt From Top to Bottom
OpenWrt From Top to Bottom
Kernel TLV
 
File Systems: Why, How and Where
File Systems: Why, How and WhereFile Systems: Why, How and Where
File Systems: Why, How and Where
Kernel TLV
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
Kernel TLV
 
KernelTLV Speaker Guidelines
KernelTLV Speaker GuidelinesKernelTLV Speaker Guidelines
KernelTLV Speaker Guidelines
Kernel TLV
 
Userfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future DevelopmentUserfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future Development
Kernel TLV
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
Kernel TLV
 
Linux Kernel Cryptographic API and Use Cases
Linux Kernel Cryptographic API and Use CasesLinux Kernel Cryptographic API and Use Cases
Linux Kernel Cryptographic API and Use Cases
Kernel TLV
 
DMA Survival Guide
DMA Survival GuideDMA Survival Guide
DMA Survival Guide
Kernel TLV
 
FD.IO Vector Packet Processing
FD.IO Vector Packet ProcessingFD.IO Vector Packet Processing
FD.IO Vector Packet Processing
Kernel TLV
 
WiFi and the Beast
WiFi and the BeastWiFi and the Beast
WiFi and the Beast
Kernel TLV
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDK
Kernel TLV
 
Specializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network StackSpecializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network Stack
Kernel TLV
 
Linux Interrupts
Linux InterruptsLinux Interrupts
Linux Interrupts
Kernel TLV
 
Userfaultfd and Post-Copy Migration
Userfaultfd and Post-Copy MigrationUserfaultfd and Post-Copy Migration
Userfaultfd and Post-Copy Migration
Kernel TLV
 
Switchdev - No More SDK
Switchdev - No More SDKSwitchdev - No More SDK
Switchdev - No More SDK
Kernel TLV
 

More from Kernel TLV (20)

DPDK In Depth
DPDK In DepthDPDK In Depth
DPDK In Depth
 
Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
 
SGX Trusted Execution Environment
SGX Trusted Execution EnvironmentSGX Trusted Execution Environment
SGX Trusted Execution Environment
 
Fun with FUSE
Fun with FUSEFun with FUSE
Fun with FUSE
 
Present Absence of Linux Filesystem Security
Present Absence of Linux Filesystem SecurityPresent Absence of Linux Filesystem Security
Present Absence of Linux Filesystem Security
 
OpenWrt From Top to Bottom
OpenWrt From Top to BottomOpenWrt From Top to Bottom
OpenWrt From Top to Bottom
 
File Systems: Why, How and Where
File Systems: Why, How and WhereFile Systems: Why, How and Where
File Systems: Why, How and Where
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
 
KernelTLV Speaker Guidelines
KernelTLV Speaker GuidelinesKernelTLV Speaker Guidelines
KernelTLV Speaker Guidelines
 
Userfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future DevelopmentUserfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future Development
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 
Linux Kernel Cryptographic API and Use Cases
Linux Kernel Cryptographic API and Use CasesLinux Kernel Cryptographic API and Use Cases
Linux Kernel Cryptographic API and Use Cases
 
DMA Survival Guide
DMA Survival GuideDMA Survival Guide
DMA Survival Guide
 
FD.IO Vector Packet Processing
FD.IO Vector Packet ProcessingFD.IO Vector Packet Processing
FD.IO Vector Packet Processing
 
WiFi and the Beast
WiFi and the BeastWiFi and the Beast
WiFi and the Beast
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDK
 
Specializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network StackSpecializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network Stack
 
Linux Interrupts
Linux InterruptsLinux Interrupts
Linux Interrupts
 
Userfaultfd and Post-Copy Migration
Userfaultfd and Post-Copy MigrationUserfaultfd and Post-Copy Migration
Userfaultfd and Post-Copy Migration
 
Switchdev - No More SDK
Switchdev - No More SDKSwitchdev - No More SDK
Switchdev - No More SDK
 

Recently uploaded

GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 

Recently uploaded (20)

GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 

The Silence of the Canaries

  • 1. The Silence of the Canaries Gili Yankovitch, Nyx Software Security Solutions
  • 2. Prerequisites ● A functioning brain ● A knowledge in the x86-x64 architectures ● Process loading ● Security attacks ● Operating system basics
  • 3. Calling Convention ● foo() has something to tell bar() ● Presenting, our stack ● And the Assembly for the code i = 42 RetAddr = 0x080483b6 EBP Locals Thread Stack Lower Addr (0x00..) Higher Addr (0xFF..)
  • 4. Buffer Overflow ● Spot the vulnerability argc, argv... RetAddr EBP Locals Thread Stack Lower Addr (0x00..) Higher Addr (0xFF..) ● What happens now? RetAddr EBP Locals “In computer security and programming, a buffer overflow, or buffer overrun, is an anomaly where a program, while writing data to a buffer, overruns the buffer’s boundary and overwrites adjacent memory locations.”
  • 5. Canaries ● A brief historical context ● Random value ○ Must be random for an attacker won’t be able to guess it. ● Stored before protected data ○ “Before” is relative to direction of overflow. ● Should be changed as much as possible ○ Heavy operation depending on the number of places the canaries are placed at.
  • 6. Canaries ● gcc implements with -fstack protector ○ -fstack-protector-strong ○ -fstack-protector-all i = 42 RetAddr = 0x080483b6 EBP Locals Thread Stack Lower Addr (0x00..) Higher Addr (0xFF..) Canary Canary == %gs:0x14 ?
  • 7. What is %gs? ● Segment register ○ Once used to partition the memory ○ Memory accesses were SEGMENT:OFFSET ○ i.e. %cs:0x0040 or %ds:0x0040 results different memory regions. ● Now used for special data storage ● %gs segment register used differently across architectures ● Canary values are stored ○ %gs:20 for 32 bit
  • 8. Random ● execve() loads binary ● Transfers Auxiliary Vector to usermode ○ binfmt_elf.c:load_elf_binary() -> create_elf_tables() ● “Good” random numbers
  • 9. ld.so init ● Every ELF process has an “interpreter” ● Its path is named in the ELF header ● ELF binary interpreter is the dynamic loader readelf -a <elf_binary> ... ● Initializing internal members at startup ● The described ld.so is GlibC ○ Too much code complexity ○ Very widespread
  • 10. Using the random ● During init phase (dl_main), calls security_init ● Initializes TLS (Thread Local Storage) ○ in x86_64 stored in %fs segment register Offset 0 8 16 24 28 32 40
  • 11. Check the canaries ● And again, validating the canaries (now x86_64)
  • 12. Kernel canaries ● Compiling with CONFIG_CC_STACKPROTECTOR ○ General -> Stack Protector buffer overflow detection ○ Exists for quite some time in Linux ○ Even 2.6.32.68 in kernel.org supports it. ● When rebuilding, needs a clean build ○ Adds snippets for every function prologue and epilogue ● Adds a performance overhead ○ Sorry Linus :(
  • 13. Kernel canaries ● Let’s say there’s a stack based BOF vulnerability in a system call ● Kernel compiled with CC_STACKPROTECTOR ● However, canary value stored at %gs. ● Malicious program can read value and bypass kernel protection!
  • 14. Kernel canaries ● We call a system call ● From Intel x86_64 Instruction set ● %gs holds percpu kernel data structures. ○ So we have a different canary for the Kernel.
  • 15. arch/x86/include/asm/stackprotector.h ● start_kernel() calls boot_init_stack_canary() ● Canary saved on task_struct ○ Initialization of init process kernel canary ● More important, percpu write
  • 16. arch/x86/include/asm/percpu.h ● Lots of macros... ● Eventually it is something like: ○ movl %1, %%gs:%0 ○ Using gcc inline assembly
  • 17. Returning to canaries setup ● Let’s focus on the values we write. 64 bit 32 bit
  • 18. 32 Bit canary placement ● In x86 32 bit, Kernel uses %gs only for canaries. Setup GDT accordingly ● Reading stored canary from boot_init_stack_canary ● Reading GDT table ● Picking the GDT entry for stack canaries ● Writing to the specific GDT entry in its wierd encoding ● Flushing the GDT to the register
  • 19. Kernel canary per process ● Not enough a single canary for kernel ● A kernel canary per user process ○ During fork() in dup_task_struct() ● Randomizes a new canary for Kernel
  • 20. You get a canary, and you get a canary, and... ● We want a different kernel canary for every process ● Need to swap the %gs segment register in context switch ● Load per-process kernel canary explicitly after task switch ● Kernel canary must be set explicitly so stack unwinding will succeed after context swapped in __switch_to()
  • 21. LAZY_GS ● The top comment at ○ arch/x86/include/asm/stackprotector.h
  • 22. LAZY_GS ● Returning to context switch. ○ This is __switch_to in ○ arch/x86/kernel/process_32.c ○ 64 bit isn’t lazy and saves the segment
  • 23. 32 bit System Call ● When we call 32 bit syscall, save all the registers
  • 24. LAZY_GS Macros ● We can see that if %gs is not lazy kernel changes the segment register upon syscall entry. ● But when it’s lazy, it does nothing? ● Problem someone? ● If this is true, then a hostile usermode process can overflow canaries with no apparent problem on x86 32 bit with CONFIG_X86_32_LAZY_GS!
  • 25. Can it be? ● Remember this comment at stackprotector.h? ● It seems to be the only place it is done, when kernel is LAZY_GS.
  • 26. Look closer ● It seems the kernel holds logic not only in code: ● in arch/x86/Kconfig ● So actually we cannot have stack protection and LAZY_GS after all. ● (Well, obviously!)
  • 27. “Buffer overflows are the poster child of why problems aren't getting better. They were discovered in the 1960s and were first used to attack computers in the 1970s. The Morris worm in 1989 was a very public use of an overflow, which at the time knocked out 10 percent of the Internet-- 6000 computers. Here we are 40 years later, and buffer overflows are the most common security problem. And that's an easy problem to fix. If you are a software vendor, there is zero excuse for buffer overflows.” - Bruce Schneier End to the Overflows Questions?

Editor's Notes

  1. Hi, My name is Gili Yankovitch, I’m the CEO and Chief Security researcher at my company, Nyx Software Security solutions. Today we will talk about: How Stack Smashing works Why it is fun What can we do about it In Usermode In Kernelmode
  2. In order to understand the lecture you need; To know a bit about Intel architecture I will cover this anyway but it’s a plus to know about SSP (Stack Smashing, P is for Protection) Basic terms in operating systems, like: Context switch, System calls etc...
  3. Every program, anywhere, has a stack. Every thread/task/whatever has its own stack. This is the basic calling convention
  4. A classic buffer overflow from network
  5. Canaries are used in coal mines If they stopped tweeting, it means no air is comming in Means danger Random data before protected data
  6. Simulation of canary addition to assembly code.
  7. %gs is a segment register. Once it was used to partition the memory into different regions comprised of BASE + OFFSET to access any memory address It was used to separate code from data Now it is used usually for program control flow with special data saved In Windows, %fs:0x0 holds first exception handler in chain In Linux, %gs:20/40 holds the canary value of each process/kernel cpu/etc
  8. Process initialization generates random numbers at process startup Sends it to the process for usage of various things One of them is the process canary. More of less...
  9. A very brief explanation regarding the dynamic loader Snippets given here are from GlibC. I strongly discourage the use GlibC. Too complex, very (VERY!!) messy code.
  10. TLS is used even in single threaded applications. We can see here that the header described in the pthread structure fits exactly to the offset needed by gcc (%gs:40 in x86 64 bit) We can see we set the Thread Local Storage to the right, with the appropriate offset in the struct.
  11. Review of canaries in x86 64 bit, user/kernel
  12. Very easy to add to your kernel. General -> Stack Protector buffer overflow detection You should rebuild your kernel if you set this option with a precompiled kernel (make clean all)
  13. Let’s imagine a possible attack on this mechanism Let’s say an attacker reads the %gs:40 canary value. Can he now exploit a kernel stack based BOF? Kernel should protect from such things, otherwise the protection is useless.
  14. So the attacker tries to exploit the vulnerability. But it seems that the kernel holds his own %gs segment register and it swaps it the first thing on syscall entry. %gs is an interesting register, as it is a percpu register and holds the pointer to percpu data structures including the kernel stack, kernel canaries etc.
  15. So where is this canary initialized? It is initialized at kernel startup, and written percpu to remember the kernel canary. The position of this function is very critical, as from this point on, any functions that installed a different value as a canary will fault upon return.
  16. Percpu writes are comprised of tons of macros Eventually, it comes down to something like movl 0x00CANARY, %%gs:0x28
  17. We write percpu to the previously declared variables irq_stack_union or stack_canary
  18. This setup happens just for 32 bit, as we just need to remember the canary. We don’t use %gs to anything else but it.
  19. This is set and swapped in context switch, as we will see in a minute. Note that this is a KERNEL canary. usermode canaries are set by TLS from ld.so!
  20. During context switch, the kernel takes the canary stored in the task_struct and sets it in the percpu relevant to gs This is done for the usermode canaries, in order to have a different canary for every process and ensure the integrity of canaries in case someone changed it in runtime.
  21. When we use 32 bit, things are a bit more complicated. Linux try to optimize switching from kernel/user or other processes by not swapping gs.
  22. Notice the lazy gs loading, if it is 0, loading is skipped.
  23. When the kernel enters a system call, it saves all its registers on the stack Then it loads the kernel GS register
  24. Notice that when using lazily with GS, it does nothing! This is in order to accelerate performance while switching from usermode to kernelmode.
  25. Usually………….
  26. It was really weird that Linux had such a major vulnerability like this. This is a lesson for everyone that uses Linux: Do read the Kconfig files too.
  27. References: The Linux Kernel Seriously. There’s no documentation of this at all.