From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-24.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00BF6C1B08C for ; Wed, 14 Jul 2021 20:02:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7B59610D1 for ; Wed, 14 Jul 2021 20:02:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241686AbhGNUEI (ORCPT ); Wed, 14 Jul 2021 16:04:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:48778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241472AbhGNTux (ORCPT ); Wed, 14 Jul 2021 15:50:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5149F613B5; Wed, 14 Jul 2021 19:48:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626292081; bh=0VNRZxuTAkaRJ2bD4WVRiPrGodwVuwGHq71wMt1He48=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AGk+hggYJkS5nDhL32x7sHXjhDbRoDiGANsido2stPHx42tWvWyK5hDu488cjmxYK KyMKZN9oTjKUsxTl0r1o0B7PIFioa34JTUwKtahx4N0vS7AlsJL/xtAyW2qPJ6djB7 wR0HsZLV1k7zy0MUnG1S5r70fKMo2/8RIt5thmUghmYXTcGyXDp9Za1Cs5q1ghxwU0 Mo4fzDlfGES0/7PwpUfLi1ARBWIhR49dg+4t6/dvk3sKKjZqpNvqDpCwtaygu/GzCL C/EP5AiYY/OWR1m4IwA2kyRhvn1oXGBma4Tt8Gxucy9yiVLRJkZxLHkdUSmC/TySHe lJCpiQiAWPWlQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Colin Ian King , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 25/28] scsi: aic7xxx: Fix unintentional sign extension issue on left shift of u8 Date: Wed, 14 Jul 2021 15:47:20 -0400 Message-Id: <20210714194723.55677-25-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210714194723.55677-1-sashal@kernel.org> References: <20210714194723.55677-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King [ Upstream commit 332a9dd1d86f1e7203fc7f0fd7e82f0b304200fe ] The shifting of the u8 integer returned fom ahc_inb(ahc, port+3) by 24 bits to the left will be promoted to a 32 bit signed int and then sign-extended to a u64. In the event that the top bit of the u8 is set then all then all the upper 32 bits of the u64 end up as also being set because of the sign-extension. Fix this by casting the u8 values to a u64 before the 24 bit left shift. [ This dates back to 2002, I found the offending commit from the git history git://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git, commit f58eb66c0b0a ("Update aic7xxx driver to 6.2.10...") ] Link: https://lore.kernel.org/r/20210621151727.20667-1-colin.king@canonical.com Signed-off-by: Colin Ian King Signed-off-by: Martin K. Petersen Addresses-Coverity: ("Unintended sign extension") Signed-off-by: Sasha Levin --- drivers/scsi/aic7xxx/aic7xxx_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c index fdbb0a3dc9b4..6929aa13adc3 100644 --- a/drivers/scsi/aic7xxx/aic7xxx_core.c +++ b/drivers/scsi/aic7xxx/aic7xxx_core.c @@ -500,7 +500,7 @@ ahc_inq(struct ahc_softc *ahc, u_int port) return ((ahc_inb(ahc, port)) | (ahc_inb(ahc, port+1) << 8) | (ahc_inb(ahc, port+2) << 16) - | (ahc_inb(ahc, port+3) << 24) + | (((uint64_t)ahc_inb(ahc, port+3)) << 24) | (((uint64_t)ahc_inb(ahc, port+4)) << 32) | (((uint64_t)ahc_inb(ahc, port+5)) << 40) | (((uint64_t)ahc_inb(ahc, port+6)) << 48) -- 2.30.2