Message ID | 20241001-v5_user_cfi_series-v1-2-3ba65b6e550f@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 26F47CEACE4 for <linux-mm@archiver.kernel.org>; Tue, 1 Oct 2024 16:07:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7787128009D; Tue, 1 Oct 2024 12:07:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 700DA280068; Tue, 1 Oct 2024 12:07:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57B8328009D; Tue, 1 Oct 2024 12:07:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 339C5280068 for <linux-mm@kvack.org>; Tue, 1 Oct 2024 12:07:08 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DBE82415D1 for <linux-mm@kvack.org>; Tue, 1 Oct 2024 16:07:07 +0000 (UTC) X-FDA: 82625512494.17.2FED94F Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf28.hostedemail.com (Postfix) with ESMTP id CAAD9C000C for <linux-mm@kvack.org>; Tue, 1 Oct 2024 16:07:05 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=zbbxLBxV; spf=pass (imf28.hostedemail.com: domain of debug@rivosinc.com designates 209.85.216.45 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=1727798698; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OwXMBbOWCv06xRC7kuAtikxfL3CuNBKfrSTtPkKqEqk=; b=YG+XDxd/ClanSaZfMrbXBpieLww3R4iyDam5dZwRQYvCg+63DkxvFt+L5lmCqxUE6OiOHo Wz2Uf5J65LCtVWh/Ata16eY8tIJxext7MkxTBvY6AqmyF70jA9wnonanHiWbwJq/SHjFBd h+XP0KImMfgqRLA5H6BkYEDOByqgZCM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727798698; a=rsa-sha256; cv=none; b=kIMyh1FVKEd2do9g7STIAlX9o4owOhb7gtEbRtYOpqUU0hsu8hV96Dol6Lq3GP7mBlHFUq Wx6E9MEzrF9mRtw/oKkl9BNxIRCuY8i3Nwa5ZV8a8EVOcyIfiw1oHe8cPogOGPeFkzlD0C xELidtG6/AZ58yWVZXiDJ4Tnui/uRyQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=zbbxLBxV; spf=pass (imf28.hostedemail.com: domain of debug@rivosinc.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2e0b93157caso3394523a91.0 for <linux-mm@kvack.org>; Tue, 01 Oct 2024 09:07:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1727798824; x=1728403624; darn=kvack.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OwXMBbOWCv06xRC7kuAtikxfL3CuNBKfrSTtPkKqEqk=; b=zbbxLBxVtdnldaTY3seKG546cRk92akiiV5wBKKUc5Ac4ubCWEmY6bKtgu50kuddw8 TJQ86PJyGdAWWbbQBJmzFLzEqo7iwd+y31i04okoSY9ERN1sZSbURcHfnGFiZJzxhLup bhqZjkoPWE8vHd7a+7NNNntfCeZFd8utIIyzVifnq89UMp8Bd7Kad9UXWNBp0sEHinDf CsGQG/rP7pD4Rpdr+e4q+SNN0Uh1+YNP0+k5NeEznv/3lVtKi3oyu3dAiE/BWgC9K2S9 b33DGWhmOrDFmpXOgzvCO20Wr7vOGMUGb+GeEPldd71B8VCN9DQLdOd8TnZxYTHsynP/ jGoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727798824; x=1728403624; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OwXMBbOWCv06xRC7kuAtikxfL3CuNBKfrSTtPkKqEqk=; b=tzPNyxDNNgah3WHaASgWLR8pvCJEZtnfaDF/e1/8yLHL1zKn46jrHkP/xljV7/UBEw Tmb3kbzLm6sCDB/z8e2Y16oW0WuT23aaymmIlNbnGnls4ZUJBAvPS+8V8CcZTfYtn7oC LOx7VjMljmIYJ4GCiGfeUv+P2kRXjgk2vN50aAQLDppEv5v1Ysi3JdFX2R058mqajZo5 Tu7w8bZIu/5P6rYuTPS5H0/LHbXqX1fC71h5x70+a3y9d/p7WSpTUcuWXgqa9usZy5Wt K7vVCnZNEOc2SU3NTsxe/6VDy4aaTgIC0m5YfyeaYQLM7vV0Re+Goo2zV95XdmZT0Gj4 h3QA== X-Forwarded-Encrypted: i=1; AJvYcCW2VK0w7uqpS9m3FkOnxyRh8DuQ03OTZi1VC1T9eJ8QWWn/fR26n1cROHmiPzY5n9r5Ik9CH/IMsA==@kvack.org X-Gm-Message-State: AOJu0Ywz+zA013+Ii/HjANSJE4p8i/2WTRDBLj2BCEz8OBSnYa9uNVnn y+OPpMVFIN6Ak/SPRk5vZjxqfIdtOQRkNc+5Qb/0y6c91bfyWFPMj7BZYSlOvzQ= X-Google-Smtp-Source: AGHT+IHz3lo2CWK5+xlTScPaDZKtUmo8trno2Ltv0riHEvGYwt0AENfouR5jnL074g0esmpKOm5AYw== X-Received: by 2002:a17:90b:154:b0:2d8:e6d8:14c8 with SMTP id 98e67ed59e1d1-2e1853e1474mr122588a91.15.1727798824224; Tue, 01 Oct 2024 09:07:04 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e06e1d7d47sm13843973a91.28.2024.10.01.09.07.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 09:07:03 -0700 (PDT) From: Deepak Gupta <debug@rivosinc.com> Date: Tue, 01 Oct 2024 09:06:07 -0700 Subject: [PATCH 02/33] mm: helper `is_shadow_stack_vma` to check shadow stack vma MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20241001-v5_user_cfi_series-v1-2-3ba65b6e550f@rivosinc.com> References: <20241001-v5_user_cfi_series-v1-0-3ba65b6e550f@rivosinc.com> In-Reply-To: <20241001-v5_user_cfi_series-v1-0-3ba65b6e550f@rivosinc.com> To: Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>, Andrew Morton <akpm@linux-foundation.org>, "Liam R. Howlett" <Liam.Howlett@oracle.com>, Vlastimil Babka <vbabka@suse.cz>, Lorenzo Stoakes <lorenzo.stoakes@oracle.com>, Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, Conor Dooley <conor@kernel.org>, Rob Herring <robh@kernel.org>, Krzysztof Kozlowski <krzk+dt@kernel.org>, Arnd Bergmann <arnd@arndb.de>, Christian Brauner <brauner@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Oleg Nesterov <oleg@redhat.com>, Eric Biederman <ebiederm@xmission.com>, Kees Cook <kees@kernel.org>, Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org> Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, alistair.francis@wdc.com, richard.henderson@linaro.org, jim.shu@sifive.com, andybnac@gmail.com, kito.cheng@sifive.com, charlie@rivosinc.com, atishp@rivosinc.com, evan@rivosinc.com, cleger@rivosinc.com, alexghiti@rivosinc.com, samitolvanen@google.com, broonie@kernel.org, rick.p.edgecombe@intel.com, Deepak Gupta <debug@rivosinc.com> X-Mailer: b4 0.14.0 X-Stat-Signature: cp39s948qoohjia4hofkwgezqjcofwx8 X-Rspamd-Queue-Id: CAAD9C000C X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1727798825-546516 X-HE-Meta: U2FsdGVkX181AXi2zYTDJHn4+IZy9SJN7j80EumDfTBsgX+zhpJT5CeFUcOyMU/7SbjwsWBsfVWQ+7oNl7ccZ2v4M8uQX7TKj11yxfLdbg0y1jLMrSnlo57VQseHU9Q6WpBKzUN6ggvJx+D2meIVotJcsDBoMC1319XoNEM8rtplOUN/ATYvn6C/zHaSoPAjKqrc4Fmpij0QYIJS60YCNJLW0+fiw4qJE6cquxaEldeHbSZyzHCD0zaNMowlZMxCwPF9vxn/K7QaqwTEh0sh5rhbxSPN5I0N/6sctivtpe+/uKjb+owW8bx/LJLrTEMj3j8+u5F5p6rg0JAaxG/2a44BmoMAj7NwJORZ4/XVsG/yIgj/5toFBE39A5rwmCbwincnTlL4fQj/oUnL/wg+EBAif/k3GsFklUyPO5wSAIBMDp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ity: 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/mm/gup.c b/mm/gup.c index a82890b46a36..8e6e14179f6c 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1282,7 +1282,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/vma.h b/mm/vma.h index 819f994cf727..0f238dc37231 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -357,7 +357,7 @@ static inline struct vm_area_struct *vma_prev_limit(struct vma_iterator *vmi, } /* - * These three helpers classifies VMAs for virtual memory accounting. + * These four helpers classifies VMAs for virtual memory accounting. */ /* @@ -368,6 +368,11 @@ static inline bool is_exec_mapping(vm_flags_t flags) return (flags & (VM_EXEC | VM_WRITE | VM_STACK)) == VM_EXEC; } +static inline bool is_shadow_stack_vma(vm_flags_t vm_flags) +{ + return !!(vm_flags & VM_SHADOW_STACK); +} + /* * Stack area (including shadow stacks) * @@ -376,7 +381,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); } /* @@ -387,7 +392,6 @@ static inline bool is_data_mapping(vm_flags_t flags) return (flags & (VM_WRITE | VM_SHARED | VM_STACK)) == VM_WRITE; } - static inline void vma_iter_config(struct vma_iterator *vmi, unsigned long index, unsigned long last) {
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> --- mm/gup.c | 2 +- mm/vma.h | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-)