SlideShare una empresa de Scribd logo
1 de 30
Descargar para leer sin conexión
Fun with FUSE
Dima Krasner
SAM Seamless Network
Agenda
● Intro to FUSE
● L33t haxx0r tricks
○ The layered mount() trick
○ The *at() family
● The tricks with FUSE
What is FUSE?
fuse(8) says:
FUSE (Filesystem in Userspace) is a
simple interface for userspace
programs to export a virtual
filesystem to the Linux kernel.
FUSE also aims to provide a secure
method for non privileged users to
create and mount their own
filesystem implementations.
man fuse
Wait, what?
3 components:
● fuse.ko, a dummy file system
○ Provides /dev/fuse
● A userspace daemon, the actual file system
● libfuse, which communicates with fuse.ko through /dev/fuse
(Interesting read: doc/how-fuse-works under the FUSE source tree)
● Distros have been shipping libfuse 2.9.x for years
○ New maintainer came in 2016
○ Moved to GitHub
■ My guess: some libfuse package maintainers and users haven’t noticed this :D
● Then, came libfuse 3.0.0
○ API breakage, legacy cruft removed
○ Called “fuse3” in pkg-config, for coexistence with libfuse 2.9.x
● This talk addresses both
○ And demo code has #ifdefs for dual libfuse2/libfuse3 support
(Very) Brief History
Pros
● Access to all the goodies of userspace
○ Good example: libcurl
○ Languages other than C
○ Flexible release cycles
● FUSE is super nice to work with
○ Multi-threading of file system operations
○ Mounting
○ Daemonization
○ API compatibility levels
● Quick development
○ python-fuse
● Overhead
● Often missing in embedded systems
Cons
Common Uses
● File systems that have no proper driver (no other choice)
○ ntfs-3g
○ exFAT
● Remote file systems (network latency)
○ httpfs2
○ gvfs
● Layered file systems (disk latency)
○ unionfs-fuse
○ posixovl
● (See? Overhead is not a deal breaker)
Questions?
● Reliability
○ Kernel lockup or crash following daemon crash
○ Stale mounts
● With great complexity comes great responsibility: CVE-2014-5207
○ Linux vuln. exploited through FUSE, https://www.exploit-db.com/exploits/34923
○ Linux commit 9566d6742852c527bf5af38af5cbb878dad75705
● Something has to be privileged: CVE-2015-3202
○ Bad handling of privileges in a SUID binary, fusermount
○ Environment is user-controlled, but no clearenv() when ruid != euid in fusermount/mount
● File systems are not seen as an attack vector
The Real Cons
It’s nice and all, but
where’s the fun?
Before we go on: how do I write to /etc on this router?
The File System Hierarchy
My / is an ext4 on /dev/sda1.
It contains a directory, tmp.
A tmpfs is mounted at /tmp.
The ability to mount a file system on
top of another is a design choice.
Photo from Wikipedia (Waffle, Pilettes, CC BY-SA 3.0)
/home
/tmp
/etc
/root
/usr
/bin
/sbin
/var
The Layered
mount() Trick
mount() works, always
Read-only file system?
Incapable file system?
No problem.
Just mount something at the same
mount point and do your magic.
The *at() Family
open()
stat()
unlink()
int openat(int dirfd ← at this directory, … );
→ openat()
→ statat()
→ unlinkat()
● Convenience
○ No need to sprintf(“/a/b/%s”, ...) like crazy
● A *at() call operates on a specific file system
○ Hardening against another mount() on top
○ Limiting paths a process can access (e.g. AppArmor) isn’t enough
○ Say, httpd reads /etc/resolv.conf
■ I can mount something at /etc and alter resolv.conf, unless httpd uses openat()
● Finicky userspace support
○ The *at() syscalls appeared individually
○ libc doesn’t expose everything
Benefits and Annoyances
Magic!
strace says:
After the umount2(), the file system is hidden.
1. We mount a tmpfs at .
2. echo -n abcd > lol
3. echo -n efgh > rofl
4. We get a file descriptor under the tmpfs (.
counts too!)
5. We lazily unmount the tmpfs
6. (The tmpfs disappears from mounts)
7. We can read files with openat()!
Questions?
Security: A Double-Edged Sword
● *at() calls can be used to protect against mount()
● But, *at() calls can be used to hide file systems
● Semi-legit use cases: packers and self-extractors
Let’s combine
everything:
● FUSE
● mount()
● *at()
Showcase
● Full control of a directory can be achieved in real-time from userspace using:
○ mount()
○ *at()
○ FUSE
● First, we’ll take a look at overheadfs, which is useless
● Then, we’ll look at logfence, which does something good with this technique
overheadfs
● Run overheadfs /tmp
● Nothing special happens
overheadfs delegates all file system
operations to the file system
mounted below it.
A proxy file system
github.com/dimkr/overheadfs
400File system god mode from userspace, in 400 lines of C code
How overheadfs Works
● fd = open(path, O_DIRECTORY)
● libfuse does its magic and mounts overheadfs
● fd allows access to the underlying file system through *at()
Instead of acting as a transparent proxy, we can use this for fun (evil?) stuff!
logfence
● Run logfence /var/log
● Start nginx
○ nginx open()s a log file for writing
● No other process can open the
same file for writing
An attacker that used a nginx
vulnerability cannot modify logs to
hide traces.
Prevents tampering with logs
github.com/dimkr/logfence
How logfence Works
● Same concept
● Manages a list of locked files
● Using flock() is probably a better idea
Questions?
More Ideas
● A file system where syscalls fail randomly, for tests
● A file system that verifies signatures of files: elfence
● A file system that uses memfd_create() as cache
○ In-memory SQLite databases that get flushed to disk every once in a while
○ Transparent AT_STATX_DONT_SYNC for all stat()
● A file system that provides an alternative to inotify
○ Embedded devices with INOTIFY_USER=n
● Everything is a file, right?
○ How does mount know what’s currently mounted?
○ How does ps know what processes are running?
○ You know the drill
● Delegation of kernel work to userspace has its costs
○ Give the user a finger and a haxx0r will grab you by the neck by exploiting through libfuse
● Complexity is the devil
○ mount() and affected stuff don’t have one linear flow because of all the flags
● The devil is in the detail
○ fusermount: something has to call mount() after all, hence SUID root
● “Everything is a file” is nice, but …
○ It’s a lie - e.g. Netlink sockets
○ (Just a symptom: the Unix philosophy is long dead too, e.g. systemd)
○ Files can be created by userspace, unlike a special Netlink family/group
○ Security-wise, file access isn’t everything
Conclusions
Thanks for
listening!
I’m Dima Krasner, senior
developer @SAM
● Trumpet player
● Aspiring philosopher
● Free software developer
● Low-level R&D (ex. Hexadite)
Feel free to reach out!
● dimakrasner.com
● github.com/dimkr
● dima@dimakrasner.com
● securingsam.com
● CV→dima@securingsam.com

Más contenido relacionado

La actualidad más candente

Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDPlcplcp1
 
Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01Hajime Tazaki
 
Storage based on_openstack_mariocho
Storage based on_openstack_mariochoStorage based on_openstack_mariocho
Storage based on_openstack_mariochoMario Cho
 
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 StorageKernel TLV
 
Linux Containers From Scratch
Linux Containers From ScratchLinux Containers From Scratch
Linux Containers From Scratchjoshuasoundcloud
 
Namespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containersNamespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containersKernel TLV
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing LandscapeKernel TLV
 
Linux Containers From Scratch: Makfile MicroVPS
Linux Containers From Scratch: Makfile MicroVPSLinux Containers From Scratch: Makfile MicroVPS
Linux Containers From Scratch: Makfile MicroVPSjoshuasoundcloud
 
Virtualization which isn't: LXC (Linux Containers)
Virtualization which isn't: LXC (Linux Containers)Virtualization which isn't: LXC (Linux Containers)
Virtualization which isn't: LXC (Linux Containers)Dobrica Pavlinušić
 
Inside Docker for Fedora20/RHEL7
Inside Docker for Fedora20/RHEL7Inside Docker for Fedora20/RHEL7
Inside Docker for Fedora20/RHEL7Etsuji Nakai
 
Talk 160920 @ Cat System Workshop
Talk 160920 @ Cat System WorkshopTalk 160920 @ Cat System Workshop
Talk 160920 @ Cat System WorkshopQuey-Liang Kao
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Jian-Hong Pan
 
Realizing Linux Containers (LXC)
Realizing Linux Containers (LXC)Realizing Linux Containers (LXC)
Realizing Linux Containers (LXC)Boden Russell
 
GlusterFS Update and OpenStack Integration
GlusterFS Update and OpenStack IntegrationGlusterFS Update and OpenStack Integration
GlusterFS Update and OpenStack IntegrationEtsuji Nakai
 
Windows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel DevelopersWindows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel DevelopersKernel TLV
 
Kqueue : Generic Event notification
Kqueue : Generic Event notificationKqueue : Generic Event notification
Kqueue : Generic Event notificationMahendra M
 

La actualidad más candente (20)

Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDP
 
Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01
 
Storage based on_openstack_mariocho
Storage based on_openstack_mariochoStorage based on_openstack_mariocho
Storage based on_openstack_mariocho
 
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 Containers From Scratch
Linux Containers From ScratchLinux Containers From Scratch
Linux Containers From Scratch
 
Namespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containersNamespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containers
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing Landscape
 
Linux Containers From Scratch: Makfile MicroVPS
Linux Containers From Scratch: Makfile MicroVPSLinux Containers From Scratch: Makfile MicroVPS
Linux Containers From Scratch: Makfile MicroVPS
 
Virtualization which isn't: LXC (Linux Containers)
Virtualization which isn't: LXC (Linux Containers)Virtualization which isn't: LXC (Linux Containers)
Virtualization which isn't: LXC (Linux Containers)
 
Linux IO
Linux IOLinux IO
Linux IO
 
Inside Docker for Fedora20/RHEL7
Inside Docker for Fedora20/RHEL7Inside Docker for Fedora20/RHEL7
Inside Docker for Fedora20/RHEL7
 
Talk 160920 @ Cat System Workshop
Talk 160920 @ Cat System WorkshopTalk 160920 @ Cat System Workshop
Talk 160920 @ Cat System Workshop
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
 
Realizing Linux Containers (LXC)
Realizing Linux Containers (LXC)Realizing Linux Containers (LXC)
Realizing Linux Containers (LXC)
 
GlusterFS Update and OpenStack Integration
GlusterFS Update and OpenStack IntegrationGlusterFS Update and OpenStack Integration
GlusterFS Update and OpenStack Integration
 
LSA2 - 02 Namespaces
LSA2 - 02  NamespacesLSA2 - 02  Namespaces
LSA2 - 02 Namespaces
 
Windows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel DevelopersWindows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel Developers
 
Kqueue : Generic Event notification
Kqueue : Generic Event notificationKqueue : Generic Event notification
Kqueue : Generic Event notification
 
Namespaces in Linux
Namespaces in LinuxNamespaces in Linux
Namespaces in Linux
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 

Similar a Fun with FUSE

Lightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFSLightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFSJérôme Petazzoni
 
Linux 开源操作系统发展新趋势
Linux 开源操作系统发展新趋势Linux 开源操作系统发展新趋势
Linux 开源操作系统发展新趋势Anthony Wong
 
the NML project
the NML projectthe NML project
the NML projectLei Yang
 
Unix fundamentals
Unix fundamentalsUnix fundamentals
Unix fundamentalsBimal Jain
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactAlessandro Selli
 
Grub and dracut ii
Grub and dracut iiGrub and dracut ii
Grub and dracut iiplarsen67
 
Linux Operating System
Linux Operating SystemLinux Operating System
Linux Operating SystemKunalKewat1
 
Poking The Filesystem For Fun And Profit
Poking The Filesystem For Fun And ProfitPoking The Filesystem For Fun And Profit
Poking The Filesystem For Fun And Profitssusera432ea1
 
Linux or unix interview questions
Linux or unix interview questionsLinux or unix interview questions
Linux or unix interview questionsTeja Bheemanapally
 
LXC Containers and AUFs
LXC Containers and AUFsLXC Containers and AUFs
LXC Containers and AUFsDocker, Inc.
 
TLPI Chapter 14 File Systems
TLPI Chapter 14 File SystemsTLPI Chapter 14 File Systems
TLPI Chapter 14 File SystemsShu-Yu Fu
 
Unix Security
Unix SecurityUnix Security
Unix Securityreplay21
 

Similar a Fun with FUSE (20)

Lightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFSLightweight Virtualization: LXC containers & AUFS
Lightweight Virtualization: LXC containers & AUFS
 
Linux 开源操作系统发展新趋势
Linux 开源操作系统发展新趋势Linux 开源操作系统发展新趋势
Linux 开源操作系统发展新趋势
 
the NML project
the NML projectthe NML project
the NML project
 
.ppt
.ppt.ppt
.ppt
 
Unix fundamentals
Unix fundamentalsUnix fundamentals
Unix fundamentals
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compact
 
Grub and dracut ii
Grub and dracut iiGrub and dracut ii
Grub and dracut ii
 
Linux security
Linux securityLinux security
Linux security
 
Linux Operating System
Linux Operating SystemLinux Operating System
Linux Operating System
 
Linux introduction (eng)
Linux introduction (eng)Linux introduction (eng)
Linux introduction (eng)
 
Poking The Filesystem For Fun And Profit
Poking The Filesystem For Fun And ProfitPoking The Filesystem For Fun And Profit
Poking The Filesystem For Fun And Profit
 
An Introduction To Linux
An Introduction To LinuxAn Introduction To Linux
An Introduction To Linux
 
Linux
LinuxLinux
Linux
 
Linux or unix interview questions
Linux or unix interview questionsLinux or unix interview questions
Linux or unix interview questions
 
LXC Containers and AUFs
LXC Containers and AUFsLXC Containers and AUFs
LXC Containers and AUFs
 
Ch12 system administration
Ch12 system administration Ch12 system administration
Ch12 system administration
 
FreeBSD Portscamp, Kuala Lumpur 2016
FreeBSD Portscamp, Kuala Lumpur 2016FreeBSD Portscamp, Kuala Lumpur 2016
FreeBSD Portscamp, Kuala Lumpur 2016
 
TLPI Chapter 14 File Systems
TLPI Chapter 14 File SystemsTLPI Chapter 14 File Systems
TLPI Chapter 14 File Systems
 
Unix Security
Unix SecurityUnix Security
Unix Security
 
Deft v7
Deft v7Deft v7
Deft v7
 

Más de Kernel TLV

SGX Trusted Execution Environment
SGX Trusted Execution EnvironmentSGX Trusted Execution Environment
SGX Trusted Execution EnvironmentKernel TLV
 
Kernel Proc Connector and Containers
Kernel Proc Connector and ContainersKernel Proc Connector and Containers
Kernel Proc Connector and ContainersKernel TLV
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Kernel TLV
 
Present Absence of Linux Filesystem Security
Present Absence of Linux Filesystem SecurityPresent Absence of Linux Filesystem Security
Present Absence of Linux Filesystem SecurityKernel TLV
 
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 ToolsKernel TLV
 
File Systems: Why, How and Where
File Systems: Why, How and WhereFile Systems: Why, How and Where
File Systems: Why, How and WhereKernel TLV
 
netfilter and iptables
netfilter and iptablesnetfilter and iptables
netfilter and iptablesKernel TLV
 
KernelTLV Speaker Guidelines
KernelTLV Speaker GuidelinesKernelTLV Speaker Guidelines
KernelTLV Speaker GuidelinesKernel 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 DevelopmentKernel 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 CasesKernel TLV
 
DMA Survival Guide
DMA Survival GuideDMA Survival Guide
DMA Survival GuideKernel TLV
 
FD.IO Vector Packet Processing
FD.IO Vector Packet ProcessingFD.IO Vector Packet Processing
FD.IO Vector Packet ProcessingKernel TLV
 
WiFi and the Beast
WiFi and the BeastWiFi and the Beast
WiFi and the BeastKernel TLV
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDKKernel 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 StackKernel TLV
 
Linux Interrupts
Linux InterruptsLinux Interrupts
Linux InterruptsKernel TLV
 
Userfaultfd and Post-Copy Migration
Userfaultfd and Post-Copy MigrationUserfaultfd and Post-Copy Migration
Userfaultfd and Post-Copy MigrationKernel TLV
 
VLANs in the Linux Kernel
VLANs in the Linux KernelVLANs in the Linux Kernel
VLANs in the Linux KernelKernel TLV
 
Switchdev - No More SDK
Switchdev - No More SDKSwitchdev - No More SDK
Switchdev - No More SDKKernel TLV
 

Más de Kernel TLV (20)

DPDK In Depth
DPDK In DepthDPDK In Depth
DPDK In Depth
 
SGX Trusted Execution Environment
SGX Trusted Execution EnvironmentSGX Trusted Execution Environment
SGX Trusted Execution Environment
 
Kernel Proc Connector and Containers
Kernel Proc Connector and ContainersKernel Proc Connector and Containers
Kernel Proc Connector and Containers
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545
 
Present Absence of Linux Filesystem Security
Present Absence of Linux Filesystem SecurityPresent Absence of Linux Filesystem Security
Present Absence of Linux Filesystem Security
 
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
 
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
 
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
 
VLANs in the Linux Kernel
VLANs in the Linux KernelVLANs in the Linux Kernel
VLANs in the Linux Kernel
 
Switchdev - No More SDK
Switchdev - No More SDKSwitchdev - No More SDK
Switchdev - No More SDK
 

Último

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%+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
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
%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 midrandmasabamasaba
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...masabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
%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 tembisamasabamasaba
 
+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
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 

Último (20)

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+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...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%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
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%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
 
+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...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 

Fun with FUSE

  • 1. Fun with FUSE Dima Krasner SAM Seamless Network
  • 2. Agenda ● Intro to FUSE ● L33t haxx0r tricks ○ The layered mount() trick ○ The *at() family ● The tricks with FUSE
  • 3. What is FUSE? fuse(8) says: FUSE (Filesystem in Userspace) is a simple interface for userspace programs to export a virtual filesystem to the Linux kernel. FUSE also aims to provide a secure method for non privileged users to create and mount their own filesystem implementations. man fuse
  • 4. Wait, what? 3 components: ● fuse.ko, a dummy file system ○ Provides /dev/fuse ● A userspace daemon, the actual file system ● libfuse, which communicates with fuse.ko through /dev/fuse (Interesting read: doc/how-fuse-works under the FUSE source tree)
  • 5. ● Distros have been shipping libfuse 2.9.x for years ○ New maintainer came in 2016 ○ Moved to GitHub ■ My guess: some libfuse package maintainers and users haven’t noticed this :D ● Then, came libfuse 3.0.0 ○ API breakage, legacy cruft removed ○ Called “fuse3” in pkg-config, for coexistence with libfuse 2.9.x ● This talk addresses both ○ And demo code has #ifdefs for dual libfuse2/libfuse3 support (Very) Brief History
  • 6. Pros ● Access to all the goodies of userspace ○ Good example: libcurl ○ Languages other than C ○ Flexible release cycles ● FUSE is super nice to work with ○ Multi-threading of file system operations ○ Mounting ○ Daemonization ○ API compatibility levels ● Quick development ○ python-fuse
  • 7. ● Overhead ● Often missing in embedded systems Cons
  • 8. Common Uses ● File systems that have no proper driver (no other choice) ○ ntfs-3g ○ exFAT ● Remote file systems (network latency) ○ httpfs2 ○ gvfs ● Layered file systems (disk latency) ○ unionfs-fuse ○ posixovl ● (See? Overhead is not a deal breaker)
  • 10. ● Reliability ○ Kernel lockup or crash following daemon crash ○ Stale mounts ● With great complexity comes great responsibility: CVE-2014-5207 ○ Linux vuln. exploited through FUSE, https://www.exploit-db.com/exploits/34923 ○ Linux commit 9566d6742852c527bf5af38af5cbb878dad75705 ● Something has to be privileged: CVE-2015-3202 ○ Bad handling of privileges in a SUID binary, fusermount ○ Environment is user-controlled, but no clearenv() when ruid != euid in fusermount/mount ● File systems are not seen as an attack vector The Real Cons
  • 11. It’s nice and all, but where’s the fun?
  • 12. Before we go on: how do I write to /etc on this router?
  • 13. The File System Hierarchy My / is an ext4 on /dev/sda1. It contains a directory, tmp. A tmpfs is mounted at /tmp. The ability to mount a file system on top of another is a design choice. Photo from Wikipedia (Waffle, Pilettes, CC BY-SA 3.0) /home /tmp /etc /root /usr /bin /sbin /var
  • 14. The Layered mount() Trick mount() works, always Read-only file system? Incapable file system? No problem. Just mount something at the same mount point and do your magic.
  • 15. The *at() Family open() stat() unlink() int openat(int dirfd ← at this directory, … ); → openat() → statat() → unlinkat()
  • 16. ● Convenience ○ No need to sprintf(“/a/b/%s”, ...) like crazy ● A *at() call operates on a specific file system ○ Hardening against another mount() on top ○ Limiting paths a process can access (e.g. AppArmor) isn’t enough ○ Say, httpd reads /etc/resolv.conf ■ I can mount something at /etc and alter resolv.conf, unless httpd uses openat() ● Finicky userspace support ○ The *at() syscalls appeared individually ○ libc doesn’t expose everything Benefits and Annoyances
  • 17. Magic! strace says: After the umount2(), the file system is hidden. 1. We mount a tmpfs at . 2. echo -n abcd > lol 3. echo -n efgh > rofl 4. We get a file descriptor under the tmpfs (. counts too!) 5. We lazily unmount the tmpfs 6. (The tmpfs disappears from mounts) 7. We can read files with openat()!
  • 19. Security: A Double-Edged Sword ● *at() calls can be used to protect against mount() ● But, *at() calls can be used to hide file systems ● Semi-legit use cases: packers and self-extractors
  • 21. Showcase ● Full control of a directory can be achieved in real-time from userspace using: ○ mount() ○ *at() ○ FUSE ● First, we’ll take a look at overheadfs, which is useless ● Then, we’ll look at logfence, which does something good with this technique
  • 22. overheadfs ● Run overheadfs /tmp ● Nothing special happens overheadfs delegates all file system operations to the file system mounted below it. A proxy file system github.com/dimkr/overheadfs
  • 23. 400File system god mode from userspace, in 400 lines of C code
  • 24. How overheadfs Works ● fd = open(path, O_DIRECTORY) ● libfuse does its magic and mounts overheadfs ● fd allows access to the underlying file system through *at() Instead of acting as a transparent proxy, we can use this for fun (evil?) stuff!
  • 25. logfence ● Run logfence /var/log ● Start nginx ○ nginx open()s a log file for writing ● No other process can open the same file for writing An attacker that used a nginx vulnerability cannot modify logs to hide traces. Prevents tampering with logs github.com/dimkr/logfence
  • 26. How logfence Works ● Same concept ● Manages a list of locked files ● Using flock() is probably a better idea
  • 28. More Ideas ● A file system where syscalls fail randomly, for tests ● A file system that verifies signatures of files: elfence ● A file system that uses memfd_create() as cache ○ In-memory SQLite databases that get flushed to disk every once in a while ○ Transparent AT_STATX_DONT_SYNC for all stat() ● A file system that provides an alternative to inotify ○ Embedded devices with INOTIFY_USER=n ● Everything is a file, right? ○ How does mount know what’s currently mounted? ○ How does ps know what processes are running? ○ You know the drill
  • 29. ● Delegation of kernel work to userspace has its costs ○ Give the user a finger and a haxx0r will grab you by the neck by exploiting through libfuse ● Complexity is the devil ○ mount() and affected stuff don’t have one linear flow because of all the flags ● The devil is in the detail ○ fusermount: something has to call mount() after all, hence SUID root ● “Everything is a file” is nice, but … ○ It’s a lie - e.g. Netlink sockets ○ (Just a symptom: the Unix philosophy is long dead too, e.g. systemd) ○ Files can be created by userspace, unlike a special Netlink family/group ○ Security-wise, file access isn’t everything Conclusions
  • 30. Thanks for listening! I’m Dima Krasner, senior developer @SAM ● Trumpet player ● Aspiring philosopher ● Free software developer ● Low-level R&D (ex. Hexadite) Feel free to reach out! ● dimakrasner.com ● github.com/dimkr ● dima@dimakrasner.com ● securingsam.com ● CV→dima@securingsam.com