From patchwork Thu Sep 10 03:25:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koba Ko X-Patchwork-Id: 1361185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bn45s5M0fz9sV8; Thu, 10 Sep 2020 13:25:37 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1kGDDK-0001p4-FO; Thu, 10 Sep 2020 03:25:34 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kGDDH-0001ns-Eb for kernel-team@lists.ubuntu.com; Thu, 10 Sep 2020 03:25:31 +0000 Received: from mail-pf1-f197.google.com ([209.85.210.197]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kGDDH-0002uz-3T for kernel-team@lists.ubuntu.com; Thu, 10 Sep 2020 03:25:31 +0000 Received: by mail-pf1-f197.google.com with SMTP id i16so2456946pfk.1 for ; Wed, 09 Sep 2020 20:25:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=CPL1+SnOyHjEq6Z2t5fYnuWjStj71FeNSDzzcrQAHVo=; b=iDIAsSR3cJpDk/84wfecCcP97CSZOmCMtSFNUw2AmSeQ1wx9m8t+OdDc0BBLEJri3d qWIIXkzK20AacBExmRlgpnCZ3x4CfngqM8YkXVaPFLegS+Kv4aOCai/UWlz7zGhWHHjH qkhMhlQorEiKv94ty3TkEq0jhTVgn97DmOYbh1nJg12j8dBygybk3DiU98UK/QeZspuw gzlD9pN15biF13ngrTKmLtiQeNRENuh+NLq6yZ1Rm2qEFN8439pzBgkOgo0VgePjIE1y p/tTOYrYMinyM6DAqBhuTWi4y+GCPgoCCkYfSCf172fShrX4RkWhq5TYd/Tjvct9qNK8 v5Xg== X-Gm-Message-State: AOAM533DX4D4H9aW/aHwrWs/qsfgID5h7fZ7FsPbSKlvo5g+RQuuwrV8 Qa+AA0NJdO17zWjvZzBvXa5MXDSWPLMtTCz4iRfNElqgDCpzWtCrFTiVBIXfD4mkrfPPaSt2x1o htKRUnspbiA2HrRuubGTxEGclh2vJkDlKqe2HVKE7hg== X-Received: by 2002:a17:90b:3444:: with SMTP id lj4mr3286485pjb.78.1599708329608; Wed, 09 Sep 2020 20:25:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJww4psQLR3wgfLF03Pz2Jg2rPJ00etA2213Xi3q4qsxG3PEOyMMvJrttRnDxhCYUVeBuBDz/Q== X-Received: by 2002:a17:90b:3444:: with SMTP id lj4mr3286471pjb.78.1599708329276; Wed, 09 Sep 2020 20:25:29 -0700 (PDT) Received: from canonical.com (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id v205sm3980540pfc.110.2020.09.09.20.25.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 Sep 2020 20:25:28 -0700 (PDT) From: Koba Ko To: kernel-team@lists.ubuntu.com Subject: [PATCH 8/8][SRU][OEM-5.6] thunderbolt: Ensure left shift of 512 does not overflow a 32 bit int Date: Thu, 10 Sep 2020 11:25:05 +0800 Message-Id: <20200910032505.10882-9-koba.ko@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910032505.10882-1-koba.ko@canonical.com> References: <20200910032505.10882-1-koba.ko@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Colin Ian King BugLink: https://bugs.launchpad.net/bugs/1895073 The 32 bit int value 512 is being left shifted and then used in a context that expects the expression to be a larger unsigned long. There may be a potential integer overflow, so make 512 a UL before shift to avoid any such issues. Addresses-Coverity: ("Uninintentional integer overflow") Fixes: 3b1d8d577ca8 ("thunderbolt: Implement USB3 bandwidth negotiation routines") Signed-off-by: Colin Ian King Signed-off-by: Mika Westerberg (cherry picked from commit 4c767ce48cf858971545164c4c53d028e6241c07) Signed-off-by: Koba Ko --- drivers/thunderbolt/usb4.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/thunderbolt/usb4.c b/drivers/thunderbolt/usb4.c index 5c8b3b95ce12..997a86a68cb2 100644 --- a/drivers/thunderbolt/usb4.c +++ b/drivers/thunderbolt/usb4.c @@ -1349,7 +1349,7 @@ static unsigned int usb3_bw_to_mbps(u32 bw, u8 scale) { unsigned long uframes; - uframes = bw * 512 << scale; + uframes = bw * 512UL << scale; return DIV_ROUND_CLOSEST(uframes * 8000, 1000 * 1000); } @@ -1359,7 +1359,7 @@ static u32 mbps_to_usb3_bw(unsigned int mbps, u8 scale) /* 1 uframe is 1/8 ms (125 us) -> 1 / 8000 s */ uframes = ((unsigned long)mbps * 1000 * 1000) / 8000; - return DIV_ROUND_UP(uframes, 512 << scale); + return DIV_ROUND_UP(uframes, 512UL << scale); } static int usb4_usb3_port_read_allocated_bandwidth(struct tb_port *port,