From patchwork Tue Oct 1 16:06:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13818404 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 2A5CBCEACDF for ; Tue, 1 Oct 2024 16:07:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B201128009C; Tue, 1 Oct 2024 12:07:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD029280068; Tue, 1 Oct 2024 12:07:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FBE928009C; Tue, 1 Oct 2024 12:07:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5B9DB280068 for ; Tue, 1 Oct 2024 12:07:05 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AC25016101F for ; Tue, 1 Oct 2024 16:07:04 +0000 (UTC) X-FDA: 82625512368.28.9D13B21 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf27.hostedemail.com (Postfix) with ESMTP id A7AEA4000F for ; Tue, 1 Oct 2024 16:07:02 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=sABOIchT; dmarc=none; spf=pass (imf27.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727798729; a=rsa-sha256; cv=none; b=vxr2xGfObSxTb3VZc/DXh4ziu8cPE/tccoWQ7aAtyoVhOMaDqtiG7uwo6aPAHghanJ+6I7 U5kr9j8DQOrGjEvwk/RRxLbBRBrJ02szUJjHu8wx1dGgBGjLdTe4rXp19QylPU67IuGtbm fb1uK5UPLDNIfDhu7Hw5kLB49/wXc/8= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=sABOIchT; dmarc=none; spf=pass (imf27.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727798729; 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=pcb1JUl7nxyzCR2L+K51gN2ROJJ8XrFInAPZeivTlr8=; b=fKqa1FmU3reBiIQlHFbk30/QTszdBEbGvysWF3nSR2wXuKszw4XJBjiWXSH0HmhURZ/1CO SIq7ufXF5suYG6VD2tPtLL+TTGNL5kV/hOLbC4ixfrWkFeHRYtzTC4uMCbKPdY17bwd9L+ KvljI+G3ez25V9zNl3FLdcsuUGvDxVA= Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-20b86298710so22447765ad.1 for ; Tue, 01 Oct 2024 09:07:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1727798821; x=1728403621; 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=pcb1JUl7nxyzCR2L+K51gN2ROJJ8XrFInAPZeivTlr8=; b=sABOIchTNUxP3IOG5mPARWZxIIiNb4Po70BfDgxI7w+WxE09VNC/6JyMlUhZ1jKgkS W+cHFVka6FEJF53cFrriHQbbPvwjCsXPQhsQJ5a7Pw6ToWkPzmLXcHZBU1i60oG4gAAS wnVyImkfekkyXP5DRb3OwzQAuiWBU8TGaKR5MPROhCDPhreRAOI15PcEG8QBWvY/i4bq gLV6XJs0jaf1Pua90NRbfRKkWmGv6Xo6odM7ODrvcaM9rznKBC01S6YS50QCFHu+zy4r +WctILWiuvBQUgub8/TFfaEIa81odcQeILOIvXNtsQdx48dcITK9mDQTFM905OTtkk/b NZ2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727798821; x=1728403621; 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=pcb1JUl7nxyzCR2L+K51gN2ROJJ8XrFInAPZeivTlr8=; b=gPYZHUG4UqOLLfVnQS1tWrrB0cohpdlMgtOHcnBNiF6IlCd6YuBm5odPJjy/KjaYRE RV1TgHGzYU8dW4zya5oYQOMN+bjyEOFCNUKV0BM5X8glYE4LK44N1hebzd1s7Yv/XpiA gGy3FI6XzusVJhzgPWCYoAOMZQNHPmcASWUSmy8+k+XbAX0NiVBGKfbY7lXx0jdqBwk+ PaU4OPY29S06fz+KTM0iGZgiSIdC/qXW1VeYvPpggnf83usE081xgMsAZcM53QHvK1Ic X4CFpx7+3YVRdPQr9boP5BRg3nUILKI0T7PBGern0i4LLgIM9rqqy6qhNtUAANBVpHDK RX8w== X-Forwarded-Encrypted: i=1; AJvYcCUl30mhN0I5/VDOqkGdHxzyVbLLU2ScN3qHrjZdY7p2H3NTU+a5kb4RpFyBu3/bdYqW1LHZjjjRmw==@kvack.org X-Gm-Message-State: AOJu0YyWejBHLWgP45sRHd0OzjZ00J5fcI3CHil4e9nbBdDePfe5TmpD 5lGjIg6tYKr2nKg3CeOPIvTjk9J3Fwe06dJ0ArOF7zwnbPOp78CR9oj9mI83q5w= X-Google-Smtp-Source: AGHT+IG/9AhOFkVlsb1ZH2XMKlQ6f717lLd7IRjhRM+ZTMobdV3S8kdqvcOsBq5NGgSC9+zelAG6Ow== X-Received: by 2002:a17:90a:650c:b0:2cc:ff56:5be1 with SMTP id 98e67ed59e1d1-2e184526f71mr233618a91.7.1727798821325; Tue, 01 Oct 2024 09:07:01 -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.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 09:07:00 -0700 (PDT) From: Deepak Gupta Date: Tue, 01 Oct 2024 09:06:06 -0700 Subject: [PATCH 01/33] mm: Introduce ARCH_HAS_USER_SHADOW_STACK MIME-Version: 1.0 Message-Id: <20241001-v5_user_cfi_series-v1-1-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 , 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, Deepak Gupta , David Hildenbrand , Carlos Bilbao X-Mailer: b4 0.14.0 X-Rspamd-Queue-Id: A7AEA4000F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 1w58mxap5pg1shii67h7o46jasfd9zrh X-HE-Tag: 1727798822-941862 X-HE-Meta: U2FsdGVkX18OyJv+3YJ9sg8e2hmKQoWYgadtUzmvdbYIdN+9vi0jHDunJb1kBtiodTxWoI5yiczR9++KZ5TBff/Dtyv4UOxhjTMlLvh3l45+fiBatDGQlRx/cXsvyPai2z7twXVnNwAI7Een9K/09BUoA0C7hGSZPTI3KtuAY+nLKAL7bZQXeflA2M9tOAig2WzKt7SXz4YJaXNJysWq+/En0lryygUhS+QH/jbuII3LJe0Qvsm32PjVhdQonek2Wrq99Y8T+RuW0jnF2hjmpmCpRZ3JqtJo3+cwIadAlEvHY/QKj9pJZrJk5vN9CX7P2yFhmQ2GKLeGX3IG/K55c2AmQoMMqdFIz4RlMEsnnXoJSKxAHQzqzF6y6pqj1EcgDESH/0209koaXdoAAQf7JYElYgLxags406LxGSadXub/XUPnxojpBGoO3gWp4KOTS8L0AoPGC3xHmQnDNyc4EWODoD+61n+tctAOrX3Gz+hZncs2HjyvYKYM/2/qe9U7J30BtUugDlRkvVcYTnjmVdkDRjlg91BH3eGaE98lGKCPO9e5pRio6PfF1pLeRwLWd956QDal1DdWUgvEX+JuVOCac5WLKXgXVDmUMBKcSwF6WiZKZwKuoibMDAzyHYutX9bOHmoj3EY722M4HOdMOs2GdMXV0mH+2ZUWbbh8tGaX28JYWrL+kfsQgl7bBYffSIhQ9v6RfO2WqYoBnus1/CkztKDOtu2+HQnAgrA8aEUDaYYLeg9MCwJqQI3bEWpb/2i9aDueYfpG3cP8n62pYTo6wO/FP5wOJKLIEg9/omUtSrp7/GrcBqoiRgUgeJrJSKTH3J/vJyFFSrIIpGOOX+r+QLXMQ7CacWqj61vj1nkCiefiXALBVMrjrU6Yxf10sUcSh3Mf9CJjjTTZb+eCP+zdNcZyhXghfixdclRVsY9E40iG6YhlKR1DJxq93Nbn2lLaOqgCtukNy3YyRDh +3Kdg/DC ZcNNjqbMbXGRcSvRmsAguKGC+RUs96U1q1Jgq/F/WYjVTQdWXatt7qd7H+oyds6eH0uCN35Qi7oB9ZlbwbPHkBix4ijGBHBAQ9qm6kxA/hW5PBWHRSa7lOqeit4FhoJGMptVa8jBpzA61nmRVDa7nNn7xOz05V8nHnpJwFSkVvILK7JrPiI4MBPA2uR0jZv8AfHdgNIZ6x5yqLEXM+HGs2D10/39Gnmde72W+xN+BQhHbVNCjj2x5ujMVIxktWrF1R4zcgHkw28Cyi33MmMMCEteX5aVg1DJtHYDhXvEzYGdSlmedWiQqsU0/Ef+IS+y5EUhx0WrraLZWad4MFUJqPq29MJ3AtUznrvWtXV/TwkBXPXBDCBaC2O2sa/RLPWDcDPgqNU/izSft7UITZRyZ8PKwArIaCn2REutWZHwe9xO4KpJQ8POwNAaoE0TBM5smA0Qz9AKjpihJHfjMmuZ0mffDsALUhsGH6wLWNszDc60jN2DSFoCjEDmsZoblnl+FcssU72HuabqtO9KgWfVAwn4xtq5uqecF73kB/IPXgRo+Z9D4BjjZI09TDi5LsJtqK8E8pyibGTSE8s+WpDl9PoSarTPI4PJnMaMl 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