9pfs: local: open/opendir: don't follow symlinks
commit996a0d76d7e756e4023ef79bc37bfe629b9eaca7
authorGreg Kurz <groug@kaod.org>
Sun, 26 Feb 2017 22:42:18 +0000 (26 23:42 +0100)
committerGreg Kurz <groug@kaod.org>
Tue, 28 Feb 2017 10:21:15 +0000 (28 11:21 +0100)
tree78bbc93d08e0142f0a845fd549598cffe58f4302
parent0e35a3782948c6154d7fafe9a02a86bc130199c7
9pfs: local: open/opendir: don't follow symlinks

The local_open() and local_opendir() callbacks are vulnerable to symlink
attacks because they call:

(1) open(O_NOFOLLOW) which follows symbolic links in all path elements but
    the rightmost one
(2) opendir() which follows symbolic links in all path elements

This patch converts both callbacks to use new helpers based on
openat_nofollow() to only open files and directories if they are
below the virtfs shared folder

This partly fixes CVE-2016-9602.

Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
hw/9pfs/9p-local.c
hw/9pfs/9p-local.h [new file with mode: 0644]