From patchwork Wed May 26 17:05:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 12282333 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 B534AC47089 for ; Wed, 26 May 2021 17:05:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5DA9D613E1 for ; Wed, 26 May 2021 17:05:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5DA9D613E1 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 4293B6B006C; Wed, 26 May 2021 13:05:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D7BA6B006E; Wed, 26 May 2021 13:05:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 093A56B0070; Wed, 26 May 2021 13:05:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0087.hostedemail.com [216.40.44.87]) by kanga.kvack.org (Postfix) with ESMTP id CF0666B006C for ; Wed, 26 May 2021 13:05:47 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5CA968249980 for ; Wed, 26 May 2021 17:05:47 +0000 (UTC) X-FDA: 78184009134.30.6ACCCCA Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by imf26.hostedemail.com (Postfix) with ESMTP id 84E8140F8C13 for ; Wed, 26 May 2021 17:05:43 +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 1llwyK-0002II-Td; Wed, 26 May 2021 17:05:33 +0000 From: Colin King To: =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Andrew Morton , Ralph Campbell , Jason Gunthorpe , Stephen Rothwell , Alistair Popple , linux-mm@kvack.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][V2][next] mm: selftests: fix potential integer overflow on shift of a int Date: Wed, 26 May 2021 18:05:30 +0100 Message-Id: <20210526170530.3766167-1-colin.king@canonical.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=canonical.com (policy=none); spf=none (imf26.hostedemail.com: domain of colin.king@canonical.com has no SPF policy when checking 91.189.89.112) smtp.mailfrom=colin.king@canonical.com X-Stat-Signature: ihayysrizmm53ciec7h9pi63ptasueth X-Rspamd-Queue-Id: 84E8140F8C13 X-Rspamd-Server: rspam02 X-HE-Tag: 1622048743-207979 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 making mapped an unsigned long. Addresses-Coverity: ("Uninitentional integer overflow") Fixes: 8b2a105c3794 ("mm: selftests for exclusive device memory") Signed-off-by: Colin Ian King Reviewed-by: Jason Gunthorpe --- V2: Make mapped an unsigned long rather than casting it to unsigned long --- lib/test_hmm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index 74d69f87691e..8c55c4723692 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -733,7 +733,8 @@ static int dmirror_exclusive(struct dmirror *dmirror, mmap_read_lock(mm); for (addr = start; addr < end; addr = next) { - int i, mapped; + unsigned long mapped; + int i; if (end < addr + (ARRAY_SIZE(pages) << PAGE_SHIFT)) next = end;