linux/drivers/staging/comedi
Ian Abbott 238b5ad855 staging: comedi: fix memory leak / bad pointer freeing for chanlist
As a follow-up to commit 6cab7a37f5 ("staging: comedi: (regression)
channel list must be set for COMEDI_CMD ioctl"), Hartley Sweeten pointed
out another couple of bugs stemming from commit 6cab7a37f5 ("staging:
comedi: comedi_fops: introduce __comedi_get_user_chanlist()").

Firstly, `do_cmdtest_ioctl()` never frees the kernel copy of the user
chanlist allocated by `__comedi_get_user_chanlist()`, so that memory is
leaked.  Fix it by freeing the allocated kernel memory pointed to by
`cmd.chanlist` before that pointer is overwritten with its original
pointer to user memory before `cmd` is copied back to user-space.

Secondly, if `__comedi_get_user_chanlist()` returns an error,
`cmd->chanlist` is left unchanged and in fact will be a pointer to user
memory.  This causes `do_cmd_ioctl()` to `goto cleanup` and call
`do_become_nonbusy()` which would attempt to free the memory pointed to
by the user-space pointer.  Fix it by setting `cmd->chanlist` to NULL at
the start of `__comedi_get_user_chanlist()`.

Fixes: c6cd0eefb2 ("staging: comedi: comedi_fops: introduce __comedi_get_user_chanlist()")
Reported-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: <stable@vger.kernel.org> # 3.15.y 3.16.y 3.17.y: 6cab7a37f5
Cc: <stable@vger.kernel.org> # 3.15.y 3.16.y 3.17.y

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-10-29 16:18:31 +08:00
..
drivers staging: comedi: ni_usb6501: add counter subdevice 2014-09-19 15:58:18 -07:00
kcomedilib Staging: comedi: kcomedilib: replace deprecated simple_strtoul() with kstrtouint() 2014-02-15 12:42:41 -08:00
Kconfig staging: comedi: Kconfig: fix config COMEDI_ADDI_APCI_3120 dependants 2014-10-29 16:18:31 +08:00
Makefile
TODO staging: comedi: TODO: remove item "reserve major number" 2014-05-28 14:18:11 -07:00
comedi.h staging: comedi: add CMDF_ROUND_... as synonyms for TRIG_ROUND_... 2014-09-08 13:50:14 -07:00
comedi_buf.c staging: comedi: migrate copyrights from "comedi_fc.c" 2014-09-19 15:55:32 -07:00
comedi_compat32.c staging: comedi: comedi_compat32: checkpatch.pl --strict cleanup 2014-07-18 16:10:39 -07:00
comedi_compat32.h staging: comedi: comedi_compat32.h: checkpatch.pl --strict cleanup 2014-07-18 16:10:40 -07:00
comedi_fops.c staging: comedi: fix memory leak / bad pointer freeing for chanlist 2014-10-29 16:18:31 +08:00
comedi_internal.h staging: comedi: comedi_internal.h: checkpatch.pl --strict cleanup 2014-07-18 16:10:39 -07:00
comedi_pci.c staging: comedi: comedi_pci: introduce comedi_pci_detach() 2014-08-30 13:24:54 -07:00
comedi_pcmcia.c
comedi_usb.c
comedidev.h staging: comedi: add comedi_read_array_from_buffer() 2014-09-19 15:55:32 -07:00
comedilib.h
drivers.c staging: comedi: migrate copyrights from "comedi_fc.c" 2014-09-19 15:55:32 -07:00
proc.c Staging: comedi: proc: title block update 2014-03-19 04:41:04 +00:00
range.c Staging: comedi: range: remove unnecessary sanity check 2014-03-08 18:59:48 -08:00