linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ming Lei <tom.leiming@gmail.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
	Maxim Patlasov <MPatlasov@parallels.com>,
	Robert Baldyga <r.baldyga@samsung.com>,
	Michal Nazarewicz <mina86@mina86.com>,
	Felipe Balbi <balbi@ti.com>,
	"open list:AIO" <linux-aio@kvack.org>,
	Linux FS Devel <linux-fsdevel@vger.kernel.org>,
	stable <stable@vger.kernel.org>
Subject: Re: [PATCH 06/12] gadgetfs: use-after-free in ->aio_read()
Date: Sun, 8 Mar 2015 18:07:00 +0800	[thread overview]
Message-ID: <CACVXFVMZeiZML6Hxxn1sdObj-cqRO8fv9L+x9T0LuwcMd2Xsbg@mail.gmail.com> (raw)
In-Reply-To: <1424714436-19371-7-git-send-email-hch@lst.de>

On Tue, Feb 24, 2015 at 2:00 AM, Christoph Hellwig <hch@lst.de> wrote:
> From: Al Viro <viro@zeniv.linux.org.uk>
>
> AIO_PREAD requests call ->aio_read() with iovec on caller's stack, so if
> we are going to access it asynchronously, we'd better get ourselves
> a copy - the one on kernel stack of aio_run_iocb() won't be there
> anymore.  function/f_fs.c take care of doing that, legacy/inode.c
> doesn't...
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
>  drivers/usb/gadget/legacy/inode.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
> index db49ec4..9fbbaa0 100644
> --- a/drivers/usb/gadget/legacy/inode.c
> +++ b/drivers/usb/gadget/legacy/inode.c
> @@ -566,7 +566,6 @@ static ssize_t ep_copy_to_user(struct kiocb_priv *priv)
>                 if (total == 0)
>                         break;
>         }
> -
>         return len;
>  }
>
> @@ -585,6 +584,7 @@ static void ep_user_copy_worker(struct work_struct *work)
>         aio_complete(iocb, ret, ret);
>
>         kfree(priv->buf);
> +       kfree(priv->iv);
>         kfree(priv);
>  }
>
> @@ -605,6 +605,7 @@ static void ep_aio_complete(struct usb_ep *ep, struct usb_request *req)
>          */
>         if (priv->iv == NULL || unlikely(req->actual == 0)) {
>                 kfree(req->buf);
> +               kfree(priv->iv);
>                 kfree(priv);
>                 iocb->private = NULL;
>                 /* aio_complete() reports bytes-transferred _and_ faults */
> @@ -640,7 +641,7 @@ ep_aio_rwtail(
>         struct usb_request      *req;
>         ssize_t                 value;
>
> -       priv = kmalloc(sizeof *priv, GFP_KERNEL);
> +       priv = kzalloc(sizeof *priv, GFP_KERNEL);
>         if (!priv) {
>                 value = -ENOMEM;
>  fail:
> @@ -649,7 +650,14 @@ fail:
>         }
>         iocb->private = priv;
>         priv->iocb = iocb;
> -       priv->iv = iv;
> +       if (iv) {
> +               priv->iv = kmemdup(iv, nr_segs * sizeof(struct iovec),
> +                                  GFP_KERNEL);
> +               if (!priv->iv) {
> +                       kfree(priv);
> +                       goto fail;
> +               }
> +       }

It should be simpler and more efficient to allocate 'iv' piggyback
inside 'priv'.

>         priv->nr_segs = nr_segs;
>         INIT_WORK(&priv->work, ep_user_copy_worker);
>
> @@ -689,6 +697,7 @@ fail:
>         mutex_unlock(&epdata->lock);
>
>         if (unlikely(value)) {
> +               kfree(priv->iv);
>                 kfree(priv);
>                 put_ep(epdata);
>         } else
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



Thanks,
Ming Lei

  reply	other threads:[~2015-03-08 10:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-23 18:00 [RFC] split struct kiocb Christoph Hellwig
2015-02-23 18:00 ` [PATCH 01/12] new helper: dup_iter() Christoph Hellwig
2015-02-23 18:00 ` [PATCH 02/12] move iov_iter.c from mm/ to lib/ Christoph Hellwig
2015-02-23 18:00 ` [PATCH 03/12] gadget/function/f_fs.c: close leaks Christoph Hellwig
2015-02-23 18:00 ` [PATCH 04/12] gadget/function/f_fs.c: use put iov_iter into io_data Christoph Hellwig
2015-02-23 18:00 ` [PATCH 05/12] gadget/function/f_fs.c: switch to ->{read,write}_iter() Christoph Hellwig
2015-02-23 18:00 ` [PATCH 06/12] gadgetfs: use-after-free in ->aio_read() Christoph Hellwig
2015-03-08 10:07   ` Ming Lei [this message]
2015-03-09 15:18     ` Michal Nazarewicz
2015-02-23 18:00 ` [PATCH 07/12] gadget: switch ep_io_operations to ->read_iter/->write_iter Christoph Hellwig
2015-02-23 18:00 ` [PATCH 08/12] fs: remove ki_nbytes Christoph Hellwig
2015-02-23 18:00 ` [PATCH 09/12] fuse: handle synchronous iocbs internally Christoph Hellwig
2015-03-06  2:54   ` Maxim Patlasov
2015-02-23 18:00 ` [PATCH 10/12] fs: don't allow to complete sync iocbs through aio_complete Christoph Hellwig
2015-02-23 18:00 ` [PATCH 11/12] fs: split generic and aio kiocb Christoph Hellwig
2015-02-23 18:00 ` [PATCH 12/12] fs: move struct kiocb to fs.h Christoph Hellwig
2015-02-23 21:20 ` [RFC] split struct kiocb Al Viro
2015-02-23 21:22   ` Christoph Hellwig
2015-02-23 21:39     ` Al Viro
2015-02-24  3:47       ` Al Viro
2015-02-23 21:23   ` Felipe Balbi
2015-02-23 21:42     ` Al Viro
2015-02-23 21:50       ` Felipe Balbi
2015-02-25 17:13   ` Felipe Balbi

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=CACVXFVMZeiZML6Hxxn1sdObj-cqRO8fv9L+x9T0LuwcMd2Xsbg@mail.gmail.com \
    --to=tom.leiming@gmail.com \
    --cc=MPatlasov@parallels.com \
    --cc=balbi@ti.com \
    --cc=hch@lst.de \
    --cc=linux-aio@kvack.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mina86@mina86.com \
    --cc=r.baldyga@samsung.com \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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).