Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1499043iog; Thu, 16 Jun 2022 07:36:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vBLQO1YfQMsUI9yrCDG3ppcKlXFjuTpZfaeU7EkZTZ7Z1RiwJvR55EIgFMWg/4139inoMv X-Received: by 2002:a63:89c2:0:b0:3fc:8bd2:aa5a with SMTP id v185-20020a6389c2000000b003fc8bd2aa5amr4795158pgd.362.1655390197288; Thu, 16 Jun 2022 07:36:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655390197; cv=none; d=google.com; s=arc-20160816; b=w3Xg1q4jT18kp6lOuFHdNX+9wzFVQSSFrM/tkg8Lp58m0xFDOGQ1vVzxFy6xqoa2ot eZ0H8/YL+6XEMKgyNnCgot59q9Z2EUQeW86o3FEvSnsnIvyQcmfyC4ZVJkEGE9OqrANs 8D1VisM0nAUmZGpDbcl5mhjgiT9uQpfBqWwUlq5NOp6KKooOarI4rUBSy1uDBoOX4Lla j+f1sKpEu666zfKF8BJ0maXQcVbHXVub5aRKl6NSTVgJuXmqcGr5KUa8/PyJI9Rq6H04 QxPuTKQ6lQ4+RJokJwlClncOmN+aJq5WhSjcWbzkllUVZlXZE++tYhlVWPiB21/EpUU/ uWqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=19IvBGiLPkMr2bRncJWiD9PLkyQXxlLgX714p/40dos=; b=NWha/DO5nlq0VmsyRMx/ba4xzfIBhLrFns3Y8vTwMjUqawWMrLdokVNrQaD9uEnmHh 2uPZspJb/Suh8dQXnxCyYmaHupSY3Pp+01ifUTBdsYP084Hbn+DF7fYhtesJ1iyCBaXI DalDLL3Xz9dLR/NEiU0SYgaR8NPY/yQ5oYo+zpQTxxU/D/F51RGDSK3xqLse37iWSncl cL1b8leyN70FAbTNRxWrq2cKU38dPNQTgulZKdnq13WUaNaVb6MU5h7NbydJ2gXCjzjo t/CGW7RVWpLOoTwKP+thOccVT7YpIBPcOq2n0GTVOqe1YVPDyobhiBexexcoJ+cJ04N9 4coA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gRwE1I5F; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i5-20020a1709026ac500b0015838c0eedbsi2414938plt.506.2022.06.16.07.36.24; Thu, 16 Jun 2022 07:36:37 -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=@intel.com header.s=Intel header.b=gRwE1I5F; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377660AbiFPOUm (ORCPT + 99 others); Thu, 16 Jun 2022 10:20:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377153AbiFPOUl (ORCPT ); Thu, 16 Jun 2022 10:20:41 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C6F23B3EF; Thu, 16 Jun 2022 07:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655389240; x=1686925240; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=3lBsGFfL5N6NyfcA2AMIV2yhCK5s/sysL3/tFfQ+p+0=; b=gRwE1I5FYojmK3j4eIjefPOn4FhmgwSFGCoRackDG3dzcrgWzVGaD3Kv Q2q4PsFDoCRBH6z+u65V+AMZNW5eaWKiaFymllAk1fO+ye8anHqfRIXZS AFaMaq2tMGUFCdH11gyyr7JVaH9vpI2fAdddtsWjbJrNkmyMdsHO4BwO8 jajsOkkPhXyAEcJEOQYFtx2BSSgG5k59sCedKhVAHKRtPOVCyFw7OUK/7 rlgQaYj4KYlz7LJE30JxJ+h8V6MHbS384WH4K4kqf1xJ16DZUrUhfJF9C S6tLgt5I/mVXdQ9kVML0t6LmkdPQAfHM52UPQOk8smMjxfMcsas1eUb86 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10379"; a="259720740" X-IronPort-AV: E=Sophos;i="5.92,305,1650956400"; d="scan'208";a="259720740" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2022 07:20:40 -0700 X-IronPort-AV: E=Sophos;i="5.92,305,1650956400"; d="scan'208";a="641563105" Received: from rrmiller-mobl.amr.corp.intel.com (HELO [10.212.205.54]) ([10.212.205.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2022 07:20:39 -0700 Message-ID: <8e2c9b2b-d8ad-5e9a-7aa6-23e0c599c2e9@intel.com> Date: Thu, 16 Jun 2022 07:20:40 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] x86/mm: Fix possible index overflow when creating page table mapping Content-Language: en-US To: Yuntao Wang Cc: bhe@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, kirill@shutemov.name, linux-kernel@vger.kernel.org, luto@kernel.org, mingo@redhat.com, peterz@infradead.org, stable@vger.kernel.org, tglx@linutronix.de, x86@kernel.org References: <3e754cf7-35f8-0163-a24a-063fa3d96718@intel.com> <20220616141525.1790083-1-ytcoode@gmail.com> From: Dave Hansen In-Reply-To: <20220616141525.1790083-1-ytcoode@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,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 On 6/16/22 07:15, Yuntao Wang wrote: > On Thu, 16 Jun 2022 07:02:56 -0700, Dave Hansen wrote: >> On 6/16/22 06:55, Yuntao Wang wrote: >>> There are two issues in phys_p4d_init(): >>> >>> - The __kernel_physical_mapping_init() does not do boundary-checking for >>> paddr_end and passes it directly to phys_p4d_init(), phys_p4d_init() does >>> not do bounds checking either, so if the physical memory to be mapped is >>> large enough, 'p4d_page + p4d_index(vaddr)' will wrap around to the >>> beginning entry of the P4D table and its data will be overwritten. >>> >>> - The for loop body will be executed only when 'vaddr < vaddr_end' >>> evaluates to true, but if that condition is true, 'paddr >= paddr_end' >>> will evaluate to false, thus the 'if (paddr >= paddr_end) {}' block will >>> never be executed and become dead code. >> Could you explain a bit how you found this? Was this encountered in >> practice and debugged or was it found by inspection? > I found it by inspection. Dare I ask how this was tested?