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.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 90691C433DB for ; Wed, 23 Dec 2020 22:34:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0B1F7223E0 for ; Wed, 23 Dec 2020 22:34:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0B1F7223E0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 501FC8D0055; Wed, 23 Dec 2020 17:34:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B25A8D0026; Wed, 23 Dec 2020 17:34:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C7A48D0055; Wed, 23 Dec 2020 17:34:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id 1E7D48D0026 for ; Wed, 23 Dec 2020 17:34:14 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id CA1A1181AEF23 for ; Wed, 23 Dec 2020 22:34:13 +0000 (UTC) X-FDA: 77626001586.08.alley11_6212c252746c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id B01E51819E769 for ; Wed, 23 Dec 2020 22:34:13 +0000 (UTC) X-HE-Tag: alley11_6212c252746c X-Filterd-Recvd-Size: 2638 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Dec 2020 22:34:13 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 2FB7422286; Wed, 23 Dec 2020 22:34:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1608762852; bh=QfEyV6AON9eZHCWPJGH08UrQUE92QqJHlb3DQgGNheM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=kIjaSIEQ6iepTIJQTdMOTY7PlAXu7uvCJGWdD8Sub/WiFj9yUz/3IYhGRI9Iex3II ehvcpf+Ki04kwhvTul0waK72A4AZ4QFV5w9sVBAFrUy7yqson8ekmCR4EJG+7Pd9GS BTUatvYkFZpDl04xjxiotkJ03JgIBhtosblsVgGQ= Date: Wed, 23 Dec 2020 14:34:11 -0800 From: Andrew Morton To: Peter Collingbourne Cc: Kostya Kortchinsky , linux-mm@kvack.org Subject: Re: [PATCH] mm: improve mprotect(R|W) efficiency on pages referenced once Message-Id: <20201223143411.e889bcad32e5a1c0252c745c@linux-foundation.org> In-Reply-To: <20201212053152.3783250-1-pcc@google.com> References: <20201212053152.3783250-1-pcc@google.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, 11 Dec 2020 21:31:52 -0800 Peter Collingbourne wrote: > In the Scudo memory allocator [1] we would like to be able to > detect use-after-free vulnerabilities involving large allocations > by issuing mprotect(PROT_NONE) on the memory region used for the > allocation when it is deallocated. Later on, after the memory > region has been "quarantined" for a sufficient period of time we > would like to be able to use it for another allocation by issuing > mprotect(PROT_READ|PROT_WRITE). > > Before this patch, after removing the write protection, any writes > to the memory region would result in page faults and entering > the copy-on-write code path, even in the usual case where the > pages are only referenced by a single PTE, harming performance > unnecessarily. Make it so that any pages in anonymous mappings that > are only referenced by a single PTE are immediately made writable > during the mprotect so that we can avoid the page faults. > I worry that some other application out there does a similar thing, but only expects to very sparsely write to the area. It will see a big increase in mprotect() latency. Would it be better to implement this as a separate operation, rather than unconditionally tying it into mprotect()? Say, a new madvise() operation?