r/C_Programming • • 23d ago

Question How to manipulate read-restricted data (possibly without OS)?

Imagine you have some block of code/data chunk that under no circumstances must never ever get read (rewrites are not critical, since the data is basically gone). There's a thing about Execute only memory, but afaik it requires OS support.

So how do we make sure some of the data is only overriden or executed (if interpreted as machine code) but never read? If possible, it would be nice to be able to set up some custom restrictions like a very specific offset in a program which has access to some data in memory for a one-time constant address read (imagine it compiles into assembly, something like mov %(rax), %rax, then does side-channel secure stuff and overrides the data with rdrand and stuff)

Appreciate any help! which doesn't include redditor behavior in its body

9 Upvotes

22 comments sorted by

View all comments

8

u/EpochVanquisher 23d ago

The basic way you do this is with a “trusted execution environment”

https://en.wikipedia.org/wiki/Trusted_execution_environment

it requires hardware support, and you need special privileges to make something like this work. You can use it for things like encryption keys, where the TEE contains the key, and the key never leaves the TEE. You can send data in and get decrypted / encrypted data out.

This design is really common. It's available on ordinary desktop/laptop computers, phones, and servers. But it may be a massive amount of work to use it, and these TEE are designed to prevent you from messing with them (some of them won't even let you run your own code in them).