Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2432840imn; Tue, 2 Aug 2022 02:36:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR62XZIJhvk05pM/DmcmPaSHtzioC/QTI3Pt2j5u+Ye+REP6ob3YyNc4aWMrt+1TynQLflPz X-Received: by 2002:a17:906:9be1:b0:730:957f:34a3 with SMTP id de33-20020a1709069be100b00730957f34a3mr4549198ejc.47.1659432980029; Tue, 02 Aug 2022 02:36:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659432980; cv=none; d=google.com; s=arc-20160816; b=Ob75LJ1aJMy8E6LKOOkUjl5u1tp67iAXxONXRvzSn/FFh/k/q9U/hZhQ1cVo1SAVVy JknPPbJoPsEfE7mF1L5JMfngRjqMEgUAXI64ce13SWzgPRxyYBbUhWJEfy1OByhm1wbi RWyCv/yEfNXqIIEkJoteA0rYVuHqP6lGiKKVVBFnQdotieHrPjdc0xf5Ykj+Lm9prR6y rJ47QhYQruZyYWSHQSZ6EICXdElhNf5ulUy7buR+hVG0/6Q2xEKl2dKCH1I8kL97Gm92 znCKv21PPsULLjMMyakp8QNpzza8+wfXCjbTML4f6IJPOPLPkRXRL5/Atr0n+Ad5TiLr TITw== 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=UkyokZQiUGgS32T7RwX35cBkz6mpMRTZP71cJgaHl4k=; b=yr+fYZ2TPaRkhNsgRBM177HvfyEx2lpjgQsY4w1Ni4pcjzZrZjftj+MHx51PZdO3n/ P9ZdKiiQ96H6FcQ6fN/Fu3kLVI6Aat/X+w8YFcPORTlrdCIRpUkoOolevEWoiU1SDwTN 5TxdzmX36qJFyQ3KVP3U/qbuKcIosfrnuu8i95XKuA4mMSfVW+FG9WgTwaK1jrvCvYEu zanWIFam/uWS7u7A++gjnwGIoql/te0z6TaU2P8gpAozcf2HhE/mcIWUaMTcn38bkZz+ XktJMf+VeDUQCtI7xwfQyZr2pDAFmrlpt9F1lzxXGnm3d4NrligbW8XUYdI2dB0eLTCh wYog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Bo7QfQt+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga31-20020a1709070c1f00b00730a539ac16si436281ejc.982.2022.08.02.02.35.55; Tue, 02 Aug 2022 02:36:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Bo7QfQt+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236130AbiHBJJj (ORCPT + 99 others); Tue, 2 Aug 2022 05:09:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233904AbiHBJJg (ORCPT ); Tue, 2 Aug 2022 05:09:36 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 119544B4A6; Tue, 2 Aug 2022 02:09:35 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B730920585; Tue, 2 Aug 2022 09:09:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1659431373; 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=UkyokZQiUGgS32T7RwX35cBkz6mpMRTZP71cJgaHl4k=; b=Bo7QfQt+FRw8GdAAowDqF5VitqqIwho89C+bfVzIEQpdEWQPxx5OvhU0d8iosWLLlXjQNt RN0v9VuCXrIG2/Aq3Kk24+Nqwly+MNLV3aWqAV4dlod5SwLgri5HraJyEmYM+/WvpJMFgP NRXcxqDlf3us08MYrOB/WwAIWdr98PY= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8AEF61345B; Tue, 2 Aug 2022 09:09:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id X37/IM3p6GKdXwAAMHmgww (envelope-from ); Tue, 02 Aug 2022 09:09:33 +0000 Date: Tue, 2 Aug 2022 11:09:32 +0200 From: Michal Hocko To: Zach O'Keefe Cc: linux-mm@kvack.org, Andrew Morton , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Axel Rasmussen , James Houghton , Hugh Dickins , Yang Shi , Miaohe Lin , David Hildenbrand , David Rientjes , Matthew Wilcox , Pasha Tatashin , Peter Xu , Rongwei Wang , SeongJae Park , Song Liu , Vlastimil Babka , Zi Yan , Andrea Arcangeli , Arnd Bergmann , Chris Kennelly , Chris Zankel , Helge Deller , Ivan Kokshaysky , "James E.J. Bottomley" , Jens Axboe , "Kirill A. Shutemov" , Matt Turner , Max Filippov , Minchan Kim , Patrick Xia , Pavel Begunkov , Thomas Bogendoerfer Subject: Re: [PATCH mm-unstable] mm/madvise: remove CAP_SYS_ADMIN requirement for process_madvise(MADV_COLLAPSE) Message-ID: References: <20220801210946.3069083-1-zokeefe@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220801210946.3069083-1-zokeefe@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hasn't this been discussed during the MADV_COLLAPSE submission? What has changed? Does this need more time to settle with the consensus? On Mon 01-08-22 14:09:46, Zach O'Keefe wrote: > process_madvise(MADV_COLLAPSE) currently requires CAP_SYS_ADMIN when not > acting on the caller's own mm. This is maximally restrictive, and > perpetuates existing issues with CAP_SYS_ADMIN. Remove this requirement. > > When acting on an external process' memory, the biggest concerns for > process_madvise(MADV_COLLAPSE) are (1) being able to influence process > performance by moving memory, possibly between nodes, that is mapped > into the address space of external process(es), (2) defeat of > address-space-layout randomization, and (3), being able to increase > process RSS and memcg usage, possibly causing memcg OOM. > > process_madvise(2) already enforces CAP_SYS_NICE and PTRACE_MODE_READ (in > PTRACE_MODE_FSCREDS mode). A process with these credentials can already > accomplish (1) and (2) via move_pages(MPOL_MF_MOVE_ALL), and (3) via > process_madvise(MADV_WILLNEED). > > process_madvise(MADV_COLLAPSE) may also circumvent sysfs THP settings. > When acting on one's own memory (which is equivalent to > madvise(MADV_COLLAPSE)), this is deemed acceptable, since aside from the > possibility of hoarding available hugepages (which is currently already > possible) no harm to the system can be done. When acting on an external > process' memory, circumventing sysfs THP settings should provide no > additional threat compared to the ones listed. As such, imposing > additional capabilities (such as CAP_SETUID, as a way to ensure the > caller could have just altered the sysfs THP settings themselves) > provides no extra protection. > > Fixes: 7ec952341312 ("mm/madvise: add MADV_COLLAPSE to process_madvise()") > Signed-off-by: Zach O'Keefe > --- > mm/madvise.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/mm/madvise.c b/mm/madvise.c > index f9e11b6c9916..af97100a0727 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -1170,16 +1170,14 @@ madvise_behavior_valid(int behavior) > } > } > > -static bool > -process_madvise_behavior_valid(int behavior, struct task_struct *task) > +static bool process_madvise_behavior_valid(int behavior) > { > switch (behavior) { > case MADV_COLD: > case MADV_PAGEOUT: > case MADV_WILLNEED: > - return true; > case MADV_COLLAPSE: > - return task == current || capable(CAP_SYS_ADMIN); > + return true; > default: > return false; > } > @@ -1457,7 +1455,7 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, > goto free_iov; > } > > - if (!process_madvise_behavior_valid(behavior, task)) { > + if (!process_madvise_behavior_valid(behavior)) { > ret = -EINVAL; > goto release_task; > } > -- > 2.37.1.455.g008518b4e5-goog -- Michal Hocko SUSE Labs