Message ID | 20240912231650.3740732-3-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 11C9CEEE274 for <linux-mm@archiver.kernel.org>; Thu, 12 Sep 2024 23:17:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FD3E6B008C; Thu, 12 Sep 2024 19:17:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 885856B0092; Thu, 12 Sep 2024 19:17:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6AF6D6B0093; Thu, 12 Sep 2024 19:17:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4AD366B008C for <linux-mm@kvack.org>; Thu, 12 Sep 2024 19:17:18 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C9D2BC0595 for <linux-mm@kvack.org>; Thu, 12 Sep 2024 23:17:17 +0000 (UTC) X-FDA: 82557649314.26.2A9B563 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf26.hostedemail.com (Postfix) with ESMTP id EBC09140005 for <linux-mm@kvack.org>; Thu, 12 Sep 2024 23:17:15 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=cqCdANpm; spf=pass (imf26.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.172 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=1726182930; 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=067qKPjJ+n9l6Epc1eYM3Yt2z4Jj28HWHwDjljiSStY=; b=pnFFDKGi/3HHnDCntLW84P7WVweMr9UE6n7Krr7fnCuAoegdpiIr9ayCdppoVsn+2Zpi18 Fx66JcMChLlquzKG/WKFj9xkwWSdHR+WSWCEhizhyC3Uv+L3YAr8DugHS78/NcCH4kNauZ KmcbLbSRP2SV4efNHWORBbd8NB/fSiE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726182930; a=rsa-sha256; cv=none; b=MZABQEcoun5LcYECsd1evFgRpHzLdihA5puDjb14aX1lKqJTd7LaHOstfgbbvKc5xvIFop xe3oWNdL7XTKS0N5zLVPuBApdCM467SFS1cH0zQOyuEX2apLQyPCuPo7y45G3KIVn7FwAK 9qR+r4NYjGpegPKVLrvlYnDFOhqJ350= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=cqCdANpm; spf=pass (imf26.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7db233cef22so183850a12.0 for <linux-mm@kvack.org>; Thu, 12 Sep 2024 16:17:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726183034; x=1726787834; 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=067qKPjJ+n9l6Epc1eYM3Yt2z4Jj28HWHwDjljiSStY=; b=cqCdANpmdn5LCNx6nuj7SkCrgFCwpIWda161ye+T3Ve1l5Ss6iyZGJtlTqbzLh7T7h cF5RHWbklw9AJdSynaUBQKHdAESmAE09pi7gYX3cK5XpY/yCpIu2EBQwa9+6FBmwL9mI 3VrSPVME2pD6klndZMdyd6xePgAqF5AH2pPy2FqlTUeEB2A5CjUzkht7Z98LgTmWiebu 5SrxFTH90t7Z0+XOmokoa2sTbYUeh61i9lGyyzCzQ1CHQnRiKedOm2KjaWUB5BQup72m NHUc5epWun7Sux8Zn3TQTW7G2ms8PXPFER9Te3cHDrVqOKsf3MPpfAKTP7GDD+nN13NP Z5/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726183034; x=1726787834; 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=067qKPjJ+n9l6Epc1eYM3Yt2z4Jj28HWHwDjljiSStY=; b=IySy8JV1krgzt6NqhyF/3BR+OaaXu91FAlb5nYoF8M071TEqVj9ULWWMqc9GzOUROd OXYcs6K/qnbZapC7hgQZlM+gJpbgT4Iv/mlPUXAgzGNAnOehBfaP4aPbX4EJs1BnBclg 3v+cCNK2LkO/RsDMdWGEz01Q6v00kqUub5oaQ++32gKnSztXThpnvHe5/fQdTmCFLGSx TorLg3wzUDFNggOp6JQWAGwBI0o5DzzVYKQ91LD2CIQXOToMqr2lSNfEtyPlq6EzNCEk IVKkYRm+Vs064EXkNtie570TMeiJPCmKoem/uUVEtiFN8J1m4SSqFPN73r3y99K7uvAf jXdQ== X-Forwarded-Encrypted: i=1; AJvYcCXAgSLZO9iHpkR6CDZsVkTekMkz+2ueaC9X2uaP0mMoHQBLxXMvKjF60K7o0TYCG6hSTV6WxwUy6Q==@kvack.org X-Gm-Message-State: AOJu0Yy2U6NiW3w3yiA0iLYcr7QctFVZ3T0WoMODDVhsooAN2X9KtRYo LdEi6ARZ5yD+u5+RClI3IYZVhjWIDgV7mZaS4gEB/ALwJc8WSiVPN/W711RWixm8kuXR4m7MBVX N X-Google-Smtp-Source: AGHT+IGUPoWnvS5/UyAev2mMCxr4fAbJAZEQ5NXGYl3k4LYiYl5m+yOy9I9Oauh7+qEP1ZcWno2Wvg== X-Received: by 2002:a17:90a:d489:b0:2d3:cd57:bd3 with SMTP id 98e67ed59e1d1-2dbb9f3a7cemr1099703a91.29.1726183034358; Thu, 12 Sep 2024 16:17:14 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 16:17:13 -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 02/30] mm: helper `is_shadow_stack_vma` to check shadow stack vma Date: Thu, 12 Sep 2024 16:16:21 -0700 Message-ID: <20240912231650.3740732-3-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-Stat-Signature: t7japkwgcbshtpsa9cobtw1rxnbwngd8 X-Rspamd-Queue-Id: EBC09140005 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1726183035-374670 X-HE-Meta: U2FsdGVkX1+clVxQ92SgDoKWtan5iltUFLVq6pILsN927TUIBCy68kfeD7QtJwuQIJTEjE9OftegnPLfPMTfsEw5y2kLPE7j08nwGDh0EKI3FTTQC482jvvwuPAW3J4bgPQ8QbtACCPhWbrjjsO8P8JyNbckJ5jtOXTAZoGurocN7F96ORKUKjHOMCYJS45namwIeC7KHFlUZ6iG0kP7LsJe9uUtDiYicbYXaSsOVBmYpk7ktIGcppQ4pzcDWZq/z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7yu5m/aA7PfT+Y4uXU8FoV4Zsk1sA1/ot50ps+HRBMCbdJlA+u5zHuHxk8jewgXeobYbaNPoYj3eJLQv64Q/O2/ChuHFIDua9T78YuRrRZZ1Fzd6Db5FBfnpPmfL636W74t1EoCbvMdl6zcvx+feyK9KZ97URgSSF7UGBjQ== 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/include/linux/mm.h b/include/linux/mm.h index e39796ea17db..f0dc94fb782a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -361,6 +361,11 @@ extern unsigned int kobjsize(const void *objp); # define VM_SHADOW_STACK VM_NONE #endif +static inline bool is_shadow_stack_vma(vm_flags_t vm_flags) +{ + return !!(vm_flags & VM_SHADOW_STACK); +} + #if defined(CONFIG_X86) # define VM_PAT VM_ARCH_1 /* PAT reserves whole VMA at once (x86) */ #elif defined(CONFIG_PPC) @@ -3504,7 +3509,7 @@ static inline unsigned long stack_guard_start_gap(struct vm_area_struct *vma) return stack_guard_gap; /* See reasoning around the VM_SHADOW_STACK definition */ - if (vma->vm_flags & VM_SHADOW_STACK) + if (is_shadow_stack_vma(vma->vm_flags)) return PAGE_SIZE; return 0; diff --git a/mm/gup.c b/mm/gup.c index 54d0dc3831fb..2f84a0a80cfe 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1289,7 +1289,7 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags) !writable_file_mapping_allowed(vma, gup_flags)) return -EFAULT; - if (!(vm_flags & VM_WRITE) || (vm_flags & VM_SHADOW_STACK)) { + if (!(vm_flags & VM_WRITE) || is_shadow_stack_vma(vm_flags)) { if (!(gup_flags & FOLL_FORCE)) return -EFAULT; /* hugetlb does not support FOLL_FORCE|FOLL_WRITE. */ diff --git a/mm/internal.h b/mm/internal.h index b4d86436565b..f7732c793f3f 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -798,7 +798,7 @@ static inline bool is_exec_mapping(vm_flags_t flags) */ static inline bool is_stack_mapping(vm_flags_t flags) { - return ((flags & VM_STACK) == VM_STACK) || (flags & VM_SHADOW_STACK); + return ((flags & VM_STACK) == VM_STACK) || is_shadow_stack_vma(flags); } /*
VM_SHADOW_STACK (alias to VM_HIGH_ARCH_5) is used to encode shadow stack VMA on three architectures (x86 shadow stack, arm GCS and RISC-V shadow stack). In case architecture doesn't implement shadow stack, it's VM_NONE Introducing a helper `is_shadow_stack_vma` to determine shadow stack vma or not. Signed-off-by: Deepak Gupta <debug@rivosinc.com> --- include/linux/mm.h | 7 ++++++- mm/gup.c | 2 +- mm/internal.h | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-)