Skip to content

Commit

Permalink
9pfs: fix vulnerability in openat_dir() and local_unlinkat_common()
Browse files Browse the repository at this point in the history
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>
(cherry picked from commit b003fc0)
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
  • Loading branch information
gkurz authored and mdroth committed Mar 16, 2017
1 parent 3731a25 commit a15785c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hw/9pfs/9p-local.c
Expand Up @@ -961,7 +961,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;
}
Expand Down
3 changes: 2 additions & 1 deletion hw/9pfs/9p-util.h
Expand Up @@ -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,
Expand Down

0 comments on commit a15785c

Please sign in to comment.