From patchwork Fri Jun 16 19:16:59 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: 109332 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1568429vqr; Fri, 16 Jun 2023 12:30:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5FO5Y3PKmEvbM5oIIjGX/BIRKSTlKXEmLb2OYrZd8IQgr+P4G0xls7r9g4nbQOVszyafh1 X-Received: by 2002:a05:6a00:c86:b0:646:3c2:4d30 with SMTP id a6-20020a056a000c8600b0064603c24d30mr3053899pfv.30.1686943830204; Fri, 16 Jun 2023 12:30:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686943830; cv=none; d=google.com; s=arc-20160816; b=w3R6ZEN5DktbroaXGIoLVZ1u6BrOv7S3Ehfd6q/mltr6YY6wCIU2xV4kARgsEq743T nv9JIUzGNCWW/+31gDmNf/u4pVd5lGGufYJw0y2fmvdJSI0feOqqMuW03yD6YKtA7MLa XmX0BE/o1WKPv2CLnk5z7xHDZkYFB0EYhkll+l03/gpDaReBLkDwwBefgmBAKewLuG9A qaadmzHEYeTNe74cQGOhnKP/r32FuEDHFGJUP2qsOy2xRq/rxPNmi8ejx5K2ArAhZS9W 9SQd4sQoyuWgPNlamM5CB2NZfoiBMeR/3A/flv/DZFv/qYSR/VvMvE5V7ZWqZvZVW/UD Ulyw== 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=3ToMvz9hdObD8Sor51jCP3QvZh1KeB3m1ZKfHNQFnSA=; b=k4AzvNJ+JT3bCwCdx6CyKvNydSlUyXXh4RJLQfxe9mzgY6kGu3Gdk01Cn7l8Kt16Q/ c7MFQjnKxmX2A3+wcUx2YJn+dmpgy+I1YJNrPkpu8J4e/4iRa7RgKQYGDl1vXuVskCif tiCFwY7rKYRYlltVVMNVkRdiKI+GbyBXVyfOPnFvHEJOQpsV/ir9NuiOG6YcE8StrUEZ bASTOz3XXoEYwDxEx8Nctw5c3QNfj03quv8/NUNoh+3i80h4dFVLeweLBFqGSAoWPc+B noIcBl9SSbRZwyoFGr6plTr7ihJ5uxPu91yCN+CHME7ozqXHeWqFFZNORtMxbD/ccukG Ee2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HFSiaoMO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=qxfdstSm; 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 z20-20020aa79f94000000b00666689cbbfasi5704851pfr.248.2023.06.16.12.30.14; Fri, 16 Jun 2023 12:30: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=@linutronix.de header.s=2020 header.b=HFSiaoMO; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=qxfdstSm; 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 S1346039AbjFPTS3 (ORCPT + 99 others); Fri, 16 Jun 2023 15:18:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345953AbjFPTRF (ORCPT ); Fri, 16 Jun 2023 15:17:05 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 544F73A8D; Fri, 16 Jun 2023 12:17:01 -0700 (PDT) Date: Fri, 16 Jun 2023 19:16:59 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686943019; 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=3ToMvz9hdObD8Sor51jCP3QvZh1KeB3m1ZKfHNQFnSA=; b=HFSiaoMOmHZLOSXbBtCLodWK7kai5HjvRANCtZVLSSbd05QKefN6axM1acETqQXG8IZtoP SbJ7OBU4M5UeY4sy9mMDouOexjrFaaVjRUNze5UbCg4jz55Lb7XAlGOtxGWb9rCsuOleo6 okISBnIPaBvYN4ZGwTGBxMaaczt5rhqpnuXrvNOjZXIsz+wTEXgx7Tt3biFY5WjQS6RR7w Lq9WiYKoFJ9Vs5uNEe087v+XfGPaEQXDVQ5EXRChwpyhXPfjXbGDvKfW9aQ9hASPhKN26O dBk3rtIcCYNx1tgW++E48NGNLmC5KYqG9yuSXyhwpVHroB689xaMPdEo/FEX9g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686943019; 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=3ToMvz9hdObD8Sor51jCP3QvZh1KeB3m1ZKfHNQFnSA=; b=qxfdstSmaVFMkv/KMZNhrwb7jZAfnpSJoZkg+/6+GY5Evo6GnlPzqK+SBMvFElYCW7shAG BZFY5AjmjzIHioDg== 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: <168694301944.404.15753114470061222047.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768888813639919522?= X-GMAIL-MSGID: =?utf-8?q?1768888813639919522?= The following commit has been merged into the x86/shstk branch of tip: Commit-ID: d3ffcb4e9599461daf567a0ac3ecebe7e09142d3 Gitweb: https://git.kernel.org/tip/d3ffcb4e9599461daf567a0ac3ecebe7e09142d3 Author: Rick Edgecombe AuthorDate: Mon, 12 Jun 2023 17:10:47 -07:00 Committer: Dave Hansen CommitterDate: Thu, 15 Jun 2023 16:31:33 -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 101e721..c4b222d 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -883,6 +883,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); @@ -890,6 +893,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);