Message ID | 20240125062739.1339782-13-debug@rivosinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-38019-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1453820dyi; Wed, 24 Jan 2024 22:33:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHSwkJmX+WDQyd2fFOckUFkqoPWNte8HR/2XLFT1SOmx/v5RCNcaHnuEK3OXczJ8jduquvn X-Received: by 2002:a25:f505:0:b0:dc3:65b8:9f9 with SMTP id a5-20020a25f505000000b00dc365b809f9mr392502ybe.37.1706164389108; Wed, 24 Jan 2024 22:33:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706164389; cv=pass; d=google.com; s=arc-20160816; b=X0bw7LjBZsADZuj02K04UCxLGt8lu7E9iNh+f07ChoYvdthBr67wCouGJo5XEJNrNj VHtsUhCatdQLZ6w84stioe6AB250a9Yj5GqFQCSyciBL2+/t+OYofAD9nI024Cn+xnjG GOdYS3OMCWMiu0h/NBimzM9YtMbkboqDDzmVyVnUj9Q65Igh5q67z9LL/CC5kWXxuhek nG7ep2WYcOp1etMFI41rpogk2MBaJa9YrfQ0EIj4x0pqmV8p1ogW4WtnEqAG1UdqdLx5 wlLFi45qUOHG40mRU0Q7eL76s3oUKXx5UvgybSzzjiQCeY1IzAoOCToWvWhuCvFMU7oB VzNw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9U4/v4w/mrwXRuPEpy9c03cIo3F2WWlXK10aLJp76Yo=; fh=oy7V1wWqiaug32hsWRXm98kKNp5NFPTWbY7PiGr4deM=; b=L5ELkQoiEQfgUWAzs1vOd2FMHJTS3O8ej29Eu+WKSTdGZt9d0PVaYxp/vcGDblFuaD DITxzeLjUt5z4W2a6+ROG0B7C4Ytefbq7Gf9oCdV+Egty3De6lXe6UZTZ4CMg1L2AsMp KUPr4V5118A6Qxq25oVbk50f047IIZmn1fCMy1TCbsPxn6G6yIZbGCpS9Lng68JpZ9Aa svpWXn7BlCkWvr8PnXWypsgiAfkfn1U6oW9OzMBYYriouCCl4gcxT4/898xs50X9afwn HIB+0YMyu0WaR0BEVJu4eJdHZV83t9RAygendyy8QvB93p7hWcfjeSBFUbhrEgOx6eVk fXAg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=sJs6+JdF; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-38019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38019-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m5-20020a0cf185000000b0067f79fc97f1si12057039qvl.397.2024.01.24.22.33.08 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 22:33:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=sJs6+JdF; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-38019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38019-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D27A51C24C8D for <ouuuleilei@gmail.com>; Thu, 25 Jan 2024 06:33:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A3C71B27D; Thu, 25 Jan 2024 06:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="sJs6+JdF" Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8683919BCA for <linux-kernel@vger.kernel.org>; Thu, 25 Jan 2024 06:29:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706164182; cv=none; b=M/GIZeQK879kCvyGt0BSb/JA3ljHCQIQq1zNWHWrOAZnwMPpZ90aYyYVSdy82PKuSt853ZuJG3ysVaacKEspKerrBGNkrLsk9GT6ird0vPf4ykUV886M8b7BpurovqzsjggUUlWtZDZrQmWih3cf0glGYFiUwvY+Nep1TfjCBq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706164182; c=relaxed/simple; bh=yGHZsYT52As0iEg7iPcfGB1vnJ1Qj3UnSp8T8gtPGCk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=knr2t0tISfA9jWR5TVGPVkz90D2Tt6BOkqKCTJBrB767hmZSdNBrDn4Uf8qvy18wfYISRSNAk8bY2rQMLhKDuMUNZ1VX9GOgDFtOs+vB4sRvJgJtiwURgXUkLG4y6ocQtpkK+xGMZEFQhm9UvggWZbIzdfJ4QwzZBbBq9uY0Yhw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=sJs6+JdF; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6dd7b525cd6so2048288b3a.2 for <linux-kernel@vger.kernel.org>; Wed, 24 Jan 2024 22:29:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706164180; x=1706768980; darn=vger.kernel.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=9U4/v4w/mrwXRuPEpy9c03cIo3F2WWlXK10aLJp76Yo=; b=sJs6+JdF4isADJZ1Tn6y+quG+jcKyWheHjkxGaZ1FWKsWGdf40ViLb1G8SULnNHGlV wz1gERUtyvwPfF2o0TXzvJyKYZNQMQLOiMJ2ND2Kkmj8Usvdv5oV9ITx8l1KQImuHHcU xrToPu4uNaDCkQs9rLYO2tgb0bBLqUeZb1CioLlkc3lYkjOijJ4fj0+D6BBKfjVfzNlK C4rgDcdLUaxPFKQI33SWV3FhUERSChp0+mc2UGJYCESGxbeVi4rtsHewP4ZG//xv+wo1 kInOSARHP6vGVFsJzjx/En+4VI4dZ1xi/vx7679lOMKKMgaVtRjp7QUQDSupkgyCqe86 hkXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706164180; x=1706768980; 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=9U4/v4w/mrwXRuPEpy9c03cIo3F2WWlXK10aLJp76Yo=; b=iJ2dgeEsm8tNe6Rbv+Qm00w9UixwERHfwo6NxiAdp8Zvm6FLRlEqEn3+g5ABnwKgPl 2K1Ts6YkCczzrcOvL/r9pgkhRSzRjIwSoo3pJ2ia86TeFkAc6MUDsnrDauJxLTGo7InR RT7daN9cftyh28PXeJ4J1Y4MI8CwBspzQU1vne+setJxvy2y55cZ8q6a3eoJUteS/Npm GFWqZVUMh0nowwt4dUYhiEW5QjvsTEfNfmHEL/VKv+Y+bh5SdWvhsReS8UgEa0kwQOkE d2y9ARsN4g4yuSCwLoW0Rl+wNuaXEvCnaFtPYWlE7CdfgxSo+lGAuVTrgSMdqPZHiZvw 63OA== X-Gm-Message-State: AOJu0YyomNkpLrsT4STM1Rx00nmzpRQYx86sM2JGyrWwrQziW3gJpyos PykhpkeFrMgSZvMrl0s+Y6SG1/xEQhgM6PNOohkSDykr6NUsxQ+XgpZikRDNbcQ= X-Received: by 2002:a05:6a00:4006:b0:6dd:a072:867 with SMTP id by6-20020a056a00400600b006dda0720867mr290270pfb.15.1706164179881; Wed, 24 Jan 2024 22:29:39 -0800 (PST) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id t19-20020a056a00139300b006dd870b51b8sm3201139pfg.126.2024.01.24.22.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 22:29:39 -0800 (PST) From: debug@rivosinc.com To: rick.p.edgecombe@intel.com, broonie@kernel.org, Szabolcs.Nagy@arm.com, kito.cheng@sifive.com, keescook@chromium.org, ajones@ventanamicro.com, paul.walmsley@sifive.com, palmer@dabbelt.com, conor.dooley@microchip.com, cleger@rivosinc.com, atishp@atishpatra.org, alex@ghiti.fr, bjorn@rivosinc.com, alexghiti@rivosinc.com Cc: corbet@lwn.net, aou@eecs.berkeley.edu, oleg@redhat.com, akpm@linux-foundation.org, arnd@arndb.de, ebiederm@xmission.com, shuah@kernel.org, brauner@kernel.org, debug@rivosinc.com, guoren@kernel.org, samitolvanen@google.com, evan@rivosinc.com, xiao.w.wang@intel.com, apatel@ventanamicro.com, mchitale@ventanamicro.com, waylingii@gmail.com, greentime.hu@sifive.com, heiko@sntech.de, jszhang@kernel.org, shikemeng@huaweicloud.com, david@redhat.com, charlie@rivosinc.com, panqinglin2020@iscas.ac.cn, willy@infradead.org, vincent.chen@sifive.com, andy.chiu@sifive.com, gerg@kernel.org, jeeheng.sia@starfivetech.com, mason.huo@starfivetech.com, ancientmodern4@gmail.com, mathis.salmen@matsal.de, cuiyunhui@bytedance.com, bhe@redhat.com, chenjiahao16@huawei.com, ruscur@russell.cc, bgray@linux.ibm.com, alx@kernel.org, baruch@tkos.co.il, zhangqing@loongson.cn, catalin.marinas@arm.com, revest@chromium.org, josh@joshtriplett.org, joey.gouly@arm.com, shr@devkernel.io, omosnace@redhat.com, ojeda@kernel.org, jhubbard@nvidia.com, linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC PATCH v1 12/28] riscv mm: manufacture shadow stack pte Date: Wed, 24 Jan 2024 22:21:37 -0800 Message-ID: <20240125062739.1339782-13-debug@rivosinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240125062739.1339782-1-debug@rivosinc.com> References: <20240125062739.1339782-1-debug@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789043030602466076 X-GMAIL-MSGID: 1789043030602466076 |
Series |
riscv control-flow integrity for usermode
|
|
Commit Message
Deepak Gupta
Jan. 25, 2024, 6:21 a.m. UTC
From: Deepak Gupta <debug@rivosinc.com> This patch implements creating shadow stack pte (on riscv). Creating shadow stack PTE on riscv means that clearing RWX and then setting W=1. Signed-off-by: Deepak Gupta <debug@rivosinc.com> --- arch/riscv/include/asm/pgtable.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 54a8dde29504..7ed00b4cc73d 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -408,6 +408,12 @@ static inline pte_t pte_mkwrite_novma(pte_t pte) return __pte(pte_val(pte) | _PAGE_WRITE); } +static inline pte_t pte_mkwrite_shstk(pte_t pte) +{ + /* shadow stack on risc-v is XWR = 010. Clear everything and only set _PAGE_WRITE */ + return __pte((pte_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE); +} + /* static inline pte_t pte_mkexec(pte_t pte) */ static inline pte_t pte_mkdirty(pte_t pte) @@ -705,6 +711,12 @@ static inline pmd_t pmd_mkwrite_novma(pmd_t pmd) return pte_pmd(pte_mkwrite_novma(pmd_pte(pmd))); } +static inline pmd_t pmd_mkwrite_shstk(pmd_t pte) +{ + /* shadow stack on risc-v is XWR = 010. Clear everything and only set _PAGE_WRITE */ + return __pmd((pmd_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE); +} + static inline pmd_t pmd_wrprotect(pmd_t pmd) { return pte_pmd(pte_wrprotect(pmd_pte(pmd)));