From: Greg Kurz <groug@kaod.org>
To: Eric Blake <eblake@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
Felix Wilhelm <fwilhelm@ernw.de>,
"Michael S. Tsirkin" <mst@redhat.com>,
qemu-devel@nongnu.org, P J P <ppandit@redhat.com>,
"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v2 5/5] 9p: forbid empty extension string
Date: Sun, 28 Aug 2016 19:34:49 +0200 [thread overview]
Message-ID: <20160828193449.0bcde2f7@bahia.lan> (raw)
In-Reply-To: <20160828192125.1f1ad6f9@bahia.lan>
[-- Attachment #1: Type: text/plain, Size: 4651 bytes --]
On Sun, 28 Aug 2016 19:21:25 +0200
Greg Kurz <groug@kaod.org> wrote:
> On Fri, 26 Aug 2016 14:00:37 -0500
> Eric Blake <eblake@redhat.com> wrote:
>
> > On 08/26/2016 10:07 AM, Greg Kurz wrote:
> > > A buggy guest using the 9p2000.u protocol can issue a create request and
> > > pass an empty string as the extension argument. This causes QEMU to crash
> > > in the case of a hard link or a special file, and leads to undefined
> > > behavior, depending on the backend, in the case of a symbolic link.
> > >
> > > This patch causes the request to fail with EINVAL in these scenarios.
> > >
> > > Signed-off-by: Greg Kurz <groug@kaod.org>
> > > ---
>
> Wait... empty strings coming from pdu_unmarshal() never have data == NULL
> so this whole patch is pointless :) and BTW, only the symlink case is about
> file names.
>
> > > hw/9pfs/9p.c | 21 +++++++++++++++++++--
> > > 1 file changed, 19 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> > > index 7b1dfe4e47cb..dc65c3125006 100644
> > > --- a/hw/9pfs/9p.c
> > > +++ b/hw/9pfs/9p.c
> > > @@ -2150,6 +2150,11 @@ static void v9fs_create(void *opaque)
> > > }
> > > fidp->fid_type = P9_FID_DIR;
> > > } else if (perm & P9_STAT_MODE_SYMLINK) {
> > > + if (extension.data == NULL) {
> > > + err = -EINVAL;
> > > + goto out;
> > > + }
> >
>
> I realize that this part belongs to patch 1 actually: it is the implementation of
> symbolic links that comes with 9P2000.u (different from the TSYMLINK request in
> 9P2000.L). In which case, the hunk would have been:
>
> + if (name_is_illegal(extension.data)) {
> + err = -EINVAL;
> + goto out;
> + }
>
> > POSIX specifically requires implementations to support creating a
> > symlink whose target is the empty string. Linux doesn't [yet] permit
> > it, but BSD does. On systems where creating such a symlink is legal,
> > POSIX requires that such a symlink either be treated as "." if
> > dereferenced, or be treated as ENOENT on attempt to dereference. But
> > since such links can be created, readlink() should be able to read them
> > without error.
> >
> > I would argue that we should NOT forbid empty symlinks on creation (but
> > pass back any error from the underlying host OS); but instead check that
> > dereferencing such a symlink behaves sanely if it was created.
> > Meanwhile, a client should not be relying on the behavior (since Linux
> > disobeys POSIX, portable clients should already be avoiding empty symlinks).
> >
> > http://austingroupbugs.net/view.php?id=649
> >
>
> Indeed, maybe we should let the backend decide if it allows symlink with
> an empty target, since the target name is simply "stored" somewhere and
> not used to create a new path. In which case, we should do the same with
> v9fs_symlink(). And we would have two exceptions to the name_is_illegal()
> helper, because we still want to avoid '/' in file names...
>
Thinking again... I guess '/' in names should result in ENOENT since it seems
to be a common way to say something is wrong with a path... or we should have
separate error paths between the '/'-in-names and the empty name cases.
> On the other hand, we only support linux hosts where the call to symlink()
> will fail with ENOENT and guests using the official linux kernel 9p client
> never send an empty target...
>
> For the sake of simplicity, I'd rather have the target names to follow the
> same rules as other file names, and return ENOENT directly (the link you
> provide states it is a valid option).
>
> Peter,
>
> Since you suggested to do explicit error checking on empty file names, do
> you have an opinion on the case of symlinks with an empty target ?
>
> > > @@ -2161,8 +2166,15 @@ static void v9fs_create(void *opaque)
> > > }
> > > v9fs_path_copy(&fidp->path, &path);
> > > } else if (perm & P9_STAT_MODE_LINK) {
> > > - int32_t ofid = atoi(extension.data);
> > > - V9fsFidState *ofidp = get_fid(pdu, ofid);
> > > + V9fsFidState *ofidp;
> > > +
> > > + if (extension.data == NULL) {
> > > + err = -EINVAL;
> > > + goto out;
> > > + }
> >
> > Rejecting an empty destination on hard link or device creation, however,
> > is indeed appropriate.
> >
>
> In the case of hard links, extension.data is a FID, not a file name.
>
> In the case of device creation, extension.data is "type major minor", not
> a file name again.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
next prev parent reply other threads:[~2016-08-28 17:35 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-26 15:06 [Qemu-devel] [PATCH v2 0/5] 9P security fixes Greg Kurz
2016-08-26 15:07 ` [Qemu-devel] [PATCH v2 1/5] 9p: forbid illegal path names Greg Kurz
2016-08-26 18:33 ` Eric Blake
2016-08-28 13:11 ` Greg Kurz
2016-08-26 15:07 ` [Qemu-devel] [PATCH v2 2/5] 9p: disallow the NUL character in all strings Greg Kurz
2016-08-26 18:41 ` Eric Blake
2016-08-28 13:33 ` Greg Kurz
2016-08-28 22:19 ` Greg Kurz
2016-08-26 15:07 ` [Qemu-devel] [PATCH v2 3/5] 9p: forbid . and .. in file names Greg Kurz
2016-08-26 18:49 ` Eric Blake
2016-08-28 14:06 ` Greg Kurz
2016-08-26 15:07 ` [Qemu-devel] [PATCH v2 4/5] 9p: handle walk of ".." in the root directory Greg Kurz
2016-08-26 18:52 ` Eric Blake
2016-08-26 15:07 ` [Qemu-devel] [PATCH v2 5/5] 9p: forbid empty extension string Greg Kurz
2016-08-26 19:00 ` Eric Blake
2016-08-26 19:10 ` Michael S. Tsirkin
2016-08-28 17:21 ` Greg Kurz
2016-08-28 17:34 ` Greg Kurz [this message]
2016-08-29 19:35 ` Eric Blake
2016-08-30 16:46 ` Greg Kurz
2016-08-28 19:41 ` Peter Maydell
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=20160828193449.0bcde2f7@bahia.lan \
--to=groug@kaod.org \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=eblake@redhat.com \
--cc=fwilhelm@ernw.de \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=ppandit@redhat.com \
--cc=qemu-devel@nongnu.org \
/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.