From: Greg Kurz <groug@kaod.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: P J P <ppandit@redhat.com>,
Qemu Developers <qemu-devel@nongnu.org>,
Prasad J Pandit <pjp@fedoraproject.org>,
"Michael S. Tsirkin" <mtsirkin@redhat.com>,
Felix Wilhelm <fwilhelm@ernw.de>,
"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH] 9pfs: add check for relative path
Date: Fri, 19 Aug 2016 18:24:14 +0200 [thread overview]
Message-ID: <20160819182414.22da61e1@bahia.lan> (raw)
In-Reply-To: <CAFEAcA9w-DhDL2kqUKQKSxaUUj+wniZKCUSLYd55U6f4QsgiyQ@mail.gmail.com>
On Fri, 19 Aug 2016 15:55:17 +0100
Peter Maydell <peter.maydell@linaro.org> wrote:
> On 11 August 2016 at 06:13, P J P <ppandit@redhat.com> wrote:
> > From: Prasad J Pandit <pjp@fedoraproject.org>
> >
> > At various places in 9pfs back-end, it creates full path by
> > concatenating two path strings. It could lead to a path
> > traversal issue if one of the parameter was a relative path.
> > Add check to avoid it.
> >
> > Reported-by: Felix Wilhelm <fwilhelm@ernw.de>
> > Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> > ---
> > hw/9pfs/9p-local.c | 31 +++++++++++++++++++++++++++----
> > 1 file changed, 27 insertions(+), 4 deletions(-)
> >
> > diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
> > index 3f271fc..c20331a 100644
> > --- a/hw/9pfs/9p-local.c
> > +++ b/hw/9pfs/9p-local.c
> > @@ -493,6 +493,9 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
> > char *buffer = NULL;
> >
> > v9fs_string_init(&fullname);
> > + if (strstr(name, "../")) {
> > + return err;
> > + }
>
> I think we also need to set errno in these error paths: the functions
> which call all these hooks in hw/9pfs/cofs.c all do:
> err = s->ops->mknod(&s->ctx, &fidp->path, name->data, &cred);
> if (err < 0) {
> err = -errno;
> } else {
> /* success path */
> }
> return err;
>
> so we must set errno appropriately if we're going to return -1.
>
Indeed. Thanks Peter for pointing this out !
> Also, strstr(name, "../") is the wrong check. There are I think
> two possibilities here:
>
> (1) the "name" parameter may only validly be a single pathname
> component. In this case we should be enforcing this by treating
> any string with a "/" in it as an error (and checking for "../"
> is not catching all the cases that should be errors).
>
> (2) the "name" parameter may be a multiple-pathname-component value.
> In this case "../" catches too many cases, because "foo../bar" is
> a valid string which is not relative. You would need to check for
> (contains "/../" OR starts with "../" OR ends with "/.." OR is "..").
>
>
> On IRC Greg and I discussed this and Greg suggested that
> case (1) is what we have. We should check this though.
>
And this seems to be the case indeed when looking at:
http://man.cat-v.org/plan_9/5/walk
It is also ok for a system to reduce the valid character set
for path components according to:
http://man.cat-v.org/plan_9/5/intro
Peter's suggestion to forbid / in names seems the way to go.
> Finally: what about the functions in this file which
> create a local filename by calling rpath() ? Are those
> all definitely OK or do some or all of those also need
> check code?
>
This needs a closer look.
> thanks
> -- PMM
Thanks for your assistance Peter !
--
Greg
prev parent reply other threads:[~2016-08-19 16:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-11 5:13 [Qemu-devel] [PATCH] 9pfs: add check for relative path P J P
2016-08-11 6:17 ` no-reply
2016-08-11 6:27 ` Fam Zheng
2016-08-18 16:55 ` Greg Kurz
2016-08-11 6:31 ` Aneesh Kumar K.V
2016-08-18 15:19 ` Greg Kurz
2016-08-18 17:06 ` Greg Kurz
2016-08-19 14:55 ` Peter Maydell
2016-08-19 15:14 ` Peter Maydell
2016-08-19 16:37 ` Greg Kurz
2016-08-19 17:03 ` Peter Maydell
2016-08-19 17:30 ` Greg Kurz
2016-08-22 9:23 ` Peter Maydell
2016-08-22 10:07 ` P J P
2016-08-22 15:02 ` Michael S. Tsirkin
2016-08-22 15:07 ` Peter Maydell
2016-08-22 14:14 ` Michael S. Tsirkin
2016-08-19 16:24 ` Greg Kurz [this message]
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=20160819182414.22da61e1@bahia.lan \
--to=groug@kaod.org \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=fwilhelm@ernw.de \
--cc=mtsirkin@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=pjp@fedoraproject.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 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).