Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2265152pxf; Sat, 20 Mar 2021 09:34:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0tSIqRYCnK+ztMB9iVOcZQI102brEXChcR9NabuUjAxsUkRHJK+TAIIKkDyIQktHj9HEr X-Received: by 2002:a05:6402:614:: with SMTP id n20mr16116041edv.58.1616258050528; Sat, 20 Mar 2021 09:34:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616258050; cv=none; d=google.com; s=arc-20160816; b=wkCddquY+icimXV1xXtIPXjAxbxCs2g/DIxp1h5zbMTorx51wJsz3gSYD9aGX05wq9 d27Hf92KRm5BDn1LcsV2eSicXmd843ZtdtR0heJyWlBhECwWw60fzrwPgjkjwew22UPg JcwF7iIT176b/339a5Czv/bGOZLHH0U8kiER7KW7NJu8Fv4L4q8KCDiQumlBK0dTVpeo 1F3Czq1Gd3PbTLE7qOwmY9Q4NmhvhVeIqGK+IVDX5fTh+nFN6Y+wi5ystKVBoYSPS8Ha DT/GnyajkvxmZaWmMSbnGQvAd0nhqjeW9GrS7ES8iv7W4smFNXCSxjHb9gVGL0h7U36c x/pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=DWquq0hhgEIwaW+K5iO20XklhRHjYZ3+k1kPDO3VbQ0=; b=TfQa3BwoU03/2SNMRVtupnT3KGtSlQRR/kroHyU/6AiwTZJrdx8xf3o8qw3x/tl1uy bRATYza53GKsfdN3QLHIQYb43LxPFETF4dnbJ8HtjnaMQnSA12KNTlg9C0m0rFh2XWEK 9f+8R+lbHs5V1RC7CuAWxdX+QfeXADOenfdIfIjWQ2Ob1I4y3W/XQSzmModE9a/cHz5z CFXBJFdM6rnnPoQoNYob6vLQ7Q4uywZbQOK10kSfWkhG5iNlX5wS6pITSOpWqGyR79SC nlaJW8w4N3QBTUc8dS1IwHDwIXJKi4ZVipSXEjsUOJ1VGciwtA2og/b+x9rVc90EMJlh vVzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=pdm+IlCZ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u19si7022846edo.583.2021.03.20.09.33.47; Sat, 20 Mar 2021 09:34:10 -0700 (PDT) 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=@linux-foundation.org header.s=korg header.b=pdm+IlCZ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229772AbhCTQcy (ORCPT + 99 others); Sat, 20 Mar 2021 12:32:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:49482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229780AbhCTQcj (ORCPT ); Sat, 20 Mar 2021 12:32:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5060161944; Sat, 20 Mar 2021 16:32:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1616257958; bh=Bl8G1B2SSUB12O7P9gYaeP6Qr+D8nLA7fC0tOMa56nM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=pdm+IlCZPt2t0IVKks5H0qWalupAigJeOR8ZAdo0+W1DtWi1KPYuepKOOZMfYbDEe N+Bbra1Ll95QtzAX7cTnuh58I/o3wtH6zyx9BIOprHyO+SL+XyKEkncKobqfKESA9v ZPjIFy3HrtIG4XT72bU5ZpWjtx6mNAgbcgAVBa1Q= Date: Sat, 20 Mar 2021 09:32:37 -0700 From: Andrew Morton To: Bui Quang Minh Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Peter Xu , Andrea Arcangeli , Axel Rasmussen Subject: Re: [PATCH] userfaultfd: Write protect when virtual memory range has no page table entry Message-Id: <20210320093237.c369eba59a0e5f452109c4ef@linux-foundation.org> In-Reply-To: <20210319152428.52683-1-minhquangbui99@gmail.com> References: <20210319152428.52683-1-minhquangbui99@gmail.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 19 Mar 2021 22:24:28 +0700 Bui Quang Minh wrote: > userfaultfd_writeprotect() use change_protection() to clear write bit in > page table entries (pte/pmd). So, later write to this virtual address > range causes a page fault, which is then handled by userspace program. > However, change_protection() has no effect when there is no page table > entries associated with that virtual memory range (a newly mapped memory > range). As a result, later access to that memory range causes allocating a > page table entry with write bit still set (due to VM_WRITE flag in > vma->vm_flags). > > Add checks for VM_UFFD_WP in vma->vm_flags when allocating new page table > entry in missing page table entry page fault path. This sounds like a pretty significant bug? Would it be possible to add a test to tools/testing/selftests/vm/userfaultfd.c to check for this? It should fail without your patch and succeed with it. Thanks.