Message ID | 20230614155223.905222-2-lee@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp67069vqr; Wed, 14 Jun 2023 09:19:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6wvngv9dCbpxFnNopIvOXyTqolBcVoBwa+9NwwN1cTLoXuiILKDuO2a1YgZmLQKi64FL57 X-Received: by 2002:a05:6a00:114b:b0:654:719b:34f4 with SMTP id b11-20020a056a00114b00b00654719b34f4mr2779046pfm.19.1686759546280; Wed, 14 Jun 2023 09:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686759546; cv=none; d=google.com; s=arc-20160816; b=OojX/OqARuhlhT0JASeSPmkaxYZ/lJgKRHuw7/cOEMKXdTWlZ4WRg2eUZ/6Mj7pd7p gcBL5kwt04AcplXGH2WXW6SJJEx87Qk9RxVfASGlXVaOyDlEc1PVnToknatzrbfCDLPk mMwxIz4wz0ZJPzaSM7pcXk+f/C2bZP9W4nP1cmR1B4Ie8OsdhI2JsuvcJI4OzmY4A6hk UOoOPSkohMEPlWIxgyUxdkT70KPYVHbK2L3NBxq/wBZko8lumxGdlnJ+P4pwT05RB/fg gxAPUKNv+Qu9fKeoK4DVPPNd54Of/DRnBQFlDIcQ96E0y5F5yw0nunLK4do1aPMqInMz hOHA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l185-20020a633ec2000000b005348f910e64si8750682pga.693.2023.06.14.09.18.52; Wed, 14 Jun 2023 09:19:06 -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 S244907AbjFNPwz (ORCPT <rfc822;n2h9z4@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <linux-kernel@vger.kernel.org>; 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 <lee@kernel.org> 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768695577757782792?= X-GMAIL-MSGID: =?utf-8?q?1768695577757782792?= |
Series |
x86: Fix .bss corruption
|
|
Commit Message
Lee Jones
June 14, 2023, 3:52 p.m. UTC
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 <dave.hansen@linux.intel.com>
Signed-off-by: Lee Jones <lee@kernel.org>
---
arch/x86/mm/kaslr.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On Wed, 14 Jun 2023, Lee Jones wrote: > 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 <dave.hansen@linux.intel.com> > Signed-off-by: Lee Jones <lee@kernel.org> > --- > 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))); This needs converting too. v2 in test. > } else { > - set_pgd(&trampoline_pgd_entry, > - __pgd(_KERNPG_TABLE | __pa(pud_page_tramp))); > + trampoline_pgd_entry = > + __pgd(_KERNPG_TABLE | __pa(pud_page_tramp)); > } > }
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)); } }