android kernel jeff vander stoep and sami tolvanen security · 2019-12-21 · combined bitcode 26....

34
Android Kernel Security Linux Security Summit Aug 2018 Jeff Vander Stoep and Sami Tolvanen

Upload: others

Post on 27-May-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Android Kernel Security

Linux Security Summit

Aug 2018

Jeff Vander Stoep and Sami Tolvanen

Page 2: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

AcknowledgementsPeople who have reported security vulnerabilities to Android security: https://source.android.com/security/overview/acknowledgements

Android SDL teamEvgenii Stepanov

Ivan LozanoJoel Galenson

Vishwath Mohan

2

Page 3: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

This data is public

https://source.android.com/security/bulletin/

Data: Sep 2017 → May 2018 3

Page 4: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Android is an open source project

Patches accepted!

4

Page 5: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Kernel vulns in Android

Data: Sep 2017 → May 2018 (Android Oreo)

Kernel accounts for ⅓ of security vulnerabilities on Android.

5

Page 6: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

What’s working well:Attack Surface Reduction

6

Page 7: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

“We think that by far the most effective mitigation work that we’ve seen on the Android platform over the last three

years has been the investment in attack surface reduction. The deployment and tightening of selinux policies and the addition of seccomp sandboxing both result in an attacker

needing to find more vulnerabilities in a smaller attack surface.”

Mark Brand - Google Project Zero

7

Page 8: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Access controls are “hard” mitigations which can be applied without

knowledge of exploitation techniques.

8

Page 9: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Attack surface reduction

Data: Sep 2017 → May 2018 (Android Oreo)

Kernel vulnerabilities that are reachable in userspace but unreachable by unprivileged processes.

(su → kernel vulns are excluded)

9

Unprivileged AccessAccess Restricted

Page 10: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

SELinux

e.g. CVE-2018-5858

Access control mechanismUnix Permissions

e.g. CVE-2017-14892

Capabilities

e.g. CVE-2017-17712

10

Unprivileged AccessPrivileged Access(userspace reachable)

Sep 2017 → Apr 2018

Page 11: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Starting in Android Oreo all apps run with a

seccomp filter. e.g. Blocks CVE-2017-14140

11

Page 12: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Access control is effectiveAttack surface reduction works!

Kernel provided access control + separation of privilege can substantially mitigate risks to the kernel.

12

Page 13: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Unprivileged reachable bugs

(userspace reachable)Sep 2017 → Apr 2018

Some futex() and meltdown vulns.

13

Page 14: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Other userspace → kernelmitigations

14

Page 15: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Hardened UsercopyProvides some run-time checks on data copied to/from userspace

copy_*_user()

15

Vulnerabilities by root cause(userspace reachable)

Sep 2017 → Apr 2018

Page 16: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

PAN

Prevents direct kernel access to userspace.

Enforces use of (hardened) copy_*_user functions.

Found/fixed multiple instances of kernel directly accessing userspace.

16

Page 17: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Unfortunately, not all kernel vulns are reached via

userspace.

17

Page 18: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Kernel vuln reachability

Data: Sep 2017 → May 2018

Userspace Reachable Not Userspace Reachable

We’ve been discussing this.

But what about this ?!?!

18

Page 19: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Non-userspace reachable vulns

Data: Sep 2017 → May 2018

By access vector

By root cause

KRACK

19

Page 20: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Summary Userspace → kernel(a) The attack surface reduction tools provided by the kernel have been very effective on Android.

(b) In addition to attack surface reduction, the kernel now provides mechanisms such as hardened-usercopy + PAN which mitigate some userspace-reachable vulnerabilities.

(c) However, 1/3 of Android’s kernel bugs are reached by other vectors. We need tools similar to (a) and (b) to help address other access vectors.

20

Page 21: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Memory (un)safety

All kernel bugsData: May 2017 → May 2018

21

Page 22: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Control Flow Integrity

22

Page 23: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Control Flow Integrity

What?

Helps protect against code reuse attacks by adding runtime checks to ensure control flow stays within a precomputed graph.

Where?

LLVM ≥ 3.7 implements forward-edge CFI, which protects indirect branches.

How?

Allows an indirect branch only to the beginning of a valid function with the correct type.

23

Page 24: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

How effective is CFI?

55% of indirect calls have ≤ 5 allowed targets

7% have > 100 allowed targets

24

Page 25: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Link Time Optimization

LLVM’s CFI implementation requires LTO to determine all valid call targets.

Must use LLVM’s integrated assembler for inline assembly and an LTO-aware linker, i.e. GNU gold or LLVM lld.

Nearly all problems caused by toolchain compatibility issues. No kernel stability issues during several months of testing.

25

Page 26: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Link Time Optimization

.S.c.c

.o.bc.bc

Front-end Linker

Thin archive

Optimizer

Code generation

vmlinux

Combined bitcode

26

Page 27: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

First Android devices with LTO+CFI kernels ship

later this year.

27

Page 28: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

CFI in the Linux kernel

C compilers allow indirect calls with mismatching types. Several benign CFI failures that had to be fixed.

Cross-DSO CFI support needed for kernel modules.

CFI adds a small overhead to indirect calls. Thanks to LTO, overall performance improved despite CFI.

28

Page 29: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Example of a CFI failure

Mismatching function pointer type

LLVM limits indirect calls to functions that match the type of the function pointer.

drivers/media/v4l2-core/v4l2-ioctl.c:

if (info->flags & INFO_FL_STD) {typedef int (*vidioc_op)(struct file *file, void *fh,

void *p);const void *p = vfd->ioctl_ops;const vidioc_op *vidioc = p + info->u.offset;

ret = (*vidioc)(file, fh, arg);}

Fixed in 3ad3b7a2ebaefae3 (“media: v4l2-ioctl: replace IOCTL_INFO_STD with stub functions”)

29

Page 30: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Example cont’d

CFI check, slowpath for cross-DSO. Only returns if the target address is allowed.

Indirect function call.

30

Page 31: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Example cont’d

Error handling

In normal mode, CFI failure results in a kernel panic, which includes the target address.

For debugging only, a permissive mode that produces a warning instead.

CFI failure (target: [<fffffff3e83d4d80>] my_target_function+0x0/0xd80):------------[ cut here ]------------kernel BUG at kernel/cfi.c:32!Internal error: Oops - BUG: 0 [#1] PREEMPT SMP…Call trace:…[<ffffff8752d00084>] handle_cfi_failure+0x20/0x28[<ffffff8752d00268>] my_buggy_function+0x0/0x10…

31

Page 32: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

CFI in Android kernels

Supported in 4.9 and 4.14 for arm64

CONFIG_LTO_CLANG=yCONFIG_CFI_CLANG=y

# CONFIG_CFI_PERMISSIVE=y for debugging.

Requires clang ≥ 5.0 and binutils ≥ 2.27.

32

Page 33: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Future work

CFI only protects indirect branches. LLVM’s Shadow Call Stack helps protect return addresses.

Plenty of issues with GNU gold. Ongoing work to switch to LLVM’s lld linker instead.

33

Page 34: Android Kernel Jeff Vander Stoep and Sami Tolvanen Security · 2019-12-21 · Combined bitcode 26. First Android devices with LTO+CFI kernels ship later this year. 27. CFI in the

Thank you