From: Kees Cook <firstname.lastname@example.org> To: email@example.com Cc: Kees Cook <firstname.lastname@example.org>, John Wood <email@example.com>, Matthew Wilcox <firstname.lastname@example.org>, Jonathan Corbet <email@example.com>, Alexander Viro <firstname.lastname@example.org>, Ingo Molnar <email@example.com>, Peter Zijlstra <firstname.lastname@example.org>, Juri Lelli <email@example.com>, Vincent Guittot <firstname.lastname@example.org>, Dietmar Eggemann <email@example.com>, Steven Rostedt <firstname.lastname@example.org>, Ben Segall <email@example.com>, Mel Gorman <firstname.lastname@example.org>, Luis Chamberlain <email@example.com>, Iurii Zaikin <firstname.lastname@example.org>, James Morris <email@example.com>, "Serge E. Hallyn" <firstname.lastname@example.org>, email@example.com, firstname.lastname@example.org, email@example.com, firstname.lastname@example.org Subject: [RESEND][RFC PATCH 0/6] Fork brute force attack mitigation (fbfam) Date: Thu, 10 Sep 2020 13:21:01 -0700 [thread overview] Message-ID: <email@example.com> (raw) [kees: re-sending this series on behalf of John Wood <firstname.lastname@example.org> also visible at https://github.com/johwood/linux fbfam] From: John Wood <email@example.com> The goal of this patch serie is to detect and mitigate a fork brute force attack. Attacks with the purpose to break ASLR or bypass canaries traditionaly use some level of brute force with the help of the fork system call. This is possible since when creating a new process using fork its memory contents are the same as those of the parent process (the process that called the fork system call). So, the attacker can test the memory infinite times to find the correct memory values or the correct memory addresses without worrying about crashing the application. Based on the above scenario it would be nice to have this detected and mitigated, and this is the goal of this implementation. Other implementations --------------------- The public version of grsecurity, as a summary, is based on the idea of delay the fork system call if a child died due to a fatal error. This has some issues: 1.- Bad practices: Add delays to the kernel is, in general, a bad idea. 2.- Weak points: This protection can be bypassed using two different methods since it acts only when the fork is called after a child has crashed. 2.1.- Bypass 1: So, it would still be possible for an attacker to fork a big amount of children (in the order of thousands), then probe all of them, and finally wait the protection time before repeat the steps. 2.2.- Bypass 2: This method is based on the idea that the protection doesn't act if the parent crashes. So, it would still be possible for an attacker to fork a process and probe itself. Then, fork the child process and probe itself again. This way, these steps can be repeated infinite times without any mitigation. This implementation ------------------- The main idea behind this implementation is to improve the existing ones focusing on the weak points annotated before. So, the solution for the first bypass method is to detect a fast crash rate instead of only one simple crash. For the second bypass method the solution is to detect both the crash of parent and child processes. Moreover, as a mitigation method it is better to kill all the offending tasks involve in the attack instead of use delays. So, the solution to the two bypass methods previously commented is to use some statistical data shared across all the processes that can have the same memory contents. Or in other words, a statistical data shared between all the processes that fork the task 0, and all the processes that fork after an execve system call. These statistics hold the timestamp for the first fork (case of a fork of task zero) or the timestamp for the execve system call (the other case). Also, hold the number of faults of all the tasks that share the same statistical data since the commented timestamp. With this information it is possible to detect a brute force attack when a task die in a fatal way computing the crashing rate. This rate shows the milliseconds per fault and when it goes under a certain threshold there is a clear signal that something malicious is happening. Once detected, the mitigation only kills the processes that share the same statistical data and so, all the tasks that can have the same memory contents. This way, an attack is rejected. The fbfam feature can be enabled, disabled and tuned as follows: 1.- Per system enabling: This feature can be enabled in build time using the config application under: Security options ---> Fork brute force attack mitigation 2.- Per process enabling/disabling: To allow that specific applications can turn off or turn on the detection and mitigation of a fork brute force attack when required, there are two new prctls. prctl(PR_FBFAM_ENABLE, 0, 0, 0, 0) -> To enable the feature prctl(PR_FBFAM_DISABLE, 0, 0, 0, 0) -> To disable the feature Both functions return zero on success and -EFAULT if the current task doesn't have statistical data. 3.- Fine tuning: To customize the detection's sensibility there is a new sysctl that allows to set the crashing rate threshold. It is accessible through the file: /proc/sys/kernel/fbfam/crashing_rate_threshold The units are in milliseconds per fault and the attack's mitigation is triggered if the crashing rate of an application goes under this threshold. So, the higher this value, the faster an attack will be detected. So, knowing all this information I will explain now the different patches: The 1/9 patch adds a new config for the fbfam feature. The 2/9 and 3/9 patches add and use the api to manage the statistical data necessary to compute the crashing rate of an application. The 4/9 patch adds a new sysctl to fine tuning the detection's sensibility. The 5/9 patch detects a fork brute force attack calculating the crashing rate. The 6/9 patch mitigates the attack killing all the offending tasks. The 7/9 patch adds two new prctls to allow per task enabling/disabling. The 8/9 patch adds general documentation. The 9/9 patch adds an entry to the maintainers list. This patch series is a task of the KSPP  and it is worth to mention that there is a previous attempt without any continuation .  https://github.com/KSPP/linux/issues/39  https://firstname.lastname@example.org/ Any constructive comments are welcome. Note: During the compilation these warnings were shown: kernel/exit.o: warning: objtool: __x64_sys_exit_group()+0x18: unreachable instruction arch/x86/kernel/cpu/mce/core.o: warning: objtool: mce_panic()+0x123: unreachable instruction arch/x86/kernel/smpboot.o: warning: objtool: native_play_dead()+0x122: unreachable instruction net/core/skbuff.o: warning: objtool: skb_push.cold()+0x14: unreachable instruction John Wood (6): security/fbfam: Add a Kconfig to enable the fbfam feature security/fbfam: Add the api to manage statistics security/fbfam: Use the api to manage statistics security/fbfam: Add a new sysctl to control the crashing rate threshold security/fbfam: Detect a fork brute force attack security/fbfam: Mitigate a fork brute force attack fs/coredump.c | 2 + fs/exec.c | 2 + include/fbfam/fbfam.h | 24 ++++ include/linux/sched.h | 4 + kernel/exit.c | 2 + kernel/fork.c | 4 + kernel/sysctl.c | 9 ++ security/Kconfig | 1 + security/Makefile | 4 + security/fbfam/Kconfig | 10 ++ security/fbfam/Makefile | 3 + security/fbfam/fbfam.c | 279 ++++++++++++++++++++++++++++++++++++++++ security/fbfam/sysctl.c | 20 +++ 13 files changed, 364 insertions(+) create mode 100644 include/fbfam/fbfam.h create mode 100644 security/fbfam/Kconfig create mode 100644 security/fbfam/Makefile create mode 100644 security/fbfam/fbfam.c create mode 100644 security/fbfam/sysctl.c -- 2.25.1
next reply other threads:[~2020-09-10 20:22 UTC|newest] Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-09-10 20:21 Kees Cook [this message] 2020-09-10 20:21 ` [RFC PATCH 1/6] security/fbfam: Add a Kconfig to enable the fbfam feature Kees Cook 2020-09-10 21:21 ` Jann Horn 2020-09-10 21:21 ` Jann Horn 2020-09-17 17:32 ` John Wood 2020-09-10 23:18 ` Kees Cook 2020-09-17 18:40 ` John Wood 2020-09-17 22:05 ` Kees Cook 2020-09-18 14:50 ` John Wood 2020-09-10 20:21 ` [RFC PATCH 2/6] security/fbfam: Add the api to manage statistics Kees Cook 2020-09-10 23:23 ` Kees Cook 2020-09-10 20:21 ` [RFC PATCH 3/6] security/fbfam: Use " Kees Cook 2020-09-10 20:27 ` Jann Horn 2020-09-10 20:27 ` Jann Horn 2020-09-10 23:33 ` Kees Cook 2020-09-29 23:47 ` Steven Rostedt 2020-09-29 23:49 ` Steven Rostedt 2020-10-03 9:52 ` John Wood 2020-09-10 20:21 ` [RFC PATCH 4/6] security/fbfam: Add a new sysctl to control the crashing rate threshold Kees Cook 2020-09-10 23:14 ` Kees Cook 2020-09-13 14:33 ` John Wood 2020-09-10 20:21 ` [RFC PATCH 5/6] security/fbfam: Detect a fork brute force attack Kees Cook 2020-09-10 21:10 ` Jann Horn 2020-09-10 21:10 ` Jann Horn 2020-09-13 17:54 ` John Wood 2020-09-14 19:42 ` Jann Horn 2020-09-14 19:42 ` Jann Horn 2020-09-15 18:44 ` John Wood 2020-09-10 23:49 ` Kees Cook 2020-09-11 0:01 ` Jann Horn 2020-09-11 0:01 ` Jann Horn 2020-09-13 16:56 ` John Wood 2020-09-14 19:39 ` Jann Horn 2020-09-14 19:39 ` Jann Horn 2020-09-15 17:36 ` John Wood 2020-09-10 20:21 ` [RFC PATCH 6/6] security/fbfam: Mitigate " Kees Cook 2020-09-10 20:55 ` Jann Horn 2020-09-10 20:55 ` Jann Horn 2020-09-10 23:56 ` Kees Cook 2020-09-11 0:20 ` Jann Horn 2020-09-11 0:20 ` Jann Horn 2020-09-18 16:02 ` John Wood 2020-09-18 21:35 ` Kees Cook 2020-09-19 8:01 ` John Wood 2020-09-10 20:39 ` [RESEND][RFC PATCH 0/6] Fork brute force attack mitigation (fbfam) Jann Horn 2020-09-10 20:39 ` Jann Horn 2020-09-10 23:58 ` Kees Cook 2020-09-11 14:48 ` John Wood 2020-09-12 7:55 ` Kees Cook 2020-09-12 12:24 ` John Wood 2020-09-12 0:03 ` James Morris 2020-09-12 7:56 ` Kees Cook 2020-09-12 9:36 ` John Wood 2020-09-12 14:47 ` Mel Gorman 2020-09-12 20:48 ` Ondrej Mosnacek 2020-09-12 20:48 ` Ondrej Mosnacek 2020-09-13 7:24 ` John Wood 2020-09-13 7:24 ` John Wood
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --subject='Re: [RESEND][RFC PATCH 0/6] Fork brute force attack mitigation (fbfam)' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.