usb-mtp: use O_NOFOLLOW and O_CLOEXEC.
commit6b29db871d1262c79d87b9a6ae3c84b1f013fb76
authorGerd Hoffmann <kraxel@redhat.com>
Thu, 13 Dec 2018 12:25:11 +0000 (13 13:25 +0100)
committerMichael Roth <mdroth@linux.vnet.ibm.com>
Thu, 28 Mar 2019 18:00:29 +0000 (28 13:00 -0500)
tree2f16b95eba8adbae9b75698ec043bc234ae8a5b9
parent6c77b5ab357b8f70b607c54e9914b3d1c1273ed2
usb-mtp: use O_NOFOLLOW and O_CLOEXEC.

Open files and directories with O_NOFOLLOW to avoid symlinks attacks.
While being at it also add O_CLOEXEC.

usb-mtp only handles regular files and directories and ignores
everything else, so users should not see a difference.

Because qemu ignores symlinks, carrying out a successful symlink attack
requires swapping an existing file or directory below rootdir for a
symlink and winning the race against the inotify notification to qemu.

Fixes: CVE-2018-16872
Cc: Prasad J Pandit <ppandit@redhat.com>
Cc: Bandan Das <bsd@redhat.com>
Reported-by: Michael Hanselmann <public@hansmi.ch>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Michael Hanselmann <public@hansmi.ch>
Message-id: 20181213122511.13853-1-kraxel@redhat.com
(cherry picked from commit bab9df35ce73d1c8e19a37e2737717ea1c984dc1)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
hw/usb/dev-mtp.c