predictable /tmp paths in PreviewPopup::DisplayImage()
Brought to you by:
dghart
4Pane uses predictable /tmp paths in PreviewPopup::DisplayImage()
pngfilepath = "/tmp/" + fn.GetName() + ".png"; if (SvgToPng(filepath, pngfilepath, handle)) image = wxImage(pngfilepath); wxRemoveFile(pngfilepath);
If fs.protected_symlinks=1, an unprivileged user can prevent 4Pane from displaying previews for SVG images.
If fs.protected_symlinks=0, an unprivileged user can overwrite arbitrary world-readable files owned by the 4Pane user.
Steps to reproduce:
nobody@localhost:/tmp> ln -s /home/user/somefile foo.png
# ... wait until the user previews a file named foo.svg
# somefile will be overwritten
An attacker can pre-create symlinks for the names of all existing SVG files on the system to increase the likelihood of triggering the bug.
Thank you for your report, and I apologise for the delay. This is now fixed by #d8b74e.
However I couldn't reproduce this here (debian) or in openSUSE 15.6. Though the behaviour you describe should in theory have occurred, in practice the file failed to be overwritten. Did it actually happen in tumbleweed?
P.S.
Files are only overwritten when
/proc/sys/fs/protected_symlinksis 0, which is not the default on most distros.If it's set to
1the bug only prevents 4Pane from displaying SVG previews.Hi David,
thanks for the fix. Unfortunately there's still a problem:
srand(time(NULL));makes the generated values very easy to predict, becausetime(NULL)has a granularity of just one second.I suggest
mkstemp()which generates secure /tmp file names, or,if you really want to do it manually, consider C++ STL random functions (for example
std::random_deviceandstd::mt19937).The issue was reproducible on openSUSE Tumbleweed. I have not tried other distros.
All the best,
Wolfgang
Please find attached a patch that fixes the remaining issue.
wxFileName::CreateTempFileName()uses the securemkstemp()function internally.Thanks again. In my senility I'd completely forgotten about wxFileName::CreateTempFileName. Now committed.