From patchwork Tue Oct 29 23:44:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13855717 Return-Path: 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 256B4D7494D for ; Tue, 29 Oct 2024 23:44:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A575B6B0088; Tue, 29 Oct 2024 19:44:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A08116B008C; Tue, 29 Oct 2024 19:44:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 880586B0093; Tue, 29 Oct 2024 19:44:21 -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 6BAA96B0088 for ; Tue, 29 Oct 2024 19:44:21 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1069F1A076F for ; Tue, 29 Oct 2024 23:44:21 +0000 (UTC) X-FDA: 82728270828.02.DC526A6 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf20.hostedemail.com (Postfix) with ESMTP id 0E68F1C0006 for ; Tue, 29 Oct 2024 23:43:47 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=uY5eYLK2; spf=pass (imf20.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730245378; a=rsa-sha256; cv=none; b=lcTVWjTsP8tUhzrIl1Bfzy7ZIKKRhv9SxRnQcUiK4ypa/Akbgva5i6MQ6EmdHVu0tm/R27 CAZDnyziKSnqcc3O4T4CNJYGYpIVY1qZaKm/FiCMha1vVXtPkDzlPfbLkMdkHL5pCbVO25 nCykcHkJPsl3AAF/2wYg6ClKoF7tjoQ= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=uY5eYLK2; spf=pass (imf20.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=1730245378; 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=A27TSZWEvDZAFIGCzgSTP5vgsRCljOGvihxqekfN1m4=; b=jk8ZpUH+JuKsWI5IXLl/gsc2hCXEjkqMVl06kBUgp1IoVsq33bxdYostKK/9TRB1GLV9nA V+ahANQ3eAJsddeHGapY+sDkEafxAFhIhmxfSJzFsJBu2LhsyEOI+Llr5jHilgkVqgKixy nwGwC+z/XgLIa5O4vrJxEfp0FMH0xlE= Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7ea16c7759cso3070101a12.1 for ; Tue, 29 Oct 2024 16:44:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1730245458; x=1730850258; 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=A27TSZWEvDZAFIGCzgSTP5vgsRCljOGvihxqekfN1m4=; b=uY5eYLK2+Rsqej2SoR/PTF08Cxi/HRGrT1ATiw32EmvygDSiFt6So0DIitNlQtGdFY 6DBBnZwAeXDixyH4MMhyMGmBfiLlmsgy+ym6bZvJEPiUdBDECPFKpGLpxTaEej0fYfDj PnEava71kNF89Q0bpl5lpzvCe4PsqGWVXxPKAWWi0XenGqjKHBtXz+ZiNi73s3MDwmkj /cidQK762Tr2Dju6pgI23ncN+bhfP0IJ3kObdCbDMUWtqISJA+AOTByjHcK4K1US3HLj Cf+OEDc9xr8r2YeA3/6gcVyZTdfww1jmZbzOC6qXlFJC1pNf8LYBQWVy/ZB8ZtMk8yrf O+7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730245458; x=1730850258; 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=A27TSZWEvDZAFIGCzgSTP5vgsRCljOGvihxqekfN1m4=; b=jYic7XQGnf4QnEKeefcxrWmAlGMHQxXkQf1XdFtlYE6FQvfti6669r0xxun0WXc/pk zybTbOiM/gjuLrlaOIT9YdzZ0C3vJFGoz7jK04WNnkQBPIhRIprcHrr1vQkY9jxvs/ww yDjIgmYR++gtNy5DRIZRnUUr9iMZHBcdiZC/RblcsA7PW0UOK5ohhcBIoIpeWdg2qblw sCVazZ8M+GsNkA9Wu652jIAPIngt/JRwSzof0XAG06r3qdio3JOQ5sR+wCorWnv7plgN pjh54Vm5T32klxArq3gYygvg/PQIhCpstAE1FUf/P19zAZ9OEqsKClUX1BcjFtb6FHXS zhDQ== X-Forwarded-Encrypted: i=1; AJvYcCWGjcU5Muu3luiN+uR8KQxHr5mbNfTqR8e3w2rrEQ9wrENTm0o/GqcqIuFdP66+RWysfnhGC8CjTg==@kvack.org X-Gm-Message-State: AOJu0Yw6WyS64QhHIicvaN05n9P6kqwd/NWBtYnXwvWs9cgVvzelklJa oPEGazWsEhdbHZTEUOK7z9Ccob7Nq7DGG1pRep4NLfP5wR173A4SOiZiHKzx6i8= X-Google-Smtp-Source: AGHT+IEl2QOb2QqMdMEvJJy28IFG3kLdP55DbuAo5+86qcvJIXvWMGt1Fwpgzfx+V0+HBr7ZrtesUw== X-Received: by 2002:a05:6a20:d521:b0:1d9:181f:e6d8 with SMTP id adf61e73a8af0-1d9a84dd394mr17393682637.31.1730245457862; Tue, 29 Oct 2024 16:44:17 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72057921863sm8157643b3a.33.2024.10.29.16.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 16:44:17 -0700 (PDT) From: Deepak Gupta Date: Tue, 29 Oct 2024 16:44:01 -0700 Subject: [PATCH v7 01/32] mm: Introduce ARCH_HAS_USER_SHADOW_STACK MIME-Version: 1.0 Message-Id: <20241029-v5_user_cfi_series-v7-1-2727ce9936cb@rivosinc.com> References: <20241029-v5_user_cfi_series-v7-0-2727ce9936cb@rivosinc.com> In-Reply-To: <20241029-v5_user_cfi_series-v7-0-2727ce9936cb@rivosinc.com> To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Arnd Bergmann , Christian Brauner , Peter Zijlstra , Oleg Nesterov , Eric Biederman , Kees Cook , Jonathan Corbet , Shuah Khan 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, David Hildenbrand , Deepak Gupta , Carlos Bilbao X-Mailer: b4 0.14.0 X-Stat-Signature: o9q94n4xr8c5jre7dg4sjsk4ub7ygpfq X-Rspamd-Queue-Id: 0E68F1C0006 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1730245427-384669 X-HE-Meta: U2FsdGVkX186mBiBU6lq8OE3ua3nfPlXlE3wati1oga9wWm0p2hXxxbOoJ9S/Ea6AXVqh/9OFWjCTwDrje7p1cIT3JTikJEu/HutbssScHGHGtZoJ8iYLPbrl+K1BnkOtAeQDK9dxMaXP2fj/ewGrjorAkVZDYmYwFsihYunaD0TCH32Y1g5RUA2lV0DTFs0lNfFDCJ+uTzi/Z4/XDXnligYG15d+rSuAOPin9Di9xkMbrfKA2SSuYzduT8X3cUfrMvm/N+UYD14OqrEuzx0bdLf447QRbAHdgPk1+MVGVbzmHV+yKXhzOlPe4kXvFbZ7++owCUCl13pXq1tyPZnsKy468JrKa2c34dpCF2WfrxDORXAlZEybFFQvLVQay5S+w2aJruyxn1ubpfmoXXHLKEwRGOEyJtf9NRJeJJ6dEmK13+IJAeeQNl1Qw0f6ariR6VAr/5z99PBR69cKVZDsb+8KafUUozbojx//KYi0XOj5PdSfHKH7z7/jafhRn/4Sciwr5N6mtyWGtytbMSMXm2GxfN9zT5VhoD9OahjIFh+b9bDDzTclnFCjOudIQnMmxVwZCJIx9A4u4xIiNKNft9yLQvkrHLAFsMlRYgRq99FPARHr7IuaoP/VVp0sRrnwoo1ciFTn0h9AWgQeYOQzW985QtlQxEgo3WzkqxLt7yDl/LaolvCKZBEBbLbJrJcw3VmxTFW3GabvnET/8BTi8UmgCA1phrm66LUJhvNGgY7zeaQ168m6ZPB34WBUn1yVENBrRq/yHZsRmYTZdZAroXtSpYg+lMvsId2nJQbxHaAMfLwoQUBPnI5vczgl56vjlrsC4j/KBSkc7ypdzi0kjOW0QhhlFQdBY9Dh44GXZj00fNPN766rvnr4yxa/971bP5OF0bm0yKChOknuXZSd9yRi0k+9H7PAaTTCf3p402+u2ygpZxklQpRj2omnExB6JeAsmIlbpv7rb23Ab+ SjSfHsi2 ccaaliKP5Oo30e59BfvBl7aTX7O1RcUnmaULXWhxuqqF2qkAjEw5FUaJjiJUEIa5GZ/a2rlRzSG8DqoILBOxVhjetYaOaeYv+wVUjiJst/yn0xjU1mlyZwUM3siu3F9IvAcyhRqs/n5yiqIbu6FDjWPvNUiHCYpCcJbZEIPTEAZZ7IUgqIZmjzl3DBMp4GLq0WkBfczSeoTKhNqxULtxY1VDIjfMJRCoIRlouJCke50QmRij07IXbKGqNibiRr9wfhmdyyk+wFXzPsVMovfauv94HGZwcW9J/AQ5mKLim+3qu+SWPI2Wa+U8qnm9SSUwEUfTXv0POtEOV2Vmj3MsaM1mNJ4QU6BBFNIWWr7l/IUmcsDIuZ90g+qLTXftmrxVCiMl3aorwnwVWeerT9JdoVzS/GVsnIxMQ8NCcLR3xAN0jRL1GSbMyk886Egvfz2D2/TPiZfC++9+VJVBOf+n18c8u4y5TJSTfewneBT5jXlc0NbRUBMTaMAi1sYRcQtF2YwLanKLPYtLxvUMbbX1kPtTw/VyM1569QhfJ2uR+O6IxJzARXU1eP+0nA9JVm3cuzlkTPAARYEamGgPyoB3qKkteuqXW7hZoM1T0 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: List-Subscribe: List-Unsubscribe: From: Mark Brown Since multiple architectures have support for shadow stacks and we need to select support for this feature in several places in the generic code provide a generic config option that the architectures can select. Suggested-by: David Hildenbrand Acked-by: David Hildenbrand Signed-off-by: Mark Brown Reviewed-by: Rick Edgecombe Reviewed-by: Deepak Gupta Reviewed-by: Carlos Bilbao --- arch/x86/Kconfig | 1 + fs/proc/task_mmu.c | 2 +- include/linux/mm.h | 2 +- mm/Kconfig | 6 ++++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 2852fcd82cbd..8ccae77d40f7 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1954,6 +1954,7 @@ config X86_USER_SHADOW_STACK depends on AS_WRUSS depends on X86_64 select ARCH_USES_HIGH_VMA_FLAGS + select ARCH_HAS_USER_SHADOW_STACK select X86_CET help Shadow stack protection is a hardware feature that detects function diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 72f14fd59c2d..23f875e78eae 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -971,7 +971,7 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) #ifdef CONFIG_HAVE_ARCH_USERFAULTFD_MINOR [ilog2(VM_UFFD_MINOR)] = "ui", #endif /* CONFIG_HAVE_ARCH_USERFAULTFD_MINOR */ -#ifdef CONFIG_X86_USER_SHADOW_STACK +#ifdef CONFIG_ARCH_HAS_USER_SHADOW_STACK [ilog2(VM_SHADOW_STACK)] = "ss", #endif #if defined(CONFIG_64BIT) || defined(CONFIG_PPC32) diff --git a/include/linux/mm.h b/include/linux/mm.h index ecf63d2b0582..57533b9cae95 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -354,7 +354,7 @@ extern unsigned int kobjsize(const void *objp); #endif #endif /* CONFIG_ARCH_HAS_PKEYS */ -#ifdef CONFIG_X86_USER_SHADOW_STACK +#ifdef CONFIG_ARCH_HAS_USER_SHADOW_STACK /* * VM_SHADOW_STACK should not be set with VM_SHARED because of lack of * support core mm. diff --git a/mm/Kconfig b/mm/Kconfig index 4c9f5ea13271..4b2a1ef9a161 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1296,6 +1296,12 @@ config NUMA_EMU into virtual nodes when booted with "numa=fake=N", where N is the number of nodes. This is only useful for debugging. +config ARCH_HAS_USER_SHADOW_STACK + bool + help + The architecture has hardware support for userspace shadow call + stacks (eg, x86 CET, arm64 GCS or RISC-V Zicfiss). + source "mm/damon/Kconfig" endmenu