From patchwork Tue Oct 15 16:11:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 13836697 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 732FDD1D887 for ; Tue, 15 Oct 2024 16:12:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5BD86B0082; Tue, 15 Oct 2024 12:12:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0C426B0088; Tue, 15 Oct 2024 12:12:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A37B06B0089; Tue, 15 Oct 2024 12:12:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 86F926B0082 for ; Tue, 15 Oct 2024 12:12:13 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A2CCDC173E for ; Tue, 15 Oct 2024 16:12:03 +0000 (UTC) X-FDA: 82676328126.20.BB2FDAD Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf03.hostedemail.com (Postfix) with ESMTP id 4236F20005 for ; Tue, 15 Oct 2024 16:12:06 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hh0Yq5Rm; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="X1PhV17/"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf03.hostedemail.com: domain of liam.howlett@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=liam.howlett@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729008587; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=KYyLF2ENtexUITmlT8lmmUNbLkPq9ljm2V6KhrAKUcA=; b=X5xe14Zd8HtMmv3ZZ0XNe5UAjPh4FO+O6ROZjZ3Qri8YZXsDmhSOOpOo4XeAHw54Cc0xZI 8jjZwVw4Jnpw8UwaSyoCgekbWyV4UDohnf77jRDfKQRwMgyxQesoq8e3rMpDpYXOY8ndKC pWaMMbIflOrAp8bm06ojcaNwhfIYtug= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729008587; a=rsa-sha256; cv=pass; b=8Q8A5qt5vFg6mQUn6ompddq/P/yNqBMdVCbOqRfCJA8FiJKTRlzMVwv/Xvh8vdiPgJgRim 5wkJNtvEbly2sO5VR+KWGaiyrMGAm1P3UcoAXmahpyhRIRcEC284/HwA7blSFBHbOtJjX7 VfydGczaG99pkHUdY3wsOtaBeRj2gX8= ARC-Authentication-Results: i=2; imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hh0Yq5Rm; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="X1PhV17/"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf03.hostedemail.com: domain of liam.howlett@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=liam.howlett@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49FF0b32003872; Tue, 15 Oct 2024 16:12:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=corp-2023-11-20; bh=KYyLF2ENtexUITml T8lmmUNbLkPq9ljm2V6KhrAKUcA=; b=hh0Yq5RmIUk+KyFlX2my6MzRWu46SVAv LrWolYHp9EbsdlFWtYKjJo56HxFPaztM1Bszbs0Q+4euJuMh2PPyGVT2EafI3YSj 55BKl0rufcK3qHCsFsatNkV9jBPg0DKnRTdjk2LrQW9Pde95ZpF2cqPcdZzIWLFl g34YK0HhicMR/jCJ4kTHmICnTpL549rIIDvhn/HPwXFhfdyLjp5T/noVDV3bWhXr oBr/3S6RJJwysAn61SRTeZd7LfOcB6F7rDjdy3T7lYu3jMPKAh6VPs+PJbuXpZjy uVCGNou9VjBn+QM5SuWLn/0Qlg8JgyhQ1veLxcGjySM4XzmNQX10sA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 427gqt1g53-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Oct 2024 16:12:04 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49FEpCew026287; Tue, 15 Oct 2024 16:12:03 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 427fj7nuhw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Oct 2024 16:12:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MwGk2BhpeYQ/xXLQDrC/SjBLylC3VM2ouET8/KKFrrmX/UU1ahDm3CSRrZGgAQkUoR5PJCpgMJD5Nyl4qt9i0Nvz26b1/UBgsSG6kyZCpNWP3P1c/TxKXyyJXIk//MeG8K1Ba58lDmzT4WbPJfEjTbyDI8qW6Fj+mYu7MDhGBQa52TFwtGvgRVJyoGlJLE5/HKWDDPeI0mV1kI6YQurgvC2Ayg0w25o6kJoa+K4RY7sFVJA6xQxtqRMDDVpuk0+Fnrhy1f3zAvthkT3SgRMsafgdZrgxWGhBsXNYCpW8irIpy+F7707+h27lXmEEYT7SqnFMwCsEZPT2IcPxupkOkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KYyLF2ENtexUITmlT8lmmUNbLkPq9ljm2V6KhrAKUcA=; b=iucsWVR3WEDINgRWSup1EkPF6mElanhfazl5Mf20d6ouH1uY0PbdSMjlKFZ4+1bg+ZruQvvl0E9ulFVbU1JEtv1uFJ8ISZe4KKHroC5JmJQ3y8EUi+2j6YXnz8SbFtXWQ+tBC1UW0DQpIgLqrT6sUZDLUeXDZBzizfAQOub5V4Bzlh9c48tWTg4NAG8FtLal2JjRM0lVFEWwjjDnDr8gzd7quY2R+0aB9GIjkOR6FJGyxwo2sKUduy7F65wSEbZactIsKqZIQAvdi+Z473wYdu8aXAakvIbDi2AEp7huX2D353XcfsiVN9U5oLAdJnkFgr/x/pDCPslXZxhOVFoTZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KYyLF2ENtexUITmlT8lmmUNbLkPq9ljm2V6KhrAKUcA=; b=X1PhV17/cjTlT5DgoAKAEVcWoSZ6UtoPGdOJjXdgB6+Pa3gNaQ4EVs6bpvdZe1A3o8lBj+C/9NpVR81EATLnM0wdvm9xDnrZ9/ldkfSe5RitLRIBUkPG2fY19z4LIbAc66X/SuOUWHUncLVzYpicSE0lynZR98goCWnIXK4FCVU= Received: from DS0PR10MB7933.namprd10.prod.outlook.com (2603:10b6:8:1b8::15) by CH2PR10MB4360.namprd10.prod.outlook.com (2603:10b6:610:ac::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Tue, 15 Oct 2024 16:12:00 +0000 Received: from DS0PR10MB7933.namprd10.prod.outlook.com ([fe80::2561:85b0:ae8f:9490]) by DS0PR10MB7933.namprd10.prod.outlook.com ([fe80::2561:85b0:ae8f:9490%7]) with mapi id 15.20.8069.016; Tue, 15 Oct 2024 16:12:00 +0000 From: "Liam R. Howlett" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , Jann Horn , Lorenzo Stoakes , Vlastimil Babka , Matthew Wilcox , David Hildenbrand Subject: [PATCH] mm/mmap: Fix race in mmap_region() with ftrucate() Date: Tue, 15 Oct 2024 12:11:35 -0400 Message-ID: <20241015161135.2133951-1-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.43.0 X-ClientProxiedBy: YT4PR01CA0113.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:d7::25) To DS0PR10MB7933.namprd10.prod.outlook.com (2603:10b6:8:1b8::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7933:EE_|CH2PR10MB4360:EE_ X-MS-Office365-Filtering-Correlation-Id: 302e019a-1a59-49f2-ff36-08dced34196d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: uPNNYiMm2vI5gg+KiwGEX/AsIU8pqVuA6QJ1ekUbFBK/n2nYBnhjAWVXSuR2ifTvnKqIUt1DZbCMvDmnyqfvCRsKuBnmBH4OGRUjWWA4+91fcayvrxUR41V9C3tJGS5vRkln718SFTsvIKWKB3Ssb0yO0M2p5WVJc37JEQijcSIr2XLZD6Db9czLVkW4Fd4chojVGSV1sHDvCtnowUsteMI8zk88rTFP+GUsWoYumhHV8MENc+vMIFTP0CX5+v/ZDmivNQ0VXK/4QPX5oGeSCaC6b3VK2g6RmbNJi2nUF7uQQomgNNWIgM91Z7pkd16c1xB1yQbIznIh+dEgcHNjJ8G6r6hZohX1JAv9VA7IrpWodwzBkePFTGa0BaOb8JJmkQN+McpjtTQIfwuYZcFYWueiObh5mKuBFpQnB3N4qBLunba5Vfz5kEYqOsEW4LlgTq70zmZw7ShE3FnJeFH1oiW4d93Y+GRhUnIxJeMwOPOZkKFSq4QRGOsk/EVlNHGCpuWbEz5m3Xkjf+SroyKw5K9cLyglnV+hTy8v/4YLV5Bnyup3oR0uNMTL1uMb55ahHsNx3Kd7/+SAZ8aeOtJmwqfvPeNJ1GbsQNfu6JP9PJN0/Dzq3xAkABMgnhJGi7iR3QFknaTOlJzo6RzxGfI0BI+ivApoKUNRz0e790HA/uXy/foIh83PJJV6J7Q0b3ppdL8Bfxg6WdZduZusXpW4tpOUVrSErUmVrCI7g7xaidqRc2EKOZU+Js+89X2zcR1jnConpjRnVwPBEhKkJ/HID0C0Dvu/zzvOr4FQtBeu+MtGMw1sIxS11dZ+uj6Qj78h0LOFx64Vr+jm2WBdicXOzYICZaJ6RPbHSpK8ph+fNn1soB+bUePr/49ZUejMl0xMISc/GU/OySFGuVr0S5Lwkd2o50zhKptriJ3pl4P6W6kDpbHu5jv4gW7eqvmBV4QuNbgPph9uZjMzmt1J7NIxLKa0TZW4OjzEHGITSgmEba0dlou+hGu2ZLh7T3Y+3LlAD3dhc2OXHLyXsOIA5Vn4RPDEHgyqWch0S5DDfGoWB0E9edIPIdv/F2OT4dgOAEo4IDwR/AMG12A4W0K8l3N09K/UzXitDNwd5qB3w3MyQhmajtBV/5ON1cOJDsWEmVoorfMO5C+LZb91GSF9B0AxnZ8FgAo+hvtAZ3pfCeCaeU2+o4Z2Rb9mhvhQWlDpdJiTsE3O9ktfMAnB0Ge7RssFurh0kCpOmhAS6vUYRpCvtGrxOEVsCR683yanPtc11MZPK0ahP4Y/qvZ8thPzt8E3Lw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR10MB7933.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: o4WKIN1pUTsHxLA7iHSwb2nRMw1ACbvE7L6ATWup5uIa3HcwyYV3UVLX8yfzP0l1yuvth4iG1cn55UJtaVU3S91mwQMfU9FOoI/NPlSw77OUFwBMlTICikWfSI4uThRX+ER8/pEcMn5iBSyxPiYHrjilNi4h0MxofLK6MzVnL1kbGbDhhB4ZcEC9ncKY6V32ggj3UUt+sLN7xhArv6QjdfDRFHy65ykNoAVzZIQX+i2BRTmwLhxo2AfNbecUnPmydVmRD4TiAv41zb30GthEge7fWHuEDHMBM02ERz0N9jn0N+jItIu+VXgZj+Y7EtG7RVCfhrRd7xFplmyeCAoAW1C2lIfirY6ah/cz3tI5X+bzeU3N42PSUf1ngBpmXNYCGUOOpAzqGfU8udJndudBlGd3/8xWdh82z5GRwWbqVjUgSrEf7pebxAKKveWa8cVdaKEwiBByStISjPyzr8YtRht83Z08iQkSyT/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NJtn/zcR30Ku7y76ePuOK5MIXCG1WbH7obyYDWE7kPM2zoQ3HtPTc7toY6US01AZVWHf3BVuPOZ/D5YI8XedX8RCg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: SwhAqEjamj7cQyaFtLttPEXqOWTKxwobAL3h3QgkUrXimqDsgeVjrskD5BDIDetN+qLG8l/PX1eudCJcBPV7erw7y/1EoIkV4VAH0/XkcrTCj+NYo7biNkajh3tdcZhHNFoRA4AqvUbE1Ftwnuqzj8csoaJcFXANfuu1EnuNvkrLYi12+yp0PB78gD4Yx+6+Fe+RtWKpRVYeb7fQr3IYl6oOkrAvGO0zToMye6zGaj6LlFG/ckGP+fgjAtD32wvWxc/EMHbugFvxQG5P/fVS7vM9IrwnYgMWBRtijiKxdWxCIBlVAUgZ/n8sLMPodv06EbrNHCP7+lR+wj8I6BBGZvWEz6IZalZIke5YKrPuzcCm/EspzbBtE2CenirHl9zggNb3M0ReiS3vsu0hTdJ95fSWWr1T75wj/2el8JGVoODPTZ5get3NCvoQfU6Fzflg+Uc9J4MJ5/fyxzmuclBRJc7fWmViRm3cGZnQi3CDCV3Qr3+TzKtoAxtiHwu2DKjpF6FTPCtT2C4fwHbiB0gw60J1krk4aoHcrTOjskLN3HIPR7ekZtz81EengA4yqjX4qOOwLKGsR1h9DjmLmrm6vsjzADDSPUnUB/ShUKH2qYU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 302e019a-1a59-49f2-ff36-08dced34196d X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7933.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2024 16:12:00.1826 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gVWB/2a/h2QpjdHP9EzOIzdY8DHk+kJt0Ha79jY/yVk8ivynhhsLN05P9MCZkSLrve0tSXttjVU7DBSGQR5lIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4360 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_11,2024-10-15_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 adultscore=0 bulkscore=0 spamscore=0 mlxlogscore=995 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410150110 X-Proofpoint-GUID: jWZU5sDgaEsvq9Lv8WbR3gYspB-0ZWe6 X-Proofpoint-ORIG-GUID: jWZU5sDgaEsvq9Lv8WbR3gYspB-0ZWe6 X-Rspamd-Queue-Id: 4236F20005 X-Stat-Signature: txtm6ky961zfhw9nqx8q5anhdxkzg71w X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1729008726-829468 X-HE-Meta: U2FsdGVkX18Zh7iMrnnXcUJPJxJOQtVp1FIjnCP8Zaxt8L1vf6pTEiBwqvaSHoqPyezu8EaRTX3us13t+TUkeHK5GeE4XHy+YR441s9ZVKtoqT0z1gUev8f+Z5bKYbxT/NtDbfmfswinqLDnZG/EaXv5rEEgV2qaRir4wHr+guZSQmAPR30LfQUqt8ETrXDMu4Ye+qUIga080sheLNmXTnpxd3awY3hCD3H99CTlTgxaOukDffVB+2d9DiWZxcaK4yn9OhhKZEy/QBJaoicjqyhc7AdnwIEoUeSWtzaSLkiUJyx9QVgomKnrjsCYBwR6m+UHfQL0Ty5PNhlPCA2bLvURiydQ/g17R9N24fHFvXLPw/3dl/jMgNGY2HPUMUkmQGh8PSumcpHJ4IlNTktZ3ZrRYm/aFx9kKQ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9oqP0/lW2N9H3YaWcUNeZdntLvlU7ltga18W6dZN39MxMMdL7R4kBDkZmX3/cRMjHSbLl6NP9fm+XK0z8bwksOF2xXqUuXu+AZfYyNNYH8iUdK1PaqHfL2eC+AhUMstyehL3VpWJzZtY+faTZbzcF7e+tMMUGhf7x5UfpL0lQRTkd8StnRoW9qO8LfZnXD1R/CO5GBGk= 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: List-Subscribe: List-Unsubscribe: From: "Liam R. Howlett" Avoiding the zeroing of the vma tree in mmap_region() introduced a race with truncate in the page table walk. To avoid any races, create a hole in the rmap during the operation by clearing the pagetable entries earlier under the mmap write lock and (critically) before the new vma is installed into the vma tree. The result is that the old vma is still in the vma tree, but the page tables are cleared while holding the i_mmap_rwsem. This change extends the fix required for hugetblfs and the call_mmap() function by moving the cleanup higher in the function and running it unconditionally. Cc: Jann Horn Cc: Lorenzo Stoakes Cc: Vlastimil Babka Cc: Matthew Wilcox Cc: David Hildenbrand Fixes: f8d112a4e657 ("mm/mmap: avoid zeroing vma tree in mmap_region()") Reported-by: Jann Horn Closes: https://lore.kernel.org/all/CAG48ez0ZpGzxi=-5O_uGQ0xKXOmbjeQ0LjZsRJ1Qtf2X5eOr1w@mail.gmail.com/ Link: https://lore.kernel.org/all/CAG48ez0ZpGzxi=-5O_uGQ0xKXOmbjeQ0LjZsRJ1Qtf2X5eOr1w@mail.gmail.com/ Signed-off-by: Liam R. Howlett Reviewed-by: Jann Horn Reviewed-by: Lorenzo Stoakes --- mm/mmap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index dd4b35a25aeb..a20998fb633c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1413,6 +1413,13 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vmg.flags = vm_flags; } + /* + * clear PTEs while the vma is still in the tree so that rmap + * cannot race with the freeing later in the truncate scenario. + * This is also needed for call_mmap(), which is why vm_ops + * close function is called. + */ + vms_clean_up_area(&vms, &mas_detach); vma = vma_merge_new_range(&vmg); if (vma) goto expanded; @@ -1432,11 +1439,6 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if (file) { vma->vm_file = get_file(file); - /* - * call_mmap() may map PTE, so ensure there are no existing PTEs - * and call the vm_ops close function if one exists. - */ - vms_clean_up_area(&vms, &mas_detach); error = call_mmap(file, vma); if (error) goto unmap_and_free_vma;