SlideShare ist ein Scribd-Unternehmen logo
1 von 27
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?

Weitere ähnliche Inhalte

Was ist angesagt?

[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
 

Was ist angesagt? (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
 

Ähnlich wie The Silence of the Canaries

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
 

Ähnlich wie 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
 

Mehr von 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
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptables
Kernel TLV
 

Mehr von 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
 

Kürzlich hochgeladen

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Kürzlich hochgeladen (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 

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?

Hinweis der Redaktion

  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.