]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commit
staging: comedi: dt3000: Fix signed integer overflow 'divider * base'
authorIan Abbott <abbotti@mev.co.uk>
Mon, 12 Aug 2019 11:15:17 +0000 (12:15 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 12 Aug 2019 14:46:07 +0000 (16:46 +0200)
commitb4d98bc3fc93ec3a58459948a2c0e0c9b501cd88
tree1c36825742177089209c1e67f439df3ec37d24bb
parentd45331b00ddb179e291766617259261c112db872
staging: comedi: dt3000: Fix signed integer overflow 'divider * base'

In `dt3k_ns_to_timer()` the following lines near the end of the function
result in a signed integer overflow:

prescale = 15;
base = timer_base * (1 << prescale);
divider = 65535;
*nanosec = divider * base;

(`divider`, `base` and `prescale` are type `int`, `timer_base` and
`*nanosec` are type `unsigned int`.  The value of `timer_base` will be
either 50 or 100.)

The main reason for the overflow is that the calculation for `base` is
completely wrong.  It should be:

base = timer_base * (prescale + 1);

which matches an earlier instance of this calculation in the same
function.

Reported-by: David Binderman <dcb314@hotmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Link: https://lore.kernel.org/r/20190812111517.26803-1-abbotti@mev.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/dt3000.c