From: Lars-Peter Clausen Date: Thu, 14 Apr 2016 15:01:17 +0000 (+0200) Subject: usb: gadget: f_fs: Fix use-after-free X-Git-Tag: v4.1.12-92~15^2~181 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=e4a0b40e0937a4c08a2626561aa64636dddb41a9;p=users%2Fjedix%2Flinux-maple.git usb: gadget: f_fs: Fix use-after-free Orabug: 25227130 [ Upstream commit 38740a5b87d53ceb89eb2c970150f6e94e00373a ] When using asynchronous read or write operations on the USB endpoints the issuer of the IO request is notified by calling the ki_complete() callback of the submitted kiocb when the URB has been completed. Calling this ki_complete() callback will free kiocb. Make sure that the structure is no longer accessed beyond that point, otherwise undefined behaviour might occur. Fixes: 2e4c7553cd6f ("usb: gadget: f_fs: add aio support") Cc: # v3.15+ Signed-off-by: Lars-Peter Clausen Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin (cherry picked from commit 0763ce11708553fc7b2124f184ce2e4bb0cb186d) Signed-off-by: Dhaval Giani --- diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 6e7be91e6097c..82240dbdf6ddf 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -646,6 +646,7 @@ static void ffs_user_copy_worker(struct work_struct *work) work); int ret = io_data->req->status ? io_data->req->status : io_data->req->actual; + bool kiocb_has_eventfd = io_data->kiocb->ki_flags & IOCB_EVENTFD; if (io_data->read && ret > 0) { use_mm(io_data->mm); @@ -657,13 +658,11 @@ static void ffs_user_copy_worker(struct work_struct *work) io_data->kiocb->ki_complete(io_data->kiocb, ret, ret); - if (io_data->ffs->ffs_eventfd && - !(io_data->kiocb->ki_flags & IOCB_EVENTFD)) + if (io_data->ffs->ffs_eventfd && !kiocb_has_eventfd) eventfd_signal(io_data->ffs->ffs_eventfd, 1); usb_ep_free_request(io_data->ep, io_data->req); - io_data->kiocb->private = NULL; if (io_data->read) kfree(io_data->to_free); kfree(io_data->buf);