Introduction

Programming in a Legacy-Free Operating System



Charles Gray

cgray@cse.unsw.edu.au

Introduction
1
Disclaimer

Most of this things in this talk are:

  • Pure Speculation

  • Designed, but not implemented

  • Partially Implemented

  • Implemented, but full of bugs

Introduction :: Disclaimer
2
Reality Check

How is this different to any other system?

Introduction :: Disclaimer :: Reality Check
3
What do we want from Mungi?
  • Better Security
  • No setuid hacks

  • Easier programming model
  • fork(), select(), signal(), mmap()

  • Modular system structure
  • User-loaded/untrusted 'file systems'

  • Fine-grained access control
  • No UMGs or `chmod o+r'

  • Confinement and accounting of untrusted/bloatware applications
  • Netscape, [x]emacs, anything with GNU in it

  • Emulate legacy operating systems (UNIX)
  • So we can run Netscape, [x]emacs, anything with GNU in it

Introduction :: Wish-list
4
What Mungi gives us
  • Threads
  • Unit of execution

  • Semaphores
  • Synchronisation

  • Persistence and Distribution
  • Just because they are cool

  • PDX
  • Rights modification and secure invocation

  • Single address space
  • Shared namespace

Mechanism HOW-TO
5
Other cool Mungi features
  • Capabilities
  • Access control

  • Bank Accounts
  • Resource management

Other Features
6
Capabilities - Demand Loading
  • Accounting for everything a thread wants to access is a pain
  • May not be known until run-time

  • Capabilities could come from yourself, other users, groups, everyone
  • Mungi doesn't let an APD have that many caps!

  • Pre-loading capabilities causes performance problems
  • Mungi does O(n2) validations

  • Capabilities can be added, removed and changed at run-time.
  • We don't want to restart gv to refresh the display

  • Solution: Do it lazily!
  • It's the Mungi way

  • User-Interface advantages?

Other Features :: Capabilities - Demand Loading
7
Capabilities - Fine grained control
  • Implement a sane lpr

  • Much better support for least-privilege
  • Hacking lpr doesn't give you much

Other Features :: Capabilities - Fine grained control
8
Capabilities - Recursive Users
  • Users don't need names in capability systems

  • Applications can shed capabilities easily
  • ...or not demand load them

  • Create temporary 'sub-users'

  • Effective confinement!

Other Features :: Capabilities - Recursive Users
9
Bank Accounts (NYI)
  • Resource Confinement/Limits
  • Create a bank account with limited funds

  • Cheap Caches
  • Delete items just before you get charged for them

  • Clean Up
  • Run leaky apps in their own bank account

  • Per-'process' Accounting
  • Just plain cool

  • Fine-grained charging
  • Databases can charge by the row

Other Features :: Bank Accounts (NYI)
10
Security
  • Breaking UNIX security is easy
  • find / -perm +4000

  • Mungi is more secure... right?

Security
11
Hacking PDX (1)
Security :: Hacking PDX (1)
12
Hacking PDX (2)
Security :: Hacking PDX (2)
13
Hacking Shared Objects
Security :: Hacking Shared Objects
14
What's the Solution?
  • Don't use PDX?

  • Don't share objects?

  • Serialise pointers?

  • Work in Progress...

Security :: What's the Solution?
15
What Mungi gives us (2)

The 10 DOs and 1500 DON'Ts of Mungi programming

Mechanism HOW-TO (2)
16
Threads

DO

  • Create threads to call untrusted PDX entry points

DON'T

  • Create 'Server' threads

  • Let others create threads in your APDs

  • Give others capabilities to your stack or heap

Mechanism HOW-TO (2) :: Threads
17
Semaphores

DO

  • Use semaphores for thread safety

DON'T

  • Share semaphores outside your APD

  • Use semaphores to create blocked server threads

Mechanism HOW-TO (2) :: Semaphores
18
Persistence and Distribution

DO

  • Take advantage of persistence

  • Remember that things could run on different nodes

DON'T

  • Use strtok() on persistent data

  • Serialise data into XML

Mechanism HOW-TO (2) :: Persistence and Distribution
19
PDX

DO

  • Use PDX as much as possible

  • Use MCS when using PDX

  • Make code as event-driven as possible

  • Pass whole capabilities, not just pointers

DON'T

  • Trust pointers and caps passed to PDX services

  • Use PDX to copy large chunks of data around

  • Put MCS in the kernel

Mechanism HOW-TO (2) :: PDX
20
Single Address Space

DO

  • Give every 'thing' a name in the SAS

  • Use capabilities for protection where possible

DON'T

  • Create other address spaces

  • Build systems relying on cache timeouts

  • Try to use AS sparsity for protection

Mechanism HOW-TO (2) :: Single Address Space
21
Mungi IO
  • User-Level
  • Safer

  • Event Driven
  • Fewer threads hanging around

  • Not connection oriented

    • No need for screen

    • Persistent login sessions are easy

  • Session semantics?

Mungi IO
22
Service designs in Mungi
  • lpr

  • Plan-9 Style Naming

  • Unbounded Heap

  • Windowing System

Mungi Services
23
lpr
  • UNIX lpr is insecure

  • setuid is a broken idea

  • Mungi is naturally better

Mungi Services :: lpr
24
lpr design
Mungi Services :: lpr :: lpr design
25
Plan-9 Naming
  • Per-'process' namespaces
  • $PATH is just plain wrong

  • Encapsulate names into a directory service

  • Mutual distrust

  • Built with the Mungi Component System (MCS)

Mungi Services :: Plan-9 Naming
26
Plan-9 Naming design
Mungi Services :: Plan-9 Naming :: Design
27
Unbounded heap
  • malloc() is persistent

  • How long is a piece of string?

  • We can't safely share pointers across APDs

  • open/close/read/write involve copies
  • Also forbids the use of storing pointers

  • ObjCreate/ObjResize creates another address space
  • Storing offsets is serialisation

  • We need a meta-data service!
  • It also conveniently implements UNIX files

Mungi Services :: Unbounded heap
28
Unbounded heap design
Mungi Services :: Unbounded heap :: Design
29
Considerations
  • Transactions
  • Session semantics

  • Shrinking heaps

  • Sparse heaps
  • Another address space

  • Solve it with fault handlers?

Mungi Services :: Unbounded heap :: Considerations
30
Windowing System
  • Apps will be running on different nodes
  • Minimise sharing (including threads!)

  • Input devices could be on different nodes

  • A recursive windowing system like Plan-9 would be cool

  • Someone needs to design and build this!

Mungi Services :: Windowing System
31
UNIX on Mungi
  • UNIX has many apps we want

  • I'm not going to re-write and maintain them

  • There's nothing fundamentally wrong with the UNIX model

UNIX on Mungi
32
What is UNIX?
  • MASOS by definition
  • fork()

  • Files and Pipes

  • Signals

  • Job Control

UNIX on Mungi :: What is UNIX?
33
What is fundamentally wrong with UNIX?
  • Job Control

  • setuid

  • root

  • ioctl

  • IPC Primitives

  • 'All or Nothing' protection

UNIX on Mungi :: What is fundamentally wrong with UNIX?
34
UNIX Files in Mungi
  • Use an unbounded heap

  • What about mmap()?

  • Exact UNIX semantics?

UNIX on Mungi :: Files
35
UNIX Pipes in Mungi
UNIX on Mungi :: Pipes
36
Considerations

Advantages

  • Fits the device model
  • cat > /dev/hda

  • No useless server threads

Problems

  • Clean-up
  • Session semantics (again)

  • Requires thread synchronisation

  • Exact UNIX semantics?

UNIX on Mungi :: Pipes :: Considerations
37
fork() to exec()
  • Most programs fork() to exec()

  • Lazy programmers modify the stack and heap

  • We can't just let the caller's data get trashed... can we?
  • ucLinux hack

UNIX on Mungi :: fork()
38
Steps to fork()
  • Caller backs up stack and heap using COW

  • Caller creates callee thread and blocks

  • Callee runs until it calls exec()

  • Callee unblocks caller before jumping

  • Caller restores original stack and heap

UNIX on Mungi :: fork() :: Steps to fork()
39
Problems
  • It's a hack

  • Buggy code can still access the caller PD

  • No caller/callee communication between fork() and exec()

  • Callee is under control of the caller
  • No kernel guarantees. setuid problems?

UNIX on Mungi :: fork() :: Problems
40
fork() to fork()
  • Some programs want fork() semantics
  • apache, squid, shells

  • Often for the wrong reasons
  • Threads, select()

UNIX on Mungi :: fork() :: fork() to fork()
41
Steps to fork() (2)
  • Caller duplicates stack and heap

  • Caller creates callee with modified stack and data pointers

UNIX on Mungi :: fork() :: fork() to fork() :: Steps to fork() (2)
42
Finished
The End
Finished
43