Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2940313imm; Thu, 24 May 2018 19:30:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpwvHql6Qb/qdYlDjUmzW2rffj7AP1SROR8FxfUMt2x773RQhn9om3Gqr+MOxi/euGEwQ3/ X-Received: by 2002:a65:410d:: with SMTP id w13-v6mr435039pgp.111.1527215449353; Thu, 24 May 2018 19:30:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527215449; cv=none; d=google.com; s=arc-20160816; b=QcwR94ITVhPdNDZ7kth2n7qmLnynqvFjHVLKGyXeUQOdRF8Drq6jxj9MBhFxORebeC wChGimB0PFhTMStqGKCyF74MX+sEolarsin3OsIqk4tru3Dj3GyDS3wh9/x8u/qSgjgF jEZfvlnUF6Tgd7orwHWFKyMnH5o87+fwmg/m9tkyWK5P6NxkIC5IFsFjyFhqmc9JKJbc w+1+PoIsItMjDMty2BDMrgNbHRxm27YyGxcgifb8Lojx3Q3Yus9kqWgYXOa8Jkn1w+OL UuQoaW1wUD3RJLKql+xegCpBY/GYIK5JGCAAMDXmv+EDj9V5+an7WHstz1QkpRd77GwS Myfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:arc-authentication-results; bh=J5Xrx+3Is4SXc816IPs18fn7FMB6sSUI3z3IWW0t3wM=; b=HHFPQc4d+e2PY5rvi5sZBfZc0FkbAe8an53m/hV/g0633rz5518LJA1GZ08EqR/VTX dGAVVHSuZQ1JRwxPvvKYlOBr1KiyDIepj15fIC1uk708k0GD9kBz+YFK/YjpH+9NftgS zBxe4dfJ2lr1CvxhyQYIMcmyPPoE+UQ5K6DVvl/YtddTpsZjp4vjZjDrRyMPH7/VpSSa 339FSPYKzfUcSWRORdUwkoTUyCr6KNsrI+ATxr1y52WswQliZZwhMMNQ+S8v8FCQzBGd 184/L2AGc9z5Qg4KCypYkmS9N088eJmOmrDCQWD3IGqiiIZyyHlYr29YTiGBG1LJ4aNJ At1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=XDwAPWYS; 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=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t12-v6si18062644pgr.690.2018.05.24.19.30.34; Thu, 24 May 2018 19:30:49 -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; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=XDwAPWYS; 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=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033798AbeEXQkR (ORCPT + 99 others); Thu, 24 May 2018 12:40:17 -0400 Received: from mail-ve1eur01on0125.outbound.protection.outlook.com ([104.47.1.125]:20064 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1031968AbeEXQkP (ORCPT ); Thu, 24 May 2018 12:40:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J5Xrx+3Is4SXc816IPs18fn7FMB6sSUI3z3IWW0t3wM=; b=XDwAPWYSvbr/AB/aYTLROoYzqRkpvqgZpbScOBYZIgD9HkkMFFlBvBCBA+GLQsUJGEtrxjRqV4BOarmxGhC4SfNWmYpc7m33Zrh00F0eT1e5KvRmvDcxuWnNDXIhIkc9ZMq0LHq6Dzbx6uLBAWA8Y4l1jub7779SBrGux3L683k= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=xemul@virtuozzo.com; Received: from [172.16.24.160] (195.214.232.6) by AM6PR08MB2983.eurprd08.prod.outlook.com (2603:10a6:209:44::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.797.11; Thu, 24 May 2018 16:40:11 +0000 Subject: Re: [PATCH] userfaultfd: prevent non-cooperative events vs mcopy_atomic races To: Mike Rapoport Cc: Andrew Morton , linux-mm , lkml , Andrea Arcangeli , Mike Kravetz , Andrei Vagin References: <1527061324-19949-1-git-send-email-rppt@linux.vnet.ibm.com> <0e1ce040-1beb-fd96-683c-1b18eb635fd6@virtuozzo.com> <20180524115613.GA16908@rapoport-lnx> From: Pavel Emelyanov Message-ID: Date: Thu, 24 May 2018 19:40:07 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180524115613.GA16908@rapoport-lnx> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1P191CA0010.EURP191.PROD.OUTLOOK.COM (2603:10a6:3:cf::20) To AM6PR08MB2983.eurprd08.prod.outlook.com (2603:10a6:209:44::24) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(2017052603328)(7153060)(7193020);SRVR:AM6PR08MB2983; X-Microsoft-Exchange-Diagnostics: 1;AM6PR08MB2983;3:ULf8hinfFooI4mOOiEfwH2HHwSkvG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9Le23uDyime8iPuuYIV51JW8leiFKE0rd9llPo3Po4R6aYmJfrw6kM4HK23lfln6Yd5frDYY97lJgJFEcKm9NqEcSaQwoNHofzu1yr6Z/WbYw5LWgiCjLmcu7QQbwpWvcmYAnIBf0Wlu5vcGFWLpZmv8F90LPiYsFO/04UEOV2GevYQgicYNeMqSdw8x3vYR7SNb+wHE3a/UP9Q7f4l0eGiVEOd0IG8exXktvHN9lL+07R0NSUIHPy8bhDlTDLTUI7gDVCLH7dNM894Cpb8mOSxXy/1jNXRimztSbd4aCnfz+vOt;4:3LoxGo2ox1mQYfD466JIgBlAu2TCnA5awqQIBLUflRbtVV1djZVyt56+3Uwg4Kvf2vTZSn4RlNheyCFiTmmGXDpK+U48bQh2d2vm9npXwPQtEj/c3LSF2a84WlQctdOW/K3NVsA51Y9J0CbWS+bw/jmJBZWzCHX8oLHMm/9WfZ6WscFJ1oUQ4ycykNHqJBoVq5u3Y+tBXPnhKJrLX/rAsq8a+49EAUvylMLaaPjrVoUt3e9pfKakVCAehUd/zD0VnMb1AMgUXLZrVfXtbJb8vQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(3002001)(3231254)(944501410)(52105095)(93006095)(93001095)(10201501046)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016);SRVR:AM6PR08MB2983;BCL:0;PCL:0;RULEID:;SRVR:AM6PR08MB2983; X-Forefront-PRVS: 0682FC00E8 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6049001)(346002)(376002)(396003)(366004)(39850400004)(39380400002)(189003)(199004)(229853002)(6486002)(25786009)(478600001)(50466002)(107886003)(97736004)(4326008)(6246003)(53936002)(64126003)(54906003)(16576012)(316002)(58126008)(59450400001)(31696002)(26005)(77096007)(6666003)(65806001)(2906002)(66066001)(65956001)(386003)(6916009)(3846002)(6116002)(68736007)(106356001)(31686004)(105586002)(36756003)(8676002)(81156014)(8936002)(81166006)(52116002)(65826007)(52146003)(2486003)(476003)(2616005)(956004)(11346002)(446003)(305945005)(486006)(7736002)(23676004)(5660300001)(230700001)(53546011)(47776003)(16526019)(86362001)(76176011)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM6PR08MB2983;H:[172.16.24.160];FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtBTTZQUjA4TUIyOTgzOzIzOnhTZnlqMzQ2RWRURmNXejBPV0lBNVdWNnhz?= =?utf-8?B?WVFaV0ROVzlCd21SbkJuak1mZkZIUWpUS2JiRER3c0tRTUVRTUlFd2txNkky?= =?utf-8?B?aFYwMWxRZ3ZCRGJLaHNSU0tVRFJvbjkyZUpjVmtRVU5xVkNiMkZyaHJWaUQz?= =?utf-8?B?d1J5ZjEySnFodE4xVUZBVXZxbENyTDhWT2o2STRFaTVhanY1WkplVTJsMUVu?= =?utf-8?B?bDVHeXZsVTV1OGNPdDM4Q2FKMDFRVFFjQklUNnM0NWNIWEJrYy9rK0I2Tk8v?= =?utf-8?B?YVVqekNDLzBzWVNUcnArZHdKWGFBNVh1aTBKTmdKam1GMXN5cG1tbExWQkIw?= =?utf-8?B?RkZOSVZkd1BIQmxqNWxhVHVuaDRQRWE3VHp3bWE2R2gwV3B4cEs2Y01jQXJq?= =?utf-8?B?cjZXelIrcXU5SzJielRvM2RUSTVnb016K1lvSUkrUWZQV0pTNXhzM2d5TkdX?= =?utf-8?B?aWpGelBTdm05RG1TRnJNRkpZOC9nanFZclp5aXVSMThwYzIwaDI3SFphdXE0?= =?utf-8?B?S3BTSzQrMmtXb0tnYW1OakNoeWNpOWVFMjhoM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jLCo2p5ozN3r0jeyPvR7T5K8djkuMF9F9nWyDd0UEu8= X-MS-Office365-Filtering-Correlation-Id: fc404747-3f06-49b5-9e31-08d5c1950501 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2018 16:40:11.5448 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc404747-3f06-49b5-9e31-08d5c1950501 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB2983 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/24/2018 02:56 PM, Mike Rapoport wrote: > On Thu, May 24, 2018 at 02:24:37PM +0300, Pavel Emelyanov wrote: >> On 05/23/2018 10:42 AM, Mike Rapoport wrote: >>> If a process monitored with userfaultfd changes it's memory mappings or >>> forks() at the same time as uffd monitor fills the process memory with >>> UFFDIO_COPY, the actual creation of page table entries and copying of the >>> data in mcopy_atomic may happen either before of after the memory mapping >>> modifications and there is no way for the uffd monitor to maintain >>> consistent view of the process memory layout. >>> >>> For instance, let's consider fork() running in parallel with >>> userfaultfd_copy(): >>> >>> process | uffd monitor >>> ---------------------------------+------------------------------ >>> fork() | userfaultfd_copy() >>> ... | ... >>> dup_mmap() | down_read(mmap_sem) >>> down_write(mmap_sem) | /* create PTEs, copy data */ >>> dup_uffd() | up_read(mmap_sem) >>> copy_page_range() | >>> up_write(mmap_sem) | >>> dup_uffd_complete() | >>> /* notify monitor */ | >>> >>> If the userfaultfd_copy() takes the mmap_sem first, the new page(s) will be >>> present by the time copy_page_range() is called and they will appear in the >>> child's memory mappings. However, if the fork() is the first to take the >>> mmap_sem, the new pages won't be mapped in the child's address space. >> >> But in this case child should get an entry, that emits a message to uffd when step upon! >> And uffd will just userfaultfd_copy() it again. No? > > There will be a message, indeed. But there is no way for monitor to tell > whether the pages it copied are present or not in the child. If there's a message, then they are not present, that's for sure :) > Since the monitor cannot assume that the process will access all its memory > it has to copy some pages "in the background". A simple monitor may look > like: > > for (;;) { > wait_for_uffd_events(timeout); > handle_uffd_events(); > uffd_copy(some not faulted pages); > } > > Then, if the "background" uffd_copy() races with fork, the pages we've > copied may be already present in parent's mappings before the call to > copy_page_range() and may be not. > > If the pages were not present, uffd_copy'ing them again to the child's > memory would be ok. Yes. > But if uffd_copy() was first to catch mmap_sem, and we would uffd_copy them > again, child process will get memory corruption. You mean the background uffd_copy()? But doesn't it race even with regular PF handling, not only the fork? How do we handle this race? -- Pavel