Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel...

40
Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo Quey-Liang Kao National Tsing Hua University, Taiwan

Transcript of Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel...

Page 1: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Dynamically Hacking the Kernel with Containers

ContainerCon Japan 2016Tokyo

Quey-Liang KaoNational Tsing Hua University, Taiwan

Page 2: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

About Myself● Research topics

– HPC (numerical), Heterogeneous computing– High-end hardware virtulization (InfiniBand, GPGPU)– Container technology

● Contributions– AUR packager and maintainer

● runc-git, openscap● kpatch

Page 3: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Outline● Motivation● Background● Demo: kernel detouring

– FreeBSD on Linux● Other approaches● Conclusion

Page 4: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Motivation

Page 5: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

HigherPerformance

LowerIsolation

VM

Container

http://typemoon.wikia.com/wiki/Holy_Grail

Page 6: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Quick Survey

Page 7: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Terms● OS container

– Like a VM– No layered FS– LXC, OpenVZ, BSD

Jails, Solaris zones

● App container– For single service– layered FS– Docker, Rocket

https://blog.risingstack.com/operating-system-containers-vs-application-containers/

Page 8: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

There Dimensions● System software

– OS container's perspective● Orchestration

– App container's perspective● Applications

Page 9: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Application

System Orchestration

DevOps

Security

NS, Cgroups KubernetesDocker Swarm

CoreOS

Page 10: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Application

System Orchestration

How do I OrchestrateMy Container?

By Isabel Jimenez

Page 11: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Application

System Orchestration

Containers at scalethanks to Kubernetes

By Brandon Philips

Page 12: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Application

System Orchestration

A Security State ofMind: ContainerSecurity in the

EnterpriseBy Chris Van Tuin

Page 13: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Application

System Orchestration

How the hell do Irun my containers

in production,and will it scale?By Daniël van Gils

Page 14: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Application

System Orchestration

Container Hacks &Fun Images

By Jessie Frazelle

Page 15: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Application

System Orchestration

Rootless Containerwith Runc

By Aleksa Sarai

Page 16: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Application

System Orchestration

Soft ContainerTowards 100%

Resource UtilizationBy Accela Zhao

Page 17: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Application

System Orchestration

Unprivileged Containers: What you Always Wanted

to Know About Name-spaces But Were Too

Afraid To AskBy James Bottomley

Page 18: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Application

System Orchestration

etc...

This workshould be here

Page 19: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Background

Modules,Live patches,

and Kerenl detouring

Page 20: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Kernel Module: Loading

Kernel

some_ext.ko

Kernel Space

User Space

Process:

insmod test.ko

syscall: init_module

Page 21: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Kernel Module: Using

Kernel some_ext.ko

Kernel Space

User Space

Process:

cat /dev/some_cdev

syscall: read

Page 22: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Live Patching: Building

Kernel

patch-fix.ko

Kernel Space

User Space

Process:

build fix.patch

syscall: init_module

File:fix.patch

Current kernel source

Bug()

Page 23: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Live Patching: Applying

Kernel

fix.ko

Kernel Space

User Space

Process:

insmod fix.ko

syscall: init_module

Bug()

Page 24: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Live Patching: Applying

Kernel fix.ko

Kernel Space

User Space

Bug() Bug-fixed()

ftrace

Page 25: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Kernel Detouring

Kernel detour.ko(namespace-aware)

Kernel Space

User Space

Normal Process Container

func() func()

Page 26: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Demo: Kernel Detouring

http://kirokueiga.seesaa.net/archives/201208-1.html

Page 27: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

FreeBSD binary on Linux

01000110011100100110010101100101010000100101001101000100

Page 28: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Specific Challenges ( FreeBSD )● Corresponding system calls

– Flag numbers are not portable– different calling/exiting conventions

● Unique system calls– Re-implementation

Page 29: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

General Challenges● Insufficient isolation● Limitation of development

– live patching should only be a temp. solution

Page 30: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Other Binary Compatibility Work● Wine

– Special loader for PEs/DLLs● FreeBSD, Windows 10

– Kernel built-in compatibility layer for Linux binary– System call remapping/re-implementation

Page 31: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Possible Applications● Experimental module/patch test bed● Images for other OSes● Educational purpose

– why not?

Page 32: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Other approaches● Hyper-V● Multi-Kernel● Unikernel

Page 33: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Microsoft Hyper-V● A private kernel per container

– stripped kernel reduced from Windows server● Unix-likes support

– as VMs ( in a VM-like container ) ( container-like VM )

Page 34: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Multi-Kernel● Barrelfish

– Philosophy: separation and duplication rather than keep syncing

– One kernel per core– Scalability and heterogeneity

● VirtuOS, Arrakis, Quest-V, etc.– Performance improvement

Page 35: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application
Page 36: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

UniKernel● Rump Kernel, MirageOS, OSv, etc.

– Application oriented● no more general-purpose

– “Compiler” approach

Page 37: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

http://www.penninkhof.com/2015/05/minimalist-cassandra-vm-using-osv/

Page 38: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

HigherPerformance

LowerIsolation

VM

Container

http://typemoon.wikia.com/wiki/Holy_Grail

Hyper-V

Kernel detouring( or some kernel-space ext. )

New paradigms( Multi-kernel, Unikernels )

Page 39: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Conclusion● The kernel detouring demo attempts to

indicate a possible movement of the development of OS containers– as a proof-of-concept

● Future direction– Make more fun– Make it more complete

Page 40: Dynamically Hacking the Kernel with Containers · 2017-12-14 · Dynamically Hacking the Kernel with Containers ContainerCon Japan 2016 Tokyo ... Docker Swarm CoreOS. Application

Q & A