linux/drivers/staging
Ian Abbott bafd9c6405 staging: comedi: ni_mio_common: Fix divide-by-zero for DIO cmdtest
`ni_cdio_cmdtest()` validates Comedi asynchronous commands for the DIO
subdevice (subdevice 2) of supported National Instruments M-series
cards.  It is called when handling the `COMEDI_CMD` and `COMEDI_CMDTEST`
ioctls for this subdevice.  There are two causes for a possible
divide-by-zero error when validating that the `stop_arg` member of the
passed-in command is not too large.

The first cause for the divide-by-zero is that calls to
`comedi_bytes_per_scan()` are only valid once the command has been
copied to `s->async->cmd`, but that copy is only done for the
`COMEDI_CMD` ioctl.  For the `COMEDI_CMDTEST` ioctl, it will use
whatever was left there by the previous `COMEDI_CMD` ioctl, if any.
(This is very likely, as it is usual for the application to use
`COMEDI_CMDTEST` before `COMEDI_CMD`.) If there has been no previous,
valid `COMEDI_CMD` for this subdevice, then `comedi_bytes_per_scan()`
will return 0, so the subsequent division in `ni_cdio_cmdtest()` of
`s->async->prealloc_bufsz / comedi_bytes_per_scan(s)` will be a
divide-by-zero error.  To fix this error, call a new function
`comedi_bytes_per_scan_cmd(s, cmd)`, based on the existing
`comedi_bytes_per_scan(s)` but using a specified `struct comedi_cmd` for
its calculations.  (Also refactor `comedi_bytes_per_scan()` to call the
new function.)

Once the first cause for the divide-by-zero has been fixed, the second
cause is that `comedi_bytes_per_scan_cmd()` can legitimately return 0 if
the `scan_end_arg` member of the `struct comedi_cmd` being tested is 0.
Fix it by only performing the division (and validating that `stop_arg`
is no more than the maximum value) if `comedi_bytes_per_scan_cmd()`
returns a non-zero value.

The problem was reported on the COMEDI mailing list here:
https://groups.google.com/forum/#!topic/comedi_list/4t9WlHzMhKM

Reported-by: Ivan Vasilyev <grabesstimme@gmail.com>
Tested-by: Ivan Vasilyev <grabesstimme@gmail.com>
Fixes: f164cbf98f ("staging: comedi: ni_mio_common: add finite regeneration to dio output")
Cc: <stable@vger.kernel.org> # 4.6+
Cc: Spencer E. Olson <olsonse@umich.edu>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-03-18 07:57:58 +01:00
..
android staging: android: ashmem: Avoid range_alloc() allocation with ashmem_mutex held. 2019-02-26 11:50:17 +01:00
axis-fifo staging: axis-fifo: Split line to stay in 80 characters. 2018-11-20 10:59:30 +01:00
board
clocking-wizard staging: clocking-wizard: match parenthesis indentation 2018-10-09 14:57:33 +02:00
comedi staging: comedi: ni_mio_common: Fix divide-by-zero for DIO cmdtest 2019-03-18 07:57:58 +01:00
emxx_udc Staging: emxx_udc: Switch to the gpio descriptor interface 2019-01-15 16:25:58 +01:00
erofs staging: erofs: fix to handle error path of erofs_vmap() 2019-03-18 07:56:14 +01:00
fbtft Staging: fbtft: Fix line over 80 characters 2019-02-26 11:40:07 +01:00
fsl-dpaa2 Staging/IIO patches for 5.1-rc1 2019-03-06 16:29:27 -08:00
fwserial Staging: fwserial: Add blank line after declarations 2019-02-26 11:40:08 +01:00
gasket staging: gasket: interrupt: remove unused including <linux/version.h> 2019-01-22 11:32:36 +01:00
gdm724x
goldfish staging: goldfish: remove GPL boiler plate text 2019-01-15 16:08:04 +01:00
greybus Staging: greybus: Alignment should match open parenthesis 2019-02-26 11:46:51 +01:00
gs_fpgaboot staging: gs_fpgaboot: cleanup alignment issue - style 2019-01-15 16:08:05 +01:00
iio staging: iio: frequency: ad9833: Load clock using clock framework 2019-02-02 17:06:49 +00:00
ks7010 Staging: ks7010: Replace typecast to int 2019-03-01 09:05:01 +01:00
media media updates for v5.1-rc1 2019-03-09 14:45:54 -08:00
most staging: most: cdev: add missing check for cdev_add failure 2019-02-04 12:36:14 +01:00
mt7621-dma staging: mt7621-dma: remove license boilerplate text 2019-03-03 09:25:42 +01:00
mt7621-dts staging: mt7621-dts: update ethernet settings. 2019-03-18 07:55:55 +01:00
mt7621-mmc staging: mt7621-mmc: Prefer using BIT macro 2019-02-19 11:18:00 +01:00
mt7621-pci staging: mt7621-pci: reverse condition to check for enabled port 2019-02-19 11:14:14 +01:00
mt7621-pci-phy staging: mt7621-pci-phy: use 'module_init' instead of 'arch_initcall' 2019-02-19 11:12:08 +01:00
mt7621-pinctrl staging: mt7621-pinctrl: Test devm_kzalloc for failure while improving the code 2019-01-30 15:38:50 +01:00
mt7621-spi staging: mt7621-spi: Clean up comparison to NULL 2019-02-04 12:34:37 +01:00
netlogic staging: netlogic: Remove boilerplate license text 2019-02-26 11:40:07 +01:00
nvec
octeon staging: octeon: fix broken phylib usage 2019-01-30 15:31:24 +01:00
octeon-usb staging: octeon-usb: fix misspelled "re-enable" 2019-02-21 10:58:11 +01:00
olpc_dcon staging: olpc_dcon: olpc_dcon_xo_1.c: Switch to the gpio descriptor interface 2018-11-08 03:59:47 -08:00
pi433 staging: pi433: add missing call to cdev_del() 2018-12-05 09:39:45 +01:00
ralink-gdma staging: Move ralink-gdma to its own directory 2019-01-15 16:28:02 +01:00
rtl8188eu staging: rtl8188eu: remove unused P2P_PRIVATE_IOCTL_SET_LEN 2019-02-28 08:45:28 +01:00
rtl8192e staging: rtl8192e: Fix space and suspect issue 2019-02-28 19:14:53 +01:00
rtl8192u staging: rtl8192u: remove redundant nul check on pointer dev 2019-02-07 13:33:54 +01:00
rtl8712 staging: rtl8712: Fix indentation issue 2019-02-28 08:45:28 +01:00
rtl8723bs Staging/IIO patches for 5.1-rc1 2019-03-06 16:29:27 -08:00
rtlwifi staging: rtlwifi: Use proper enum for return in halmac_parse_psd_data_88xx 2019-02-21 10:58:11 +01:00
rts5208 Staging: rts5208: Fix error handling on rtsx_send_cmd 2019-01-07 11:28:15 +01:00
sm750fb staging: sm750fb: Rename setDisplayControl to set_display_control - style 2019-02-07 13:33:54 +01:00
speakup staging: speakup: fix line over 80 characters. 2019-03-01 09:05:00 +01:00
unisys staging: visornic: use skb_put_zero() instead of open-coded version 2019-02-19 15:35:25 +01:00
vboxvideo staging/vboxvideo: prepare for drmP.h removal from drm_modeset_helper.h 2019-02-07 21:47:29 +01:00
vc04_services media updates for v5.1-rc1 2019-03-09 14:45:54 -08:00
vme
vt6655 Staging: vt6655: Align a static function declaration 2019-03-01 09:05:01 +01:00
vt6656 staging: vt6656: key: Mark expected switch fall-throughs 2019-02-19 11:14:14 +01:00
wilc1000 staging: wilc1000: fix incorrent type in initializer 2019-02-28 08:45:28 +01:00
wlan-ng staging: wlan-ng: formatting change in cfg80211.c 2019-02-08 10:31:14 +01:00
Kconfig staging: remove mt7621-eth 2019-03-18 07:55:55 +01:00
Makefile staging: remove mt7621-eth 2019-03-18 07:55:55 +01:00