From: Michal Hocko <mhocko@suse.com>
To: Zach O'Keefe <zokeefe@google.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
linux-api@vger.kernel.org, linux-kernel@vger.kernel.org,
Axel Rasmussen <axelrasmussen@google.com>,
James Houghton <jthoughton@google.com>,
Hugh Dickins <hughd@google.com>, Yang Shi <shy828301@gmail.com>,
Miaohe Lin <linmiaohe@huawei.com>,
David Hildenbrand <david@redhat.com>,
David Rientjes <rientjes@google.com>,
Matthew Wilcox <willy@infradead.org>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Peter Xu <peterx@redhat.com>,
Rongwei Wang <rongwei.wang@linux.alibaba.com>,
SeongJae Park <sj@kernel.org>, Song Liu <songliubraving@fb.com>,
Vlastimil Babka <vbabka@suse.cz>, Zi Yan <ziy@nvidia.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Arnd Bergmann <arnd@arndb.de>,
Chris Kennelly <ckennelly@google.com>,
Chris Zankel <chris@zankel.net>, Helge Deller <deller@gmx.de>,
Ivan Kokshaysky <ink@jurassic.park.msu.ru>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
Jens Axboe <axboe@kernel.dk>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Matt Turner <mattst88@gmail.com>,
Max Filippov <jcmvbkbc@gmail.com>,
Minchan Kim <minchan@kernel.org>,
Patrick Xia <patrickx@google.com>,
Pavel Begunkov <asml.silence@gmail.com>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Subject: Re: [PATCH mm-unstable] mm/madvise: remove CAP_SYS_ADMIN requirement for process_madvise(MADV_COLLAPSE)
Date: Tue, 2 Aug 2022 11:09:32 +0200 [thread overview]
Message-ID: <YujpzGKImMQsn8SM@dhcp22.suse.cz> (raw)
In-Reply-To: <20220801210946.3069083-1-zokeefe@google.com>
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 <zokeefe@google.com>
> ---
> 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
next prev parent reply other threads:[~2022-08-02 9:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-01 21:09 Zach O'Keefe
2022-08-02 9:09 ` Michal Hocko [this message]
2022-08-02 9:48 ` Zach O'Keefe
2022-08-02 12:04 ` Michal Hocko
2022-08-02 19:42 ` Zach O'Keefe
2022-08-04 17:46 ` Yang Shi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YujpzGKImMQsn8SM@dhcp22.suse.cz \
--to=mhocko@suse.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=axelrasmussen@google.com \
--cc=chris@zankel.net \
--cc=ckennelly@google.com \
--cc=david@redhat.com \
--cc=deller@gmx.de \
--cc=hughd@google.com \
--cc=ink@jurassic.park.msu.ru \
--cc=jcmvbkbc@gmail.com \
--cc=jthoughton@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linmiaohe@huawei.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mattst88@gmail.com \
--cc=minchan@kernel.org \
--cc=pasha.tatashin@soleen.com \
--cc=patrickx@google.com \
--cc=peterx@redhat.com \
--cc=rientjes@google.com \
--cc=rongwei.wang@linux.alibaba.com \
--cc=shy828301@gmail.com \
--cc=sj@kernel.org \
--cc=songliubraving@fb.com \
--cc=tsbogend@alpha.franken.de \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=ziy@nvidia.com \
--cc=zokeefe@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox