From: Greg Kurz <groug@kaod.org>
To: Miklos Szeredi <mszeredi@redhat.com>
Cc: Daniel Berrange <berrange@redhat.com>,
QEMU Developers <qemu-devel@nongnu.org>,
P J P <ppandit@redhat.com>, virtio-fs-list <virtio-fs@redhat.com>,
Alex Xu <alex@alxu.ca>, Laszlo Ersek <lersek@redhat.com>,
Vivek Goyal <vgoyal@redhat.com>
Subject: Re: [Virtio-fs] [PATCH v2] virtiofsd: prevent opening of special files (CVE-2020-35517)
Date: Wed, 27 Jan 2021 16:09:20 +0100 [thread overview]
Message-ID: <20210127160920.062e47f0@bahia.lan> (raw)
In-Reply-To: <CAOssrKeN9iYT-Z46FVtzdKnWcTLfMqK77b1faf78m3XTXnEVGw@mail.gmail.com>
On Wed, 27 Jan 2021 15:09:50 +0100
Miklos Szeredi <mszeredi@redhat.com> wrote:
> On Wed, Jan 27, 2021 at 2:49 PM Greg Kurz <groug@kaod.org> wrote:
> >
> > On Wed, 27 Jan 2021 11:34:52 +0100
> > Miklos Szeredi <mszeredi@redhat.com> wrote:
>
> > > Another solution specifically for O_CREAT without O_EXCL would be to
> > > turn it into an exclusive create.
> >
> > Would this added O_EXCL then appear on the client side, e.g. to
> > guest userspace doing fcntl(F_GETFL) ?
>
> No. Guest kernel keeps track of open flags.
>
That was my impression as well as I didn't find a FUSE_GETFL request.
Thanks for confirming that !
> > > If that fails with EEXIST then try
> > > the normal open path (open with O_PATH, fstat, open proc symlink). If
> >
> > open(O_PATH | O_NOFOLLOW) + fstatat(AT_EMPTY_PATH|AT_SYMLINK_NOFOLLOW)
> > would indeed allow to filter out anything that isn't a directory and
> > to safely open the proc symlink.
> >
> > > that fails with ENOENT, then retry the whole thing a certain number of
> >
> > Indeed someone could have unlinked the file in the meantime, in which
> > case the open(O_PATH | O_NOFOLLOW) would fail, but if it succeeds then
> > we cannot hit ENOENT anymore AFAICT.
>
> Right.
>
> > > times. If it still fails then somebody is definitely messing with us
> > > and we can fail the request with EIO.
> > >
> >
> > Not sure what the retry+timeout is trying to mitigate here... why not
> > returning EIO right away ?
>
> The semantics of O_CREATE are that it can fail neither because the
> file exists nor because it doesn't. This doesn't matter if the
> exported tree is not modified outside of a single guest, because of
> locking provided by the guest kernel.
>
Wrong. O_CREAT can legitimately fail with ENOENT if one element
of the pathname doesn't exist. And even if pathname only has
one element, you can still have O_CREAT to fail the same way
if the path of the parent directory is removed.
cat>enoent.c<<EOF
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char **argv)
{
mkdir("foo", 0777);
chdir("foo");
rmdir("../foo");
open("bar", O_CREAT);
}
EOF
make enoent
strace ./enoent
[...]
mkdir("foo", 0777) = 0
chdir("foo") = 0
rmdir("../foo") = 0
openat(AT_FDCWD, "bar", O_RDONLY|O_CREAT, 0117130) = -1 ENOENT (No such file or directory)
> However if we want to support shared access to a tree then O_CREAT
> semantics should work even in the face of races due to external
> modification of the tree. I.e. following race:
>
Yeah, handling shared access is where the fun starts :)
> virtiofsd: open(foo, O_CREAT | O_EXCL) -> EEXIST
> other task: unlink(foo)
> virtiofsd: open(foo, O_PATH | O_NOFOLLOW) -> ENOENT
>
> To properly support the above the O_CREAT | O_EXCL open would need to
> be retried.
>
But in this case, it seems fine to return ENOENT since
the guest userspace cannot really assume it never happens.
> Thanks,
> Miklos
>
WARNING: multiple messages have this Message-ID (diff)
From: Greg Kurz <groug@kaod.org>
To: Miklos Szeredi <mszeredi@redhat.com>
Cc: Daniel Berrange <berrange@redhat.com>,
QEMU Developers <qemu-devel@nongnu.org>,
P J P <ppandit@redhat.com>, virtio-fs-list <virtio-fs@redhat.com>,
Alex Xu <alex@alxu.ca>, Stefan Hajnoczi <stefanha@redhat.com>,
Laszlo Ersek <lersek@redhat.com>, Vivek Goyal <vgoyal@redhat.com>
Subject: Re: [Virtio-fs] [PATCH v2] virtiofsd: prevent opening of special files (CVE-2020-35517)
Date: Wed, 27 Jan 2021 16:09:20 +0100 [thread overview]
Message-ID: <20210127160920.062e47f0@bahia.lan> (raw)
In-Reply-To: <CAOssrKeN9iYT-Z46FVtzdKnWcTLfMqK77b1faf78m3XTXnEVGw@mail.gmail.com>
On Wed, 27 Jan 2021 15:09:50 +0100
Miklos Szeredi <mszeredi@redhat.com> wrote:
> On Wed, Jan 27, 2021 at 2:49 PM Greg Kurz <groug@kaod.org> wrote:
> >
> > On Wed, 27 Jan 2021 11:34:52 +0100
> > Miklos Szeredi <mszeredi@redhat.com> wrote:
>
> > > Another solution specifically for O_CREAT without O_EXCL would be to
> > > turn it into an exclusive create.
> >
> > Would this added O_EXCL then appear on the client side, e.g. to
> > guest userspace doing fcntl(F_GETFL) ?
>
> No. Guest kernel keeps track of open flags.
>
That was my impression as well as I didn't find a FUSE_GETFL request.
Thanks for confirming that !
> > > If that fails with EEXIST then try
> > > the normal open path (open with O_PATH, fstat, open proc symlink). If
> >
> > open(O_PATH | O_NOFOLLOW) + fstatat(AT_EMPTY_PATH|AT_SYMLINK_NOFOLLOW)
> > would indeed allow to filter out anything that isn't a directory and
> > to safely open the proc symlink.
> >
> > > that fails with ENOENT, then retry the whole thing a certain number of
> >
> > Indeed someone could have unlinked the file in the meantime, in which
> > case the open(O_PATH | O_NOFOLLOW) would fail, but if it succeeds then
> > we cannot hit ENOENT anymore AFAICT.
>
> Right.
>
> > > times. If it still fails then somebody is definitely messing with us
> > > and we can fail the request with EIO.
> > >
> >
> > Not sure what the retry+timeout is trying to mitigate here... why not
> > returning EIO right away ?
>
> The semantics of O_CREATE are that it can fail neither because the
> file exists nor because it doesn't. This doesn't matter if the
> exported tree is not modified outside of a single guest, because of
> locking provided by the guest kernel.
>
Wrong. O_CREAT can legitimately fail with ENOENT if one element
of the pathname doesn't exist. And even if pathname only has
one element, you can still have O_CREAT to fail the same way
if the path of the parent directory is removed.
cat>enoent.c<<EOF
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char **argv)
{
mkdir("foo", 0777);
chdir("foo");
rmdir("../foo");
open("bar", O_CREAT);
}
EOF
make enoent
strace ./enoent
[...]
mkdir("foo", 0777) = 0
chdir("foo") = 0
rmdir("../foo") = 0
openat(AT_FDCWD, "bar", O_RDONLY|O_CREAT, 0117130) = -1 ENOENT (No such file or directory)
> However if we want to support shared access to a tree then O_CREAT
> semantics should work even in the face of races due to external
> modification of the tree. I.e. following race:
>
Yeah, handling shared access is where the fun starts :)
> virtiofsd: open(foo, O_CREAT | O_EXCL) -> EEXIST
> other task: unlink(foo)
> virtiofsd: open(foo, O_PATH | O_NOFOLLOW) -> ENOENT
>
> To properly support the above the O_CREAT | O_EXCL open would need to
> be retried.
>
But in this case, it seems fine to return ENOENT since
the guest userspace cannot really assume it never happens.
> Thanks,
> Miklos
>
next prev parent reply other threads:[~2021-01-27 15:09 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-26 10:35 [Virtio-fs] [PATCH v2] virtiofsd: prevent opening of special files (CVE-2020-35517) Stefan Hajnoczi
2021-01-26 10:35 ` Stefan Hajnoczi
2021-01-26 10:36 ` [Virtio-fs] " Daniel P. Berrangé
2021-01-26 10:36 ` Daniel P. Berrangé
2021-01-26 10:47 ` [Virtio-fs] " Liam Merwick
2021-01-26 17:16 ` Greg Kurz
2021-01-27 9:25 ` Miklos Szeredi
2021-01-27 9:25 ` Miklos Szeredi
2021-01-27 10:20 ` Greg Kurz
2021-01-27 10:20 ` Greg Kurz
2021-01-27 10:34 ` Miklos Szeredi
2021-01-27 10:34 ` Miklos Szeredi
2021-01-27 13:49 ` Greg Kurz
2021-01-27 13:49 ` Greg Kurz
2021-01-27 14:09 ` Miklos Szeredi
2021-01-27 14:09 ` Miklos Szeredi
2021-01-27 15:09 ` Greg Kurz [this message]
2021-01-27 15:09 ` Greg Kurz
2021-01-27 15:22 ` Miklos Szeredi
2021-01-27 15:22 ` Miklos Szeredi
2021-01-27 15:35 ` Greg Kurz
2021-01-27 15:35 ` Greg Kurz
2021-01-27 15:47 ` Miklos Szeredi
2021-01-27 15:47 ` Miklos Szeredi
2021-01-27 15:52 ` Miklos Szeredi
2021-01-27 15:52 ` Miklos Szeredi
2021-01-28 12:14 ` Greg Kurz
2021-01-28 12:14 ` Greg Kurz
2021-01-28 14:00 ` Miklos Szeredi
2021-01-28 14:00 ` Miklos Szeredi
2021-01-28 14:26 ` Greg Kurz
2021-01-28 14:26 ` Greg Kurz
2021-01-27 10:18 ` 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=20210127160920.062e47f0@bahia.lan \
--to=groug@kaod.org \
--cc=alex@alxu.ca \
--cc=berrange@redhat.com \
--cc=lersek@redhat.com \
--cc=mszeredi@redhat.com \
--cc=ppandit@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vgoyal@redhat.com \
--cc=virtio-fs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.