diff options
author | Matthieu CASTET <matthieu.castet@parrot.com> | 2012-06-28 16:51:56 +0200 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2012-10-10 03:31:17 +0100 |
commit | 3313aa9015c7c868a9bcdb7b1c143719d2873a66 (patch) | |
tree | 22614ac4d4912cb46d9ac2acafbc44ff0934b66e | |
parent | 9c48cc08ae1255d4b244529408f52d26673e1ccb (diff) | |
download | linux-stable-3313aa9015c7c868a9bcdb7b1c143719d2873a66.tar.gz linux-stable-3313aa9015c7c868a9bcdb7b1c143719d2873a66.tar.bz2 linux-stable-3313aa9015c7c868a9bcdb7b1c143719d2873a66.zip |
HID: hidraw: fix list->buffer memleak
commit 4c7b417ecb756e85dfc955b0e7a04fd45585533e upstream.
If we don't read fast enough hidraw device, hidraw_report_event
will cycle and we will leak list->buffer.
Also list->buffer are not free on release.
After this patch, kmemleak report nothing.
Signed-off-by: Matthieu CASTET <matthieu.castet@parrot.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | drivers/hid/hidraw.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c index 36fa77b40ffb..3b6f7bf5a77e 100644 --- a/drivers/hid/hidraw.c +++ b/drivers/hid/hidraw.c @@ -96,6 +96,7 @@ static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count, } kfree(list->buffer[list->tail].value); + list->buffer[list->tail].value = NULL; list->tail = (list->tail + 1) & (HIDRAW_BUFFER_SIZE - 1); } out: @@ -300,6 +301,7 @@ static int hidraw_release(struct inode * inode, struct file * file) struct hidraw *dev; struct hidraw_list *list = file->private_data; int ret; + int i; mutex_lock(&minors_lock); if (!hidraw_table[minor]) { @@ -317,6 +319,9 @@ static int hidraw_release(struct inode * inode, struct file * file) kfree(list->hidraw); } } + + for (i = 0; i < HIDRAW_BUFFER_SIZE; ++i) + kfree(list->buffer[i].value); kfree(list); ret = 0; unlock: @@ -446,12 +451,17 @@ int hidraw_report_event(struct hid_device *hid, u8 *data, int len) int ret = 0; list_for_each_entry(list, &dev->list, node) { + int new_head = (list->head + 1) & (HIDRAW_BUFFER_SIZE - 1); + + if (new_head == list->tail) + continue; + if (!(list->buffer[list->head].value = kmemdup(data, len, GFP_ATOMIC))) { ret = -ENOMEM; break; } list->buffer[list->head].len = len; - list->head = (list->head + 1) & (HIDRAW_BUFFER_SIZE - 1); + list->head = new_head; kill_fasync(&list->fasync, SIGIO, POLL_IN); } |