All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andi Kleen <ak@linux.intel.com>
To: speck@linutronix.de
Subject: [MODERATED] Re: [PATCH v6 10/43] MDSv6
Date: Mon, 25 Feb 2019 08:58:16 -0800	[thread overview]
Message-ID: <20190225165816.GT16922@tassilo.jf.intel.com> (raw)
In-Reply-To: <20190225163013.GB22318@kroah.com>


Ok I feel like a lawyer now, but ... Let's see if we can draft a contract.

On Mon, Feb 25, 2019 at 05:30:13PM +0100, speck for Greg KH wrote:
> On Sun, Feb 24, 2019 at 07:07:16AM -0800, speck for Andi Kleen wrote:
> > +Guidance for driver/subsystem developers
> > +----------------------------------------
> > +
> > +[These generally need to be enforced in code review for new code now]
> > +
> > +When you touch user supplied data of *other* processes in system call
> > +context add lazy_clear_cpu().
> 
> What do you mean by "user supplied data of *other* processes"?  I think
> I understand the kernel, and I have no idea what this means.

*other* here means a process which is not current. 

Anything that would be copied from/to the other process.

It's actually fairly rare.

Or rather in all situations I know about the process has access
to the other process' data anyways (e.g. ptrace or process_vm_read/write)

It happens in special situations like the context switch today.

Here's a hypothetical situation where it could happen:

You have a driver which processes a shared input queue which
contains data for multiple processes. The processing 
happens with the CPU so touches data, and does not only
read metadata, but actually has to read the full data.

It runs some code in process context to go through the queue
and pick out data items that belong to a process. It skips
data for other processes, but still has to read it.

That would be touching other processes' data.

Does it actually happen anywhere in the code?
I'm not sure. But I wanted to document it anyways.

> 
> > +For the cases below we care only about data from other processes.
> > +Touching non cryptographic data from the current process is always allowed.
> 
> Define "non cryptographic data".  Is data coming across a serial port
> crypto data?  From a camera?

That's IO data which is sensitive.

> 
> > +
> > +Touching only pointers to user data is always allowed.
> 
> But not touching the data the pointer points to?

Right.

> I still don't know what "user data" means.  Is a serial stream coming
> from a bluetooth device "user data"?  Is a program that talks directly
> to a USB data without a special kernel driver reading "user data"?  Is a
> serial port data stream "user data"?

These are all IO (but not meta) data.

> > +For networking code, make sure to only touch user data through
> > +skb_push/put/copy [add more], unless it is data from the current
> > +process. If that is not ensured add lazy_clear_cpu or
> > +lazy_clear_cpu_interrupt.
> 
> How do you know if data coming across the network is for the "current"
> process?  What does "current process" even mean here?

Current process is "current". You know it if you're in process context
and you only process data for your process.

For example recvmsg() doesn't need to worry because it only processes
a queue of data that is for the current process context.

> How about UIO drivers, how does their data get classified?  Lots of
> networking stacks use UIO now...  virtual io channels?

It's all sensitive I guess. These will clear after the
process context switch anyways.

> 
> We do that today, right?  If not, that needs to be done regardless.

Yes.

> 
> And what about password data?  I _think_ we got most of that now out of
> the tty layer, but we could be wrong :)

I don't think the kernel processes passwords directly.

If it's in the tty later it's IO data. If it's in the user program
it's user data. When it's uploaded to the kernel as a processed
key it's cryptographic data.

> 
> > +
> > +If your RCU callback touches user data add lazy_clear_cpu().
> 
> Ugh, really?

Yes. But none need it currently, so it's very unlikely.

BTW you seem to think that lazy_clear_cpu is very expensive. 
It is not. And it is done after all process context switches anyways.

> > +Protecting process data
> > +-----------------------
> > +
> > +If a system call touches data of its own process, CPU state does not
> > +need to be cleared, because it has already access to it.
> 
> How do you know if it is it's own process or not?

See above.

> 
> What about something like IPC data?

You already have access to that, so no need to clear.

> > +
> > +If there is a sandbox inside the process the process should take care
> > +itself of clearing its own sensitive data before running sandbox
> > +code. This would include data touched by system calls.
> 
> i.e. "Userspace code is hosed, sorry."?

User space has lots of own ways to mitigate. Most code which
doesn't use run untrusted code sandboxes doesn't need to worry.

> 
> > +BPF
> > +---
> > +
> > +Assume BPF execution does not touch other user's data, so does
> > +not need to schedule a clear for itself.
> 
> Can you assume that?
> 
> > +BPF could attack the rest of the kernel if it can successfully
> > +measure side channel side effects.
> 
> Can it do such a measurement?

For Spectre it could, so likely it can for MDS too.

-Andi

  parent reply	other threads:[~2019-02-25 16:58 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-24 15:07 [MODERATED] [PATCH v6 00/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 01/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 02/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 03/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 04/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 05/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 06/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 07/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 08/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 09/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 10/43] MDSv6 Andi Kleen
2019-02-25 16:11   ` [MODERATED] " Greg KH
2019-02-25 16:42     ` Andi Kleen
2019-02-25 16:30   ` Greg KH
2019-02-25 16:41     ` [MODERATED] Encrypted Message Jon Masters
2019-02-25 16:58     ` Andi Kleen [this message]
2019-02-25 17:18   ` [MODERATED] Re: [PATCH v6 10/43] MDSv6 Dave Hansen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 11/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 12/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 13/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 14/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 15/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 16/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 17/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 18/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 19/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 20/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 21/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 22/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 23/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 24/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 25/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 26/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 27/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 28/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 29/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 30/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 31/43] MDSv6 Andi Kleen
2019-02-25 15:19   ` [MODERATED] " Greg KH
2019-02-25 15:34     ` Andi Kleen
2019-02-25 15:49       ` Greg KH
2019-02-25 15:52         ` [MODERATED] Encrypted Message Jon Masters
2019-02-25 16:00           ` [MODERATED] " Greg KH
2019-02-25 16:19             ` [MODERATED] " Jon Masters
2019-02-25 16:19         ` [MODERATED] Re: [PATCH v6 31/43] MDSv6 Andi Kleen
2019-02-25 16:24         ` mark gross
2019-02-25 16:24         ` Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 32/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 33/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 34/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 35/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [FROZEN] [PATCH v6 36/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 37/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 38/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 39/43] MDSv6 Andi Kleen
2019-02-25 15:26   ` [MODERATED] " Greg KH
2019-02-25 16:28     ` Andi Kleen
2019-02-25 16:47       ` Greg KH
2019-02-25 17:05         ` Andi Kleen
2019-02-25 17:49           ` Greg KH
2019-02-25 18:10             ` Andi Kleen
2019-02-25 20:11               ` Greg KH
2019-02-25 21:00                 ` Greg KH
2019-02-25 21:19                 ` Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 40/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 41/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 42/43] MDSv6 Andi Kleen
2019-02-24 15:07 ` [MODERATED] [PATCH v6 43/43] MDSv6 Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190225165816.GT16922@tassilo.jf.intel.com \
    --to=ak@linux.intel.com \
    --cc=speck@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.