Help needed for my on-demand ELF decryption

Submitted by kikanjuu
on November 10, 2007 - 7:41am

Hello, everyone:
I'm a fresh linux kernel developer and am working on the following project:

An ELF application is encrypted and I want it to be decrypted when the encrypted executable data is loaded in by the page fault handler, so that it's decrypted page by page and become runnable in the process's user space.

I have already successfully implemented the on-demand decryption in do_no_page() which will be invoked by the page fault handler when an encrypted page is loaded in. The system now can run an encrytped helloworld ELF program by decrypting it page by page in the page fault handler during the run time.

However, the problem is that since the decryption is done directly on the page cached file memory mapped page, after the program exits, the decrypted page in the page cache is available to other programs that wants to access the same ELF file, which is not secure. For example, suppose in the console:

> cp encrypted_helloworld encrypted_h
> ./encrypted_h
hello world!
>diff encrytped_helloworld encrypted_h
The two binaries differ.

The above is not what I want.
What I want is that after encrypted_h is executed, the file encrypted_h is the same as encrypted_helloworld! Here, diff obvious retrieves the decrypted data in encrypted_h file(may through the page cache, is it flushed to disk here?), which is not secure.

However, if I reboot the whole system, and again types:
> diff encrypted_helloworld encrytped_h
>
There's no difference now! Does it mean that the previous difference is caused by the page cache which is not flushed to disk on rebooting the system?

How can I modify the linux kernel so that even before rebooting the system, after "./encrypted_h", encrypted_h and encrypted_helloworld is the same for any user program that wants to access encrypted_h?

Yours sincrely,
Kikanjuu
2007-11-10

What is insecure?

Anonymous (not verified)
on
November 11, 2007 - 1:58am

You can encrypt block devices with the device mapper. You can use a loopback encrypted file system.

I have no real idea if these help you because I do not know who you are trying to prevent from doing what. I assume you are trying to store a secret inside an executable that I can execute and that I do not have root. On the other hand, I can set LD_PRELOAD (see man ld.so). You could get around that by static linking, but I am sure there will be another hack available.

Tell us what you are trying to achieve and then we can tell you if all your hard work was a complete waste of time.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.