Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3825843pxb; Tue, 26 Jan 2021 05:56:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsI/Xr5uwvZnjN8oSl69dKLnIUEt+ybl6371P2+WsyYfxrTQTUqGE60sbXuYI7+Om5XiEV X-Received: by 2002:a17:906:a445:: with SMTP id cb5mr3585105ejb.0.1611669376946; Tue, 26 Jan 2021 05:56:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611669376; cv=none; d=google.com; s=arc-20160816; b=NEOIseAXwxE1GehCFNlCkAqfoVOyo78BFP1DLzOvBeK392dHPEKdA+/PitYI1LeqVx f2GD0hkPvqeDyoeOl8GwzMLG0Ixqm5RjKstrSPen8Z3IV+gxIOsjjUnd2KcLLwKkk1sj L4rLg3m4OZH6HAQNyYKRTc6vA0HmZufoSY7Ls0QmH3FYUA1owPFvoZoqyNLOdy7Vn2nS 4UNfsgMkqKnQOFKwbJG2ixEVtixCxxxwQdhlFVnpnPyqqv885OVBbODHGQsm1i/DzatE EQkF1czQ09BJ6SyQmLdo0Ismlnt27pfn610s89AAEbf0lKdapP6m8marTfpKpODmgonJ RYdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Eq0eIxGFaOAtL0zlId1JHPNVaLrojruOSnd68XSBtBQ=; b=Auw7xK1BzCWl+VdOdOBDnk35OkQ3jOinjvv77LSfKOiDpfKEAh6RYpxj5MeznzuYcR wCHtQCw7QCXynAKei4p4ozE1nxeBr8OymeOdBM24IrSFqNs43I85fopadY68fgrY9XA9 sOOQEJw3VXycNI/boJzfkL0NGc7vUalX027nadeRBqHrSoiFV2MqjePsEgNxh8lKwRmP KEHD9+fU8TybtRPWOeGysFTsu62AnVgahZRyDv7HiWPR7s8+FGT6MCLSmqoLRkd1TF+n 0PF1mEynIbZx+nHQoHNDaQNKe3+sjx9n2C4T/M7xN57+EgAi7MvoRVMbMcGWLYanW6Wb j1DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=CyfrVNC7; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k13si7086846ejv.559.2021.01.26.05.55.52; Tue, 26 Jan 2021 05:56:16 -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=@suse.com header.s=susede1 header.b=CyfrVNC7; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405550AbhAZNxr (ORCPT + 99 others); Tue, 26 Jan 2021 08:53:47 -0500 Received: from mx2.suse.de ([195.135.220.15]:51562 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405524AbhAZNxo (ORCPT ); Tue, 26 Jan 2021 08:53:44 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1611669176; h=from:from:reply-to: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=Eq0eIxGFaOAtL0zlId1JHPNVaLrojruOSnd68XSBtBQ=; b=CyfrVNC7X2pzMVUtodZD8Q54ECXgj72/vBxcKX6o/p/ycRnIOVXjr9PY7SVSh2qANeS7X8 tkNB7fGLi3QHWICIfDRlqoCG22/m9GfM9TnKGLTAXs6AKQerEbtX3eSn2ePgE87q5qKOvg a5PlvteXw8R4Jgyq8X/1YK/mMJkFWkQ= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 72D54AEAC; Tue, 26 Jan 2021 13:52:56 +0000 (UTC) Date: Tue, 26 Jan 2021 14:52:54 +0100 From: Michal Hocko To: Jann Horn Cc: Suren Baghdasaryan , Oleg Nesterov , Andrew Morton , Kees Cook , Jeffrey Vander Stoep , Minchan Kim , Shakeel Butt , David Rientjes , Edgar Arriaga =?iso-8859-1?Q?Garc=EDa?= , Tim Murray , linux-mm , SElinux list , Linux API , LKML , kernel-team , linux-security-module Subject: Re: [PATCH v2 1/1] mm/madvise: replace ptrace attach requirement for process_madvise Message-ID: <20210126135254.GP827@dhcp22.suse.cz> References: <20210111170622.2613577-1-surenb@google.com> <20210112074629.GG22493@dhcp22.suse.cz> <20210112174507.GA23780@redhat.com> <20210113142202.GC22493@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 20-01-21 14:17:39, 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 the clarification. I still cannot say I would have a good mental picture. Having something in Documentation/core-api/ sounds really needed. Wrt to perf_event_open it sounds really odd it can do more than other places restrict indeed. Something for the respective maintainer but I strongly suspect people simply copy the pattern from other places because the expected semantic is not really clear. -- Michal Hocko SUSE Labs