From: Stefan Hajnoczi <stefanha@gmail.com>
To: Greg Kurz <groug@kaod.org>
Cc: qemu-devel@nongnu.org, Jann Horn <jannh@google.com>,
Prasad J Pandit <prasad@redhat.com>,
"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 22/28] 9pfs: local: chmod: don't follow symlinks
Date: Mon, 27 Feb 2017 13:17:53 +0000 [thread overview]
Message-ID: <20170227131753.GN28403@stefanha-x1.localdomain> (raw)
In-Reply-To: <148814906880.28146.13942320633418827458.stgit@bahia>
[-- Attachment #1: Type: text/plain, Size: 1800 bytes --]
On Sun, Feb 26, 2017 at 11:44:28PM +0100, Greg Kurz wrote:
> The local_chmod() callback is vulnerable to symlink attacks because it
> calls:
>
> (1) chmod() which follows symbolic links for all path elements
> (2) local_set_xattr()->setxattr() which follows symbolic links for all
> path elements
> (3) local_set_mapped_file_attr() which calls in turn local_fopen() and
> mkdir(), both functions following symbolic links for all path
> elements but the rightmost one
>
> We would need fchmodat() to implement AT_SYMLINK_NOFOLLOW to fix (1). This
> isn't the case on linux unfortunately: the kernel doesn't even have a flags
> argument to the syscall :-\ It is impossible to fix it in userspace in
> a race-free manner. This patch hence converts local_chmod() to rely on
> open_nofollow() and fchmod(). This fixes the vulnerability but introduces
> a limitation: the target file must readable and/or writable for the call
> to openat() to succeed.
>
> It introduces a local_set_xattrat() replacement to local_set_xattr()
> based on fsetxattrat() to fix (2), and a local_set_mapped_file_attrat()
> replacement to local_set_mapped_file_attr() based on local_fopenat()
> and mkdirat() to fix (3). No effort is made to factor out code because
> both local_set_xattr() and local_set_mapped_file_attr() will be dropped
> when all users have been converted to use the "at" versions.
>
> This partly fixes CVE-2016-9602.
>
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
> v2: - use openat_dir()
> - updated the changelog and added a comment for fchmod()
> ---
> hw/9pfs/9p-local.c | 178 +++++++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 167 insertions(+), 11 deletions(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
next prev parent reply other threads:[~2017-02-27 13:18 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-26 22:41 [Qemu-devel] [PATCH v2 00/28] Series short description Greg Kurz
2017-02-26 22:41 ` [Qemu-devel] [PATCH v2 01/28] 9pfs: local: move xattr security ops to 9p-xattr.c Greg Kurz
2017-02-26 22:41 ` [Qemu-devel] [PATCH v2 02/28] 9pfs: remove side-effects in local_init() Greg Kurz
2017-02-26 22:41 ` [Qemu-devel] [PATCH v2 03/28] 9pfs: remove side-effects in local_open() and local_opendir() Greg Kurz
2017-02-26 22:42 ` [Qemu-devel] [PATCH v2 04/28] 9pfs: introduce openat_nofollow() helper Greg Kurz
2017-02-27 12:44 ` Stefan Hajnoczi
2017-02-27 14:31 ` Greg Kurz
2017-02-27 15:32 ` Stefan Hajnoczi
2017-02-27 23:28 ` Eric Blake
2017-02-28 0:32 ` Greg Kurz
2017-02-26 22:42 ` [Qemu-devel] [PATCH v2 05/28] 9pfs: local: keep a file descriptor on the shared folder Greg Kurz
2017-02-26 22:42 ` [Qemu-devel] [PATCH v2 06/28] 9pfs: local: open/opendir: don't follow symlinks Greg Kurz
2017-02-27 12:49 ` Stefan Hajnoczi
2017-02-27 14:35 ` Greg Kurz
2017-02-26 22:42 ` [Qemu-devel] [PATCH v2 07/28] 9pfs: local: lgetxattr: " Greg Kurz
2017-02-27 12:58 ` Stefan Hajnoczi
2017-02-26 22:42 ` [Qemu-devel] [PATCH v2 08/28] 9pfs: local: llistxattr: " Greg Kurz
2017-02-27 13:08 ` Stefan Hajnoczi
2017-02-26 22:42 ` [Qemu-devel] [PATCH v2 09/28] 9pfs: local: lsetxattr: " Greg Kurz
2017-02-27 13:10 ` Stefan Hajnoczi
2017-02-26 22:42 ` [Qemu-devel] [PATCH v2 10/28] 9pfs: local: lremovexattr: " Greg Kurz
2017-02-27 13:12 ` Stefan Hajnoczi
2017-02-26 22:43 ` [Qemu-devel] [PATCH v2 11/28] 9pfs: local: unlinkat: " Greg Kurz
2017-02-27 13:14 ` Stefan Hajnoczi
2017-02-26 22:43 ` [Qemu-devel] [PATCH v2 12/28] 9pfs: local: remove: " Greg Kurz
2017-02-26 22:43 ` [Qemu-devel] [PATCH v2 13/28] 9pfs: local: utimensat: " Greg Kurz
2017-02-26 22:43 ` [Qemu-devel] [PATCH v2 14/28] 9pfs: local: statfs: " Greg Kurz
2017-02-26 22:43 ` [Qemu-devel] [PATCH v2 15/28] 9pfs: local: truncate: " Greg Kurz
2017-02-26 22:43 ` [Qemu-devel] [PATCH v2 16/28] 9pfs: local: readlink: " Greg Kurz
2017-02-26 22:43 ` [Qemu-devel] [PATCH v2 17/28] 9pfs: local: lstat: " Greg Kurz
2017-02-26 22:43 ` [Qemu-devel] [PATCH v2 18/28] 9pfs: local: renameat: " Greg Kurz
2017-02-26 22:44 ` [Qemu-devel] [PATCH v2 19/28] 9pfs: local: rename: use renameat Greg Kurz
2017-02-26 22:44 ` [Qemu-devel] [PATCH v2 20/28] 9pfs: local: improve error handling in link op Greg Kurz
2017-02-26 22:44 ` [Qemu-devel] [PATCH v2 21/28] 9pfs: local: link: don't follow symlinks Greg Kurz
2017-02-26 22:44 ` [Qemu-devel] [PATCH v2 22/28] 9pfs: local: chmod: " Greg Kurz
2017-02-27 13:17 ` Stefan Hajnoczi [this message]
2017-02-26 22:44 ` [Qemu-devel] [PATCH v2 23/28] 9pfs: local: chown: " Greg Kurz
2017-02-26 22:44 ` [Qemu-devel] [PATCH v2 24/28] 9pfs: local: symlink: " Greg Kurz
2017-02-26 22:44 ` [Qemu-devel] [PATCH v2 25/28] 9pfs: local: mknod: " Greg Kurz
2017-02-27 13:18 ` Stefan Hajnoczi
2017-02-26 22:45 ` [Qemu-devel] [PATCH v2 26/28] 9pfs: local: mkdir: " Greg Kurz
2017-02-26 22:45 ` [Qemu-devel] [PATCH v2 27/28] 9pfs: local: open2: " Greg Kurz
2017-02-27 13:18 ` Stefan Hajnoczi
2017-02-26 22:45 ` [Qemu-devel] [PATCH v2 28/28] 9pfs: local: drop unused code Greg Kurz
2017-02-26 23:45 ` [Qemu-devel] [PATCH v2 00/28] 9pfs: local: fix vulnerability to symlink attacks Greg Kurz
2017-02-27 13:24 ` [Qemu-devel] [PATCH v2 00/28] Series short description Stefan Hajnoczi
2017-02-27 15:33 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170227131753.GN28403@stefanha-x1.localdomain \
--to=stefanha@gmail.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=groug@kaod.org \
--cc=jannh@google.com \
--cc=prasad@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).