From patchwork Mon Nov 18 16:17:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13878822 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 C4BA3D44009 for ; Mon, 18 Nov 2024 16:18:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C49B6B0082; Mon, 18 Nov 2024 11:18:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4742B6B0083; Mon, 18 Nov 2024 11:18:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 252076B0085; Mon, 18 Nov 2024 11:18:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 00ADC6B0082 for ; Mon, 18 Nov 2024 11:18:52 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8FC9EC031A for ; Mon, 18 Nov 2024 16:18:52 +0000 (UTC) X-FDA: 82799721984.01.393CF08 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf07.hostedemail.com (Postfix) with ESMTP id DB53E40022 for ; Mon, 18 Nov 2024 16:17:39 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=C9Mw7j1y; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=e1FzDHBy; spf=pass (imf07.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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=1731946549; 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=n677DzD/vofqdaHKQpPiCq3teUv8/eVlhrcSr5BSnVM=; b=lRlx0WtinLPiO5LUnwW5ATgP75jdcDa5xDvFuZzyNrh86yjIuzoGgHXzVm8HS5QjD+1dcs lMSbE9McxghnJuc2FSzAFtdaJAN+uiXGFV83UM6nwohInq/GrtHrE6Cqkc76o6eOLJMfqu s+6UMS44Ie9J7FfSwRCFl9fF94M6zx4= ARC-Authentication-Results: i=2; imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=C9Mw7j1y; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=e1FzDHBy; spf=pass (imf07.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1731946549; a=rsa-sha256; cv=pass; b=vJdFrAOZy+jUthDnhyKmdLweq+U1R0RnQ2jRgU3qY4AlEYq6c+GVlycs/t1tEjVMp/rJc7 nFEE+rFwxwb0FI7xv2Cz0orD0RgASiRki5SawlPioYLG7EL9uTXkj+PNyg0nRJCgTPiHQK kPBwkOwYJBrgdatlyQDrRdfpfbVF02g= 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 4AI8R2ub011100; Mon, 18 Nov 2024 16:18:34 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=n677DzD/vofqdaHKQpPiCq3teUv8/eVlhrcSr5BSnVM=; b= C9Mw7j1y4KtZ3qckz3L2nDH5GF7OUQw7njWsmGRKwmfE0vDlC36kRaKvqsQKlPue ckEdFkLcC+AjfPbsNBFw3QA6zVfltn2Vsp7MozjM2YyQDVsa4W0W/kD2GvP7/zZQ f1TpxHAm+ZQUNpY3xhatSVF1cddPxCiNOBNjixjlNd6PBigMjhnUO3tlMnLl8yIx e/A97sqmQCj7QHrzOb8X9TelctkPXRXAe4wmLKEGCK7Ma5L01rjdC3VX4DAcxs7G RyN4y+MpqlHSD9Kjrz0uqsCswmi+6l/+0ME5XXdEFy1qXmv3q+SLnVxStEM6HbOp VMKd43tWWDJLsELDQjPwBg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42xhtc341d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Nov 2024 16:18:33 +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 4AIFPi6R039269; Mon, 18 Nov 2024 16:18:32 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2172.outbound.protection.outlook.com [104.47.58.172]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42xhu78bdx-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 18 Nov 2024 16:18:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=l6Lkp3Phv2GNO1HWDoSqAkSi+feWCIJk4sosigJGjvO2sFzg9HR1/vYsewBW38Td1GhBCATJwE38W+7w9P5dlAaUrkZrH8NC7qP3KvmQ+8HSQ/YdhVUUNRjenm5yixQPQIIsjiicJm8ym8jVSEgk1S34EWGDcWQhe6bpxsjByr3WM4UCV0pXvhjtFAWqdYBuoA+EiwzIgj68Zm0p7N+j1dlbST26hFvAbv/xKl3uy8OnkonZiCW0xaDzSbhVbimRApikD/5EJJt7DJGq9QcH9H0BAygy4CRfJ4osoIOHI7XH/3MUjYfdLKxJrpyBLs9R5Uui1iiqWVOnzb0XiYhpTQ== 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=n677DzD/vofqdaHKQpPiCq3teUv8/eVlhrcSr5BSnVM=; b=daYf5txv0qw2+KObYNtBXUISXjolKfg4dEqrxhnMhW7mI9uolysBfqN7umclxxMtzp98/C+Cd0036HlFPXCqZ5W0eDcFXAHMJDMbyhTLvZ2OOGT9N6s8NCIWRIf5WzJDi0RG7OLKh8AyI/sgVLP5Jn/qZjj3BYbwom9WvpzSgawLwVueBUmPqFBKnq4ftAVbjfRN6hUSiUfDFEzx0sNLScGT3PZ4kMJIYsAsfEp1ZXsaxn66KaKPZgUAe68JH8FsgJFPes9w0ICbvtaS19CUxRdMOtdGtEBJzTHuCHhwXyHE56ipZWUPcrwoXaXkZ8+mbVY72hJm9jWYAaoh18REeA== 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=n677DzD/vofqdaHKQpPiCq3teUv8/eVlhrcSr5BSnVM=; b=e1FzDHBy98dxMyeMfON+V8NSVZ/GSY5GMzitf1KxasSB7VXwK9F6KowQFemA/w+WV/itDESfwVJGcN4yIRp9umDtoC/0P/pSy8e6hqw/3zzaBMtMDvSuPSspIdBKPIxPaus6xGV2vQ1F2Q2jmre2h1ll52NmGrdNkUgg7fpDYAQ= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SJ2PR10MB7619.namprd10.prod.outlook.com (2603:10b6:a03:549::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.20; Mon, 18 Nov 2024 16:18:15 +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:15 +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 1/4] mm: avoid unsafe VMA hook invocation when error arises on mmap hook Date: Mon, 18 Nov 2024 16:17:25 +0000 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO6P123CA0012.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:338::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_|SJ2PR10MB7619:EE_ X-MS-Office365-Filtering-Correlation-Id: 73313726-e6d1-4e96-20f5-08dd07ec9af0 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: xLJ0lMkVIz1E+3mcPoFq2sgaVaU8NyJl/TvdHQ+tCIeqGCkcvnt87puxwfIMRr7ZUK+du8w2Am5QAWB6lUrVlfDW/d6tuk77Z6QuGJx/yFcohOIiFKBqLSYyqVEGEOpHaeFivLWWAO08qcLUQJ0bUjHLHaBA0ad8cGfmRy11jswpVUQQ88YctdIFcme3L5AT302Y1ry277tTR/65DPB5x7hRIGr7Fvmjfgiks3VzKBLMyxX2dS8vmeW2Tb5k/vbnoTZBn0+N9nj91WJJQ9RsMVKZca3FnOmBEKULK7wR9+gvIgguRnO8F6TCmRNa+qIC4vwowMnGy9bb6E7eiw/yh5aqjnNxs1YXSuzILwWGNjoSG1E5+2utuOLx697H87icFlW9PJhwRHbb1nR/mpjQiLDwr0FNd/hjlyLpsssKqW7WUGNKZbFIe8fDniYsQFcvqdG/BcgEqIQ9aPogvs8qmPvZB2ZlAdM75+iadzbvRJ57hnAOFFV19C1W5itqyNL2s6rh8ccEjmhkVKGJMlqCZqUZdTLj9enXekd2PTgaV8EiSSS4/foeXOXS7fKopXTqWyaepzi6Dy0g2gfoUdd/CnLWI6YIJTVi5kZimnreL84bnxA0Af/JzA/BREVchHGI7bb1mVkshY9MkXkcqxJALTcd2vZ2kHsTGxSaWtplCgU/YJc0C20ORViYeXkFQuPNtZE8k5fBuh0zk+57NBhn5fqRMZV2Q3EQ1pRD/NEHzIOrIVLn1Qwi3NtuNWBcRai62vdD/utPTzaZG6CjiAQP8639YEF2Q7swttML4rvNMz7DZ/T1kqgPfy7k2o1OP2K+Ojb1Myr/62AipSiJmfj21F12TEkhHGflIkv47qujrPkAKRa+r128/bvnl/R6+R4zGP5awhxHL5BWN6oTK3QA5lHTx1X6Al42FLhROOm2CdoUjzvgQn0gpr21NqP51hb9FJWtczITPgmi0sfRE7gxcCFiYq4pp5xkkZbbUvvk92BhpqZWJFS221/4sJgvveERHXJ7OrgfWfZ6jbCTvSJai93QVQZyoD007nMvinbtdxyPoMSg7SDtVFKgLUJ8te1b3oluA6fkh5fopFElaHChdvAFqPAowLVUldxrGX8yAqt2OoLYvZuKlpXXDGAtlkOIAuZiRfFRVqQ4ugNicdomicXQ5LBHzfGyzHMgYPuQBTJS7gIONZtKwBqgK+limXAKREuJMJACyqk929JyyC47M4qtEsbkx6w3RD7ZzTsV8W2KLbhZKtcJK6dDBIsAiLvqQDGOThlD23tK+Te7F9gmn4rmbPWEvxemQVHOg0s5XIMLlMVc4uZkAp4aQvq2qBbb 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: qwdCXglZeY0MW7NO+1Nd2YxlrlLRWK2EpSl6/HRFIQBNwwm5nNxoXY1uDI+Ieb5OUQKpujsL9DPw7aBlfL5am9Uf0nDOuZvWFiDHtFAvMd9lC+CEGdoIHsJmqlh2Yk87tySjFbubR9bXNfefeHR0mwpRaEYSOQUVOjxiLLWfSqgIdTKAfiQprICVqJBcCd/Q8BgBgdhZmkvjEIJAsD+krd2BFdB+sTIf9p76Ba72ylJxFn2KSLH0W7JUxVvxceqfR52EnhzOSPhrEoxUG24ZoWBqbtXdm7LO6DRRK1Bhqt8vFwdhqrDqTbTsVL3ss/s8iNP1+bugFBHkg+pwqRjP+hWO28i3VD0oY/16psS/eKf8AqXLWuaoa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VGDsaAea0FTFFl15tjxFRCvVXuUhixl13ZRvhl6ofLGo21ECNsC7bjT7tlSJCGhfBcy1aS3ht99lmRfU8adrq/oSI6+K0LuJotUEZWKiWNWTn4cJC8vDwVOUiEx4y9INu+cZfIQf/LgAm24U3s1AjgieySp5zcSK9w== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: C9PvO/plObP3PHclyxX4YjwjHhUMr+npa9MCysNO5F3ZTSa9z5LQhANNUN74ykqiVaZYLMLHJSv1mVA6DFhvv5mINtvpEdTyc9Gvq0dOc67BmZS3y4FdVXborE+3p/FEQA4LN2zh/5tUDII1pwOgp23HGrJA1uqAioZ58e8qVzGrsxjozYwRyezJb195hX6T/ghf3bIV5gAK8lE07wucMuGzbHgdoFbBl8GQWHTjiZpA6I0AnQ5a1bgpMxpQ4qVcgQgTosDxdmYguogPW5acPtG0iTJ2quThszR/V9/Mql/yFEepp3Asyty7NvB26Tmx3j+Ucm4bRUJ/mb/brb0wO5a3tGnhtPLN0hJ03/W4bh8K/724ejUjAEK12CJl3S4PyCnWM2pSNRAnOo0z/34tOWd1MOeMtoDoh+B08oU5sazussp2q1RiUr/En3Nj56fDJ0qspcLhkTxm4tofXLyNq3ngPpeF6yklhPdl52mF0/nGHTSwwtUu2cY2xv6siNQvo4vn34HmNqJuAy8jz19Z9Xt5Gp0Mj/G+UD/45KYTL68kxN8h+wdG+nzHUFI6iF/+SbGjb1gqGdzBVuPCCvbGUB6cgPep3BSncCrxdxGpUAo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 73313726-e6d1-4e96-20f5-08dd07ec9af0 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:15.2244 (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: 0sdrATx/udyTeQ2j+bXhdn/r62RaKTdzucerfkxJyuXmBFuGO1ET3J+Tkiw3jg9az0K/Eq8bqbATo7HQknuffHuwHjSW63cf46sCs5cTqys= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7619 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 mlxscore=0 spamscore=0 phishscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2411180135 X-Proofpoint-GUID: qGUQBavZK78VVyz307kCXBkpWgCsEw4l X-Proofpoint-ORIG-GUID: qGUQBavZK78VVyz307kCXBkpWgCsEw4l X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: DB53E40022 X-Stat-Signature: o5u6buyan1egqpcomkbq5jwqrhmjpqrp X-Rspam-User: X-HE-Tag: 1731946659-609971 X-HE-Meta: U2FsdGVkX18I8dIPv0xusm0JjmArrcNzM779/R0jRvXHEJshQm1uN3XdFYIozo0u+gwsNRksl9pL6fTq517Pf3DPzxMmdLKNdUqiLdD0vUjvqmQIBEE5wSCZs96/C7S/Hl2I6unC4DufOBJ9Q0NmXidwknl8OglS+E1x8oMO7i0CJOoTCEZgWlEQQAccw3PXfiDmnlqG/ffSn0owGDNB1ONMBt16n5ZeLWlmdoakm9Yy8s5mlJIKXOBGgDaFfd63lJ2EP5QOdmYmd+C/i8I7B+c3TruTQPi9UkAfeg0p5Pc3aLIVki2poKZJ62Pp2g8u19Xv9G5qLxMxmiDbRM7qBhCq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b7blq6y+gjkjYQt7IYytjq8LCYX0gE7H3hb29roVp9F+0e906XNkTXzf0ms136lLYmWacId5Xjxg8Yfwid8m/F74LQ/w6Gqp5jyyZlwlrTyE0g7N/NTTSJ5Muig6oZAvgdiLkQH60lSJLYwlvzAww8+GBoVxEg84aLyxAshE8Ss3JxP9n/1eKq1zCRGPo7HUhe3hGHca8zqdFiVHZ41nrEAF7p5neioz92M0Cl7IQ7HOMc10WE1j28KE2hF49k058iJrcm7tN5ruehTTVtMgcIQgCZxmj43y9L009T9RcvEVJpBGH6yBQM8ISySCMwQckH7pLoZlalQTNxkil/1w+KMrX6w5mLF6fp9l2HIMF5FVaaXmA6mdlwWJygNlyK7+ylWg8dfAm69UfxsBuk+c/UK+07mhL9Uq1V1UpO8a/2aqDmum0fXSvWQq4AN9Puvd8CcIUbpYmFSIUfGKzLJry05CYMZVyXiekaEV3rAf4FgIyzOiL96V2w99cYVOD6quHd8r1YUNkLwSKI= 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 3dd6ed34ce1f2356a77fb88edafb5ec96784e3cf ] Patch series "fix error handling in mmap_region() and refactor (hotfixes)", v4. mmap_region() 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. This series goes to great lengths to simplify how mmap_region() works and to avoid unwinding errors late on in the process of setting up the VMA for the new mapping, and equally avoids such operations occurring while the VMA is in an inconsistent state. The patches in this series comprise the minimal changes required to resolve existing issues in mmap_region() error handling, in order that they can be hotfixed and backported. There is additionally a follow up series which goes further, separated out from the v1 series and sent and updated separately. This patch (of 5): After an attempted mmap() fails, we are no longer in a situation where we can safely interact with VMA hooks. This is currently not enforced, meaning that we need complicated handling to ensure we do not incorrectly call these hooks. We can avoid the whole issue by treating the VMA as suspect the moment that the file->f_ops->mmap() function reports an error by replacing whatever VMA operations were installed with a dummy empty set of VMA operations. We do so through a new helper function internal to mm - mmap_file() - which is both more logically named than the existing call_mmap() function and correctly isolates handling of the vm_op reassignment to mm. All the existing invocations of call_mmap() outside of mm are ultimately nested within the call_mmap() from mm, which we now replace. It is therefore safe to leave call_mmap() in place as a convenience function (and to avoid churn). The invokers are: ovl_file_operations -> mmap -> ovl_mmap() -> backing_file_mmap() coda_file_operations -> mmap -> coda_file_mmap() shm_file_operations -> shm_mmap() shm_file_operations_huge -> shm_mmap() dma_buf_fops -> dma_buf_mmap_internal -> i915_dmabuf_ops -> i915_gem_dmabuf_mmap() None of these callers interact with vm_ops or mappings in a problematic way on error, quickly exiting out. Link: https://lkml.kernel.org/r/cover.1730224667.git.lorenzo.stoakes@oracle.com Link: https://lkml.kernel.org/r/d41fd763496fd0048a962f3fd9407dc72dd4fd86.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 Reviewed-by: Jann Horn Cc: Andreas Larsson Cc: Catalin Marinas Cc: David S. Miller Cc: Helge Deller Cc: James E.J. Bottomley Cc: Linus Torvalds Cc: Mark Brown Cc: Peter Xu Cc: Will Deacon Cc: Signed-off-by: Andrew Morton Signed-off-by: Lorenzo Stoakes --- mm/internal.h | 12 ++++++++++++ mm/mmap.c | 4 ++-- mm/nommu.c | 4 ++-- mm/util.c | 18 ++++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index a50bc08337d2..85ac9c6a1393 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -52,6 +52,18 @@ struct folio_batch; void page_writeback_init(void); +/* + * This is a file-backed mapping, and is about to be memory mapped - invoke its + * mmap hook and safely handle error conditions. On error, VMA hooks will be + * mutated. + * + * @file: File which backs the mapping. + * @vma: VMA which we are mapping. + * + * Returns: 0 if success, error otherwise. + */ +int mmap_file(struct file *file, struct vm_area_struct *vma); + static inline void *folio_raw_mapping(struct folio *folio) { unsigned long mapping = (unsigned long)folio->mapping; diff --git a/mm/mmap.c b/mm/mmap.c index c0f9575493de..bf2f1ca87bef 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2760,7 +2760,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, } vma->vm_file = get_file(file); - error = call_mmap(file, vma); + error = mmap_file(file, vma); if (error) goto unmap_and_free_vma; @@ -2775,7 +2775,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, mas_reset(&mas); /* - * If vm_flags changed after call_mmap(), we should try merge + * If vm_flags changed after mmap_file(), we should try merge * vma again as we may succeed this time. */ if (unlikely(vm_flags != vma->vm_flags && prev)) { diff --git a/mm/nommu.c b/mm/nommu.c index 8e8fe491d914..f09e798a4416 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -939,7 +939,7 @@ static int do_mmap_shared_file(struct vm_area_struct *vma) { int ret; - ret = call_mmap(vma->vm_file, vma); + ret = mmap_file(vma->vm_file, vma); if (ret == 0) { vma->vm_region->vm_top = vma->vm_region->vm_end; return 0; @@ -970,7 +970,7 @@ static int do_mmap_private(struct vm_area_struct *vma, * - VM_MAYSHARE will be set if it may attempt to share */ if (capabilities & NOMMU_MAP_DIRECT) { - ret = call_mmap(vma->vm_file, vma); + ret = mmap_file(vma->vm_file, vma); if (ret == 0) { /* shouldn't return success if we're not sharing */ BUG_ON(!(vma->vm_flags & VM_MAYSHARE)); diff --git a/mm/util.c b/mm/util.c index 94fff247831b..15f1970da665 100644 --- a/mm/util.c +++ b/mm/util.c @@ -1103,6 +1103,24 @@ int __weak memcmp_pages(struct page *page1, struct page *page2) return ret; } +int mmap_file(struct file *file, struct vm_area_struct *vma) +{ + static const struct vm_operations_struct dummy_vm_ops = {}; + int err = call_mmap(file, vma); + + if (likely(!err)) + return 0; + + /* + * OK, we tried to call the file hook for mmap(), but an error + * arose. The mapping is in an inconsistent state and we most not invoke + * any further hooks on it. + */ + vma->vm_ops = &dummy_vm_ops; + + return err; +} + #ifdef CONFIG_PRINTK /** * mem_dump_obj - Print available provenance information