Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp389355pxb; Wed, 8 Sep 2021 03:37:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtpGvtnKq7GNvHSTI9wr8xJpOB+Hkz0r06NkL3tjxeHH/2iRwi0dAhcpFSbg31GuYZmPCD X-Received: by 2002:a05:6e02:505:: with SMTP id d5mr2477458ils.150.1631097445397; Wed, 08 Sep 2021 03:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631097445; cv=none; d=google.com; s=arc-20160816; b=xYL19oow1xPgoezzO3iDB/6Nw9wmAq3YBMoPCOoUbY2tIIUoBr0gtvbRPmqIExJeYs rdLc/slGUNXa2P0YisDB5xHKPbfBnbaYyQXS5HFo5/OE6MDI2iAEunYhJIU9fFeKn+rV NpKBCzetkTVZYrvwJknHrlPa8l3yVVk8ubimGvGQM8mPTRKJJR7m5tphaU2L/gvPDx0g aMoFhdsaeSbz16TWRFmxUDdTpW+cZInEfbUOzlIkQNkQgQdWb4HtaSI0/p1VOBboRoNI fWyOTlSOtE/EzUGSsRF7a/AXHnK+RV7X1xHCM+bfTNwqgwHbmn7Pbs6fmr6TmVTaia2v eGnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vNZo46xtdLfPCSghubjAQ0AbiTd/3e4sJ5wQ5kYrsZk=; b=zvcT3UuG8ZIks4oxSwBYFvTHqhpapAhzEMIVJOMYXisWpCXOkic8yyZc8D9IKKHs49 MCgR98kaU7Om7A1D//UJgMkgJ8ukCttjRg/aCn9XxyT+aDArxxUqkgksjpzD4mxh9dpu opImQ4Z/C7VTKmXMTC+5IzCFqxjxl3UFdV7JJ52/d0tgB84HvJ8nz0GMqbo0C+9ZbYj+ FpgZ2RA3vJDfRSa40ggW5/VyeKzPvfV6wDLMdOJCnPG4DR1dJ0W4+/u1tFZeULnufydY VpiYqf0+PtNlPDeqU3nvES4UvJCKe7G0WGQoYL8L4i1Mk2/pPZu1zpBaSkoivb5KkMdz G0vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=aRJSgvRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c11si1671072ild.118.2021.09.08.03.37.10; Wed, 08 Sep 2021 03:37:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=aRJSgvRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231684AbhIHKgk (ORCPT + 99 others); Wed, 8 Sep 2021 06:36:40 -0400 Received: from mail.skyhub.de ([5.9.137.197]:59040 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbhIHKgj (ORCPT ); Wed, 8 Sep 2021 06:36:39 -0400 Received: from zn.tnic (p200300ec2f0efc002d1ac0b1b41b9169.dip0.t-ipconnect.de [IPv6:2003:ec:2f0e:fc00:2d1a:c0b1:b41b:9169]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 5B73C1EC036B; Wed, 8 Sep 2021 12:35:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1631097330; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=vNZo46xtdLfPCSghubjAQ0AbiTd/3e4sJ5wQ5kYrsZk=; b=aRJSgvRLCoKkTWzIqFJm5RepVqZxbasjqfKuU8UvRw9DGDOAjYyqQXl+jgGN/P0Y/4qyYf qAH2j4creMyuTF+DO2WKIckrrNg72u000ui50+YNIeysEGcVatNjDcL5w3Cn9Mn6Lk34qF VS3GawEjtGqtDyAYGL8tP62fy0OfuDI= Date: Wed, 8 Sep 2021 12:35:21 +0200 From: Borislav Petkov To: Dave Hansen Cc: Mike Rapoport , x86@kernel.org, Andrew Morton , Andy Lutomirski , Dave Hansen , David Hildenbrand , Ingo Molnar , Jiri Olsa , Mike Rapoport , Oscar Salvador , Peter Zijlstra , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] x86/mm: fix kern_addr_valid to cope with existing but not present entries Message-ID: References: <20210819132717.19358-1-rppt@kernel.org> <35f4a263-1001-5ba5-7b6c-3fcc5f93cc30@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <35f4a263-1001-5ba5-7b6c-3fcc5f93cc30@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 25, 2021 at 11:47:10AM -0700, Dave Hansen wrote: > On 8/19/21 6:27 AM, Mike Rapoport wrote: > > Such PMDs are created when free_kernel_image_pages() frees regions larger > > than 2Mb. In this case a part of the freed memory is mapped with PMDs and > > the set_memory_np_noalias() -> ... -> __change_page_attr() sequence will > > mark the PMD as not present rather than wipe it completely. > > > > Make kern_addr_valid() to check whether higher level page table entries are > > present before trying to dereference them to fix this issue and to avoid > > similar issues in the future. > > > > Reported-by: Jiri Olsa > > Signed-off-by: Mike Rapoport > > Cc: # 4.4... > > pmd = pmd_offset(pud, addr); > > - if (pmd_none(*pmd)) > > + if (!pmd_present(*pmd)) > > return 0; > > Yeah, that seems like the right fix. The one kern_addr_valid() user is > going to touch the memory so it *better* be present. p*d_none() was > definitely the wrong check. > > Acked-by: Dave Hansen So I did stare at this for a while, trying to make sense of it and David Hildenbrand asked for a Fixes: tag in v1 review and from doing a bit of git archeology I think it should be: c40a56a7818c ("x86/mm/init: Remove freed kernel image areas from alias mapping") because that thing added the clearing of the Present bit for the high kernel image mapping of those areas. Right? -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette