lkml.org 
[lkml]   [2022]   [May]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH V10 14/44] mm/pkeys: Introduce pks_set_readwrite()
On Tue, May 10, 2022 at 02:33:03PM -0700, Ira Weiny wrote:
> On Mon, May 09, 2022 at 02:38:38PM -0700, Kees Cook wrote:
> > [...]
> > Better yet would be:
> >
> > preempt_disable();
> > rdmsrl(MSR_IA32_PKRS, pkrs);
> > pkrs = pkey_update_pkval(pkrs, pkey, protection);
> > pks_write_pkrs(pkrs);
> > current->thread.pkrs = pkrs;
> > preempt_enable();
> >
> > Then cross-thread attacks cannot corrupt the _other_ PKS keys (i.e.
> > write the desired changes to target's current->thread.kprs and trigger
> > an update to a different pkey, resulting in flushing the attacker's
> > changes to that CPU's pkey state.
>
> Unfortunately I don't think this entirely prevents an attack through the
> thread.pkrs value. thread.pkrs has to be used to set the MSR when a thread is
> scheduled. Therefore the rdmsrl above will by definition pick up the
> thread.pkrs but from an earlier time.

Ooh, good point, yeah.

> I'm not opposed to doing this as I think it does reduce the time window of such
> an attack but I wanted to mention it. Especially since I specifically avoided
> ever reading the MSR to improve performance.
>
> I'm going to run some tests. Perhaps the MSR read is not that big of a deal
> and I can convince myself that the performance diff is negligible.

Yeah, given "loaded at scheduling" point, there's not much benefit in
read/write pair. I think my first suggestion about only writing to
thread.pkrs after the write, etc, still stands. I'll ponder this a bit
more.

> > While adding these, can you please also add pks_set_nowrite()? This
> > will be needed for protecting writes to memory that should be otherwise
> > readable.
>
> I have a patch to add pks_set_readonly() but I was advised to not send it
> because this series does not include a use case for it. (PMEM does not need
> it.)
>
> Dave, Dan? Are you ok adding that back?
>
> Kees would you prefer pks_set_nowrite() as a name?

I think nowrite is the better name (in the sense that "read-only" can
sometimes imply non-executable).

> >
> > With these changes it should be possible to protect the kernel's page
> > table entries from "stray" writes. :)
>
> Yes, Rick has done some great work in that area.

Oh! I would _love_ to see this series. I was trying to scope the work
yesterday but gave up after I couldn't figure out the qemu PKS trick. :)

--
Kees Cook

\
 
 \ /
  Last update: 2022-05-11 00:09    [W:0.710 / U:0.324 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site