lkml.org 
[lkml]   [2020]   [May]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2 0/2] Replace and improve "mcsafe" with copy_safe()
From
Date
On 5/1/20 11:28 AM, Linus Torvalds wrote:
> Plus on x86 you can't reasonably even have different code sequences
> for that case, because CLAC/STAC don't have a "enable users read
> accesses" vs "write accesses" case. It's an all-or-nothing "enable
> user faults".
>
> We _used_ to have a difference on x86, back when we did the whole "fs
> segment points to user space".

Protection keys might give us _some_ of this back. If we're doing a
copy_from_user(), we could (logically) do:

stac()
save_pkru()
pkru |= ~0x55555555
... do userspace read
restore_pkru()
clac()

That *should* generate a fault if we try to write to userspace in there
because PKRU affects all user *addresses* (PTEs with _PAGE_USER set) not
user-mode *accesses*.

Properly stashing the value off and context switching it correctly would
be fun, but probably not impossible to pull off. You actually wouldn't
even technically need to restore PKRU in this path. It would just need
to be restored before the thread runs userspace or hits a copy_to_user()
equivalent.

I can't imagine this would all be worth the trouble, but there are
crazier people out there than me.

\
 
 \ /
  Last update: 2020-05-01 22:17    [W:0.108 / U:0.116 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site