From patchwork Fri Nov 15 12:41:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13876188 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 F17ACD6DDF7 for ; Fri, 15 Nov 2024 12:42:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 30F916B00B2; Fri, 15 Nov 2024 07:42:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C1226B00B3; Fri, 15 Nov 2024 07:42:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 076DA6B00B4; Fri, 15 Nov 2024 07:42:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D290F6B00B2 for ; Fri, 15 Nov 2024 07:42:39 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8EAB4ACEAA for ; Fri, 15 Nov 2024 12:42:39 +0000 (UTC) X-FDA: 82788291852.23.5A4ACAD Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf17.hostedemail.com (Postfix) with ESMTP id 4B1874000E for ; Fri, 15 Nov 2024 12:42:01 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=dVCXG0jz; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=WMPMPZVR; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf17.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1731674424; a=rsa-sha256; cv=pass; b=TYsWkyWNbvmekwzuOV55efBAGoEAN2AYmSwm+2l0LXVdsV4vRMvn21A2zu/NvlsPNioxzo ZNawsCSJrqn748cbn53mxx0QFnLNs2cgC9hvWduU6arWwkb4pIzXMteHazdycES5submU/ Pl6AYpwya6mCzF/lCzYzpJ4XO6IV6Ug= ARC-Authentication-Results: i=2; imf17.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=dVCXG0jz; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=WMPMPZVR; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf17.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731674424; 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:in-reply-to:references:references:dkim-signature; bh=0TwxBJSLcC4galjZladP3skso+2UgAA4dyxp3qrUK9g=; b=aLnkwm86qe4GulF68mianSHUQvaQdvIrVIdpUsBZVOkkWggR7opp+COhEeEBKVqUSZeRPz /ffK7dtQdUBF8HminoSylziGCWXgjgLy1XOYTemq1bSPrWISse2QpHdtOmJzafhtzZW5C4 iA2sAF132Bos1JTINRSkexXv/4Fj01c= Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AFAH0Gr014175; Fri, 15 Nov 2024 12:42:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=0TwxBJSLcC4galjZladP3skso+2UgAA4dyxp3qrUK9g=; b= dVCXG0jzMDL0qrPPbJBQYZSch02bxa61nvtDqVwb1R065qeNGUlS5dyDb7FwC3px V77ov7Ja6Ukx/HVEp45Xd/5Py/EIOMf80z6Z6c0MDmZ685CY6qxMDwXJ6Pppk8HA JLkLFrrZsNEGmxyeYgCX+EdvdaZ3pOdCgV5WE+VpCuSs72MIL60vkO1A5Bhzxcrk a9VoFjV+4+KSQh8LIoEaFwYtRpseEQWPGk+jl8zgo4h1s6DHPAKTafBRh1PXZKql KbThgQnpfuZUdzeRLV1XkK7164KJ3CHdAQ+ynD9im+Ng5ixFXmhwbf1/FjreR9V6 K50CloRg6B+fTIyQjc8YAQ== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42t0k5k5yj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Nov 2024 12:42:23 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 4AFBtqeb022740; Fri, 15 Nov 2024 12:42:22 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42vuw2mtnv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Nov 2024 12:42:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=t52z7c01UOjJ5bJ/324plUaSmuFrQNdInzxtI8jUAVRzv3hcaGPqJC089Q3me3SvF+2tYao/9seGFdzYCsQCHmYVrNke69e0Eazy5ne4xT9PSCYm1zlJcDBFCU4J1PJeej+LlIESb9MYY5obHB9aPoi1icepcuemZ3N3tXs71DyN6/g+eIh1ijjBcYAV4zYkYcF8s/LIZfPhlyzWBEyaVahmQUqI30R1/O9k/1gPcDtUmNamBQpBHuZyZHTMeX6fCkz+QNgPFGOMON+sQYte7yJ8jOf7lHijDNGuKKAdo7G2OlULBVodwPMHrJNwC+gXsKdgEQ7epmsXhl9QMOStug== 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=0TwxBJSLcC4galjZladP3skso+2UgAA4dyxp3qrUK9g=; b=OWxZYKGpN/CDYuE/kGLCM4RECBkkbeyoM0zm8Kgpy8SRODSp8PWmy9M1iMAgoH2VAryKBz95BY5lDa8yjfJD7DutLnuaxfZvZoBoMz6otOcpluk/Eaw6JT2abfieIdP/9KMVeyahg2z3OhV+kO9YpilN7isaYp0+8rB4zBuyaj653ZMlo23oeUFYLwys5TWu+qgAaLI/5UJFosYwyVJAqD1txhJJHHT/8f90rHy0xXq8iGKSSpnkQE/LbHebtcY9b4J4ZLbtvWsr7ZUwtny//jdCxJguMHQ9T6qeiEfbUzSGtMPq1QNB3PYzGnATCd6+i4y1gLMJJM1bWNG2xgGT4g== 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=0TwxBJSLcC4galjZladP3skso+2UgAA4dyxp3qrUK9g=; b=WMPMPZVRMbgbO9pCwuNHV1QAtBblWk1x4KxscvLJgI7hAPOT9E8Lzou+ghMGGDfwrp4SJkUKKM2aQXibirFjUYXBBIc+UBveeMduunrxnSAMkX3RuFKrWBABs/DFxpw3yr/DY0dhXbmhKNnU3yd0vwqBBZThdmWNnE68LMQavi4= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by DM6PR10MB4201.namprd10.prod.outlook.com (2603:10b6:5:216::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.20; Fri, 15 Nov 2024 12:42:19 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%7]) with mapi id 15.20.8137.027; Fri, 15 Nov 2024 12:42:19 +0000 From: Lorenzo Stoakes To: stable@vger.kernel.org Cc: Andrew Morton , "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson , "James E . J . Bottomley" , Helge Deller Subject: [PATCH 6.6.y 5/5] mm: resolve faulty mmap_region() error path behaviour Date: Fri, 15 Nov 2024 12:41:58 +0000 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0102.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::18) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|DM6PR10MB4201:EE_ X-MS-Office365-Filtering-Correlation-Id: d4067e71-2fa9-4653-36b3-08dd0572f166 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: rnM4R5DjMiLmA+papYF1WUsA7g0XnYs5natgwjGSpp/3bpoZjUYn7qiRLm1VkWIPQQXmh5fvBZfXx7SXS4cfgrwo0+ojM5MFpjDIkqDATouCTliRZwAIVdhvRbaECLcbq+aTb+aERfsrCxq6H13GS9HuJ2WRgddcrRm5CQXa7WDQt/ihxDD1A9VJ/4f9QOw1+PdG7BI2OPve08jCUgWGjoA7hNNaOB6Notbb9mmaoJViaTRZGkzYgdPrp1KKqca4llrZOWAmdlBkUVf6Iv3EaDctluuMyUCWer+OwbQx8RFowauTrg0VusWC6KvZiXULy5Srgsn0chOLL/cVn1GsnQeknTYUcX+z7vz/Sfv7xi2+mShzegwNlDtN6jvHQr2wZXx5PsrLw2bGt0/9Yn7jlalDLlwZ8MOZe/lDs35YACtKvT5hQA13FapobGtmJRo+Z2Fny4VE/0vtvPWMw2P3bkAa/0dhwVR/YtET+mkyt4Bs76kvyeEAMtlKKNY+hCCMi13LRd1inKdH9kt/PAxA5c9dEGkrKx6TqOYknDCwVVOOgZe8udPhC8RAsbvjwngSKLT5zJ81XWMbIQBtOpnP5oGSt8jksqWzj2q0Ae9TrhqW0BFc4CuxVZA4SkRIPOlyh2yb5DA3ZJcFcLVOF1NizP1jr4/zDfwbbcLPlptSLRbZZ+IMlE070gB/KiU4qvKvdrfXCg7ffdJh6pRz5qMxo+AQQXYkfYIWa23PNg5u00Ic8Z0VaMksgF+VSNGc9GaoTk3qdIu1sqOAjTB30aTPg3dA7AIVSS9xWjhi1NxvkG4dNCyk1nOBjIt/Nx8iM/AupJhpcA23ga8b1Jto4pjTdyHBGbl5j1QVuHEglBWag2CUPd6jKqjRyVkm1F7F+3digGT1wbrbkvSvsY6GKQIfSe7Tm1j370fEGkjJurmrsRpH5wYEYHEY+Dn7aeNQAwQOSq1cx2/e4Wu6zCM+RNVUQ0CGhDyx27hHKdSWhjMMGS0yTQj9rxZaM4dwyEKr7xFFHWvqZqJBPGTXPsX9MFs1wmoRt4KAeL7t/YUETJPx8VwcJU41MoKfDwZf4Mx+wrxjr3CuvlXrIBi5JbTVtmm/ugq+CCkIIxEeF2PhGR0dAUX77apuvDAuXqK8xhMFtzMaBJSbiih/UaV1/dlzAgRu6mo0DsjVQWs6wkTX9lte2L79CuYhsYiEu2KBEnFj4Kra/3+szlsV1qzK3wbPMXVaaDMgnKqXUsa6dyNEfyc7szR8xKR3VIgr5Cz7yPShumTGyoHaR6fU7bjxgVpfULaPwwRGl75fVIcs9yimAjpltecwjS1j4akf2aa5f+j9vTMY X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kVTTCYSNTol9yfi3dgu25fbjFqd82rgUyQbtbipDCnWtd5FjdmM+PAlv3uuNFucKyp/comdQCHfMrC2UKCxSR1vOdQYfTaIz+wEAKIH85a07L8ILYRzNqrpiD4MUeY2oXyq3vK4+XvRxkEEWI6OSufJhjKQoLqISLrnRBobxt5Z9pCL5Vmc6jDvI16IEPsiIFYtW9bFPNm7u5z+AdLHP33oKy9JjqGR7AFk+F2ynQwEOetSZqFdougchRj62MEgl9A/ZsYIZ3wu6PXe4IpJge9N/dQuUZdACIegJOBSGhPVejSIBUORF52NhtLQiKhsZNbwRXQm/cUlDlsSw/gIbis4ommT4Ju/V8GW0aakPABj6Yao1FfC/szGNIkSo1L2IJ9YcChsR+qRyvbH55zu9q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6tx5xELccIoD/pHEbWzCxLzp4f+HGWqpLkxafdE7jfZOVtAbOLPmwp6o0XpY5tV/lNTNI46lxewV6rYI4oIqO8pv+6h2yObqrMa/rLf+EMRGHcpH58usMkebPLqZLOsxgEHanCHUg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 6u5CO3oMB+f63mcFWyXXQro31n8bQS5+W2dZsPOlhtqJbIfUhkeiORF0F/maFHJEi7tqXxoh/AeHjdol8RCMUi25B3Sc80LL1wO1MPQG4YLFODeZCpxj6oqNixwmeVGMvunbX3VHNzJuC/cdoQskCa4u4Aw5OtL02h17fDkqgcVds8OTpqiTofH0RgYhSeY2UMZJvegfa2ObMnoAwJj2YS4czz3ybxVSKAq5gT69DEpkrH1RqVQzb7xAxa6D2yel80TJd7wxK5XsPdY+I2wux+nsX/NYLrFuABa2grXMKgP2PCYl82rwAo5nIVNnRAnXeUWktoENgeArBhMV/O7UQT6n51iXymnbGoAAswn2VwZPNiFwBcQm9I53yOtjQXqkSywhNdm/ioy9N4y8UoQkmSSwSM2uGuD5T0UTq9zkgptzKno6gWVmpFh1dK8rIWaeqx3x3ARpxZeNqasQlmjrPmi7yUOsmyfgURffgGSQUHLNXqk7cigQ18+eASi2bSXajyW7aDYCSXLXrmJ97MVd75varfQVLRo+0u+prucAoqF43Q05FW+F1kfxfoTWIRLMBe3lnJYDFXvl2WW4NFOMH7Kj7RySK7wqkKrddQIEiAA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d4067e71-2fa9-4653-36b3-08dd0572f166 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2024 12:42:19.2130 (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: IXbzhdledHIS3VEXMI1wuELdsBBlJFf+oLZB8L9I+dsnNT+m6hSXMLBrxj+OU5vGO61FkmjDAnoruXVIh2qqYSWz+GUnCnQ2VCiEbMptJgs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB4201 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-14_05,2024-11-14_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2411150108 X-Proofpoint-ORIG-GUID: tmQ4f_OegXEagwmH2a8LtWiayz_lGjGB X-Proofpoint-GUID: tmQ4f_OegXEagwmH2a8LtWiayz_lGjGB X-Rspamd-Queue-Id: 4B1874000E X-Stat-Signature: wmnzdww6ft37mqz1t6zykz9r96s94brw X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731674521-294017 X-HE-Meta: U2FsdGVkX1+MfZelZecHXWke5puBHLT81494c9dL9kPWPLl2uz/0SAuW0LvQXFRY7q61LBScXJRmYtLJvMAPdzCTCJADl5jAjXrTekkLhARxPckKAQgiLqtoD1xjb1Sd9z4WZLXpXnWBP0kitNWcXd3beuAHEmaSv8BsnQQMzzF27JOADf4PVb3BxTcY7U2yckt+SPqQ2exxRj71e3iuupaoBghkeMmt9C+c7YkBGOPGyCLZvphVr3LTSoI/Ie+kkHWUeeWERyP84EKW6a7klUiETdW43NI8vY64CAbi7qm83qA5k92k7U6ky/iGKUs0V3mOrl67ZTcKeVY0fkNephwyV4sfxdofzFswJUq2ET2WGEXKe+f3N+tEuSvtcZHgcKqXXn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Jkq4wUsATQw3BU2NXvEO1ExOuna9dLfCDJ5rUfvivYA15F33tbqKUFXgKr9b5DXLkwE9sKRxXrSeQrOEbqdmz8dydND2TJ55+YtlNWSmLx5G+K3ZTpTbuU+UfpuJkUSTtMZRjxH0DRTjGtW8Mvna+ie53wcN3K2K+FP4+tOBc9mKKb3z3UULoZFDbwp9SHmpj02gEkmUPn8/a0oFjEQYARrNVMPFK77jy9SAztmXaDQOG8/ZlxyLvZS1iEgvTDjfs2JPkTctUG2glYLJWR/L4Ba1IxHCU9x9soPgAQE3NlopHF87YqY4bEkSI381XmbYD+Nm+wS/SbsOVzLyj5Ti1GLK25d0rAXveUEjzCptDkPqhHbOXYQCW1/udTRLqSaQzKRhnnkN1qOYR30wFKPzEV9RsxGc75c3pSTNNGdkW6TO/fx1RKFJMTuWvk3njxN/lrEjmHXP8tKa4tq42mhY2jKcuR2hEatFZDilWfB1bTUD6f1f1vkIMALaqP wvIM3IaJ 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: [ Upstream commit 5de195060b2e251a835f622759550e6202167641 ] The mmap_region() function is somewhat terrifying, with spaghetti-like control flow and numerous means by which issues can arise and incomplete state, memory leaks and other unpleasantness can occur. A large amount of the complexity arises from trying to handle errors late in the process of mapping a VMA, which forms the basis of recently observed issues with resource leaks and observable inconsistent state. Taking advantage of previous patches in this series we move a number of checks earlier in the code, simplifying things by moving the core of the logic into a static internal function __mmap_region(). Doing this allows us to perform a number of checks up front before we do any real work, and allows us to unwind the writable unmap check unconditionally as required and to perform a CONFIG_DEBUG_VM_MAPLE_TREE validation unconditionally also. We move a number of things here: 1. We preallocate memory for the iterator before we call the file-backed memory hook, allowing us to exit early and avoid having to perform complicated and error-prone close/free logic. We carefully free iterator state on both success and error paths. 2. The enclosing mmap_region() function handles the mapping_map_writable() logic early. Previously the logic had the mapping_map_writable() at the point of mapping a newly allocated file-backed VMA, and a matching mapping_unmap_writable() on success and error paths. We now do this unconditionally if this is a file-backed, shared writable mapping. If a driver changes the flags to eliminate VM_MAYWRITE, however doing so does not invalidate the seal check we just performed, and we in any case always decrement the counter in the wrapper. We perform a debug assert to ensure a driver does not attempt to do the opposite. 3. We also move arch_validate_flags() up into the mmap_region() function. This is only relevant on arm64 and sparc64, and the check is only meaningful for SPARC with ADI enabled. We explicitly add a warning for this arch if a driver invalidates this check, though the code ought eventually to be fixed to eliminate the need for this. With all of these measures in place, we no longer need to explicitly close the VMA on error paths, as we place all checks which might fail prior to a call to any driver mmap hook. This eliminates an entire class of errors, makes the code easier to reason about and more robust. Link: https://lkml.kernel.org/r/6e0becb36d2f5472053ac5d544c0edfe9b899e25.1730224667.git.lorenzo.stoakes@oracle.com Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Signed-off-by: Lorenzo Stoakes Reported-by: Jann Horn Reviewed-by: Liam R. Howlett Reviewed-by: Vlastimil Babka Tested-by: Mark Brown Cc: Andreas Larsson Cc: Catalin Marinas Cc: David S. Miller Cc: Helge Deller Cc: James E.J. Bottomley Cc: Linus Torvalds Cc: Peter Xu Cc: Will Deacon Cc: Signed-off-by: Andrew Morton Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 115 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 66 insertions(+), 49 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index fca3429da2fe..e4dfeaef668a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2666,14 +2666,14 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, return do_vmi_munmap(&vmi, mm, start, len, uf, false); } -unsigned long mmap_region(struct file *file, unsigned long addr, +static unsigned long __mmap_region(struct file *file, unsigned long addr, unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, struct list_head *uf) { struct mm_struct *mm = current->mm; struct vm_area_struct *vma = NULL; struct vm_area_struct *next, *prev, *merge; - pgoff_t pglen = len >> PAGE_SHIFT; + pgoff_t pglen = PHYS_PFN(len); unsigned long charged = 0; unsigned long end = addr + len; unsigned long merge_start = addr, merge_end = end; @@ -2770,25 +2770,26 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma->vm_page_prot = vm_get_page_prot(vm_flags); vma->vm_pgoff = pgoff; - if (file) { - if (vm_flags & VM_SHARED) { - error = mapping_map_writable(file->f_mapping); - if (error) - goto free_vma; - } + if (vma_iter_prealloc(&vmi, vma)) { + error = -ENOMEM; + goto free_vma; + } + if (file) { vma->vm_file = get_file(file); error = mmap_file(file, vma); if (error) - goto unmap_and_free_vma; + goto unmap_and_free_file_vma; + /* Drivers cannot alter the address of the VMA. */ + WARN_ON_ONCE(addr != vma->vm_start); /* - * Expansion is handled above, merging is handled below. - * Drivers should not alter the address of the VMA. + * Drivers should not permit writability when previously it was + * disallowed. */ - error = -EINVAL; - if (WARN_ON((addr != vma->vm_start))) - goto close_and_free_vma; + VM_WARN_ON_ONCE(vm_flags != vma->vm_flags && + !(vm_flags & VM_MAYWRITE) && + (vma->vm_flags & VM_MAYWRITE)); vma_iter_config(&vmi, addr, end); /* @@ -2800,6 +2801,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma->vm_end, vma->vm_flags, NULL, vma->vm_file, vma->vm_pgoff, NULL, NULL_VM_UFFD_CTX, NULL); + if (merge) { /* * ->mmap() can change vma->vm_file and fput @@ -2813,7 +2815,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma = merge; /* Update vm_flags to pick up the change. */ vm_flags = vma->vm_flags; - goto unmap_writable; + goto file_expanded; } } @@ -2821,24 +2823,15 @@ unsigned long mmap_region(struct file *file, unsigned long addr, } else if (vm_flags & VM_SHARED) { error = shmem_zero_setup(vma); if (error) - goto free_vma; + goto free_iter_vma; } else { vma_set_anonymous(vma); } - if (map_deny_write_exec(vma->vm_flags, vma->vm_flags)) { - error = -EACCES; - goto close_and_free_vma; - } - - /* Allow architectures to sanity-check the vm_flags */ - error = -EINVAL; - if (!arch_validate_flags(vma->vm_flags)) - goto close_and_free_vma; - - error = -ENOMEM; - if (vma_iter_prealloc(&vmi, vma)) - goto close_and_free_vma; +#ifdef CONFIG_SPARC64 + /* TODO: Fix SPARC ADI! */ + WARN_ON_ONCE(!arch_validate_flags(vm_flags)); +#endif /* Lock the VMA since it is modified after insertion into VMA tree */ vma_start_write(vma); @@ -2861,10 +2854,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, */ khugepaged_enter_vma(vma, vma->vm_flags); - /* Once vma denies write, undo our temporary denial count */ -unmap_writable: - if (file && vm_flags & VM_SHARED) - mapping_unmap_writable(file->f_mapping); +file_expanded: file = vma->vm_file; ksm_add_vma(vma); expanded: @@ -2894,33 +2884,60 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_set_page_prot(vma); - validate_mm(mm); return addr; -close_and_free_vma: - vma_close(vma); - - if (file || vma->vm_file) { -unmap_and_free_vma: - fput(vma->vm_file); - vma->vm_file = NULL; +unmap_and_free_file_vma: + fput(vma->vm_file); + vma->vm_file = NULL; - vma_iter_set(&vmi, vma->vm_end); - /* Undo any partial mapping done by a device driver. */ - unmap_region(mm, &vmi.mas, vma, prev, next, vma->vm_start, - vma->vm_end, vma->vm_end, true); - } - if (file && (vm_flags & VM_SHARED)) - mapping_unmap_writable(file->f_mapping); + vma_iter_set(&vmi, vma->vm_end); + /* Undo any partial mapping done by a device driver. */ + unmap_region(mm, &vmi.mas, vma, prev, next, vma->vm_start, + vma->vm_end, vma->vm_end, true); +free_iter_vma: + vma_iter_free(&vmi); free_vma: vm_area_free(vma); unacct_error: if (charged) vm_unacct_memory(charged); - validate_mm(mm); return error; } +unsigned long mmap_region(struct file *file, unsigned long addr, + unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, + struct list_head *uf) +{ + unsigned long ret; + bool writable_file_mapping = false; + + /* Check to see if MDWE is applicable. */ + if (map_deny_write_exec(vm_flags, vm_flags)) + return -EACCES; + + /* Allow architectures to sanity-check the vm_flags. */ + if (!arch_validate_flags(vm_flags)) + return -EINVAL; + + /* Map writable and ensure this isn't a sealed memfd. */ + if (file && (vm_flags & VM_SHARED)) { + int error = mapping_map_writable(file->f_mapping); + + if (error) + return error; + writable_file_mapping = true; + } + + ret = __mmap_region(file, addr, len, vm_flags, pgoff, uf); + + /* Clear our write mapping regardless of error. */ + if (writable_file_mapping) + mapping_unmap_writable(file->f_mapping); + + validate_mm(current->mm); + return ret; +} + static int __vm_munmap(unsigned long start, size_t len, bool unlock) { int ret;