Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9472357pxu; Mon, 28 Dec 2020 17:47:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxiUnXfympd9CB6GhJ/r7zLTnHdnXoc8X+1qheXn1xtuMmEQxFiiQsIKOVDheonNVZ7qlHf X-Received: by 2002:a17:906:b002:: with SMTP id v2mr44314012ejy.531.1609206464495; Mon, 28 Dec 2020 17:47:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609206464; cv=none; d=google.com; s=arc-20160816; b=QTHehVYBEZuai54faRPRWtJYSFQ4EXDyHDRvNd3L9JokdNxV3SdmxPl4cw4YAezHdb ulsXFd1mqxb2VoStUNRbkYogNaW0d8bc8B86w5oaf5TITLtMygQo3FhwMp7hrYE8G0FW Sl2j9YwKdicAUr6wN4YAkWeOv6XRJFYTMm7TlUiTG8ej+AaXirWtZ3NVPXSCDXX+NBha 94GVpRionps7C26WL7QGdeb77dbnJ4N8WWZ7vW3U8GdLU5rgbpYMokpYaBhcM5WJWG2t qnnQIpKMST6m67iLENzAPpu60pETloiDNe/o1HH3hlnFBqAdp+7TVSDxsMQ8G5ckw/xT b08A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=Z0KfyjgxJTuJfSURWXlwLwsumCTCv+/5+ZkyQAaU7PI=; b=IY0N1WCj3jXXfiglmmFqetZD/fm6hcQSlleiGmR0ufs/SF6Udoxe4sorLrKgYO0OvY kubPIvDI7igaXa00hD8tGA+PuBHPq2MkxoZSj7bM1pPJ2q65+Bz3c+hlfWxRjVuOhxfD wUoR0mjMAaMBtp6vWcyKMol74qP4gg00lK7yuqtiz5yZlyQXiwHF8F2VBcnavFI3TYgn rMGIKQeCjtrpfmHdlfOucjgquQRTxARcfi3Isi0OZwoIdw8Ko5OgpW8mQBMSZLpdCXLB T1NQVD7eRcf9R5JU3FN9gIhNVHAT5j4SX0Oz63Fr+WTfsCJ/xCSG1DdPxU88qoM7+rMn 9icw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=XqRyu90N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si19544861ejw.548.2020.12.28.17.47.22; Mon, 28 Dec 2020 17:47:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=XqRyu90N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729407AbgL1Wzd (ORCPT + 99 others); Mon, 28 Dec 2020 17:55:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729283AbgL1Td6 (ORCPT ); Mon, 28 Dec 2020 14:33:58 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC47CC061796 for ; Mon, 28 Dec 2020 11:33:17 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id k10so323893wmi.3 for ; Mon, 28 Dec 2020 11:33:17 -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=aJRwLu13Oa3WfYmWuUYnkD7AUw197oKiJB/FuPHeP7LYzNgl0bVpDJcAl8x2dg1tNz +3RqFfYDKOvvtT0QuQdOZ0JkOXQm41fvFFXl02TvSyxN/UWaX5AamVlP4cSElb0RrOJM ZhzvWhBBxZ7XyQJVkyXBAEpx5YU8RAJHt8oxOFmuN9buEJFF2PILL6NQOX5I8jY0B0Pv miyiNL8Ewg50O5cwB1doJhTAvQMNc/sTr53DRXIm9/Kt6R9L+vLXyWNGO3z/wuwAZS7s rhDyWIdsX3Nm61ixTFUnwr+nZ5xh5tB0WHeNcjHpz2B9m48x3MiGIDIKy2ARpKeIP0LD YyTQ== X-Gm-Message-State: AOAM532ZdG0m4jScZNZ8o3XXm/xKH9QkrQhAY7Jbdij+hq82ViGAFCjL HO33c34NiUQhpDMMXdBQt3iAMw== 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [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