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=-1.0 required=3.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 AD3D9C10F27 for ; Tue, 10 Mar 2020 18:48:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7402820873 for ; Tue, 10 Mar 2020 18:48:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7402820873 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 EA0C86B0005; Tue, 10 Mar 2020 14:48:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E50086B0006; Tue, 10 Mar 2020 14:48:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D66446B0007; Tue, 10 Mar 2020 14:48:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0252.hostedemail.com [216.40.44.252]) by kanga.kvack.org (Postfix) with ESMTP id BC44C6B0005 for ; Tue, 10 Mar 2020 14:48:18 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7608A181AEF0B for ; Tue, 10 Mar 2020 18:48:18 +0000 (UTC) X-FDA: 76580337876.18.dad84_e4821a88391c X-HE-Tag: dad84_e4821a88391c X-Filterd-Recvd-Size: 4146 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Mar 2020 18:48:18 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id m9so8244252wro.12 for ; Tue, 10 Mar 2020 11:48:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=faj4Gnv3ao1AYalzRRSD4ZhnRIS4F6sDhppOSlAm8cg=; b=WyosYsWB+7MEarK6DcNS2w0TIF8Z88Jb9myc1r8sf3kfiPZ/rw2kvN+rZ5ZmOi2vmy U4fiUgFvzFCtr5pYMrZq/e4yUIvOAA2QZyoZ/6HZyFrUqrOJJF+THfCdkaSFz2jmyG7O JY5fyF9jBaFZx/GtqWRF7QVWL19UXqHjLk5Q9UHUYSFFuSLl3EBEpPvbq6HbIXQ9OmeH YytUEz8Mu7cuzXMLjlhVo8Cz/Ux9uNOqoZtPl6LqNTv74SEms2H3wJKyuzA/JVmVTW0O BuLERuIP+F9saVNNrx0KGxhEx5fp896lCPGV4pmzaHuQ2SpB601x/puSJsXvnt5rj6rY 3WFA== X-Gm-Message-State: ANhLgQ2i8jjE0wufNjcW7d3RvktbeKNxjDzkwJpF0Jjuga+t6auUhDUh DOIVd+bGrFoiklqljUs8QLI= X-Google-Smtp-Source: ADFU+vvvvXe3gYO63vIzXpyJejrK0vbmhPUZgnsZtDYuXrKXHRkybLQuppeHuZyOfjZbQ8Dub0Smcg== X-Received: by 2002:adf:e906:: with SMTP id f6mr2623231wrm.108.1583866097007; Tue, 10 Mar 2020 11:48:17 -0700 (PDT) Received: from localhost (ip-37-188-253-35.eurotel.cz. [37.188.253.35]) by smtp.gmail.com with ESMTPSA id w15sm2934119wrm.9.2020.03.10.11.48.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2020 11:48:16 -0700 (PDT) Date: Tue, 10 Mar 2020 19:48:14 +0100 From: Michal Hocko To: Jann Horn Cc: Minchan Kim , Linux-MM , kernel list , Daniel Colascione , Dave Hansen , "Joel Fernandes (Google)" Subject: Re: interaction of MADV_PAGEOUT with CoW anonymous mappings? Message-ID: <20200310184814.GA8447@dhcp22.suse.cz> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Bogosity: Ham, tests=bogofilter, spamicity=0.004259, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue 10-03-20 19:08:28, Jann Horn wrote: > Hi! > > >From looking at the source code, it looks to me as if using > MADV_PAGEOUT on a CoW anonymous mapping will page out the page if > possible, even if other processes still have the same page mapped. Is > that correct? > > If so, that's probably bad in environments where many processes (with > different privileges) are forked from a single zygote process (like > Android and Chrome), I think? If you accidentally call it on a CoW > anonymous mapping with shared pages, you'll degrade the performance of > other processes. And if an attacker does it intentionally, they could > use that to aid with exploiting race conditions or weird > microarchitectural stuff (e.g. the new https://lviattack.eu/lvi.pdf > talks about "the assumption that attackers can provoke page faults or > microcode assists for (arbitrary) load operations in the victim > domain"). > > Should madvise_cold_or_pageout_pte_range() maybe refuse to operate on > pages with mapcount>1, or something like that? Or does it already do > that, and I just missed the check? I have brought up side channel attacks earlier [1] but only in the context of shared page cache pages. I didn't really consider shared anonymous pages to be a real problem. I was under impression that CoW pages shouldn't be a real problem because any security sensible applications shouldn't allow untrusted code to be forked and CoW anything really important. I believe we have made this assumption in other places - IIRC on gup with FOLL_FORCE but I admit I have very happily forgot most details. [1] http://lkml.kernel.org/r/20190619132450.GQ2968@dhcp22.suse.cz -- Michal Hocko SUSE Labs