r/linuxquestions • • 14d 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.

14 Upvotes

96 comments sorted by

91

u/i_am_blacklite 14d 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.

10

u/Jaded-Piccolo-4678 14d ago

I'm not really protecting from anybody, just curious and paranoid.

11

u/knouqs 14d ago

OK, curiosity got you to post this stuff, and for that, great. My question about the practical use case remains: RAM needs near-constant refreshing through power bursts in order to maintain its data. When a user tells the computer to hibernate, the operating system tells itself "Save the state of the RAM to disk in a hibernation file." Then, the RAM can safely lose power without the contents being lost.

Obviously, you can see that the contents of RAM are still lost upon power down. They just get repopulated when the system resumes as the operating system first checks whether there is a hibernation file.

So, in the event of a power failure, the contents of RAM generally get destroyed with little chance of recovery.

-10

u/sswam 14d ago

So maybe you need psychological help, not technical help. Even most of the most extremely security sensitive organisations and applications do not do this.

15

u/LawElectrical2434 14d ago

And every college course happily looks into those topics. It's a nice thought experiment. But go ahead, declare them all crazy.

2

u/sswam 13d ago

He said he's paranoid. That's pretty close to a cry for help.

1

u/bebe_likes_hugs 13d ago

Ever heard of an iperbole?

1

u/myusernameblabla 14d ago

I'm curious, why not? Isn't that a major security weak point?

6

u/daffalaxia 14d ago

The attacker needs privileged, direct access to your hardware. If they have that, then they aren't wasting time scanning ram.

Prior ram-based attacks like spectre and rowhammer rely on bugs to break out of the security models already in place.

0

u/wowsomuchempty 14d ago

Actually, this would have application on HPC.

HPC isn't suitable for sensitive data, one reason being multiple user access to RAM. Encrypted per-user RAM bundles could be useful here.

Storage is only encrypted at rest.. I don't think this could work, actually.

17

u/skyfishgoo 14d 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.

1

u/Jaded-Piccolo-4678 14d 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

u/ipsirc 14d ago

Hibernating does exist.

2

u/fr000gs 14d ago

s3 sleep (deep sleep) also used to exist, until m$ bullied hardware manufacturers to not do it anymore

1

u/stufforstuff 14d ago

Or a password protected screen saver.

2

u/skyfishgoo 14d 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 14d 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 14d 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.

2

u/knouqs 14d ago

Heh, it's fine -- your data, I don't care. The only reason you have my (and probably others') curiosities piqued is because of your insistence on the paranoia aspect of things.

I hope that you have discovered by now that you don't need to encrypt your RAM.

10

u/Spudd 14d 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 14d 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

u/wowsomuchempty 14d ago

When has this ever successfully happened?

-3

u/Human_Cantaloupe8249 14d ago

Yes. You can search for cold boot on YouTube

5

u/Conscious-Ball8373 14d ago

CO2 does not liquify, it freezes directly from a gas to dry ice.

5

u/ephemeralmiko deca: ostree/bootc w. cinnamon 14d 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.

16

u/trifortay123 14d 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 14d 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 14d 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 13d 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 13d 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 11d 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

u/Some-Struggle5052 14d ago

Yes, that's what I was thinking about.

0

u/Jaded-Piccolo-4678 14d 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 14d 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 14d 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 loud

6

u/trifortay123 14d 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 14d 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 14d 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 14d 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 14d 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 14d 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 14d 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 14d 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 14d 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 14d 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 14d ago

You're data is safe if you know what you're doing. Nothing persists in ram. Just shut off your pc.

1

u/Ivorymothi 14d ago

you make a solid point about swap, never thought of it that way before

4

u/knouqs 14d 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 14d 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 14d 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/Jaded-Piccolo-4678 14d 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 13d 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!

1

u/Some-Struggle5052 14d 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.

5

u/TroutFarms 14d ago

Encrypting ram wouldn't protect from that since the encryption key would have to be stored in the ram.

1

u/Luigi003 14d ago

Encryption key could be held on the TPM chip or the CPU itself but yeah

1

u/Some-Struggle5052 14d 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. 

2

u/0riginal-Syn ⛵ Solus Maintainer 14d 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 14d ago edited 14d 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 14d 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 14d 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/treeoflife314 14d 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 14d 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 14d ago

He was actively using the laptop, so the "encrypt on inactivity" proposed by OP wouldn't have worked anyway

9

u/djDef80 14d 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 13d 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

u/whatThePleb 14d ago

Also check kernel configs.

1

u/Ozmataz__Buckshank 14d ago

There is also "data scrambler" I believe.

8

u/alexforencich 14d ago

Aside from CPU features like TSME, the best option is probably swap on LUKS and then hibernate the machine.

7

u/JivanP 14d 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 11d ago

And even then, SGX (which by the way uses TME) can still be decrypted if you have interposer access sooo...

3

u/Spaghetti-Code_ 14d 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.

3

u/whatThePleb 14d ago

SME / TSME or TME / MKTME

And for swap: zram + dm-crypt

3

u/p_235615 14d 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.

2

u/Existing-Tough-6517 14d ago

If you want to secure your machine while it's suspended Google go-luks-suspend

2

u/cheaphomemadeacid 14d 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/Ozmataz__Buckshank 14d 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.

4

u/ipsirc 14d ago

problemxy

2

u/0riginal-Syn ⛵ Solus Maintainer 14d 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 14d 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 14d ago

Fedora defaults to this with encryption selected.

1

u/JivanP 14d 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 14d ago edited 13d 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.

1

u/hmmm101010 13d 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 13d ago

You’re right, it’s s2i and I have encrypted RAM on my thinkpad. I had to confirm with fwupd.

0

u/TroutFarms 14d ago

Debian and Red Hat both default to this if you check the box for encrypting.

1

u/JivanP 14d 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 14d ago

In Debian, it was introduced about 20 years ago (with Debian 4).

1

u/JivanP 14d 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 14d 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.

2

u/c2btw 14d ago

Tails.is is where I would look for stuff like this. And this isn't going to be something's that togeled on and off, for one you would have to reread and then rewright the entirety of ram every time. 2 why. It's eitrer encyoted from boot or not at all

1

u/Smart_Advice_1420 14d 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 14d 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/skreak 14d ago

The idea of encrypting ram makes so little sense I can't even think of an analogy to explain how little sense it makes.

-2

u/TroutFarms 14d ago

Encrypting ram wouldn't really be useful. The key to decrypt it would have to be stored in...ram.

2

u/dontquestionmyaction 14d ago

No, it would be stored in a secure enclave in the processor. The obvious spot to put it.