From patchwork Mon Nov 18 16:17:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13878824 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 721ACD49207 for ; Mon, 18 Nov 2024 16:18:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 16C666B0089; Mon, 18 Nov 2024 11:18:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A7406B008A; Mon, 18 Nov 2024 11:18:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D038B6B008C; Mon, 18 Nov 2024 11:18:56 -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 9FABF6B0089 for ; Mon, 18 Nov 2024 11:18:56 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4E8691202CC for ; Mon, 18 Nov 2024 16:18:56 +0000 (UTC) X-FDA: 82799723538.05.B457193 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf06.hostedemail.com (Postfix) with ESMTP id 03FE118000B for ; Mon, 18 Nov 2024 16:18:17 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="NB4v6gl/"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="Rk8L9i/P"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf06.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@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=1731946490; 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=MRrVHGDRLughqVlx4AwYJKYY2Ke4n4qbuAKF0PLzItY=; b=j1PcedSQ4Dn7cmYUe592Z6pfVkMc0EhsXrFRb6W+TLddhGayW3MtMC1zFqgJzwYVBJAH/S N2knmAmc8naG1+v3fw5LfkKZi34Irq3331OQ/f0rh50+v3z1rM5Yz9lPGGcyC/2+pH2+Wu DKYuukBxyAsuqDNCrWfSrxhLYU5dCNs= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="NB4v6gl/"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="Rk8L9i/P"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf06.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1731946490; a=rsa-sha256; cv=pass; b=aBVMVbNaxsFZccNOYgs5XW8fjYQwyykEMv5IF7c6e0Vidf6c2x3xyfL5WtIIPKEYvF4Won PNSEMMbDgSPgl7rEDT2MkIuMnosYdqV49kA1Pf2vPV4WwvkFGf2PpaneBe9qDGhT9bB3sT WVmOP0DPlEpLwLzSWUERhU6mjnBPIME= 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 4AIGGoai032669; Mon, 18 Nov 2024 16:18:41 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=MRrVHGDRLughqVlx4AwYJKYY2Ke4n4qbuAKF0PLzItY=; b= NB4v6gl/5FbjBYm8DjknXrLGi19T3bwjAug/yVuXq1+GHeikqDYjDOm3glO2yCEg 98154/IOItpmPj7lGNBWMK7B3c4oly3X61d0IxpQctMnHH2F7bCnnrOSZwlmPE3b P3CygkzZK/X2M9+46JJAbF4pO7z1kFnpsFTno+S7WHq4gV3r3rDwjKM0aUpmjZ1z 1QLmSlW4i8RmJZZL2EQ6QNgBNFqxaNxH9WyfJEH9KwV1naHH65UiSfyxYjMpkP89 q5LgK+wQETnnDKXeEokaihL2ikZIWDIkm+Dnc6a6reQ4dE6CM+i6yX+NPjgIAIDJ 5dODssgmKqb8a34azwQ4iw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42xk0sk2nj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Nov 2024 16:18:40 +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 4AIG1G5m009102; Mon, 18 Nov 2024 16:18:39 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2045.outbound.protection.outlook.com [104.47.70.45]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42xhu7gxfh-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Nov 2024 16:18:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cnykYleQF+PZvdoGuZaTx1JSX4mq1pd8c1B+HcxOzYyc+p+mHRcq1+8KYte2VAAbs8ziwkEE/pXIBRc4qo5guteFCmazfOiYY5WO4OULF+uVFymtZPWRQbJvqirOxX4XfMgbYa8J7evj+fHbUn5vHwjGQkJdc/QBfzLTrj5WwHbnm04KP2JacV3RL5KRhFzvrtKhN/ubRKvL9wQouPzG92ZCok19KZYDJcEiVCRgNmHUI61jAyodMAb0R68o0LwxRxraB3P3k8MVs0UgYwN6C9rnUr6qvodtPhEcQHGy4xF3MnyT+xUp14XeWG83MkxeX0xDoSDbCTrnFfHACcD9SA== 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=MRrVHGDRLughqVlx4AwYJKYY2Ke4n4qbuAKF0PLzItY=; b=QpmZbdsA4vGKz1/JoWoRTtW5SfOydIINF36ltMy59F8rdHCQT9txqsJnmYe3CIDZMkYlA26mrqXuOIXPrsI1/RpFz+Njfwg0JuwtSRkQ8EFTOMiVGgt1aybERyVH179rSaK1vEPYH4YY2g0nzVs0gvKxaEBvTMvuI3pOV7uue+TNylFoWZcQybRrHoSZHSd/Vr8vzdhKLYU/ap2a4dOhJAywzEt41UsJLgYGyaMwUueA0ErnYMCFzIACX29oPXDwxSh4yPHFAIgcPigJIgfwy3Nf06qzYfxBL71mC5/nC8hg5ricyILfa6TIAOwjqtExg4dlLOuz2yS2i1KobyT2kQ== 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=MRrVHGDRLughqVlx4AwYJKYY2Ke4n4qbuAKF0PLzItY=; b=Rk8L9i/PawLwM0ab1iB2T6sIlRyIttdH6locWvTOaCvGD3mOPPKCstWlHEhHA7SmpoWfaLj7xAnBSv2s3KyDnZXaIBUN3gO1/Q6I6p64kGzR7dJkB6D9Z/VDzBsQOhtDbbMha9NIP1u+6XxaFTjtMwv6fXE8j1GNWgdXg8CVPZs= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by IA0PR10MB6819.namprd10.prod.outlook.com (2603:10b6:208:438::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.23; Mon, 18 Nov 2024 16:18:27 +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.8158.021; Mon, 18 Nov 2024 16:18:27 +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.1.y v2 4/4] mm: resolve faulty mmap_region() error path behaviour Date: Mon, 18 Nov 2024 16:17:28 +0000 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO6P123CA0034.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:2fe::16) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|IA0PR10MB6819:EE_ X-MS-Office365-Filtering-Correlation-Id: 5b3d2cfd-8951-4881-3972-08dd07eca07a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: vV2subp5ZSTXCGM0ZknUUWeI7WfJT1L1hC+JgPOIAoe1oEIShHB2YVYVnkfcOYj8f0d2VE9bKiiv556qwuDO7m5Rttorrh2eeMni27ipbx0MaxtcyGTG6Yr4IoPfKELXUYHDDUfrqHyHMy6JvPT/cVnnSNeQb6cUctehWMnrl3foqXRsa8InrxaYWv8u6AcgpN++bAMR4BpaGPX/dCJDDe3de7lAwSyf3tB690ogW/huhB900BnQgORy/sdHPeOkwv3hWllYE9juT/fGGrQwJGBqHm03cx4Ac+Oa/zB59LKGZTlvBymGnZa8GZSr0K8z+GU/e3uveJsnJ7/m7Qtc3Q8sY5uS2uvS9srPr0FDoriorINQYLnEypKEZd0V0MRNsOHPdrdqlOmF/GWKpeX8WdISYpAuugl5oxQ5iDlZ6nzD4x+UBq4EhpviCvtXjdGyLcf4Q4XUSGwa9I0RAZPSJEVc3TdAg7QrLFEMi246JuIIDsc2VEQwsUYmjpa6LqK1FuwXkORtnEC5hpAmQurM14CYWUh/jdcO+FnEIy1t0JSOCdlH15WUY0embR81U66SSE37nUu/7eIJhatdVnE9CKxrKDAJdB9HOq02aybeFbK6dXYEctMt2KXAw94VHps3epjpW6aeXnca69AcRXsfMgq5AueojB8BkCnOB1HvikOxKuK6vZPvhybj1w6/BAIiw7B1hd0Ldf+Ndttx/6GeTYsmX8adUdhfCs5zluSTK0DvCWZrVZG6QxgFZ34tc20lPAA5OAgecx5bqtrBmav8V3HqJ8SaDLRwxl3XB7chN8gn2V/zoCxMi+zHLQuTILlABcTbnUFmQh9x5Nx0qq8QQVkwCxkpJ2T6P5FJueNhCckydyhSRf4qFrih+r4Ox0jh8CXVs56GB5yGNxiJWAAkIMMbVP0S/pqYRuaOn9Nz1oKub6AYOxgu1TevNloT30nnZUXWG7v7fQH8Hytu3YJQ3vj/GnCO1mUSEf3EGHxHUSU/ehz2HzW5AzDNzfe3fCviKx8/qyI9seCNulXX5O15bs9qrI4e+X+7ZOxPJBs566Y6glMqlSJorVRehYvKZ4b/+dwDEk+gCCbGRxwhR19HBPtE3hAtOUxEpBLqk0sgD4P40dvYyRaL+SomegsU0Iqi+Kjv14RxExV0qx/ZXLmI9F53+62Ix1yqgEA+vIcgQQvxiYX3KZsvrWZIN4A1KVdI+ORkFbojqqYEKo0yK0+YWI7i6X/x4Hw7O9X1RynZqmoUqt4IRNoM8qQHhVAUXOUSME1lIhFAM/ESOV/FJ2BSBReNS0laBo4ggQb7sBplE1QZYHz7L9RNkGM6utnk83se 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)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mQs9o+66NfqJNu9Yb7PJWJQFaXE62ns30pd3KonjEqZezIp8M1t0ryO60PNkraX7ZUS93yDXhdYbaERnJXVjIZguQha0ogoLjcjgKkZCaNRse0VGDn3GGL776/mIQwp8kRWPKPOs0KvSezCCq/FCpTWs55KOoxy1gPMQP9nveH+9qeihSad7Ctko/NnRb2RbwBKga2aNHWesB+SaDkZInPI9gbbt7G0vp3a+xJ+p2FxmPhyodgYoBHfSun96kOLugiHkTe6xacmlj3+RtHdSJyu5jJvyZvkn8llR98+dO0C2ZErZ/D1X+S+ePrsuIkG0ZdcuXisZzxjjkoy+aoVHpx8g96lxVaK0hXA7E/8yMIbeCTncmlWf61ZwTJu3l+OitPRnsvJFbur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FpzZACpC2CPPv+Ls8qBbnen1bxah73oKVQ9G8sUVNlWQeKMXrWw/28NoFLEkSrc53VvF1V+1unZXFcin/+gsGat4HuqTfhcuapCTDmqeyDRCSK2IPQhvFV6ZfPlyCSJJj9QYhWiNMjHfxsrj/JzFFADFw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: vYbqDmGKA/0Xq65BX9YqqJGuvL+LdyShB0qJRCfVwmG6JqvG3BXcXMkioU1VXyzTwHtiKqDnkTDr+mU8aOl1RU9zTLKiy8HiI204wI8iAs5oiJrN+6Yw5pUv9Ta5cs31YGSkvP0JcIZ+D4DfLg25DKj69HWHifgPgqgKoYuyha5B1zvqSvlsDhrRbqLYlufIMhhjdN7Ut0tcRGK9MvWUcUwvpWO3ePTgzx8tTIkj8aVFOZhDUDh0zb06s9f8+llU0ufeD1cUPhZ+pMWrnelAcY25/feFBHvZUDv1amVVlKNcS7MRjHurGuGqMX/wrQF7PXSKocO1snPRmp9zzFf+tVfL8YBrMtldjfvKzoLeIDELk52q+MoGXgx4KazXkWBodRRIoQ4Zs5bsdKTsWkHlYi2N0cMVsDm66BSNHUn+YAwptFwWlKDaixilh3CQzjglgZVwmcX3vgK47kAfgd9ZsaswxDn+d0uabH/+MJkF713HErbObgywhh7lt5z6dGl2/iqqSH3FF4SUBMizILNGaea8M6vVYq3/IBqmkLaXcJEJ9MrpsqCKvrCSQwcsxChC/ohIOATzfj0j30OewGYUYsD9JPxPlb6mOtjX4VixVnk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b3d2cfd-8951-4881-3972-08dd07eca07a X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2024 16:18:24.3757 (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: WSRO9MZcbgSJBm/udHr7q46plGDBbNRdH6g7/V5Xh7AcG0cI/B/Hc/g5mheEVGPxMezRvSJRkvg0ZP7ySac92Ac+oAOcJFd1CpLKv7Nz71c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB6819 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-18_12,2024-11-18_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 suspectscore=0 adultscore=0 bulkscore=0 mlxscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2411180135 X-Proofpoint-ORIG-GUID: FBo21Tb_ueMxPh26xCT8TRDS_g92OSh0 X-Proofpoint-GUID: FBo21Tb_ueMxPh26xCT8TRDS_g92OSh0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 03FE118000B X-Stat-Signature: c643qt5tupnw8r8tq4qash47mdq9jnmm X-Rspam-User: X-HE-Tag: 1731946697-946714 X-HE-Meta: U2FsdGVkX1+eH/GwNak9Z6xeY5C2iraTa0zoepcAwYze1yyyYwQ+VSsYYeRmVifbbHD+rsIrP/bX/Ae/a5D25WF3S/0Sus16lUPtgdGfkrzQccWEHHOyShl9daiaaCQNsBlcvtneZ2klUTSgAYKH0fpymX8bBN79MEuEbldHwXcG4DH5x7VpHpuBDGCykeqN3KVFiQQ7h/I1uChEzbFzMhQi6YpjxdO8zZuxkFRrV2DJ0cMBM6nvBJNJ1j5vmKJTFxAb7vW4c7rxCHU2JjOW6FtQNXL+Yw5iPLWW5v8Zuru73BASHYnmUVivLNwWY+0O8mwuEwxRiv4QAu2Ff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+Q33Vhz67ETX3ITegWCH4DVROyAxrespgY3q2KMeXl1T4AGQCDNA9Xtu4+jgcHeQ5GVJa7OT1vKwlX1JIs4BSV3QTi0z94Eq0/ZA3Gx6f1yGidVb6GQ7UeeONxWdLdhWP2zEm6QxZs/0q2wl+e+JtmoVlZ3ZkaVXGOSRPmoJoRv7X36SGc10ZLnIggrycayVoMCB/nbRMfXmGBy4f5BP6qowc4JRuJ0e1+GTqL59pPJLY2kN9dGd15o8HLM++08qMxaFWj7DjCV2gecD0Y1JOca0pEGl0vg/STM//8R1KAJBZAVALICuRopZddc9GdqzZKAkIj77M20F/q8Iu9LakfPsN3LeZw6VuBWgK0hTV1ZJ24ebMy/FoweFTAitpxeXpJTZuPbnCDoDoOpQZfuJmA50zol4U7sNCGmFqgpHQ6vIVJ0OwJso4MstTM9fqMjC2J21nCmhuBfHMsO+bhDeiV39q5JWYl28ylj0NotGAw4Wqu0giKZw9bem2oP5r88bm7ZfR/gWVDmjY6Yavgt4QN10gUjrs6RcRIFKyyqI6DRTKeaEVc JdHVfzTQ 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 | 104 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 57 insertions(+), 47 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 322677f61d30..9a9933ede542 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2652,7 +2652,7 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, return do_mas_munmap(&mas, 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) { @@ -2750,26 +2750,28 @@ 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 (mas_preallocate(&mas, vma, GFP_KERNEL)) { + 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. */ - if (WARN_ON((addr != vma->vm_start))) { - error = -EINVAL; - goto close_and_free_vma; - } + VM_WARN_ON_ONCE(vm_flags != vma->vm_flags && + !(vm_flags & VM_MAYWRITE) && + (vma->vm_flags & VM_MAYWRITE)); + mas_reset(&mas); /* @@ -2792,7 +2794,8 @@ 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; + mas_destroy(&mas); + goto file_expanded; } } @@ -2800,31 +2803,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); } - /* Allow architectures to sanity-check the vm_flags */ - if (!arch_validate_flags(vma->vm_flags)) { - error = -EINVAL; - if (file) - goto close_and_free_vma; - else if (vma->vm_file) - goto unmap_and_free_vma; - else - goto free_vma; - } - - if (mas_preallocate(&mas, vma, GFP_KERNEL)) { - error = -ENOMEM; - if (file) - goto close_and_free_vma; - else if (vma->vm_file) - goto unmap_and_free_vma; - else - goto free_vma; - } +#ifdef CONFIG_SPARC64 + /* TODO: Fix SPARC ADI! */ + WARN_ON_ONCE(!arch_validate_flags(vm_flags)); +#endif if (vma->vm_file) i_mmap_lock_write(vma->vm_file->f_mapping); @@ -2847,10 +2834,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; expanded: perf_event_mmap(vma); @@ -2879,28 +2863,54 @@ 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); -unmap_and_free_vma: +unmap_and_free_file_vma: fput(vma->vm_file); vma->vm_file = NULL; /* Undo any partial mapping done by a device driver. */ unmap_region(mm, mas.tree, vma, prev, next, vma->vm_start, vma->vm_end); - if (file && (vm_flags & VM_SHARED)) - mapping_unmap_writable(file->f_mapping); +free_iter_vma: + mas_destroy(&mas); 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; + + /* 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 downgrade) { int ret;