Received: by 2002:aa6:c46f:0:b029:96:faae:e639 with SMTP id i15csp322303lkq; Thu, 5 Nov 2020 03:28:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJx6nTwTT4+owMsDrSSvufg0HCyppgFiZ1qSyhlKzV0vhs4//E7NoU9le7kjtxE+q3oxhfoI X-Received: by 2002:a17:906:578b:: with SMTP id k11mr1836853ejq.330.1604575723653; Thu, 05 Nov 2020 03:28:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604575723; cv=none; d=google.com; s=arc-20160816; b=HBw/XkrvG7W0Ty2DKH7Es1AArL0SUNQ4+7MEKYD1k3C7pZjkRcbVt/O6FE2VtLle3w /DuYqHgCRDvbvCEl+OQ0sVorWwx3IeiRMd/lz+e7m0FbNm9vPQDF6zYKym39Izr85YYK DxN3cqIDhhhESQRF43H35qaNmT6Ws4NY6/GfcxGaXF8SNbANUmqwNH93Yxe38wjI4IE5 mREXVTHb8NeraEQswQpzXgehHpuOkYbUo6Q54pTQlEZJHQiqx6RTWQb/TDZuZNHiXrPV LF1GEbTRi8N5QcpeeQPIaWBI+zCkOpTa51El3qx2U3DmTre5ONVT+fEJSakvQjIQJ2bA V93g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=QErRrNZ/WLQmTtL95bMB5fXEBLHT5lczeUDtzCvnp4g=; b=ehI2Kmm3SFMHPtfY38MpqR0hdl4BKipn+DH0q4qMoIUr5MyYGzzL7MnaFwjYm5MMG5 9El8IMiE28Ep0jr74nJOiJjdlSOqGuGnclfAfECMoTCui0Z6Vgx+2riKSK+QW/BS0QuM FqRBhzJPmtWYQtlwYrCp/d49VYOEY1TTTNNdIheEYkgniJd9HYFXKQxM7F9LQe+FJdo3 WPsPgvI+wQ90iV7nWqxFrwjibyAcRDgzmcu9zzDolGtTBtwysi3aTx1wHCO/M1IKp3Hm aF6R5XQVyEVD/yW6rA75dQyuFQOQfxSka657Gqq2d1yHTtqzWSRJAamF0GuUPmZNMBdP njlQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r22si862906ejc.124.2020.11.05.03.28.21; Thu, 05 Nov 2020 03:28:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730243AbgKELYg (ORCPT + 99 others); Thu, 5 Nov 2020 06:24:36 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:56442 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729263AbgKELYc (ORCPT ); Thu, 5 Nov 2020 06:24:32 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kadNT-0003Wm-Fn; Thu, 05 Nov 2020 11:24:27 +0000 From: Colin King To: Wolfgang Grandegger , "David S . Miller" , Jakub Kicinski , Stephane Grosjean , linux-can@vger.kernel.org, netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] can: usb: fix potential integer overflow on shift of a int Date: Thu, 5 Nov 2020 11:24:27 +0000 Message-Id: <20201105112427.40688-1-colin.king@canonical.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King 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. Addresses-Coverity: ("Unintentional integer overflow") Fixes: bb4785551f64 ("can: usb: PEAK-System Technik USB adapters driver core") Signed-off-by: Colin Ian King --- 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.27.0