[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 13/81] 9pfs: local: utimensat: don't follow symlinks
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH 13/81] 9pfs: local: utimensat: don't follow symlinks |
Date: |
Mon, 20 Mar 2017 18:07:37 -0500 |
From: Greg Kurz <address@hidden>
The local_utimensat() callback is vulnerable to symlink attacks because it
calls qemu_utimens()->utimensat(AT_SYMLINK_NOFOLLOW) which follows symbolic
links in all path elements but the rightmost one or qemu_utimens()->utimes()
which follows symbolic links for all path elements.
This patch converts local_utimensat() to rely on opendir_nofollow() and
utimensat(AT_SYMLINK_NOFOLLOW) directly instead of using qemu_utimens().
It is hence assumed that the OS supports utimensat(), i.e. has glibc 2.6
or higher and linux 2.6.22 or higher, which seems reasonable nowadays.
This partly fixes CVE-2016-9602.
Signed-off-by: Greg Kurz <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
(cherry picked from commit a33eda0dd99e00faa3bacae43d19490bb9500e07)
Signed-off-by: Greg Kurz <address@hidden>
Signed-off-by: Michael Roth <address@hidden>
---
hw/9pfs/9p-local.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 9caee0e..fa1477f 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -960,13 +960,20 @@ static int local_chown(FsContext *fs_ctx, V9fsPath
*fs_path, FsCred *credp)
static int local_utimensat(FsContext *s, V9fsPath *fs_path,
const struct timespec *buf)
{
- char *buffer;
- int ret;
- char *path = fs_path->data;
+ char *dirpath = g_path_get_dirname(fs_path->data);
+ char *name = g_path_get_basename(fs_path->data);
+ int dirfd, ret = -1;
- buffer = rpath(s, path);
- ret = qemu_utimens(buffer, buf);
- g_free(buffer);
+ dirfd = local_opendir_nofollow(s, dirpath);
+ if (dirfd == -1) {
+ goto out;
+ }
+
+ ret = utimensat(dirfd, name, buf, AT_SYMLINK_NOFOLLOW);
+ close_preserve_errno(dirfd);
+out:
+ g_free(dirpath);
+ g_free(name);
return ret;
}
--
2.7.4
- [Qemu-devel] [PATCH 00/81] Patch Round-up for stable 2.8.1, freeze on 2017-03-27, Michael Roth, 2017/03/20
- [Qemu-devel] [PATCH 10/81] 9pfs: local: lremovexattr: don't follow symlinks, Michael Roth, 2017/03/20
- [Qemu-devel] [PATCH 11/81] 9pfs: local: unlinkat: don't follow symlinks, Michael Roth, 2017/03/20
- [Qemu-devel] [PATCH 09/81] 9pfs: local: lsetxattr: don't follow symlinks, Michael Roth, 2017/03/20
- [Qemu-devel] [PATCH 13/81] 9pfs: local: utimensat: don't follow symlinks,
Michael Roth <=
- [Qemu-devel] [PATCH 14/81] 9pfs: local: statfs: don't follow symlinks, Michael Roth, 2017/03/20
- [Qemu-devel] [PATCH 15/81] 9pfs: local: truncate: don't follow symlinks, Michael Roth, 2017/03/20
- [Qemu-devel] [PATCH 12/81] 9pfs: local: remove: don't follow symlinks, Michael Roth, 2017/03/20
- [Qemu-devel] [PATCH 19/81] 9pfs: local: rename: use renameat, Michael Roth, 2017/03/20
- [Qemu-devel] [PATCH 17/81] 9pfs: local: lstat: don't follow symlinks, Michael Roth, 2017/03/20
- [Qemu-devel] [PATCH 16/81] 9pfs: local: readlink: don't follow symlinks, Michael Roth, 2017/03/20
- [Qemu-devel] [PATCH 21/81] 9pfs: local: link: don't follow symlinks, Michael Roth, 2017/03/20
- [Qemu-devel] [PATCH 18/81] 9pfs: local: renameat: don't follow symlinks, Michael Roth, 2017/03/20
- [Qemu-devel] [PATCH 29/81] 9pfs: fix bogus fd check in local_remove(), Michael Roth, 2017/03/20
- [Qemu-devel] [PATCH 25/81] 9pfs: local: mknod: don't follow symlinks, Michael Roth, 2017/03/20