Received: by 10.192.165.156 with SMTP id m28csp2346648imm; Thu, 12 Apr 2018 12:44:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+tDW7/Skq6S1zD80qsofUva8+EiZGloFNAsuIkikphU6KHkXBJnIguTAkBF4nKUkc1UOsF X-Received: by 2002:a17:902:6d0f:: with SMTP id s15-v6mr2395628plk.241.1523562249354; Thu, 12 Apr 2018 12:44:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523562249; cv=none; d=google.com; s=arc-20160816; b=TDK/FPQBDzMVjBsckQWGwcO48BdS/BX9XRKMmTorYdFAcvRiQSg5VVC6TS35eP1kxe V572H4gZ343xZOVOZyz4oR6fXU/xS4MUzEwNiVsGfS4ULpxpfosfd/J2l/kb94IQ5SMM 8Zc8iJJ+DqjBS7yfJ3cGWvj6ZZKekApaKS5ER3C1odAb7YcoSFN6p+NEuvW/1Y3f3lPK PZuYBNaNmcfYfgvN5usGZeOZOKhVT9i/8xv1MpP+cb8QTpZFOFHEuaE4yTixM0YxDVVT qylutQAAk8AbZ4oz0FpictD92KDVttqlb3YdSAJh3YS2zajR/wcdXsAqJtIxHxdC3aL2 BXjA== 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:cc:dkim-signature :arc-authentication-results; bh=C7yyX6ost3eiMgxyWGi/LuyJs2Xjh4t9nAy1/JJWLOw=; b=mS74FRxKw/2bndooTHlcTTB/+XeDWArjXEdT1mp1tUp/cvSY+0h2tFGvjPPqQmYPU9 z1mEOa5I/aGmKxXy40647UWVNNUKc9gdQ20BdYqWrv6fivIjQ2fbZh15CaI5I/8tPPvO ZeT/Br98ArdMsvzALFJOfw7LAXpf1uV3K+a0msOO2CxU2T5Xe6dBzDuJoRV2SqFoGLe6 d0J2yWNg3NkPdC3ZzDrhtIkeqvNiI5XExs1RZNgqVHmZkWgekf0XuF5TPOU+xCeUxaUZ Y4SUidUZlUw4j7QRfG11BXE8HzCALMLROFzqxf9tJ56g8TdtLXNlF3DVMcmwFYKmMU7e IsBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HxYoPwIk; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3si2959854pff.312.2018.04.12.12.43.55; Thu, 12 Apr 2018 12:44:09 -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=@gmail.com header.s=20161025 header.b=HxYoPwIk; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753254AbeDLScr (ORCPT + 99 others); Thu, 12 Apr 2018 14:32:47 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:38710 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752937AbeDLScp (ORCPT ); Thu, 12 Apr 2018 14:32:45 -0400 Received: by mail-wm0-f65.google.com with SMTP id i3so86017wmf.3; Thu, 12 Apr 2018 11:32:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=cc:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=C7yyX6ost3eiMgxyWGi/LuyJs2Xjh4t9nAy1/JJWLOw=; b=HxYoPwIklx9DBC+gUTbKPZr14PIjiHvgY8c0d2Eh2YjEMDQgA6XQVAOTIPAqjkMl86 hCHzm0aavMJT256J95C1iyobltoqKI6MA5GxEsKToAvyenLb2dXRpB+4pAMJ9DE1b3MO h0eC05Mc5Lk7KAlZs0xcWe762tP5Y+rjL9jepRzrB1+UJRfrX9mk+BT33Wlh/apVQLxY ItAUSuyt3YF6pMWLKmlxqONcAhN8D3kydqUSEI6m1p9kZGEzuwdis6dWoath603Dan5v oJcaKzPhnHNL0xfVwuDeUe5LC7nK6uzTJryvHvaowgUoiqtzG5YhmaRVaFky9Xv93UR/ CgbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:cc:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=C7yyX6ost3eiMgxyWGi/LuyJs2Xjh4t9nAy1/JJWLOw=; b=e7DeYd+1K8So9hZwVYFmaP0kS8FZ+pYuaShcbdzDtUTUoRAijRvd42e9GhPuDXbeL/ QyvsH4IaVatsD4x4XxXNy3eIhmoqM7Neqc58jOiOGB5T4jeqDALSNc8aNc5uRYzxKFcE JlicL3kGebY/pCJ0oTURPt/OGM8cfvp5qdHI8ktoiFFzJ9XyAFJKfsCv0FaKMfzodpil +yqL+uvlhuM65R1hOBzmW3lDKIj7fI0wbSHmD7KfUGQDv5qwvjQOtq0DVsKrexh3+FTh JRhuO/W6RozpbTpHD4AdtwRrLNGDSAU/5JYKGgQgI8XfZnTDRZbkmqwnrGf13jI7XiQA ugjA== X-Gm-Message-State: ALQs6tDC7vV2Wh8JYpvo0QuDjQkdzBWMwl8d/kSvLNsy2KydJrizWIjb 2VYr6tlmggk7YfyMv7IFAvE= X-Received: by 10.28.12.17 with SMTP id 17mr1441919wmm.75.1523557964116; Thu, 12 Apr 2018 11:32:44 -0700 (PDT) Received: from ?IPv6:2001:a61:2419:8900:7ee9:d3ff:fef5:1a91? ([2001:a61:2419:8900:7ee9:d3ff:fef5:1a91]) by smtp.gmail.com with ESMTPSA id 67sm3528464wra.9.2018.04.12.11.32.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Apr 2018 11:32:43 -0700 (PDT) Cc: mtk.manpages@gmail.com Subject: Re: [PATCH] mmap.2: MAP_FIXED is okay if the address range has been reserved To: Jann Horn , linux-man@vger.kernel.org, mhocko@kernel.org, jhubbard@nvidia.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org References: <20180412153941.170849-1-jannh@google.com> From: "Michael Kerrisk (man-pages)" Message-ID: <3ff7472c-23c8-402b-ddfb-871a749c5016@gmail.com> Date: Thu, 12 Apr 2018 20:32:40 +0200 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: <20180412153941.170849-1-jannh@google.com> 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 Hello Jann, On 04/12/2018 05:39 PM, 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. > .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 ) > +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! Nice patch! Applied. Cheers, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/