Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2868532rwb; Mon, 15 Aug 2022 12:59:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR7kS8OSoG7DKokGKGKb3ol7mK52PbvngvErfr6dM/+pCxBCf+hEdENxoimweQ0kae3ybpdG X-Received: by 2002:a05:6a00:ad1:b0:530:2cb7:84de with SMTP id c17-20020a056a000ad100b005302cb784demr17966857pfl.3.1660593551871; Mon, 15 Aug 2022 12:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660593551; cv=none; d=google.com; s=arc-20160816; b=poUNIeWc1cOtLPepk5SkeitxlUknzfW3+bK6YRZYejy54Q9XueW4PdgVhZMsaOs8AZ SRgc/imVtutpxRWJNL7xk9NfxHXd/I5vmQfJATJZyF4Xz75jEW5ahCQjPAUn5XAEvjao JZ6MGdljnZok6AIVu5Jrw9Z497ObVxubU8uH1RzAOWZ/lClHXw4oFMdlAwcGrmM6mh+u FQy31Ld9JXnw4WIq+uEXz2YdN4AlQTtjHrlPDdCDfv/7WnIAlgUKN6jhHhkW+qewd+SA ncecrzdbZmPFBNOI5Xon/b1Tbd3tM+lPa1Q3XBfChsXKpry0mTUGHbi3jfTAgOCxr0FA 82vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=r8diIbMJtUFX1w7dbavkvGR0EC4yidQxrs4q7KeL5aM=; b=hgNOvws7xSY/tH/GZLAbX77gjPpjCoXqEhsa2MCZt0bwyMdOCoQbAvyXHTICvEm7T6 1hG/DFfAg1LRywf0ulgvL009Gb2hkOD5K25XrzeeRbRk8lnBC9+bbdzymuDZAYDNU+sN Wa2RrQS5OnW0SKpedqB6hIOrtgNwTPxAmS1WEtuLLhV3B+gmZ8BHZsa/Zbvd7rdscr/P STOd4Be6Fh/wKIWiBs077qjUP2F8kEJYjgKIumYX08sxkpU4iSfTYT9DiUH+mm+B6ZE4 UJDD3OT2L6WbONXSZFunc8FiM0hsJ4N8YYaNmLVhCcq8q2A6dU7PKT2hUovYW1cfnvWh rjfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=f8cJ2wSi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h1-20020a17090a604100b001f70261fe1fsi7690983pjm.46.2022.08.15.12.59.00; Mon, 15 Aug 2022 12:59:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=f8cJ2wSi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239687AbiHOTOW (ORCPT + 99 others); Mon, 15 Aug 2022 15:14:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343877AbiHOTLL (ORCPT ); Mon, 15 Aug 2022 15:11:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79F1847B92; Mon, 15 Aug 2022 11:36:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BEACB610A4; Mon, 15 Aug 2022 18:36:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7E89C433B5; Mon, 15 Aug 2022 18:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588613; bh=AoWZxuR6WXPi8Pqjbv7dEunLrV46Cyhu9vllKRjqP4s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f8cJ2wSiItzkzeAtjpykZeLIaFg6n0s/AW9e39IORCKVcPugAvyAfzMHm/B05H9Gk GdpwL2CdmUJEl74gWo1jw3sA6zQWb0movJtjjtO29xjym4+oC00LPmiMp+82JPKyu+ KpDu1tGgcPmLprob4iyC7s9Kk4YnCS3bKVhH8XUg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaohe Lin , Jerome Glisse , Alistair Popple , Jason Gunthorpe , Ralph Campbell , Andrew Morton , Sasha Levin Subject: [PATCH 5.15 429/779] lib/test_hmm: avoid accessing uninitialized pages Date: Mon, 15 Aug 2022 20:01:13 +0200 Message-Id: <20220815180355.612757882@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miaohe Lin [ Upstream commit ed913b055a74b723976f8e885a3395162a0371e6 ] If make_device_exclusive_range() fails or returns pages marked for exclusive access less than required, remaining fields of pages will left uninitialized. So dmirror_atomic_map() will access those yet uninitialized fields of pages. To fix it, do dmirror_atomic_map() iff all pages are marked for exclusive access (we will break if mapped is less than required anyway) so we won't access those uninitialized fields of pages. Link: https://lkml.kernel.org/r/20220609130835.35110-1-linmiaohe@huawei.com Fixes: b659baea7546 ("mm: selftests for exclusive device memory") Signed-off-by: Miaohe Lin Cc: Jerome Glisse Cc: Alistair Popple Cc: Jason Gunthorpe Cc: Ralph Campbell Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- lib/test_hmm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/test_hmm.c b/lib/test_hmm.c index ac794e354069..a89cb4281c9d 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -731,7 +731,7 @@ static int dmirror_exclusive(struct dmirror *dmirror, mmap_read_lock(mm); for (addr = start; addr < end; addr = next) { - unsigned long mapped; + unsigned long mapped = 0; int i; if (end < addr + (ARRAY_SIZE(pages) << PAGE_SHIFT)) @@ -740,7 +740,13 @@ static int dmirror_exclusive(struct dmirror *dmirror, next = addr + (ARRAY_SIZE(pages) << PAGE_SHIFT); ret = make_device_exclusive_range(mm, addr, next, pages, NULL); - mapped = dmirror_atomic_map(addr, next, pages, dmirror); + /* + * Do dmirror_atomic_map() iff all pages are marked for + * exclusive access to avoid accessing uninitialized + * fields of pages. + */ + if (ret == (next - addr) >> PAGE_SHIFT) + mapped = dmirror_atomic_map(addr, next, pages, dmirror); for (i = 0; i < ret; i++) { if (pages[i]) { unlock_page(pages[i]); -- 2.35.1