Skip to main content

Meltdown Mitigation KPTI

Meltdown is such a big issue since it breaks down a fundamental assumption of the operating system that user in user mode does not have access to the information stored in kernel memory, which may contain some sensitive data. Since people can not really avoid the vulnerability in processor hardware, the only mitigation of Meltdown is actually in the operating system kernel. As soon as Meltdown goes public among people, companies have released their patches to fix this vulnerability. At this point, kernel page-table isolation (KPTI) seems to be the most efficient solution.


Before the KPTI mitigation, user and kernel modes are actually sharing the same page table. Based on people’s original assumption, user mode can not access information in kernel memory (arrow 1). However, Meltdown proves people wrong. It turns out that with the help of out-of-order execution, people can actually access that sensitive information in kernel memory, applying Meltdown(arrow 2).

This is the place where KPTI comes to assist.KPTI helps to restore the assumption we mentioned above. This mitigation gives each application two sets of pages tables rather than one and switches between them on every kernel-to-user and user-to-kernel transition. In other words, KPTI separate user-space and kernel-space memory entirely. Thus, when attackers try to access the data in the kernel memory in user mode, they can not use the user-mode page table to point to the kernel memory, since those can only be accessed by using kernel-mode page table, which can not be pulled up in user mode.  


However, KPTI comes with pros and cons. Because of the separation of page table, page table swap happens on each system call, interruption and exception, and these swaps may have some impact on the performance of the processors.  Even though there are only few extra instructions on each swap, the translation lookaside buffer (TLB) is cleared each time. The TLB is a cache that stores the virtual and physical memory pairings. When the processor tries to access data in a virtual address, it looks up in the TLB first to check if there is a cache hit before it passing the virtual address into the page table to translate into a physical address. For instance, if there is a TLB cache hit when people try to access a certain address in virtual memory, it only takes about 1 CPU clock cycle to access data in RAM. However, if it is a cache miss in TLB, the CPU is forced to go through the page table mapping again to find the physical address, which may take 10~100 CPU clock cycles. Apparently, when KPTI does the swap between user and kernel space page table and TLB is cleared, there can be no cache hit on each memory access. In other words, KPTI slows down the processor memory access process at least 10 times than processor with Meltdown vulnerability.
People put an experiment on the impact of the KPTI patch. The experiment mainly compares the time of the CPU spent in kernel mode and user mode. The program the CPU working on is fairly easy. It is just a loop that makes a simple system call in the middle. Here is the result:

As you can see, the average time CPU spent in kernel mode is 36.671 before the patch and 39.358 after the KPTI patch. It is clear that the processor spends about (39.358-36.671)/36.671=7.32% more time in the kernel mode. In other words, the processor has less time to process the code people offer it. Plus the TLB issue we mentioned above, the CPU can be slowed down significantly. The worst scenario in this experiment would be the processor needs to access a huge amount of data in the memory while there are many system calls in the same loop. In this case, the TLB will be flushed over and over again and CPU needs to use the page table to map to the physical address repeatedly.

Fortunately, modern CPUs that have the so-called ‘PCID’ feature can mitigate this issue to some extent because they can use this feature – which tags page table entries so the process associated with them can be retrieved efficiently – to avoid flushing the entire TLB on each mode transition.

The same group of people made another experiment to test the KPTI patch's impact on the I/O performance. They used several disk benchmarking tools to examine the effect of the patch on disk I/O (Crystal, Atto, and IOMeter) and they used a very fast SSD to test the experiment. Slower disks have limits on the system calls due to its speed, so they chose an extremely fast disk will maximize the impact of KPTI on I/O. The result shows that even though the sequential read is not affected at all, the random read (multi-thread 4K read) was slowed down from 10% to 15%.

After all, should people patch the Meltdown with the KPTI patch or not? There are different answers to different cases. According to Microsoft, database server not running in a multi-tenanted environment, (e.g on bare metal or as a guest where the other guests are also trusted) may not need patching. While web servers may be more complicated. You cannot be sure who is accessing the server in most cases, so you will probably have no option but to patch it. However, web servers can make significant I/O and network demands and may experience performance slowdowns as a result.


Reference
https://en.wikipedia.org/wiki/Meltdown_(security_vulnerability)
https://en.wikipedia.org/wiki/Kernel_page-table_isolation
https://databricks.com/blog/2018/01/16/meltdown-and-spectre-exploits-and-mitigation-strategies.html
https://www.1e.com/news-insights/blogs/predicting-meltdown/

Comments

Popular posts from this blog

Angr: A Multi-Architecture Binary Analysis Toolkit

This blog is quoted from several angr blogs and documentations, click  here  and  here . angr is a multi-architecture binary analysis toolkit, with the capability to perform dynamic symbolic execution (like Mayhem, KLEE, etc.) and various static analyses on binaries. We've tried to make using angr as pain-free as possible - our goal is to create a user-friendly binary analysis suite, allowing a user to simply start up iPython and easily perform intensive binary analyses with a couple of commands. That being said, binary analysis is complex, which makes angr complex. This documentation is an attempt to help out with that, providing narrative explanation and exploration of angr and its design. Several challenges must be overcome to programmatically analyze a binary. They are, roughly: Loading a binary into the analysis program. Translating a binary into an intermediate representation (IR). Performing the actual analysis. This could be: A partial or full-program static

Information Side Channel

By Elaine Cole and Jarek Millburg An information side channel can be used to gain information about the system or data that it processes. A side-channel attack identifies a physical or micro-architectural signal that leaks such desired information and monitors and analyzes that signal as the system operates. While there are many different types of information side channels and even more ways to maliciously exploit them, this blog explores a recent publication that leverages information side channels within IoT devices to aid crime scene investigators in real-time. In this blog, we provide an overview of the general attack procedure, and explore two of the many forms of side channel attacks. Side Channel Attack General Procedure While there are many different forms of side channels, at a high level, a side channel attack requires the following: 1. identify a side channel:  The attacker must first identify  a physical or micro-architectural signal that leaks desired

Introduction to SGX and potential attack method

The Overview of SGX What is the SGX? With more and more attack on systems and bigger danger inside the internet. We get a new technology which named The Security Guard Extensions (The SGX). Actually the SGX aimed to separate the whole applications to two parts: secure part and unsecure part. The secure part named enclave. Which is stored in protected memory. Between the enclave and application, there is an interface is implemented. Which is consists of e-calls and o-calls. The e-calls are inside the enclave for calling to the unsecured code. The o-calls are located in the unsecured code for collecting data inside the enclave. The enclave is totally protected which means any access from external are not allowed. Only when the untrusted part of application call the trusted function then the code inside the enclave can see the data. When it returns, the enclave data are still stays in safe memory. figure.1 Actually while the application’s host in pr