Landlock LSM: toward unprivileged sandboxing Micka el Sala un - - PowerPoint PPT Presentation

landlock lsm toward unprivileged sandboxing
SMART_READER_LITE
LIVE PREVIEW

Landlock LSM: toward unprivileged sandboxing Micka el Sala un - - PowerPoint PPT Presentation

Landlock LSM: toward unprivileged sandboxing Micka el Sala un ANSSI September 14, 2017 1 / 21 Secure user-space software How to harden an application? secure development follow the least privilege principle compartmentalize


slide-1
SLIDE 1

Landlock LSM: toward unprivileged sandboxing

Micka¨ el Sala¨ un

ANSSI

September 14, 2017

1 / 21

slide-2
SLIDE 2

Secure user-space software

How to harden an application?

◮ secure development ◮ follow the least privilege principle ◮ compartmentalize exposed processes

2 / 21

slide-3
SLIDE 3

Secure user-space software

How to harden an application?

◮ secure development ◮ follow the least privilege principle ◮ compartmentalize exposed processes

Multiple sandbox uses

◮ built-in sandboxing (tailored security policy) ◮ sandbox managers (unprivileged and dynamic compartmentalization) ◮ container managers (hardened containers)

2 / 21

slide-4
SLIDE 4

What can provide the needed features?

Fine-grained control Embedded policy Unprivileged use

  • SELinux. . .
slide-5
SLIDE 5

What can provide the needed features?

Fine-grained control Embedded policy Unprivileged use

  • SELinux. . .
  • seccomp-bpf
  • namespaces
slide-6
SLIDE 6

What can provide the needed features?

Fine-grained control Embedded policy Unprivileged use

  • SELinux. . .
  • seccomp-bpf
  • namespaces

Landlock

  • Tailored access control to match your needs: programmatic access control

3 / 21

slide-7
SLIDE 7

What can provide the needed features?

Fine-grained control Embedded policy Unprivileged use

  • SELinux. . .
  • seccomp-bpf
  • namespaces

Landlock

  • Tailored access control to match your needs: programmatic access control

Example

Run an application allowed to write only on a terminal.

3 / 21

slide-8
SLIDE 8

Landlock overview

4 / 21

slide-9
SLIDE 9

Landlock: patch v7

◮ a minimum viable product ◮ a stackable LSM ◮ using eBPF ◮ focused on filesystem access control

5 / 21

slide-10
SLIDE 10

The Linux Security Modules framework (LSM)

LSM framework

◮ allow or deny user-space actions on kernel objects ◮ policy decision and enforcement points ◮ kernel API: support various security models ◮ 200+ hooks: inode permission, inode unlink, file ioctl. . .

6 / 21

slide-11
SLIDE 11

The Linux Security Modules framework (LSM)

LSM framework

◮ allow or deny user-space actions on kernel objects ◮ policy decision and enforcement points ◮ kernel API: support various security models ◮ 200+ hooks: inode permission, inode unlink, file ioctl. . .

Landlock

◮ rule: control an action on an object ◮ event: use of a kernel object type (e.g. file) ◮ action: read, write, execute, remove, IOCTL. . .

6 / 21

slide-12
SLIDE 12

Life cycle of a Landlock rule

7 / 21

slide-13
SLIDE 13

Landlock rule example

◮ read-only access to the filesystem... ◮ ...but allowed to write on TTY and pipes ◮ rule enforced on each filesystem access request

8 / 21

slide-14
SLIDE 14

Landlock rule example

1

SEC("landlock1")

2

int landlock_fs_rule1(struct landlock_context *ctx)

3

{

4

int mode;

5 6

/* allow non-write actions */

7

if (!(ctx->arg2 & LANDLOCK_ACTION_FS_WRITE))

8

return 0;

9

/* get the file mode */

10

mode = bpf_handle_fs_get_mode(ctx->arg1);

11

/* allow write on TTY and pipes */

12

if (S_ISCHR(mode) || S_ISFIFO(mode))

13

return 0;

14

return 1;

15

}

8 / 21

slide-15
SLIDE 15

Landlock rule example

1

SEC("landlock1")

2

int landlock_fs_rule1(struct landlock_context *ctx)

3

{

4

int mode;

5 6

/* allow non-write actions */

7

if (!(ctx->arg2 & LANDLOCK_ACTION_FS_WRITE))

8

return 0;

9

/* get the file mode */

10

mode = bpf_handle_fs_get_mode(ctx->arg1);

11

/* allow write on TTY and pipes */

12

if (S_ISCHR(mode) || S_ISFIFO(mode))

13

return 0;

14

return 1;

15

}

8 / 21

slide-16
SLIDE 16

Landlock rule example

1

SEC("landlock1")

2

int landlock_fs_rule1(struct landlock_context *ctx)

3

{

4

int mode;

5 6

/* allow non-write actions */

7

if (!(ctx->arg2 & LANDLOCK_ACTION_FS_WRITE))

8

return 0;

9

/* get the file mode */

10

mode = bpf_handle_fs_get_mode(ctx->arg1);

11

/* allow write on TTY and pipes */

12

if (S_ISCHR(mode) || S_ISFIFO(mode))

13

return 0;

14

return 1;

15

}

8 / 21

slide-17
SLIDE 17

Landlock rule example

1

SEC("landlock1")

2

int landlock_fs_rule1(struct landlock_context *ctx)

3

{

4

int mode;

5 6

/* allow non-write actions */

7

if (!(ctx->arg2 & LANDLOCK_ACTION_FS_WRITE))

8

return 0;

9

/* get the file mode */

10

mode = bpf_handle_fs_get_mode(ctx->arg1);

11

/* allow write on TTY and pipes */

12

if (S_ISCHR(mode) || S_ISFIFO(mode))

13

return 0;

14

return 1;

15

}

8 / 21

slide-18
SLIDE 18

Landlock rule example

1

SEC("landlock1")

2

int landlock_fs_rule1(struct landlock_context *ctx)

3

{

4

int mode;

5 6

/* allow non-write actions */

7

if (!(ctx->arg2 & LANDLOCK_ACTION_FS_WRITE))

8

return 0;

9

/* get the file mode */

10

mode = bpf_handle_fs_get_mode(ctx->arg1);

11

/* allow write on TTY and pipes */

12

if (S_ISCHR(mode) || S_ISFIFO(mode))

13

return 0;

14

return 1;

15

}

8 / 21

slide-19
SLIDE 19

Landlock rule example

1

SEC("landlock1")

2

int landlock_fs_rule1(struct landlock_context *ctx)

3

{

4

int mode;

5 6

/* allow non-write actions */

7

if (!(ctx->arg2 & LANDLOCK_ACTION_FS_WRITE))

8

return 0;

9

/* get the file mode */

10

mode = bpf_handle_fs_get_mode(ctx->arg1);

11

/* allow write on TTY and pipes */

12

if (S_ISCHR(mode) || S_ISFIFO(mode))

13

return 0;

14

return 1;

15

}

8 / 21

slide-20
SLIDE 20

Landlock rule example

1

SEC("landlock1")

2

int landlock_fs_rule1(struct landlock_context *ctx)

3

{

4

int mode;

5 6

/* allow non-write actions */

7

if (!(ctx->arg2 & LANDLOCK_ACTION_FS_WRITE))

8

return 0;

9

/* get the file mode */

10

mode = bpf_handle_fs_get_mode(ctx->arg1);

11

/* allow write on TTY and pipes */

12

if (S_ISCHR(mode) || S_ISFIFO(mode))

13

return 0;

14

return 1;

15

}

8 / 21

slide-21
SLIDE 21

Landlock rule example

1

SEC("landlock1")

2

int landlock_fs_rule1(struct landlock_context *ctx)

3

{

4

int mode;

5 6

/* allow non-write actions */

7

if (!(ctx->arg2 & LANDLOCK_ACTION_FS_WRITE))

8

return 0;

9

/* get the file mode */

10

mode = bpf_handle_fs_get_mode(ctx->arg1);

11

/* allow write on TTY and pipes */

12

if (S_ISCHR(mode) || S_ISFIFO(mode))

13

return 0;

14

return 1;

15

}

8 / 21

slide-22
SLIDE 22

extended Berkeley Packet Filter

In-kernel virtual machine

◮ safely execute code in the kernel at run time ◮ widely used in the kernel: network filtering, seccomp-bpf, tracing. . . ◮ can call dedicated functions ◮ can exchange data through maps between eBPF programs and

user-space

9 / 21

slide-23
SLIDE 23

extended Berkeley Packet Filter

In-kernel virtual machine

◮ safely execute code in the kernel at run time ◮ widely used in the kernel: network filtering, seccomp-bpf, tracing. . . ◮ can call dedicated functions ◮ can exchange data through maps between eBPF programs and

user-space

Static program verification at load time

◮ memory access checks ◮ register typing and tainting ◮ pointer leak restrictions ◮ execution flow restrictions

9 / 21

slide-24
SLIDE 24

Loading a rule in the kernel

1

static union bpf_prog_subtype metadata = {

2

.landlock_rule = {

3

.event = LANDLOCK_EVENT_FS,

4

.ability = LANDLOCK_ABILITY_DEBUG,

5

}

6

};

7

union bpf_attr attr = {

8

.insns = bytecode_array,

9

.prog_type = BPF_PROG_TYPE_LANDLOCK_RULE,

10

.prog_subtype = &metadata,

11

// [...]

12

};

13

int rule_fd = bpf(BPF_PROG_LOAD, &attr, sizeof(attr));

10 / 21

slide-25
SLIDE 25

Loading a rule in the kernel

1

static union bpf_prog_subtype metadata = {

2

.landlock_rule = {

3

.event = LANDLOCK_EVENT_FS,

4

.ability = LANDLOCK_ABILITY_DEBUG,

5

}

6

};

7

union bpf_attr attr = {

8

.insns = bytecode_array,

9

.prog_type = BPF_PROG_TYPE_LANDLOCK_RULE,

10

.prog_subtype = &metadata,

11

// [...]

12

};

13

int rule_fd = bpf(BPF_PROG_LOAD, &attr, sizeof(attr));

10 / 21

slide-26
SLIDE 26

Loading a rule in the kernel

1

static union bpf_prog_subtype metadata = {

2

.landlock_rule = {

3

.event = LANDLOCK_EVENT_FS,

4

.ability = LANDLOCK_ABILITY_DEBUG,

5

}

6

};

7

union bpf_attr attr = {

8

.insns = bytecode_array,

9

.prog_type = BPF_PROG_TYPE_LANDLOCK_RULE,

10

.prog_subtype = &metadata,

11

// [...]

12

};

13

int rule_fd = bpf(BPF_PROG_LOAD, &attr, sizeof(attr));

10 / 21

slide-27
SLIDE 27

Loading a rule in the kernel

1

static union bpf_prog_subtype metadata = {

2

.landlock_rule = {

3

.event = LANDLOCK_EVENT_FS,

4

.ability = LANDLOCK_ABILITY_DEBUG,

5

}

6

};

7

union bpf_attr attr = {

8

.insns = bytecode_array,

9

.prog_type = BPF_PROG_TYPE_LANDLOCK_RULE,

10

.prog_subtype = &metadata,

11

// [...]

12

};

13

int rule_fd = bpf(BPF_PROG_LOAD, &attr, sizeof(attr));

10 / 21

slide-28
SLIDE 28

Loading a rule in the kernel

1

static union bpf_prog_subtype metadata = {

2

.landlock_rule = {

3

.event = LANDLOCK_EVENT_FS,

4

.ability = LANDLOCK_ABILITY_DEBUG,

5

}

6

};

7

union bpf_attr attr = {

8

.insns = bytecode_array,

9

.prog_type = BPF_PROG_TYPE_LANDLOCK_RULE,

10

.prog_subtype = &metadata,

11

// [...]

12

};

13

int rule_fd = bpf(BPF_PROG_LOAD, &attr, sizeof(attr));

10 / 21

slide-29
SLIDE 29

Loading a rule in the kernel

1

static union bpf_prog_subtype metadata = {

2

.landlock_rule = {

3

.event = LANDLOCK_EVENT_FS,

4

.ability = LANDLOCK_ABILITY_DEBUG,

5

}

6

};

7

union bpf_attr attr = {

8

.insns = bytecode_array,

9

.prog_type = BPF_PROG_TYPE_LANDLOCK_RULE,

10

.prog_subtype = &metadata,

11

// [...]

12

};

13

int rule_fd = bpf(BPF_PROG_LOAD, &attr, sizeof(attr));

10 / 21

slide-30
SLIDE 30

Loading a rule in the kernel

10 / 21

slide-31
SLIDE 31

Applying a rule to a process

1

seccomp(SECCOMP_PREPEND_LANDLOCK_RULE, 0, &rule_fd);

11 / 21

slide-32
SLIDE 32

Applying a rule to a process

11 / 21

slide-33
SLIDE 33

Applying a rule to a process

11 / 21

slide-34
SLIDE 34

Applying a rule to a process

11 / 21

slide-35
SLIDE 35

Rule enforcement on process hierarchy

12 / 21

slide-36
SLIDE 36

Rule enforcement on process hierarchy

12 / 21

slide-37
SLIDE 37

Rule enforcement on process hierarchy

12 / 21

slide-38
SLIDE 38

Rule enforcement on process hierarchy

12 / 21

slide-39
SLIDE 39

Rule enforcement on process hierarchy

12 / 21

slide-40
SLIDE 40

Rule enforcement on process hierarchy

12 / 21

slide-41
SLIDE 41

Demonstration #1 An (almost) read-only filesystem

13 / 21

slide-42
SLIDE 42

Landlock: pending features

◮ unprivileged access control ◮ enforcement through cgroups ◮ eBPF map fsview ◮ coming next. . .

14 / 21

slide-43
SLIDE 43

Unprivileged access control

Why?

embed a security policy in any application, following the least privilege principle

15 / 21

slide-44
SLIDE 44

Unprivileged access control

Why?

embed a security policy in any application, following the least privilege principle

Challenges

◮ applying a security policy requires privileges ◮ unlike SUID, Landlock should only reduce accesses ◮ prevent accesses through other processes: ptrace restrictions ◮ protect the kernel: eBPF static analysis ◮ prevent information leak: an eBPF program shall not have more

access rights than the process which loaded it

15 / 21

slide-45
SLIDE 45

Enforcement through cgroups

Why?

user/admin security policy (e.g. container): manage groups of processes

16 / 21

slide-46
SLIDE 46

Enforcement through cgroups

Why?

user/admin security policy (e.g. container): manage groups of processes

Challenges

◮ complementary to the process hierarchy rules (via seccomp(2)) ◮ processes moving in or out of a cgroup ◮ unprivileged use with cgroups delegation (e.g. user session)

16 / 21

slide-47
SLIDE 47

eBPF map fsview

Why?

restrict access to a subset of the filesystem

17 / 21

slide-48
SLIDE 48

eBPF map fsview

Why?

restrict access to a subset of the filesystem

Challenges

◮ efficient ◮ updatable from user-space ◮ unprivileged use (i.e. no xattr)

17 / 21

slide-49
SLIDE 49

eBPF map fsview

Why?

restrict access to a subset of the filesystem

Challenges

◮ efficient ◮ updatable from user-space ◮ unprivileged use (i.e. no xattr)

Proposal

◮ new eBPF map to identify a filesystem view: mount point hierarchies

at a given time

◮ new eBPF function to compare a file access to such a view

17 / 21

slide-50
SLIDE 50

Demonstration #2 What might a filesystem access control looks like?

18 / 21

slide-51
SLIDE 51

Current roadmap

Incremental upstream integration

  • 1. minimum viable product
  • 2. cgroups handling
  • 3. new eBPF map type for filesystem-related checks
  • 4. unprivileged mode

19 / 21

slide-52
SLIDE 52

Landlock: wrap-up

User-space hardening

◮ programmatic access control ◮ designed for unprivileged use

20 / 21

slide-53
SLIDE 53

Landlock: wrap-up

User-space hardening

◮ programmatic access control ◮ designed for unprivileged use

Current status: patch v7

◮ autonomous patches merged in net, security and kselftest trees ◮ security/landlock/*: ∼1K SLOC ◮ ongoing patch series: LKML, @l0kod ◮ growing interest for containers, secure OS and service managers

20 / 21

slide-54
SLIDE 54

https://landlock.io

21 / 21

slide-55
SLIDE 55

Landlock context

1

struct landlock_context {

2

__u64 status;

3

__u64 event;

4

__u64 arg1;

5

__u64 arg2;

6

};

1 / 2

slide-56
SLIDE 56

Landlock context

1

struct landlock_context {

2

__u64 status;

3

__u64 event;

4

__u64 arg1;

5

__u64 arg2;

6

};

Landlock events

◮ LANDLOCK EVENT FS

1 / 2

slide-57
SLIDE 57

Landlock context

1

struct landlock_context {

2

__u64 status;

3

__u64 event;

4

__u64 arg1;

5

__u64 arg2;

6

};

Landlock events

◮ LANDLOCK EVENT FS

1 / 2

slide-58
SLIDE 58

Landlock context

1

struct landlock_context {

2

__u64 status;

3

__u64 event;

4

__u64 arg1;

5

__u64 arg2;

6

};

Landlock events

◮ LANDLOCK EVENT FS

Landlock actions for an FS event

◮ LANDLOCK ACTION FS EXEC ◮ LANDLOCK ACTION FS WRITE ◮ LANDLOCK ACTION FS READ ◮ LANDLOCK ACTION FS NEW ◮ LANDLOCK ACTION FS GET ◮ LANDLOCK ACTION FS REMOVE ◮ LANDLOCK ACTION FS IOCTL ◮ LANDLOCK ACTION FS LOCK ◮ LANDLOCK ACTION FS FCNTL

1 / 2

slide-59
SLIDE 59

Landlock context

1

struct landlock_context {

2

__u64 status;

3

__u64 event;

4

__u64 arg1;

5

__u64 arg2;

6

};

Landlock events

◮ LANDLOCK EVENT FS ◮ LANDLOCK EVENT FS IOCTL ◮ LANDLOCK EVENT FS LOCK ◮ LANDLOCK EVENT FS FCNTL

Landlock actions for an FS event

◮ LANDLOCK ACTION FS EXEC ◮ LANDLOCK ACTION FS WRITE ◮ LANDLOCK ACTION FS READ ◮ LANDLOCK ACTION FS NEW ◮ LANDLOCK ACTION FS GET ◮ LANDLOCK ACTION FS REMOVE ◮ LANDLOCK ACTION FS IOCTL ◮ LANDLOCK ACTION FS LOCK ◮ LANDLOCK ACTION FS FCNTL

1 / 2

slide-60
SLIDE 60

Available eBPF functions for Landlock rules

Any rule

◮ bpf handle fs get mode

2 / 2

slide-61
SLIDE 61

Available eBPF functions for Landlock rules

Any rule

◮ bpf handle fs get mode

Debug mode: need CAP SYS ADMIN

◮ bpf get current comm ◮ bpf get current pid tgid ◮ bpf get current uid gid ◮ bpf get trace printk

2 / 2