From patchwork Wed May 26 15:09:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 12282039 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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 C9557C47088 for ; Wed, 26 May 2021 15:09:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 56462613CC for ; Wed, 26 May 2021 15:09:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 56462613CC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 97B586B006E; Wed, 26 May 2021 11:09:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9041C6B0070; Wed, 26 May 2021 11:09:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77D756B0071; Wed, 26 May 2021 11:09:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0165.hostedemail.com [216.40.44.165]) by kanga.kvack.org (Postfix) with ESMTP id 3CF5E6B006E for ; Wed, 26 May 2021 11:09:55 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C0804180AD81F for ; Wed, 26 May 2021 15:09:54 +0000 (UTC) X-FDA: 78183717108.01.C302816 Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by imf20.hostedemail.com (Postfix) with ESMTP id 55BEB2E0 for ; Wed, 26 May 2021 15:09:44 +0000 (UTC) Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1llvAK-0002oe-3B; Wed, 26 May 2021 15:09:48 +0000 From: Colin King To: =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Alistair Popple , Ralph Campbell , Stephen Rothwell , Andrew Morton , Jason Gunthorpe , linux-mm@kvack.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] mm: selftests: fix potential integer overflow on shift of a int Date: Wed, 26 May 2021 16:09:47 +0100 Message-Id: <20210526150947.3751728-1-colin.king@canonical.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 55BEB2E0 Authentication-Results: imf20.hostedemail.com; dkim=none; spf=none (imf20.hostedemail.com: domain of colin.king@canonical.com has no SPF policy when checking 91.189.89.112) smtp.mailfrom=colin.king@canonical.com; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=canonical.com (policy=none) X-Rspamd-Server: rspam03 X-Stat-Signature: 69n6r33sxbyhpqwfnac85jqh4si38q9g X-HE-Tag: 1622041784-494474 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Colin Ian King The left shift of the int mapped is evaluated using 32 bit arithmetic and then assigned to an unsigned long. In the case where mapped is 0x80000 when PAGE_SHIFT is 12 will lead to the upper bits being sign extended in the unsigned long. Larger values can lead to an int overflow. Avoid this by casting mapped to unsigned long before shifting. Addresses-Coverity: ("Uninitentional integer overflow") Fixes: 8b2a105c3794 ("mm: selftests for exclusive device memory") Signed-off-by: Colin Ian King --- lib/test_hmm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 74d69f87691e..b54657701b3a 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -749,7 +749,7 @@ static int dmirror_exclusive(struct dmirror *dmirror, } } - if (addr + (mapped << PAGE_SHIFT) < next) { + if (addr + ((unsigned int)mapped << PAGE_SHIFT) < next) { mmap_read_unlock(mm); mmput(mm); return -EBUSY;