I'm losing files in /tmp on current Ubuntu (22.04.2), possibly related to virtualisation. Any insights appreciated. This is not a normal cleanup; the file is lost immediately.
I have two systems: a remote VPS, and a local staging system, both running the same software. On both systems, /tmp is not a tmpfs; it's part of the LVM volume group mounted at /.
Apache runs program1 and program2 immediately after each other:
program1creates a new subdirectory under/tmp, with 2 files:file1(a Python source file) andfile2(the output offile1). If debug is enabled,file1is retained; otherwise, it it deleted after creatingfile2(with a C libraryremove)program2returnsfile2to the client
This all works as expected on the staging system. If debug is enabled, the new /tmp/xxx directory is still on the filesystem, and contains both file1 and file2. If debug isn't enabled, it contains only file2.
On the VPS:
- if debug is not enabled, everything works, but there's nothing left under
/tmp - if debug is enabled,
program2fails, reporting thatfile2doesn't exist
I have 'fixed' the code by removing the C lib remove, so that file1 is always retained, but I don't understand what's going on - it appears that the file remove has somewhere triggered a remove of the entire directory.
www-dataon both systems, and both/tmparedrwxrwxrwt, as expected. No auditing enabled. – EML Jun 01 '23 at 13:37/tmptraditionally has been a shared space for all local services and users and also been a big source of security problems for all kinds of services. Symlink attacks and DoS vulnerabilities due to guessable /tmp temporary files are common. That's why systemd introduced thePrivateTmp=yessetting. Iftruethat sets up a new file system namespace for the executed processes and mounts private/tmp/and/var/tmp/directories inside it that are not shared by processes outside of the namespace. – HBruijn Jun 01 '23 at 13:38PrivateTmp=yesis the default for Apache2 in the recent Ubuntu versions, which may explain some of your problems. – HBruijn Jun 01 '23 at 13:38PrivateTmptrue. So I presume that one Apache managed to run bothprogram1andprogram2in the same process, and the other has them in different processes, so maybe theremoveis irrelevant. Both apaches havemod_cgid. I think the answer must be to setPrivateTmpoff. But why is it on anyway? This isn't a system service - why wouldsystemdcare if I want to have two Apache processes talking to each other? – EML Jun 01 '23 at 14:39/tmpto store your files and/or (temporarily) disable thePrivateTmp=truesetting by changing the apache2.service systemd unit file (see https://serverfault.com/a/840999/37681) – HBruijn Jun 01 '23 at 14:52