]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.14/staging-comedi-ni_usb6501-fix-possible-double-free-of-usb_rx_buf.patch
Linux 4.9.171
[thirdparty/kernel/stable-queue.git] / queue-4.14 / staging-comedi-ni_usb6501-fix-possible-double-free-of-usb_rx_buf.patch
1 From af4b54a2e5ba18259ff9aac445bf546dd60d037e Mon Sep 17 00:00:00 2001
2 From: Ian Abbott <abbotti@mev.co.uk>
3 Date: Mon, 15 Apr 2019 12:43:02 +0100
4 Subject: staging: comedi: ni_usb6501: Fix possible double-free of ->usb_rx_buf
5
6 From: Ian Abbott <abbotti@mev.co.uk>
7
8 commit af4b54a2e5ba18259ff9aac445bf546dd60d037e upstream.
9
10 `ni6501_alloc_usb_buffers()` is called from `ni6501_auto_attach()` to
11 allocate RX and TX buffers for USB transfers. It allocates
12 `devpriv->usb_rx_buf` followed by `devpriv->usb_tx_buf`. If the
13 allocation of `devpriv->usb_tx_buf` fails, it frees
14 `devpriv->usb_rx_buf`, leaving the pointer set dangling, and returns an
15 error. Later, `ni6501_detach()` will be called from the core comedi
16 module code to clean up. `ni6501_detach()` also frees both
17 `devpriv->usb_rx_buf` and `devpriv->usb_tx_buf`, but
18 `devpriv->usb_rx_buf` may have already beed freed, leading to a
19 double-free error. Fix it bu removing the call to
20 `kfree(devpriv->usb_rx_buf)` from `ni6501_alloc_usb_buffers()`, relying
21 on `ni6501_detach()` to free the memory.
22
23 Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
24 Cc: stable <stable@vger.kernel.org>
25 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26
27 ---
28 drivers/staging/comedi/drivers/ni_usb6501.c | 4 +---
29 1 file changed, 1 insertion(+), 3 deletions(-)
30
31 --- a/drivers/staging/comedi/drivers/ni_usb6501.c
32 +++ b/drivers/staging/comedi/drivers/ni_usb6501.c
33 @@ -472,10 +472,8 @@ static int ni6501_alloc_usb_buffers(stru
34
35 size = usb_endpoint_maxp(devpriv->ep_tx);
36 devpriv->usb_tx_buf = kzalloc(size, GFP_KERNEL);
37 - if (!devpriv->usb_tx_buf) {
38 - kfree(devpriv->usb_rx_buf);
39 + if (!devpriv->usb_tx_buf)
40 return -ENOMEM;
41 - }
42
43 return 0;
44 }