Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2955038rwd; Wed, 14 Jun 2023 09:17:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4xfHvw+gUK9+W0XcuGw5HXRNnoJq9lfr3FZdnlaDLvC1d2qX7dG8QLbuZ0eEhHBNw+9I/J X-Received: by 2002:a05:6a21:970c:b0:10c:6dbc:2806 with SMTP id ub12-20020a056a21970c00b0010c6dbc2806mr1874577pzb.46.1686759450832; Wed, 14 Jun 2023 09:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686759450; cv=none; d=google.com; s=arc-20160816; b=J4orrm+/KKPifYNu0+uJIDegu2Lac7p4Lx8fflkPeWF5Pgnvy2MRKdg5cB2NjmXWHy lnIsuoZ9m4j6CX7YWniPicXg3hqjCmURiuPL+XopNrugDW+hBo627gvUrQtiC3G691c6 2BugOt/HsPJMtu49Iy8HFK7NEiPbWZ9QlPcqdgTCquVi3ZlRL0LYJFfBWcsPsYjIxeif wOs960iCJBr3l9aaAQX66sdeDBJeE93NZB9cgWVRXD3z/XeXXVCQC1dcI4J9Ai9Qkkkd Rzwer7v6IpzQkcCxwmaEeoxktTqkBR4tACInF59sXICeibkkrfJHRDbR0DuW3ll4VlMY n9/w== 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=xQB4g4VJczVGJoLysQsm5AoKEJfk8MiRLlClfYQhVrg=; b=xtq6loTDWs7oAbL8QgcGCR0l2dCEzylQzGfwy25TUeUO24bEWfwT5e3YXQ1sua+hvr I1gfh8+CWuljjLXoNcNvvjXNnTiP1e+RHKw9cqw0dmUEj/bae7Y/70wsGb2lzNTgEPHL jFx5U9A8x7vWEWcLIeiQY1ppEGpay9fGBhbG2bEkjBrivrURrbZwalHIjYpgUl2dVww1 W4DJgoOSnNGlGBccQGjZCFTWboGDzUiWmrL3knB6NhYDVQc/O5MT2Ct9tWey5RZJDd0j 9vEGhRZ8mcyruT6R1dTc3f2ZImIZP40HeE/GMelQzdruEsInNiR+sgu+tiZoZbhla6J/ KAeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HKuxnUbj; 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 l189-20020a6388c6000000b0054fde1c2a9bsi988793pgd.791.2023.06.14.09.17.17; Wed, 14 Jun 2023 09:17:30 -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=HKuxnUbj; 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 S244905AbjFNPwz (ORCPT + 99 others); Wed, 14 Jun 2023 11:52:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244853AbjFNPwx (ORCPT ); Wed, 14 Jun 2023 11:52:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFDEB170E for ; Wed, 14 Jun 2023 08:52:52 -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 3E15E643FD for ; Wed, 14 Jun 2023 15:52:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30A84C433CC; Wed, 14 Jun 2023 15:52:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686757971; bh=A8TF2ckDAIr4008OG16ynqI8vPNCnEPAU4BPRdH58lk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HKuxnUbj/uowyKcgmYurVBwnX5CC+yfvHstHH3hviyfohLiqu0HWzZC4jKpThsgik +uYpg9wgh9e107P8gTDVX7mulbhtow0NmULW10beniC4op0IhoG204ZtTZzWAAn9xj Z6XAcTFhbpBAQCq4B9FfYrY1dFdsrt50HURIgQSuWgsgSWwE3wmo2jxGSAyLkzdvnt E7PsSlVy2SlwzWQ+L+GhRppjXKD9MQ1Da/aboYWbxLXQk5PYHAXaUbjB/kIVFMbP5l eC9z2EgXobSvIxNufUd0Z4ztDzaOHHcLw4F1XxU07ctryWe4kP5Lwn4Ir6pSeujQio NfhS4eaAMR9Xg== 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 1/1] x86/mm/KASLR: Store pud_page_tramp into entry rather than page Date: Wed, 14 Jun 2023 16:52:10 +0100 Message-ID: <20230614155223.905222-2-lee@kernel.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230614155223.905222-1-lee@kernel.org> References: <20230614155223.905222-1-lee@kernel.org> MIME-Version: 1.0 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 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c index 557f0fe25dff4..ee6f22f3385b6 100644 --- a/arch/x86/mm/kaslr.c +++ b/arch/x86/mm/kaslr.c @@ -175,7 +175,7 @@ void __meminit init_trampoline_kaslr(void) set_pgd(&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