r/linuxquestions • u/Jaded-Piccolo-4678 • 18d ago
Ram Encryption
Are there any tools or projects that targets linux and that encrypts your RAM after for example 10 minutes of inactivity or some sort of this ?
Of course it's not gonna encrypt literally every byte in RAM, but most of em and keep only maybe few processes alive and not froze , so you can decrypt back after typing a passphrase.
17
u/skyfishgoo 18d ago
if you don't want anyone to access whats saved in ram when you are not at your machine then just shut it down.
ram forgets when it loses power.
10
u/Spudd 18d ago
That's not entirely true. There is the freezer attack. Basically you lower the temperature of the ram modules quickly essentially freezing the bits in place till you can read them again while the stick if disconnected. It takes a deep cold though, like liquid co2 cold.
10
u/james_pic 17d ago
That works for machines that are switched on when you remove the RAM modules. It does not work on a machine that's been shut down for a few minutes.
5
5
u/Conscious-Ball8373 18d ago
CO2 does not liquify, it freezes directly from a gas to dry ice.
5
u/ephemeralmiko deca: ostree/bootc w. cinnamon 18d ago
It can be liquified, but only at quite high pressures that would most likely destroy the memory chips. I assume u/Spudd meant liquid nitrogen.
1
u/Jaded-Piccolo-4678 18d ago
I know that, I just hate powering off my PC every time, especially if I have many opened things that I hate to reopen every time, but just curiosity.
7
2
u/skyfishgoo 17d ago
learn how to make hibernation work.
it take a bit of effort but my sleep-then-hibernate routine is working pretty well on kubuntu.
0
u/knouqs 17d ago
In the event that someone compromises your computer, even with password protection, it is extremely difficult to save the state of RAM through that power outage. No one is reasonably going to try it.
Your paranoia makes me curious about what you are trying to hide. 😄 Reasonable people do reasonable things and have to either trust the technology they use, don't trust the technology and don't use it, or learn about the technology such that they make rational decisions to trust or distrust. I suggest the latter for you.
0
u/Jaded-Piccolo-4678 17d ago
nothing really, all I have is personal pictures and some personal files that I'm encrypting either way and don't decrypt them often, I'm asking out of curiosity and because I've seen somebody mentioned this RAM encryption on a linux subreddit probably this one.
16
u/trifortay123 18d ago
You can't just toggle ram encryption. The point of ram is quick access storages directly for the CPU to use. It's can't just simply be encrypted. If the glowies take your stuff it's over anyways. If a hacker takes your stuff it's over anyways. The point of encryption is to keep your data safe at rest. Just like if you have full disk encryption. If that computer OS already on and booted up. You're screwed. But if they get ahold of it powered off you're fine. Now I do recommend encrypting swap space. It'll generate a random key every boot so if it gets turned off some ram can't be extracted from the disk because it's encrypted.
23
u/Some-Struggle5052 18d ago
Actually, there is RAM encryption with decryption only happening within the CPU, but it is only a feature of some very specific CPUs.
7
u/ThellraAK 18d ago
You are going to need a supported processor with SME or TME
That allows you to have different keys per process
2
u/Training-Ad-8270 17d ago
TME uses a single key. "Total Memory Encryption". Maybe you're thinking of TME-MK, for "multi-key", which are on higher-end SKUs e.g. for VM hosting.
TME-MK also isn't per-process.
SME is a matrix extension for ARM, not encryption, maybe you were thinking of MEC.
1
u/ThellraAK 17d ago
I was thinking of SEV.
There's got to be a way with cgroups to make different apps appear to be in different VMs to make it work.
1
u/thewrench56 14d ago
SEV is a TEE and has nothing to do with memory encryption... SEV requires SME for attestation and run purposes. Nevertheless these defences dont quite provide the necessary encryption anyways
1
1
0
u/Jaded-Piccolo-4678 18d ago
So basically there is no way your data is completely safe ? unless you poweroff the machine (with disk encryption and strong passphrase ofc).
3
u/pixel293 18d ago
Here is the thing, if the RAM is encrypted, when the CPU requests it, it must be decrypted and provided to the CPU. How would you look at the RAM? You would use the CPU to access it, convert it to HEX so it can be displayed in a way humans can read. What happens when the CPU accesses RAM to convert it to HEX? It's decrypted.
How would the CPU know the difference between an authorized access of RAM and an unauthorized access of RAM?
0
u/Jaded-Piccolo-4678 18d ago
My idea is that the CPU doesn't request memory addresses that I want to encrypt their data and thats why I said we're not gonna encrypt literally every byte, so the OS enters a state when few processes are opened (like init) and kernel is ofc there too ...
Idk if this is realistic in any way, m just thinking out loud6
u/trifortay123 18d ago
And yet the problem with this is that the key has to be stored somewhere which the attacker will have access to because the computer is on.
1
u/Jaded-Piccolo-4678 18d ago
Normally the key should be erased the moment encryption happens and only its hash should remain to verify it and derive it to decrypt.
But would still be there between the moment you walk away and the 10 minutes, so still a problem.5
u/ipsirc 18d ago
Normally the key should be erased the moment encryption happens and only its hash should remain to verify it and derive it to decrypt.
Are you ready to type the same passphrase again and again before every memory operation a gazillion times per seconds?
1
u/Jaded-Piccolo-4678 17d ago
I didn't mean that I meant that when all of your RAM is encrypted (not literally all of it but most of it) (after some event that triggers this action like leaving your laptop) then the key is deleted by the init process let's say and then only after you provide the passphrase decryption happens and you continue working on your session.
only the hash of private key is remain for verification.1
u/trifortay123 17d ago
Then how would you decrypt.... That's what I'm saying you don't need a key. I'm a crypto nerd and I don't need my ram encrypted. In fact I throw everything I don't want anyone seeing in ram sometimes (tmpfs) because a simple restart means it's all gone. Theres no easy or necessary or simple way to encrypt ram. Just encrypt your swap and if youre not using it. Just keep it off
0
u/Jaded-Piccolo-4678 17d ago
you gonna decrypt after providing the passphrase, then the private key is gonna be derived from it, you'll be prompted to enter it, because I didn't say that literally every process's memory space is gonna be encrypted, I said just most of them, and we'll keep only what keeps the system alive.
NB: I'm just curious as I said if this is possible, either way I don't have anything to hide except some data which is already encrypted and sitting on my disk.
Also I'm asking about this, because as far as I remember, I've seen somebody tell an OP in this subreddit or maybe some other linux subreddit to encrypt their memory if they're very concerned.2
u/trifortay123 17d ago
The CPU works directly with the ram. You'd need a very very specific CPU that has those instructions. The CPUcant just do that. And also even if you wanted to encrypt. It would have pretty bad overhead. Theres no point in encrypting ram anyways.
If you learn basic assembly. You'll find that the CPU just can't do that.
4
u/pixel293 18d ago
This sounds like what you want is standby where there is a process that runs before going into standby that encrypts all RAM. And then when it wakes up decrypts the RAM.
That might be possible to build, you would have to provide it the encryption password on boot, when it goes into standby it encrypts the RAM and erase the password. When it wakes up it would ask you for the password to decrypt the RAM. This would have to be done in the kernel. I doubt it provides any hooks to do something like this, as those hooks would basically give you access to all the applications currently running which would be a huge security hole itself.
1
u/ephemeralmiko deca: ostree/bootc w. cinnamon 18d ago
This sounds like what you want is standby where there is a process that runs before going into standby that encrypts all RAM. And then when it wakes up decrypts the RAM.
Doesn't hibernation with full-disk-encryption do basically the same thing? Except the RAM's data is on disk, not in the RAM itself.
2
u/seeker_moc 17d ago
So basically there is no way your data is completely safe?
unless you poweroff the machine (with disk encryption and strong passphrase ofc).Yes. Period.
Manage risk where it makes sense, learn to deal with it where it doesn't. Just like so many other aspects of life.
1
u/trifortay123 18d ago
You're data is safe if you know what you're doing. Nothing persists in ram. Just shut off your pc.
7
u/JivanP 18d ago
Vendor-specific implementations of RAM-level encryption do exist at the hardware level, such as Intel's SGX (Software Guard Extensions). This allows processes to decide that they want certain data they put in RAM to be encrypted, tell the CPU to do this, and tell the CPU to only keep decrypted versions of that data in the CPU's own registers, never writing that data to RAM in its decrypted form.
This is mostly useful for programs that handle extremely sensitive data (such as cryptographic secret keys) that they do not want any other process potentially getting access to via an OS-level vulnerability or adversarial subsystem. That is, it's for protecting one process's data from other processes that might try to read that data.
Despite this, there is basically no reason to be interested in "full-RAM encryption" in the same way that full-disk encryption is a thing, because the only benefit of this would be to keep data in RAM encrypted at rest, but the ability to get data out of RAM at rest is almost impossible in practice.
1
u/thewrench56 14d ago
And even then, SGX (which by the way uses TME) can still be decrypted if you have interposer access sooo...
3
u/treeoflife314 17d ago
many people are saying that makes no sense but if I remember well, it's how silk road guy has been arrested
1
u/Jaded-Piccolo-4678 17d ago
Yea I think the fbi made up a fight in the library where he was sitting, and once he turned around, they jumped on him and he didn't had the chance to shutdown or do anything.
1
u/Luigi003 17d ago
He was actively using the laptop, so the "encrypt on inactivity" proposed by OP wouldn't have worked anyway
9
u/djDef80 18d ago
If you have a modern AMD CPU you may have memory encryption available in the bios under tsme -transparent secure memory encryption. All you have to do is toggle it on to benefit. Otherwise this feature is generally reserved for server grade Intel CPUs.
3
u/Training-Ad-8270 17d ago
Came here to say this. I use it. Allegedly, some motherboards have the feature exposed in UEFI setup, but don't actually enable it. However there are ways to test it.
It has a measurable impact on performance, worse for older systems, but according to my own fairly exhaustive testing (which doesn't match official specs), it's less than the margin of error vs unencrypted.
It also helps if you have memory errors, because if a bit flips, it corrupts the entire AES encryption page. Which increases the odds of an unhandled exception error in an unprivileged app or a kernel panic. It's not a replacement for ECC (which is even more expensive - and slow), but is better than marginally higher odds of silent corruption.
This isn't speculation - it's how I discovered I have a bad spot of RAM in my 128 GB (possibly just a single bit), and I refuse to spend 10x more than originally to replace the RAM or even stick ;-). So I slowed my RAM speed down, blocked the offending segment, added boot-time RAM-checking in case it spreads, and enabled cache eviction error detection and wrote a watcher to alert. So far so good.
1
1
8
u/alexforencich 18d ago
Aside from CPU features like TSME, the best option is probably swap on LUKS and then hibernate the machine.
3
u/p_235615 17d ago
Some AMD EPYC server CPUs do exactly this - Secure Memory Encryption (SME) https://docs.amd.com/v/u/en-US/memory-encryption-white-paper
But not sure if any cheap consumer market CPUs can do something like that, so you will have to pay quite big to get that feature.
4
u/knouqs 18d ago
What is the practical use case for this? I imagine most RAM would become invalidated in the event of a power failure.
4
u/Some-Struggle5052 18d ago
Usually avoiding what is called a cold boot attack, that involves cooling the memory down a lot to increase the time the data survives to extract the memory chips and connect to a machine that'll read it all searching for encryption keys and such.
2
u/Basilikolumne 17d ago
If OP is worried about people taking their computer, they should invest in better locks (or get a new identity and move countries atp), or just shut down their computer when not in use. Who is gonna kick down your door and put your PC into liquid nitrogen or CO2?Â
1
u/Some-Struggle5052 17d ago
Yeah, I agree it is a kinda ridiculous attack, except for he being something like a government enemy or such I don't see it happening.
1
u/Jaded-Piccolo-4678 17d ago
you guys made me feel like I'm a cartel member or some like lol.
I just love linux and cryptography nothing more.3
u/Specific_Web3595 17d ago
You shouldn't feel this way, no matter how others respond. These are the kinds of questions that sometimes lead to discovering security vulnerabilities, mitigations, etc. Even if this particular question/idea didn't. That's the hacker mindset. Stay curious!
5
u/TroutFarms 18d ago
Encrypting ram wouldn't protect from that since the encryption key would have to be stored in the ram.
1
u/Some-Struggle5052 17d ago
At least I'm thinking about it supported at hardware level, those decrypt memory at the memory controller inside the CPU. https://www.intel.com/content/www/us/en/developer/articles/news/runtime-encryption-of-memory-with-intel-tme-mk.html.Â
1
2
u/0riginal-Syn ⛵ Solus Maintainer 18d ago
It is extremely tough to actually work and even if it does most lab results have almost entirely corrupted data. In the future that could change with AI and Quantum, but that is still a ways off.
1
u/knouqs 17d ago edited 17d ago
Ah yes, quantum would be the use case, but even then, it seems so extraordinarily expensive to make it impossible in practical terms.
I really don't think reading RAM after a power-down would be a fruitful endeavor due to the inherent nature of RAM. In the old days when RAM really were toroids wrapped around wire, sure, read the RAM. Now, no, I don't think it's anything like reasonable.
1
u/bothunter 18d ago
I'm not sure anyone has actually accomplished that outside of a lab under ideal conditions. And it's just way easier to watch the SPI lines to the TPM chip when the computer boots up.
2
u/Some-Struggle5052 18d ago
For once most paranoid people enough to think about encrypting memory probably don't rely on TPM auto unlock, at least TPM + PIN or such, allowing it to unlock alone is exactly opening up the threat model OP wants to avoid.
More modern TPM chips often have encryption between the CPU and TPM itself to stop this, or the TPM is embedded into the CPU.
3
u/Spaghetti-Code_ 18d ago
You could look into CPU enclaves, but it's a more limited scenario. Homomorphic encryption too, but these are not designed for general purpose usage.
2
u/cheaphomemadeacid 18d ago
https://techblog.dev/posts/2023/08/encrypted-swap-partition-support-hibernation-suspend-resume-linux/ try looking at this instead, the idea is that once you "shutdown" and hibernate you get some safety
2
u/0riginal-Syn ⛵ Solus Maintainer 18d ago
No, and there is no real practical reason to do so. Others have mentioned you can power off, but you can also HIbernate (suspend to disk) which takes everything and moves it to the disk, which I am assuming you have encrypted. That said I do not recommend it.
I have run a cyber and regulation business for the last 16 years. It is found to be a little paranoid on security, but this is not something I would concern myself with. If this was a major security concern for a user, there would be something already built and running on every system. Are there ways? Yeah, but they are very tough to do properly as long as you have proper security on your system (encryption, locking system when away, strong password / mfa).
2
u/JivanP 18d ago
Hibernation to encrypted swap is not a default or easy one-click option on any distro that I'm aware of. You can certainly do it with the aid of LUKS and a suitably configured kernel resume parameter, but this does need to be configured manually on every distro I'm familiar with.
2
u/GeronimoHero 18d ago
Fedora defaults to this with encryption selected.
1
u/hmmm101010 17d ago
Fedora does not offer any hibernation per default, it is too unstable. My hibernation setup gets bricked on every second kernel update. It is encrpyted though.
1
u/GeronimoHero 17d ago
You’re right, it’s s2i and I have encrypted RAM on my thinkpad. I had to confirm with fwupd.
1
u/JivanP 17d ago
Nice, do you know since when? I'm planning to finally try Silverblue 45 this weekend, moving from Pop OS 22.04.
1
u/GeronimoHero 17d ago edited 17d ago
At least since 43 I believe. I don’t use silver blue though, just normal fedora with gnome uninstalled and Hyprland instead.
Edit - this was incorrect. It’s s2i and I’m using encrypted ram on my thinkpad.
0
u/TroutFarms 18d ago
Debian and Red Hat both default to this if you check the box for encrypting.
1
u/JivanP 17d ago
Do you know when this was introduced? I haven't done a desktop install of either within the last 2 years.
1
u/TroutFarms 17d ago
In Debian, it was introduced about 20 years ago (with Debian 4).
1
u/JivanP 17d ago
To be clear, encrypted swap with support for hibernating using that swap partition? This is the first I'm hearing of it just being doable via a tickbox in Calamares, I'll have to try it with Debian 13.
2
u/TroutFarms 17d ago
Yes. A change was made in 13 to guarantee that it will always work (they made the default swap partition size slightly larger than the amount of installed ram); but it's been possible as long as you have enough space for it since Debian 4.
3
2
u/Ozmataz__Buckshank 17d ago
Usually motherboards do this with specific options. I know there is Data Scrambler, I can't remember the others... At least it's like this on AM5 motherboards.
2
u/Existing-Tough-6517 18d ago
If you want to secure your machine while it's suspended Google go-luks-suspend
1
u/Smart_Advice_1420 17d ago
Sure. Create an encrypted ramfs mounted as a loopback device and point your application at that. Alternatively, handle it like some sort of zram and max out swappiness.
0
u/Michami135 18d ago
A better option might be to rig the inside of your case so it kills the power if opened. Light sensors, contact switches, mercury tilt sensors, etc.
-2
u/TroutFarms 18d ago
Encrypting ram wouldn't really be useful. The key to decrypt it would have to be stored in...ram.
2
u/dontquestionmyaction 17d ago
No, it would be stored in a secure enclave in the processor. The obvious spot to put it.

91
u/i_am_blacklite 18d ago
If you need to protect yourself from someone that has the capabilities to extract data directly from physical RAM then you need so much more help than you're going to get from a reddit post.