diff options
author | Andrzej Pietrasiewicz <andrzej.p@samsung.com> | 2014-01-20 02:33:50 -0500 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2014-02-20 10:17:23 -0500 |
commit | f0f42204d0cc04a63ac61fdaa3b6a269ea0dc08b (patch) | |
tree | 5e564e3f582d872a91433cc62dc1fa3ff8007cbd | |
parent | 8679059e360543b7afecd228ada6566da9f304a4 (diff) |
usb: gadget: fix NULL pointer dereference
Fix possible NULL pointer dereference introduced in
commit 219580e (usb: f_fs: check quirk to pad epout
buf size when not aligned to maxpacketsize)
In cases we do wait with:
wait_event_interruptible(epfile->wait, (ep = epfile->ep));
for endpoint to be enabled, functionfs_bind() has not been called yet
and epfile->ffs->gadget is still NULL and the automatic variable 'gadget'
has been initialized with NULL at the point of its definition.
Later on it is used as a parameter to:
usb_ep_align_maybe(gadget, ep->ep, len)
which in turn dereferences it.
This patch fixes it by moving the actual assignment to the local 'gadget'
variable after the potential waiting has completed.
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r-- | drivers/usb/gadget/f_fs.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c index 306a2b52125c..2b4334394076 100644 --- a/drivers/usb/gadget/f_fs.c +++ b/drivers/usb/gadget/f_fs.c | |||
@@ -585,7 +585,6 @@ static ssize_t ffs_epfile_io(struct file *file, | |||
585 | char __user *buf, size_t len, int read) | 585 | char __user *buf, size_t len, int read) |
586 | { | 586 | { |
587 | struct ffs_epfile *epfile = file->private_data; | 587 | struct ffs_epfile *epfile = file->private_data; |
588 | struct usb_gadget *gadget = epfile->ffs->gadget; | ||
589 | struct ffs_ep *ep; | 588 | struct ffs_ep *ep; |
590 | char *data = NULL; | 589 | char *data = NULL; |
591 | ssize_t ret, data_len; | 590 | ssize_t ret, data_len; |
@@ -622,6 +621,12 @@ static ssize_t ffs_epfile_io(struct file *file, | |||
622 | /* Allocate & copy */ | 621 | /* Allocate & copy */ |
623 | if (!halt) { | 622 | if (!halt) { |
624 | /* | 623 | /* |
624 | * if we _do_ wait above, the epfile->ffs->gadget might be NULL | ||
625 | * before the waiting completes, so do not assign to 'gadget' earlier | ||
626 | */ | ||
627 | struct usb_gadget *gadget = epfile->ffs->gadget; | ||
628 | |||
629 | /* | ||
625 | * Controller may require buffer size to be aligned to | 630 | * Controller may require buffer size to be aligned to |
626 | * maxpacketsize of an out endpoint. | 631 | * maxpacketsize of an out endpoint. |
627 | */ | 632 | */ |