From patchwork Fri Oct 11 00:32:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13831614 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 0E843D2444F for ; Fri, 11 Oct 2024 00:32:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3FE0E6B007B; Thu, 10 Oct 2024 20:32:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AE076B0082; Thu, 10 Oct 2024 20:32:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29C8F6B0083; Thu, 10 Oct 2024 20:32:24 -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 0AADC6B007B for ; Thu, 10 Oct 2024 20:32:24 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2631E120583 for ; Fri, 11 Oct 2024 00:32:20 +0000 (UTC) X-FDA: 82659444924.07.F38B9ED Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf13.hostedemail.com (Postfix) with ESMTP id 94D4520010 for ; Fri, 11 Oct 2024 00:32:19 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="QQp/PEjZ"; dmarc=none; spf=pass (imf13.hostedemail.com: domain of debug@rivosinc.com designates 209.85.210.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=1728606590; 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: references:dkim-signature; bh=L88k/6LQJ6n1DZsE/un1+ux0jKynkO+0CSLGH0Z2NJk=; b=PASv2J7ydsLf8so2SQR8huyd0zmJYib12/fldeILJzP0y7XynJcwhFjF8mhb8fa2HjWJ15 yXhfx9k+Ch9ovSg8hDE4j/hAC72+xI5SjKmbnHFKpM1bBYDE2amFkteT30uQtTzc+FBGJT jTs9pRjZ9zy7JoXlVnoNLyZnuYwbP0g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728606590; a=rsa-sha256; cv=none; b=vtW6OTqEAREpye2sUI/rRm6wGnLNqyL/hfMo3/kpRLD/whV0Gaav1367SDVY+aox1Ss69S KXK5D0SJTHWtQit0pCiUv1ga0fptijPLAfdMKaQvxNPQEfa0atsHNBo8BjmzBczKL26DPS EmKJhr6pZrSPhLgYsb7pHFipLkbEePw= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="QQp/PEjZ"; dmarc=none; spf=pass (imf13.hostedemail.com: domain of debug@rivosinc.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=debug@rivosinc.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-71de9e1f374so1150748b3a.1 for ; Thu, 10 Oct 2024 17:32:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1728606740; x=1729211540; darn=kvack.org; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:from:to:cc:subject:date:message-id:reply-to; bh=L88k/6LQJ6n1DZsE/un1+ux0jKynkO+0CSLGH0Z2NJk=; b=QQp/PEjZ4aGEBHBBjMbYpaMV/uai5Ghryijj3MnGj0wrUemUdr+ujJpKo0vw8yfov6 a/Cdkifyr1HKjKCSiQT91DbSkcBwwrNDTPBT33q1LAmvHxN5iiZqjy1BmHovcPGtqWE/ HMy+8+cywW02Yn0DzZG2QaJlIVA38Bi/4KXzg5UCcQFm2kzTpAIFzH8d6drzPVaOEJjd WQqatDaacYbvSmXp9x+s1IOzGmt8sDEo080setm4oSyZj4JEyDupMnSCzznrNz/VKvu2 UtuwWQmgQbrKmVtgxyNcDy+Q94EiQX/zpIGMIAhFfBTD2/Tybq5RlVWo9BOco9faCPEq Z8BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728606740; x=1729211540; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=L88k/6LQJ6n1DZsE/un1+ux0jKynkO+0CSLGH0Z2NJk=; b=mXacsgnD3KyAt5SqIZOqDfVtUTLgT9o0HUAHwWHhRbiLRDJp9lOo47G18PhbVPepUR okcjyFT+yKSZltUt/6evPl9IF0Am+yAUAJaoDA8MHs+cU625pRmq/mLkDuL9g4QpiRKK KuS1lYeB1qc5EyZOAIfFi58Ah3PbzSs9HubDzho+zWOibTv186ppjYghrieMbwBwuYWI ghvm/grj39aLA/lgK7mXZfpDGxEaZQ1FMm2QtspVy+Ek+gBPBTKTyesGUI28HjWrj6ti vfekYAlTBkijjqohWwHG2E46sub0dVS7aRpM9S5S+/W4lcij9rglILBe0EPBziNCesf4 n+BQ== X-Forwarded-Encrypted: i=1; AJvYcCXgcVl192LqlQorwKzo0Cdtb5Sr8Zilcp1i9QqiZ+emRKzoiJWzmu+lRU86hHmA6KorPDs9D05SVg==@kvack.org X-Gm-Message-State: AOJu0Yzp50ucTRQCO0RT/G7TzhHQVNu+P+kJuCzyZu+4OL9XBpoCnOrf qJGPdcxCy7vDYauyQ+xeRn92FGUXpJ35HckPf4f9RwciynnjEZ+O2v8Sd9TFP2I= X-Google-Smtp-Source: AGHT+IGyS+aA9UxCtkzeUWYlobH1ifyQtJfGEXOmfg62rhTEkQa/syWVFaq3tPCmx1Ml8NjwqupEEw== X-Received: by 2002:a05:6a00:4f95:b0:71e:21:d2da with SMTP id d2e1a72fcca58-71e38083ec2mr1436401b3a.27.1728606740101; Thu, 10 Oct 2024 17:32:20 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7ea4496b1afsm1545600a12.94.2024.10.10.17.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 17:32:19 -0700 (PDT) From: Deepak Gupta Subject: [PATCH RFC/RFT 0/3] Converge common flows for cpu assisted shadow stack Date: Thu, 10 Oct 2024 17:32:02 -0700 Message-Id: <20241010-shstk_converge-v1-0-631beca676e7@rivosinc.com> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAAJyCGcC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxNDA0MD3eKM4pLs+OT8vLLUIqBsYmpaUnJSapppirmhElBTQVFqWmYF2MB opSA3Z/0gtxCl2NpaAE6oGlppAAAA To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, Rick Edgecombe , Mark Brown , Deepak Gupta , David Hildenbrand , Carlos Bilbao X-Mailer: b4 0.14.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 94D4520010 X-Stat-Signature: rpj7dd484fy16fsnw4o8ynpi17x5a64x X-Rspam-User: X-HE-Tag: 1728606739-554359 X-HE-Meta: U2FsdGVkX197OezPgKYFejECArDKLLPrMshfsLLmoB3qp+DQr8a2P2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TjZDVgwc7mB3pQSW/RIPto9Te1ISvb2WDpFvNaHYISb9Ujw0uL/JqkyxT9XOxDeRz5+2BT9z0A0e+yyfMbM5yahuvHNyWvzEMi6CC/38IgBV8cahTHTwHQS+4CLOt9ZdJS8adlUbPVBFjtTHmT5fWEcU0HI6v5M14nDSsJyRVgfOZMcLgyO4gUEMlLHyVRMbUmdMZTpE3l9wsKO744IE1RlMHEJePq4dpPsIunMls8tNaqh+pGBGgXgEVu6B8oN1tmzwYEuP2jtUcWXMPu6Z+Sz1n90SOgw8piikbcYWO/GbiM6hk4kMMuXL2A/cwPkkr3RlO6P/C84RnCWCYberRwWOhkGjnQKFlaVZ8qRa0wq60IX6CFp1zKrXGQ6fTe0sWrA3bGv5k3xZT1LL/Y/ubbT1kRJENhQMGfHIT8OqJH6CaeM9Oi1qrZD4xNhKooVUOW3u6fzcGrMnYOytzHrpD75e0Ra/JQ9EwPcfN5w77rfjG/PuFE4f6o0xfqDVujVjrmwqPy8rS9yvXPvP6iO2dQSS5m5ZALbGs37eOtAxT47cnK6cl5C19heyQ9szL+r5igG9EjA1Kc3iXlyTRAM5gszM+rbAVQEhz4 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: x86, arm64 and risc-v support cpu assisted shadow stack. x86 was first one and most of the shadow stack related code is in x86 arch directory. arm64 guarded control stack (GCS) patches from Mark Brown are in -next. There are significant flows which are quite common between all 3 arches: - Enabling is via prctl. - Managing virtual memory for shadow stack handled similarly. - Virtual memory management of shadow stack on clone/fork is similar. This led to obvious discussion many how to merge certain common flows in generic code. Recent one being [1]. Goes without saying having generic code helps with bug management as well (not having to fix same bug for 3 different arches). In that attempt, Mark brown introduced `ARCH_HAS_SHADOW_STACK` as part of arm64 gcs series [2]. This patchset uses same config to move as much as possible common code in generic kernel. Additionaly this patchset introduces wrapper abstractions where arch specific handling is required. I looked at only x86 and risc-v while carving out common code and defining these abstractions. Mark, please take a look at this and point out if arm64 would require something additional (or removal). I've not tested this. Only compiled for x86 with shadow stack enable. Thus this is a RFC and possible looking for some help to test as well on x86. [1] - https://lore.kernel.org/all/20241008-v5_user_cfi_series-v6-0-60d9fe073f37@rivosinc.com/T/#m98d14237663150778a3f8df59a76a3fe6318624a [2] - https://lore.kernel.org/linux-arm-kernel/20241001-arm64-gcs-v13-0-222b78d87eee@kernel.org/T/#m1ff65a49873b0e770e71de7af178f581c72be7ad To: Thomas Gleixner To: Ingo Molnar To: Borislav Petkov To: Dave Hansen To: x86@kernel.org To: H. Peter Anvin To: Andrew Morton To: Liam R. Howlett To: Vlastimil Babka To: Lorenzo Stoakes To: Arnd Bergmann Cc: linux-kernel@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org Cc: linux-arch@vger.kernel.org Cc: Rick Edgecombe Cc: Mark Brown Signed-off-by: Deepak Gupta --- Deepak Gupta (2): mm: helper `is_shadow_stack_vma` to check shadow stack vma kernel: converge common shadow stack flow agnostic to arch Mark Brown (1): mm: Introduce ARCH_HAS_USER_SHADOW_STACK arch/x86/Kconfig | 1 + arch/x86/include/asm/shstk.h | 9 + arch/x86/include/uapi/asm/mman.h | 3 - arch/x86/kernel/shstk.c | 270 ++++++------------------------ fs/proc/task_mmu.c | 2 +- include/linux/mm.h | 2 +- include/linux/usershstk.h | 25 +++ include/uapi/asm-generic/mman-common.h | 3 + kernel/Makefile | 2 + kernel/usershstk.c | 289 +++++++++++++++++++++++++++++++++ mm/Kconfig | 6 + mm/gup.c | 2 +- mm/vma.h | 10 +- 13 files changed, 392 insertions(+), 232 deletions(-) --- base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc change-id: 20241010-shstk_converge-aefbcbef5d71 -- - debug