From patchwork Wed Jul 19 22:47:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 122903 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2770480vqt; Wed, 19 Jul 2023 16:25:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlGaBCTsnNTftLcsMqYygCGROd12xNc4MwYXGqi2Q0s1nhlVEA1pNMbjEuB4jH8NmddibD/h X-Received: by 2002:a05:6a21:6da6:b0:134:40f0:5d04 with SMTP id wl38-20020a056a216da600b0013440f05d04mr7866918pzb.13.1689809114574; Wed, 19 Jul 2023 16:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689809114; cv=none; d=google.com; s=arc-20160816; b=A0Rhm+lc7w1xjUQiX66bV+X+Hup6d4vkyJw/fllygYR4V9m0WjE5BRNEJkxUZBhxIH NE5TAW48FQ/IB/dhac65qSfjYwhzRLEI4f9XiXkjg6H7o0KDv3skl2IyrmND7b6npOya iGFdT7Z5LXGGvyvCf2RvlVO3lSzS5eFnJVwGzhIz9AmHdT4MvxPoERqJf44o59skpshQ SZKy+DL82cfG03HKbfIEOriQq171waRub4dUQ+qSyx+vKKvDAhga8Q4KiEluPARcb8MQ hCAuA0rWyqURkKl+KDVwie4UGs4kZ5mDtot5IrWAjY+JYffgeWowFbDPZj7SdltMW9cs ayww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=6RaDc0uxTpDv+FQGSYEtH1QqNCE6dth2JPIYxw7pRKE=; fh=51d+xfMZexvPfo43XKCgAntV7P1NFdumS/3EFcLjpfc=; b=OVXb2kleWZg5YWcM80u1MoggVA2vF5T/hhU5KMfWzlxii84KBcospRC43c0mmz7O4k D9bMrbxlPbpiZpxxhCKftSasUeu76ovthCqPQaHMt/3OoCS6Et4qlxY4L5teNNEHGnuq KiIUtdqV6qbqi2EbS4MHruxUOTkCF+D06Z29XA9RTjX6ymcqE9vNEmM95zwrhaSZWzdR uHIBQmOsgJFBj8F8Apy0r0ssUuumAdl7tJzrPZGbfwvCYo1UBmIlLQ/oRI3ozATgp+JK xh3G32WpcWSMnuUJXtDoNsFlQxZVdnhvOZTlF3hYbRCttla1+1oh0ApOi6VdKDkusGEP 16Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Jht+gsbT; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l63-20020a639142000000b0053424040bb7si4331687pge.298.2023.07.19.16.25.02; Wed, 19 Jul 2023 16:25:14 -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=@linutronix.de header.s=2020 header.b=Jht+gsbT; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230368AbjGSWs4 (ORCPT + 99 others); Wed, 19 Jul 2023 18:48:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231134AbjGSWru (ORCPT ); Wed, 19 Jul 2023 18:47:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9593C2127; Wed, 19 Jul 2023 15:47:37 -0700 (PDT) Date: Wed, 19 Jul 2023 22:47:34 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1689806855; h=from:from:sender:sender:reply-to: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:content-transfer-encoding; bh=6RaDc0uxTpDv+FQGSYEtH1QqNCE6dth2JPIYxw7pRKE=; b=Jht+gsbTQDV1VCi8uZEMOvuiK5c6n6x9UXgxsGfTLtlBllB+VUElmVc1jqmMBKoWL+NOqG Rt3Cv9+9fOv+MGiEw/u4ewkBc/+vocb0tk5zV312yurGxj7axEEQjt7KVuDoEj84/M4usW m3TeOo01xMEUszXRM3igkhx7jLjSmLgdrFtrzosSICt/4aYhFMydMu4rHubhpWZ2e3bllM 5viVMS0UBQFqxGIdUFUtOLQO08WGAMdQ5jPl0eW1rNKNgNWRsCg6fqqru04VJgXqtiZ3Ih cWiseo6d4N3XqEGcyxMLea0C4rjjGNfa3Vcc3KUPq/W0E8GvuTUEXxdZ+Jqx1w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1689806855; h=from:from:sender:sender:reply-to: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:content-transfer-encoding; bh=6RaDc0uxTpDv+FQGSYEtH1QqNCE6dth2JPIYxw7pRKE=; b=HkBiGbWW/TsWnjYg++SaZzsm818kzBfJRCrr/5RHSBWCEvoyI/zUxNvRG7N2pj2GTsShtg wqYdvqzoMHEr8/CA== From: "tip-bot2 for Rick Edgecombe" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/shstk] x86/mm: Teach pte_mkwrite() about stack memory Cc: Rick Edgecombe , Dave Hansen , "Borislav Petkov (AMD)" , Kees Cook , "Mike Rapoport (IBM)" , Deepak Gupta , Pengfei Xu , John Allen , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <168980685497.28540.12778915917294389214.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771893281893596120 X-GMAIL-MSGID: 1771893281893596120 The following commit has been merged into the x86/shstk branch of tip: Commit-ID: b497e52ddb2ab750b00d8cc78209613558fc503b Gitweb: https://git.kernel.org/tip/b497e52ddb2ab750b00d8cc78209613558fc503b Author: Rick Edgecombe AuthorDate: Mon, 12 Jun 2023 17:10:47 -07:00 Committer: Rick Edgecombe CommitterDate: Tue, 11 Jul 2023 14:12:19 -07:00 x86/mm: Teach pte_mkwrite() about stack memory If a VMA has the VM_SHADOW_STACK flag, it is shadow stack memory. So when it is made writable with pte_mkwrite(), it should create shadow stack memory, not conventionally writable memory. Now that all the places where shadow stack memory might be created pass a VMA into pte_mkwrite(), it can know when it should do this. So make pte_mkwrite() create shadow stack memory when the VMA has the VM_SHADOW_STACK flag. Do the same thing for pmd_mkwrite(). This requires referencing VM_SHADOW_STACK in these functions, which are currently defined in pgtable.h, however mm.h (where VM_SHADOW_STACK is located) can't be pulled in without causing problems for files that reference pgtable.h. So also move pte/pmd_mkwrite() into pgtable.c, where they can safely reference VM_SHADOW_STACK. Signed-off-by: Rick Edgecombe Signed-off-by: Dave Hansen Reviewed-by: Borislav Petkov (AMD) Reviewed-by: Kees Cook Acked-by: Mike Rapoport (IBM) Acked-by: Deepak Gupta Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Link: https://lore.kernel.org/all/20230613001108.3040476-22-rick.p.edgecombe%40intel.com --- arch/x86/mm/pgtable.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 4bfbe4c..0d66aeb 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -875,6 +875,9 @@ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr) pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma) { + if (vma->vm_flags & VM_SHADOW_STACK) + return pte_mkwrite_shstk(pte); + pte = pte_mkwrite_novma(pte); return pte_clear_saveddirty(pte); @@ -882,6 +885,9 @@ pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma) pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma) { + if (vma->vm_flags & VM_SHADOW_STACK) + return pmd_mkwrite_shstk(pmd); + pmd = pmd_mkwrite_novma(pmd); return pmd_clear_saveddirty(pmd);