MDSv6
Subsystems (248)
Greg KH
maintainerI'm sorry, I just can't stop...
Documentation/clearcpu.txt line 62
Quoted 7 lines · speck for Andi Kleen
Documentation/clearcpu.txt new file +7
-0+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.
Documentation/clearcpu.txt line 65
Quoted 2 lines
Documentation/clearcpu.txt new file +2
-0+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?
Review
Quoted 2 lines
(quoted diff) +2
-0+ +Touching only pointers to user data is always allowed.
But not touching the data the pointer points to?
Review
Quoted 2 lines
(quoted diff) +2
-0+ +When your interrupt does touch user data directly mark it with IRQF_USER_DATA.
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"?
Documentation/clearcpu.txt line 72
Quoted 3 lines
Documentation/clearcpu.txt new file +3
-0+ +When your tasklet does touch user data directly, mark it TASKLET_USER_DATA +using tasklet_init_flags/or DECLARE_TASKLET_USERDATA*.
Same as above.
Documentation/clearcpu.txt line 75
Quoted 3 lines
Documentation/clearcpu.txt new file +3
-0+ +When your timer does touch user data mark it with TIMER_USER_DATA +If it is a hrtimer and touches user data, mark it with HRTIMER_MODE_USER_DATA.
Mark what, the timer function?
Quoted 1 line
+When your irq poll handler does touch user data, mark it
lazy_clear_cpu().
Mark what? That's a function call?
Documentation/clearcpu.txt line 82
Quoted 4 lines
Documentation/clearcpu.txt new file +4
-0+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?
How about UIO drivers, how does their data get classified? Lots of networking stacks use UIO now... virtual io channels?
Documentation/clearcpu.txt line 85
Quoted 2 lines
Documentation/clearcpu.txt new file +2
-0+Any cryptographic code touching key data should use memzero_explicit +or kzfree to free the data.
We do that today, right? If not, that needs to be done regardless.
And what about password data? I _think_ we got most of that now out of the tty layer, but we could be wrong :)
Review
Quoted 2 lines
(quoted diff) +2
-0+ +If your RCU callback touches user data add lazy_clear_cpu().
Ugh, really?
Documentation/clearcpu.txt line 91
Quoted 4 lines
Documentation/clearcpu.txt new file +4
-0+ +These steps are currently only needed for code that runs on MDS affected +CPUs, which is currently only x86. But might be worth being prepared +if other architectures become affected too.
As someone who probably reviews more new drivers than anyone else right now, my first recommendation is going to be, "Buy a non-Intel processor, we have no idea what they expect from driver writers now, just give up trying to appease them." Because if I, the person that is responsible for reviewing those drivers has no idea what to do here, how can some random driver author be expected to know?
Seriously, this is crazy.
And if you all are going to expect me to start auditing all new drivers based on these new rules, I need a _big_ raise. I somehow doubt you are asking all other OS vendors to do all of this crud.
Documentation/clearcpu.txt line 98
Quoted 6 lines
Documentation/clearcpu.txt new file +6
-0+Implementation details/assumptions +---------------------------------- + +Any buffer clearing is done lazily on next kernel exit. lazy_clear* +is only a few fast instructions with no cache misses setting +a flag and can be used frequently even in fast paths.
I can not parse this paragraph at all, what are you trying to say?
Documentation/clearcpu.txt line 104
Quoted 5 lines
Documentation/clearcpu.txt new file +5
-0+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?
What about something like IPC data?
Documentation/clearcpu.txt line 110
Quoted 5 lines
Documentation/clearcpu.txt new file +5
-0+On context switching we clear data, unless the context switch is +inside a process. We also clear after any context switches from kernel +threads. + +Cryptographic keys inside the kernel should be protected.
"Protected"? How? Huh? ugh.
<big snip as I got tired>
Documentation/clearcpu.txt line 217
Quoted 8 lines
Documentation/clearcpu.txt new file +8
-0+Sandboxes +--------- + +We don't do anything special for seccomp processes + +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."?
Documentation/clearcpu.txt line 223
Quoted 5 lines
Documentation/clearcpu.txt new file +5
-0+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?
Documentation/clearcpu.txt line 226
Quoted 2 lines
Documentation/clearcpu.txt new file +2
-0+BPF could attack the rest of the kernel if it can successfully +measure side channel side effects.
Can it do such a measurement?
Quoted 14 lines
Documentation/clearcpu.txt new file +14
-0+When the BPF program was loaded unprivileged, always clear the CPU +to prevent any exploits written in BPF using side channels to read +data leaked from other kernel code + +We only do this when running in an interrupt, or if an clear cpu is +already scheduled (which means for example there was a context +switch, or crypto operation before) + +In process context we assume the code only accesses data of the +current user and check that the BPF running was loaded by the +same user so even if data leaked it would not cross privilege +boundaries. + +Technically we would only need to do this if the BPF program
Documentation/clearcpu.txt line 251
Quoted 10 lines
Documentation/clearcpu.txt new file +10
-0+contains conditional branches and loads dominated by them, but +let's assume that nearly all do. + +This could be further optimized by batching clears for +many similar EBPF executions in a row (e.g. for packet +processing). This would need ensuring that no sensitive +data is touched inbetween the EBPF executions, and also +that all EBPF scripts are set up by the same uid. +We could add such optimizations later based on +profile data.
Please contact the BPF people before writing any of the above. The fact that you all have not done so is scandalous.
greg k-h
[MODERATED] Encrypted Message
From: Jon Masters <[email protected]>
To: speck for Greg KH <[email protected]>
Subject: Re: [PATCH v6 10/43] MDSv6
Quoted 4 lines · speck for Greg KH
Documentation/clearcpu.txt line 226
Quoted 2 lines
Documentation/clearcpu.txt new file +2
-0+BPF could attack the rest of the kernel if it can successfully +measure side channel side effects.Can it do such a measurement?
The researchers involved in MDS are actively working on an exploit using BPF as well, so I expect we'll know soon. My assumption is "yes".
Jon.
Signature · 1 line
Computer Architect | Sent with my Fedora powered laptop
Quoted 4 lines
What do you mean by "terminal data"?
And by including stuff like "input devices", I think you need a much better definition of what you are now calling "user data".
It seems clear to me. Can you elaborate what exactly is unclear and how you would define it?
Quoted 5 lines
You have two types of data now, "sensitive" and "not sensitive". Don't confuse things by trying to say "user", as the data coming from "outside" of the system (i.e. random events) might somehow be classified as "sensitive" in your world view here (i.e. usb random number generators).
Ok can change the terminology.
Quoted 21 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+We assume that only data actually accessed by the kernel by explicit +instructions can be leaked.What do you mean by "explicit"? A memcpy? Setting up a DMA channel and processing the data afterward in userspace? Gazing wistfully as it flows through the unipro fabric to and from a camera?
Documentation/clearcpu.txt line 54
Quoted 6 lines
Note that this may not be always
Documentation/clearcpu.txt new file +5
-0+true, in theory prefetching or speculation may touch more. The assumption +is that if any such happens it will be very low bandwidth and hard +to control due to the existing Spectre and other mitigations, +such as memory randomization. If a user is concerned about this they +need to use mds=full.Let me shorten this paragraph for you:
We really have no idea what data might be touched by the processor or read by anyone else. If you happen to care if some other process on the physical system can read your data, use mds=full.
Quoted 1 line
Is that a better summary?
I don't think so. It's a quantitative argument. It's about rising the bar enough, while still having good performance.
For all the side channel mitigations (like Spectre v1) we used those.
But anyways so you seem to disagree with Linus' here. I'm just implementing what he suggested. Please argue it out with him!
-Andi
Greg KH
maintainerQuoted 10 lines · speck for Andi Kleen
Quoted 5 lines
Quoted 2 lines
Instead of marking all the USB interrupts and timers as clear cpu only clear it when the user data touching actually happens.
Um, almost all irqs here _do_ receive data across the wire, and your patch shows this happening. The text here is all wrong.
Just to be clear touching here it means "access with the CPU" especially copying. Just manipulating data addresses is fine.
Quoted 6 lines
Quoted 4 lines
Also, why are you classifying USB data as "user data"? It's coming from some random piece of hardware. I don't see a definition of what you are calling "user data" anywhere in this patchset, did I miss that somewhere?
user data includes IO data (but not metadata)
What is "metadata" when you are dealing with a stream of scsi data over a random physical layer?
Quoted 3 lines
USB could be key presses (e.g. your password) or mouse movements or block IO data
These are all considered sensitive.
So, all USB data is sensitive, great, document that crazyness! What about thunderbolt data? Unipro data? amba bus data?
Do you care about the physical layer (USB, unipro, amba, thunderbolt), or do you care about the "class" of data (keyboard, block, input, hid, camera)? Right now you seem to be mixing the two up in horridly complex ways that is guaranteed to drive you, and us, crazy.
greg k-h
Ok I feel like a lawyer now, but ... Let's see if we can draft a contract.
Quoted 11 lines · speck for Greg KH
Documentation/clearcpu.txt line 62
Quoted 7 lines · speck for Andi Kleen
Documentation/clearcpu.txt new file +7
-0+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.
Quoted 6 lines
Documentation/clearcpu.txt line 65
Quoted 3 lines
Documentation/clearcpu.txt new file +2
-0+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.
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ +Touching only pointers to user data is always allowed.But not touching the data the pointer points to?
Right.
Quoted 4 lines
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.
Quoted 7 lines
Documentation/clearcpu.txt line 82
Quoted 4 lines
Documentation/clearcpu.txt new file +4
-0+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.
Quoted 2 lines
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.
Quoted 2 lines
We do that today, right? If not, that needs to be done regardless.
Yes.
Quoted 3 lines
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.
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ +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.
Quoted 7 lines
Documentation/clearcpu.txt line 104
Quoted 5 lines
Documentation/clearcpu.txt new file +5
-0+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.
Quoted 2 lines
What about something like IPC data?
You already have access to that, so no need to clear.
Quoted 6 lines
Documentation/clearcpu.txt line 217
Quoted 4 lines
Documentation/clearcpu.txt new file +4
-0+ +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.
Quoted 9 lines
Documentation/clearcpu.txt line 223
Quoted 6 lines
Documentation/clearcpu.txt new file +5
-0+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?
Quoted 4 lines
Documentation/clearcpu.txt line 226
Quoted 2 lines
Documentation/clearcpu.txt new file +2
-0+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
Quoted 16 lines · speck for Greg KH
Quoted 15 lines · speck for Andi Kleen
Quoted 5 lines
Quoted 2 lines
Instead of marking all the USB interrupts and timers as clear cpu only clear it when the user data touching actually happens.
Um, almost all irqs here _do_ receive data across the wire, and your patch shows this happening. The text here is all wrong.
Just to be clear touching here it means "access with the CPU" especially copying. Just manipulating data addresses is fine.
Quoted 4 lines
Also, why are you classifying USB data as "user data"? It's coming from some random piece of hardware. I don't see a definition of what you are calling "user data" anywhere in this patchset, did I miss that somewhere?
Quoted 4 lines
Quoted 1 line
user data includes IO data (but not metadata)
What is "metadata" when you are dealing with a stream of scsi data over a random physical layer?
Anything that's not the user visible data on disk.
(ok perhaps checksums too, but I didn't find any driver that handles those)
Quoted 7 lines
Quoted 4 lines
USB could be key presses (e.g. your password) or mouse movements or block IO data
These are all considered sensitive.
So, all USB data is sensitive, great, document that crazyness! What about thunderbolt data? Unipro data? amba bus data?
Only the payloads, not the metadata.
Quoted 4 lines
Do you care about the physical layer (USB, unipro, amba, thunderbolt), or do you care about the "class" of data (keyboard, block, input, hid, camera)? Right now you seem to be mixing the two up in horridly complex ways that is guaranteed to drive you, and us, crazy.
Please just use your common sense, on't play the lawyer.
Would an attacker care about e.g. a sequence number or flags bit in some USB header? Likely no.
Would an attacker care about the keypress containing parts of your password? Yes
So we're trying to protect that part.
I'm trying to define a model that is secure enough, but still implementable.
If everyone thinks we should just go with mds=full I'm happy to drop these patches. It certainly makes everything a lot simpler! It's not that I like doing all of this personally.
But as long as people think the performance
benefits of the lazy approach are needed, we'll need some model like this, and some variant of these patches.
-Andi
I haven't been paying super-close attention to all this MDS stuff, but I have written a bunch of docs on all these things, so here are some suggestions if you find them valuable. Take 'em or leave 'em. :)
Documentation/clearcpu.txt line 7
Quoted 3 lines
Documentation/clearcpu.txt new file +3
-0+Some CPUs can leave read or written data in internal buffers, +which then later might be sampled through side effects. +For more details see CVE-2018-12126 CVE-2018-12130 CVE-2018-12127
Maybe:
Some CPUs can leave data in internal buffers which might later be leaked. For more details see CVE-2018-12126 CVE-2018-12130 CVE-2018-12127
Quoted 1 line
+This can be avoided by explicitly clearing the CPU state.
If you say "buffers" in the previous paragraph, it's probably good to be consistent in the next paragraph.
Documentation/clearcpu.txt line 13
Quoted 3 lines
Documentation/clearcpu.txt new file +3
-0+We attempt to avoid leaking data between different processes, +and also some sensitive data, like cryptographic data, to +user space.
The kernel attempts to avoid leaking sensitive data from inside the kernel to applications and also between applications.
Documentation/clearcpu.txt line 24
Quoted 10 lines
Documentation/clearcpu.txt new file +10
-0+We support three modes: + +(1) mitigation off (mds=off) +(2) clear only when needed (default) +(3) clear on every kernel exit, or guest entry (mds=full) + +(1) and (3) are trivial, the rest of the document discusses (2) + +In general option (3) is the most conservative choice. It does +not make ST assumptions about leaking data.
ST?
Do we need to say anything about why you might make one choice or another?
Documentation/clearcpu.txt line 29
Quoted 4 lines
Documentation/clearcpu.txt new file +4
-0+Basic requirements and assumptions +---------------------------------- + +Kernel addresses and kernel temporary data are not sensitive.
Should we say something more about the implications? Basically, picking mode-1 or mode-2 weakens KASLR.
Quoted 1 line
+User data is sensitive, but only for other processes.
I thought we went to some trouble with Spectre-v2 to at least have some minimal checks for app-to-app trust. This makes it sound like we consider all apps untrusted whether they are from the same user or not.
Documentation/clearcpu.txt line 38
Quoted 6 lines
Documentation/clearcpu.txt new file +6
-0+User data is anything in the user address space, or data buffers +directly copied from/to the user (e.g. read/write). It does not +include metadata, or flag settings. For example packet headers +or file names are not sensitive in this model. + +Block IO data (but not meta data) is sensitive.
Aren't filenames part of metadata? We go to the trouble of encrypting them for ecryptfs. I thought that's because they can be sensitive.
Documentation/clearcpu.txt line 46
Quoted 7 lines
Documentation/clearcpu.txt new file +7
-0+Most data structures in the kernel are not sensitive. + +Kernel data is sensitive when it involves cryptographic keys. + +We consider data from input devices (such as key presses) +sensitive. We also consider sound data or terminal +data sensitive.
One problem I have with the tone of this documentation is that it seems to state fact after fact with none of the backing logic. For instance, I think you're saying that the terminals are sensitive because folks type passwords into them. But, it would be wonderful to actually say that.
That way, folks can actually check the logic of the author or expand on it.
Review
Quoted 2 lines
(quoted diff) +2
-0+We assume that only data actually accessed by the kernel by explicit +instructions can be leaked.
I'm not a fan of saying "explicit instructions". Explicit to me means an instruction in the code base. I think you mean something closer to "instructions with architectural effects" or "retired instructions" or something.
I'd also think that a gadget formed out of the middle of an instruction that comes from the codebase wouldn't be "explicit", but this model doesn't seem to comprehend those.
Documentation/clearcpu.txt line 54
Quoted 6 lines
Note that this may not be always
Documentation/clearcpu.txt new file +5
-0+true, in theory prefetching or speculation may touch more. The assumption +is that if any such happens it will be very low bandwidth and hard +to control due to the existing Spectre and other mitigations, +such as memory randomization. If a user is concerned about this they +need to use mds=full.
What is "memory randomization"? Do you mean user and kernel ASLR?
Should this maybe say something like:
This approach does not mitigate leaks that originate from non- architectural data access such as speculation or prefetching.
I also have a hard time restating the "low-bandwidth" bits, mostly because I don't know enough about it to say if such a channel would be high or low-bandwidh. I *hope* it would be low-bandwidth, and that's obviously required by the model here, but I just don't know what we're supposed to take away from this.
Why even bother to mention "Spectre and other mitigations"?
Documentation/clearcpu.txt line 61
Quoted 6 lines
Documentation/clearcpu.txt new file +6
-0+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
Nit: needs to be "user-supplied"
Quoted 1 line
+context add
lazy_clear_cpu().
An example here would be nice. I can't think of one of these of the top of my head other than ptrace, and *that* is actually a counter-example.
Documentation/clearcpu.txt line 65
Quoted 2 lines
Documentation/clearcpu.txt new file +2
-0+For the cases below we care only about data from other processes. +Touching non cryptographic data from the current process is always allowed.
Nit: needs to be "non-cryptographic"
Quoted 1 line
+Touching only pointers to user data is always allowed.
Is this referring to the pointer or the data pointed to? But, I usually think of "touching a pointer" as dereferencing it.
Documentation/clearcpu.txt line 75
Quoted 7 lines
Documentation/clearcpu.txt new file +7
-0+When your interrupt does touch user data directly mark it with IRQF_USER_DATA. + +When your tasklet does touch user data directly, mark it TASKLET_USER_DATA +using tasklet_init_flags/or DECLARE_TASKLET_USERDATA*. + +When your timer does touch user data mark it with TIMER_USER_DATA +If it is a hrtimer and touches user data, mark it with HRTIMER_MODE_USER_DATA.
This all looks good and straightforward.
Quoted 1 line
+When your irq poll handler does touch user data, mark it
lazy_clear_cpu().
This is different than the others. This is a *call* you have to make, and it has to be done in a specific order versus touching the data. If you clear before touching the data, it's no good. This is backwards from some of the other mitigations, so probably really good to mention.
Documentation/clearcpu.txt line 82
Quoted 4 lines
Documentation/clearcpu.txt new file +4
-0+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.
Nit: lazy_clear_cpu has parenthesis in the previous paragraph but not here. Consistency would be nice.
Documentation/clearcpu.txt line 85
Quoted 2 lines
Documentation/clearcpu.txt new file +2
-0+Any cryptographic code touching key data should use memzero_explicit +or kzfree to free the data.
Is it just key data? I would think the plaintext is just as sensitive as the key data.
Documentation/clearcpu.txt line 89
Quoted 3 lines
Documentation/clearcpu.txt new file +3
-0+If your RCU callback touches user data add lazy_clear_cpu(). + +These steps are currently only needed for code that runs on MDS affected
Nit: MDS-affected
Documentation/clearcpu.txt line 91
Quoted 2 lines
Documentation/clearcpu.txt new file +2
-0+CPUs, which is currently only x86. But might be worth being prepared +if other architectures become affected too.
I think you're trying to say that even code that can't or doesn't run on x86 can add these mitigations. They might want to do this in the case that similar vulnerabilities appear in the future.
Documentation/clearcpu.txt line 98
Quoted 6 lines
Documentation/clearcpu.txt new file +6
-0+Implementation details/assumptions +---------------------------------- + +Any buffer clearing is done lazily on next kernel exit. lazy_clear* +is only a few fast instructions with no cache misses setting +a flag and can be used frequently even in fast paths.
This is a bit overzealous. :)
It's not like we're using some magic instructions that never miss the caches. Maybe:
lazy_clear* is designed to be low-cost and can be used frequently even in performance-sensitive paths.
Greg KH
maintainerQuoted 17 lines · speck for Andi Kleen
Quoted 16 lines · speck for Greg KH
Quoted 15 lines · speck for Andi Kleen
Quoted 5 lines
Quoted 2 lines
Instead of marking all the USB interrupts and timers as clear cpu only clear it when the user data touching actually happens.
Um, almost all irqs here _do_ receive data across the wire, and your patch shows this happening. The text here is all wrong.
Just to be clear touching here it means "access with the CPU" especially copying. Just manipulating data addresses is fine.
Quoted 4 lines
Also, why are you classifying USB data as "user data"? It's coming from some random piece of hardware. I don't see a definition of what you are calling "user data" anywhere in this patchset, did I miss that somewhere?
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
user data includes IO data (but not metadata)
What is "metadata" when you are dealing with a stream of scsi data over a random physical layer?
Anything that's not the user visible data on disk.
(ok perhaps checksums too, but I didn't find any driver that handles those)
But typically transports mix those up, so you are going to have a hard time here if you wish to tease them apart, as Mark mentioned.
Quoted 14 lines
Quoted 6 lines
Quoted 3 lines
USB could be key presses (e.g. your password) or mouse movements or block IO data
These are all considered sensitive.
So, all USB data is sensitive, great, document that crazyness! What about thunderbolt data? Unipro data? amba bus data?
Only the payloads, not the metadata.
Quoted 4 lines
Do you care about the physical layer (USB, unipro, amba, thunderbolt), or do you care about the "class" of data (keyboard, block, input, hid, camera)? Right now you seem to be mixing the two up in horridly complex ways that is guaranteed to drive you, and us, crazy.
Quoted 7 lines
Please just use your common sense, on't play the lawyer.
Would an attacker care about e.g. a sequence number or flags bit in some USB header? Likely no.
Would an attacker care about the keypress containing parts of your password? Yes
I am not trying to be a lawyer, I am trying to make this simpler and actually figure out what needs to be done here.
You obviously do not care about all bus data, only some. So which "some"? As we have class drivers, why not focus on the type of data you feel is an issue? That way you have a chance to keep on top of this thing.
If you only focus on a bus, then you will miss those types of things that do not use a bus. If you focus on the type of data, then you have a chance to do this right.
If you can't determine this then mds=full is going to have to be the only solution.
What are other operating systems going to do about all of this? Are they just punting and doing the "full" protection, or are they actually trying to mitigate this by focusing on what data types need to be protected?
thanks,
greg k-h
Quoted 2 lines
You obviously do not care about all bus data, only some. So which "some"? As we have class drivers, why not focus on the type of data you
For most drivers anything that would end up being copy_*_user()ed.
(modulo some corner cases like a network address. While I would like to protect those too, I don't see a practical way to do so. And they're already visible on the network)
Quoted 2 lines
feel is an issue? That way you have a chance to keep on top of this thing.
Ok so the problem is the terminology?
We should call it sensitive data?
I'll not be able to list all the cases explicitely in the document (this would require understanding all drivers and all subsystems which I certainly don't), there has to be some discretion.
Quoted 3 lines
If you only focus on a bus, then you will miss those types of things that do not use a bus. If you focus on the type of data, then you have a chance to do this right.
I wasn't really looking for busses, or anything like that, mainly just going through the code and looking for copies or direct data access.
-Andi
Greg KH
maintainerQuoted 20 lines · speck for Andi Kleen
Quoted 2 lines
You obviously do not care about all bus data, only some. So which "some"? As we have class drivers, why not focus on the type of data you
For most drivers anything that would end up being copy_*_user()ed.
(modulo some corner cases like a network address. While I would like to protect those too, I don't see a practical way to do so. And they're already visible on the network)
Quoted 2 lines
feel is an issue? That way you have a chance to keep on top of this thing.
Ok so the problem is the terminology?
We should call it sensitive data?
I'll not be able to list all the cases explicitely in the document (this would require understanding all drivers and all subsystems which I certainly don't), there has to be some discretion.
Quoted 6 lines
Quoted 3 lines
If you only focus on a bus, then you will miss those types of things that do not use a bus. If you focus on the type of data, then you have a chance to do this right.
I wasn't really looking for busses, or anything like that, mainly just going through the code and looking for copies or direct data access.
To make this clearer to me, is this a better definition of the problem:
- Whenever the kernel touches data that userspace will eventually see, but does not want any other userspace process to see, the CPU buffers need to be flushed before returning from the kernel to userspace.
Is that correct? If not, how would you rephrase this in a single sentence?
If this statement is true, do you care about multiple copies of that data, or only the "last" one as you just need to flush things when returning to userspace?
I ask as your patchset, for the USB data flow cases, calls lazy_clear_cpu_interrupt() twice on the same irq, each time after the buffer was copied off, which is very odd to me.
So do we care about the first copy, every copy, the last copy, or do we just need to call lazy_clear_cpu_interrupt() at least once per data flow?
As an example, here's the data coming in from a USB keyboard through to userspace:
- USB irq
- USB data potentially copied from USB controller buffer -> usbmon buffer
- USB data copied from USB controller buffer -> HID driver buffer
- HID driver parsing and copying -> input data buffer
- input data buffer copied -> input event buffer(s)
- irq return
So we have USB layer copying once, maybe twice, HID layer copying, and input layer copying (at least once, maybe multiple times as you can multiplex input streams together). Where do we care about calling lazy_clear_cpu_interrupt() on this call chain? Everywhere, or just at least once?
If only once, why not just care about the input layer, as that is where things get sent to userspace and that is the _type_ of data you are concerned about.
[Note, I'm not sure about the input layer, it's just an example, things could be better than it used to be, but you get the idea here.]
Same goes for USB storage data. Sometimes that uses dma bounce buffers, do we care about those? If not, do we care later if the SCSI layer strips things off and reconstructs data paths and feeds that to the block layer? If so, shouldn't we only care about the block layer and not scsi or USB?
I'm asking you to think of the data either at the physical layer (USB, PCI, DMA, MIPI, I2C, etc.) or at the logical layer (tty, bluetooth, mouse, sound input, block, etc.) or both. Right now it's not obvious from your patchset what the correct thing is at all.
thanks,
greg k-h
Greg KH
maintainerQuoted 30 lines · speck for Greg KH
Quoted 20 lines · speck for Andi Kleen
Quoted 2 lines
You obviously do not care about all bus data, only some. So which "some"? As we have class drivers, why not focus on the type of data you
For most drivers anything that would end up being copy_*_user()ed.
(modulo some corner cases like a network address. While I would like to protect those too, I don't see a practical way to do so. And they're already visible on the network)
Quoted 2 lines
feel is an issue? That way you have a chance to keep on top of this thing.
Ok so the problem is the terminology?
We should call it sensitive data?
I'll not be able to list all the cases explicitely in the document (this would require understanding all drivers and all subsystems which I certainly don't), there has to be some discretion.
Quoted 6 lines
Quoted 3 lines
If you only focus on a bus, then you will miss those types of things that do not use a bus. If you focus on the type of data, then you have a chance to do this right.
I wasn't really looking for busses, or anything like that, mainly just going through the code and looking for copies or direct data access.
To make this clearer to me, is this a better definition of the problem:
Quoted 7 lines
- Whenever the kernel touches data that userspace will eventually see, but does not want any other userspace process to see, the CPU buffers need to be flushed before returning from the kernel to userspace.
Is that correct? If not, how would you rephrase this in a single sentence?
Ok, I just read the "Deep Dive: Intel Analysis of MSBDS" pdf that Intel gave me last weekend, and I think the above sentence is correct. But it would be great for someone to verify it.
Quoted 3 lines
If this statement is true, do you care about multiple copies of that data, or only the "last" one as you just need to flush things when returning to userspace?
And to answer myself, I think that all is needed is to flush when returning from userspace, which lazy_clear_cpu_interrupt() _should_ be marking to have happen.
So my original point remains for the usbmon patch, it's pointless :)
Quoted 37 lines
I ask as your patchset, for the USB data flow cases, calls
lazy_clear_cpu_interrupt()twice on the same irq, each time after the buffer was copied off, which is very odd to me.So do we care about the first copy, every copy, the last copy, or do we just need to call
lazy_clear_cpu_interrupt()at least once per data flow?As an example, here's the data coming in from a USB keyboard through to userspace:
- USB irq
- USB data potentially copied from USB controller buffer -> usbmon buffer
- USB data copied from USB controller buffer -> HID driver buffer
- HID driver parsing and copying -> input data buffer
- input data buffer copied -> input event buffer(s)
- irq returnSo we have USB layer copying once, maybe twice, HID layer copying, and input layer copying (at least once, maybe multiple times as you can multiplex input streams together). Where do we care about calling
lazy_clear_cpu_interrupt()on this call chain? Everywhere, or just at least once?If only once, why not just care about the input layer, as that is where things get sent to userspace and that is the _type_ of data you are concerned about.
[Note, I'm not sure about the input layer, it's just an example, things could be better than it used to be, but you get the idea here.]
Same goes for USB storage data. Sometimes that uses dma bounce buffers, do we care about those? If not, do we care later if the SCSI layer strips things off and reconstructs data paths and feeds that to the block layer? If so, shouldn't we only care about the block layer and not scsi or USB?
Quoted 4 lines
I'm asking you to think of the data either at the physical layer (USB, PCI, DMA, MIPI, I2C, etc.) or at the logical layer (tty, bluetooth, mouse, sound input, block, etc.) or both. Right now it's not obvious from your patchset what the correct thing is at all.
After reading the paper, I think you need to focus on the logical layer, when possible, and for busses that copy data in an irq, care about them _IFF_ they are carrying data for a logical type you care about.
greg k-h
Quoted 5 lines
Quoted 2 lines
I wasn't really looking for busses, or anything like that, mainly just going through the code and looking for copies or direct data access.
To make this clearer to me, is this a better definition of the problem:
Quoted 7 lines
- Whenever the kernel touches data that userspace will eventually see, but does not want any other userspace process to see, the CPU buffers need to be flushed before returning from the kernel to userspace.
Is that correct? If not, how would you rephrase this in a single sentence?
Here's my version:
In an asynchronous context (such as interrupts or softirqs), whenever the kernel touches data with the CPU, which originates from or will finally end up in a processes address space that may not be the current process, the CPU buffers need to be cleared before returning from kernel to user space.
This excludes some metadata, such as a network addresses, which are already visible on the network and which are difficult to protect efficiently.
[btw please avoid the term "flushing", it's a clear, not a flush]
Quoted 3 lines
If this statement is true, do you care about multiple copies of that data, or only the "last" one as you just need to flush things when returning to userspace?
In principle all touching needs to be protected.
But the flag to clear the CPU lazily only needs to be set once per asynchronous event. So if you guarantee that someone else already sets it in the same interrupt it doesn't need to be set again.
Quoted 3 lines
I ask as your patchset, for the USB data flow cases, calls
lazy_clear_cpu_interrupt()twice on the same irq, each time after the buffer was copied off, which is very odd to me.
lazy_clear_cpu_interrupt() is very cheap (as in a few cycles) It's just a few instructions that set a flag. So I didn't make any attempts to minimize it. It can just be used wherever convenient.
The actual clear action is always only on the next kernel to user transition.
Quoted 3 lines
So do we care about the first copy, every copy, the last copy, or do we just need to call
lazy_clear_cpu_interrupt()at least once per data flow?
At least once.
Quoted 9 lines
As an example, here's the data coming in from a USB keyboard through to userspace:
- USB irq
- USB data potentially copied from USB controller buffer -> usbmon buffer
- USB data copied from USB controller buffer -> HID driver buffer
- HID driver parsing and copying -> input data buffer
- input data buffer copied -> input event buffer(s)
This particular case is covered by the lazy_clear_cpus in the input layer.
But if there are other HID drivers that do the "USB data copied" step in interrupt context they might need lazy_clear_cpu()s too. Did I miss some here?
Quoted 5 lines
So we have USB layer copying once, maybe twice, HID layer copying, and input layer copying (at least once, maybe multiple times as you can multiplex input streams together). Where do we care about calling
lazy_clear_cpu_interrupt()on this call chain? Everywhere, or just at least once?
At least once.
Quoted 4 lines
If only once, why not just care about the input layer, as that is where things get sent to userspace and that is the _type_ of data you are concerned about.o
Yes that's what I did. It's in the patchkit.
The tty layer does it too.
Generally I only patched the drivers itself when there wasn't a convenient middle layer or utility function that they called.
Quoted 9 lines
[Note, I'm not sure about the input layer, it's just an example, things could be better than it used to be, but you get the idea here.]
Same goes for USB storage data. Sometimes that uses dma bounce buffers, do we care about those? If not, do we care later if the SCSI layer
You mean swiotlb? That is covered in the patch kit.
Quoted 2 lines
strips things off and reconstructs data paths and feeds that to the block layer?
Does usb storage copy the data somewhere in the path? If yes I might have missed something. Can you point to the code?
Quoted 2 lines
If so, shouldn't we only care about the block layer and not scsi or USB?
I audited the block layer and all the users seemed to use kmap_atomic, so I put the clear hook in there.
For SCSI we only marked those that did PIO etc.
Quoted 4 lines
I'm asking you to think of the data either at the physical layer (USB, PCI, DMA, MIPI, I2C, etc.) or at the logical layer (tty, bluetooth, mouse, sound input, block, etc.) or both. Right now it's not obvious from your patchset what the correct thing is at all.
It was done case by case.
input drivers --> done in input layer
scsi drivers --> only needed to mark explicit PIO
network drivers --> most rely on skb annotation (just marked a few outliers) usb -> maybe we missed something here. The only obvious copy seemed to be usbmon.
-Andi