From mboxrd@z Thu Jan 1 00:00:00 1970 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 368ECC369C2 for ; Fri, 25 Apr 2025 16:39:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 666F26B000C; Fri, 25 Apr 2025 12:39:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5EF466B000D; Fri, 25 Apr 2025 12:39:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 441526B000E; Fri, 25 Apr 2025 12:39:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 241236B000C for ; Fri, 25 Apr 2025 12:39:25 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 23EF5C77B2 for ; Fri, 25 Apr 2025 16:39:25 +0000 (UTC) X-FDA: 83373126690.19.BA4871B Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf12.hostedemail.com (Postfix) with ESMTP id 1E1E440002 for ; Fri, 25 Apr 2025 16:39:22 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Q7biBekg; dmarc=none; spf=pass (imf12.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.175 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=1745599163; 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=uObhd6griCLVRMAdAUyHQB5JJqltVnuTe7FYQAThLL4=; b=6M3Agyx6DzuUgvOo6+exUsj6uR21Qv3FFo0W03lMGzPxN0Y7Y6Ga0yfPRHlQyuHyHSAB2K 82BEaI/0KYkrCjA1yJbQiK0Dr3bX8cMWHR18+vKXLGzh1q6rgODS/bjqrCeg43B06wIIK3 n8CHMYXYDexshRZalbj5VOLbVMQ0MXU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Q7biBekg; dmarc=none; spf=pass (imf12.hostedemail.com: domain of debug@rivosinc.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745599163; a=rsa-sha256; cv=none; b=paY6dOpqApMgPYPvBzttVv9+PlG0dvgDQ/OA8GVihhMRMBdiZzyFhrg5WiZqBA9kc6lMSO YWnBhVJmxLmlDRgIs0dtAIKzW+kCK07v4NHSMPykJQjf/LKSU+YKeOOQklU+S5BSkdksB6 JcNWwCqP6H/SJxDx5Es1XBhKdpO3enA= Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-22c33e4fdb8so27810865ad.2 for ; Fri, 25 Apr 2025 09:39:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1745599162; x=1746203962; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=uObhd6griCLVRMAdAUyHQB5JJqltVnuTe7FYQAThLL4=; b=Q7biBekgmpkfM9DNnrkfpz4nhxEQOR5U7p5l+Vp2ehGW0W3zwqyeSm1+4QmPQlKU1t VDdBInXnE62Frgl7XrZ4jXXo1EdnUaJmy8tNCk4A3dK/DM+EAB3KyeFvJi5GKkY3qPNI zjWrOa4FCtNmGCBEGlBUmP+yvoBNtq+GxD/q4JMGL+cyJHO3iEePecNHP3XA5AL3CdkM LaddjTAscyrsPHyYkpUTiC2CA6+j9XG94uxyEIKrXtK6UHXz82Hn2gBrO7xHE0HkBsGP JIC4iHOK32bKU4sETu94xWLzNPBSupnyA7+HDXqzL7hLclTbHq4+BdXnyS3AI+52VE4H tFFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745599162; x=1746203962; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uObhd6griCLVRMAdAUyHQB5JJqltVnuTe7FYQAThLL4=; b=I1zzm/ajsJhqIj9R+t3ZNDOXKmO1Mg3HztDDX4zdM1mmvO3A2UbVbIlI8duMefQiSk QdRfTVHHQzpNONUQhSeJ4jatVYeAUabmNvNzyTZqXwZ2qdlmHT4dXoHzASAej9ToCwuD 95EjvOVASUBmSSrSxiAr6rcAldF2Sj1k3QWNBC5II+gzarvtWyRpprKxwMWKKSM6cO4F IDYjJnJklxLcZiIKD4Lojf0GnxSRIHpqn4YswZHvEteAjFcv+1a0zXsXXYIRyrVe+M73 CGf7e25Q7M3xekbI7AifQ8/F3hw1YbS5C/DsvkGugTylLTzykqRG7/rmgIWQtN7vDF6P q4Iw== X-Forwarded-Encrypted: i=1; AJvYcCVJlfswcXV+HrQihLT5Xr/um2Z0gpBDdUmNvuCw2g0DvZ26PoFmO0gVZkldCt4HtEFhbo5Zz75SgA==@kvack.org X-Gm-Message-State: AOJu0YzsIv6K8HwlowGSnH4T3sYvbBE5poI1ziYTytunt3/jkGR9yrKZ or3Ntd8yZbHpP39s00bIpMZ8tX9lTI//A7ucT4pEzwu5opl+FIOYLz2wws1QlQg= X-Gm-Gg: ASbGncuEPYckoxRgHl0lj9XZXBJqer1k4xUcajheq8ise4UyYuKalVot7TLhK0MNJlD 570Q8RTZ+kMK16gRVaOFd5EdtKm2moqRrVlhka0jMLMfp0S/IIjUk44E5IuEAf/mtIHNan838D4 rYEZQUrFVnhE8x2D1aeCQFb/u+hqKY5klGOj4sJK6DASwSladyA1uG/4UabjeL0FgyLyNMXksKN zkLNgdOwM6JI/UojdUBXBOztpZr7U8+Zwd5ro/utyBiaizkw9sb9ZrS7Rr6WPasn9eyEDdAkBKR 8iA7O9uPxCOkm8Q51d1DXl3EDGUvwA1LIRtLBBYXi3Pv63e+Nbo= X-Google-Smtp-Source: AGHT+IFNazEr6ZYOzQGCXjgc58dYoHgOgILSppSPlOaxKyAejkPiwQZrkFFar4hARLXGCzwX+g5Izw== X-Received: by 2002:a17:903:40c9:b0:215:b9a6:5cb9 with SMTP id d9443c01a7336-22dbf4db64dmr47389315ad.5.1745599161894; Fri, 25 Apr 2025 09:39:21 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db51028basm34556395ad.196.2025.04.25.09.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 09:39:21 -0700 (PDT) Date: Fri, 25 Apr 2025 09:39:18 -0700 From: Deepak Gupta To: Radim =?utf-8?B?S3LEjW3DocWZ?= Cc: 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 , Jann Horn , Conor Dooley , 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, linux-riscv Subject: Re: [PATCH v12 12/28] riscv: Implements arch agnostic shadow stack prctls Message-ID: References: <20250314-v5_user_cfi_series-v12-0-e51202b53138@rivosinc.com> <20250314-v5_user_cfi_series-v12-12-e51202b53138@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Stat-Signature: i3epfre3zgpc3hbwgyz369wpqryfupfm X-Rspamd-Queue-Id: 1E1E440002 X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1745599162-774814 X-HE-Meta: U2FsdGVkX19j3mUZ9g/48zCTzCLkEGCmK1S2yWKMReiEpfvnt81e+ylH7FvZLiazLhjPxr2KCH+Jtl60Gj7mMLlpyTlmMsqoYNPVIwWM+vfBi78MHxwSF0ocUapsWTqgVjkfkm/eCGtgccjc1McP0a7yVgTSBvTdtlw1HMu0iBU9S5l36zrF3r5s7V2lrPGloaH3zqCdF9qWn8rcRzEQtdhHyIIroGkWGasDbbNvzYjT3/YmSV8g394FsU37dheHeQU0j4cgUh3l5rznOwU70RcotpFzRdVXMKhusCHBHKAjA79Ey0euP9RtyFJreVoCaNzZ281YYsMI5bCWDgTnW84gOorPzs4yP7L5iN+kUGL6004CwDU5GTUxCQP99pOTD3M+hltpQP/67hElKhcvCqLXs2OTPaslHIIPi/APNpkKWnUo7vT27CwIU+aKI4rw6VyHJdE2gzxrjF33xH2mn1TV0zoMqVNM02trBN4a3ks7hNxDnB5EhPWzMqfchZdBgMpdRcM9GzjEcDwvqNDfUEIKe+P+YkNhpPytAcPcXlR7WWnQ/zAw1iuavtvYLk43RWA9QAyQVtwg+zSheFEBUVNq5J8x4L/xFnti4BG19+f9TQvoXXDlEFNU6Xtuo+tjiIEJL4EJoBtwyZmjsnvrJC24aIWOIK8t20z/l/eOiGXYZmqL279s2gOKT6s6+fWjNGOsQkJ8WYfZkl5kNTQ5JgdtkvpfT3dDly29iEHDMlcUwWgmxLR9wRnflBnDntWm4e33ZOmq8s9QlES1ehBn/gPkX8G16amRd0TVh7+OlDeoJuMUXREdFxJ5ta9M3eZvPXIEL84lTyGocw6LuzWvkgh3kyiqqP1FDzyFW/L82u2tENCbLC1hsUIVjwie8Ifv13+fgPDMO9XPeeBTYHnzOcEK1oet4kHwX3JCE+CHL+8z5S1+TOQ4c6ZF/rvotZf7uEvLMgmwWb78+KF0j+W jBdGVTGT sYLWr5p3Haz/KvuTMCiiAmHSWylTwGo3XBYircE0KO38nSZTbO0/RicOJrOdMiOSKHVjU1hLvxpfxSKH5ermIJaIyQnUbapOZFJWDg2/b1uwU3Gx41Go6BkshmUhUO4A+fkPjKZZ+FJr3fPzXFZ6iroT7wMNpfdAdBfTlG0oRjUPgEkfMwZJmXzin7yJnFRjDNLlbvykoiKmBRCELnvPzSCRjUS0ScVROXCHAWV0YGPQqLrRYB3lHtQRnHg1Xw2SnEwg2uFtKbZt8kkHRKg6RsQ9I6+Wp8Br0IWb3XdOrT+NyYi3O+S5bZn0y16ujYia6EmgphV3/XXtXTzl0GhuPk2/6rAXh/HEdFypbwOgJa9uStKqqhekdaE3D1R1D4u4poJBpJgzqI+T7/O6Dqcs9lGIoOXvKJP4RFXfIIa07/ZbgDx9QB9UCZRXZbuLsLgWfI0IxU9a4lk1ahYHXGFiCMJTUx1Qq1BV2Xajtp6vVM3HL2vmtcXB7901etfj673yZ9XPINbBkJZWEHZ5R0GHwxy1BOA== 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: On Fri, Apr 25, 2025 at 01:42:44PM +0200, Radim Krčmář wrote: >2025-04-24T11:16:19-07:00, Deepak Gupta : >> On Thu, Apr 24, 2025 at 03:36:54PM +0200, Radim Krčmář wrote: >>>2025-04-23T21:44:09-07:00, Deepak Gupta : >>>> On Thu, Apr 10, 2025 at 11:45:58AM +0200, Radim Krčmář wrote: >>>>>2025-03-14T14:39:31-07:00, Deepak Gupta : >>>>>> diff --git a/arch/riscv/include/asm/usercfi.h b/arch/riscv/include/asm/usercfi.h >>>>>> @@ -14,7 +15,8 @@ struct kernel_clone_args; >>>>>> struct cfi_status { >>>>>> unsigned long ubcfi_en : 1; /* Enable for backward cfi. */ >>>>>> - unsigned long rsvd : ((sizeof(unsigned long) * 8) - 1); >>>>>> + unsigned long ubcfi_locked : 1; >>>>>> + unsigned long rsvd : ((sizeof(unsigned long) * 8) - 2); >>>>> >>>>>The rsvd field shouldn't be necessary as the container for the bitfield >>>>>is 'unsigned long' sized. >>>>> >>>>>Why don't we use bools here, though? >>>>>It might produce a better binary and we're not hurting for struct size. >>>> >>>> If you remember one of the previous patch discussion, this goes into >>>> `thread_info` Don't want to bloat it. Even if we end shoving into task_struct, >>>> don't want to bloat that either. I can just convert it into bitmask if >>>> bitfields are an eyesore here. >>> >>> "unsigned long rsvd : ((sizeof(unsigned long) * 8) - 2);" >>> >>>is an eyesore that defines exactly the same as the two lines alone >>> >>> unsigned long ubcfi_en : 1; >>> unsigned long ubcfi_locked : 1; >>> >>>That one should be removed. >>> >>>If we have only 4 bits in 4/8 bytes, then bitfields do generate worse >>>code than 4 bools and a 0/4 byte hole. The struct size stays the same. >>> >>>I don't care much about the switch to bools, though, because this code >>>is not called often. >> >> I'll remove the bitfields, have single `unsigned long cfi_control_state` >> And do `#define RISCV_UBCFI_EN 1` and so on. > >I might have seemed too much against the bitfieds, sorry. I am against >the rsvd fields, because it is a pointless cognitive overhead and even >this series already had a bug in them. Aah got it. > >#defines should generate the same code as bitfields (worse than bools), >so the source code is really a matter of personal preference. >(I do prefer bitfields.) > >>>>>> @@ -262,3 +292,83 @@ void shstk_release(struct task_struct *tsk) >>>>>> +int arch_lock_shadow_stack_status(struct task_struct *task, >>>>>> + unsigned long arg) >>>>>> +{ >>>>>> + /* If shtstk not supported or not enabled on task, nothing to lock here */ >>>>>> + if (!cpu_supports_shadow_stack() || >>>>>> + !is_shstk_enabled(task) || arg != 0) >>>>>> + return -EINVAL; >>>>> >>>>>The task might want to prevent shadow stack from being enabled? >>>> >>>> But Why would it want to do that? Task can simply not issue the prctl. There >>>> are glibc tunables as well using which it can be disabled. >>> >>>The task might do it as some last resort to prevent a buggy code from >>>enabling shadow stacks that would just crash. Or whatever complicated >>>reason userspace can think of. >>> >>>It's more the other way around. I wonder why we're removing this option >>>when we don't really care what userspace does to itself. >>>I think it's complicating the kernel without an obvious gain. >> >> It just feels wierd. There isn't anything like this for other features lit-up >> via envcfg. Does hwprobe allow this on per-task basis? I'll look into it. > >I think PMM doesn't allow to lock and the rest don't seem configurable >from userspace. > >It's not that important and we hopefully won't be breaking any userspace >if we decided to allow it later, so I'm fine with this version.