Linux Internals: How /proc/self/mem writes to unwritable memory (2021)
offlinemark.com - 63 poäng - 13 kommentarer - 27463 sekunder sedan
Kommentarer (4)
- hansendc - 21744 sekunder sedan"On x86-64, there are two CPU settings which control the kernel’s ability to access memory."
There are a couple more than two, even in 2021.
Memory Protection Keys come to mind, as do the NPT/EPT tables when virtualization is in play. SEV and SGX also have their own ways of preventing the kernel from writing to memory. The CPU also has range registers that protect certain special physical address ranges, like the TDX module's range. You can't write there either.
That's all that comes to mind at the moment. It's definitely a fun question!
- KenoFischer - 12305 sekunder sedanI'm still surprised I was the first one to notice when Linus tried to change this - I always thought it was a pretty well known behavior.
- bluepeter - 22892 sekunder sedanThe kernel owns the page tables. It can always find another way in.
- haberman - 15319 sekunder sedanTL;DR: when a user writes to /proc/self/mem, the kernel bypasses the MMU and hardware address translation, opting to emulate it in software (including emulated page faults!), which allows it to disregard any memory protection that is currently setup in the page tables.
Nördnytt! 🤓