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=-8.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL 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 7950AC10DCE for ; Tue, 10 Mar 2020 20:19:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 11BE622522 for ; Tue, 10 Mar 2020 20:19:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FTRhK5wR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 11BE622522 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 B75346B0005; Tue, 10 Mar 2020 16:19:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B24006B0006; Tue, 10 Mar 2020 16:19:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A622B6B0007; Tue, 10 Mar 2020 16:19:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0216.hostedemail.com [216.40.44.216]) by kanga.kvack.org (Postfix) with ESMTP id 8F1C46B0005 for ; Tue, 10 Mar 2020 16:19:49 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4C8969079 for ; Tue, 10 Mar 2020 20:19:49 +0000 (UTC) X-FDA: 76580568498.19.shop09_55ba16bf5a32b X-HE-Tag: shop09_55ba16bf5a32b X-Filterd-Recvd-Size: 5070 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Mar 2020 20:19:48 +0000 (UTC) Received: by mail-lf1-f45.google.com with SMTP id j15so12070209lfk.6 for ; Tue, 10 Mar 2020 13:19:48 -0700 (PDT) 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=Ph0vbxjhiVWxt5rg3nkX2vAEthsG0dcjm7RlaAwg098=; b=FTRhK5wRW+NRGmaoV4Ks4Odxss3oisU/sts3+fM0oGm2ippT+eDkr1IaNE6RESk+lr uP42CT/VBEM8RxZzRhXu7OdoPtl5ghIZEFU0Sv2IQsJ3dsb3HDE68bjkrG/0JEnJJzf0 h6OdM2SCHqYO8CccNpImf0UM6jUH0ewQIPYtbBJzBYWqxTlfX+DXwC0GZqRBGhDFShoh XCfYyNmsQDQ3gC5kkVw7Uuas1zPz/IW24F0I0iX7Q/Ik/pIlrdUPuv0Qa8NVg21pd4QD oVdancEdjuYHMTQh2nox/OksTwzF4NxKTaM0bkelHD5AejJfdXyGtde0aTBYJcvQlxAN WqKQ== 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=Ph0vbxjhiVWxt5rg3nkX2vAEthsG0dcjm7RlaAwg098=; b=kCoehm9MH25HtuTpeQuHiBrwP72/6Aj3rsvfze035WjNk5TpIUfv11OM4aJf3kgS7j hcAzgF7rc9WHNJ4cYWvkxCY1uzkQM4hS6P0r7Q4R9sZ4+w6DRfDFxdBG1fcdO56LFgf2 XHZaexBlq5uyUQNFhWpgzsJZpmrzN9Jj/h8rVVUMQrRQXcQ1AInjQnsd5JY2+2lm6mT2 aF0JdaRHQZmAueqa8aqerxHm41/qdIE22qNUXbhgi3onKEvv2Vm1+Kzr8Y/caDRuKYg/ Ei+cxOSWJBIUiVx6ujLKr4OONRvGL95/b/EKVwsRQ28AmkPMrAq7WmLBMA22CRgbKaiM dTtg== X-Gm-Message-State: ANhLgQ23Uw0/+FWSlGBOWLAfRUf08T5p+YZhdiBqB9eN73Cu5dmut/tb L/PCHcrzrpZ0Id9SBgtKOhVyd4jwvVVCKtt8YpvsnA== X-Google-Smtp-Source: ADFU+vtmwZqppStJchtpo+FXaK2zYi5y4NF4w2GV6ag8hGufCvRmr98qaLuzObauOhshhDxAZdF9relJA+CJ5k6OMUc= X-Received: by 2002:a05:6512:68a:: with SMTP id t10mr13869220lfe.126.1583871586843; Tue, 10 Mar 2020 13:19:46 -0700 (PDT) MIME-Version: 1.0 References: <20200310184814.GA8447@dhcp22.suse.cz> In-Reply-To: <20200310184814.GA8447@dhcp22.suse.cz> From: Daniel Colascione Date: Tue, 10 Mar 2020 13:19:09 -0700 Message-ID: Subject: Re: interaction of MADV_PAGEOUT with CoW anonymous mappings? To: Michal Hocko Cc: Jann Horn , Minchan Kim , Linux-MM , kernel list , Dave Hansen , "Joel Fernandes (Google)" Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Mar 10, 2020 at 11:48 AM Michal Hocko wrote: > > 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. I'm more worried about the performance implications. Consider libc.so's data section: that's a COW mapping, and we COW it during zygote initialization as we load and relocate libc.so. Child processes shouldn't be dirtying and re-COWing those relocated pages. If I understand Jann's message correctly, MADV_PAGEOUT would force the pages corresponding to the libc.so data segment out to zram just because we MADV_PAGEOUT-ed a single process that happened to use libc. We should leave those pages in memory, IMHO.