From patchwork Mon Nov 11 20:53:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13871338 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 40136D3ABF5 for ; Mon, 11 Nov 2024 20:54:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA7056B00BB; Mon, 11 Nov 2024 15:54:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A56916B00BC; Mon, 11 Nov 2024 15:54:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8823A6B00BD; Mon, 11 Nov 2024 15:54:00 -0500 (EST) 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 612706B00BB for ; Mon, 11 Nov 2024 15:54:00 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 015F5A1B02 for ; Mon, 11 Nov 2024 20:53:59 +0000 (UTC) X-FDA: 82775015442.04.AC272CB Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf20.hostedemail.com (Postfix) with ESMTP id 1C6EA1C0011 for ; Mon, 11 Nov 2024 20:53:06 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=103CRVDf; spf=pass (imf20.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.181 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=1731358296; 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=Ziaktb89WDbwUZ535GFbmTELWOQHyNOPVHZfKRHAH5o=; b=OxO0ZxXEJrXwayrVV021LYGJioogq8orAkuAlkmtjGEQG6UBWpfjGs63Bs6eb1ErKCPWXR WRaHDiZQpV2mozCwgPqkdr2sQkGrKDgPM9zcq3mfMnQpXcBswR67XE5BjiDqKZxVmIR6Jl TYR664hQFe6Y5gzvXJ4HCgWfdaYlGFg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731358296; a=rsa-sha256; cv=none; b=c+G8gtePMJIX61A0vedBObq4QvUwAlx01cyNwQMpeH0vp/yHX/8wiF8ybsdaE0syzmQvm0 GH/YYt4jB4GaWuTqHQO64X7C3RA2tbwExhUzITRjlsm8zKpNqNfobIHhTfUs/enzc2TNGt h59xwJBWDlkH+bnCgb8lnsCg1jKDOxA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=103CRVDf; spf=pass (imf20.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2114214c63eso40990195ad.3 for ; Mon, 11 Nov 2024 12:53:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1731358437; x=1731963237; 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=Ziaktb89WDbwUZ535GFbmTELWOQHyNOPVHZfKRHAH5o=; b=103CRVDfjsNiUoldoOMOW88ufdELTs0JjbfFgy46HwEo20om4r/9FpHFIBJLtuRshd S+tHrO/3+3Cb7YSoVPJL2B1pGWjHPhRMUy6XV4TC3ax80xS5dEtM/5b+FU6iVHR4xmYa UTv4QfTXThW8g0DPKh9P6pGGiG+DmCdWM9gCbNlvz8e0oBHwY0aYJXJh675SUoUH/ZuM 1IMSIskN2JKC3SUCGVSrevCPJmto8gHnkXw6lqSbfdRkk2FbR2AvUtwHBuokUqToxjkh C7fWmKlEipojJG+ELdp1DfDiKkbQ1AVu4xN3x2nHvNWi2lm+w53f/7bFpiM94VmD9i3N MdTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731358437; x=1731963237; 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=Ziaktb89WDbwUZ535GFbmTELWOQHyNOPVHZfKRHAH5o=; b=dVmjUfDGuwS8vVzHRC8oTG/FAqs6paLY4NKWGY21vtaoKNfLcxSd732Pofmtjd9ISE O3ZY7UFUfoAMHUZT/HS/E2JsQ1lZQ13qM5oozRba2xKdrvhIbNhKXTxfEx6CXNEySF6h qxcCnNj5GS1VQ9vzNaZhPNRJncBPuT2vUMIhYTEsPBk+v44WjBLepWGfVg12PB+JYHm3 DvdSf2hjHg4xy/hUKaEulhh5yqAbuMgqv2G2TU9CT95mJhrBevoOw7YtqDJF0r8DW5RR XCVRYlO3V+XBqZaccLhDovTHnHeh73eKZGgZSHw+h5o+XSub2Chehuc76r2AmxzTfDRz yt/A== X-Forwarded-Encrypted: i=1; AJvYcCUZVbLeAOjcYhiuUueNH5UfozR9/xw8Gjs6l5uzXqI4OwgleeKODIxUoEkFQiEchHuf+X7biURd2A==@kvack.org X-Gm-Message-State: AOJu0YyERM5jf1hJf1Gyx6/lXzbDvhnu+bRG+01poMjcStFbPeyskcsg iF95kS8qcq7ruEQaE8Zvi7rLFpTU/nELpQGxG6NGLBwbUTZbleiFUqsXAvPRScQ= X-Google-Smtp-Source: AGHT+IEyGabgVA75UQcsueBpJ7RpOtRzKc95ETC4lvjZRAohKnXlL6Ozkv/pWiQeL+cJUAE6GKxHGg== X-Received: by 2002:a17:902:db0b:b0:20b:5b16:b16b with SMTP id d9443c01a7336-2118359cb22mr204360415ad.36.1731358436616; Mon, 11 Nov 2024 12:53:56 -0800 (PST) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e9a5fd1534sm9059974a91.42.2024.11.11.12.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:53:56 -0800 (PST) From: Deepak Gupta Date: Mon, 11 Nov 2024 12:53:46 -0800 Subject: [PATCH v8 01/29] mm: Introduce ARCH_HAS_USER_SHADOW_STACK MIME-Version: 1.0 Message-Id: <20241111-v5_user_cfi_series-v8-1-dce14aa30207@rivosinc.com> References: <20241111-v5_user_cfi_series-v8-0-dce14aa30207@rivosinc.com> In-Reply-To: <20241111-v5_user_cfi_series-v8-0-dce14aa30207@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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1C6EA1C0011 X-Stat-Signature: qd9y83c9eix5oom7m9azh84p7e5dbzpi X-HE-Tag: 1731358386-546463 X-HE-Meta: U2FsdGVkX1+OJCipooLt6T0MycTVMtjjwzBaOj3jmN62qWTU/zQkIqAGy9G4XOzP8WUu2wa2uyTQr55XVWwur1Z5DEpjQSNDLCa74hPukhVJTCxymRJiiWeH+pOjsBxMep60DXX3gPT//ysjYQjaZDiGQzt7y4heoViTHD5UNJeLEH/OEKIWJOQooZnn8xLKim1Z8P1Le/kfDsPCfRLNdxqxnbp1cO4e/+mzo/O4IOwNH84i/0vHer1Z4R31k1EOvM7iCb8ppNW6w8fvLpNQ/8whKlY3XUu72cv4DNTLKqrFYOCobErtXXlbM4rQKuHAoItzPFyqIBMfSfcUxh3kLEMHphPYg9NSiFkFD3AgL+ySZjIJ7OIt/mQXwF46Qm3HE69t+07BtMZSkaq5KMFTu3C3iBjNyKXxqqRe+Atz6ZBKQYY+JolwiW0FJ3WJw/fZP44xEcmEDPcLdtpeDk7lnnERXTxXLG1f6jZN7jqGf9TJhYZZnGt+QMXD+oETP+JktxBmNLanvVz+Vfkqp9HieWI2WTrtv8VvxiD+bvi6l1Uhs58qqaxkDVY8DH5+OoB+00CSUxOQmGwJ5PJVA3ytmi5MMQwlJm1S3HuhOL7w+YcjPu78SIZ8XcLWYTxmzbIZ1aISJqkJJC6J+altp24oDN6RTyZT2rJfVbZuRawoqbI/IfIiESQVJ5p70ey/+V8hm+cCKM2m3qDZBOpZQ7MD2rVXibR5gfZvRk77Kfjf+edmIUJtVXcSqaBFjDELgoNafftyh9F7H3IkV14uTLD2wgxzlMnleiTcOHtM5tGdlz30uDRbpvcojFKdrhf1Y6u96DLubQ7A1SffLlJqkxe2yJ+XdvDib0bTGB4GKyJFmkHXj/CxkjnWkf6MtVayexJZ+yLC1YfzuYVdmddozLA7YtF0qZRztr5NMby+XVRN7j7FrBf7Ii0moG8r3aNDvv8LtLlPJ5ok+vsnBeEhR14 fLOIX8jm EHXGYfN9vwrltYrNamAfqQn1BmO4fRufwrFCGjy13ymziKMCSKoUUQ+vttd40fcSG0Ww3sOyymlTORUnlLFCTxcnKsmIt3PKyhbBUj8KjZiO2WIniiQ/bpcCEiP/WBlzgdxj9aHl2XD52wsshHrKndBXkF4uDos7iAwao3o/EcsumkE9sfXC0zxlPNCd7Cc58cqcn1VA+OBSg7nGNZDGn8LRrFuzWvUezxo6p1VQrBj5THYPVUwI1K6HnH7GgxryAM4syfk2hdntPTOohjieaoHhHYDSm9/gv4BWBNVHqVrXSEAJdQEwoTQEQDMyEwfydkjo6b0kWjOreHl16g6X5JgGr0jqJ2S83hpvD0ZlQ/K9VZQ55FInsKtIQVUaBOvJP5Pptikrz6342Z5H7r9tRF3vt/OTYyrH/TmSvKVLbinOf17ojZYt+HIBE6RBBvkgc1PzhoPtrNmga2t8iRreNfqKEVMbtjZpWqSRnvmSp0WTIYHR8wswC1utl5HlY8X8tcG/h2Jah/YC/QcBsnk6K9PLPGe/xiG+vZ6jb/RJb1ggVHb/lnMvGyUTXcVM4cntreNiQNzvnZdmN1uXpPOZBRcgelBNx+NTeNMdU 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 16354dfa6d96..fe6e9ece64b9 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 e52bd96137a6..f57ea9b308bb 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -978,7 +978,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 61fff5d34ed5..2291c02c74d2 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