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=-15.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 328A9C433E0 for ; Mon, 28 Dec 2020 19:33:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B0E1A2064A for ; Mon, 28 Dec 2020 19:33:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B0E1A2064A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=arista.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C043C8D0019; Mon, 28 Dec 2020 14:33:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B8DD38D0018; Mon, 28 Dec 2020 14:33:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7C318D0019; Mon, 28 Dec 2020 14:33:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id 8F6EE8D0018 for ; Mon, 28 Dec 2020 14:33:17 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5116B3489 for ; Mon, 28 Dec 2020 19:33:17 +0000 (UTC) X-FDA: 77643689634.06.place92_0c0076327496 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 2EF231003500D for ; Mon, 28 Dec 2020 19:33:17 +0000 (UTC) X-HE-Tag: place92_0c0076327496 X-Filterd-Recvd-Size: 5586 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Mon, 28 Dec 2020 19:33:16 +0000 (UTC) Received: by mail-wm1-f54.google.com with SMTP id g185so357374wmf.3 for ; Mon, 28 Dec 2020 11:33:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Z0KfyjgxJTuJfSURWXlwLwsumCTCv+/5+ZkyQAaU7PI=; b=XqRyu90NuceEFpT6tF4NofE7WRFm5S3LNywInKKEKjCvkAJwNJtodtyAoxTGiupGV4 ujY+V7ODzTVsylv5MWG8aDK8q/m0q3kHPylzv0UqLa3BFEHg4PUmj1uguOzJdn35mgCw TFfm4xM4ea+wswAn2AxCTN2ZLSfYz8ykCkYzVluX81LRQ9yaeWZxltVh63xf18Wvh6lq NItTquO1MNg3t1ihf9tuLZoYemAG6CNhK0QUpH8T0SPAX/3figPG18UWDj5zahAH1YRE 1lbt5QJF0JpxWgdZ5uZyaIWYfxnGl3e+wMsIAkMFbHd2pd3+qnqSQkmk66JxeijJWKnn kUjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Z0KfyjgxJTuJfSURWXlwLwsumCTCv+/5+ZkyQAaU7PI=; b=WJw1p1r1225W2oJQ6kV+GbMZQHYvGJoyFwPXkpaBZOfJEPGEkfUavnxp5L/2xph6xf Mbyjdm5b+LHk084eP7Skxc+NnP8ujRteK+5Do6nOKoSAW3M6ENo1qTCBhTjk+MAmnhRV E2hIx6w+sgRCod5RLa0bWLCPK5H/BlJds2FcfLI4tOXggPejRGUfWJMgQky4aGndL/OK j6g/tkYq0iCmKed2X8I5KoXkHdpmD/veXnAJRafpqnHaYw+N189OtMekQwCPjB+HUzws D7ErNMOzvtb7XZ2C2Jvn36LqPQjzUUo0cI57MVlzCX3atS1t/X7KfyfS3U+McHdP2emi 2Q+A== X-Gm-Message-State: AOAM530Rd7W0lQIBiTrvRaR2H77uJhdiDVuXENmkgEA2Io54haoeJosw PEUo8zNyg0WM6CQQKFWe6wO60g== X-Google-Smtp-Source: ABdhPJyQK/aP+EZvb8UjoNqqqOAM87tRgF0AgpxqbYLmb4xZC4WpszLjUmL76sYOJz4uZq4VYyhiTg== X-Received: by 2002:a1c:e142:: with SMTP id y63mr397332wmg.28.1609183995440; Mon, 28 Dec 2020 11:33:15 -0800 (PST) Received: from ?IPv6:2a02:8084:e84:2480:228:f8ff:fe6f:83a8? ([2a02:8084:e84:2480:228:f8ff:fe6f:83a8]) by smtp.gmail.com with ESMTPSA id i18sm58308624wrp.74.2020.12.28.11.33.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Dec 2020 11:33:14 -0800 (PST) Subject: Re: [PATCH 3/6] mremap: Don't allow MREMAP_DONTUNMAP on special_mappings and aio To: Brian Geffon Cc: LKML , Dmitry Safonov <0x7f454c46@gmail.com>, Alexander Viro , Andrew Morton , Andy Lutomirski , Catalin Marinas , Dan Williams , Dave Jiang , Hugh Dickins , Ingo Molnar , "Kirill A. Shutemov" , Mike Kravetz , Minchan Kim , Russell King , Thomas Bogendoerfer , Thomas Gleixner , Vishal Verma , Vlastimil Babka , Will Deacon , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, linux-mm References: <20201013013416.390574-1-dima@arista.com> <20201013013416.390574-4-dima@arista.com> From: Dmitry Safonov Message-ID: Date: Mon, 28 Dec 2020 19:33:13 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US 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: [I moved your reply to avoid top-posting] On 12/28/20 6:03 PM, Brian Geffon wrote: > On Mon, Oct 12, 2020 at 6:34 PM Dmitry Safonov wrote: >> >> As kernel expect to see only one of such mappings, any further >> operations on the VMA-copy may be unexpected by the kernel. >> Maybe it's being on the safe side, but there doesn't seem to be any >> expected use-case for this, so restrict it now. >> >> Fixes: commit e346b3813067 ("mm/mremap: add MREMAP_DONTUNMAP to mremap()") >> Signed-off-by: Dmitry Safonov > > I don't think this situation can ever happen MREMAP_DONTUNMAP is > already restricted to anonymous mappings (defined as not having > vm_ops) and vma_to_resize checks that the mapping is anonymous before > move_vma is called. I've looked again now, I think it is possible. One can call MREMAP_DONTUNMAP without MREMAP_FIXED and without resizing. So that the old VMA is copied at some free address. The calltrace would be: mremap()=>move_vma() [under if (flags & MREMAP_MAYMOVE)]. On the other side I agree with you that the fix could have been better if I realized the semantics that MREMAP_DONTUNMAP should only work with anonymous mappings. Probably, a better fix would be to move : if (flags & MREMAP_DONTUNMAP && (!vma_is_anonymous(vma) || : vma->vm_flags & VM_SHARED)) : return ERR_PTR(-EINVAL); from vma_to_resize() into the mremap() syscall directly. What do you think? -- Dima