Distribution Kernel Security Hardening with ftrace

Similar documents
How Linux Capability Works in

CPSC Tutorial 17

Landlock LSM: toward unprivileged sandboxing

CS 423 Operating System Design: Introduction to Linux Kernel Programming (MP1 Q&A)

ViryaOS RFC: Secure Containers for Embedded and IoT. A proposal for a new Xen Project sub-project

First order of Business

Securing Containers on the High Seas. Jack OWASP Belgium September 2018

Using the Kernel Security Module Interface

Hacking and Hardening Kubernetes

Fall 2014:: CSE 506:: Section 2 (PhD) Securing Linux. Hyungjoon Koo and Anke Li

Operating system hardening

International Journal of Computer Engineering and Technology (IJCET), ISSN 0976 & TECHNOLOGY (IJCET) PROCESS BEHAVIOUR MODELLING USING LSM

CONTAINER AND MICROSERVICE SECURITY ADRIAN MOUAT

PROCESS MANAGEMENT Operating Systems Design Euiseong Seo

Subverting the Linux Kernel Linux Kernel Rootkits 101

Outline. Basic features of BPF virtual machine

Advanced Systems Security: Principles

Container Isolation at Scale (... and introducing gvisor) Dawn Chen and Zhengyu He

Seccomp, network and namespaces. Francesco Tornieri <francesco.tornieri AT kiratech.it>

CNIT 127: Exploit Development. Ch 3: Shellcode. Updated

7.3 Simplest module for embedded Linux drivers

Linux Kernel Security Overview

Cyber Common Technical Core (CCTC) Advance Sheet Windows Operating Systems

Overview. This Lecture. Interrupts and exceptions Source: ULK ch 4, ELDD ch1, ch2 & ch4. COSC440 Lecture 3: Interrupts 1

Docker Security. Mika Vatanen

CS 326: Operating Systems. Process Execution. Lecture 5

Using a Linux Security Module for Contest Security

Module: Operating System Security. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security

File access-control per container with Landlock

Kprobes Presentation Overview

Using seccomp to limit the kernel attack surface

Background: Operating Systems

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

Linux Security Summit Europe 2018

Sandboxing. (1) Motivation. (2) Sandboxing Approaches. (3) Chroot

Secure Containers with EPT Isolation

ISOLATION DEFENSES GRAD SEC OCT

Virtual File System (VFS) Implementation in Linux. Tushar B. Kute,

Docker Container Manager: A Simple Toolkit for Isolated Work with Shared Computational, Storage, and Network Resources

How to Restrict a Login Shell Using Linux Namespaces

Securing Android-Powered Mobile Devices Using SELinux

The Case for Security Enhanced (SE) Android. Stephen Smalley Trusted Systems Research National Security Agency

CERT Secure Coding Initiative. Define security requirements. Model Threats 11/30/2010

Loadable Kernel Modules

PREVENTING EXPLOITS WITH SECURITY ENHANCED LINUX

OS Security III: Sandbox and SFI

Seccomp. Linux Security and Isolation APIs. Outline. Michael Kerrisk, man7.org c 2017 November 2017

Linux Kernel Exploitation. Where no user has gone before

Securing Unix Filesystems - When Good Permissions Go Bad

CS 356 Operating System Security. Fall 2013

A Design for Comprehensive Kernel Instrumentation

CS 5460/6460 Operating Systems

CERIAS Tech Report Trojan Horse Resistant Discretionary Access Control by Ziqing Mao, Ninghui Li, Hong Chen, Xuxian Jiang Center for Education

Using seccomp to limit the kernel attack surface

Presented By: Gregory M. Kurtzer HPC Systems Architect Lawrence Berkeley National Laboratory CONTAINERS IN HPC WITH SINGULARITY

OS security mechanisms:

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

Device Drivers. CS449 Fall 2017

March 10, Linux Live Patching. Adrien schischi Schildknecht. Why? Who? How? When? (consistency model) Conclusion

Runtime Process Insemination

CSE Computer Security

Last time. Security Policies and Models. Trusted Operating System Design. Bell La-Padula and Biba Security Models Information Flow Control

Operating System System Call & Debugging Technique

Secureworld Conference

Multi-tenancy Virtualization Challenges & Solutions. Daniel J Walsh Mr SELinux, Red Hat Date

Operating Systems II BS degree in Computer Engineering Sapienza University of Rome Lecturer: Francesco Quaglia. Topics: 1.

CSC369 Lecture 2. Larry Zhang

Operating system security models

Securing Untrusted Code

Live Patching: The long road from Kernel to User Space. João Moreira Toolchain Engineer - SUSE Labs

CSC369 Lecture 2. Larry Zhang, September 21, 2015

Secure Software Programming and Vulnerability Analysis

Linux drivers - Exercise

SE350: Operating Systems. Lecture 3: Concurrency

CS61 Scribe Notes Date: Topic: Fork, Advanced Virtual Memory. Scribes: Mitchel Cole Emily Lawton Jefferson Lee Wentao Xu

SECURING SOFTWARE AGAINST LIBRARY ATTACKS

Sandboxing. CS-576 Systems Security Instructor: Georgios Portokalidis Spring 2018

TCSS 422: OPERATING SYSTEMS

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

Using seccomp to limit the kernel attack surface

Running Network Services under User-Mode

Using kgdb and the kgdb Internals

OPENVMS SECURITY & NEW FEATURES IN V8.4

CS5460/6460: Operating Systems. Lecture 24: Device drivers. Anton Burtsev April, 2014

Web Application Security Payloads. Andrés Riancho SecTor 2010, Toronto, Canada.

Who am I? I m a python developer who has been working on OpenStack since I currently work for Aptira, who do OpenStack, SDN, and orchestration

July 14, EPITA Systems/Security Laboratory (LSE) Code sandboxing. Alpha Abdoulaye - Pierre Marsais. Introduction. Solutions.

ECE 471 Embedded Systems Lecture 22

Network stack virtualization for FreeBSD 7.0. Marko Zec

Problem System administration tasks on a VM from the outside, e.g., issue administrative commands such as hostname and rmmod. One step ahead tradition

Data Security and Privacy. Unix Discretionary Access Control

Outline. Security as an economic good. Risk budgeting with ALE. Failure: Risk compensation. Failure: Displacement activity

Chapter 2: System Structures. Operating System Concepts 9 th Edition

SELinux Introduction. Jason Zaman FOSSASIA 2017 March 17th - 19th blog.perfinion.com

, Inc

Advanced Systems Security: Ordinary Operating Systems

Secure Architecture Principles

Advanced Operating Systems #13

SELinux type label enforcement

Transcription:

Distribution Kernel Security Hardening with ftrace Because sometimes your OS vendor just doesn't have the security features that you want. Written by: Corey Henderson

Exploit Attack Surface Hardening system security is essentially all about reducing the attack surface in which a bad actor is able work in. In the absence of hardening tools, the default mode of the linux operating system is discretionary access control, which allows programs to make any syscall available on the system. While syscalls are generally well protected, little is done to detect and eliminate arbitrary code execution that occurs due to overran memory, which is largely where privilage escalation exploits are made possible. Exploits that give elevated access on a system are often done through syscalls in which a program shouldn't need to make anyway. Even in the presence of mandatory access control systems such as SELinux and AppArmor, access to a wide array of syscalls are still left unrestricted. The Linux Security Module (LSM) framework that allows these mandatory access control systems still doesn't directly address this either. While tightening what access a process has to the filesystem and other running processes, it doesn't allow for targeted instrumented protections against available syscalls. Thus, if a bad actor is able to execute arbitrary code in memory, the LSM framework has little ability to detect and stop the attempt. The grsecurity project does an excellent job in preventing exploits via address randomization, preventing memory overrun, execution of read-only memory, among other methods, yet its protections are mostly unavailable in most linux kernel distributions available today. Firewall for syscalls The seccomp filter interface does allow a process to drop its ability to make syscalls, akin to how a firewall prevents the network from talking to specific ports. Docker has done an excellent job of making this easily available to its container process, and will go a long way to narrowing the attack surface of any program it isolates. However, this does nothing if any exploit is available in a syscall that a program does have access to, and the default docker seccomp configuration is still rather permissive. Consider running an application in a Docker container process with all kernel capabilities dropped, a read-only filesystem, and a seccomp profile that limits the available syscalls down to a narrow set. This is a very small attack surface should the container process be compromised. However, a bad actor still has the non-filtered syscalls avaiable for exploit. Like any firewall, an available syscall is akin to a port allowed by a firewall. Advanced firewalls are able to monitor traffic on allowed ports and take defensive action if that traffic is suspicious. The generic seccomp filter doesn't have this capability, and the LSM framework is limited in its scope. While this is a least privileged scenario, there are still opportunities for a bad actor to do privilege escalation, because some syscalls are still available for use. How do we instrument advanced functionality for active checking of what a process does send through these syscalls?

Hooking kernel functions with ftrace / fopskit The ftrace interface is intended for tracing kernel threads for debugging purposes, but can do so much more than that. Because it can instrument almost any kernel symbol to redirect the execution flow of any process on the system, it can be used to hook kernel functions that otherwise have insufficient capability for targeted projection. The out-of-kernel fopskit code is a wrapper to ftrace to make the hooking of kernel symbols easy to do from within a kernel module. Below is code for a very simple example of this. It targets the sys_open() syscall with code to deny an open if the running process is in a given group id and the file is within the /boot directory. While this can be done with normal filesystem permissions, it shows how targeted code written by a security programmer to instrument specific protections to specific kernel functions. First, download the source code of fopskit located in on github: https://github.com/cormander/tpe-lkm/blob/2.0.0/fopskit.h https://github.com/cormander/tpe-lkm/blob/2.0.0/fopskit.c Then compile the below module code: #include <linux/module.h> #include "fopskit.h" int test_eaccess(void) { return -EACCES; fopskit_hook_handler(sys_open) { if (in_group_p(kgidt_init(1000)) &&!strncmp((const char *)REGS_ARG1, "/boot", 5)) regs->ip = (unsigned long)test_eaccess; struct fops_hook hook_sys_open = fops_hook_val(sys_open); static int init test_init(void) { fopskit_sym_hook(&hook_sys_open); return 0; static void exit test_exit(void) { fopskit_sym_unhook(&hook_sys_open); module_init(test_init); module_exit(test_exit); MODULE_LICENSE("GPL");

After module insertion, a user belonging to gid 1000 can no longer make open calls on files in the /boot directory: $ sudo insmod test.ko $ cat /boot/config-3.10.0-514.10.2.el7.x86_64 cat: /boot/config-3.10.0-514.10.2.el7.x86_64 $ echo $? 1 This of course isn't a complete protection of the files in the boot directory, as other syscalls can still find their way into reading those files, but serves as an example of how easy it is and how little code is required to hook a function with ftrace. Instrumenting Security Hardening Features Consider the Trusted Path Execution (TPE) feature of grsecurity. It's a simple concept; users are denied execution of binary code that exist in files they are able to write to. This prevents certain entry points for code by a bad actor that would otherwise be left wide open for exploitation. Since almost every process on a system needs the ability to make calls to the syscalls responsible for code execution (mmap, mprotect, and execve), removing access to them via seccomp filtering is unrealistic. The LSM hooks also fail to protect in this area because they are limited to the code that already exists in the kernel itself, which does not add the ability to create this protection. By planting an ftrace at functions used by each of these syscalls and redirecting to new code by a loadable kernel module, a system administrator can instrument the targeted protection of TPE with very minimal code. Consider the following example: fopskit_hook_handler(security_bprm_check) { struct linux_binprm *bprm = (struct linux_binprm *)REGS_ARG1; if (bprm->file) if (tpe_allow_file(bprm->file, "exec")) regs->ip = (unsigned long)tpe_eaccess; What happens here is the fopskit_hook_handler() macro automatically creates the needed fops_struct corresponding to the kernel function, in this case, security_bprm_check(), and assigns its address to it. The fopskit_sym_hook() call uses the ftrace interface to redirect the given kernel symbol back to that code. The hook handler is a void function and normally ftrace would send the code flow back to the original function, preventing the change of the return value of the function. However, you can override the kernel return address via regs->ip register, and thus have the ability to control the return value. In this example, if the tpe_allow_file() check return an error, the code flow is redirected to the tpe_eaccess() function, which returns the permission denied error code back to the calling thread.

This only handles calls to execve. Full protection of code execution of course requires instrumentation of the mmap and mprotect syscalls, which the tpe-lkm kernel module project does. Full source code available on github: https://github.com/cormander/tpe-lkm/ Summary By closing down the unused syscalls of a process via the seccomp filter, and hooking the syscalls left open, security programmers can instrument targeted code to create protections akin to an advanced firewall. While the container process needs certain syscalls to function, the ability to lock down those syscalls to only the intended purposes can further secure a system from bad actors. Also, security features that are out-of-tree of that distribution could be added. For example, AppArmor could theoretically be inserted into a kernel running SELinux, where under normal circumstances only one LSM framework could be run.