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=-13.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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 D8495C433DB for ; Fri, 8 Jan 2021 22:15:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 577E023A9F for ; Fri, 8 Jan 2021 22:15:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 577E023A9F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8342F8D01B1; Fri, 8 Jan 2021 17:15:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 813B68D01B0; Fri, 8 Jan 2021 17:15:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 747E68D01B1; Fri, 8 Jan 2021 17:15:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0049.hostedemail.com [216.40.44.49]) by kanga.kvack.org (Postfix) with ESMTP id 603CA8D01B0 for ; Fri, 8 Jan 2021 17:15:42 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 295B73CFB for ; Fri, 8 Jan 2021 22:15:42 +0000 (UTC) X-FDA: 77684015724.21.humor58_0f02bb5274f6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 092DB180442C2 for ; Fri, 8 Jan 2021 22:15:42 +0000 (UTC) X-HE-Tag: humor58_0f02bb5274f6 X-Filterd-Recvd-Size: 5305 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Fri, 8 Jan 2021 22:15:41 +0000 (UTC) Received: by mail-pj1-f43.google.com with SMTP id f14so4392562pju.4 for ; Fri, 08 Jan 2021 14:15:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=cPwxujGNNyOBnF0Vwn1tLQOHKm27c8aE8Qm8sfiISfM=; b=rI/GoBBGWlXF5JUC0/uPwoTcwobevsRYyKgkfhrgde/PuiIA7VM71TTPWx2an5anQ0 qP3a8g0ZYMtCczxBB+l/0bEOt+goxz88uiM9BRoP1eazMsil4IUXfVqOxTxyItzoE2WJ zpUhjuyTBJRSEslBe/YubfQ6h24QfaoFp3nwEBd28ascrg+EK+0WBe39JNDg4+QQXaIg MTI6n8R1EVdMFWGB74kNH4G/ctcN/hm0lIBglC18rNAJbshB8ktGt7giiftPldRWk2Qf MsTq4cwKOV00oLw2Ln/PMZZD8aQyjSnTCgFzAr/xew0GkKEhHs0pT4ia0p8smIlIBg2V mRcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=cPwxujGNNyOBnF0Vwn1tLQOHKm27c8aE8Qm8sfiISfM=; b=c7sN1t8hGN+GkO74vGsMlTg/GUB/LL6OTqPlrKKjp/H+AAPeXcpWAmZwGA15H8nnBR +4ofkqQVwjY+ZCAUWwTq2v18J6rwi80YF760Umc8wBVr4cdL/8Nl1H4oUkjsLYtzBqYl KBXqMcYWKeK29eN6MuDgOVzqCSJQzS6vWpdxSP2Y/UtrbwNhGFy9MN/xLfbE4L6OMcOK bt1mqPYgz3qJ125QcN74ZdEfp/HKta4kpSVrtkH/+4B7ummenfzyt6Xb54ywBWi9M53q ZO+GRhxnwXDn06G6XZOA+5mkhCec5NJpJReLgUmn6bgltLKYnmpxCQJgN41ameZdMPvD 2T8g== X-Gm-Message-State: AOAM5312TYhxtV1ib2fFwQOwm3sPUnUmSqfrpuFfiyahdighvFPxT79K NJZ0SmGW3jUHaZYUeWsxntA= X-Google-Smtp-Source: ABdhPJy4f4mlQgM559uJm1g1tPUPB7QKx9c6aaz7sIh4PCKsyofkc+Ulp6tDGlFc4DCvAuSUOc8NtA== X-Received: by 2002:a17:90a:6708:: with SMTP id n8mr5974485pjj.35.1610144140538; Fri, 08 Jan 2021 14:15:40 -0800 (PST) Received: from google.com ([2620:15c:211:201:7220:84ff:fe09:5e58]) by smtp.gmail.com with ESMTPSA id 77sm9968507pfv.16.2021.01.08.14.15.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 14:15:39 -0800 (PST) Date: Fri, 8 Jan 2021 14:15:37 -0800 From: Minchan Kim To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, jannh@google.com, keescook@chromium.org, jeffv@google.com, mhocko@suse.com, shakeelb@google.com, rientjes@google.com, edgararriaga@google.com, timmurray@google.com, linux-mm@kvack.org, selinux@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH 1/1] mm/madvise: replace ptrace attach requirement for process_madvise Message-ID: References: <20210108205857.1471269-1-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210108205857.1471269-1-surenb@google.com> 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 Fri, Jan 08, 2021 at 12:58:57PM -0800, 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. > > Signed-off-by: Suren Baghdasaryan It sounds logical to me. If security folks don't see any concern and fix below, Acked-by: Minchan Kim > @@ -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_task; mmput? > + } > + > total_len = iov_iter_count(&iter); > > while (iov_iter_count(&iter)) { > -- > 2.30.0.284.gd98b1dd5eaa7-goog >