From patchwork Tue Dec 1 13:27:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Zixian X-Patchwork-Id: 11942973 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 993BDC64E7A for ; Tue, 1 Dec 2020 13:28:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D3483207FF for ; Tue, 1 Dec 2020 13:28:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D3483207FF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B41438D0002; Tue, 1 Dec 2020 08:28:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AF17C8D0001; Tue, 1 Dec 2020 08:28:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DE4C8D0002; Tue, 1 Dec 2020 08:28:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0236.hostedemail.com [216.40.44.236]) by kanga.kvack.org (Postfix) with ESMTP id 8886D8D0001 for ; Tue, 1 Dec 2020 08:28:08 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0E2ED180AD815 for ; Tue, 1 Dec 2020 13:28:08 +0000 (UTC) X-FDA: 77544791856.10.wind54_0701d0c273aa Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id D96C116A4B1 for ; Tue, 1 Dec 2020 13:28:07 +0000 (UTC) X-HE-Tag: wind54_0701d0c273aa X-Filterd-Recvd-Size: 2296 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Tue, 1 Dec 2020 13:28:06 +0000 (UTC) Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CljZd36NXzhkm5; Tue, 1 Dec 2020 21:27:37 +0800 (CST) Received: from huawei.com (10.174.176.134) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Tue, 1 Dec 2020 21:27:56 +0800 From: Liu Zixian To: , , , , CC: Subject: [PATCH] fix mmap return value when vma is merged after call_mmap() Date: Tue, 1 Dec 2020 21:27:55 +0800 Message-ID: <20201201132755.5076-1-liuzixian4@huawei.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.174.176.134] X-CFilter-Loop: Reflected 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 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 --- 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 --- a/mm/mmap.c +++ 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 * 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; }