From patchwork Thu Sep 10 03:45:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Koba Ko X-Patchwork-Id: 1361199 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 4Bn4bt055Wz9sTd; Thu, 10 Sep 2020 13:48:10 +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 1kGDZ9-0003yw-5C; Thu, 10 Sep 2020 03:48:07 +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 1kGDZ7-0003yq-Rd for kernel-team@lists.ubuntu.com; Thu, 10 Sep 2020 03:48:05 +0000 Received: from mail-pl1-f198.google.com ([209.85.214.198]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kGDWv-0004MW-Nz for kernel-team@lists.ubuntu.com; Thu, 10 Sep 2020 03:46:08 +0000 Received: by mail-pl1-f198.google.com with SMTP id o6so287070pll.9 for ; Wed, 09 Sep 2020 20:45:49 -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=umPvUG2cOKuZUmeK6r9mCBdqVp3osk+/wmNBgr5HuyE=; b=fPBePzjT7/yGTnwjqsXyD60Ua1dyPm0eNa73zguJpLb+o2VyRqTOTDyXTQAcP7XPd9 LXuWkCkhsqCALk2xQhOHjN6C0wsJu+++fGtEWUxiEiN+jaSY0muhcXNUM0/0uxAU0SlI jIzM3OJl6A9mmOxvGRPL/XDapBAjAhhcyO1D/U7ZJ604l8ELjZ7H3DBIsqgM0Pqgod5l JGCDRlCWjf2kv8hjJm/ci998yZnRlT547dtDt8fFU91vU3Fm9ZI+cCG6G+Bg9/pQFIsl ZNDa65caisMOklzE8S9xhgOoPDSb2xxuQ40M+eENIonn01J/RpymGN8TEeQVzr0Knvd+ azag== X-Gm-Message-State: AOAM5326KTBmKdNKsq6Key+0oqBp3oq3vXrhaTKL2QoKIRLvRBmnLw0g nNHszajd81vcyH+0DOf16NHDow8/dmygq0ulCd94FAxR8+rUGBHyTBbDzvRl9pw2p+h9iVDHOv3 84/4RCQ8gCXiKOutA5b9gv96FOZoU+SzqpVh0f7azhA== X-Received: by 2002:a17:90a:ea02:: with SMTP id w2mr3487492pjy.9.1599709548302; Wed, 09 Sep 2020 20:45:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQ4Xftd5pSAP7dnMoHiIU4Cqrmox4UUwvAq/Dpej9WiufnXCEeb6hO2kXEAgbOqyUxhLthtw== X-Received: by 2002:a17:90a:ea02:: with SMTP id w2mr3487480pjy.9.1599709548050; Wed, 09 Sep 2020 20:45:48 -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 y195sm4079930pfc.137.2020.09.09.20.45.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 Sep 2020 20:45:47 -0700 (PDT) From: Koba Ko To: kernel-team@lists.ubuntu.com Subject: [PATCH 8/8][SRU][G] thunderbolt: Ensure left shift of 512 does not overflow a 32 bit int Date: Thu, 10 Sep 2020 11:45:26 +0800 Message-Id: <20200910034526.12438-9-koba.ko@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910034526.12438-1-koba.ko@canonical.com> References: <20200910034526.12438-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 ed8cffb173b3..06d32fef58cd 100644 --- a/drivers/thunderbolt/usb4.c +++ b/drivers/thunderbolt/usb4.c @@ -1353,7 +1353,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); } @@ -1363,7 +1363,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,