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 X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D7E3C43381 for ; Tue, 12 Jan 2021 18:12:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C09722311F for ; Tue, 12 Jan 2021 18:12:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C09722311F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 24C0A6B0093; Tue, 12 Jan 2021 13:12:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FBC46B0096; Tue, 12 Jan 2021 13:12:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09DDB6B0098; Tue, 12 Jan 2021 13:12:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0219.hostedemail.com [216.40.44.219]) by kanga.kvack.org (Postfix) with ESMTP id E6F606B0093 for ; Tue, 12 Jan 2021 13:12:16 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9282C181AEF30 for ; Tue, 12 Jan 2021 18:12:16 +0000 (UTC) X-FDA: 77697917472.16.cave21_5c0f0eb27517 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 6C0AB100E690B for ; Tue, 12 Jan 2021 18:12:16 +0000 (UTC) X-HE-Tag: cave21_5c0f0eb27517 X-Filterd-Recvd-Size: 6807 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 18:12:15 +0000 (UTC) Received: by mail-wm1-f49.google.com with SMTP id i63so2739341wma.4 for ; Tue, 12 Jan 2021 10:12:15 -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=smXyl8aMoZOEr9J+WPP+DzU0ZsazRkPgKalBFLKErx4=; b=pIKsGNS7XHejO5gTe8wbn24/35SeJMW+SvSJ/oeKw17yifkmaFlfbY9+v66BJ7um5N jU+IZrFDd6idbjz3QMSPU1pUH3f9jUl95GJRt8W0v+LVJIO+2jf7snXL3mAKC9L//EMK BnBogYSBWvwjxmqPmRhwtpjK/wFUSLWKW4v7cI9+lddzYKjqxtV51WsYOKjn1kJb7Y8i KuYCguZi4+XAkVMo8O93yjXREx8rmKPnAG1WfT9kpAGQOwTBfmpug7TdUsfvnCpc8zVm 40fWFaxeCpSkrVd746bx3+hRw39BqL48JDjWwBi8+2hnQtppjAqXxe/1drWSKIMgYa/Z FwdA== 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=smXyl8aMoZOEr9J+WPP+DzU0ZsazRkPgKalBFLKErx4=; b=TI04tQlPFlALuyF3mjWb6Qks46ByQ20xSzsoJ1EJD1HylIsga6YEf2B6yqKQBdJP/i rlHiIsoQY/7zsFbUZeIoEsTorLcFSYXFQrCP6Lbx/VPWSbnhmIWrxn57WMwoxFACgPHd C28jFrePQc57z40fAcNW8JeR3f3XmhphELoQNbnupBrjoGxEPXVh1YcvkEQ5ki3mdzx/ kiRx5ph/BrxunOcP1cl6WqgDjPfZJk1wg3pYV7kHRALJ95Sc76wMeL5BXEeTRMHmDB6k +QU3L9tQIFVtMbY0ApZV9eK9ViKbA+B4lW4Dp1rDutz4pamV0nZOKYXoVqWT96EBQ4Gw Yp7A== X-Gm-Message-State: AOAM532s9v8R1n2rDojvh0TjWJOaXaVWvSg/PJIsD9lkfiTys1qM587o BMSloCoUftJYUwMdZeqQo1xIGghv4HV3woPu9kPouw== X-Google-Smtp-Source: ABdhPJz5caMoBvGVsM71MxbmEH8PEzgl9neSsmGPzQ4gGQozZ+H8IpOItvaPYAYpiMSgpFD+C1qTg+cErr0BdINtfyU= X-Received: by 2002:a1c:4e0a:: with SMTP id g10mr502029wmh.88.1610475134449; Tue, 12 Jan 2021 10:12:14 -0800 (PST) MIME-Version: 1.0 References: <20210111170622.2613577-1-surenb@google.com> <20210112074629.GG22493@dhcp22.suse.cz> In-Reply-To: <20210112074629.GG22493@dhcp22.suse.cz> From: Suren Baghdasaryan Date: Tue, 12 Jan 2021 10:12:03 -0800 Message-ID: Subject: Re: [PATCH v2 1/1] mm/madvise: replace ptrace attach requirement for process_madvise To: Michal Hocko Cc: Andrew Morton , Jann Horn , Kees Cook , Jeffrey Vander Stoep , Minchan Kim , Shakeel Butt , David Rientjes , =?UTF-8?Q?Edgar_Arriaga_Garc=C3=ADa?= , Tim Murray , linux-mm , selinux@vger.kernel.org, Linux API , LKML , kernel-team , Oleg Nesterov Content-Type: text/plain; charset="UTF-8" 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: On Mon, Jan 11, 2021 at 11:46 PM Michal Hocko wrote: > > On Mon 11-01-21 09:06:22, 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). > > Yes it doesn't influence the correctness but it is still a very > sensitive operation because it can allow a targeted side channel timing > attacks so we should be really careful. Sorry, I missed this comment in my answer. Possibility of affecting the target's performance including side channel attack is why we require CAP_SYS_NICE. > > > 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). > > Is CAP_SYS_NICE requirement really necessary? > > > Signed-off-by: Suren Baghdasaryan > > Acked-by: Minchan Kim > > Acked-by: David Rientjes > > --- > > mm/madvise.c | 13 ++++++++++++- > > 1 file changed, 12 insertions(+), 1 deletion(-) > > > > diff --git a/mm/madvise.c b/mm/madvise.c > > index 6a660858784b..a9bcd16b5d95 100644 > > --- a/mm/madvise.c > > +++ b/mm/madvise.c > > @@ -1197,12 +1197,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. > > + */ > > + if (!capable(CAP_SYS_NICE)) { > > + ret = -EPERM; > > + goto release_mm; > > + } > > + > > total_len = iov_iter_count(&iter); > > > > while (iov_iter_count(&iter)) { > > @@ -1217,6 +1227,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.0.284.gd98b1dd5eaa7-goog > > > > -- > Michal Hocko > SUSE Labs