linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org,
	kernel@pengutronix.de, Colin Ian King <colin.king@canonical.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [net 06/15] can: peak_usb: fix potential integer overflow on shift of a int
Date: Sun, 15 Nov 2020 18:41:22 +0100	[thread overview]
Message-ID: <20201115174131.2089251-7-mkl@pengutronix.de> (raw)
In-Reply-To: <20201115174131.2089251-1-mkl@pengutronix.de>

From: Colin Ian King <colin.king@canonical.com>

The left shift of int 32 bit integer constant 1 is evaluated using 32 bit
arithmetic and then assigned to a signed 64 bit variable. In the case where
time_ref->adapter->ts_used_bits is 32 or more this can lead to an oveflow.
Avoid this by shifting using the BIT_ULL macro instead.

Fixes: bb4785551f64 ("can: usb: PEAK-System Technik USB adapters driver core")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Link: https://lore.kernel.org/r/20201105112427.40688-1-colin.king@canonical.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/peak_usb/pcan_usb_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index c2764799f9ef..204ccb27d6d9 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -156,7 +156,7 @@ void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time)
 		if (time_ref->ts_dev_1 < time_ref->ts_dev_2) {
 			/* case when event time (tsw) wraps */
 			if (ts < time_ref->ts_dev_1)
-				delta_ts = 1 << time_ref->adapter->ts_used_bits;
+				delta_ts = BIT_ULL(time_ref->adapter->ts_used_bits);
 
 		/* Otherwise, sync time counter (ts_dev_2) has wrapped:
 		 * handle case when event time (tsn) hasn't.
@@ -168,7 +168,7 @@ void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *time)
 		 *              tsn            ts
 		 */
 		} else if (time_ref->ts_dev_1 < ts) {
-			delta_ts = -(1 << time_ref->adapter->ts_used_bits);
+			delta_ts = -BIT_ULL(time_ref->adapter->ts_used_bits);
 		}
 
 		/* add delay between last sync and event timestamps */
-- 
2.29.2


  parent reply	other threads:[~2020-11-15 17:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-15 17:41 pull-request: can 2020-11-15 Marc Kleine-Budde
2020-11-15 17:41 ` [net 01/15] can: af_can: prevent potential access of uninitialized member in can_rcv() Marc Kleine-Budde
2020-11-15 17:41 ` [net 02/15] can: af_can: prevent potential access of uninitialized member in canfd_rcv() Marc Kleine-Budde
2020-11-15 17:41 ` [net 03/15] can: dev: can_restart(): post buffer from the right context Marc Kleine-Budde
2020-11-15 17:41 ` [net 04/15] can: ti_hecc: Fix memleak in ti_hecc_probe Marc Kleine-Budde
2020-11-15 17:41 ` [net 05/15] can: mcba_usb: mcba_usb_start_xmit(): first fill skb, then pass to can_put_echo_skb() Marc Kleine-Budde
2020-11-15 17:41 ` Marc Kleine-Budde [this message]
2020-11-15 17:41 ` [net 07/15] can: flexcan: flexcan_setup_stop_mode(): add missing "req_bit" to stop mode property comment Marc Kleine-Budde
2020-11-15 17:41 ` [net 08/15] can: flexcan: fix failure handling of pm_runtime_get_sync() Marc Kleine-Budde
2020-11-15 17:41 ` [net 09/15] can: tcan4x5x: replace depends on REGMAP_SPI with depends on SPI Marc Kleine-Budde
2020-11-15 17:41 ` [net 10/15] can: tcan4x5x: tcan4x5x_can_probe(): add missing error checking for devm_regmap_init() Marc Kleine-Budde
2020-11-17 14:01   ` Dan Murphy
2020-11-15 17:41 ` [net 11/15] can: tcan4x5x: tcan4x5x_can_remove(): fix order of deregistration Marc Kleine-Budde
2020-11-17 14:00   ` Dan Murphy
2020-11-17 14:02     ` Marc Kleine-Budde
2020-11-15 17:41 ` [net 12/15] can: m_can: m_can_handle_state_change(): fix state change Marc Kleine-Budde
2020-11-17 14:01   ` Dan Murphy
2020-11-15 17:41 ` [net 13/15] can: m_can: m_can_class_free_dev(): introduce new function Marc Kleine-Budde
2020-11-15 17:41 ` [net 14/15] can: m_can: Fix freeing of can device from peripherials Marc Kleine-Budde
2020-11-15 17:41 ` [net 15/15] can: m_can: m_can_stop(): set device to software init mode before closing Marc Kleine-Budde
2020-11-16 15:37 ` pull-request: can 2020-11-15 Jakub Kicinski
  -- strict thread matches above, loose matches on Subject: below --
2020-11-14 17:33 pull-request: can 2020-11-14 Marc Kleine-Budde
2020-11-14 17:33 ` [net 06/15] can: peak_usb: fix potential integer overflow on shift of a int Marc Kleine-Budde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201115174131.2089251-7-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=colin.king@canonical.com \
    --cc=davem@davemloft.net \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).