Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4544480rwl; Mon, 3 Apr 2023 06:33:04 -0700 (PDT) X-Google-Smtp-Source: AKy350Zhd2/yiWNx9H2I9UONA/YoblUpZNaWHWw+bSjPQ9uIey+owE9xJGW9TRua6nr85R4sBmDk X-Received: by 2002:a17:906:b159:b0:93d:b767:9fea with SMTP id bt25-20020a170906b15900b0093db7679feamr33417037ejb.31.1680528783940; Mon, 03 Apr 2023 06:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680528783; cv=none; d=google.com; s=arc-20160816; b=pMo5EwDdukvo8VcuxmwoNpqkMp1YYznoSeg6fQIU9FCWZIKPODUOU9sYD/WfuOoYhs pvsLzH67F0O/5sTMng99oZdGUWAu7H6iWAbbmFYyfebt0/pIvRi1lHeJXg+qE2BE6FLC TQamQZzIuOixxF7xfdT1akh636yCt7ig90NZEIO5VE3x/GB815vOt2tSwZqWhvQpR4Hm NhaKRk0nOtIf8nYOjvrISZpaSR6GzJdfW7uH2lPZoIqFCvyPFaaENRoxLyMrtUVOVlXr /oUN4bp9QJJeWNOT6a79J81KYpELNEQhU6BokNNDVUEKc0bxo0EbeEXJ1fookNrdTCYn 4D+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=QFh2Qzhmxh/G7C5fjFWTwiJiilCSTiKC1fL8nFAOZyk=; b=FeyDbE08jASwaw6/d83WukUloQhpheqK1RqmNMbTk3UP+h5PUQNmeb3DEd92msTL1D 8d0eTXfklcY29Bx1SViHGakYPr/+QIl9gH0pRG5bYRC7kH+xAZQys9pNcS/jmWQIWzvn IJlIneFPE1GDvPk+1sHCiiM992PK5UuvDE/6AuLHO1PZxJIozg1wWIO4KOAKrIy944ag 8m2A60nKuSYUBD6+CXMTVYoFHcAKjAw/biRpAN9UvE7My2z9UaGtcUti9f+BtfSNaLN8 Ov+pb4cnGDwk8xQ1Ya/0Fp+O5aqI2q5WPHVwd3xZ+swDRnncQvle/hYSdEh7EoziIeMi MkIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=JAoQkerD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c15-20020a056402120f00b0050202f2c2f7si6707579edw.424.2023.04.03.06.32.31; Mon, 03 Apr 2023 06:33:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=JAoQkerD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231958AbjDCNcB (ORCPT + 99 others); Mon, 3 Apr 2023 09:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232559AbjDCNb7 (ORCPT ); Mon, 3 Apr 2023 09:31:59 -0400 Received: from forward501c.mail.yandex.net (forward501c.mail.yandex.net [178.154.239.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 028C2A4 for ; Mon, 3 Apr 2023 06:31:57 -0700 (PDT) Received: from mail-nwsmtp-smtp-production-main-33.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-33.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:2016:0:640:1006:0]) by forward501c.mail.yandex.net (Yandex) with ESMTP id DE4535EF50; Mon, 3 Apr 2023 16:31:55 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-33.iva.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id rVNgRulWlGk0-l4X6HZXH; Mon, 03 Apr 2023 16:31:55 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1680528715; bh=QFh2Qzhmxh/G7C5fjFWTwiJiilCSTiKC1fL8nFAOZyk=; h=From:In-Reply-To:Cc:Date:References:To:Subject:Message-ID; b=JAoQkerD3dS1q+fAQJvhjnxFjnuGpEcwxi+rEkPbJe2EBfcckaqmg0wXbQRWQ/ovJ eSjTFr5G0t2Sgz/RWe5Njyoxo6JVQ2x8eK6lgnmxMm5gEctuPUrGNZHa0pY7YFBmID xCraE1i3+FiNMVnkKlltaDke35t/rNbGfRSgRscI= Authentication-Results: mail-nwsmtp-smtp-production-main-33.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Message-ID: <07fe91e7-104a-32d0-e59b-c1d2d459fdbe@yandex.ru> Date: Mon, 3 Apr 2023 18:31:52 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: MREMAP_FIXED unmaps dest on error Content-Language: en-US To: David Hildenbrand , Linux Kernel Mailing List Cc: linux-mm@kvack.org, =?UTF-8?Q?Jakub_Mat=c4=9bna?= , Hugh Dickins , Vlastimil Babka , "Peter Zijlstra (Intel)" References: <18c36a78-4082-fab6-c7c9-69a249516803@yandex.ru> From: stsp In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, NICE_REPLY_A,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, 03.04.2023 16:58, David Hildenbrand пишет: > On 30.03.23 17:48, stsp wrote: >> Hello. >> >> The attached test-case demonstrates a >> bug in mremap(). If MREMAP_FIXED is used >> over an existing mapping and mremap() fails, >> destination area gets unmapped. >> AFAIK the failed syscall should have no >> observable effects. > > I remember that holds for various mapping-related syscalls: if > something goes wrong, the end result is not guaranteed to be what we > had before the syscall. > > For example, if you use mmap(MAP_FIXED) to replace part of an exiting > mapping, we first munmap what's there and then try to mmap the new > mapping. If something goes wrong while doing that, we cannot simple > undo what we already did. > > Long story short: the semantics of these syscalls has never been to > leave the system in the state as it was before in case anything goes > wrong. > > > As another example, if you do an mprotect() that covers multiple VMAS, > and there is an issue with the last VMA, all but the last VMA will > have their permissions changed. > Thanks for info. Is this documented in a man page? I wonder how do you deal with mmap() and mprotect() on such occasions. mremap() is an extension, but mmap() and mprotect() are from posix, so is it a compliant impl? Also my example shows another bug that the VMAs are not merged after I restore the protection of one of them, allowing them to merge.