Received: by 10.192.165.156 with SMTP id m28csp2281372imm; Thu, 12 Apr 2018 11:35:10 -0700 (PDT) X-Google-Smtp-Source: AIpwx48TzWaNnCPqBtouXRQiD4saPZDdTfOjnj39QmWS1GhH8bLlUPbOLLnABOCzAkXvBUzbhTIr X-Received: by 2002:a17:902:69ce:: with SMTP id m14-v6mr2191256pln.358.1523558110106; Thu, 12 Apr 2018 11:35:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523558110; cv=none; d=google.com; s=arc-20160816; b=HK74800BIfjaSnjGk6C+7YUkmSpZA/XUGn+8esM9VjejYEHdBnOhEQY1IXePE91cK4 9Y/8TgKpU9AOwWHn/FreVA5KEsawjhs37kmAonCXTwEw7z1wvvci64nceRKvNwRENX5b gM7+lMhM5WOA8z2Ei0IyZQDy1QClJxD1gVs1kB7YwPbRV0MKRmN0qXGu/gg5sBCwUwcJ HhVdqf0p75/8IbcJ1T5xQHwdH+4zuR9c1xqlf1Jduj8Db/2qq1bfpJTeAfwuKDqUIiJO vhhhQRIFBUWOLIG+N04pkLeU62nWFgJMP4IhUAT4s9u/xuucM6pF2cKq334AoIilKEyo 1xuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:arc-authentication-results; bh=keYEIjFKlmUSg/GFBEfw5IwN6x21mY1RzrHMGxG8P7A=; b=qaX3+NyTjiO5OI/bcVW0srJJaVOQDgkJjgkEjBehXNUzKMcjMJ3LMJj9YOlbmsH+iG ZGMy2jl4SmlzxG3XtGIFoVgxGhC78s+hZvIzkpBV6EbWQZMw3wSFn/C3jbvlzJURgxn4 WAnJVNHVhiOwnL0MjU9AKnjxLJeK6s+XCcjwKBgrvN4OOtxvLyNuKikwtPwXmZD9rQWU 30fZI3Sv3M79i3mNMmtlBgrfacn/iQZ8r6t28FZqXN8hdkPWvlIKSIFYX2n6WYA6Sy4F xGa+5H1gMhXED6yXnRBOsPPjI/tzioesbEcvfv8BGTBxyxYzIoxUC8UScd2rw1u9/sBX AcAg== 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=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x24-v6si3971883pll.25.2018.04.12.11.34.55; Thu, 12 Apr 2018 11:35:10 -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=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753294AbeDLSdI (ORCPT + 99 others); Thu, 12 Apr 2018 14:33:08 -0400 Received: from hqemgate14.nvidia.com ([216.228.121.143]:12558 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753219AbeDLSdH (ORCPT ); Thu, 12 Apr 2018 14:33:07 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com id ; Thu, 12 Apr 2018 11:33:06 -0700 Received: from HQMAIL107.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Thu, 12 Apr 2018 11:32:56 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Thu, 12 Apr 2018 11:32:56 -0700 Received: from [10.110.48.28] (10.110.48.28) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 12 Apr 2018 18:33:04 +0000 Subject: Re: [PATCH] mmap.2: MAP_FIXED is okay if the address range has been reserved To: Jann Horn , , , , , , , References: <20180412153941.170849-1-jannh@google.com> X-Nvconfidentiality: public From: John Hubbard Message-ID: Date: Thu, 12 Apr 2018 11:33:04 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180412153941.170849-1-jannh@google.com> X-Originating-IP: [10.110.48.28] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/12/2018 08:39 AM, Jann Horn wrote: > Clarify that MAP_FIXED is appropriate if the specified address range has > been reserved using an existing mapping, but shouldn't be used otherwise. > > Signed-off-by: Jann Horn > --- > man2/mmap.2 | 19 +++++++++++-------- > 1 file changed, 11 insertions(+), 8 deletions(-) > > diff --git a/man2/mmap.2 b/man2/mmap.2 > index bef8b4432..80c9ec285 100644 > --- a/man2/mmap.2 > +++ b/man2/mmap.2 > @@ -253,8 +253,9 @@ Software that aspires to be portable should use this option with care, > keeping in mind that the exact layout of a process's memory mappings > is allowed to change significantly between kernel versions, > C library versions, and operating system releases. > -Furthermore, this option is extremely hazardous (when used on its own), > -because it forcibly removes preexisting mappings, > +This option should only be used when the specified memory region has > +already been reserved using another mapping; otherwise, it is extremely > +hazardous because it forcibly removes preexisting mappings, > making it easy for a multithreaded process to corrupt its own address space. Yes, that's clearer and provides more information than before. > .IP > For example, suppose that thread A looks through > @@ -284,13 +285,15 @@ and the PAM libraries > .UR http://www.linux-pam.org > .UE . > .IP > -Newer kernels > -(Linux 4.17 and later) have a > +For cases in which the specified memory region has not been reserved using an > +existing mapping, newer kernels (Linux 4.17 and later) provide an option > .B MAP_FIXED_NOREPLACE > -option that avoids the corruption problem; if available, > -.B MAP_FIXED_NOREPLACE > -should be preferred over > -.BR MAP_FIXED . > +that should be used instead; older kernels require the caller to use > +.I addr > +as a hint (without > +.BR MAP_FIXED ) Here, I got lost: the sentence suddenly jumps into explaining non-MAP_FIXED behavior, in the MAP_FIXED section. Maybe if you break up the sentence, and possibly omit non-MAP_FIXED discussion, it will help. > +and take appropriate action if the kernel places the new mapping at a > +different address. > .TP > .BR MAP_FIXED_NOREPLACE " (since Linux 4.17)" > .\" commit a4ff8e8620d3f4f50ac4b41e8067b7d395056843 > thanks, -- John Hubbard NVIDIA