Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1612221 > unrolled thread
| Started by | Kees Cook <keescook@chromium.org> |
|---|---|
| First post | 2017-03-29 20:20 +0200 |
| Last post | 2017-03-29 21:20 +0200 |
| Articles | 20 on this page of 56 — 13 participants |
Back to article view | Back to linux.kernel
[RFC v2] Introduce rare_write() infrastructure Kees Cook <keescook@chromium.org> - 2017-03-29 20:20 +0200
[RFC v2][PATCH 10/11] gcc-plugins: Add constify plugin Kees Cook <keescook@chromium.org> - 2017-03-29 20:20 +0200
[RFC v2][PATCH 03/11] net: switch sock_diag handlers to rare_write() Kees Cook <keescook@chromium.org> - 2017-03-29 20:20 +0200
[RFC v2][PATCH 07/11] ARM: mm: set DOMAIN_WR_RARE for rodata Kees Cook <keescook@chromium.org> - 2017-03-29 20:20 +0200
[RFC v2][PATCH 01/11] Introduce rare_write() infrastructure Kees Cook <keescook@chromium.org> - 2017-03-29 20:20 +0200
Re: [RFC v2][PATCH 01/11] Introduce rare_write() infrastructure Kees Cook <keescook@chromium.org> - 2017-03-29 20:30 +0200
Re: [RFC v2][PATCH 01/11] Introduce rare_write() infrastructure Ho-Eun Ryu <hoeun.ryu@gmail.com> - 2017-03-30 09:50 +0200
Re: [RFC v2][PATCH 01/11] Introduce rare_write() infrastructure Kees Cook <keescook@chromium.org> - 2017-03-30 19:10 +0200
Re: [RFC v2][PATCH 01/11] Introduce rare_write() infrastructure Ho-Eun Ryu <hoeun.ryu@gmail.com> - 2017-04-07 10:20 +0200
Re: [RFC v2][PATCH 01/11] Introduce rare_write() infrastructure Kees Cook <keescook@chromium.org> - 2017-04-07 22:40 +0200
[RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Kees Cook <keescook@chromium.org> - 2017-03-29 20:20 +0200
Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Andy Lutomirski <luto@amacapital.net> - 2017-03-30 00:40 +0200
Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Kees Cook <keescook@chromium.org> - 2017-03-30 03:50 +0200
Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Andy Lutomirski <luto@kernel.org> - 2017-04-06 02:00 +0200
Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Kees Cook <keescook@chromium.org> - 2017-04-06 02:20 +0200
Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Andy Lutomirski <luto@amacapital.net> - 2017-04-06 18:00 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Mathias Krause <minipli@googlemail.com> - 2017-04-07 10:40 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Thomas Gleixner <tglx@linutronix.de> - 2017-04-07 11:50 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Mathias Krause <minipli@googlemail.com> - 2017-04-07 13:00 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Thomas Gleixner <tglx@linutronix.de> - 2017-04-07 15:20 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Mathias Krause <minipli@googlemail.com> - 2017-04-07 15:40 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Andy Lutomirski <luto@kernel.org> - 2017-04-07 18:20 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Mark Rutland <mark.rutland@arm.com> - 2017-04-07 18:30 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() "PaX Team" <pageexec@freemail.hu> - 2017-04-07 22:10 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Andy Lutomirski <luto@kernel.org> - 2017-04-08 07:00 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() "PaX Team" <pageexec@freemail.hu> - 2017-04-09 14:50 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Andy Lutomirski <luto@kernel.org> - 2017-04-10 02:20 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() "PaX Team" <pageexec@freemail.hu> - 2017-04-10 12:50 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Thomas Gleixner <tglx@linutronix.de> - 2017-04-07 22:50 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Kees Cook <keescook@chromium.org> - 2017-04-07 23:30 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Daniel Micay <danielmicay@gmail.com> - 2017-04-08 06:20 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Daniel Micay <danielmicay@gmail.com> - 2017-04-08 06:20 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Daniel Micay <danielmicay@gmail.com> - 2017-04-08 06:30 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Andy Lutomirski <luto@kernel.org> - 2017-04-08 07:10 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Daniel Micay <danielmicay@gmail.com> - 2017-04-08 09:40 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Andy Lutomirski <luto@kernel.org> - 2017-04-08 17:30 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Ingo Molnar <mingo@kernel.org> - 2017-04-09 13:00 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Mark Rutland <mark.rutland@arm.com> - 2017-04-10 12:30 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() "PaX Team" <pageexec@freemail.hu> - 2017-04-09 22:30 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Andy Lutomirski <luto@kernel.org> - 2017-04-10 02:40 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Thomas Gleixner <tglx@linutronix.de> - 2017-04-07 21:30 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Peter Zijlstra <peterz@infradead.org> - 2017-04-07 16:50 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Mark Rutland <mark.rutland@arm.com> - 2017-04-10 12:40 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() "PaX Team" <pageexec@freemail.hu> - 2017-04-07 22:40 +0200
Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Thomas Gleixner <tglx@linutronix.de> - 2017-04-10 10:30 +0200
Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() Peter Zijlstra <peterz@infradead.org> - 2017-04-07 11:40 +0200
[RFC v2][PATCH 09/11] list: add rare_write() list helpers Kees Cook <keescook@chromium.org> - 2017-03-29 20:20 +0200
[RFC v2][PATCH 05/11] ARM: mm: dump: Add domain to output Kees Cook <keescook@chromium.org> - 2017-03-29 20:20 +0200
[RFC v2][PATCH 11/11] cgroups: force all struct cftype const Kees Cook <keescook@chromium.org> - 2017-03-29 20:20 +0200
[RFC v2][PATCH 08/11] ARM: Implement __arch_rare_write_begin/end() Kees Cook <keescook@chromium.org> - 2017-03-29 20:20 +0200
Re: [RFC v2][PATCH 08/11] ARM: Implement __arch_rare_write_begin/end() Peter Zijlstra <peterz@infradead.org> - 2017-04-07 11:40 +0200
[RFC v2][PATCH 02/11] lkdtm: add test for rare_write() infrastructure Kees Cook <keescook@chromium.org> - 2017-03-29 20:20 +0200
Re: [kernel-hardening] [RFC v2][PATCH 02/11] lkdtm: add test for rare_write() infrastructure Ian Campbell <ijc@hellion.org.uk> - 2017-03-30 12:20 +0200
Re: [kernel-hardening] [RFC v2][PATCH 02/11] lkdtm: add test for rare_write() infrastructure Kees Cook <keescook@chromium.org> - 2017-03-30 18:20 +0200
Re: [RFC v2] Introduce rare_write() infrastructure Russell King - ARM Linux <linux@armlinux.org.uk> - 2017-03-29 21:10 +0200
Re: [RFC v2] Introduce rare_write() infrastructure Kees Cook <keescook@chromium.org> - 2017-03-29 21:20 +0200
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
| From | Mathias Krause <minipli@googlemail.com> |
|---|---|
| Date | 2017-04-07 15:40 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <ttChj-7G0-13@gated-at.bofh.it> |
| In reply to | #1618786 |
On 7 April 2017 at 15:14, Thomas Gleixner <tglx@linutronix.de> wrote: > On Fri, 7 Apr 2017, Mathias Krause wrote: >> On 7 April 2017 at 11:46, Thomas Gleixner <tglx@linutronix.de> wrote: >> > Whether protected by preempt_disable or local_irq_disable, to make that >> > work it needs CR0 handling in the exception entry/exit at the lowest >> > level. And that's just a nightmare maintainence wise as it's prone to be >> > broken over time. >> >> It seems to be working fine for more than a decade now in PaX. So it >> can't be such a big maintenance nightmare ;) > > I really do not care whether PaX wants to chase and verify that over and > over. I certainly don't want to take the chance to leak CR0.WP ever and I > very much care about extra stuff to check in the entry/exit path. Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP)) somewhere sensible should make those "leaks" visible fast -- and their exploitation impossible, i.e. fail hard. >> The "proper solution" seems to be much slower compared to just >> toggling CR0.WP (which is costly in itself, already) because of the >> TLB invalidation / synchronisation involved. > > Why the heck should we care about rare writes being performant? As soon as they stop being rare and people start extending the r/o protection to critical data structures accessed often. Then performance matters. >> > It's valid (at least on x86) to have a shadow map with the same page >> > attributes but write enabled. That does not require any fixups of CR0 and >> > just works. >> >> "Just works", sure -- but it's not as tightly focused as the PaX >> solution which is CPU local, while your proposed solution is globally >> visible. > > Making the world and some more writeable hardly qualifies as tightly > focussed. Making the mapping concept CPU local is not rocket science > either. The question is whethers it's worth the trouble. No, the question is if the value of the concept is well understood and if people can see what could be done with such a strong primitive. Apparently not... Cheers, Mathias
[toc] | [prev] | [next] | [standalone]
| From | Andy Lutomirski <luto@kernel.org> |
|---|---|
| Date | 2017-04-07 18:20 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <ttEMa-18X-23@gated-at.bofh.it> |
| In reply to | #1618802 |
On Fri, Apr 7, 2017 at 6:30 AM, Mathias Krause <minipli@googlemail.com> wrote: > On 7 April 2017 at 15:14, Thomas Gleixner <tglx@linutronix.de> wrote: >> On Fri, 7 Apr 2017, Mathias Krause wrote: >>> On 7 April 2017 at 11:46, Thomas Gleixner <tglx@linutronix.de> wrote: >>> > Whether protected by preempt_disable or local_irq_disable, to make that >>> > work it needs CR0 handling in the exception entry/exit at the lowest >>> > level. And that's just a nightmare maintainence wise as it's prone to be >>> > broken over time. >>> >>> It seems to be working fine for more than a decade now in PaX. So it >>> can't be such a big maintenance nightmare ;) >> >> I really do not care whether PaX wants to chase and verify that over and >> over. I certainly don't want to take the chance to leak CR0.WP ever and I >> very much care about extra stuff to check in the entry/exit path. > > Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP)) > somewhere sensible should make those "leaks" visible fast -- and their > exploitation impossible, i.e. fail hard. The leaks surely exist and now we'll just add an exploitable BUG. >>> > It's valid (at least on x86) to have a shadow map with the same page >>> > attributes but write enabled. That does not require any fixups of CR0 and >>> > just works. >>> >>> "Just works", sure -- but it's not as tightly focused as the PaX >>> solution which is CPU local, while your proposed solution is globally >>> visible. >> >> Making the world and some more writeable hardly qualifies as tightly >> focussed. Making the mapping concept CPU local is not rocket science >> either. The question is whethers it's worth the trouble. > > No, the question is if the value of the concept is well understood and > if people can see what could be done with such a strong primitive. > Apparently not... I think we're approaching this all wrong, actually. The fact that x86 has this CR0.WP thing is arguably a historical accident, and the fact that PaX uses it doesn't mean that PaX is doing it the best way for upstream Linux. Why don't we start at the other end and do a generic non-arch-specific implementation: set up an mm_struct that contains an RW alias of the relevant parts of rodata and use use_mm to access it. (That is, get_fs() to back up the old fs, set_fs(USER_DS), use_mm(&rare_write_mm), do the write using copy_to_user, undo everything.) Then someone who cares about performance can benchmark the CR0.WP approach against it and try to argue that it's a good idea. This benchmark should wait until I'm done with my PCID work, because PCID is going to make use_mm() a whole heck of a lot faster. --Andy
[toc] | [prev] | [next] | [standalone]
| From | Mark Rutland <mark.rutland@arm.com> |
|---|---|
| Date | 2017-04-07 18:30 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <ttEVP-1dU-7@gated-at.bofh.it> |
| In reply to | #1618945 |
On Fri, Apr 07, 2017 at 09:14:29AM -0700, Andy Lutomirski wrote: > I think we're approaching this all wrong, actually. The fact that x86 > has this CR0.WP thing is arguably a historical accident, and the fact > that PaX uses it doesn't mean that PaX is doing it the best way for > upstream Linux. > > Why don't we start at the other end and do a generic non-arch-specific > implementation: set up an mm_struct that contains an RW alias of the > relevant parts of rodata and use use_mm to access it. (That is, > get_fs() to back up the old fs, set_fs(USER_DS), > use_mm(&rare_write_mm), do the write using copy_to_user, undo > everything.) FWIW, I completely agree with this approach. That's largely the approach arm64 would have to take regardless (as per Hoeun's patches), and having a consistent common implementation would be desireable. There are a couple of other complications to handle (e.g. a perf interrupt coming in and trying to read from the mapping), but I think we can handle that generically. Thanks, Mark.
[toc] | [prev] | [next] | [standalone]
| From | "PaX Team" <pageexec@freemail.hu> |
|---|---|
| Date | 2017-04-07 22:10 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <ttImK-3TM-3@gated-at.bofh.it> |
| In reply to | #1618945 |
On 7 Apr 2017 at 9:14, Andy Lutomirski wrote: > On Fri, Apr 7, 2017 at 6:30 AM, Mathias Krause <minipli@googlemail.com> wrote: > > On 7 April 2017 at 15:14, Thomas Gleixner <tglx@linutronix.de> wrote: > >> On Fri, 7 Apr 2017, Mathias Krause wrote: > > Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP)) > > somewhere sensible should make those "leaks" visible fast -- and their > > exploitation impossible, i.e. fail hard. > > The leaks surely exist and now we'll just add an exploitable BUG. can you please share those leaks that 'surely exist' and CC oss-security while at it? > I think we're approaching this all wrong, actually. The fact that x86 > has this CR0.WP thing is arguably a historical accident, and the fact > that PaX uses it doesn't mean that PaX is doing it the best way for > upstream Linux. > > Why don't we start at the other end and do a generic non-arch-specific > implementation: set up an mm_struct that contains an RW alias of the > relevant parts of rodata and use use_mm to access it. (That is, > get_fs() to back up the old fs, set_fs(USER_DS), > use_mm(&rare_write_mm), do the write using copy_to_user, undo > everything.) > > Then someone who cares about performance can benchmark the CR0.WP > approach against it and try to argue that it's a good idea. This > benchmark should wait until I'm done with my PCID work, because PCID > is going to make use_mm() a whole heck of a lot faster. in my measurements switching PCID is hovers around 230 cycles for snb-ivb and 200-220 for hsw-skl whereas cr0 writes are around 230-240 cycles. there's of course a whole lot more impact for switching address spaces so it'll never be fast enough to beat cr0.wp.
[toc] | [prev] | [next] | [standalone]
| From | Andy Lutomirski <luto@kernel.org> |
|---|---|
| Date | 2017-04-08 07:00 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <ttQDE-FB-11@gated-at.bofh.it> |
| In reply to | #1619076 |
On Fri, Apr 7, 2017 at 12:58 PM, PaX Team <pageexec@freemail.hu> wrote: > On 7 Apr 2017 at 9:14, Andy Lutomirski wrote: > >> On Fri, Apr 7, 2017 at 6:30 AM, Mathias Krause <minipli@googlemail.com> wrote: >> > On 7 April 2017 at 15:14, Thomas Gleixner <tglx@linutronix.de> wrote: >> >> On Fri, 7 Apr 2017, Mathias Krause wrote: >> > Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP)) >> > somewhere sensible should make those "leaks" visible fast -- and their >> > exploitation impossible, i.e. fail hard. >> >> The leaks surely exist and now we'll just add an exploitable BUG. > > can you please share those leaks that 'surely exist' and CC oss-security > while at it? I meant in the patchset here, not in grsecurity. grsecurity (on very, very brief inspection) seems to read cr0 and fix it up in pax_enter_kernel. >> >> Then someone who cares about performance can benchmark the CR0.WP >> approach against it and try to argue that it's a good idea. This >> benchmark should wait until I'm done with my PCID work, because PCID >> is going to make use_mm() a whole heck of a lot faster. > > in my measurements switching PCID is hovers around 230 cycles for snb-ivb > and 200-220 for hsw-skl whereas cr0 writes are around 230-240 cycles. there's > of course a whole lot more impact for switching address spaces so it'll never > be fast enough to beat cr0.wp. > If I'm reading this right, you're saying that a non-flushing CR3 write is about the same cost as a CR0.WP write. If so, then why should CR0 be preferred over the (arch-neutral) CR3 approach? And why would switching address spaces obviously be much slower? There'll be a very small number of TLB fills needed for the actual protected access. --Andy
[toc] | [prev] | [next] | [standalone]
| From | "PaX Team" <pageexec@freemail.hu> |
|---|---|
| Date | 2017-04-09 14:50 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <tuks1-2PA-3@gated-at.bofh.it> |
| In reply to | #1619225 |
On 7 Apr 2017 at 21:58, Andy Lutomirski wrote: > On Fri, Apr 7, 2017 at 12:58 PM, PaX Team <pageexec@freemail.hu> wrote: > > On 7 Apr 2017 at 9:14, Andy Lutomirski wrote: > >> Then someone who cares about performance can benchmark the CR0.WP > >> approach against it and try to argue that it's a good idea. This > >> benchmark should wait until I'm done with my PCID work, because PCID > >> is going to make use_mm() a whole heck of a lot faster. > > > > in my measurements switching PCID is hovers around 230 cycles for snb-ivb > > and 200-220 for hsw-skl whereas cr0 writes are around 230-240 cycles. there's > > of course a whole lot more impact for switching address spaces so it'll never > > be fast enough to beat cr0.wp. > > > > If I'm reading this right, you're saying that a non-flushing CR3 write > is about the same cost as a CR0.WP write. If so, then why should CR0 > be preferred over the (arch-neutral) CR3 approach? cr3 (page table switching) isn't arch neutral at all ;). you probably meant the higher level primitives except they're not enough to implement the scheme as discussed before since the enter/exit paths are very much arch dependent. on x86 the cost of the pax_open/close_kernel primitives comes from the cr0 writes and nothing else, use_mm suffers not only from the cr3 writes but also locking/atomic ops and cr4 writes on its path and the inevitable TLB entry costs. and if cpu vendors cared enough, they could make toggling cr0.wp a fast path in the microcode and reduce its overhead by an order of magnitude. > And why would switching address spaces obviously be much slower? > There'll be a very small number of TLB fills needed for the actual > protected access. you'll be duplicating TLB entries in the alternative PCID for both code and data, where they will accumulate (=take room away from the normal PCID and expose unwanted memory for access) unless you also flush them when switching back (which then will cost even more cycles). also i'm not sure that processors implement all the 12 PCID bits so depending on how many PCIDs you plan to use, you could be causing even more unnecessary TLB replacements.
[toc] | [prev] | [next] | [standalone]
| From | Andy Lutomirski <luto@kernel.org> |
|---|---|
| Date | 2017-04-10 02:20 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <tuvdL-1Fy-7@gated-at.bofh.it> |
| In reply to | #1619490 |
On Sun, Apr 9, 2017 at 5:47 AM, PaX Team <pageexec@freemail.hu> wrote: > On 7 Apr 2017 at 21:58, Andy Lutomirski wrote: > >> On Fri, Apr 7, 2017 at 12:58 PM, PaX Team <pageexec@freemail.hu> wrote: >> > On 7 Apr 2017 at 9:14, Andy Lutomirski wrote: >> >> Then someone who cares about performance can benchmark the CR0.WP >> >> approach against it and try to argue that it's a good idea. This >> >> benchmark should wait until I'm done with my PCID work, because PCID >> >> is going to make use_mm() a whole heck of a lot faster. >> > >> > in my measurements switching PCID is hovers around 230 cycles for snb-ivb >> > and 200-220 for hsw-skl whereas cr0 writes are around 230-240 cycles. there's >> > of course a whole lot more impact for switching address spaces so it'll never >> > be fast enough to beat cr0.wp. >> > >> >> If I'm reading this right, you're saying that a non-flushing CR3 write >> is about the same cost as a CR0.WP write. If so, then why should CR0 >> be preferred over the (arch-neutral) CR3 approach? > > cr3 (page table switching) isn't arch neutral at all ;). you probably meant > the higher level primitives except they're not enough to implement the scheme > as discussed before since the enter/exit paths are very much arch dependent. Yes. > > on x86 the cost of the pax_open/close_kernel primitives comes from the cr0 > writes and nothing else, use_mm suffers not only from the cr3 writes but > also locking/atomic ops and cr4 writes on its path and the inevitable TLB > entry costs. and if cpu vendors cared enough, they could make toggling cr0.wp > a fast path in the microcode and reduce its overhead by an order of magnitude. > If the CR4 writes happen in for this use case, that's a bug. >> And why would switching address spaces obviously be much slower? >> There'll be a very small number of TLB fills needed for the actual >> protected access. > > you'll be duplicating TLB entries in the alternative PCID for both code > and data, where they will accumulate (=take room away from the normal PCID > and expose unwanted memory for access) unless you also flush them when > switching back (which then will cost even more cycles). also i'm not sure > that processors implement all the 12 PCID bits so depending on how many PCIDs > you plan to use, you could be causing even more unnecessary TLB replacements. > Unless the CPU is rather dumber than I expect, the only duplicated entries should be for the writable aliases of pages that are written. The rest of the pages are global and should be shared for all PCIDs. --Andy
[toc] | [prev] | [next] | [standalone]
| From | "PaX Team" <pageexec@freemail.hu> |
|---|---|
| Date | 2017-04-10 12:50 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <tuF3s-7X5-7@gated-at.bofh.it> |
| In reply to | #1619575 |
On 9 Apr 2017 at 17:10, Andy Lutomirski wrote: > On Sun, Apr 9, 2017 at 5:47 AM, PaX Team <pageexec@freemail.hu> wrote: > > on x86 the cost of the pax_open/close_kernel primitives comes from the cr0 > > writes and nothing else, use_mm suffers not only from the cr3 writes but > > also locking/atomic ops and cr4 writes on its path and the inevitable TLB > > entry costs. and if cpu vendors cared enough, they could make toggling cr0.wp > > a fast path in the microcode and reduce its overhead by an order of magnitude. > > > > If the CR4 writes happen in for this use case, that's a bug. that depends on how you plan to handle perf/rdpmc users and how many alternative mm structs you plan to manage (one global, one per cpu, one per mm struct, etc). > > you'll be duplicating TLB entries in the alternative PCID for both code > > and data, where they will accumulate (=take room away from the normal PCID > > and expose unwanted memory for access) unless you also flush them when > > switching back (which then will cost even more cycles). also i'm not sure > > that processors implement all the 12 PCID bits so depending on how many PCIDs > > you plan to use, you could be causing even more unnecessary TLB replacements. > > > > Unless the CPU is rather dumber than I expect, the only duplicated > entries should be for the writable aliases of pages that are written. > The rest of the pages are global and should be shared for all PCIDs. well, 4.10.2.4 has language like this (4.10.3.2 implies similar): A logical processor may use a global TLB entry to translate a linear address, even if the TLB entry is associated with a PCID different from the current PCID. that to me says that global page entries are associated with a PCID and may (not) be used while in another PCID. in Intel-speak that's not 'dumb' but "tricks up our sleeve that we don't really want to tell you about in detail, except perhaps under a NDA".
[toc] | [prev] | [next] | [standalone]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2017-04-07 22:50 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <ttIZr-4bj-5@gated-at.bofh.it> |
| In reply to | #1618945 |
On Fri, 7 Apr 2017, Andy Lutomirski wrote: > On Fri, Apr 7, 2017 at 6:30 AM, Mathias Krause <minipli@googlemail.com> wrote: > > On 7 April 2017 at 15:14, Thomas Gleixner <tglx@linutronix.de> wrote: > >> I really do not care whether PaX wants to chase and verify that over and > >> over. I certainly don't want to take the chance to leak CR0.WP ever and I > >> very much care about extra stuff to check in the entry/exit path. > > > > Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP)) > > somewhere sensible should make those "leaks" visible fast -- and their > > exploitation impossible, i.e. fail hard. > > The leaks surely exist and now we'll just add an exploitable BUG. :) > I think we're approaching this all wrong, actually. The fact that x86 > has this CR0.WP thing is arguably a historical accident, and the fact > that PaX uses it doesn't mean that PaX is doing it the best way for > upstream Linux. As I said before. It should be fused to 1. > Why don't we start at the other end and do a generic non-arch-specific > implementation: set up an mm_struct that contains an RW alias of the > relevant parts of rodata and use use_mm to access it. (That is, > get_fs() to back up the old fs, set_fs(USER_DS), > use_mm(&rare_write_mm), do the write using copy_to_user, undo > everything.) That works too, though I'm not sure that it's more efficient than temporarily creating and undoing a single cpu local alias mapping similar to the kmap_atomic mechanism in the highmem case. Aside of that the alias mapping requires a full PGDIR entry unless you want to get into the mess of keeping yet another identity mapping up to date. Thanks, tglx
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@chromium.org> |
|---|---|
| Date | 2017-04-07 23:30 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <ttJCa-4GN-9@gated-at.bofh.it> |
| In reply to | #1619091 |
On Fri, Apr 7, 2017 at 1:44 PM, Thomas Gleixner <tglx@linutronix.de> wrote: > On Fri, 7 Apr 2017, Andy Lutomirski wrote: >> On Fri, Apr 7, 2017 at 6:30 AM, Mathias Krause <minipli@googlemail.com> wrote: >> > On 7 April 2017 at 15:14, Thomas Gleixner <tglx@linutronix.de> wrote: >> >> I really do not care whether PaX wants to chase and verify that over and >> >> over. I certainly don't want to take the chance to leak CR0.WP ever and I >> >> very much care about extra stuff to check in the entry/exit path. >> > >> > Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP)) >> > somewhere sensible should make those "leaks" visible fast -- and their >> > exploitation impossible, i.e. fail hard. >> >> The leaks surely exist and now we'll just add an exploitable BUG. > > :) > >> I think we're approaching this all wrong, actually. The fact that x86 >> has this CR0.WP thing is arguably a historical accident, and the fact >> that PaX uses it doesn't mean that PaX is doing it the best way for >> upstream Linux. > > As I said before. It should be fused to 1. > >> Why don't we start at the other end and do a generic non-arch-specific >> implementation: set up an mm_struct that contains an RW alias of the >> relevant parts of rodata and use use_mm to access it. (That is, >> get_fs() to back up the old fs, set_fs(USER_DS), >> use_mm(&rare_write_mm), do the write using copy_to_user, undo >> everything.) > > That works too, though I'm not sure that it's more efficient than > temporarily creating and undoing a single cpu local alias mapping similar > to the kmap_atomic mechanism in the highmem case. > > Aside of that the alias mapping requires a full PGDIR entry unless you want > to get into the mess of keeping yet another identity mapping up to date. I probably chose the wrong name for this feature (write rarely). That's _usually_ true, but "sensitive_write()" was getting rather long. The things that we need to protect with this are certainly stuff that doesn't get much writing, but some things are just plain sensitive (like page tables) and we should still try to be as fast as possible with them. I'll try to include a third example in the next posting of the series that makes this more obvious. I'm all for a general case for the infrastructure (as Andy and Mark has mentioned), but I don't want to get into the situation where people start refusing to use it because it's "too slow" (for example, see refcount_t vs net-dev right now). -Kees -- Kees Cook Pixel Security
[toc] | [prev] | [next] | [standalone]
| From | Daniel Micay <danielmicay@gmail.com> |
|---|---|
| Date | 2017-04-08 06:20 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <ttQ0V-qd-1@gated-at.bofh.it> |
| In reply to | #1619126 |
> I probably chose the wrong name for this feature (write rarely). > That's _usually_ true, but "sensitive_write()" was getting rather > long. The things that we need to protect with this are certainly stuff > that doesn't get much writing, but some things are just plain > sensitive (like page tables) and we should still try to be as fast as > possible with them. Not too late to rename it. Scoped write? I think it makes change to use a different API than PaX for portability too, but not a different x86 implementation. It's quite important to limit the writes to the calling thread and it needs to perform well to be introduced widely. > I'm all for a general case for the infrastructure (as Andy and Mark > has mentioned), but I don't want to get into the situation where > people start refusing to use it because it's "too slow" (for example, > see refcount_t vs net-dev right now). Meanwhile, the PaX implementation has improved to avoid the issues that were brought up while only introducing a single always-predicted (due to code placement) branch on the overflow flag. That seems to have gone unnoticed upstream, where there's now a much slower implementation that's not more secure, and is blocked from introduction in areas where it's most needed based on the performance. Not to mention that it's opt-in... which is never going to work.
[toc] | [prev] | [next] | [standalone]
| From | Daniel Micay <danielmicay@gmail.com> |
|---|---|
| Date | 2017-04-08 06:20 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <ttQ0V-qd-3@gated-at.bofh.it> |
| In reply to | #1619218 |
> Not too late to rename it. Scoped write? I think it makes change to s/change/sense/
[toc] | [prev] | [next] | [standalone]
| From | Daniel Micay <danielmicay@gmail.com> |
|---|---|
| Date | 2017-04-08 06:30 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <ttQaB-wo-1@gated-at.bofh.it> |
| In reply to | #1618945 |
>> Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP)) >> somewhere sensible should make those "leaks" visible fast -- and their >> exploitation impossible, i.e. fail hard. > > The leaks surely exist and now we'll just add an exploitable BUG. That didn't seem to matter for landing a rewrite of KSTACKOVERFLOW with a bunch of *known* DoS bugs dealt with in grsecurity and those were known issues that were unfixed for no apparent reason other than keeping egos intact. It looks like there are still some left... In that case, there also wasn't a security/performance advantage.
[toc] | [prev] | [next] | [standalone]
| From | Andy Lutomirski <luto@kernel.org> |
|---|---|
| Date | 2017-04-08 07:10 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <ttQNj-YJ-1@gated-at.bofh.it> |
| In reply to | #1619220 |
On Fri, Apr 7, 2017 at 9:21 PM, Daniel Micay <danielmicay@gmail.com> wrote: >>> Fair enough. However, placing a BUG_ON(!(read_cr0() & X86_CR0_WP)) >>> somewhere sensible should make those "leaks" visible fast -- and their >>> exploitation impossible, i.e. fail hard. >> >> The leaks surely exist and now we'll just add an exploitable BUG. > > That didn't seem to matter for landing a rewrite of KSTACKOVERFLOW > with a bunch of *known* DoS bugs dealt with in grsecurity and those > were known issues that were unfixed for no apparent reason other than > keeping egos intact. It looks like there are still some left... > > In that case, there also wasn't a security/performance advantage. This is wildly off topic, but I think it's worth answering anyway because there's an important point here: grsecurity and PaX are great projects. They have a lot of good ideas, and they're put together quite nicely. The upstream kernel should *not* do things differently from they way they are in grsecurity/PaX just because it wants to be different. Conversely, the upstream kernel should not do things the same way as PaX just to be more like PaX. Keep in mind that the upstream kernel and grsecurity/PaX operate under different constraints. The upstream kernel tries to keep itself clean and to make tree-wide updates rather that keeping compatibility stuff around. PaX and grsecurity presumably want to retain some degree of simplicity when porting to newer upstream versions. In the context of virtually mapped stacks / KSTACKOVERFLOW, this naturally leads to different solutions. The upstream kernel had a bunch of buggy drivers that played badly with virtually mapped stacks. grsecurity sensibly went for the approach where the buggy drivers kept working. The upstream kernel went for the approach of fixing the drivers rather than keeping a compatibility workaround. Different constraints, different solutions. The point being that, if someone sends a patch to the x86 entry code that's justified by "be like PaX" or by "be different than PaX", that's not okay. It needs a real justification that stands on its own. In the case of rare writes or pax_open_kernel [1] or whatever we want to call it, CR3 would work without arch-specific code, and CR0 would not. That's an argument for CR3 that would need to be countered by something. (Sure, avoiding leaks either way might need arch changes. OTOH, a *randomized* CR3-based approach might not have as much of a leak issue to begin with.) [1] Contrary to popular belief, I don't sit around reading grsecurity code or config options, so I really don't know what this thing is called.
[toc] | [prev] | [next] | [standalone]
| From | Daniel Micay <danielmicay@gmail.com> |
|---|---|
| Date | 2017-04-08 09:40 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <ttT8t-2kE-5@gated-at.bofh.it> |
| In reply to | #1619228 |
> grsecurity and PaX are great projects. They have a lot of good ideas, > and they're put together quite nicely. The upstream kernel should > *not* do things differently from they way they are in grsecurity/PaX > just because it wants to be different. Conversely, the upstream > kernel should not do things the same way as PaX just to be more like > PaX. > > Keep in mind that the upstream kernel and grsecurity/PaX operate under > different constraints. The upstream kernel tries to keep itself clean > and to make tree-wide updates rather that keeping compatibility stuff > around. PaX and grsecurity presumably want to retain some degree of > simplicity when porting to newer upstream versions. > > In the context of virtually mapped stacks / KSTACKOVERFLOW, this > naturally leads to different solutions. The upstream kernel had a > bunch of buggy drivers that played badly with virtually mapped stacks. > grsecurity sensibly went for the approach where the buggy drivers kept > working. The upstream kernel went for the approach of fixing the > drivers rather than keeping a compatibility workaround. Different > constraints, different solutions. Sure, but nothing is currently landed right now and the PaX implementation is a known quantity with a lot of testing. The submitted code is aimed at rare writes to globals, but this feature is more than that and design decisions shouldn't be based on just the short term. Kees is sensibly landing features by submitting them a little bit at a time, but a negative side effect of that is too much focus on just the initial proposed usage. As a downstream that's going to be making heavy use of mainline security features as a base due to PaX and grsecurity becoming commercial only private patches (*because* of upstream and the companies involved), I hope things go in the right direction i.e. not weaker/slower implementations than PaX. For example, while USERCOPY isn't entirely landed upstream (missing slab whitelisting and user offset/size), it's the base for the full feature and is going to get more testing. On the other hand, refcount_t and the slab/page sanitization work is 100% useless if you're willing to incorporate the changes to do it without needless performance loss and complexity. PAN emulation on 64-bit ARM was fresh ground while on ARMv7 a weaker implementation was used for no better reason than clashing egos. The upstream virtual mapped stacks will probably be perfectly good, but I just find it to be such a waste of time and effort to reinvent it and retread the same ground in terms of finding the bugs. I actually care a lot more about 64-bit ARM support than I do x86, but using a portable API for pax_open_kernel (for the simple uses at least) is separate from choosing the underlying implementation. There might not be a great way to do it on the architectures I care about but that doesn't need to hinder x86. It's really not that much code... A weaker/slower implementation for x86 also encourages the same elsewhere. > In the case of rare writes or pax_open_kernel [1] or whatever we want > to call it, CR3 would work without arch-specific code, and CR0 would > not. That's an argument for CR3 that would need to be countered by > something. (Sure, avoiding leaks either way might need arch changes. > OTOH, a *randomized* CR3-based approach might not have as much of a > leak issue to begin with.) By randomized do you mean just ASLR? Even if the window of opportunity to exploit it is small, it's really not the same and this has a lot more use than just rare writes to small global variables. I wouldn't consider stack ASLR to be a replacement for making them readable/writable only by the current thread either (required for race-free return CFI on x86, at least without not using actual returns). > [1] Contrary to popular belief, I don't sit around reading grsecurity > code or config options, so I really don't know what this thing is > called. Lots of the features aren't actually named. Maybe this could be considered part of KERNEXEC but I don't think it is.
[toc] | [prev] | [next] | [standalone]
| From | Andy Lutomirski <luto@kernel.org> |
|---|---|
| Date | 2017-04-08 17:30 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <tu0tk-6YE-13@gated-at.bofh.it> |
| In reply to | #1619240 |
On Sat, Apr 8, 2017 at 12:33 AM, Daniel Micay <danielmicay@gmail.com> wrote: > The > submitted code is aimed at rare writes to globals, but this feature is > more than that and design decisions shouldn't be based on just the > short term. Then, if you disagree with a proposed design, *explain why* in a standalone manner. Say what future uses a different design would have. > I actually care a lot more about 64-bit ARM support than I do x86, but > using a portable API for pax_open_kernel (for the simple uses at > least) is separate from choosing the underlying implementation. There > might not be a great way to do it on the architectures I care about > but that doesn't need to hinder x86. It's really not that much code... > A weaker/slower implementation for x86 also encourages the same > elsewhere. No one has explained how CR0.WP is weaker or slower than my proposal. Here's what I'm proposing: At boot, choose a random address A. Create an mm_struct that has a single VMA starting at A that represents the kernel's rarely-written section. Compute O = (A - VA of rarely-written section). To do a rare write, use_mm() the mm, write to (VA + O), then unuse_mm(). This should work on any arch that has an MMU that allows this type of aliasing and that doesn't have PA-based protections on the rarely-written section. It'll be considerably slower than CR0.WP on a current x86 kernel, but, with PCID landed, it shouldn't be much slower. It has the added benefit that writes to non-rare-write data using the rare-write primitive will fail. --Andy
[toc] | [prev] | [next] | [standalone]
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2017-04-09 13:00 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <tuiJA-1J6-9@gated-at.bofh.it> |
| In reply to | #1619310 |
* Andy Lutomirski <luto@kernel.org> wrote: > On Sat, Apr 8, 2017 at 12:33 AM, Daniel Micay <danielmicay@gmail.com> wrote: > > The > > submitted code is aimed at rare writes to globals, but this feature is > > more than that and design decisions shouldn't be based on just the > > short term. > > Then, if you disagree with a proposed design, *explain why* in a > standalone manner. Say what future uses a different design would > have. > > > I actually care a lot more about 64-bit ARM support than I do x86, but > > using a portable API for pax_open_kernel (for the simple uses at > > least) is separate from choosing the underlying implementation. There > > might not be a great way to do it on the architectures I care about > > but that doesn't need to hinder x86. It's really not that much code... > > A weaker/slower implementation for x86 also encourages the same > > elsewhere. > > No one has explained how CR0.WP is weaker or slower than my proposal. > Here's what I'm proposing: > > At boot, choose a random address A. Create an mm_struct that has a > single VMA starting at A that represents the kernel's rarely-written > section. Compute O = (A - VA of rarely-written section). To do a > rare write, use_mm() the mm, write to (VA + O), then unuse_mm(). BTW., note that this is basically a pagetable based protection key variant. > It'll be considerably slower than CR0.WP on a current x86 kernel, but, with PCID > landed, it shouldn't be much slower. It has the added benefit that writes to > non-rare-write data using the rare-write primitive will fail. ... which is a security advantage of the use_mm() based design you suggest. Thanks, Ingo
[toc] | [prev] | [next] | [standalone]
| From | Mark Rutland <mark.rutland@arm.com> |
|---|---|
| Date | 2017-04-10 12:30 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <tuEK5-7QB-13@gated-at.bofh.it> |
| In reply to | #1619310 |
On Sat, Apr 08, 2017 at 08:20:03AM -0700, Andy Lutomirski wrote: > On Sat, Apr 8, 2017 at 12:33 AM, Daniel Micay <danielmicay@gmail.com> wrote: > > The > > submitted code is aimed at rare writes to globals, but this feature is > > more than that and design decisions shouldn't be based on just the > > short term. > > Then, if you disagree with a proposed design, *explain why* in a > standalone manner. Say what future uses a different design would > have. > > > I actually care a lot more about 64-bit ARM support than I do x86, but > > using a portable API for pax_open_kernel (for the simple uses at > > least) is separate from choosing the underlying implementation. There > > might not be a great way to do it on the architectures I care about > > but that doesn't need to hinder x86. It's really not that much code... > > A weaker/slower implementation for x86 also encourages the same > > elsewhere. > > No one has explained how CR0.WP is weaker or slower than my proposal. > Here's what I'm proposing: > > At boot, choose a random address A. Create an mm_struct that has a > single VMA starting at A that represents the kernel's rarely-written > section. Compute O = (A - VA of rarely-written section). To do a > rare write, use_mm() the mm, write to (VA + O), then unuse_mm(). > > This should work on any arch that has an MMU that allows this type of > aliasing and that doesn't have PA-based protections on the > rarely-written section. Modulo randomization, that sounds exactly like what I had envisaged [1], so that makes sense to me. Thanks, Mark. [1] http://www.openwall.com/lists/kernel-hardening/2016/11/18/3
[toc] | [prev] | [next] | [standalone]
| From | "PaX Team" <pageexec@freemail.hu> |
|---|---|
| Date | 2017-04-09 22:30 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <turDb-7Lg-5@gated-at.bofh.it> |
| In reply to | #1619228 |
On 7 Apr 2017 at 22:07, Andy Lutomirski wrote:
> grsecurity and PaX are great projects. They have a lot of good ideas,
> and they're put together quite nicely. The upstream kernel should
> *not* do things differently from they way they are in grsecurity/PaX
> just because it wants to be different. Conversely, the upstream
> kernel should not do things the same way as PaX just to be more like
> PaX.
so weit so gut.
> Keep in mind that the upstream kernel and grsecurity/PaX operate under
> different constraints. The upstream kernel tries to keep itself clean
so do we.
> and to make tree-wide updates rather that keeping compatibility stuff
> around.
so do we (e.g., fptr fixes for RAP, non-refcount atomic users, etc).
> PaX and grsecurity presumably want to retain some degree of
> simplicity when porting to newer upstream versions.
s/simplicity/minimality/ as the code itself can be complex but that'll be
of the minimal complexity we can come up with.
> In the context of virtually mapped stacks / KSTACKOVERFLOW, this
> naturally leads to different solutions. The upstream kernel had a
> bunch of buggy drivers that played badly with virtually mapped stacks.
> grsecurity sensibly went for the approach where the buggy drivers kept
> working. The upstream kernel went for the approach of fixing the
> drivers rather than keeping a compatibility workaround. Different
> constraints, different solutions.
except that's not what happened at all. spender's first version did just
a vmalloc for the kstack like the totally NIH'd version upstream does
now. while we always anticipated buggy dma users and thus had code that
would detect them so that we could fix them, we quickly figured that the
upstream kernel wasn't quite up to snuff as we had assumed and faced with
the amount of buggy code, we went for the current vmap approach which
kept users' systems working instead of breaking them.
you're trying to imply that upstream fixed the drivers but as the facts
show, that's not true. you simply unleashed your code on the world and
hoped(?) that enough suckers would try it out during the -rc window. as
we all know several releases and almost a year later, that was a losing
bet as you still keep fixing those drivers (and something tells me that
we haven't seen the end of it). this is simply irresponsible engineering
for no technical reason.
> In the case of rare writes or pax_open_kernel [1] or whatever we want
> to call it, CR3 would work without arch-specific code, and CR0 would
> not. That's an argument for CR3 that would need to be countered by
> something. (Sure, avoiding leaks either way might need arch changes.
> OTOH, a *randomized* CR3-based approach might not have as much of a
> leak issue to begin with.)
i have yet to see anyone explain what they mean by 'leak' here but if it
is what i think it is then the arch specific entry/exit changes are not
optional but mandatory. see below for randomization.
[merging in your other mail as it's the same topic]
> No one has explained how CR0.WP is weaker or slower than my proposal.
you misunderstood, Daniel was talking about your use_mm approach.
> Here's what I'm proposing:
>
> At boot, choose a random address A.
what is the threat that a random address defends against?
> Create an mm_struct that has a
> single VMA starting at A that represents the kernel's rarely-written
> section. Compute O = (A - VA of rarely-written section). To do a
> rare write, use_mm() the mm, write to (VA + O), then unuse_mm().
the problem is that the amount of __read_only data extends beyond vmlinux,
i.e., this approach won't scale. another problem is that it can't be used
inside use_mm and switch_mm themselves (no read-only task structs or percpu
pgd for you ;) and probably several other contexts.
last but not least, use_mm says this about itself:
(Note: this routine is intended to be called only
from a kernel thread context)
so using it will need some engineering (or the comment be fixed).
> This should work on any arch that has an MMU that allows this type of
> aliasing and that doesn't have PA-based protections on the rarely-written
> section.
you didn't address the arch-specific changes needed in the enter/exit paths.
> It'll be considerably slower than CR0.WP on a current x86 kernel, but,
> with PCID landed, it shouldn't be much slower.
based on my experience with UDEREF on amd64, unfortunately PCID isn't all
it's cracked up to be (IIRC, it maybe halved the UDEREF overhead instead of
basically eliminating it as i had anticipated, and that was on snb, ivb and
later do even worse).
> It has the added benefit that writes to non-rare-write data using the
> rare-write primitive will fail.
what is the threat model you're assuming for this feature? based on what i
have for PaX (arbitrary read/write access exploited for data-only attacks),
the above makes no sense to me...
[toc] | [prev] | [next] | [standalone]
| From | Andy Lutomirski <luto@kernel.org> |
|---|---|
| Date | 2017-04-10 02:40 +0200 |
| Subject | Re: [kernel-hardening] Re: [RFC v2][PATCH 04/11] x86: Implement __arch_rare_write_begin/unmap() |
| Message-ID | <tuvx7-1Nh-5@gated-at.bofh.it> |
| In reply to | #1619546 |
On Sun, Apr 9, 2017 at 1:24 PM, PaX Team <pageexec@freemail.hu> wrote: > >> In the context of virtually mapped stacks / KSTACKOVERFLOW, this >> naturally leads to different solutions. The upstream kernel had a >> bunch of buggy drivers that played badly with virtually mapped stacks. >> grsecurity sensibly went for the approach where the buggy drivers kept >> working. The upstream kernel went for the approach of fixing the >> drivers rather than keeping a compatibility workaround. Different >> constraints, different solutions. > > except that's not what happened at all. spender's first version did just > a vmalloc for the kstack like the totally NIH'd version upstream does > now. while we always anticipated buggy dma users and thus had code that > would detect them so that we could fix them, we quickly figured that the > upstream kernel wasn't quite up to snuff as we had assumed and faced with > the amount of buggy code, we went for the current vmap approach which > kept users' systems working instead of breaking them. > > you're trying to imply that upstream fixed the drivers but as the facts > show, that's not true. you simply unleashed your code on the world and > hoped(?) that enough suckers would try it out during the -rc window. as > we all know several releases and almost a year later, that was a losing > bet as you still keep fixing those drivers (and something tells me that > we haven't seen the end of it). this is simply irresponsible engineering > for no technical reason. I consider breaking buggy drivers (in a way that they either generally work okay or that they break with a nice OOPS depending on config) to be better than having a special case in what's supposed to be a fast path to keep them working. I did consider forcing the relevant debug options on for a while just to help shake these bugs out the woodwork faster. > >> In the case of rare writes or pax_open_kernel [1] or whatever we want >> to call it, CR3 would work without arch-specific code, and CR0 would >> not. That's an argument for CR3 that would need to be countered by >> something. (Sure, avoiding leaks either way might need arch changes. >> OTOH, a *randomized* CR3-based approach might not have as much of a >> leak issue to begin with.) > > i have yet to see anyone explain what they mean by 'leak' here but if it > is what i think it is then the arch specific entry/exit changes are not > optional but mandatory. see below for randomization. By "leak" I mean that a bug or exploit causes unintended code to run with CR0.WP or a special CR3 or a special PTE or whatever loaded. PaX hooks the entry code to avoid leaks. >> At boot, choose a random address A. > > what is the threat that a random address defends against? Makes it harder to exploit a case where the CR3 setting leaks. > >> Create an mm_struct that has a >> single VMA starting at A that represents the kernel's rarely-written >> section. Compute O = (A - VA of rarely-written section). To do a >> rare write, use_mm() the mm, write to (VA + O), then unuse_mm(). > > the problem is that the amount of __read_only data extends beyond vmlinux, > i.e., this approach won't scale. another problem is that it can't be used > inside use_mm and switch_mm themselves (no read-only task structs or percpu > pgd for you ;) and probably several other contexts. Can you clarify these uses that extend beyond vmlinux? I haven't looked at the grsecurity patch extensively. Are you talking about the BPF JIT stuff? If so, I think that should possibly be handled a bit differently, since I think the normal write-to-rare-write-vmlinux-sections primitive should preferably *not* be usable to write to executable pages. Using a real mm_struct for this could help. > > last but not least, use_mm says this about itself: > > (Note: this routine is intended to be called only > from a kernel thread context) > > so using it will need some engineering (or the comment be fixed). Indeed. >> It has the added benefit that writes to non-rare-write data using the >> rare-write primitive will fail. > > what is the threat model you're assuming for this feature? based on what i > have for PaX (arbitrary read/write access exploited for data-only attacks), > the above makes no sense to me... > If I use the primitive to try to write a value to the wrong section (write to kernel text, for example), IMO it would be nice to OOPS instead of succeeding. Please keep in mind that, unlike PaX, uses of a pax_open_kernel()-like function will may be carefully audited by a friendly security expert such as yourself. It would be nice to harden the primitive to a reasonable extent against minor misuses such as putting it in a context where the compiler will emit mov-a-reg-with-WP-set-to-CR0; ret.
[toc] | [prev] | [next] | [standalone]
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
Back to top | Article view | linux.kernel
csiph-web