Date: Thu, 14 Feb 2019 07:52:07 +0000 From: "Reshetova, Elena" <elena.reshetova@...el.com> To: "Perla, Enrico" <enrico.perla@...el.com>, Andy Lutomirski <luto@...capital.net>, "keescook@...omium.org" <keescook@...omium.org>, "Jann Horn" <jannh@...gle.com> CC: Andy Lutomirski <luto@...nel.org>, Peter Zijlstra <peterz@...radead.org>, "kernel-hardening@...ts.openwall.com" <kernel-hardening@...ts.openwall.com>, "tglx@...utronix.de" <tglx@...utronix.de>, "mingo@...hat.com" <mingo@...hat.com>, "bp@...en8.de" <bp@...en8.de>, "tytso@....edu" <tytso@....edu> Subject: RE: [RFC PATCH] x86/entry/64: randomize kernel stack offset upon system call After some thinking and discussions, let me try to summarize the options and the security benefits of each approach based on everyone else feedback before going any further with work. We all want only useful things in kernel, so merging smth that provides a subtle/almost non-existing benefit is clearly not a priority. So, first about the protection methods. We can do randomization in two ways: 1. stack top itself (and location of pt_regs) 2. relative stack positioning (offset from pt_regs). In addition to randomization we can do some fixup on exit, like Andy proposed: 3. Make sure CS always points to user on exit (for example by regs->cs |= 3), potentially smth else can be fixed up similarly, if needed Here are *known* (at least to me, please shout if you know more!) possible attacks vectors and implications on them by doing 1), 2) or 3) a) attacker's goal is to store some user-controlled data in pt_regs to reference it later 1) pt_regs is not predictable, but can be discovered in ptrace-style scenario or cache-probing. If discovered, then attack succeeds as of now. 2) nothing changed for this type of attack, attack succeeds as of now 3) nothing changed for this type of attack, attack succeeds as of now b) attacker's goal is to return to userland from a syscall with CS pointing to kernel 1) pt_regs is not predictable, but can be discovered in ptrace-style scenario or cache-probing. If discovered, then attack succeeds as of now. 2) nothing changed for this type of attack, attack succeeds as of now 3) CS changed explicitly on exit, so impossible to have this attack, *given* that the change is done late enough and no races, sleeps, etc. are possible c) attacker's goal is to perform some kind of stack overflow into parts of adjusted stack memory via some method. Here the main unknown is the "method". This vector of attack is the challenge for the current exploit writers: I guess if you can do it now with all the current protections for stack enabled, you get a nice defcon talk at least :) VLA used to be an easy way of doing it, hopefully they are gone from the main source now (out of tree drivers is a different story). Uninitialized locals might be other way, but there is work ongoing to close this (see Kees's patches on stackinit). Smth else we don’t yet know? Now back to our proposed countermeasures given that attacker has found a way to do a crafted overflow and overwrite: 1) pt_regs is not predictable, but can be discovered in ptrace-style scenario or cache-probing. If discovered, then attack succeeds as of now. 2) relative stack offset is not predictable and randomized, cannot be probed very easily via cache or ptrace. So, this is an additional hurdle on the attacker's way since stack is non- deterministic now. 3) nothing changed for this type of attack, given that attacker's goal is not to overwrite CS in adjusted pt_regs. If it is his goal, then it helps with that. Now summary: It would seem to me that: - regs->cs |= 3 on exit is a thing worth doing anyway, just because it is cheap, as Andy said, and it might make a positive difference in two out of three attack scenarios. Objections? - randomization of stack top is only worth doing in ptrace-blocked scenario. Do we have such scenarios left that people care about? Because if we do, then we know that there is a real attack vector that we close this way, otherwise not. This is actually interesting, because we need to remember to take ptrace into our overall kernel hardening threat model (smth that at least I haven't quite realized before) and evaluate every new feature (especially randomization ones) being robust against ptrace probing. - randomization after pt_regs only would make a difference in attack scenario "c", for which we don't yet have a proof of concept exploit or technique that would work (does not guarantee that attackers don't have the exploits ready through :( ). So, if we implement this, the "justification part" for the feature would be smth like "to make it harder for future possible stack-based exploits that utilize overflows", if/when someone find a new 'ala VLA' way of doing the controlled overflow. How do people feel about it? Is it worth having? I can work on the POC for this in direction that Andy outlined and can provide performance impact/etc., but it is good that we understand that we cannot provide a better justification for this feature at the moment unless someone is ready to share some new exploit technique with us. Best Regards, Elena.
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.