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 5BB3EC0218D for ; Wed, 29 Jan 2025 00:25:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF8FD280023; Tue, 28 Jan 2025 19:25:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B823228001B; Tue, 28 Jan 2025 19:25:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FAF1280023; Tue, 28 Jan 2025 19:25:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7E5B828001B for ; Tue, 28 Jan 2025 19:25:28 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 098861601E2 for ; Wed, 29 Jan 2025 00:25:28 +0000 (UTC) X-FDA: 83058595536.09.3DDD531 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) by imf17.hostedemail.com (Postfix) with ESMTP id 1629040003 for ; Wed, 29 Jan 2025 00:25:25 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mOLNm13u; spf=pass (imf17.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.188 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738110326; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MT13IexUZhkAAXhwE/N0PrSufPCrXu/MeHtXnJGqnn8=; b=EgHMM3Mu/6/P8OmRkQc4miIGJygwJysxTZNJs3znCqptZWS3NyynoQwX6P8BE6gQ8QhJC3 8G/cjBvK9jzNwNIDW8t1jkxxJqHAhQLKe1aG/IrKNX9sA8fARpmEUy1SSovC+6Wy5hjH2K UBKvYa09AAIaXv2YKX1FvngVJwfxlHI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738110326; a=rsa-sha256; cv=none; b=Q1mrxp7b9X2QfzrMt5QExEjdo7xytcNPpidYjsYTipQgH8AZhnHjX74J/NWXmhY4joyPx3 XoOQrqazv49y0kz07KDsWDDuBrPpWhKGg4oBZE1j2Hw/gdGmdCth5EFjn+YAmvjb39yRok mEtowjSLVKR91vAeWEP0WwiT7E2WD+k= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mOLNm13u; spf=pass (imf17.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.188 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Date: Tue, 28 Jan 2025 16:25:13 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1738110319; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MT13IexUZhkAAXhwE/N0PrSufPCrXu/MeHtXnJGqnn8=; b=mOLNm13uTp1vCBsoCiMl443USr46+89cRqKasoOx3qvZ6rPiOKrAfMdyUmGK6Odgyd1abE lEB1SUSXM8Guk9nu61FSeDbyqg+xDwSH/5kq/N+3XJZmfSh2jB0esZ9W/y+xDxrbE6ubqu wBucS28Dl8oGS9oDRufiiSfn4F0AzPY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Andrii Nakryiko Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, brauner@kernel.org, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, peterz@infradead.org, mingo@kernel.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, rppt@kernel.org, liam.howlett@oracle.com, surenb@google.com, kees@kernel.org, jannh@google.com Subject: Re: [PATCH v2] mm,procfs: allow read-only remote mm access under CAP_PERFMON Message-ID: References: <20250127222114.1132392-1-andrii@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250127222114.1132392-1-andrii@kernel.org> X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 8hfxmdoq1kxfjpydq3xnq5e8393j71ed X-Rspamd-Queue-Id: 1629040003 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1738110325-806115 X-HE-Meta: U2FsdGVkX1+syBG+ObTbtjKv6E0n2PZ67rahSP5BLeIDbs4Fp6i9qB88F106IUKeMh3nOv3aF2QJVhCQ0gmkTPUWuv4LRuD4nUMXoXIlUBtGHZH4VD+QX0yyzq85YwoL+CcGgxEd6ZVo5oUdDHI4yU2i2O8AorHoJGgm/dPjl127rTiy+emBuNhcvO2Jr+j1emwl8dg8lXdfuLYn29VoJTz4LdAv995G8ojl9kl3mEQ5UbHRVrFGTkj8nRLKidevMd5yNdQld2li2G9Vzf6edAe+zp1772hS/TgMcpdLcyCXNPyeM5KGxHOe6nyRFdSQBwA7Dtmob4vEpwS/xpMXYYCnMNffEi+e/OJK4q55lac5kNywxinHeLk8VEk0G0to9xFqBCG3IIQ+UmhetUfrEzfR/ws3jSp8tHmGRq9ZfHoRCcTiYdAwUEXv6IpiMbUC1smoU+adCD3ggvIGRD7fOFgkLdkhcQgSr12NDGSS3H9PkfCagCZxate5gBhI9utRZlXZ9jERb9A0E6HIr1Daj5IW0Xn6Nm39sEBPPB/KGq7o94IJGRysX8+l4lyHfU3Ha6NUECH1aXelGXpJIzBLGHGAweF8ebdKAFvdGC8qPX6RIEh6Mx30kyjXkc+TIsOsBDLAEEtAiUHHH/us3rpd6Pne+nKBjUXgQ+FEL3PMWlKbXVLnhuh6RDkGbL277sK/xt62auTf9jG7m9nol6051RK7DHi5asAzs9cmCHxKTgLk9JV+ukXCPST3XKB3BSRwRWJXs0JnE4k4DfYYwvBGWCXZzYp6AAJ7mT76VqVkKZwx7JLaak2zsbAUOMz7HnLc4KUuG5uRZncUI8b6xfo2SBV8hJuIvHCPhg+FTyYi7syD4iqBYJTgdwT7kQ39UoKfwv50tCLVlC0BtWgDzHfvjR5pkhb7YcBm43O/bJrdTo8yZ+1/OXmvMDj1c8BjPEre1PCNvrzdISmDAoPmkzB /FzeHipa vW066Ew4YSUr/ZLQEhvY71mACBRVzmlIVU++udNyOWYgO6G5ygnDXHlzt8HKxiF1jG9RgYhOxi2RSlV6TLbfNPXQnt3Fqw+HCv82xs2sJoeYtDjgDhrP8AmYM9sN3yDCCsc9rpCuu5DwqOVngAv7Sg85aQXCOxgy6ewelqlrQcLsKT/DNdujzxlsY4xRwSzpMYPUYxNx9kHqgN5bnINXmr0GG3J4DTA803i1BmzuCEhuBlVTcBAiihO/qIz0H2N3j2cZU X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, 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 Mon, Jan 27, 2025 at 02:21:14PM -0800, Andrii Nakryiko wrote: > It's very common for various tracing and profiling toolis to need to > access /proc/PID/maps contents for stack symbolization needs to learn > which shared libraries are mapped in memory, at which file offset, etc. > Currently, access to /proc/PID/maps requires CAP_SYS_PTRACE (unless we > are looking at data for our own process, which is a trivial case not too > relevant for profilers use cases). > > Unfortunately, CAP_SYS_PTRACE implies way more than just ability to > discover memory layout of another process: it allows to fully control > arbitrary other processes. This is problematic from security POV for > applications that only need read-only /proc/PID/maps (and other similar > read-only data) access, and in large production settings CAP_SYS_PTRACE > is frowned upon even for the system-wide profilers. > > On the other hand, it's already possible to access similar kind of > information (and more) with just CAP_PERFMON capability. E.g., setting > up PERF_RECORD_MMAP collection through perf_event_open() would give one > similar information to what /proc/PID/maps provides. > > CAP_PERFMON, together with CAP_BPF, is already a very common combination > for system-wide profiling and observability application. As such, it's > reasonable and convenient to be able to access /proc/PID/maps with > CAP_PERFMON capabilities instead of CAP_SYS_PTRACE. > > For procfs, these permissions are checked through common mm_access() > helper, and so we augment that with cap_perfmon() check *only* if > requested mode is PTRACE_MODE_READ. I.e., PTRACE_MODE_ATTACH wouldn't be > permitted by CAP_PERFMON. So /proc/PID/mem, which uses > PTRACE_MODE_ATTACH, won't be permitted by CAP_PERFMON, but > /proc/PID/maps, /proc/PID/environ, and a bunch of other read-only > contents will be allowable under CAP_PERFMON. > > Besides procfs itself, mm_access() is used by process_madvise() and > process_vm_{readv,writev}() syscalls. The former one uses > PTRACE_MODE_READ to avoid leaking ASLR metadata, and as such CAP_PERFMON > seems like a meaningful allowable capability as well. > > process_vm_{readv,writev} currently assume PTRACE_MODE_ATTACH level of > permissions (though for readv PTRACE_MODE_READ seems more reasonable, > but that's outside the scope of this change), and as such won't be > affected by this patch. > > Signed-off-by: Andrii Nakryiko Reviewed-by: Shakeel Butt