←back to thread

Against /Tmp

(dotat.at)
140 points todsacerdoti | 10 comments | | HN request time: 0.606s | source | bottom
Show context
Aardwolf ◴[] No.41913873[source]
I like /tmp in RAM myself, it's truly temporary that way

EDIT: I do this more for avoiding certain disk reads/writes than security actually

replies(6): >>41913905 #>>41913910 #>>41913918 #>>41914627 #>>41916103 #>>41916856 #
1. nullindividual ◴[] No.41913905[source]
You'd need to pin pages in physical memory to guarantee it stays in physical memory. What happens if an 'attacker' (or accidental user) exceeds available physical memory? OOM Kill other applications? Just don't accept temp data, leading to failures in operations requested by the user or system?

Pages in physical memory are not typically zero'ed out upon disuse. Yes, they're temporary... but only guaranteed temporary if you turn the system off and the DRAM cells bleed out their voltage.

replies(3): >>41913943 #>>41913945 #>>41915792 #
2. Aardwolf ◴[] No.41913943[source]
I use this with a size of a few GB: https://wiki.archlinux.org/title/Tmpfs
3. noirscape ◴[] No.41913945[source]
By default a tmpfs has a really low RAM priority so the OS will try to move it in swapspace if memory gets low. tmpfs size is specified on creation of the tmpfs (and cant be larger than the total memory available, which is swap + RAM) but it's only "occupied" when files begin to fill the tmpfs.

If it gets too full for regular OS operations, you get the fun of the OOM Killer shutting down services (tmpfs is never targeted by the OOM Killer) until the entire OS just deadlocks if you somehow manage to fill the tmpfs up entirely.

replies(1): >>41913983 #
4. nullindividual ◴[] No.41913983[source]
> OS will try to move it in swapspace if memory gets low

That defeats the idea GP presented.

replies(2): >>41914042 #>>41914260 #
5. noirscape ◴[] No.41914042{3}[source]
That depends on how you view swapspace; on most devices, swapspace is either created as a separate partition on the disk or as a file living somewhere on the filesystem.

For practical reasons, swapspace isn't really the same thing as keeping it in an actual storage folder - the OS treats swapspace as essentially being empty data on each reboot. (You'd probably be able to extract data from swapspace with disk recovery tools though.)

On a literal level it's not the same as "keep it in RAM", but practically speaking swapspace is treated as a seamless (but slower) extension of installed RAM.

replies(1): >>41914155 #
6. nullindividual ◴[] No.41914155{4}[source]
> On a literal level it's not the same as "keep it in RAM"

I read the GP as 'literal level' in-RAM. If I interpreted that incorrectly, apologies to GP.

replies(1): >>41915723 #
7. dspillett ◴[] No.41914260{3}[source]
Only if memory gets low, otherwise it'll stay in RAM and give the benefit GGP intended. IIRC tmpfs data shouldn't be evicted to swap just to allow more room for cache, or if an app requests a large chunk of memory but doesn't use it, just to allow more room for application pages that are actively in use.

Normal case: tmpfs data stays in RAM

Worst case: it is pushed to swap partitions/files, which is no worse than it being in a filesystem on physical media to start with (depending on access patters and how swap space is arranged it may still be a little more efficient).

It isn't quite the same as /tmp being on disk anyway but under normal loads in cache, because the data will usually get written to disk even if only ever read from cache and the cached data from disk will be evicted to make room for caching other data where tmpfs data is less likely to.

replies(1): >>41917129 #
8. marcosdumay ◴[] No.41915723{5}[source]
It may or may not be what the OP was talking about, depending on your threat model.
9. RiverCrochet ◴[] No.41915792[source]
Well I guess you could tell Linux to not use some memory addresses using the BadRAM feature, then setup an `mtd` device to those memory addresses and create a RAM-based block device, then use `cryptsetup` to encrypt it. If your Linux box is headless and you have a GPU with RAM there mostly sitting unused then you could use the VRAM.
10. cowsandmilk ◴[] No.41917129{4}[source]
Use of /tmp on regular file system has almost the same behavior because the kernel has a file system cache… if you’re using the file, it will remain available in RAM. There’s some subtle differences, but I’ve seen enough benchmarks around this to have realized that tmpfs doesn’t really have an impact.