9pfs fixes for 2.9 2017-03-06
The following changes since commit 56b51708e9e22809d2a78f38d0ac84bb3f3fca92:
Merge remote-tracking branch 'remotes/dgibson/tags/ppc-for-2.9-20170306' into staging (2017-03-06 13:06:30 +0000)
are available in the git repository at:
https://github.com/gkurz/qemu.git tags/fixes-for-2.9
for you to fetch changes up to b003fc0d8aa5e7060dbf7e5862b8013c73857c7f:
9pfs: fix vulnerability in openat_dir() and local_unlinkat_common() (2017-03-06 17:34:01 +0100)
----------------------------------------------------------------
Fixes issues that got merged with the latest pull request:
- missing O_NOFOLLOW flag for CVE-2016-960
- build break with older glibc that don't have O_PATH and AT_EMPTY_PATH
- various bugs reported by Coverity
----------------------------------------------------------------
Greg Kurz (6):
9pfs: fix bogus fd check in local_remove()
9pfs: fix fd leak in local_opendir()
9pfs: fail local_statfs() earlier
9pfs: don't use AT_EMPTY_PATH in local_set_cred_passthrough() 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 | 10 +++++++--- hw/9pfs/9p-util.h | 8 +++++++- 2 files changed, 14 insertions(+), 4 deletions(-)
Signature · 1 line
2.7.4
[Qemu-devel] [PULL 1/6] 9pfs: fix bogus fd check in local_remove()
This was spotted by Coverity as a fd leak. This is certainly true, but also local_remove() would always return without doing anything, unless the fd is zero, which is very unlikely.
(Coverity issue CID1371732)
--- hw/9pfs/9p-local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/9pfs/9p-local.c +1 -1
@@ -1008,7 +1008,7 @@ static int local_remove(FsContext *ctx, const char *path)int err =-1 ; dirfd =local_opendir_nofollow (ctx, dirpath); -if (dirfd) { +if (dirfd ==-1 ) { goto out; }
Signature · 1 line
2.7.4
[Qemu-devel] [PULL 2/6] 9pfs: fix fd leak in local_opendir()
In reply to Greg KurzCoverity issue CID1371731
--- hw/9pfs/9p-local.c | 1 + 1 file changed, 1 insertion(+)
hw/9pfs/9p-local.c +1 -0
@@ -435,6 +435,7 @@ static int local_opendir(FsContext *ctx, stream =fdopendir (dirfd);if (!stream) { +close (dirfd);return -1 ; } fs->dir.stream = stream;
Signature · 1 line
2.7.4
[Qemu-devel] [PULL 3/6] 9pfs: fail local_statfs() earlier
In reply to Greg KurzIf we cannot open the given path, we can return right away instead of passing -1 to fstatfs() and close(). This will make Coverity happy.
(Coverity issue CID1371729)
--- hw/9pfs/9p-local.c | 3 +++ 1 file changed, 3 insertions(+)
hw/9pfs/9p-local.c +3 -0
@@ -1053,6 +1053,9 @@ static int local_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf)int fd, ret; fd =local_open_nofollow (s, fs_path->data,O_RDONLY ,0 ); +if (fd ==-1 ) { +return -1 ; + } ret =fstatfs (fd, stbuf);close_preserve_errno (fd);return ret;
Signature · 1 line
2.7.4
[Qemu-devel] [PULL 5/6] 9pfs: fix O_PATH build break with older glibc versions
In reply to Greg KurzWhen 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.
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.
(added last paragraph to changelog as suggested by Eric Blake)
--- 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,
Signature · 1 line
2.7.4
[Qemu-devel] [PULL 4/6] 9pfs: don't use AT_EMPTY_PATH in local_set_cred_passthrough()
In reply to Greg KurzThe name argument can never be an empty string, and dirfd always point to the containing directory of the file name. AT_EMPTY_PATH is hence useless here. Also it breaks build with glibc version 2.13 and older.
It is actually an oversight of a previous tentative patch to implement this function. We can safely drop it.
--- hw/9pfs/9p-local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/9pfs/9p-local.c +1 -1
@@ -349,7 +349,7 @@ static int local_set_cred_passthrough(FsContext *fs_ctx, int dirfd, const char *name, FsCred *credp) { if (fchownat(dirfd, name, credp->fc_uid, credp->fc_gid, - AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH) < 0) { + AT_SYMLINK_NOFOLLOW) < 0) {/* * If we fail to change ownership and if we are * using security model none. Ignore the error
Signature · 1 line
2.7.4
[Qemu-devel] [PULL 6/6] 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.
--- 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,
Signature · 1 line
2.7.4
Quoted 27 lines · Greg Kurz
The following changes since commit
56b51708e9e22809d2a78f38d0ac84bb3f3fca92:Merge remote-tracking branch 'remotes/dgibson/tags/ppc-for-2.9-20170306' into staging (2017-03-06 13:06:30 +0000)
are available in the git repository at:
https://github.com/gkurz/qemu.git tags/fixes-for-2.9
for you to fetch changes up to
b003fc0d8aa5e7060dbf7e5862b8013c73857c7f:9pfs: fix vulnerability in
openat_dir()andlocal_unlinkat_common()(2017-03-06 17:34:01 +0100)----------------------------------------------------------------
Fixes issues that got merged with the latest pull request:
- missingO_NOFOLLOWflag for CVE-2016-960
- build break with older glibc that don't haveO_PATHandAT_EMPTY_PATH
- various bugs reported by Coverity----------------------------------------------------------------
Greg Kurz (6):
9pfs: fix bogus fd check inlocal_remove()
9pfs: fix fd leak inlocal_opendir()
9pfs: faillocal_statfs()earlier
9pfs: don't useAT_EMPTY_PATHinlocal_set_cred_passthrough()9pfs: fixO_PATHbuild break with older glibc versions 9pfs: fix vulnerability inopenat_dir()andlocal_unlinkat_common()
Quoted 3 lines
hw/9pfs/9p-local.c | 10 +++++++--- hw/9pfs/9p-util.h | 8 +++++++- 2 files changed, 14 insertions(+), 4 deletions(-)
Greg - just to confirm that I've done a local checkout of the above tag and it fixes the build for me. Thanks for taking the time to sort this one out even though it's an issue caused by an older OS.
ATB,
Mark.
Peter Maydell
AppliedQuoted 18 lines · Greg Kurz
The following changes since commit
56b51708e9e22809d2a78f38d0ac84bb3f3fca92:Merge remote-tracking branch 'remotes/dgibson/tags/ppc-for-2.9-20170306' into staging (2017-03-06 13:06:30 +0000)
are available in the git repository at:
https://github.com/gkurz/qemu.git tags/fixes-for-2.9
for you to fetch changes up to
b003fc0d8aa5e7060dbf7e5862b8013c73857c7f:9pfs: fix vulnerability in
openat_dir()andlocal_unlinkat_common()(2017-03-06 17:34:01 +0100)----------------------------------------------------------------
Fixes issues that got merged with the latest pull request:
- missingO_NOFOLLOWflag for CVE-2016-960
- build break with older glibc that don't haveO_PATHandAT_EMPTY_PATH
- various bugs reported by Coverity
Quoted 9 lines
----------------------------------------------------------------
Greg Kurz (6):
9pfs: fix bogus fd check inlocal_remove()
9pfs: fix fd leak inlocal_opendir()
9pfs: faillocal_statfs()earlier
9pfs: don't useAT_EMPTY_PATHinlocal_set_cred_passthrough()9pfs: fixO_PATHbuild break with older glibc versions 9pfs: fix vulnerability inopenat_dir()andlocal_unlinkat_common()
Applied, thanks.
-- PMM