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,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 85AB7C10DCE for ; Tue, 10 Mar 2020 21:40:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 42532222C3 for ; Tue, 10 Mar 2020 21:40:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pVHbW9YK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 42532222C3 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 EBA446B0007; Tue, 10 Mar 2020 17:40:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E443B6B0008; Tue, 10 Mar 2020 17:40:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0AF06B000A; Tue, 10 Mar 2020 17:40:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id B22AE6B0007 for ; Tue, 10 Mar 2020 17:40:28 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 811538248047 for ; Tue, 10 Mar 2020 21:40:28 +0000 (UTC) X-FDA: 76580771736.13.cake99_3e50978430e31 X-HE-Tag: cake99_3e50978430e31 X-Filterd-Recvd-Size: 5644 Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Mar 2020 21:40:28 +0000 (UTC) Received: by mail-ot1-f50.google.com with SMTP id f21so14693787otp.12 for ; Tue, 10 Mar 2020 14:40:27 -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=30v28QZwvgciyeUbGcFniNwVinb7jSfmAcitW4ywOgw=; b=pVHbW9YKRfFKZADsnAMJUGWLLN4457YVQMmhbheWBFB3MwtHdAS3MmRJYpyKaJnsOb rFf6OXsUpkBbr5iDyWHykufITmHwEqrVNRlJqU63iuzLFlg1Z9MIRUH7UWE4GgLt0miz 5WTmAnuC4FApvZNx+enghhHzYN0PInrSX/8HNHkBs5vuFg6tkrFnlhEmj47EoYVX5IjP YOccE9PudP0FfqfHBvzgCI8LKHZgbRKKToWxImEyQlMGHTFJqk+EXMcAF0uDr+n5LQKg fy1W/aiXBgKwdLBhXziDEqmkP5FSQOg05yyWFYcle69NPG2P47ndKV1i5Wvpy21K2sEQ X47w== 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=30v28QZwvgciyeUbGcFniNwVinb7jSfmAcitW4ywOgw=; b=F6/Q4SzC4OQ1aYyG5mqg5WxmC5z30d1zKrH2ddMzwlufgYHokZTPoYxjytuq0cb5fE 8eJSx+v4OeAxxsyIQ6HkPAZoE69ND/aMUfEQ4eON/C8L+WrXEnd2WlP3Y6nMzHPw7C4e /5fWiMLuWCwuGFstCpACGgOwhyFIfVnJrNY7AJA+803u/TzR8Y33xlESwm0NeSSRDmnI j07Ziq7AyhZOGZyOwDS62jc0rMPxz09JI3oxRulFTi8E/eqZSEZQi6m1Rj5KZ/pHaJCR golNXOftw2ekqMUOgAI42dW+iR84kFsGAoV6DtScoPctTtpk90SnTgaUYQiZD0/Rpkcy Ec6g== X-Gm-Message-State: ANhLgQ1T4X0Uq7+U+ZFQ5W/PugJ1IdkCodv6P6CGBUgXSNcar3LgxIMt X7qpj14dWDjqrygzz0R8YtVfFsQjRYYQYNxZW/LXpw== X-Google-Smtp-Source: ADFU+vuwo43Am+Q4ZOSwVz+gheEF2PfMeUE0HNw3+JQ8rS3wiOXwG1aHHfvywTiOdtBznco4h3w5ww0CkXTuxEA/kKc= X-Received: by 2002:a9d:6654:: with SMTP id q20mr5592078otm.180.1583876427094; Tue, 10 Mar 2020 14:40:27 -0700 (PDT) MIME-Version: 1.0 References: <20200310184814.GA8447@dhcp22.suse.cz> In-Reply-To: From: Jann Horn Date: Tue, 10 Mar 2020 22:40:00 +0100 Message-ID: Subject: Re: interaction of MADV_PAGEOUT with CoW anonymous mappings? To: Daniel Colascione Cc: Michal Hocko , 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.016568, 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 9:19 PM Daniel Colascione wrote: > On Tue, Mar 10, 2020 at 11:48 AM Michal Hocko wrote: > > On Tue 10-03-20 19:08:28, Jann Horn wrote: > > > >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. Actually, the libc.so data section is a file mapping, so I think can_do_pageout() would decide whether the caller is allowed to force pageout based on whether the caller is the owner of (or capable over) libc (in other words, root, basically). But I think the bss section, as well as heap memory, could have pageout forced by anyone.