Message ID | 20240912231650.3740732-14-debug@rivosinc.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D55BFEEE271 for <linux-mm@archiver.kernel.org>; Thu, 12 Sep 2024 23:18:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 702C76B00A8; Thu, 12 Sep 2024 19:18:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B10D6B00AA; Thu, 12 Sep 2024 19:18:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B5B36B00AB; Thu, 12 Sep 2024 19:18:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2A6596B00A8 for <linux-mm@kvack.org>; Thu, 12 Sep 2024 19:18:06 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E3E98C0595 for <linux-mm@kvack.org>; Thu, 12 Sep 2024 23:18:05 +0000 (UTC) X-FDA: 82557651330.28.79BB934 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf19.hostedemail.com (Postfix) with ESMTP id 27A781A0007 for <linux-mm@kvack.org>; Thu, 12 Sep 2024 23:18:03 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=SQfku0bI; spf=pass (imf19.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726183031; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2o2VksxHwPquNK6/4RcwFNcMNDB9IND71Ze1od4h7MM=; b=XcKgee1OYWcMZ4flGDC+NSgC8paj+ZXL+uEAQXZuL8D0yXN24TNeFD+4U2ugFmyefL+MB5 aYFwV0INFRMT0GXauZrRoN18q8TSGKv+qKxbqj7+pmECjfQ1hIqgZzvE90eNnoYJF3nK91 Oswcho/IXKzArcF+DF8hrs56rnbFXNk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=SQfku0bI; spf=pass (imf19.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726183031; a=rsa-sha256; cv=none; b=uCg7gyZTClG4HUCuvYqxHacgdDsjZEDHrzzRS1zjl9yRS023/Nbc/pxznHWc+tPSIMznRi li/U6e8XnQl46LfRIIRdrVXEmowd55VsaW+t7rPdm0B/NPHEdx9tCwXJ6jV7BmuLpi3X91 9MTvXQbBsm77x3xx+5GsV51rsny2UHk= Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-70b2421471aso180296a12.0 for <linux-mm@kvack.org>; Thu, 12 Sep 2024 16:18:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726183083; x=1726787883; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2o2VksxHwPquNK6/4RcwFNcMNDB9IND71Ze1od4h7MM=; b=SQfku0bIy28Mew+2NMELYMWCr1NXBxVBMrmgXBkjTDO6963xF0djPjN7gYx7aZTxZ5 Ue1wIwUOoBxIr7n+ImJzjKZ1ofGIixyroGsZpTKOQz8+zQRwpSIDA56ESIRsU6pts9RG mIKnWeGRJJta9E5uGPUcuF3cPVqduId14oEYlIObt8LmRgZQJSHQkxPH3uG5LxRM3OO3 j0E12NFxJLFSYG530DmQYlWG63AmhQRY1l4LCGF/l7HnerPH0P5AS2V8MJvvu8MDLcwo 1uyxOtP4W32H8jLRK/gFCWq9VY6Qn4Nv7ZL4CoUCNGpOSL0XRcjCVoTkuyRk3bKFobLQ RomA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726183083; x=1726787883; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2o2VksxHwPquNK6/4RcwFNcMNDB9IND71Ze1od4h7MM=; b=ohEfXbNvsCLfOUXQbpE8MKB2PjOmbVrpbNK/DavztlNOBxCz9SbQ3S0xdeHZZA7t++ f4SEaQVoo/zpVj7UVxIs74n/GOK/2dK5MLJyaQ7LSyPwzqeau/v0fwfEbR9D+0/3/3OT nBIrj1CbmPwDq3VBhRZfY31/E2dNuPvvjYe1TuXHiTe0+xkQQvLIHpICJBon5igFS9BO vX+nUE9++AYvEJsLegth+5mqHU2VuBa9xFJhemrQsiGqA56wvMc2FYI5ICQYG3LU/nbr 3ovbsN04BAhcRPpsshnaQe+T2Ghudyv8uo9S4aWMA3NLKeP1yE6YgfVtp1IXvDffpMCH fx6g== X-Forwarded-Encrypted: i=1; AJvYcCWoPnwJaU5IY2vYrD94Lw2wvdwCEYQ0RdEQB8tC4RIRGpx94fq2N1gvGFWoTd+fEJxQbPrNSgfgpQ==@kvack.org X-Gm-Message-State: AOJu0YxF1mCcSFgBXIMv6VCCrKOU1ZT1w+P5XIF59i4un6EYk1Q8ITQl qWIuXuu4cm7RAxRhXx1uDY+XJ/OlRdeA/KXegF3pakeeig8a2WcfUsNU5zOKiZ4= X-Google-Smtp-Source: AGHT+IFc5Xo3W7imJs6v1qZAyylQCnIMRJTm9oY3HnptRktjFuhlx1nDwXattiRmY7sUUOR5c5uRiQ== X-Received: by 2002:a17:90b:1e45:b0:2d3:b748:96dd with SMTP id 98e67ed59e1d1-2dbb9eda70cmr1036124a91.25.1726183082840; Thu, 12 Sep 2024 16:18:02 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db6c1ac69asm3157591a91.0.2024.09.12.16.17.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:18:02 -0700 (PDT) From: Deepak Gupta <debug@rivosinc.com> To: paul.walmsley@sifive.com, palmer@sifive.com, conor@kernel.org, linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: corbet@lwn.net, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh@kernel.org, krzk+dt@kernel.org, oleg@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, peterz@infradead.org, akpm@linux-foundation.org, arnd@arndb.de, ebiederm@xmission.com, kees@kernel.org, Liam.Howlett@oracle.com, vbabka@suse.cz, lorenzo.stoakes@oracle.com, shuah@kernel.org, brauner@kernel.org, samuel.holland@sifive.com, debug@rivosinc.com, andy.chiu@sifive.com, jerry.shih@sifive.com, greentime.hu@sifive.com, charlie@rivosinc.com, evan@rivosinc.com, cleger@rivosinc.com, xiao.w.wang@intel.com, ajones@ventanamicro.com, anup@brainfault.org, mchitale@ventanamicro.com, atishp@rivosinc.com, sameo@rivosinc.com, bjorn@rivosinc.com, alexghiti@rivosinc.com, david@redhat.com, libang.li@antgroup.com, jszhang@kernel.org, leobras@redhat.com, guoren@kernel.org, samitolvanen@google.com, songshuaishuai@tinylab.org, costa.shul@redhat.com, bhe@redhat.com, zong.li@sifive.com, puranjay@kernel.org, namcaov@gmail.com, antonb@tenstorrent.com, sorear@fastmail.com, quic_bjorande@quicinc.com, ancientmodern4@gmail.com, ben.dooks@codethink.co.uk, quic_zhonhan@quicinc.com, cuiyunhui@bytedance.com, yang.lee@linux.alibaba.com, ke.zhao@shingroup.cn, sunilvl@ventanamicro.com, tanzhasanwork@gmail.com, schwab@suse.de, dawei.li@shingroup.cn, rppt@kernel.org, willy@infradead.org, usama.anjum@collabora.com, osalvador@suse.de, ryan.roberts@arm.com, andrii@kernel.org, alx@kernel.org, catalin.marinas@arm.com, broonie@kernel.org, revest@chromium.org, bgray@linux.ibm.com, deller@gmx.de, zev@bewilderbeest.net Subject: [PATCH v4 13/30] riscv mmu: teach pte_mkwrite to manufacture shadow stack PTEs Date: Thu, 12 Sep 2024 16:16:32 -0700 Message-ID: <20240912231650.3740732-14-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240912231650.3740732-1-debug@rivosinc.com> References: <20240912231650.3740732-1-debug@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 27A781A0007 X-Stat-Signature: gcxtjsxma1bi4u53tcd13crh86ndxe76 X-HE-Tag: 1726183083-506176 X-HE-Meta: U2FsdGVkX19JjYoX832xVrp+/1jr/iLMySvqo5O+Vr0NdphE85nDJgmwe9VvrNDdj2K8aQj4MMFBTcwtGTBYe+JP8MEytCqyhGwDNAakklhaUehJd9xtClhz2KSbqSBqTEMdg5FIV7/LbrdSOQnt+dFYijuaHI7QaW/pmyfStZZ6YpQfUW+yfIvjUodMgN4tb9wiGPAVdh79xXZV2VBfDonK16p9tQFgXLFQYgt05REn3vRfd0F8wUe/TnwBTu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I7hUsy9of4raTFKP/OpK4QU3xJg2VQ1kEZ2UPcz4nnwSfkxkQD/n5APlGolmHg5bRSjpKGRVeTM07PkmvhleuIP7xi8dRoeh3sGs//9nrdzDUXLnzsuIE4F+5T9b7toPdU X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
riscv control-flow integrity for usermode
|
expand
|
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 0b6c66fb853a..30fd4874e871 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -420,6 +420,10 @@ static inline pte_t pte_wrprotect(pte_t pte) /* static inline pte_t pte_mkread(pte_t pte) */ +struct vm_area_struct; +pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma); +#define pte_mkwrite pte_mkwrite + static inline pte_t pte_mkwrite_novma(pte_t pte) { return __pte(pte_val(pte) | _PAGE_WRITE); @@ -732,6 +736,9 @@ static inline pmd_t pmd_mkyoung(pmd_t pmd) return pte_pmd(pte_mkyoung(pmd_pte(pmd))); } +pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma); +#define pmd_mkwrite pmd_mkwrite + static inline pmd_t pmd_mkwrite_novma(pmd_t pmd) { return pte_pmd(pte_mkwrite_novma(pmd_pte(pmd))); diff --git a/arch/riscv/mm/pgtable.c b/arch/riscv/mm/pgtable.c index 533ec9055fa0..0dd6104a35ac 100644 --- a/arch/riscv/mm/pgtable.c +++ b/arch/riscv/mm/pgtable.c @@ -142,3 +142,20 @@ pmd_t pmdp_collapse_flush(struct vm_area_struct *vma, return pmd; } #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + +pte_t pte_mkwrite(pte_t pte, struct vm_area_struct *vma) +{ + if (vma->vm_flags & VM_SHADOW_STACK) + return pte_mkwrite_shstk(pte); + + return pte_mkwrite_novma(pte); +} + +pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma) +{ + if (vma->vm_flags & VM_SHADOW_STACK) + return pmd_mkwrite_shstk(pmd); + + return pmd_mkwrite_novma(pmd); +} +