landlock: a new kind of linux security module leveraging ebpf · 9/12/2019  · extended berkeley...

78
Landlock: a new kind of Linux Security Module leveraging eBPF Micka¨ el Sala¨ un ANSSI September 12, 2019 1 / 32

Upload: others

Post on 22-Jul-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock: a new kind of Linux Security Moduleleveraging eBPF

Mickael Salaun

ANSSI

September 12, 2019

1 / 32

Page 2: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Protect users from your application

Threat1. bug exploitation of your code

2. bug or backdoor in a third party component

⇒ your application is used against your will

DefensesI follow secure development practices

I use an hardened toolchain

I use OS security features (e.g. sandboxes)

The Landlock features (current)

I helps define and embed security policy in your code

I enforces an access control on your application

2 / 32

Page 3: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Protect users from your application

Threat1. bug exploitation of your code

2. bug or backdoor in a third party component

⇒ your application is used against your will

DefensesI follow secure development practices

I use an hardened toolchain

I use OS security features (e.g. sandboxes)

The Landlock features (current)

I helps define and embed security policy in your code

I enforces an access control on your application

2 / 32

Page 4: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Protect users from your application

Threat1. bug exploitation of your code

2. bug or backdoor in a third party component

⇒ your application is used against your will

DefensesI follow secure development practices

I use an hardened toolchain

I use OS security features (e.g. sandboxes)

The Landlock features (current)

I helps define and embed security policy in your code

I enforces an access control on your application

2 / 32

Page 5: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Demonstration #1 [PATCH v8]

Read-only accesses...

I /publicI /etcI /usrI . . .

...and read-write accessesI /tmpI . . .

3 / 32

Page 6: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

What about the other Linux security features?

Fine-grained control Embedded policy Unprivileged use

SELinux. . . X

seccomp-bpf X X

namespaces X ∼

Landlock X X X1

Tailored access control to match your needs: programmatic access control

1Disabled on purpose for the initial upstream inclusion, but planned to be enabledafter a test period (and subject to upstream point of view).

4 / 32

Page 7: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

What about the other Linux security features?

Fine-grained control Embedded policy Unprivileged use

SELinux. . . X

seccomp-bpf X X

namespaces X ∼

Landlock X X X1

Tailored access control to match your needs: programmatic access control

1Disabled on purpose for the initial upstream inclusion, but planned to be enabledafter a test period (and subject to upstream point of view).

4 / 32

Page 8: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

What about the other Linux security features?

Fine-grained control Embedded policy Unprivileged use

SELinux. . . X

seccomp-bpf X X

namespaces X ∼

Landlock X X X1

Tailored access control to match your needs: programmatic access control

1Disabled on purpose for the initial upstream inclusion, but planned to be enabledafter a test period (and subject to upstream point of view).

4 / 32

Page 9: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock overview

5 / 32

Page 10: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

extended Berkeley Packet Filter

In-kernel virtual machineI safely execute code in the kernel at run time

I widely used in the kernel: network filtering (XDP), seccomp-bpf,tracing. . .

I can call dedicated functions

I can exchange data through maps between eBPF programs anduser-space

Static program verification at load time

I memory access checks

I register typing and tainting

I pointer leak restrictions

I execution flow restrictions

6 / 32

Page 11: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

extended Berkeley Packet Filter

In-kernel virtual machineI safely execute code in the kernel at run time

I widely used in the kernel: network filtering (XDP), seccomp-bpf,tracing. . .

I can call dedicated functions

I can exchange data through maps between eBPF programs anduser-space

Static program verification at load time

I memory access checks

I register typing and tainting

I pointer leak restrictions

I execution flow restrictions

6 / 32

Page 12: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

The Linux Security Modules framework (LSM)

LSM frameworkI allow or deny user-space actions on kernel objects

I policy decision and enforcement points

I kernel API: support various security models

I 200+ hooks: inode permission, inode unlink, file ioctl. . .

LandlockI hook: set of actions on a specific kernel object (e.g. walk a file path,

change memory protection)

I program: access-control checks stacked on a hook

I triggers: actions mask for which a program is run (e.g. read, write,execute, remove, IOCTL. . . )

7 / 32

Page 13: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

The Linux Security Modules framework (LSM)

LSM frameworkI allow or deny user-space actions on kernel objects

I policy decision and enforcement points

I kernel API: support various security models

I 200+ hooks: inode permission, inode unlink, file ioctl. . .

LandlockI hook: set of actions on a specific kernel object (e.g. walk a file path,

change memory protection)

I program: access-control checks stacked on a hook

I triggers: actions mask for which a program is run (e.g. read, write,execute, remove, IOCTL. . . )

7 / 32

Page 14: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

History of Landlock

Overview of the major patch series

I [PATCH v1] (Mar. 2016): seccomp-object

I [PATCH v2] (Aug. 2016): LSM + cgroups

I [PATCH v8] (Feb. 2018): file path identification

I [PATCH v10] (Jul. 2019): shrink patches (current version)

8 / 32

Page 15: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Safely handle malicious policies

I Landlock should be usable by everyone

I we can’t tell if a process will be malicious

⇒ trust issue

9 / 32

Page 16: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Unprivileged access control

Sought properties

I multiple applications, need independant but composable securitypolicies

I tamper proof: prevent bypass through other processes (i.e. via ptrace)

HarmlessnessI safe approach: follow the least privilege principle (i.e. no SUID)

I limit the kernel attack surface:I minimal kernel code (security/landlock/*: ∼1080 SLOC)I eBPF static analysisI move complexity from the kernel to eBPF programs

10 / 32

Page 17: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Unprivileged access control

Sought properties

I multiple applications, need independant but composable securitypolicies

I tamper proof: prevent bypass through other processes (i.e. via ptrace)

HarmlessnessI safe approach: follow the least privilege principle (i.e. no SUID)

I limit the kernel attack surface:I minimal kernel code (security/landlock/*: ∼1080 SLOC)I eBPF static analysisI move complexity from the kernel to eBPF programs

10 / 32

Page 18: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Unprivileged access control

Protect access to process ressources

I the rule creator must be allowed to ptrace the sandboxed process

Protect access to kernel ressourcesI prevent information leak: an eBPF program shall not have more

access rights than the process which loaded it

I still, access control need some knowledge to take decision (e.g. filepath check)

I only interpreted on viewable objects and after other access controls

11 / 32

Page 19: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Unprivileged access control

Protect access to process ressources

I the rule creator must be allowed to ptrace the sandboxed process

Protect access to kernel ressourcesI prevent information leak: an eBPF program shall not have more

access rights than the process which loaded it

I still, access control need some knowledge to take decision (e.g. filepath check)

I only interpreted on viewable objects and after other access controls

11 / 32

Page 20: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Identifying a file path

I path evaluation based on walking through inodes

I multiple Landlock program types

12 / 32

Page 21: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

eBPF inode map

Goalrestrict access to a subset of the filesystem

Challenges

I efficient

I updatable from user-space

I unprivileged use:I no xattrI no absolute path

SolutionI new eBPF map type to identify an inode object

I use inode as key and associate it with an arbitrary value

13 / 32

Page 22: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

eBPF inode map

Goalrestrict access to a subset of the filesystem

Challenges

I efficient

I updatable from user-space

I unprivileged use:I no xattrI no absolute path

SolutionI new eBPF map type to identify an inode object

I use inode as key and associate it with an arbitrary value

13 / 32

Page 23: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

eBPF inode map

Goalrestrict access to a subset of the filesystem

Challenges

I efficient

I updatable from user-space

I unprivileged use:I no xattrI no absolute path

SolutionI new eBPF map type to identify an inode object

I use inode as key and associate it with an arbitrary value

13 / 32

Page 24: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Demonstration #2 [PATCH v8]

Update access rights on the fly

14 / 32

Page 25: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Chained programs and session [PATCH v8]

Landlock programs and their triggers (example)

15 / 32

Page 26: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Chained programs and session [PATCH v8]

Landlock programs and their triggers (example)

15 / 32

Page 27: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Chained programs and session [PATCH v8]

Landlock programs and their triggers (example)

15 / 32

Page 28: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Walking through a file path [PATCH v8]

Example: open /public/web/index.html

16 / 32

Page 29: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Walking through a file path [PATCH v8]

Example: open /public/web/index.html

16 / 32

Page 30: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Walking through a file path [PATCH v8]

Example: open /public/web/index.html

16 / 32

Page 31: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Walking through a file path [PATCH v8]

Example: open /public/web/index.html

16 / 32

Page 32: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Walking through a file path [PATCH v8]

Example: open /public/web/index.html

16 / 32

Page 33: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Walking through a file path [PATCH v8]

Example: open /public/web/index.html

16 / 32

Page 34: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Demonstration #3 [PATCH v10]

I deny access to ∼/.ssh and ∼/.gnupgI ptrace restriction

17 / 32

Page 35: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

From the rule to the kernel

I writing a Landlock rule

I loading it in the kernel

I enforcing it on a set of processes

18 / 32

Page 36: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Life cycle of a Landlock program

19 / 32

Page 37: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock eBPF inode map

1 struct bpf_map_def SEC("maps") inode_map = {2 .type = BPF_MAP_TYPE_INODE,3 .key_size = sizeof(u32),4 .value_size = sizeof(u64),5 .max_entries = MAP_MAX_ENTRIES,6 .map_flags = BPF_F_RDONLY_PROG,7 };

20 / 32

Page 38: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock eBPF inode map

1 struct bpf_map_def SEC("maps") inode_map = {2 .type = BPF_MAP_TYPE_INODE,3 .key_size = sizeof(u32),4 .value_size = sizeof(u64),5 .max_entries = MAP_MAX_ENTRIES,6 .map_flags = BPF_F_RDONLY_PROG,7 };

20 / 32

Page 39: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock eBPF inode map

1 struct bpf_map_def SEC("maps") inode_map = {2 .type = BPF_MAP_TYPE_INODE,3 .key_size = sizeof(u32),4 .value_size = sizeof(u64),5 .max_entries = MAP_MAX_ENTRIES,6 .map_flags = BPF_F_RDONLY_PROG,7 };

20 / 32

Page 40: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock eBPF inode map

1 struct bpf_map_def SEC("maps") inode_map = {2 .type = BPF_MAP_TYPE_INODE,3 .key_size = sizeof(u32),4 .value_size = sizeof(u64),5 .max_entries = MAP_MAX_ENTRIES,6 .map_flags = BPF_F_RDONLY_PROG,7 };

20 / 32

Page 41: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock eBPF program code

1 SEC("landlock/fs_pick")2 int fs_pick_ro(struct landlock_ctx_fs_pick *ctx)3 {4 u64 *flags;56 flags = bpf_inode_map_lookup_elem(&inode_map,7 (void *)ctx->inode);8 if (flags && (*flags & MAP_FLAG_DENY))9 return LANDLOCK_RET_DENY;

10 return LANDLOCK_RET_ALLOW;11 }

21 / 32

Page 42: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock eBPF program code

1 SEC("landlock/fs_pick")2 int fs_pick_ro(struct landlock_ctx_fs_pick *ctx)3 {4 u64 *flags;56 flags = bpf_inode_map_lookup_elem(&inode_map,7 (void *)ctx->inode);8 if (flags && (*flags & MAP_FLAG_DENY))9 return LANDLOCK_RET_DENY;

10 return LANDLOCK_RET_ALLOW;11 }

21 / 32

Page 43: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock eBPF program code

1 SEC("landlock/fs_pick")2 int fs_pick_ro(struct landlock_ctx_fs_pick *ctx)3 {4 u64 *flags;56 flags = bpf_inode_map_lookup_elem(&inode_map,7 (void *)ctx->inode);8 if (flags && (*flags & MAP_FLAG_DENY))9 return LANDLOCK_RET_DENY;

10 return LANDLOCK_RET_ALLOW;11 }

21 / 32

Page 44: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock eBPF program code

1 SEC("landlock/fs_pick")2 int fs_pick_ro(struct landlock_ctx_fs_pick *ctx)3 {4 u64 *flags;56 flags = bpf_inode_map_lookup_elem(&inode_map,7 (void *)ctx->inode);8 if (flags && (*flags & MAP_FLAG_DENY))9 return LANDLOCK_RET_DENY;

10 return LANDLOCK_RET_ALLOW;11 }

21 / 32

Page 45: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock eBPF program code

1 SEC("landlock/fs_pick")2 int fs_pick_ro(struct landlock_ctx_fs_pick *ctx)3 {4 u64 *flags;56 flags = bpf_inode_map_lookup_elem(&inode_map,7 (void *)ctx->inode);8 if (flags && (*flags & MAP_FLAG_DENY))9 return LANDLOCK_RET_DENY;

10 return LANDLOCK_RET_ALLOW;11 }

21 / 32

Page 46: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock eBPF program code

1 SEC("landlock/fs_pick")2 int fs_pick_ro(struct landlock_ctx_fs_pick *ctx)3 {4 u64 *flags;56 flags = bpf_inode_map_lookup_elem(&inode_map,7 (void *)ctx->inode);8 if (flags && (*flags & MAP_FLAG_DENY))9 return LANDLOCK_RET_DENY;

10 return LANDLOCK_RET_ALLOW;11 }

21 / 32

Page 47: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock eBPF program code

1 SEC("landlock/fs_pick")2 int fs_pick_ro(struct landlock_ctx_fs_pick *ctx)3 {4 u64 *flags;56 flags = bpf_inode_map_lookup_elem(&inode_map,7 (void *)ctx->inode);8 if (flags && (*flags & MAP_FLAG_DENY))9 return LANDLOCK_RET_DENY;

10 return LANDLOCK_RET_ALLOW;11 }

21 / 32

Page 48: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock program’s metadata

1 struct bpf_load_program_attr load_attr = {};23 load_attr.prog_type = BPF_PROG_TYPE_LANDLOCK_HOOK;4 load_attr.expected_attach_type = BPF_LANDLOCK_FS_PICK;5 load_attr.expected_attach_triggers = LANDLOCK_TRIGGER_FS_PICK_OPEN;6 load_attr.insns = insns;7 load_attr.insns_cnt = sizeof(insn) / sizeof(struct bpf_insn);8 load_attr.license = "GPL";9

10 int prog_fd = bpf_load_program_xattr(&load_attr, log_buf, log_buf_sz);11 if (prog_fd == -1)12 exit(1);

22 / 32

Page 49: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock program’s metadata

1 struct bpf_load_program_attr load_attr = {};23 load_attr.prog_type = BPF_PROG_TYPE_LANDLOCK_HOOK;4 load_attr.expected_attach_type = BPF_LANDLOCK_FS_PICK;5 load_attr.expected_attach_triggers = LANDLOCK_TRIGGER_FS_PICK_OPEN;6 load_attr.insns = insns;7 load_attr.insns_cnt = sizeof(insn) / sizeof(struct bpf_insn);8 load_attr.license = "GPL";9

10 int prog_fd = bpf_load_program_xattr(&load_attr, log_buf, log_buf_sz);11 if (prog_fd == -1)12 exit(1);

22 / 32

Page 50: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock program’s metadata

1 struct bpf_load_program_attr load_attr = {};23 load_attr.prog_type = BPF_PROG_TYPE_LANDLOCK_HOOK;4 load_attr.expected_attach_type = BPF_LANDLOCK_FS_PICK;5 load_attr.expected_attach_triggers = LANDLOCK_TRIGGER_FS_PICK_OPEN;6 load_attr.insns = insns;7 load_attr.insns_cnt = sizeof(insn) / sizeof(struct bpf_insn);8 load_attr.license = "GPL";9

10 int prog_fd = bpf_load_program_xattr(&load_attr, log_buf, log_buf_sz);11 if (prog_fd == -1)12 exit(1);

22 / 32

Page 51: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock program’s metadata

1 struct bpf_load_program_attr load_attr = {};23 load_attr.prog_type = BPF_PROG_TYPE_LANDLOCK_HOOK;4 load_attr.expected_attach_type = BPF_LANDLOCK_FS_PICK;5 load_attr.expected_attach_triggers = LANDLOCK_TRIGGER_FS_PICK_OPEN;6 load_attr.insns = insns;7 load_attr.insns_cnt = sizeof(insn) / sizeof(struct bpf_insn);8 load_attr.license = "GPL";9

10 int prog_fd = bpf_load_program_xattr(&load_attr, log_buf, log_buf_sz);11 if (prog_fd == -1)12 exit(1);

22 / 32

Page 52: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock program’s metadata

1 struct bpf_load_program_attr load_attr = {};23 load_attr.prog_type = BPF_PROG_TYPE_LANDLOCK_HOOK;4 load_attr.expected_attach_type = BPF_LANDLOCK_FS_PICK;5 load_attr.expected_attach_triggers = LANDLOCK_TRIGGER_FS_PICK_OPEN;6 load_attr.insns = insns;7 load_attr.insns_cnt = sizeof(insn) / sizeof(struct bpf_insn);8 load_attr.license = "GPL";9

10 int prog_fd = bpf_load_program_xattr(&load_attr, log_buf, log_buf_sz);11 if (prog_fd == -1)12 exit(1);

22 / 32

Page 53: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock program’s metadata

1 struct bpf_load_program_attr load_attr = {};23 load_attr.prog_type = BPF_PROG_TYPE_LANDLOCK_HOOK;4 load_attr.expected_attach_type = BPF_LANDLOCK_FS_PICK;5 load_attr.expected_attach_triggers = LANDLOCK_TRIGGER_FS_PICK_OPEN;6 load_attr.insns = insns;7 load_attr.insns_cnt = sizeof(insn) / sizeof(struct bpf_insn);8 load_attr.license = "GPL";9

10 int prog_fd = bpf_load_program_xattr(&load_attr, log_buf, log_buf_sz);11 if (prog_fd == -1)12 exit(1);

22 / 32

Page 54: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Loading a rule in the kernel

23 / 32

Page 55: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Applying a Landlock program to a process

1 seccomp(SECCOMP_PREPEND_LANDLOCK_PROG, 0, &prog_fd);

24 / 32

Page 56: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Applying a Landlock program to a process

24 / 32

Page 57: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Applying a Landlock program to a process

24 / 32

Page 58: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Applying a Landlock program to a process

24 / 32

Page 59: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Kernel execution flow

Example: the inode create hook

1. check if landlocked(current)2. call decide fs pick(LANDLOCK TRIGGER FS PICK CREATE, dir)3. for all fs pick programs enforced on the current process

3.1 update the program’s context3.2 interpret the program3.3 continue until one denies the access

25 / 32

Page 60: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Rule enforcement on process hierarchy

Page 61: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Rule enforcement on process hierarchy

Page 62: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Rule enforcement on process hierarchy

Page 63: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Rule enforcement on process hierarchy

Page 64: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Rule enforcement on process hierarchy

Page 65: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Rule enforcement on process hierarchy

Page 66: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Enforcement through cgroups [PATCH v4]

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

Challenges

I complementary to the process hierarchy rules (via seccomp(2))

I processes moving in or out of a cgroup

I unprivileged use with cgroups delegation (e.g. user session)

Page 67: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Enforcement through cgroups [PATCH v4]

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

Challenges

I complementary to the process hierarchy rules (via seccomp(2))

I processes moving in or out of a cgroup

I unprivileged use with cgroups delegation (e.g. user session)

Page 68: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

What is comming [PATCH v11]

Smaller MVP:I remove file system support (i.e. inode map) for now

I add a memory protection hook

26 / 32

Page 69: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Memory protection hook

Handle memory-rights related syscalls

I mmap(2)

I munmap(2)

I mprotect(2)

I pkey mprotect(2)

Rights

I PROT READ

I PROT WRITE

I PROT EXEC

I PROT SHARE

27 / 32

Page 70: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

New BPF LANDLOCK MEM PROT

Dedicated eBPF program context

1 struct landlock_ctx_mem_prot {2 __u64 address;3 __u64 length;4 __u8 protections_current;5 __u8 protections_requested;6 };

28 / 32

Page 71: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

What could come later(medium/long-term)

29 / 32

Page 72: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Future Landlock program types

fs gettag inodes: needed for relative path checks (e.g. openat(2))

fs ioctlcheck IOCTL commands

net *check IPs, ports, protocol. . .

Page 73: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Future Landlock program types

fs gettag inodes: needed for relative path checks (e.g. openat(2))

fs ioctlcheck IOCTL commands

net *check IPs, ports, protocol. . .

Page 74: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Future Landlock program types

fs gettag inodes: needed for relative path checks (e.g. openat(2))

fs ioctlcheck IOCTL commands

net *check IPs, ports, protocol. . .

Page 75: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock: wrap-up

User-space hardening

I programmatic and embeddable access control

I designed for unprivileged2 use

I apply tailored access controls per process

I make it evolve over time (map)

Current statusI standalone patches merged in net/bpf, security and kselftest trees

I current security/landlock/*: ∼1080 SLOC

I stackable security module

I ongoing patch series: LKML, @l0kod

2If you can move mountains, you can move molehills.30 / 32

Page 76: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

Landlock: wrap-up

User-space hardening

I programmatic and embeddable access control

I designed for unprivileged2 use

I apply tailored access controls per process

I make it evolve over time (map)

Current statusI standalone patches merged in net/bpf, security and kselftest trees

I current security/landlock/*: ∼1080 SLOC

I stackable security module

I ongoing patch series: LKML, @l0kod

2If you can move mountains, you can move molehills.30 / 32

Page 77: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

https://landlock.io

31 / 32

Page 78: Landlock: a new kind of Linux Security Module leveraging eBPF · 9/12/2019  · extended Berkeley Packet Filter In-kernel virtual machine I safely execute code in the kernel at run

What about Kernel Runtime Security Instrumentation?

GoalI framework to run security agents, i.e. HIDS (and HIPS?)

I mainly focused on malicious behavior detection

Common points

I LSM

I eBPF

DifferencesI global system audit (neither by cgroups nor by process hierarchies)

I no access-control enforcement (for now)

I not designed for unprivileged use (for now)

I pretty new RFC/PoC

32 / 32