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.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 B79EDC64E7B for ; Tue, 1 Dec 2020 16:06:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DE14B2222A for ; Tue, 1 Dec 2020 16:06:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="LdcB5azu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DE14B2222A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 157268D0002; Tue, 1 Dec 2020 11:06:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 12DE88D0001; Tue, 1 Dec 2020 11:06:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06AC88D0002; Tue, 1 Dec 2020 11:06:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0157.hostedemail.com [216.40.44.157]) by kanga.kvack.org (Postfix) with ESMTP id E146E8D0001 for ; Tue, 1 Dec 2020 11:06:24 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 98F158249980 for ; Tue, 1 Dec 2020 16:06:24 +0000 (UTC) X-FDA: 77545190688.10.mouth88_1316625273ab Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id 804FD168815 for ; Tue, 1 Dec 2020 16:06:14 +0000 (UTC) X-HE-Tag: mouth88_1316625273ab X-Filterd-Recvd-Size: 5087 Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Tue, 1 Dec 2020 16:06:13 +0000 (UTC) Received: by mail-qk1-f195.google.com with SMTP id z188so1724313qke.9 for ; Tue, 01 Dec 2020 08:06:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=WEJkhm+ph+mvO/O7e3W8IL0tl/7MxVJcOmqbjrcwABg=; b=LdcB5azuX77LS6zKX1wIeHM+sk+u5vhjnbJdPMZqdg+P5jNb0l0y6x9U3/TeEANQUB gfJh6ICTw+08G1Cm8m+cyksgC5NMTTdR9+hk7nUBimYMmCKHHBrKh0NTpLUsDDFgqzeM 78PBG9ijAu8kvLATgvpkFvjufxKMmDAcVFDGRM9iuwuYW4jJSUoe7+ZFJAcmoInT/4J2 G7Cz3GUYVXdrEs6MzXgXoyo+QI2DGH1T6WFYibb98cBletS7uJ1i2or4F05e3srTnc0L CpqXE5IWoDbPRik04bQYhcHe6asN8WO2N0Msd1F0k2zR8s5Vn5gbqwXjy+ILvyEawcq7 Y8LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=WEJkhm+ph+mvO/O7e3W8IL0tl/7MxVJcOmqbjrcwABg=; b=hMz05EuI1VXVKmjsz2Y8CP+xGYFgsU3AUXnlbFCAdlFeBWY5oRw1ZH2A5/gQBPEyz6 w822GuA7vCp4MVVDu8/0vRcphCSGip4gTvmnX+z4w4Nuu0KLQz5zOwT3RxEA/nZeTzKe YImfX/eH6KBwvp0QShTjaszamyMyfOif5BvlLZ6k5AEpi8w0u8sxuxc19n+azWXOafwf jVIxt2R9QHG1NvtwcMKQgWBXPPIKC0ZfnYDycu0jXxu9CUxaNU2gDmGE0KVCA5NTbc7V EMTIE6lSTOADd+x8LlxGTxbwLdP4OpifXlf3Q2lIUtVsU/42CBleJUBONcTVh9A5M8bk Ze7Q== X-Gm-Message-State: AOAM532UuldfHNhr0GzqP+Ko23hjd47rPMcpeneFmvmSqW0nO8kU+77m XHoFA4HjjPVjy2kBF0+n7ORwpQ== X-Google-Smtp-Source: ABdhPJy8Sy0ZAAdu0FvFBhR4BPfMmWXKkwBySq7PlA6UzsX3LUc90SE+GZ6SqvJHR9kbf75kdIDr3A== X-Received: by 2002:a37:d2c4:: with SMTP id f187mr3584755qkj.286.1606838772812; Tue, 01 Dec 2020 08:06:12 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id 14sm1903290qkk.128.2020.12.01.08.06.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 08:06:10 -0800 (PST) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kk8AL-004TNC-7g; Tue, 01 Dec 2020 12:06:09 -0400 Date: Tue, 1 Dec 2020 12:06:09 -0400 From: Jason Gunthorpe To: Liu Zixian Cc: akpm@linux-foundation.org, linmiaohe@huawei.com, louhongxiang@huawei.com, linux-mm@kvack.org, hushiyuan@huawei.com Subject: Re: [PATCH] fix mmap return value when vma is merged after call_mmap() Message-ID: <20201201160609.GE5487@ziepe.ca> References: <20201201132755.5076-1-liuzixian4@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201201132755.5076-1-liuzixian4@huawei.com> 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: On Tue, Dec 01, 2020 at 09:27:55PM +0800, Liu Zixian wrote: > On success, mmap should return the begin address of newly mapped area, > but patch "mm: mmap: merge vma after call_mmap() if possible" > set vm_start of newly merged vma to return value addr. > Users of mmap will get wrong address if vma is merged after call_mmap(). > We fix this by moving the assignment to addr before merging vma. > > Fixes: d70cec898324 ("mm: mmap: merge vma after call_mmap() if possible") > > Signed-off-by: Liu Zixian No blank line after Fixes: Consider a Cc: stable since this is quite a significant bug, if you hit it. > mm/mmap.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/mm/mmap.c b/mm/mmap.c > index d91ecb00d38c..9199b5e8cc1e 100644 > +++ b/mm/mmap.c > @@ -1820,12 +1820,12 @@ unsigned long mmap_region(struct file *file, unsigned long addr, > * and cause general protection fault ultimately. > */ > fput(vma->vm_file); > - vm_area_free(vma); > - vma = merge; > /* Update vm_flags and possible addr to pick up the change. We don't This comment is now out of date, we don't want to pick up the 'possible addr' change. > * warn here if addr changed as the vma is not linked by vma_link(). > */ > addr = vma->vm_start; > + vm_area_free(vma); > + vma = merge; > vm_flags = vma->vm_flags; > goto unmap_writable; > } David's remarks are correct, how was the original patch tested? Did it always prepend during merge so the new vm_start is OK? The previous patch really added more spaghetti to this function, jumping into the label 'unmap_writable' inside an if is aweful. At least for this fix it would be cleaner if the entire if(unlikely) block was moved below here: WARN_ON_ONCE(addr != vma->vm_start); addr = vma->vm_start; Since we want to do that unconditionally after call_mmap. Jason