Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3304683pxu; Sat, 19 Dec 2020 21:11:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYsP520o+xTFvO0ZdTzaJPsF05Rtv3afvZY9/ZLy+5GxYec1Tx10aQLZ+7OeFoiJ/E+4Sl X-Received: by 2002:a17:906:3949:: with SMTP id g9mr10366496eje.493.1608441117540; Sat, 19 Dec 2020 21:11:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608441117; cv=none; d=google.com; s=arc-20160816; b=CrPPduTSaTaUmqrSECckCLJo0+9Xhkfom5sjSWlDVuolXkehIwt6KaWnEPaLUj4WTW VgFP5fVn93WRxlXA8U1m01PETWfvxgcEIZpdK+fG9iOBXWN5RdVso2zMSHBn7GY4btbB dFZY42CfoW9ExnIM5eedfncDAwDzsmDSL8w8rcv5btTVxIN/jAD2eM2opUzDtH4SVsHX iS8WY9Gkod2V7SOmLqnrzBBzrMghCQs7BRkhFIWFYPv9Z2cOOw0xyaAaxBhsqH1eE3Ak 2acRnGb1XP3nwe5NqxfAaDl1jodysns9uc7Tx4KqWR8zl1ya4HkmfypsmecsfvqsXPN1 eKpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=4psQ539gSdUCJx7REDun4KViWJMtLK5GdpAKcpcDaS8=; b=oL+1EpzeXR1VgfrZRcaFG5xrFpKDEH7MEIbgKNeyF+yuvoMa0dppLnY7n0BS3r/k/K +6090tAUKo4XGA6S+wkw4MeqHQQ36cnIF4izigaPHEzwg5Yz1yia2sPolVwc/jxaGo9I ySsXb41Lic2r39R9lI+oTKXv2HqrKZX84poc1nQXrT/+W2PIwRvMz+LA8w6qO5QqkVPF UJKL85yjSzM/FQrEh2kf2TmP5spqEavwrfQlUhIF9DKIHxfpqZvUROUqB2vLVu+mScS8 tYH8M97v/lwwkGNEdPt7v1dIR4meL8+5AXlNWRqYj/zlY5tQv3UAUIa3MH5upEm71op/ LDhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="T/epbYFY"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r9si7494676ejb.246.2020.12.19.21.11.22; Sat, 19 Dec 2020 21:11:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="T/epbYFY"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726304AbgLTFJt (ORCPT + 99 others); Sun, 20 Dec 2020 00:09:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:39238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725929AbgLTFJs (ORCPT ); Sun, 20 Dec 2020 00:09:48 -0500 X-Gm-Message-State: AOAM532QemnG3fs4GBpPIR01pNobjeejCRjTn0PDPdztfor2ivbltfoq ja18JYOl8ptgazsq9IkF6LpblSID0B5iBX4JkTSNOA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1608440948; bh=GNcHtmmK5oaVHaZAxSYIqYGpmWW61XjeRJLDrDtv2VI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=T/epbYFYuycN0qKI9D1avY2WbZqHTdNEyWd0n+45yZ+ZrgTeKIf4qwe4wRec+1cbZ EUq3Cm3p+vNfq+0qmde90fCRwzvqopBgFPssOVNikkmMZLrnMWpM8jz41NRm7UzJhO grzi98MO+nrmOBIUeCvz/x449p/xPnxPXyL1fY9NB6Wuwk7/RIANbGyO0VWe4QR/vu gzetq+3WDKTw743MVuGIImcnzj2j0egswYC/ZksOeh6p63rREFnkJ35qRrQ/WvBIPO MFYgZHSaE256ZjoEFpunCatVrHTuUGaKfE/mykdjvfpL5UHkqiTa4dUUKAaGTKf6K5 KEO2HdQnp+3Kw== X-Received: by 2002:adf:e64b:: with SMTP id b11mr11996469wrn.257.1608440946397; Sat, 19 Dec 2020 21:09:06 -0800 (PST) MIME-Version: 1.0 References: <20201219043006.2206347-1-namit@vmware.com> In-Reply-To: From: Andy Lutomirski Date: Sat, 19 Dec 2020 21:08:55 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] mm/userfaultfd: fix memory corruption due to writeprotect To: Andrea Arcangeli Cc: Andy Lutomirski , Nadav Amit , Dave Hansen , linux-mm , Peter Xu , lkml , Pavel Emelyanov , Mike Kravetz , Mike Rapoport , stable , Minchan Kim , Yu Zhao , Will Deacon , Peter Zijlstra Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Dec 19, 2020 at 6:49 PM Andrea Arcangeli wrote: > > On Sat, Dec 19, 2020 at 06:01:39PM -0800, Andy Lutomirski wrote: > > I missed the beginning of this thread, but it looks to me like > > userfaultfd changes PTEs with not locking except mmap_read_lock(). It > > There's no mmap_read_lock, I assume you mean mmap_lock for reading. Yes. > > The ptes are changed always with the PT lock, in fact there's no > problem with the PTE updates. The only difference with mprotect > runtime is that the mmap_lock is taken for reading. And the effect > contested for this change doesn't affect the PTE, but supposedly the > tlb flushing deferral. Can you point me at where the lock ends up being taken in this path? I apparently missed it somewhere. > Anyway to wait the wrprotect to do the deferred flush, before the > unprotect can even start, one more mutex in the mm to take in all > callers of change_protection_range with the mmap_lock for reading may > be enough. I'll read the code again tomorrow.