Skip to contentSkip to conversation

patch "staging: comedi: dt3000: Fix signed integer overflow 'divider * base'" added to staging-linus

PATCH [email protected] 1 participant 1 message Aug 12, 2019

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

staging: comedi: dt3000: Fix signed integer overflow 'divider * base'

to my staging git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git
in the staging-linus branch.

The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)

The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.

If you have any questions about this process, please let me know.

From b4d98bc3fc93ec3a58459948a2c0e0c9b501cd88 Mon Sep 17 00:00:00 2001
From: Ian Abbott <[email protected]>
Date: Mon, 12 Aug 2019 12:15:17 +0100
Subject: 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.

---
 drivers/staging/comedi/drivers/dt3000.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/comedi/drivers/dt3000.c +1 -1
index 2edf3ee91300..4ad176fc14ad 100644
@@ -368,7 +368,7 @@ static int dt3k_ns_to_timer(unsigned int timer_base, unsigned int *nanosec,
 	}
 
 	prescale = 15;
-	base = timer_base * (1 << prescale);
+	base = timer_base * (prescale + 1);
 	divider = 65535;
 	*nanosec = divider * base;
 	return (prescale << 16) | (divider);
Signature · 1 line
2.22.0