Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp967664ybh; Tue, 10 Mar 2020 11:49:22 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvSqt8y11Md897c2UXuAawbOLjNdHHSqkgKhc2ODWGchCZiAM5VuXO6c7Y4iosfQgJGBaom X-Received: by 2002:aca:b9c2:: with SMTP id j185mr2142849oif.112.1583866162813; Tue, 10 Mar 2020 11:49:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583866162; cv=none; d=google.com; s=arc-20160816; b=gcMwmgj78tBpc0WI2vjuwDIUrsI0Q8hGzqESo18Ez02kdmwHswEJw8TqHkxbuQKGYd gPEBGcxJPa0Fs7DNCzJ/YhFiFwIl5oJIsKuGc8WnDXxg2u5geucwHhFH90kSiS+TIfAM Izu+T+D20QCej5kDhCzvAWqse9A3/WYbVl5joyiAV8lUxRadMT36xWX8UMvB0BYGhCx6 mcVJGcKDU4Qb8AfOENWbV+N0rctKSf2GUulKwTmPdsMJGDqxwEXiKkIaMABGYRmUv0Y2 ll1fhic+H9k4QZ4/nNEAMF2ScumT8b7CbFxtvQE9lDOf/zaqRLQZuJTZGVd8iUfyvsZ0 T86Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=faj4Gnv3ao1AYalzRRSD4ZhnRIS4F6sDhppOSlAm8cg=; b=nlIuwe3OGakrXdl7Bpeii78kAxkMD96C0yVG+iv6ymou42dDxi39KbsDpzGefO6suT gh9w6KvWWy4mlCRclf57ddqTZ+BGwa6d9Dtz11FpAtbND1b1//BOj2Yf7D1W5UrMQLfP GBX4iVl2q5n/5jh0LU2YV1KuHGhUQgYyttHE4v2NqjbYFXA+ES85YXwBpFBl2nten3U2 aYSFoHqe1HaXt8/KxmqKpzj2EZbhKiwknsGKD0kYZhLaykf5Ord2l0YV04v3orXeCNjf saF1ww96IIDJFlAZa3+s39kVxe8iBcpJ9SelhVVLa9Kv6Aqkkdfdgq261aJSJO+rDSX+ 3yUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k11si2184230oik.241.2020.03.10.11.49.10; Tue, 10 Mar 2020 11:49:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727385AbgCJSsU (ORCPT + 99 others); Tue, 10 Mar 2020 14:48:20 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35786 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726546AbgCJSsU (ORCPT ); Tue, 10 Mar 2020 14:48:20 -0400 Received: by mail-wr1-f68.google.com with SMTP id r7so17276989wro.2 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=S9TRnxeKkA43VAS0Qykppksx1pmQ7QLn1qgc2Y4KfwWEQnVYQw5B2ZyBfy3giegCVM 6mj/TwtxgMHlMAmr1/SdywooC2TZN1RfB8kx9T1fl4ssYj9YuRcDr/+MNiY4qMOasATo OiyXAKLBlbbkdjihmvfor4bGEXzOZU86wCtuoYfDc8537Y5qREHTkdYm/40/31aT79Bm vpXsJrNu2IGttKYP/07vMtxu1uCQBXWa7rksl8DFFhGwgYwKQhI63Q6WYy3GzwlG9CRE DU0HWp+dKnLWhctkINkiuOM1g2zn9sLDlQv5bLKtq3IHRUj+64Tfwa8p6+cN4uouJ/3N ilBw== X-Gm-Message-State: ANhLgQ2NdVrpLlKoqYZnABqhliCRqosKBA6CFxWxJrDMqrN4OUrjUI15 0VQgAxHJ5RBypS/mveLlCxMTYlAV/I8= 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: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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