Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1231993 > unrolled thread
| Started by | Ingo Molnar <mingo@kernel.org> |
|---|---|
| First post | 2015-09-24 12:00 +0200 |
| Last post | 2015-10-03 10:20 +0200 |
| Articles | 20 on this page of 28 — 6 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH 26/26] x86, pkeys: Documentation Ingo Molnar <mingo@kernel.org> - 2015-09-24 12:00 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Andy Lutomirski <luto@amacapital.net> - 2015-09-24 21:20 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Ingo Molnar <mingo@kernel.org> - 2015-09-25 09:20 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Dave Hansen <dave@sr71.net> - 2015-09-24 21:20 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Ingo Molnar <mingo@kernel.org> - 2015-09-25 08:20 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Ingo Molnar <mingo@kernel.org> - 2015-10-01 13:20 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Kees Cook <keescook@google.com> - 2015-10-01 22:40 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Andy Lutomirski <luto@amacapital.net> - 2015-10-01 22:50 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Ingo Molnar <mingo@kernel.org> - 2015-10-02 08:30 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Dave Hansen <dave@sr71.net> - 2015-10-02 20:00 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Ingo Molnar <mingo@kernel.org> - 2015-10-03 09:30 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Dave Hansen <dave@sr71.net> - 2015-10-01 23:00 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Dave Hansen <dave@sr71.net> - 2015-10-02 00:40 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Dave Hansen <dave@sr71.net> - 2015-10-02 00:40 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Kees Cook <keescook@google.com> - 2015-10-02 00:40 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Linus Torvalds <torvalds@linux-foundation.org> - 2015-10-02 00:50 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Dave Hansen <dave@sr71.net> - 2015-10-02 01:00 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Linus Torvalds <torvalds@linux-foundation.org> - 2015-10-02 03:40 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Dave Hansen <dave@sr71.net> - 2015-10-02 20:10 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Ingo Molnar <mingo@kernel.org> - 2015-10-02 09:10 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Ingo Molnar <mingo@kernel.org> - 2015-10-03 09:00 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Paolo Bonzini <pbonzini@redhat.com> - 2015-10-02 13:50 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Linus Torvalds <torvalds@linux-foundation.org> - 2015-10-02 14:00 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Paolo Bonzini <pbonzini@redhat.com> - 2015-10-02 14:20 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Ingo Molnar <mingo@kernel.org> - 2015-10-03 08:50 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Andy Lutomirski <luto@amacapital.net> - 2015-10-02 01:00 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Ingo Molnar <mingo@kernel.org> - 2015-10-02 08:10 +0200
Re: [PATCH 26/26] x86, pkeys: Documentation Ingo Molnar <mingo@kernel.org> - 2015-10-03 10:20 +0200
Page 1 of 2 [1] 2 Next page →
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2015-09-24 12:00 +0200 |
| Subject | Re: [PATCH 26/26] x86, pkeys: Documentation |
| Message-ID | <qcbtN-7ST-37@gated-at.bofh.it> |
* Dave Hansen <dave@sr71.net> wrote: > > Another question, related to enumeration as well: I'm wondering whether > > there's any way for the kernel to allocate a bit or two for its own purposes - > > such as protecting crypto keys? Or is the facility fundamentally intended for > > user-space use only? > > No, that's not possible with the current setup. Ok, then another question, have you considered the following usecase: AFAICS pkeys only affect data loads and stores. Instruction fetches are notably absent from the documentation. Can you clarify that instructions can be fetched and executed from PTE_READ but pkeys-all-access-disabled pags? If yes then this could be a significant security feature / usecase for pkeys: executable sections of shared libraries and binaries could be mapped with pkey access disabled. If I read the Intel documentation correctly then that should be possible. The advantage of doing that is that an existing attack method to circumvent ASLR (or to scout out an unknown binary) is to use an existing (user-space) information leak to read the address space of a server process - and to use that to figure out the actual code present at that address. The code signature can then be be used to identify the precise layout of the binary, and/or to create ROP gadgets - to escallate permissions using an otherwise not exploitable buffer overflow. I.e. AFAICS pkeys could be used to create true '--x' permissions for executable (user-space) pages. But I might be reading it wrong ... Thanks, Ingo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Andy Lutomirski <luto@amacapital.net> |
|---|---|
| Date | 2015-09-24 21:20 +0200 |
| Message-ID | <qckdI-3Kz-3@gated-at.bofh.it> |
| In reply to | #1231993 |
On Thu, Sep 24, 2015 at 12:10 PM, Dave Hansen <dave@sr71.net> wrote: > On 09/24/2015 02:49 AM, Ingo Molnar wrote: >> * Dave Hansen <dave@sr71.net> wrote: >>>> Another question, related to enumeration as well: I'm wondering whether >>>> there's any way for the kernel to allocate a bit or two for its own purposes - >>>> such as protecting crypto keys? Or is the facility fundamentally intended for >>>> user-space use only? >>> >>> No, that's not possible with the current setup. >> >> Ok, then another question, have you considered the following usecase: >> >> AFAICS pkeys only affect data loads and stores. Instruction fetches are notably >> absent from the documentation. Can you clarify that instructions can be fetched >> and executed from PTE_READ but pkeys-all-access-disabled pags? > > That is my understanding. I don't have a test for it, but I'll go make one. > >> If yes then this could be a significant security feature / usecase for pkeys: >> executable sections of shared libraries and binaries could be mapped with pkey >> access disabled. If I read the Intel documentation correctly then that should be >> possible. > > Agreed. I've even heard from some researchers who are interested in this: > > https://www.infsec.cs.uni-saarland.de/wp-content/uploads/sites/2/2014/10/nuernberger2014ccs_disclosure.pdf > >> I.e. AFAICS pkeys could be used to create true '--x' permissions for executable >> (user-space) pages. > > Just remember that all of the protections are dependent on the contents > of PKRU. If an attacker controls the Access-Disable bit in PKRU for the > executable-only region, you're sunk. > > But, that either requires being able to construct and execute arbitrary > code *or* call existing code that sets PKRU to the desired values. > Which, I guess, gets harder to do if all of the the wrpkru's are *in* > the execute-only area. > This may mean that we want to have a way for binaries to indicate that they want their --x segments to be loaded with a particular protection key. The right way to do that might be using an ELF note, and I also want to use ELF notes to allow turning off vsyscalls, so maybe it's time to write an ELF note parser in the kernel. --Andy -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2015-09-25 09:20 +0200 |
| Message-ID | <qcvst-2R9-3@gated-at.bofh.it> |
| In reply to | #1232357 |
* Andy Lutomirski <luto@amacapital.net> wrote: > This may mean that we want to have a way for binaries to indicate that they want > their --x segments to be loaded with a particular protection key. The right way > to do that might be using an ELF note, and I also want to use ELF notes to allow > turning off vsyscalls, so maybe it's time to write an ELF note parser in the > kernel. That would be absolutely lovely for many other reasons as well, and we should also add a tool to tools/ to edit/expand/shrink those ELF notes on existing systems. I.e. make it really easy to augment security policies on an existing distro, using any filesystem (not just ACL capable ones) and using the binary only. Linux binaries could carry capabilities information, etc. etc. Thanks, Ingo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Dave Hansen <dave@sr71.net> |
|---|---|
| Date | 2015-09-24 21:20 +0200 |
| Message-ID | <qckdI-3Kz-5@gated-at.bofh.it> |
| In reply to | #1231993 |
On 09/24/2015 02:49 AM, Ingo Molnar wrote: > * Dave Hansen <dave@sr71.net> wrote: >>> Another question, related to enumeration as well: I'm wondering whether >>> there's any way for the kernel to allocate a bit or two for its own purposes - >>> such as protecting crypto keys? Or is the facility fundamentally intended for >>> user-space use only? >> >> No, that's not possible with the current setup. > > Ok, then another question, have you considered the following usecase: > > AFAICS pkeys only affect data loads and stores. Instruction fetches are notably > absent from the documentation. Can you clarify that instructions can be fetched > and executed from PTE_READ but pkeys-all-access-disabled pags? That is my understanding. I don't have a test for it, but I'll go make one. > If yes then this could be a significant security feature / usecase for pkeys: > executable sections of shared libraries and binaries could be mapped with pkey > access disabled. If I read the Intel documentation correctly then that should be > possible. Agreed. I've even heard from some researchers who are interested in this: https://www.infsec.cs.uni-saarland.de/wp-content/uploads/sites/2/2014/10/nuernberger2014ccs_disclosure.pdf > I.e. AFAICS pkeys could be used to create true '--x' permissions for executable > (user-space) pages. Just remember that all of the protections are dependent on the contents of PKRU. If an attacker controls the Access-Disable bit in PKRU for the executable-only region, you're sunk. But, that either requires being able to construct and execute arbitrary code *or* call existing code that sets PKRU to the desired values. Which, I guess, gets harder to do if all of the the wrpkru's are *in* the execute-only area. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2015-09-25 08:20 +0200 |
| Message-ID | <qcuwq-1vM-1@gated-at.bofh.it> |
| In reply to | #1232371 |
* Dave Hansen <dave@sr71.net> wrote: > > I.e. AFAICS pkeys could be used to create true '--x' permissions for executable > > (user-space) pages. > > Just remember that all of the protections are dependent on the contents of PKRU. > If an attacker controls the Access-Disable bit in PKRU for the executable-only > region, you're sunk. The same is true if the attacker can execute mprotect() calls. > But, that either requires being able to construct and execute arbitrary code > *or* call existing code that sets PKRU to the desired values. Which, I guess, > gets harder to do if all of the the wrpkru's are *in* the execute-only area. Exactly. True --x executable regions makes it harder to 'upgrade' limited attacks. Thanks, Ingo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2015-10-01 13:20 +0200 |
| Message-ID | <qeK42-2oH-7@gated-at.bofh.it> |
| In reply to | #1232371 |
* Dave Hansen <dave@sr71.net> wrote: > > If yes then this could be a significant security feature / usecase for pkeys: > > executable sections of shared libraries and binaries could be mapped with pkey > > access disabled. If I read the Intel documentation correctly then that should > > be possible. > > Agreed. I've even heard from some researchers who are interested in this: > > https://www.infsec.cs.uni-saarland.de/wp-content/uploads/sites/2/2014/10/nuernberger2014ccs_disclosure.pdf So could we try to add an (opt-in) kernel option that enables this transparently and automatically for all PROT_EXEC && !PROT_WRITE mappings, without any user-space changes and syscalls necessary? Beyond the security improvement, this would enable this hardware feature on most x86 Linux distros automatically, on supported hardware, which is good for testing. Assuming it boots up fine on a typical distro, i.e. assuming that there are no surprises where PROT_READ && PROT_EXEC sections are accessed as data. Thanks, Ingo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@google.com> |
|---|---|
| Date | 2015-10-01 22:40 +0200 |
| Message-ID | <qeSNY-71t-25@gated-at.bofh.it> |
| In reply to | #1237279 |
On Thu, Oct 1, 2015 at 4:17 AM, Ingo Molnar <mingo@kernel.org> wrote: > > * Dave Hansen <dave@sr71.net> wrote: > >> > If yes then this could be a significant security feature / usecase for pkeys: Which CPUs (will) have pkeys? >> > executable sections of shared libraries and binaries could be mapped with pkey >> > access disabled. If I read the Intel documentation correctly then that should >> > be possible. >> >> Agreed. I've even heard from some researchers who are interested in this: >> >> https://www.infsec.cs.uni-saarland.de/wp-content/uploads/sites/2/2014/10/nuernberger2014ccs_disclosure.pdf > > So could we try to add an (opt-in) kernel option that enables this transparently > and automatically for all PROT_EXEC && !PROT_WRITE mappings, without any > user-space changes and syscalls necessary? I would like this very much. :) > Beyond the security improvement, this would enable this hardware feature on most > x86 Linux distros automatically, on supported hardware, which is good for testing. > > Assuming it boots up fine on a typical distro, i.e. assuming that there are no > surprises where PROT_READ && PROT_EXEC sections are accessed as data. I can't wait to find out what implicitly expects PROT_READ from PROT_EXEC mappings. :) -Kees -- Kees Cook Chrome OS Security -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Andy Lutomirski <luto@amacapital.net> |
|---|---|
| Date | 2015-10-01 22:50 +0200 |
| Message-ID | <qeSXD-7fI-5@gated-at.bofh.it> |
| In reply to | #1237715 |
On Thu, Oct 1, 2015 at 1:39 PM, Kees Cook <keescook@google.com> wrote: > On Thu, Oct 1, 2015 at 4:17 AM, Ingo Molnar <mingo@kernel.org> wrote: >> >> * Dave Hansen <dave@sr71.net> wrote: >> >>> > If yes then this could be a significant security feature / usecase for pkeys: > > Which CPUs (will) have pkeys? > >>> > executable sections of shared libraries and binaries could be mapped with pkey >>> > access disabled. If I read the Intel documentation correctly then that should >>> > be possible. >>> >>> Agreed. I've even heard from some researchers who are interested in this: >>> >>> https://www.infsec.cs.uni-saarland.de/wp-content/uploads/sites/2/2014/10/nuernberger2014ccs_disclosure.pdf >> >> So could we try to add an (opt-in) kernel option that enables this transparently >> and automatically for all PROT_EXEC && !PROT_WRITE mappings, without any >> user-space changes and syscalls necessary? > > I would like this very much. :) > >> Beyond the security improvement, this would enable this hardware feature on most >> x86 Linux distros automatically, on supported hardware, which is good for testing. >> >> Assuming it boots up fine on a typical distro, i.e. assuming that there are no >> surprises where PROT_READ && PROT_EXEC sections are accessed as data. > > I can't wait to find out what implicitly expects PROT_READ from > PROT_EXEC mappings. :) There's one annoying issue at least: mprotect_pkey(..., PROT_READ | PROT_EXEC, 0) sets protection key 0. mprotect_pkey(..., PROT_EXEC, 0) maybe sets protection key 15 or whatever we use for this. What does mprotect_pkey(..., PROT_EXEC, 0) do? What if the caller actually wants key 0? What if some CPU vendor some day implements --x for real? Also, how do we do mprotect_pkey and say "don't change the key"? > > -Kees > > -- > Kees Cook > Chrome OS Security -- Andy Lutomirski AMA Capital Management, LLC -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2015-10-02 08:30 +0200 |
| Message-ID | <qf20W-3Fm-23@gated-at.bofh.it> |
| In reply to | #1237717 |
* Andy Lutomirski <luto@amacapital.net> wrote:
> >> Assuming it boots up fine on a typical distro, i.e. assuming that there are no
> >> surprises where PROT_READ && PROT_EXEC sections are accessed as data.
> >
> > I can't wait to find out what implicitly expects PROT_READ from
> > PROT_EXEC mappings. :)
So what seems to happen is that there are no pure PROT_EXEC mappings in practice -
they are only omnibus PROT_READ|PROT_EXEC mappings, an unknown proportion of which
truly relies on PROT_READ:
$ for C in firefox ls perf libreoffice google-chrome Xorg xterm \
konsole; do echo; echo "# $C:"; strace -e trace=mmap -f $C -h 2>&1 | cut -d, -f3 | \
grep PROT | sort | uniq -c; done
# firefox:
13 PROT_READ
82 PROT_READ|PROT_EXEC
184 PROT_READ|PROT_WRITE
2 PROT_READ|PROT_WRITE|PROT_EXEC
# ls:
2 PROT_READ
7 PROT_READ|PROT_EXEC
17 PROT_READ|PROT_WRITE
# perf:
1 PROT_READ
20 PROT_READ|PROT_EXEC
44 PROT_READ|PROT_WRITE
# libreoffice:
2 PROT_NONE
87 PROT_READ
148 PROT_READ|PROT_EXEC
339 PROT_READ|PROT_WRITE
# google-chrome:
39 PROT_READ
121 PROT_READ|PROT_EXEC
345 PROT_READ|PROT_WRITE
# Xorg:
1 PROT_READ
22 PROT_READ|PROT_EXEC
39 PROT_READ|PROT_WRITE
# xterm:
1 PROT_READ
25 PROT_READ|PROT_EXEC
46 PROT_READ|PROT_WRITE
# konsole:
1 PROT_READ
101 PROT_READ|PROT_EXEC
175 PROT_READ|PROT_WRITE
So whatever kernel side method we come up with, it's not something that I expect
to become production quality. "Proper" conversion to pkeys has to be driven from
the user-space side.
That does not mean we can not try! :-)
> There's one annoying issue at least:
>
> mprotect_pkey(..., PROT_READ | PROT_EXEC, 0) sets protection key 0.
> mprotect_pkey(..., PROT_EXEC, 0) maybe sets protection key 15 or
> whatever we use for this. What does mprotect_pkey(..., PROT_EXEC, 0)
> do? What if the caller actually wants key 0? What if some CPU vendor
> some day implements --x for real?
That comes from the hardcoded "user-space has 4 bits to itself, not managed by the
kernel" assumption in the whole design. So no layering between different
user-space libraries using pkeys in a different fashion, no transparent kernel use
of pkeys (such as it may be), etc.
I'm not sure it's _worth_ managing these 4 bits, but '16 separate keys' does seem
to be to me above a certain resource threshold that should be more explicitly
managed than telling user-space: "it's all yours!".
> Also, how do we do mprotect_pkey and say "don't change the key"?
So if we start managing keys as a resource (i.e. alloc/free up to 16 of them), and
provide APIs for user-space to do all that, then user-space is not supposed to
touch keys it has not allocated for itself - just like it's not supposed to write
to fds it has not opened.
Such an allocation method can still 'mess up', and if the kernel allocates a key
for its purposes it should not assume that user-space cannot change it, but at
least for non-buggy code there's no interaction and it would work out fine.
Thanks,
Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Dave Hansen <dave@sr71.net> |
|---|---|
| Date | 2015-10-02 20:00 +0200 |
| Message-ID | <qfcMI-29a-23@gated-at.bofh.it> |
| In reply to | #1237965 |
On 10/01/2015 11:23 PM, Ingo Molnar wrote:
>> > Also, how do we do mprotect_pkey and say "don't change the key"?
> So if we start managing keys as a resource (i.e. alloc/free up to 16 of them), and
> provide APIs for user-space to do all that, then user-space is not supposed to
> touch keys it has not allocated for itself - just like it's not supposed to write
> to fds it has not opened.
I like that. It gives us at least a "soft" indicator to userspace about
what keys it should or shouldn't be using.
> Such an allocation method can still 'mess up', and if the kernel allocates a key
> for its purposes it should not assume that user-space cannot change it, but at
> least for non-buggy code there's no interaction and it would work out fine.
Yeah. It also provides a clean interface so that future hardware could
enforce enforce kernel "ownership" of a key which could protect against
even buggy code.
So, we add a pair of syscalls,
unsigned long sys_alloc_pkey(unsigned long flags??)
unsigned long sys_free_pkey(unsigned long pkey)
keep the metadata in the mm, and then make sure that userspace allocated
it before it is allowed to do an mprotect_pkey() with it.
mprotect_pkey(add, flags, pkey)
{
if (!(mm->pkeys_allocated & (1 << pkey))
return -EINVAL;
}
That should be pretty easy to implement. The only real overhead is the
16 bits we need to keep in the mm somewhere.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2015-10-03 09:30 +0200 |
| Message-ID | <qfpqx-3sS-5@gated-at.bofh.it> |
| In reply to | #1238480 |
* Dave Hansen <dave@sr71.net> wrote:
> On 10/01/2015 11:23 PM, Ingo Molnar wrote:
> >> > Also, how do we do mprotect_pkey and say "don't change the key"?
> >
> > So if we start managing keys as a resource (i.e. alloc/free up to 16 of them),
> > and provide APIs for user-space to do all that, then user-space is not
> > supposed to touch keys it has not allocated for itself - just like it's not
> > supposed to write to fds it has not opened.
>
> I like that. It gives us at least a "soft" indicator to userspace about what
> keys it should or shouldn't be using.
Yes. A 16-bit allocation bitmap would solve this nicely.
> > Such an allocation method can still 'mess up', and if the kernel allocates a key
> > for its purposes it should not assume that user-space cannot change it, but at
> > least for non-buggy code there's no interaction and it would work out fine.
>
> Yeah. It also provides a clean interface so that future hardware could
> enforce enforce kernel "ownership" of a key which could protect against
> even buggy code.
>
> So, we add a pair of syscalls,
>
> unsigned long sys_alloc_pkey(unsigned long flags??)
> unsigned long sys_free_pkey(unsigned long pkey)
>
> keep the metadata in the mm, and then make sure that userspace allocated
> it before it is allowed to do an mprotect_pkey() with it.
Yeah, so such an interface would allow the clean, transparent usage of pkeys for
pure PROT_EXEC mappings.
I'd expect the --x/PROT_EXEC mappings to be _by far_ more frequently used than
pure pkeys - but we still need the management interface to keep the kernel's use
of pkeys separate from user-space's use.
If all the necessary tooling changes are propagated through then in fact I'd
expect every pkeys capable Linux system to use pkeys, for almost every user-space
task.
To have maximum future flexibility for pkeys I'd suggest the following additional
changes to the syscall ABI:
- Please name them with a pkey_ prefix, along the sys_pkey_* nomenclature, so
that it becomes an easily identified 'family' of system calls.
- I'd also suggest providing an initial value with the 'alloc' call. It's true
that user-space can do this itself in assembly, OTOH there's no reason not to
provide a C interface for this.
- Make the pkey identifier 'int', not 'long', like fds are. There's very little
expectation to ever have more than 4 billion pkeys per mm, right?
- How far do we want the kernel to manage this? Any reason we don't want a
'set pkey' operation, if user-space wants to use pure C interfaces? That could
be vDSO accelerated as well, to use the unprivileged op. An advantage of such
an interface would be that it would enable the kernel to more actively manage
the actual mappings as well in the future: for example to automatically not
allow accidental RWX mappings. Such an interface would also allow the future
introduction of privileged pkey mappings on the hardware side, without having
to change user-space, since everything goes via the kernel interface.
- Along similar considerations, also add a sys_pkey_query() system call to query
the mapping of a specific pkey. (returns -EBADF or so if the key is not mapped
at the moment.) This too could be vDSO accelerated in the future.
I.e. something like:
unsigned long sys_pkey_alloc (unsigned long flags, unsigned long init_val)
unsigned long sys_pkey_set (int pkey, unsigned long new_val)
unsigned long sys_pkey_get (int pkey)
unsigned long sys_pkey_free (int pkey)
Optional suggestion:
- _Maybe_ also allow the 'remote managed' setup of pkeys: of non-local tasks -
but I'm not sure about that: it looks expensive and complex, and a TID argument
can always be added later if there's some real need.
> That should be pretty easy to implement. The only real overhead is the 16 bits
> we need to keep in the mm somewhere.
Yes.
Note that if we use the C syscall interface suggestions I outlined above, we could
in the future also change to have a full table, and manage it explicitly - without
user-space changes - if the hardware side is tweaked to allow kernel side pkeys.
Thanks,
Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Dave Hansen <dave@sr71.net> |
|---|---|
| Date | 2015-10-01 23:00 +0200 |
| Message-ID | <qeT7l-7th-25@gated-at.bofh.it> |
| In reply to | #1237715 |
On 10/01/2015 01:39 PM, Kees Cook wrote: > On Thu, Oct 1, 2015 at 4:17 AM, Ingo Molnar <mingo@kernel.org> wrote: >> * Dave Hansen <dave@sr71.net> wrote: >>>> If yes then this could be a significant security feature / usecase for pkeys: > > Which CPUs (will) have pkeys? It hasn't been announced publicly, so all I can say here is "future ones". >>>> executable sections of shared libraries and binaries could be mapped with pkey >>>> access disabled. If I read the Intel documentation correctly then that should >>>> be possible. >>> >>> Agreed. I've even heard from some researchers who are interested in this: >>> >>> https://www.infsec.cs.uni-saarland.de/wp-content/uploads/sites/2/2014/10/nuernberger2014ccs_disclosure.pdf >> >> So could we try to add an (opt-in) kernel option that enables this transparently >> and automatically for all PROT_EXEC && !PROT_WRITE mappings, without any >> user-space changes and syscalls necessary? > > I would like this very much. :) I'll go hack something together and see what breaks. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Dave Hansen <dave@sr71.net> |
|---|---|
| Date | 2015-10-02 00:40 +0200 |
| Message-ID | <qeUG5-1pD-1@gated-at.bofh.it> |
| In reply to | #1237715 |
On 10/01/2015 03:35 PM, Kees Cook wrote: > On Thu, Oct 1, 2015 at 3:33 PM, Dave Hansen <dave@sr71.net> wrote: >> On 10/01/2015 01:39 PM, Kees Cook wrote: >>> On Thu, Oct 1, 2015 at 4:17 AM, Ingo Molnar <mingo@kernel.org> wrote: >>>> So could we try to add an (opt-in) kernel option that enables this transparently >>>> and automatically for all PROT_EXEC && !PROT_WRITE mappings, without any >>>> user-space changes and syscalls necessary? >>> >>> I would like this very much. :) >> >> Here it is in a quite fugly form (well, it's not opt-in). Init crashes >> if I boot with this, though. > > *laugh* Okay... well, we've got some work to do, I guess. :) > > (And which init?) systemd for better or worse. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Dave Hansen <dave@sr71.net> |
|---|---|
| Date | 2015-10-02 00:40 +0200 |
| Message-ID | <qeUG5-1pD-3@gated-at.bofh.it> |
| In reply to | #1237715 |
[Multipart message — attachments visible in raw view] — view raw
On 10/01/2015 01:39 PM, Kees Cook wrote: > On Thu, Oct 1, 2015 at 4:17 AM, Ingo Molnar <mingo@kernel.org> wrote: >> So could we try to add an (opt-in) kernel option that enables this transparently >> and automatically for all PROT_EXEC && !PROT_WRITE mappings, without any >> user-space changes and syscalls necessary? > > I would like this very much. :) Here it is in a quite fugly form (well, it's not opt-in). Init crashes if I boot with this, though. I'll see if I can turn it in to a bit more of an opt-in and see what's actually going wrong.
[toc] | [prev] | [next] | [standalone]
| From | Kees Cook <keescook@google.com> |
|---|---|
| Date | 2015-10-02 00:40 +0200 |
| Message-ID | <qeUG5-1pD-5@gated-at.bofh.it> |
| In reply to | #1237804 |
On Thu, Oct 1, 2015 at 3:33 PM, Dave Hansen <dave@sr71.net> wrote: > On 10/01/2015 01:39 PM, Kees Cook wrote: >> On Thu, Oct 1, 2015 at 4:17 AM, Ingo Molnar <mingo@kernel.org> wrote: >>> So could we try to add an (opt-in) kernel option that enables this transparently >>> and automatically for all PROT_EXEC && !PROT_WRITE mappings, without any >>> user-space changes and syscalls necessary? >> >> I would like this very much. :) > > Here it is in a quite fugly form (well, it's not opt-in). Init crashes > if I boot with this, though. *laugh* Okay... well, we've got some work to do, I guess. :) (And which init?) > I'll see if I can turn it in to a bit more of an opt-in and see what's > actually going wrong. Cool, thanks! -Kees -- Kees Cook Chrome OS Security -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Linus Torvalds <torvalds@linux-foundation.org> |
|---|---|
| Date | 2015-10-02 00:50 +0200 |
| Message-ID | <qeUPL-1B8-5@gated-at.bofh.it> |
| In reply to | #1237804 |
On Thu, Oct 1, 2015 at 6:33 PM, Dave Hansen <dave@sr71.net> wrote:
>
> Here it is in a quite fugly form (well, it's not opt-in). Init crashes
> if I boot with this, though.
>
> I'll see if I can turn it in to a bit more of an opt-in and see what's
> actually going wrong.
It's quite likely that you will find that compilers put read-only
constants in the text section, knowing that executable means readable.
So it's entirely possible that it's pretty much all over.
That said, I don't understand your patch. Why check PROT_WRITE? We've
had :"execute but not write" forever. It's "execute and not *read*"
that is interesting.
So I wonder if your testing is just bogus. But maybe I'm mis-reading this?
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Dave Hansen <dave@sr71.net> |
|---|---|
| Date | 2015-10-02 01:00 +0200 |
| Message-ID | <qeUZs-1Mq-15@gated-at.bofh.it> |
| In reply to | #1237809 |
On 10/01/2015 03:48 PM, Linus Torvalds wrote: > On Thu, Oct 1, 2015 at 6:33 PM, Dave Hansen <dave@sr71.net> wrote: >> >> Here it is in a quite fugly form (well, it's not opt-in). Init crashes >> if I boot with this, though. >> >> I'll see if I can turn it in to a bit more of an opt-in and see what's >> actually going wrong. ... > That said, I don't understand your patch. Why check PROT_WRITE? We've > had :"execute but not write" forever. It's "execute and not *read*" > that is interesting. I was thinking that almost anybody doing a PROT_WRITE|PROT_EXEC really *is* going to write to it so they'll notice pretty fast if we completely deny them access to it. Also, a quick ftrace showed that most mmap() callers that set PROT_EXEC also set PROT_READ. I'm just assuming that folks are setting PROT_READ but aren't _really_ going to read it, so we can safely deny them all access other than exec. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Linus Torvalds <torvalds@linux-foundation.org> |
|---|---|
| Date | 2015-10-02 03:40 +0200 |
| Message-ID | <qeXuh-5r2-3@gated-at.bofh.it> |
| In reply to | #1237817 |
On Thu, Oct 1, 2015 at 6:56 PM, Dave Hansen <dave@sr71.net> wrote:
>
> Also, a quick ftrace showed that most mmap() callers that set PROT_EXEC
> also set PROT_READ. I'm just assuming that folks are setting PROT_READ
> but aren't _really_ going to read it, so we can safely deny them all
> access other than exec.
That's a completely insane assumption. There are tons of reasons to
have code and read-only data in the same segment, and it's very
traditional. Just assuming that you only execute out of something that
has PROT_EXEC | PROT_READ is insane.
No, what you *should* look at is to use the protection keys to
actually enforce a plain PROT_EXEC. That has never worked before
(because traditionally R implies X, and then we got NX).
That would at least allow people who know they don't intersperse
read-only constants in the code to use PROT_EXE only.
Of course, there may well be users who use PROT_EXE that actually *do*
do reads, and just relied on the old hardware behavior. So it's not
guaranteed to work either without any extra flags. But at least it's
worth a try, unlike the "yeah, the user asked for read, but the user
doesn't know what he's doing" thinking that is just crazy talk.
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Dave Hansen <dave@sr71.net> |
|---|---|
| Date | 2015-10-02 20:10 +0200 |
| Message-ID | <qfcWn-2zG-21@gated-at.bofh.it> |
| In reply to | #1237874 |
On 10/01/2015 06:38 PM, Linus Torvalds wrote: > On Thu, Oct 1, 2015 at 6:56 PM, Dave Hansen <dave@sr71.net> wrote: >> >> Also, a quick ftrace showed that most mmap() callers that set PROT_EXEC >> also set PROT_READ. I'm just assuming that folks are setting PROT_READ >> but aren't _really_ going to read it, so we can safely deny them all >> access other than exec. > > That's a completely insane assumption. There are tons of reasons to > have code and read-only data in the same segment, and it's very > traditional. Just assuming that you only execute out of something that > has PROT_EXEC | PROT_READ is insane. Yes, it's insane, and I confirmed that ld.so actually reads some stuff out of the first page of the r-x part of the executable. But, it did find a bug in my code where I wouldn't allow instruction fetches to fault in pages in a pkey-protected area, so it wasn't a completely worthless exercise. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2015-10-02 09:10 +0200 |
| Message-ID | <qf2DE-4Dq-23@gated-at.bofh.it> |
| In reply to | #1237809 |
* Linus Torvalds <torvalds@linux-foundation.org> wrote: > On Thu, Oct 1, 2015 at 6:33 PM, Dave Hansen <dave@sr71.net> wrote: > > > > Here it is in a quite fugly form (well, it's not opt-in). Init crashes if I > > boot with this, though. > > > > I'll see if I can turn it in to a bit more of an opt-in and see what's > > actually going wrong. > > It's quite likely that you will find that compilers put read-only constants in > the text section, knowing that executable means readable. At least with pkeys enabling true --x mappings, that compiler practice becomes a (mild) security problem: it provides a readable and executable return target for stack/buffer overflow attacks - FWIIW. (It's a limited concern because the true code areas are executable already.) I'd expect such readonly data to eventually move out into the regular data sections, the moment the kernel gives a tool to distros to enforce true PROT_EXEC mappings. > So it's entirely possible that it's pretty much all over. I'd expect that too. > That said, I don't understand your patch. Why check PROT_WRITE? We've had > :"execute but not write" forever. It's "execute and not *read*" that is > interesting. Yeah, but almost none of user-space seems to be using it. > So I wonder if your testing is just bogus. But maybe I'm mis-reading this? I don't think you are mis-reading it: my (hacky! bad! not signed off!) debug idea was to fudge PROT_EXEC|PROT_READ bits into pure PROT_EXEC only - at least to get pkeys used in a much more serious fashion than standalone testcases, without having to change the distro itself. You are probably right that true data reads from executable sections are very common, so this might not be a viable technique even for testing purposes. But worth a try. Thanks, Ingo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | linux.kernel
csiph-web