Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1184076pxb; Thu, 4 Mar 2021 05:37:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJysZ17cIwaQ3DajSo+Fa4M+/9wstl66fz1Mwep6YxAuhgNvpgTGsRiKZxDZ03UKBRGjMPJ/ X-Received: by 2002:a17:906:19d9:: with SMTP id h25mr4406114ejd.453.1614865069224; Thu, 04 Mar 2021 05:37:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614865069; cv=none; d=google.com; s=arc-20160816; b=fhsd8aNjhWzW+4erOKq1R+B3wtdA5TY7Jp+zq6rkP0AD7Gc3VMWdGJO/H8G4p6lrmp OFVMsCf7RPCkrb04Q3Mbsw1Rc/fXyTzTLC0DbRiCFQOl+bRwSi3ZBmbyw8Km60Srl2ZO 2BNyb0xx6JvZE5JLsMu1V+LBO7ZX/zvov2371N85X16SJ2J6/njjn+bIAetexBwm4fvQ 5CH8N90L5cwKJ1G5DHbLk59fsYkwuDqCn02b744I3yETxJxEJcxtd2EbDl8tK6uAx0dU wbA6bIQLcTIkR/OPlhd9t8DmDaHaFLC7sxtM8m/uVAfGhf1/r2RvnauSbg/sKpmo2cTS n0Mw== 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=bJioWY2SyxYVyQ6HbJCASiO240osNAH7hbvsbBMN9q8=; b=Cq1zsuXJ49/dY2F4bDZux8MfIuk+NtiU3Aq3E76KlUYUPxLgoFBeDgma/Yv/k3zSS/ jCchWaRa+BplQUusZQKTlnW4gEL1MvgN/rgiVEZ1QrrT2DyIrn3ML4KG4zxbzY4x+/31 gNuY7w8pHDy5FJUrTMakXcu4YreyV9tA1AiRDOwo7eznfwXsC0k2WAWCfR/E7ivIBgYp DIESyNaUF+au9I2WG2o7Qp2P2bJrjTEz3Em4AqgloaLXGHhK4Kt//C1V7ovn68b8mFjW dUMJx2M3gK2BJiYQuimkB35k7EXzJN4DVaALm12IWxV+0mRjRTCJzQdYHVdPBYjopOik QSqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FoRQIWOr; 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 a7si14867920edm.320.2021.03.04.05.37.26; Thu, 04 Mar 2021 05:37:49 -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=FoRQIWOr; 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 S1392420AbhCDAOl (ORCPT + 99 others); Wed, 3 Mar 2021 19:14:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352984AbhCDACw (ORCPT ); Wed, 3 Mar 2021 19:02:52 -0500 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38EB6C0613D9 for ; Wed, 3 Mar 2021 15:17:46 -0800 (PST) Received: by mail-lf1-x12c.google.com with SMTP id v5so39934833lft.13 for ; Wed, 03 Mar 2021 15:17:46 -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=bJioWY2SyxYVyQ6HbJCASiO240osNAH7hbvsbBMN9q8=; b=FoRQIWOrOSWpnQbeeOXEI0flZTsv0PV0p6wcI8b93AXHcM1gZ9aSnR1JoGSQ7lgbr2 kqVLxVWd6pXmGnnj6l3QenA5IzsbN0UptJpSd2tLC9BrhNhfIQJZg9nB5Uj2nGB1bY8D eDxdv3YfhpMCGKxTMQbxtC6iSYy0t+VepEzieFcHY/2yYJ2YLCgecFfgiDt0F9Hm0jk9 O7MVXDHKDSSsq0dj8J/OQcQNe0x8KFa6yLZ2DYMjQDjsp728TzXjhJkTby2uUZRcUhTv EFhOCncRRxDkD4iVeoGMRenftxA9y/iA12zP7+x7Bgg9/08hogDFwBNfHnJQEFzROPTL 41KA== 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=bJioWY2SyxYVyQ6HbJCASiO240osNAH7hbvsbBMN9q8=; b=iPm7wqLzX9kCAwp9ssSova4Gk9jwbGe6titiw9Ee1LLePEpReDMT3TjHUQ91Bfg1C5 m9OCNHQG7aQUw2HYdTT3V3gekcxmDkvu9sw0X9fUbN3j/rIm8TyckW3DXogW/NsmtQyM 8+kKKFBcGNffHFZC6O58G3sWmTImo9DbLr65Wvci+bg2JidZoQqpmb406aFZP/pxI8vD Fn2zF3/1UHN7HYWhtz9qMEOYqQUB1u/ryK58pbus5R1j7DMJNw80qPxUX0KjtbbNu8ih EqnFy0VM752dm0FX5n4okPi5NsbNp/gVkwQ0wXLerQx4u+Cyx8wL6njlwSnYatQKlcvW rw9Q== X-Gm-Message-State: AOAM530LjbmOql4NbRkEU177YuwQJN1rX6brAKBppu+UmeHeDlaFWdG/ uDpwQdJrQlDCwN7ahfovGHL2tNTkzmS/1YcGyDgZPQ== X-Received: by 2002:a05:6512:10c8:: with SMTP id k8mr587955lfg.299.1614813464307; Wed, 03 Mar 2021 15:17:44 -0800 (PST) MIME-Version: 1.0 References: <20210303185807.2160264-1-surenb@google.com> In-Reply-To: <20210303185807.2160264-1-surenb@google.com> From: Shakeel Butt Date: Wed, 3 Mar 2021 15:17:30 -0800 Message-ID: Subject: Re: [PATCH v3 1/1] mm/madvise: replace ptrace attach requirement for process_madvise To: Suren Baghdasaryan Cc: Andrew Morton , Jann Horn , Kees Cook , jeffv@google.com, Minchan Kim , Michal Hocko , David Rientjes , edgararriaga@google.com, Tim Murray , fweimer@redhat.com, oleg@redhat.com, jmorris@namei.org, Linux MM , selinux@vger.kernel.org, linux-api@vger.kernel.org, linux-security-module@vger.kernel.org, stable@vger.kernel.org, LKML , kernel-team Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 3, 2021 at 10:58 AM Suren Baghdasaryan wrote: > > process_madvise currently requires ptrace attach capability. > PTRACE_MODE_ATTACH gives one process complete control over another > process. It effectively removes the security boundary between the > two processes (in one direction). Granting ptrace attach capability > even to a system process is considered dangerous since it creates an > attack surface. This severely limits the usage of this API. > The operations process_madvise can perform do not affect the correctness > of the operation of the target process; they only affect where the data > is physically located (and therefore, how fast it can be accessed). > 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. > > Cc: stable@vger.kernel.org # 5.10+ > Signed-off-by: Suren Baghdasaryan > Reviewed-by: Kees Cook > Acked-by: Minchan Kim > Acked-by: David Rientjes > --- > changes in v3 > - Added Reviewed-by: Kees Cook > - Created man page for process_madvise per Andrew's request: https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=a144f458bad476a3358e3a45023789cb7bb9f993 > - cc'ed stable@vger.kernel.org # 5.10+ per Andrew's request > - cc'ed linux-security-module@vger.kernel.org per James Morris's request > > mm/madvise.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/mm/madvise.c b/mm/madvise.c > index df692d2e35d4..01fef79ac761 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -1198,12 +1198,22 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, > goto release_task; > } > > - mm = mm_access(task, PTRACE_MODE_ATTACH_FSCREDS); > + /* Require PTRACE_MODE_READ to avoid leaking ASLR metadata. */ > + mm = mm_access(task, PTRACE_MODE_READ_FSCREDS); > if (IS_ERR_OR_NULL(mm)) { > ret = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH; > goto release_task; > } > > + /* > + * Require CAP_SYS_NICE for influencing process performance. Note that > + * only non-destructive hints are currently supported. How is non-destructive defined? Is MADV_DONTNEED non-destructive? > + */ > + if (!capable(CAP_SYS_NICE)) { > + ret = -EPERM; > + goto release_mm; > + } > + > total_len = iov_iter_count(&iter); > > while (iov_iter_count(&iter)) { > @@ -1218,6 +1228,7 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, > if (ret == 0) > ret = total_len - iov_iter_count(&iter); > > +release_mm: > mmput(mm); > release_task: > put_task_struct(task); > -- > 2.30.1.766.gb4fecdf3b7-goog >