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 10E72C02188 for ; Tue, 28 Jan 2025 00:41:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81F6D2801E9; Mon, 27 Jan 2025 19:41:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D0DB2801E4; Mon, 27 Jan 2025 19:41:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66FCB2801E9; Mon, 27 Jan 2025 19:41:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 451092801E4 for ; Mon, 27 Jan 2025 19:41:12 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C65DB80992 for ; Tue, 28 Jan 2025 00:41:11 +0000 (UTC) X-FDA: 83055006342.21.C8E273D Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 13F4AA000E for ; Tue, 28 Jan 2025 00:41:09 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="0/WiCq9v"; spf=pass (imf15.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738024870; 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=1tdj4/k9dZ6zLA3HUsRa2EkQj72MAkr2bT0sDPudd6Q=; b=3bf6RQqcnmuXp08Tq/6oTw5cOw+crXQRtY1V8deaTmoNJF8StuRvjm+xpZGhyZeBPCkOU7 ZhpLxei6h+8BL+LuhF79j3lw+RY8Gb2hkDsRyrBbGWnYrTvmNGnr9n8CJzlZwpI2xvJd7M TiCu4cSN+t8H8UU+alaNJWQwCfbsb78= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="0/WiCq9v"; spf=pass (imf15.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738024870; a=rsa-sha256; cv=none; b=i8Rmfj2gRltKwvkVb7KnQL5ZY2YTRvS5vUr2MoSnQWRSZ/VRjnanymyzsG7Twj2vSYmUWi pCKJ/heTjENMMyyiHLBUhd2CQ++hmoX703DbTVd7vxojj63KaXULmFyw/D+pM8cpkjnXBf beTYbovuXeEPMi5Cgukg4ngl311XNr0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D6D945C5858; Tue, 28 Jan 2025 00:40:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12F3FC4CED2; Tue, 28 Jan 2025 00:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1738024868; bh=n9XTVKn6KHy7cORMWOZCzd4Ie6hNugIHiNZYNrvLsD4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=0/WiCq9vvlbeyOMCmkWvXr2wXtiaAyUu5RI+un3MWYf6/wGRcRDRTgH0K+aFp/PSx Ajs5w4OT9TXmrgAvwljfQpSGGbyvGUA/dxmjg1XDxLkFrMiNgnqc1Xb6Ksy8Pg1Zn+ GCII9kuSHFUCjSdofzYBmSAOmwtKZbKsdwCC5agQ= Date: Mon, 27 Jan 2025 16:41:06 -0800 From: Andrew Morton To: Andrii Nakryiko Cc: linux-mm@kvack.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, shakeel.butt@linux.dev, 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: <20250127164106.5f40b62e0f1cf353538c46fd@linux-foundation.org> In-Reply-To: <20250127222114.1132392-1-andrii@kernel.org> References: <20250127222114.1132392-1-andrii@kernel.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 13F4AA000E X-Stat-Signature: 56xqbaun4pqjtbnuuicrzq6kytrpt7c6 X-HE-Tag: 1738024869-189661 X-HE-Meta: U2FsdGVkX18STDfXS1QMGFPRdVeOoIrjdZGAO/dzidSEN8R92xkhkG2xg/dyuxLuKjvGCGuIwgR+FN6ytKfjKgyJcq5N8dkBQyRoqenLa31twbsrgHfAvB25vPGLqKf6fuH9ec+5Ypy/ayUDd4YwStxUnYHFFI1NJMw0LBsprWueOtDxle376NIWzwmoD1GgkaoDdSf3YbG2XmHfmNIT8XdH3UztaQGVLoTTgNxnONmpDB1KUYieKXwW5hhtpawIzC7WFFxcFBKEwHWrjSxtNpbhui0PknyBtnp556DI6asAc0G+2/PnMYrg07byWP2kbFWT5ndFvZd48JJEGNa87/AiGNHfsFxbfrY/WsipR9UGVRXmQIaHavqqX4QLqWFnmx/GM3ct6+dINIWttkAQevPlfq8Y8QAlFxyHbOt9Pcvibh+ITLJuvZrKxqWC0oQ0v/j8edH2IwlfjqUEnX+0ngWMcqCHNoWVjaZFV8jnjPiM/9zkQ1A46aAn+bWRNYZNmm1aZruhsMbw1LcEPC7T59+HY4BBVKBSI2EPv5RretTNhvTxlFgnnkcsXDnsW95tr7qf44vyhbsmpsfiiKS9kPRLdG2MRphaMXdiozRANE+J1/vkQqOiiJtjG1Mp5pzrsL3JU0pS5solkcSycOnNbUmixEpCKv6ikQ3lurctZXLXLTuckgziNi93Meu9fLDDMe5eRrkTnu0xplwzX5W40HmsLiwtXg7WlBBagoa4TCW3EgbW4+s2WV4DFFzIao2g6a7FPz5GSCNH7qd9xY3Ih5mMXlzpZsh1Y/rk6rsczZLtiXpzH/3G5lfkyNBJgy1GWFPcb6UyU8ks+XrLwzZnMvANUIB95kZ7ZNsJ/uQTiLsZux3w48Um2jReDKfkV7jphE/Ne0Keb6P8eyJhD+DPzxlziy52yIRu1P+d1Rugai74UhvkNElOe7R0ILzjDS3ymLmik5bNv81lKH3NIdu KyKCTf65 VQDyFKcUh6QLSYyZWMtH+qNwcQTabLVXPjCqGD767JbmcAGnsnpNcWsCAGnKOg4+/1xT91KsGo7xZEMa0LhDy0irHjgNy2ovgTYhiIa+ILCtvQX78vMvZx+Ahx/fspSMYVH/APRe+xZLVqEHuIC+JFqMmRFofBHdg89b/esBRGIg1jXf9YtqTrIpED/I9+iyBKu8fLW2jWyuviQpIBZazdTPgDJQB/JjRMYSgQbmtxghhjwYDCS6ZWvmPtQXNfCo2z7zjnaTqhj2Fqnkk+45gW8+mfCf8oJ21yTKf 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 Mon, 27 Jan 2025 14:21:14 -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. > This should be documented somewhere, so we can tell our users what we did. Documentation/filesystems/proc.rst seems to be the place. .