Commit 0b4b4c30 authored by Al Viro's avatar Al Viro Committed by Zefan Li

gadgetfs: use-after-free in ->aio_read()

commit f01d35a1 upstream.

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...
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
[lizf: Backproted to 3.4:
 - adjust context
 - need kfree() after calling get_ready_ep()]
Signed-off-by: default avatarZefan Li <lizefan@huawei.com>
parent 464e5035
......@@ -570,6 +570,7 @@ static ssize_t ep_aio_read_retry(struct kiocb *iocb)
break;
}
kfree(priv->buf);
kfree(priv->iv);
kfree(priv);
return len;
}
......@@ -591,6 +592,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 */
......@@ -626,7 +628,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:
......@@ -634,11 +636,19 @@ ep_aio_rwtail(
return value;
}
iocb->private = priv;
priv->iv = iv;
if (iv) {
priv->iv = kmemdup(iv, nr_segs * sizeof(struct iovec),
GFP_KERNEL);
if (!priv->iv) {
kfree(priv);
goto fail;
}
}
priv->nr_segs = nr_segs;
value = get_ready_ep(iocb->ki_filp->f_flags, epdata);
if (unlikely(value < 0)) {
kfree(priv->iv);
kfree(priv);
goto fail;
}
......@@ -672,6 +682,7 @@ ep_aio_rwtail(
mutex_unlock(&epdata->lock);
if (unlikely(value)) {
kfree(priv->iv);
kfree(priv);
put_ep(epdata);
} else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment