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

Show parent comment

2

u/Salat_Leaf 23d ago

No, I don't care about reverse engineering, I just have a specific chunk of memory (in RAM) which might contain sensitive data and it's extremely important to make sure it's untouched even if some other program tries to read it (in case there's something funny going on with jump overrides)

2

u/Interesting_Debate57 23d ago

The owner of the data should cryptographically sign the data using a public key encryption system and then you can let basically anyone read it, and enforce the thing you're worried about (not sharing the information) via key control.

If this is in hardware that means that there's a special USB key required to be plugged in, otherwise you'll just get random garbage when you try to use the read.

Yes that means that the authorized party has to do 10x the normal amount of effort, but if it's hyper-critical to keep the data cold, this is a good way.

0

u/[deleted] 23d ago

[deleted] — view deleted comment

1

u/Interesting_Debate57 22d ago

Encrypt and sign, I think.

0

u/[deleted] 22d ago

[deleted] — view deleted comment

1

u/Salat_Leaf 22d ago

There's that minor window of vulnerability when I have to decrypt the data itself from custom AEAD scheme before encrypting it again into TLS-compatible profile for e.g. HTTPS. I wanma make it impossible to read even if somebody wants to via the host CPU/process/system

0

u/[deleted] 22d ago

[deleted] — view deleted comment

1

u/Salat_Leaf 22d ago

Alrighty, thx!

1

u/onlyonequickquestion 23d ago

I was googling it because I'd never really thought about it before, by the time I got back, looks like others have answered. I found Intel sgx might work? Most solutions seemed hardware dependent though. Sounds like some other people have more experience and will be able to give you a better answer. Good luck, sounds like a fun problem to crack. 

2

u/Salat_Leaf 23d ago

Still appreciate the help regardless!