9pfs: fix vulnerability in openat_dir() and local_unlinkat_common()
authorGreg Kurz <groug@kaod.org>
Mon, 6 Mar 2017 16:34:01 +0000 (17:34 +0100)
committerGreg Kurz <groug@kaod.org>
Mon, 6 Mar 2017 16:34:01 +0000 (17:34 +0100)
We 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.

Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
hw/9pfs/9p-local.c
hw/9pfs/9p-util.h

index 0ca4c94ee4a8a19dbafa02e39203faf487053df9..45e9a1f9b0caccfe5525f1c0127371e473d0bf7b 100644 (file)
@@ -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;
             }
index cb7b2072d3aceb1bfcf625c3be937725c088283b..517027c5203250950dd9a7fdeb3f1e0720d97a0d 100644 (file)
@@ -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,