Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3008048rwd; Wed, 14 Jun 2023 09:59:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7q9QCeHWZ1LAEmcOxDAZtW3gC36i1Ja9i+iazcF71gOUOpxFUZUEWfZ/gQhi0lecD2xf/g X-Received: by 2002:a17:907:9615:b0:968:892b:1902 with SMTP id gb21-20020a170907961500b00968892b1902mr2489085ejc.6.1686761955985; Wed, 14 Jun 2023 09:59:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686761955; cv=none; d=google.com; s=arc-20160816; b=jcpGh/L0feQwB0JW1GIgaHFc+iDY0j2cLgj0clBuuIowaWB6CYnMB+89tmhkuMIdqD vTQi5PhgLNxGhV3DfnzOGON6XG5BqjKhDR/+yI+PncWDuSRW6H2Ksav6vGzfYnQaBjou dtSYNRjef/LW4SqxYtQIqi1gyl87rx7rsJlPfao6U2uMSUVAlD5nqKaOly/aRLWXFLqm DNKYnvyfcqdcssFM+t9i2Oi5pe63PsxwUXE6nU543W14xNw4OINFaQUfleycRRcQSZbu KRhqLCViaFygg82P7P1OgTctRuO7bSbTRwJaZncxgXrm3OIFS8FsSElzBeItkbIWCpH7 Fukg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JpotcZvu92R1QGWTXDbnByx0mcrSCDcuvxrJiTLzyTw=; b=lPFWPNhjDlN2pcuauOJHd4HBgfw+/lBeuDehz4yzMsX8kJm0T0Eud/xP2BDXLtMbig JMvK6Id7b51tgiuBvYe5GJQB0ZWP3NcJY5essqzcXxH30G+mnU8xVLQ+LhNmXMUmBMHs dkAUz11zDsymhlFh49H1a+k1WDIUewzHCwWuPlGbCJeuYFYnV1Uc8zxp6rZxNkUkFYNf 86rt5vWU6PFyss5qe/BOCgda64Pyg0PbcpHbLmVChlwyssqCF9VDQOStO3l+318Z5m7X SY6MtH5EsKDU13VBK9lMRZ2fni63dlRIHWiyoFcfY+TJP1M7WiGcfg66fHh1w7diHY2k xsbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a5eEFKOn; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i12-20020a170906114c00b009584dfeebbcsi8810217eja.471.2023.06.14.09.58.38; Wed, 14 Jun 2023 09:59:15 -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=@kernel.org header.s=k20201202 header.b=a5eEFKOn; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234807AbjFNQjc (ORCPT + 99 others); Wed, 14 Jun 2023 12:39:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234093AbjFNQjb (ORCPT ); Wed, 14 Jun 2023 12:39:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61F4C199 for ; Wed, 14 Jun 2023 09:39:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EAF7C64450 for ; Wed, 14 Jun 2023 16:39:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6CCEC433BB; Wed, 14 Jun 2023 16:39:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686760769; bh=CiaATWA3DUiAf96JCsvwKvujvWjgKxROvf/tLbnTMT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a5eEFKOn/oJfksLkjOkh0XikxN/2rxRKsth1fo3Humda0sRF+XcIdTsOZHltbnEke r0uXSJB7JvDMGlTDGHZZ5A4YvieVJlgRBk7kMIQ0r6yalVxy77ojfomI4lnjrWNFh9 YLFBZ22E+kL4iw076ctEAqgZmHczLccQpVW0eheI1eKqiy8Ln5kVI1RicBtxeYoXcW F5r0mILjCM+2solcJ8PvMXSY1hWIfAo1sKCqHSCvQkYEKHc21zWwvfXPp2BH9vz9bH HuNCLANCAbHcbtzKuPurXHPvhkuBnB57YIqPQLa/MvGZlCkxEuWnuW8IH6JihQ8R7G QLGqaIQ8dvEyA== From: Lee Jones To: lee@kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 1/1] x86/mm/KASLR: Store pud_page_tramp into entry rather than page Date: Wed, 14 Jun 2023 17:38:54 +0100 Message-ID: <20230614163859.924309-2-lee@kernel.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230614163859.924309-1-lee@kernel.org> References: <20230614163859.924309-1-lee@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 set_pgd() expects to be passed whole pages to operate on, whereas trampoline_pgd_entry is, as the name suggests, an entry. The ramifications for using set_pgd() here are that the following thread of execution will not only place the suggested value into the trampoline_pgd_entry (8-Byte globally stored [.bss]) variable, PTI will also attempt to replicate that value into the non-existent neighboring user page (located +4k away), leading to the corruption of other global [.bss] stored variables. Suggested-by: Dave Hansen Signed-off-by: Lee Jones --- arch/x86/mm/kaslr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c index 557f0fe25dff4..37db264866b64 100644 --- a/arch/x86/mm/kaslr.c +++ b/arch/x86/mm/kaslr.c @@ -172,10 +172,10 @@ void __meminit init_trampoline_kaslr(void) set_p4d(p4d_tramp, __p4d(_KERNPG_TABLE | __pa(pud_page_tramp))); - set_pgd(&trampoline_pgd_entry, - __pgd(_KERNPG_TABLE | __pa(p4d_page_tramp))); + trampoline_pgd_entry = + __pgd(_KERNPG_TABLE | __pa(p4d_page_tramp)); } else { - set_pgd(&trampoline_pgd_entry, - __pgd(_KERNPG_TABLE | __pa(pud_page_tramp))); + trampoline_pgd_entry = + __pgd(_KERNPG_TABLE | __pa(pud_page_tramp)); } } -- 2.41.0.162.gfafddb0af9-goog