Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp519474pxb; Wed, 20 Jan 2021 12:54:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJylacDgEvM8mKP9duLmA/xZ5zLICAncER6j3HmaWrOQc9QEjYaS8YkKhk6HwpvgkTlv6p7D X-Received: by 2002:a05:6402:1701:: with SMTP id y1mr8484972edu.251.1611176093710; Wed, 20 Jan 2021 12:54:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611176093; cv=none; d=google.com; s=arc-20160816; b=UcYKe9Vkx73XaQWNMTW5wRuFYYamqVwdGu6aWN3mJ6Q49g4PD7DSkhpHzlgZwwdp41 zr5EeTdLrfMVNicqAgNceN+UeBajVvFx7OG0HlYKaJuJAI+khcvcXHCcBGAu7/QNeswE JR9hzdVtRAn98cmT+fUHM0C7Wdm6dvjMymB7Ue2hBtSBqhaEb/zrn5fSPFPM5s6uJu0h sI/nntO3xD2tD5OYvD04t3nUfR7Ia14rVzgkZBuTxvASEh3kF0Px9HRX/89eI210gmBz 1SVpGlvJd6AJhNwzFqLrtsyQsU3oNUnYkHzLgG/Is00hanhJi2ffofBKkUXJEQGXGNyt fAxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=FuVKEjQez4IgvhTSGsdofKZoh+yL5vcdn6sFuKQVNEc=; b=Bq6Fbh/R9aWvJKL01xg9bPPqXJ+53/QGnlzmxpJ4IO9vYSgLkOBBseLBZ1pKsHmecE rFuVrxgamkGl7fMw1YOPzBIwG1+CNOEhL51rW50ycZMazQBRr1jQCNZXRRQtb347jVQh Hcwf9Cd5xowMckFY1dnTYKyH9LmYKRlO77DsQGwqfdHXLXCzFeYXtcxjfRkAEa1I35Dx BHw0VUQUIJ+wP3XHTSAOBqKceZ2Hd0Mwo0sKOvjVqoVdE9B2+2Y0FPf6deGfPm5IANDa 6Rco30+SfA22+I4SP2Z9KdD73PzD8vTbfqo9CnHAl6GLJ4Yab+F98DEAKEmFBZOuSj76 dUzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Pm+Tk+XH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c15si1013091ejr.124.2021.01.20.12.54.25; Wed, 20 Jan 2021 12:54:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Pm+Tk+XH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733263AbhATUsS (ORCPT + 99 others); Wed, 20 Jan 2021 15:48:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388790AbhATUrl (ORCPT ); Wed, 20 Jan 2021 15:47:41 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65CF5C0613C1 for ; Wed, 20 Jan 2021 12:47:01 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id 190so3952306wmz.0 for ; Wed, 20 Jan 2021 12:47:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FuVKEjQez4IgvhTSGsdofKZoh+yL5vcdn6sFuKQVNEc=; b=Pm+Tk+XH56AJLV4R9q8ryuaX/PS5v2qdPsQr0bB+Spl24KGCLqt7Nlmq9SE2i086Qj 7NKz6u6EF3+gHIIsTajqFsRUUFa+S8l13K9mSh/CzsgxDbMsiMDr+a4dJ8DUpxqUGeG4 X4P43o46XC3TBQsZRzKJ8Ms1Y1I5TWpJAKDhYdHhIjY64cp60MAKDLu3dmxh7PRL2rVG lP81NSAfyw/WC4Y1FXusX7fNzCmZJzK+miggd9n3eJixh8SBeKfo75KSRBT9TMbIh2Fs 0p11l7CZ0IuUWukJQ+6vghvwx+j/uAPW+VAZvjfvYUgkn5HTC6h6pXHljcf9Y2S/ix7B m5Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FuVKEjQez4IgvhTSGsdofKZoh+yL5vcdn6sFuKQVNEc=; b=WeKu2qAjOW73i5OV87taE1Hzxa5Si7CoNlpXXxzJi/rKwncPEKym5Kd8u0uwjHWQ03 unRBtJotyc4M0DTiwzyWujjsO60hgxyrTSUA9r3ZgANVVLCn9ccAYgqDJiUmLfTTPpbw f0nSvOwLAfz7m1A5tlIWAGvg8eNyrQhRTxuig1Zd8ZNhpeGFP2lQoCnBCuUxxZLnQnkk ZVN8uOZ1qGqgkkz4bQBP0vIrJii7f9YwuWTLIe9vqpF8+6YtEz2ZiIlIEKQYnW1thuP4 G8mtJn1g/kmk/wT8u7SYLS+A2UByQ9S+Ma/Qtxua9n6k8d7bgUgpsj5yJXs+R+LJNAsC FVfw== X-Gm-Message-State: AOAM533pBIRpBAed5bC7cx3jeCF/GodUEsjAB7Xn4dxp9f4SxHKIFTMk GAqai935BaWnLqn+TwlLZHP3SG9gfgOSM5ZjN+N00g== X-Received: by 2002:a1c:9dd5:: with SMTP id g204mr5955507wme.37.1611175619858; Wed, 20 Jan 2021 12:46:59 -0800 (PST) MIME-Version: 1.0 References: <20210111170622.2613577-1-surenb@google.com> <20210112074629.GG22493@dhcp22.suse.cz> <20210112174507.GA23780@redhat.com> <20210113142202.GC22493@dhcp22.suse.cz> In-Reply-To: From: Suren Baghdasaryan Date: Wed, 20 Jan 2021 12:46:49 -0800 Message-ID: Subject: Re: [PATCH v2 1/1] mm/madvise: replace ptrace attach requirement for process_madvise To: Jann Horn Cc: Michal Hocko , Oleg Nesterov , Andrew Morton , Kees Cook , Jeffrey Vander Stoep , Minchan Kim , Shakeel Butt , David Rientjes , =?UTF-8?Q?Edgar_Arriaga_Garc=C3=ADa?= , Tim Murray , linux-mm , SElinux list , Linux API , LKML , kernel-team , linux-security-module , stable Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 20, 2021 at 8:57 AM Suren Baghdasaryan wrote: > > On Wed, Jan 20, 2021 at 5:18 AM Jann Horn wrote: > > > > On Wed, Jan 13, 2021 at 3:22 PM Michal Hocko wrote: > > > On Tue 12-01-21 09:51:24, Suren Baghdasaryan wrote: > > > > On Tue, Jan 12, 2021 at 9:45 AM Oleg Nesterov wrote: > > > > > > > > > > On 01/12, Michal Hocko wrote: > > > > > > > > > > > > On Mon 11-01-21 09:06:22, Suren Baghdasaryan wrote: > > > > > > > > > > > > > What we want is the ability for one process to influence another process > > > > > > > in order to optimize performance across the entire system while leaving > > > > > > > the security boundary intact. > > > > > > > Replace PTRACE_MODE_ATTACH with a combination of PTRACE_MODE_READ > > > > > > > and CAP_SYS_NICE. PTRACE_MODE_READ to prevent leaking ASLR metadata > > > > > > > and CAP_SYS_NICE for influencing process performance. > > > > > > > > > > > > I have to say that ptrace modes are rather obscure to me. So I cannot > > > > > > really judge whether MODE_READ is sufficient. My understanding has > > > > > > always been that this is requred to RO access to the address space. But > > > > > > this operation clearly has a visible side effect. Do we have any actual > > > > > > documentation for the existing modes? > > > > > > > > > > > > I would be really curious to hear from Jann and Oleg (now Cced). > > > > > > > > > > Can't comment, sorry. I never understood these security checks and never tried. > > > > > IIUC only selinux/etc can treat ATTACH/READ differently and I have no idea what > > > > > is the difference. > > > > Yama in particular only does its checks on ATTACH and ignores READ, > > that's the difference you're probably most likely to encounter on a > > normal desktop system, since some distros turn Yama on by default. > > Basically the idea there is that running "gdb -p $pid" or "strace -p > > $pid" as a normal user will usually fail, but reading /proc/$pid/maps > > still works; so you can see things like detailed memory usage > > information and such, but you're not supposed to be able to directly > > peek into a running SSH client and inject data into the existing SSH > > connection, or steal the cryptographic keys for the current > > connection, or something like that. > > > > > > I haven't seen a written explanation on ptrace modes but when I > > > > consulted Jann his explanation was: > > > > > > > > PTRACE_MODE_READ means you can inspect metadata about processes with > > > > the specified domain, across UID boundaries. > > > > PTRACE_MODE_ATTACH means you can fully impersonate processes with the > > > > specified domain, across UID boundaries. > > > > > > Maybe this would be a good start to document expectations. Some more > > > practical examples where the difference is visible would be great as > > > well. > > > > Before documenting the behavior, it would be a good idea to figure out > > what to do with perf_event_open(). That one's weird in that it only > > requires PTRACE_MODE_READ, but actually allows you to sample stuff > > like userspace stack and register contents (if perf_event_paranoid is > > 1 or 2). Maybe for SELinux things (and maybe also for Yama), there > > should be a level in between that allows fully inspecting the process > > (for purposes like profiling) but without the ability to corrupt its > > memory or registers or things like that. Or maybe perf_event_open() > > should just use the ATTACH mode. > > Thanks for additional clarifications, Jann! > Just to clarify, the documentation I'm preparing is a man page for > process_madvise(2) which will list the required capabilities but won't > dive into all the security details. > I believe the above suggestions are for documenting different PTRACE > modes and will not be included in that man page. Maybe a separate > document could do that but I'm definitely not qualified to write it. Folks, I posted the man page here: https://lore.kernel.org/linux-mm/20210120202337.1481402-1-surenb@google.com/ Also I realized that this patch is not changing at all and if I send a new version, the only difference would be CC'ing it to stable and linux-security-module. I'm CC'ing stable (James already CC'ed LSM), but if I should re-post it please let me know. Cc: stable@vger.kernel.org # 5.10+