From patchwork Tue Oct 22 20:40:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13846147 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 8BB24CDD0F4 for ; Tue, 22 Oct 2024 20:41:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48B4C6B00AF; Tue, 22 Oct 2024 16:41:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3ED1B6B00B0; Tue, 22 Oct 2024 16:41:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17D6E6B00B1; Tue, 22 Oct 2024 16:41:15 -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 E93236B00AF for ; Tue, 22 Oct 2024 16:41:14 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4A4F0A0503 for ; Tue, 22 Oct 2024 20:40:44 +0000 (UTC) X-FDA: 82702407270.07.4A4602B Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf20.hostedemail.com (Postfix) with ESMTP id 5022D1C0009 for ; Tue, 22 Oct 2024 20:40:51 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Fm0cjR99; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=aGJLOcpg; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf20.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=1729629519; 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=iYFdRZtxK3YWDV2kNLEF9wGq/1fKTAuij1RdPiYsVFg=; b=GYS/qY7DREen4OBMnNtDRbq3Phnc3geYU0tABcl7vbkqdIeZdaEXOE4dmps3okO+Ih2s0r w3g+Kbq0Uny8LbbjpthZZQPK55EaswxDZdaTwM5mpFoFuqAj7OEVP85W+f4jLJCslOXRdi ZolT20usm3bR/vd3r/EHPqIy+1jiEbk= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729629519; a=rsa-sha256; cv=pass; b=rdBxvj0xiY+VA9A1qjwRFl7kG9vAHkDbpLRcncyKWOAqMhe0oYfJ2zHoopy9FWnFHPMH88 XZzD2HHBjtk0tWeUeVEzNvCJzUyvrlh/ihzJZMiFTwJFmUzPZjqRh/Uu/77jGPA5755n+5 UMyFjnemaGyjtUSR2EFOjpOJgUQohIQ= ARC-Authentication-Results: i=2; imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Fm0cjR99; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=aGJLOcpg; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf20.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 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49MK3Wt4025707; Tue, 22 Oct 2024 20:41:09 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=iYFdRZtxK3YWDV2kNLEF9wGq/1fKTAuij1RdPiYsVFg=; b= Fm0cjR99ocgVdxgL7Ky62AiHNGhtHszKgm6g/+O4/Y6AoVAJo/yMbTPjhB1BM9XJ mU9yvg+jh1LWd7iNd93Ti22rFi6hPrpLBbqi7/2+lpp3IBrPffCi3omRQsmCTNnQ Cl8ucla6GyvPaPgxlWGnMfkM/SYAad7P4qLUyL6k1xrn7JqlyWd0dTrV7wRdtK4n HoiQzawBeFOVVKwbPqNNMqp7vMWr/QC7o8ScfNVzCZYF/C3Ap0BgjfV8O3l29S0F +LJXOIQuJJi98T0ZP6EluassC3LvAKsmBpUsrPPsB5zKevW5eBrzvU9geVm8DoK2 9tR1pUd3ayatb8iQBRt8jw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c57qendh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:09 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49MJnVOJ012557; Tue, 22 Oct 2024 20:41:08 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2041.outbound.protection.outlook.com [104.47.73.41]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42c3780p3w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fLFkM2c6jabIaGB9NvkgFBRD0d3iFEhkieHc8LttAf5OjAFbet7p9sMFufP6F+l/S7irILPkXLdk5rsOTCC77d6J7Dorj7eulPSEVpVz9ZpydWYFkp5gnP8j5BLIfjRtzIfjtOlJjrkXEfWJiY9ZkONiDf5pvub8ohLglfbA4lsoOohL819naTWizoz2i2ZRY4nVOF6zac6+pyJjHxqRJM39S6qGtFnjDXe82XTZcxP0Ihb8KDvOjb46F6UPKc5iPYoBWnOBYz8FsjKOKZ4pJy1q/LmoFakwDbKPhgqAwmqhlDa0xcalWOG8mt1ZNHVSQAKvi4OWpIs250nPxc4U1g== 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=iYFdRZtxK3YWDV2kNLEF9wGq/1fKTAuij1RdPiYsVFg=; b=Qnqa7rXaSeTFfEBGMjTSYj3HiJ1bpoUS0gFqGgHEkFv7tDvGi2R5S/5KO6xZNkTEr1FY2MFpitSqTZwkBIDAqJKNOb/PnTQtG/6/HBlwbrlkGqzt0hMKbOaWLHl3VNXUa9KiMwmNoPnYgOpHugKoYynV+f60CKvaNPkNtYXSUuDabcdn78TdImkoxMjaa8/QQBuPLcPYTH+bCVCuGl8hRztHKv2staS9Z9DK8RBXUlB4M5SM4Yf9/cl9EMJ8UrfcBvUzcqGLH0BGMRCEH7SOjI9fe8TLdzj5/+6+KoXBDsqkKn2Krtz5abW2XuKNm2Bo68bXGBNN81bEuXWhQGctyw== 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=iYFdRZtxK3YWDV2kNLEF9wGq/1fKTAuij1RdPiYsVFg=; b=aGJLOcpgTq4B2jVrDIdDtyIBsT9nEtQ7sz/lOEQNFtFM7OTxXIVKsFfumqj8sLRCpQkmqIs1os8qMeASdaQE7jzg0eecc8OvKZePA4y/ov2a80V8Nppd28aD4clVVTMHJ5MXN8j92TNcuhiSVt/jx0jSwk414QRSChB8IkRkVMs= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by PH7PR10MB5879.namprd10.prod.outlook.com (2603:10b6:510:130::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Tue, 22 Oct 2024 20:41:06 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8069.024; Tue, 22 Oct 2024 20:41:06 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH hotfix 6.12 1/8] mm: avoid unsafe VMA hook invocation when error arises on mmap hook Date: Tue, 22 Oct 2024 21:40:52 +0100 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0381.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18f::8) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|PH7PR10MB5879:EE_ X-MS-Office365-Filtering-Correlation-Id: bfb2990c-65ac-4234-bbf2-08dcf2d9da37 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|10070799003; X-Microsoft-Antispam-Message-Info: yqSyCZZK7ce9SaRWsdXgMFtZiY+ntTCawqaZ8k1AhI/LPkwAhoTsENN5ax4GwbTGHbd0+gIRg2DViL9ORfkOZKIKqMbwXplQbWy4Epqb/T8XTRPK7swLH7RR3Pez6DcmIkMBFgjWUT1clzGcRYhdOt9CxAyfDJq+OR6bQYQWPgGJMZ1WyCVN3Pc+jipiQFPO5Alt+ViorTf58Pdym4F5BXmnM8VecjDAXaly2zHN3e71Bq5cC7/PQFF1JHJSa19oBYGodbKurt3ED2XKrzvXjZU5jxPOPjoeGZeCpOsKLEHkXSYl0cJ287E/7LL7nPWc3T8uXiKJMcFFa08kXTj5Yxq2/hO7/67jWQs+zpXSTFvqnK3hxoxoL1MpjuWRZGeTyxk2kr+MSYQOHNe3kZSUA+gVbbUfZnxzs0GxbhHgMYz6ZpmgYlrJs1JP9cnIxbbZr6LGn8Wu9FVu06Xn1CE5tiAA3wAa5BEd/pZoYpWyq9sphsrH1K4MGHNrkquEGvTxqmTeA8EzUHZ95eRvV+VbdFurNweHz+Ng0yR3D5anCYgTgTuMZzN7w+iZ9CugXthUnWUp/8ER4b2b9xc8Sr/4r+QPga4EarhDSg4vCwKVQiftjO7csKAr79ZJkf434BZ2BAE1AlInxnx4rfQ4l19sYu7EMD1YQHMgHgO+jJpUwhVarqz8CYJju+it6lNQgrTadZyNozrqulEXEytULW7XoWlRwx+S8jRy+XWtn/AyOOaQ4KN/5ZlCMbCxhnTOS+xxdYhy6Ypzt+Vap3w2LZSK/vtgb87HH28jRkIeLCCQtFCnclC6wPK27EYYWsVIPKsW6Lnxj0yk1nFw4myfGHReEIOJ2Ka+shtcrNQCivSTbTUQNbJBHpcSkOyHaE1STQglWhr9jHv4vUO8CVn7NBwE8oKcW2AHLsISxvFwhvv1pndBxVe6n77xOS5Y2gc2HtLldqnMDTvMeru/aXnXd19IQyuLCKkS9A6COBSMALITnczYLjFAQwLXmTpu+NTs17TOwInc0veo8uOPXlIn8bNoymAWJm5yLYgUcgx9Hu83bm0LK+H559v2SI9nKKycHlhegqMKVt2n38pwGBaUlMJ/+IvSz/ZURk+qy3wGZ5o4mzGi5BDtFL/WxWfdW4kyFKeglEa2Xg6TbBJuVcxQN1xjTEf5EUTX0Es2EgHdtil8sH4+ImeIgNe9CJSFJhJNCH58npUylO9eOQB2Jn9hRUlJ6EBnkTt6yXjLGDX0xw4wvBwanBylrS5ZgoYruXYyOouP03aUJ9K4By4AlkhqlyoghZffbVQacZ+mEWs/QcHTVokLrv/vJw+FOesiH3coiNcm 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)(376014)(366016)(10070799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4EFOZLY82UQQUT5TcDfVvJErsCLAo+YkaRDaVebfMgcwE72YVFyCjzTeec/pZ7odI4qCGNaQQ+33wtohHdi+ILMY/aZxYrdVdk+X3XOgXp8TMJbxIFWrRoCuvOReAvieE5WXI7ZE0IXwmPGdpaSpAJuz9mSvc5OLb1KOfqIyANAr25LJKnf4gUQhWhbY0X0semELLmYq6aIjfv9ryxJcF9ZbGH75lzukGitEe/0yc1UgT7YwQXG3fCesO7N5+j88iJPJzcglA/usVRO6oi8PI2/Sl6Uhp6M8vUWlvqXzWs8BKwFM6Qq7zA8WWnLuWxP40VlVNh9bxYLJmK7AruqKJb1bOnrHMtY202GIPh4ATgKqX48yIaRzb/Yo5e/bqBs5xmhlZGpIK2ksXbD1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T43b9TsUDvCSVjxoj4MnRgg6AHU880jgV3l/O7uJpUMvijvtnXbe7IzGgfG5hJmgOvt20pkBRQhFFVBtFUoLcK1+VumzNUoreGQXBDZhi+tARY8Uovf+x7O0hs/HKey3kaVixzirLNo0lbZuqm40JQ30vaTsKo392FccZiUiq5pUXDcWrFgFEJTMfWDa4ww== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: OAN6fGUaUQWwmSC29JWzZxVjVStP+d3v2gctyn954aPTjI0zjBMFawxMzuoJRamCGeDaaV8gHNG+efligHCrNztbJh2LJ7vdhmkMs8ES0vRxBwn5j5sSsbJNjBiiKMr+AnPIdgTkmweQzrJE2n/VU3KTV4oaSt9J3fI1LKiWc7/vhuAMSxHNbuo86jMomOsnypv/hAq9yh3dqPg9R/COem0GMKW6Xgk4jBV2x8QZCYpPoDHPufriY34zilVI2RNgVZu55xNFBB2mSKF57oZizhz9qnYpGjdE9k4MnkcjrZh2BRpacFGJmjfagzvCXNiJXMt3rYMIEi0Ur3C6mSRpITnI1NEBi1BdphqwPtHrwGGbeJwpCvu66CKA9kOEXkArDJ7blvnBrTm2VOoUTfvrHLnIB/hyicnIpgSxdJBRkGzX3Upuqs9zpWNdKPWMcS+Zy16oePFkInJuncFu/i3biUo1vpb5YzFgd0RWQ2neIPivUo8mhY2uhblJqJLy7EuLVdbvLD1aztTHa+NTT14m3F5vKonZIhf3OIFekfhi/fhBrVuZ40ojCjG2xkVuDlURRAarrcqYQed5+UC5wJlZCogoxl0D1o7GR6QkVRONRa8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: bfb2990c-65ac-4234-bbf2-08dcf2d9da37 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 20:41:06.4929 (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: UWrQkSa+ChaTgSVy0YwWTbU38CS8vXW6qQLoVfiv5chXrtSs1HDHG6oPpu1kBcXKo9bhNS2m0z9t2zKGOB448i4IVrlae3ta6IhmDpKOzW8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB5879 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-22_21,2024-10-22_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410220134 X-Proofpoint-ORIG-GUID: 3TfZiNXp4y8ylZEWf_jytYJC_KGEgrWo X-Proofpoint-GUID: 3TfZiNXp4y8ylZEWf_jytYJC_KGEgrWo X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5022D1C0009 X-Stat-Signature: 5uwyf4ntqkorsewdczr1dd31q3caihjh X-HE-Tag: 1729629651-424996 X-HE-Meta: U2FsdGVkX1+RLf7keV8Z3YFEs0UQJ1XCusDj5kHCJzS+25/yjsNTxLmcQfEJSAICS+m2Lwq9DiGIx08x6JEybi0U8Gsgz48DrvZBZ7LvTW8IlWQok82poG8mhMIy4AzvYCz5Pm5ce9Z22vgc71qsHlleF+/CNk2TBQEz92MwKpW63cnB9szZml+P/ObLmxsp58zSInKhpzR2GnJFtXDZPKAl+YY0gtbhnA3M7lgV4zDdTTUKhfV3eLN9jlRldF4zrPC4+1fNOX6ypXCrHYVlGfGFcLb/uE4pjOQu76jwNQWClyx/YmSddLbjK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s1kdoL4ZspGfsvjusoPd4jNpp1r3YsYhswRB5OxjGzkCCdkOMpEHxoBVlPfa1gG5LOUYLTG9CDpZMR3XB0ae0IF/lyEgIgcB4rnhNcEs/qSEj711lzHD2UdCbu1lNOhE5449uUdi7+pBiGIUric8W6e3vYU2zkB6UF6lgvDSV 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: 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. Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Signed-off-by: Lorenzo Stoakes Reviewed-by: Jann Horn Reviewed-by: Vlastimil Babka Reviewed-by: Liam R. Howlett --- mm/internal.h | 27 +++++++++++++++++++++++++++ mm/mmap.c | 6 +++--- mm/nommu.c | 4 ++-- 3 files changed, 32 insertions(+), 5 deletions(-) -- 2.47.0 diff --git a/mm/internal.h b/mm/internal.h index 508f7802dd2b..af032e76dfd4 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -108,6 +108,33 @@ static inline void *folio_raw_mapping(const struct folio *folio) return (void *)(mapping & ~PAGE_MAPPING_FLAGS); } +/* + * 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. + */ +static inline int mmap_file(struct file *file, struct vm_area_struct *vma) +{ + 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 = &vma_dummy_vm_ops; + + return err; +} + #ifdef CONFIG_MMU /* Flags for folio_pte_batch(). */ diff --git a/mm/mmap.c b/mm/mmap.c index 1ba0878bbc30..10f4ccaf491b 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1425,7 +1425,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* * 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 + * This is also needed for mmap_file(), which is why vm_ops * close function is called. */ vms_clean_up_area(&vms, &mas_detach); @@ -1450,7 +1450,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if (file) { vma->vm_file = get_file(file); - error = call_mmap(file, vma); + error = mmap_file(file, vma); if (error) goto unmap_and_free_vma; @@ -1473,7 +1473,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_iter_config(&vmi, addr, end); /* - * 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 && vmg.prev)) { diff --git a/mm/nommu.c b/mm/nommu.c index 385b0c15add8..f9ccc02458ec 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -885,7 +885,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; @@ -918,7 +918,7 @@ static int do_mmap_private(struct vm_area_struct *vma, * happy. */ if (capabilities & NOMMU_MAP_DIRECT) { - ret = call_mmap(vma->vm_file, vma); + ret = mmap_file(vma->vm_file, vma); /* shouldn't return success if we're not sharing */ if (WARN_ON_ONCE(!is_nommu_shared_mapping(vma->vm_flags))) ret = -ENOSYS;