I want to run some confidential program on a cloud server. In order to protect it from being copied, I can encrypt it into a drive and mount the decrypted drive to run it. However I want to umount the decrypted drive once it sets up running in memory to minimize the time window of the decryption.
Is it ever possible to do so? Or Linux locks this drive for the program is running from?
A similar situation is to run a program on a drive and then umount that drive.
No cleanly. You can, for example, remove a USB you are running software from. If the program does not need any resources from there, then nothing will happen but it will not exit cleanly.
If you go to another terminal and try to
umount /mnt
the system will tell you it is busy, andfuser -m /mnt
will list newbash as the process using it, alsolsof
.Even though the filesystem is in use, you could do
umount --lazy /mnt
BUT that could have nasty consequences. You don't know if the whole executable is in memory and the system might need to fetch a part of it for example.It would be asking for trouble. The option is there to avoid wait forever on resources you no longer have access to, for example at shutdown.
If all you want is to run it on memory, then you could create a ramdisk, copy it there and run it.
You could even setup something like encfs so that the folder in the ramdisk is encrypted.