9pfs: fix vulnerability and build break
v2 cover 9pfs: fix vulnerability and build break
The "9pfs: fix vulnerability in openat_dir() and local_unlinkat_common()" was sent to add the missing O_NOFOLLOW flag and drop O_PATH, which causes build breaks with older versions of glibc.
Eric Blake pointed out during review that O_PATH could be kept:
https://lists.nongnu.org/archive/html/qemu-devel/2017-03/msg00923.html
This v2 does that in a separate patch, to address the build break with older glibc.
---
Greg Kurz (2):
9pfs: fix O_PATH build break with older glibc versions 9pfs: fix vulnerability in openat_dir() and local_unlinkat_common()
hw/9pfs/9p-local.c | 2 +- hw/9pfs/9p-util.h | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-)
--
Greg
PATCH v2 1/2 9pfs: fix O_PATH build break with older glibc versions
When O_PATH is used with O_DIRECTORY, it only acts as an optimization: the openat() syscall simply finds the name in the VFS, and doesn't trigger the underlying filesystem.
On systems that don't define O_PATH, because they have glibc version 2.13 or older for example, we can safely omit it. We don't want to deactivate O_PATH globally though, in case it is used without O_DIRECTORY. The is done with a dedicated macro.
--- hw/9pfs/9p-util.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
hw/9pfs/9p-util.h +6 -1
@@ -22,7 +22,12 @@ static inline void close_preserve_errno(int fd)static inline int openat_dir (int dirfd,const char *name) { -return openat (dirfd, name,O_DIRECTORY |O_RDONLY |O_PATH ); +#ifdef O_PATH +#define OPENAT_DIR_O_PATH O_PATH +#else +#define OPENAT_DIR_O_PATH 0 +#endif +return openat (dirfd, name,O_DIRECTORY |O_RDONLY |OPENAT_DIR_O_PATH ); } static inline int openat_file(int dirfd, const char *name, int flags,
Re: [Qemu-devel] [PATCH v2 1/2] 9pfs: fix O_PATH build break with older glibc versions
Quoted 8 lines · Greg Kurz
When
O_PATHis used withO_DIRECTORY, it only acts as an optimization: theopenat()syscall simply finds the name in the VFS, and doesn't trigger the underlying filesystem.On systems that don't define
O_PATH, because they have glibc version 2.13 or older for example, we can safely omit it. We don't want to deactivateO_PATHglobally though, in case it is used withoutO_DIRECTORY. The is done with a dedicated macro.
May be worth adding:
Systems without O_PATH may thus fail to resolve names that involve unreadable directories, compared to newer systems succeeding, but such corner case failure is our only option on those older systems to avoid the security hole of chasing symlinks inappropriately.
Quoted 5 lines
Signed-off-by Greg Kurz <[email protected]>--- hw/9pfs/9p-util.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 2/2 9pfs: fix vulnerability in openat_dir() and local_unlinkat_common()
In reply to Greg KurzWe should pass O_NOFOLLOW otherwise openat() will follow symlinks and make QEMU vulnerable.
While here, we also fix local_unlinkat_common() to use openat_dir() for the same reasons (it was a leftover in the original patchset actually).
This fixes CVE-2016-9602.
--
v2: - keep O_PATH (Eric Blake)
--- hw/9pfs/9p-local.c | 2 +- hw/9pfs/9p-util.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
hw/9pfs/9p-local.c +1 -1
@@ -960,7 +960,7 @@ static int local_unlinkat_common(FsContext *ctx, int dirfd, const char *name,if (flags ==AT_REMOVEDIR ) {int fd; - fd =openat (dirfd, name,O_RDONLY |O_DIRECTORY |O_PATH ); + fd =openat_dir (dirfd, name);if (fd ==-1 ) { goto err_out; }
hw/9pfs/9p-util.h +2 -1
@@ -27,7 +27,8 @@ static inline int openat_dir(int dirfd, const char *name)#else #define OPENAT_DIR_O_PATH 0#endif -return openat (dirfd, name,O_DIRECTORY |O_RDONLY |OPENAT_DIR_O_PATH ); +return openat (dirfd, name, +O_DIRECTORY |O_RDONLY |O_NOFOLLOW |OPENAT_DIR_O_PATH ); } static inline int openat_file(int dirfd, const char *name, int flags,
Re: [Qemu-devel] [PATCH v2 2/2] 9pfs: fix vulnerability in openat_dir() and local_unlinkat_common()
Quoted 6 lines · Greg Kurz
We should pass
O_NOFOLLOWotherwiseopenat()will follow symlinks and make QEMU vulnerable.While here, we also fix
local_unlinkat_common()to useopenat_dir()for the same reasons (it was a leftover in the original patchset actually).
Quoted 6 lines
This fixes CVE-2016-9602.
Signed-off-by Greg Kurz <[email protected]>Reviewed-by Daniel P. Berrange <[email protected]>--
v2: - keepO_PATH(Eric Blake)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org