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; From patchwork Tue Oct 22 20:40:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13846148 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 C68C5CDD0F4 for ; Tue, 22 Oct 2024 20:41:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43DCE8D0002; Tue, 22 Oct 2024 16:41:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3ED6D8D0001; Tue, 22 Oct 2024 16:41:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CA238D0002; Tue, 22 Oct 2024 16:41:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EB3208D0001 for ; Tue, 22 Oct 2024 16:41:21 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AE5031A029C for ; Tue, 22 Oct 2024 20:40:51 +0000 (UTC) X-FDA: 82702407984.05.57A47E5 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf07.hostedemail.com (Postfix) with ESMTP id 96C4340012 for ; Tue, 22 Oct 2024 20:40:55 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=BZrx4mew; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="wTJ/5LRb"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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; 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=1729629526; 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=PjHEtf0t6dnYaFIMePzzq4ewJmFLT/0zq4zRJVRV9/w=; b=RBKY0Eps4PIZbl7GgVZ+8ZJbVaKe3gZUNheI8WrTdzvhtOu6PCZk7d55tOOT1Sxe51vlv4 EQA+M6M/uDJTW2obbidggVq8XfsNQ4At9eFlec4aAjSuonsW4JpQdJk8xMBR7Lr43sUmm9 +sips9WdZwCMFKfbX3U7r1R6Yy8lJCA= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729629526; a=rsa-sha256; cv=pass; b=kJJVbi+PPRpzOtT1cVfrwJQwfyqOsZMWNwCPaqMAWidMpvktP/6MoRxSgKxiGqC2lWDite 6aPwIdTXq8lMrvu9QYWvrTBzPms3lU6uvFKSVy69WHBOeGPQBEre6zmuYFX6KvJXny3SkN WusgZd3GyLCjUFszwwkZjgZc9NGQAsE= ARC-Authentication-Results: i=2; imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=BZrx4mew; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="wTJ/5LRb"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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; dmarc=pass (policy=reject) header.from=oracle.com 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 49MK3YdY013268; Tue, 22 Oct 2024 20:41:16 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=PjHEtf0t6dnYaFIMePzzq4ewJmFLT/0zq4zRJVRV9/w=; b= BZrx4mewpVIUcf7/MShtRvUhM6W6speBCmot8W2Rk7zoJh2UGPMnkW8N4H57pe1n PnYWVoAVOyDgcM+R5SQpTeWqSSgFAjspJe7Bffd1deJrxDdKt1xZ/8BEufwTlJMe S0zlro2jpBk6RinPjMo/AiXYvK6cCx0yfHUQU6hfqtBHsx5O7bU61M+LHKzut4PJ DV9C1SMQo/eAQnvKQyeSKudNXl5qkX4psXY9xiv+CWeCHUlIAYl6rkJdTU7wkFy8 hzdz5v8qY+2kTNxBF6daRmixLlDY4UaQlUMecRfpdMZvCG5Pn3y+omvCBBFodhDl yGBHTl94lvzC8s7FB4JYeA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42cqv3dsuv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:16 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49MJWbiV019683; Tue, 22 Oct 2024 20:41:15 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2172.outbound.protection.outlook.com [104.47.73.172]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42c37ef3fn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ch4x8gcGhoeXmO00w/f4rd1FJi+f5FqTwJX8shzylK1q7QlwYiS/6rskbynSX5h44MNCbhd0X6GehO0DSxcEZOvauBDR0rg7O+CSWd1SHHeM5iIaw3twg/rn9qJGGsbHwYeKjmMY34yV9krHoMm1d+yFKObg9CAJx5xXgbPbygrF2oD65UIK7I6Xf3lAiXJmJE2KZnpd10gG09iksKWsk8bjJMq7ArotjSPxIJ9f8X9PWZizjYUW7EEWVEWAFqEKghLp8LgmQwk59Nrcx9somUlym3eT8Q0VqjykWYykDsZcVx2EPDgoPvv99ZLRpK4XJVVntWgjHY+5xKByXUnnXg== 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=PjHEtf0t6dnYaFIMePzzq4ewJmFLT/0zq4zRJVRV9/w=; b=EV5p5tkKOojlQQR/XsK7XE7TpZ91vZaCT/NSP11Xktu4ElwG00gPXE7VXfoJFIwK/50DhNAVBweTJfL/rS4ywziHtHQUVn2qCyH8C0WF8DQwW16QCrEYx3+KLDOlCdv3BxRs4IGwuz0hw/OE2IzxwjtyL2gZGC2m5QCHoRcxs4zQ+oS1HMdasz4yQsFRuy46A1f5TTxs1RyfVrXUCMfOu+Trjf8RCnY+/U6pYhZw1uW1IqwoG+e2VjXroV9bZynLnFKRzjDionTFvYHqC7uQU5me21G8zbO6sFh0xYj7U2BQCX87Vv25J+Rg71vXWHA8dShSsuSx5ZTGB1FzyfnV5g== 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=PjHEtf0t6dnYaFIMePzzq4ewJmFLT/0zq4zRJVRV9/w=; b=wTJ/5LRb+dP/Y2llETdj8rZBm77kKWWRg4Dw8bmBbFMmaRPkyw+uBVDQbj1Knd6HD9J3snP5rPOflqdfillGPoM7yVLtWoG+I/VKUKgLgq344kGwgI8FcD1xC3FmXDE1R3xKDd2c9Mwqgh/gvOl3zopxFUF2EAbbOYmNsuNp8Fs= 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:12 +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:12 +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 2/8] mm: unconditionally close VMAs on error Date: Tue, 22 Oct 2024 21:40:53 +0100 Message-ID: <9a84bad9fdebbdb0adca2b5b43ed63afceb5bacc.1729628198.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0416.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18b::7) 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: b9f0d0b3-f308-42f4-5329-08dcf2d9dde2 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: eGQrU38wwzwvye5J79bqpxCOdaQFFaRBEdscKnT+DtSl5jrczs7IJq2i9CIiYVaGeKpEjrh08NqL+g2ZvtWkdg/qyfY8XPEgxw83d49hhnC3OUTvaubNoaPH5o0beGzPh0NhKg61MmY0DOiXOC9qC7cKeXeNzS3Vvry34mUx33bbH0k7JSRvfpidlufZSsacTgDy5/YyHGSLy4PEYWezDD92yrbrxvpJCFM8nCf7b4wuysW4ARjsm/U3Dvqf1L9kPBJaayXhjJVG3UFGJEYZqYh1MJebc/Y57OfXc/9IuDRtmDO6l3C0QiA1ETTsefSFitCKbGsgRhZm8wxoawiQxJaBEi3+dkcBlLE7S+EIipyJJE3OCpNZH52/FxNTNUYceqE793JDqLumRPVfjjBq0/daK7PGVvXpHlCMy7tgK043e2M7QKE728FtV9uZqsVRi6o53hKtsFR1GxYdssexkbpaYwmy1e5H32Z+sJWxHACER0+6JvhyQlm2nqucpVUnforkoRV3I8XsXy25iMNBWeWIhnxDVlpAZ9zpslWA1L5ddwSf3RVQVaH1dBl+8uQJGHDoncVly03UtzoKZvOaM8sUh07/wz7J6ugnRDMyY6Jd6kj0WEuBkpg+U2vEU4WEeY1BWXCj3nxFzTKbgPC0D89nbA3Wu3it5C8+xeElzyVOZRr2aA10GHMyMz2nk2LZkJy9nhGeeVrX+C7T4sb8L3TCwWH6nfNEXjqCAYU3iSCe3ssuq949iy6i78cHpJf2S3fwaWyyz5VdYrBps5iaDxgSFZ0aAwPjfh6x8leLVOM6HfBpaYx9HE0IGaPOZ1TvXD3smLtE+DchjBIgP5KGnC/vsyBTWuXWaFyPBOcRD1DWrBBQ3ZrAVmJEUa5o0uxsWU9IcrfaEPdGgfOEyH3BPxq/Sv0w3bBbbAyL5tFOys38uQHRfbqXDid6YwnAlRDIdE3cTyg7LPjRMLQP65dQJVH8Rui5d2tlvFEN+GzpT1A6WEsejyxT1fvJWmOmwsfkjZoi3GN801v4NscAfxqiAost6+tvOBg8WgxuLpCkast1GrOxCTKykQFKmGXZjojsw4HGkStSMWbnIE2wLkJ0yv7I1/eB87CYuqWNz/brbh+h8lBdx8OpGxdHSZufaYMBf7MBOGrsNEVpDf+Y0MNnbtXsMgmgiR158m9+8vgLLsmVX7R2bhH08d2QPySfZxGn4SD2OMKJnAKgtjWzPoJ/dxYUmbvO9V3XCEVK5nEEE7kHuxyIu7kUtT0fhHmY+mUJ6crex4VdV8bdNjW4U0zjeL9KugnYENILz2cAzo1MwEFQTa1FuTQ52SCI9FhXGXO8 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: wZhTIblHJBDgKuzUokAtWHChDA3BPO0gbqyYX3P/wEpUFkaDkWSiAPLdoCqmFhyUIwq8M7Ll1QF16GWdhsg4ZmssJxFHBupYgYEl8gnPBuvdGpqLbsrRKVVRACtKij9rNGiYY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VEaJC4bdKcv+L9igVTmSYl67w317y91OQnc1+8O5LgQHUHLz6/b96rbU68PwZ7Zf349ZoJADuFhp1rEO8UQ5Ozs6rWOjGBHPBP+EElcEFphG41hOQOKxiw7LFS3hz+7MQILy5I80UuSS99Wm5LO1QvPL219T3PtX/HJK53qsE3OSn+MdXRlfv6AK++z3AH5NNtmu7xiPW2Hj9mwkBFLExZEZO++l2Q414gnqP0k7L/4+EufkV2uP06QxODwjNTjH80X5Y1TjeToIOmXn7B1ydq8tz+BJ2Nptlfde4g50wVS3BWlpjw64WQO+IyBxvVVzYG+BmPMSm11anwQe4Xh9s4Oos7KIf6Fw2ZLgK52ibEX+fOBdlNZuyZvCOjkeTJus9jKdOZmfd/RA8jHfJga5WFCv+RTmYTBA4V1chemUqUOzfSOl8H9L2b19UzKzQlTbNGfl4Ofar6CysjHRHUcUdQhg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: CB+/3eOtNrnw3NeH5cO3Y9t2vNpwc25OegDmla78hYOHI1MVtLRMk2TUnEsYamzRk/4BSlPDd07cEaJuln9Mxz9ifrq49y/fy4v8Xm4dhRZ70m3DiCpsPiRjTujriTaFckm7LkRvxc5fxdl+QqZuP6LQlOkZUkuSHP1Pv9kAqSG8uBYlN0MIOlR35bcKq773ncZZb1sH5UfCc6kA5IokeJoHFYZsi63PwIswdgaAEJMTQ9GfRUSXJsDIIKbpzUtrU0hPVPebqaiGcgZtggpDUGM536hY8ozZ5fgeSicNfcA+1LW2hmy7FY3+4+4dKdn2dxP2B767EARem5rUun/kdHALam65pRmhfuTypIsaTJCwvvvLVeJ+1KazO0HOW7PZH3o+J8I2uSr+Fo32TruXo7Qpubzp0oKZ0LY/Gqo6Bjjym0kIfTwU3uMBonQUUgh3R0L1socXisWlWfL3vkPAtFNkguJ6TtGPQef9w4yttKfI+AJliaLOZ4QLbs53GzRbBneSVgfbWeH866XaB1WhBWHddmEx37f9oxxcP/BB+/cWlxoaYl6AQ+sfy9kBN5GQJhev6ydfOTjpiRlkkK7c5IyVZMO7jy8Pvd8unW8OHsk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9f0d0b3-f308-42f4-5329-08dcf2d9dde2 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:12.6586 (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: KCx1MzieMdI2YlRHT4ddYf438j+3cI83iFpPEuKWPH2sib+DhX+4gvpGseuDq1g81XevfjzTKXgQIrWwzYyF7kSeH4NoRZMnTlY+dKQcTIA= 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 suspectscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 mlxscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410220134 X-Proofpoint-ORIG-GUID: W2EFi4ZGfqTeh4WURatfCC1aiD82zXZK X-Proofpoint-GUID: W2EFi4ZGfqTeh4WURatfCC1aiD82zXZK X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 96C4340012 X-Stat-Signature: ks9fophzat8ebkxowsbpygyo7n4wz1fj X-HE-Tag: 1729629655-230248 X-HE-Meta: U2FsdGVkX1++rYaiDJGNJmwJUjBg5FN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ewD1bcCCx37vcgxH5gyj13crVSiel5GqJbhVrcknQrqB24NKILAQOxVNiWsXTmRtYmhgYsRIof2ReFdM97QhyRLm+sK9wtV1zZ0asRpJjv6hMNsrsKtlVzooIDuXzhMuAjtVQRuD7UIYLBBC7HAnV0jZ3EcVATN2qZVBEJxcyewSu80D0dski84gRXmf893nz4YD5k1ks8B0ZNSBtP3RgJljha9Bas9R0LW2Yms+Px+GY/li5gqM1AjU91a/PK43DfRrwCZVDiv7b/m3BBdSPMnGSw2B2SUp8Cx7R8p+FWCJ/Ir6EA2sLSYm62ZLnRzxT9jRHOC45HCoZYD2Qc2iui6/ZUNA0RdJkc3HsrCv53Y6v5T3aTB0DVEyiqdaje+yVneaEBQoUWzuhj1wfnPQgF3fcTViY46B7UP1CPMv6mTFjj/aVakpa88SlrfsVghttNxatWIEKD5URqXcP 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: Incorrect invocation of VMA callbacks when the VMA is no longer in a consistent state is bug prone and risky to perform. With regards to the important vm_ops->close() callback We have gone to great lengths to try to track whether or not we ought to close VMAs. Rather than doing so and risking making a mistake somewhere, instead unconditionally close and reset vma->vm_ops to an empty dummy operations set with a NULL .close operator. We introduce a new function to do so - vma_close() - and simplify existing vms logic which tracked whether we needed to close or not. This simplifies the logic, avoids incorrect double-calling of the .close() callback and allows us to update error paths to simply call vma_close() unconditionally - making VMA closure idempotent. 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 Reviewed-by: Liam R. Howlett --- mm/internal.h | 17 +++++++++++++++++ mm/mmap.c | 5 ++--- mm/nommu.c | 3 +-- mm/vma.c | 14 +++++--------- mm/vma.h | 4 +--- 5 files changed, 26 insertions(+), 17 deletions(-) -- 2.47.0 diff --git a/mm/internal.h b/mm/internal.h index af032e76dfd4..3a45cc592fd0 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -135,6 +135,23 @@ static inline int mmap_file(struct file *file, struct vm_area_struct *vma) return err; } +/* + * Unconditionally close the VMA if it has a close hook and prevent hooks from + * being invoked after close. VMA hooks are mutated. + */ +static inline void vma_close(struct vm_area_struct *vma) +{ + if (vma->vm_ops && vma->vm_ops->close) { + vma->vm_ops->close(vma); + + /* + * The mapping is in an inconsistent state, and no further hooks + * may be invoked upon it. + */ + vma->vm_ops = &vma_dummy_vm_ops; + } +} + #ifdef CONFIG_MMU /* Flags for folio_pte_batch(). */ diff --git a/mm/mmap.c b/mm/mmap.c index 10f4ccaf491b..d55c58e99a54 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1576,8 +1576,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, return addr; close_and_free_vma: - if (file && !vms.closed_vm_ops && vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); + vma_close(vma); if (file || vma->vm_file) { unmap_and_free_vma: @@ -1937,7 +1936,7 @@ void exit_mmap(struct mm_struct *mm) do { if (vma->vm_flags & VM_ACCOUNT) nr_accounted += vma_pages(vma); - remove_vma(vma, /* unreachable = */ true, /* closed = */ false); + remove_vma(vma, /* unreachable = */ true); count++; cond_resched(); vma = vma_next(&vmi); diff --git a/mm/nommu.c b/mm/nommu.c index f9ccc02458ec..635d028d647b 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -589,8 +589,7 @@ static int delete_vma_from_mm(struct vm_area_struct *vma) */ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma) { - if (vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); + vma_close(vma); if (vma->vm_file) fput(vma->vm_file); put_nommu_region(vma->vm_region); diff --git a/mm/vma.c b/mm/vma.c index 3c5a80876725..bb7cfa2dc282 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -323,11 +323,10 @@ static bool can_vma_merge_right(struct vma_merge_struct *vmg, /* * Close a vm structure and free it. */ -void remove_vma(struct vm_area_struct *vma, bool unreachable, bool closed) +void remove_vma(struct vm_area_struct *vma, bool unreachable) { might_sleep(); - if (!closed && vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); + vma_close(vma); if (vma->vm_file) fput(vma->vm_file); mpol_put(vma_policy(vma)); @@ -1115,9 +1114,7 @@ void vms_clean_up_area(struct vma_munmap_struct *vms, vms_clear_ptes(vms, mas_detach, true); mas_set(mas_detach, 0); mas_for_each(mas_detach, vma, ULONG_MAX) - if (vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); - vms->closed_vm_ops = true; + vma_close(vma); } /* @@ -1160,7 +1157,7 @@ void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, /* Remove and clean up vmas */ mas_set(mas_detach, 0); mas_for_each(mas_detach, vma, ULONG_MAX) - remove_vma(vma, /* = */ false, vms->closed_vm_ops); + remove_vma(vma, /* unreachable = */ false); vm_unacct_memory(vms->nr_accounted); validate_mm(mm); @@ -1684,8 +1681,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, return new_vma; out_vma_link: - if (new_vma->vm_ops && new_vma->vm_ops->close) - new_vma->vm_ops->close(new_vma); + vma_close(new_vma); if (new_vma->vm_file) fput(new_vma->vm_file); diff --git a/mm/vma.h b/mm/vma.h index 55457cb68200..75558b5e9c8c 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -42,7 +42,6 @@ struct vma_munmap_struct { int vma_count; /* Number of vmas that will be removed */ bool unlock; /* Unlock after the munmap */ bool clear_ptes; /* If there are outstanding PTE to be cleared */ - bool closed_vm_ops; /* call_mmap() was encountered, so vmas may be closed */ /* 1 byte hole */ unsigned long nr_pages; /* Number of pages being removed */ unsigned long locked_vm; /* Number of locked pages */ @@ -198,7 +197,6 @@ static inline void init_vma_munmap(struct vma_munmap_struct *vms, vms->unmap_start = FIRST_USER_ADDRESS; vms->unmap_end = USER_PGTABLES_CEILING; vms->clear_ptes = false; - vms->closed_vm_ops = false; } #endif @@ -269,7 +267,7 @@ int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, unsigned long start, size_t len, struct list_head *uf, bool unlock); -void remove_vma(struct vm_area_struct *vma, bool unreachable, bool closed); +void remove_vma(struct vm_area_struct *vma, bool unreachable); void unmap_region(struct ma_state *mas, struct vm_area_struct *vma, struct vm_area_struct *prev, struct vm_area_struct *next); From patchwork Tue Oct 22 20:40:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13846149 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 6F9A5CDD0F4 for ; Tue, 22 Oct 2024 20:41:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E02CD8D0003; Tue, 22 Oct 2024 16:41:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB0DE8D0001; Tue, 22 Oct 2024 16:41:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8E988D0003; Tue, 22 Oct 2024 16:41:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 994CF8D0001 for ; Tue, 22 Oct 2024 16:41:25 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3F50A1A04CF for ; Tue, 22 Oct 2024 20:40:55 +0000 (UTC) X-FDA: 82702408362.29.9E6E2D8 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf16.hostedemail.com (Postfix) with ESMTP id A4F2118000A for ; Tue, 22 Oct 2024 20:41:05 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=aB9G1H7O; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=u7QE0iUf; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf16.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") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729629515; 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=e34AEHAMhHEQASKV1R/2I3fLJ9/l6ehQMuhQiU5tCX8=; b=tyxd/gZN7zDEoK+d5EttWICk8EY8aGPVKTLrloIJ5fly2UpLvt6pJnZqMmqHYE6NswU0I5 Ryci/qP7CWECCDVf1X+sNcQwNV5mSSoR/tFO38Sxb9aBtZW2NKUjFaI+Y43LOtAFWwVykx WFLLRWWMfOA1bdT2To8pXA+05Nx0YKo= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729629515; a=rsa-sha256; cv=pass; b=3I50zFdsiglksSraxQl6GlLrLBKMjvf79jwHP3LcJRZhIrSQxwowRdzov3zDHVlNC5Q95e Uz2zWq16boclZCFRYYHY1F7HCiyjtosK0u4aX4jfTfsxywfBwLwf0qL6iE5LVfsWZJsxji ajFGYM9Fbbtd9WeYIu7CovLjAw7iEUA= ARC-Authentication-Results: i=2; imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=aB9G1H7O; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=u7QE0iUf; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf16.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") 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 49MK3XG7025798; Tue, 22 Oct 2024 20:41:20 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=e34AEHAMhHEQASKV1R/2I3fLJ9/l6ehQMuhQiU5tCX8=; b= aB9G1H7OBEbDW8H01Vv8nphGJm1lsMifIVg9ELbFFvjeJ81a8wA4FEdx5jsnwgk1 PN2B1zSr5WUt4MBaMfHBvyfMbZEESNEbWofgra2aiVmBkFVMWbQOXZjygrewXmKf hK7pG53idv6m4aXl9lr+5mlgeUb1NU5FdzLLBCk+RGumJkbC4A3fvHpyAGMpMvrV aW/ZW5ZYtPA9Q2upEntenUirFdss7DxGSOiKgNw1pym+24fxkf4cHdfmshw6KEAu cEJxLmWT8ttIV0Asj/23H9VUV/vOn+18Ftps5cH/VdknCkmYJuTtgtKWc0tFn7z+ A01Yc8jPgutIWOAZlZFRYw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c57qendq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:19 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49MIoKGl022660; Tue, 22 Oct 2024 20:41:19 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2175.outbound.protection.outlook.com [104.47.56.175]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42c8ew34a2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=F4WPXWYz03hWe3vlZnQ65HCuHk9NWxQ8CTaH+pO9j3n1C0HKu++MpXV9qshcDWvaWwvimB+lq5Xim/0ZQ7LtSZlNbNdheF9b80yBEeQ+TtDxHU+Lq4/RSMf0a3gceMslcbXdlnJ9YHp5DiB12ZamrLNzHrc7ogfnshRaijwSYllb/Wp8gt5fY/fio1L9CCRjkT/bHYqL6nz+lAEuVH3DzwICZESWKq0ku3H+ajDou7cTlPBgni6aZut3kx+1RHzud9cvKG5bTDMRQt6ChGvauRMgCcmt7t9B10aAHcGhmboslE5WiQV+U8LJOcVkJ48KSg8QFQG2VP010F3g2JZS+g== 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=e34AEHAMhHEQASKV1R/2I3fLJ9/l6ehQMuhQiU5tCX8=; b=nutyY0oz+Qqec4+zZcn1sOz/G7tJyONM4fRgPGw2ye34LMIKHFFn+5ok5m4C2392hZ9Q0hj1F09QHxZYqv8c7r1sqVaMGAliWGRpf1IRp+TtQua0pKl0OjvQuWJJKTlx1xpMfwRIjxk6oHVCMCOyzwSR8GrXbnJ28YfCYJGKqpkUT4cM4UT1I4c6O9+bqPdMD7q1GHq84tZj02AcyhrrWwLXhlVw+LGzjbo/OG2dpT0AoZlma03hoGfqKn2belfefywVmcmrgWW7NGhx2040tUL9+TpIbkqISgg5g5rM0Z6GP1imZjuXTWPTEoZJrRL5Pz+peLdbCrjaS/N7R3feig== 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=e34AEHAMhHEQASKV1R/2I3fLJ9/l6ehQMuhQiU5tCX8=; b=u7QE0iUf4/7EINHeCJQSJvz+rMV4tPGFkFZa8coisXNVjEV2iiCyf6Mt9wY3e3nmCKc9ypXOaNtd8GQBACrOjr+UFHZnMGSkA5CfKVXuoSk0ZF0pY0bx4dz72TCxc/9fNk6A+jxkj+TfZoCVBmp1DuY2uQ2QcRDH/m93+dPACrk= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by CH0PR10MB7437.namprd10.prod.outlook.com (2603:10b6:610:193::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Tue, 22 Oct 2024 20:41:16 +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:16 +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 3/8] mm: refactor map_deny_write_exec() Date: Tue, 22 Oct 2024 21:40:54 +0100 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO6P123CA0042.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:2fe::13) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|CH0PR10MB7437:EE_ X-MS-Office365-Filtering-Correlation-Id: 1694ec98-4a0b-46b6-4121-08dcf2d9dff8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: iNB1fbNOqFArCB/MHYwHXYvPo4K6+0FIBNdHXU3Odw2cSMfiSPp/jvIyW4JkUj+fp2OvXcubLIlxUctbDUlq/uAc0VA06WKBUGavp5HsjZlUSXGDyq5BCj2uwEJyAEbQX2xMK3GN5+bNk9inYjajPzsLJETpP12TjWNBeOGT+pC84NxZkEC0/0U0nUy34nik46GYb3AY1t5hERIx4e1k7nT+xQJrl+fyqwUj079K9lUM+WzeeuM/OYwyvRM0mstvSlNAEn9v+ScVKmO/QQrl7EQLt5+Vem+RopA6D8HX2Nw43FK9cvZ2JHkQlapM2Nn6egZxE4PDZTjf6NiRfq3CD44DNFEd5RP24bPjR5tU1xN46BrHYniaBHXuA7viWG8JDzj0r/RYxBQmdmX1tJnS3CQmbMp6S/Ide3CPJggyiZfTeNL9Gm5K5fTGnEjtPUv8Tu17gRxRUntN0op52pFMd/Y8LUbtGNBFFikR7a/04DsVrUKeUSUEWXH0s4wkZarHY5E5RXOeJTO6rMVFHMCWk1K+vNTxBABoz9tae6ZQ/+JSEdCP6m/0GOqDV3bluRPp4NulidqBL/PxunXdJaJyKVtRn9Kpm7DCDJo7qQX6g3xcFZWZ/nw6gmIseuhWPyakj6A+I36afIWyfJ0Umt09kljwoWJ2MLwfjHGBcDParrx3fLWBraSfODGGu9osnQ0wSZtldoShTmn5io3wHR0qooAaa6DkRPAtdrWkYVDiLPTFfYQg5J/X5uysZLf7P5aHGDTHeRuUqmX7DGyKZwbsSdHdvIBu2AK6gHnnFaqkBK6HGZ9XVuEIzivZIcOHUwS+sOf6Z9x1IzQj1D327SmPbsBPe8yWhRXEjJ+s7sqisKRzUXFtZDKJU8KqmeibDwPt60JJ00Lbi7woIENpJZFmXv9KdyY46TXIoSXVu6QRa8PbTFw4QUZZVO53wHFMn7mPFYGh/xpb8QVtBiJbJWUxZUGwgsKJiF18SZVqvLBSIxJud/tRZfdG/zA6DIOL0UMD/fwACaVbYFlbtiUvE+MhDxbpOVi5dH600cwe1/Adre4Wl/wgrn44lUPsF/7SlDD2DR2PuL81qDR2jlIA3N/Uqu8N4PN9LGGb6ssbaxShSobryQKcGzzV9bUNJ0ucaSVCtDWxi4pfMq7uHSImQJXHGBShCcPTwdk3apkFBHxXQ6uVdUlmQr+S6BXIC3Qw1Ze+vqQ4t/FckGroq0bpAFrdC2+thVeuXnxgQinHy1syQrj4wbvz88/S0WF+bVa6xwMW/XNbSh90K6nxjSuwDUmizYOpIZwJrpjwICgrKXDuhXHdZAD8w545shYPiaotec8n 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)(10070799003)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GAEs2oRJ9cb6A6wsNcJ/1ftn6B28ju7DBUXqGo6hzRMDIitM/5IM5SVQDTPNRqdzrBXebKXfytU1QIlwRgUiVHbreCIYitwWm+YFatCe01Tj1baCwrnUWkLrrQgESUOiCxmF3thGHk3/W1v/zgiXi7VInOX/vjYCo68WNnmI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GyYY1bAKiCmHuzsVlfKZ8KX06aDDDeSInuItOitKkfuqrSPOEY6gza/+/46Oc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1694ec98-4a0b-46b6-4121-08dcf2d9dff8 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:16.2030 (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: /dIBKnR+sLk9fNlRTmE+b4te/3o03spUBU8Rd+p1qxmtdDhiLciTVDdIPAq1fXg97GrZrA/7FIfDM24n1gw0TmFb/1nTmoF1Jo50He/+SoI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB7437 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 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 mlxlogscore=979 spamscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410220134 X-Proofpoint-ORIG-GUID: rZgmdcJBQiJr_qbbFFJtO5VJevnX5oaw X-Proofpoint-GUID: rZgmdcJBQiJr_qbbFFJtO5VJevnX5oaw X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A4F2118000A X-Stat-Signature: rt654ccpy9ddrhjn6frzyrauugcxpaxs X-Rspam-User: X-HE-Tag: 1729629665-976114 X-HE-Meta: U2FsdGVkX18Q4eI9XvQ7Bd1kcFWtmLK533yXqsjJ3a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3EPjMTjoSZ+Jnn8gpx54MRIZY0Z+ZftUuaeHfEEOP+gOanHwBg5D4COlZhkAgJ/yugO3dsk/4Az5k/wlYUwkgN+OHrGJr4YrCE5eFWy7SV4Psez/YGQBXXMn8RuNOsQaY38qARkSEcrS76uXkWVR5BFwfjsEtc31ET7J/vy7ro9QU5AdR9yAELo6on+OFqcVM6M93Sj4sVHKsBk96hmTL9ILXqwJTWzgiC8cU7qhqgVUssOISXhdIJtgNko/e8QnC1fVOIW6yfr8pxz4eV+UYdp25YYLvDMQjjStk1y8fJyZ0xcgmU1hCRwDODvf4UQp4jTi4z4At/jW/QTyCZk4caL4kum4vrWLI6jMviBqaQYM4Rg7H3PbsfssdSiEcMnJ7p6IUMh/Ray2WxSFLibi2faciRXOd2ZLjCbx8tVZnvqSHuy8CHcpkU7pMF4nUPQ7Hvw6FymIvnod13ReR0UXh8k9XzhhILPt0Vg7Qy75uY5DLoTs5mrZm69tE3kk= 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: Refactor the map_deny_write_exec() to not unnecessarily require a VMA parameter but rather to accept VMA flags parameters, which allows us to use this function early in mmap_region() in a subsequent commit. While we're here, we refactor the function to be more readable and add some additional documentation. 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 --- include/linux/mman.h | 21 ++++++++++++++++++--- mm/mmap.c | 2 +- mm/mprotect.c | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) -- 2.47.0 diff --git a/include/linux/mman.h b/include/linux/mman.h index bcb201ab7a41..d71f83b821ef 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -188,16 +188,31 @@ static inline bool arch_memory_deny_write_exec_supported(void) * * d) mmap(PROT_READ | PROT_EXEC) * mmap(PROT_READ | PROT_EXEC | PROT_BTI) + * + * This is only applicable if the user has set the Memory-Deny-Write-Execute + * (MDWE) protection mask for the current process. + * + * @old specifies the VMA flags the VMA originally possessed, and @new the ones + * we propose to set. + * + * Return: false if proposed change is OK, true if not ok and should be denied. */ -static inline bool map_deny_write_exec(struct vm_area_struct *vma, unsigned long vm_flags) +static inline bool map_deny_write_exec(unsigned long old, unsigned long new) { + /* If MDWE is disabled, we have nothing to deny. */ if (!test_bit(MMF_HAS_MDWE, ¤t->mm->flags)) return false; - if ((vm_flags & VM_EXEC) && (vm_flags & VM_WRITE)) + /* If the new VMA is not executable, we have nothing to deny. */ + if (!(new & VM_EXEC)) + return false; + + /* Under MDWE we absolutely do not accept writably executable... */ + if (new & VM_WRITE) return true; - if (!(vma->vm_flags & VM_EXEC) && (vm_flags & VM_EXEC)) + /* ...nor newly executable VMAs. */ + if (!(old & VM_EXEC)) return true; return false; diff --git a/mm/mmap.c b/mm/mmap.c index d55c58e99a54..66edf0ebba94 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1508,7 +1508,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_set_anonymous(vma); } - if (map_deny_write_exec(vma, vma->vm_flags)) { + if (map_deny_write_exec(vma->vm_flags, vma->vm_flags)) { error = -EACCES; goto close_and_free_vma; } diff --git a/mm/mprotect.c b/mm/mprotect.c index 0c5d6d06107d..6f450af3252e 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -810,7 +810,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, break; } - if (map_deny_write_exec(vma, newflags)) { + if (map_deny_write_exec(vma->vm_flags, newflags)) { error = -EACCES; break; } From patchwork Tue Oct 22 20:40:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13846150 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 3D144CDD0EA for ; Tue, 22 Oct 2024 20:41:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C30576B00B2; Tue, 22 Oct 2024 16:41:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BBA316B00B3; Tue, 22 Oct 2024 16:41:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9938B6B00B4; Tue, 22 Oct 2024 16:41:28 -0400 (EDT) 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 747736B00B2 for ; Tue, 22 Oct 2024 16:41:28 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B8E1E1404FC for ; Tue, 22 Oct 2024 20:41:10 +0000 (UTC) X-FDA: 82702408320.16.BBA48F6 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf12.hostedemail.com (Postfix) with ESMTP id 6729040018 for ; Tue, 22 Oct 2024 20:41:17 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=lUsgi4Ly; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=lbH5GsFw; spf=pass (imf12.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=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729629607; a=rsa-sha256; cv=pass; b=gpmWPHVnriCma9AuJ+obzMoz+hhrOoj2kE+HlzyBifOAaGjQYanFPydYkLtRY23QuoLxio KVeEctBSMACm97zHfBLo1xPSRtftZxpDRAFsPfSosq60vvsHQJDVzDtW4mcLhVO445YsNs 9vjzqi3jUfgVls+oQBGeizaVehRHoqg= ARC-Authentication-Results: i=2; imf12.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=lUsgi4Ly; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=lbH5GsFw; spf=pass (imf12.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=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729629607; 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=yCK8Nyvg2JGUKvD2t+3bdnTb0tis8I4rLlCnKTQX+/8=; b=MCPJMnwBjU9He76V3KfKIgCJ84UAjBnAzZodanIMS450RLii7eyUV/kaCBMpmNrwo0qf65 xmQ19rZ2TLE9dkVQXVoswkUyim74+fw/yXeNhPVdrSopd5+dZqWS5q0MgFd2Bok2HrujyL qdyND3vtH+NmavHBsmC5AFugbVXx1L4= Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49MK3Xjd022857; Tue, 22 Oct 2024 20:41: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=yCK8Nyvg2JGUKvD2t+3bdnTb0tis8I4rLlCnKTQX+/8=; b= lUsgi4LyKBE3aZPyUNIeryeuBekwLW1VbIC1L0M3CQ0O722OlDLyXJkvD/3KeMdm ayc6BGn4aVxPrYDLJ3nybaXJgqOOqHza9sWdBHYe0BK5cWDWm+IK3w9XT8+VmPi4 hSckP+Aaihg29akkzVe/v8w/Fe8w828H8IWXvuOcGDsTKclQ4FYfhpg9dFycpPnT TaYMHJP6sQd0zFrospyG7gC+CHVPxvwJhvjNN2yuPIPcLzt00T2tLWuKHPRzGT+Q aPwl6Z+W/I0AfLXw1SznTdd3d3e/MVcyCiyFExqEoGUbf7WiprFuVTrELobrjp7U 4Q9AHAVGOPGj8UncFJ0sTA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c5456qu1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:22 +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 49MJL6AN011963; Tue, 22 Oct 2024 20:41:22 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2172.outbound.protection.outlook.com [104.47.57.172]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42c3780peu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vZGm0fVkamId52zWloPhuDTAx1oWI1wjGbs6Wg8+bjqEMCkHmy9Ym9IZb6STPx8oHnStyqxi+Whb9cDbdZgBhslxf805zOkqA8L2zxlpAyZh/DAQ7VqFoj1qTlhAtibo4pSHLCNbHZMY4TvWgnKgiY4BZGOOZFqPn/v26bT16ORhew+FvXkgrgOewiGRmaQdh0WYQqRdSeVwwfMODmWkADHjk2xRnwv0A4ZymgknKHA97TQBgDtIzBjhnmp/RjwqJUTnDZgBuSHBw55MLxg/sCdzTKghtv4u5zE4AC9YGurtRdz020ES8E/aJ2sOSqQ0YU+WiyuId2u76KpxDL/U7Q== 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=yCK8Nyvg2JGUKvD2t+3bdnTb0tis8I4rLlCnKTQX+/8=; b=artAZW/Hy/lzM8HJoFi1Bzq3qZCpdrOSFFxljl/+hvh+NBukPJvEVJEj6qrR/7bF9NWm4fEEBn0DyMm0k2yBqjZ0/W5/r9wKMwYeNqPEZU+Nm5+QW+ZojVzsJ7lj/u/iPlcVmZOiDbQM27zpgensjEwskpMkpnf2XV3LV2BURWbXxh/OBAz9j7uH7R/icHskHdGGYf9JnkXGfXRczn6o/62hr2JhC6GsO2WlK8iRvl5xoz7/4NYoThpNwkJnEw6sgKHbG8voONLtD+E8izj8MG7bi8KeCLNhrScU51HQV84dkWnylLmCksXl4F1s4xAtYK1BZsQs4X09Jh36knxiNw== 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=yCK8Nyvg2JGUKvD2t+3bdnTb0tis8I4rLlCnKTQX+/8=; b=lbH5GsFwHF9IYVdFa+1UdwIDdO025LzdQq+ljSamxoe7b87dttcFkABn8FX7oVI2z5s1Gm/oYh7nYNk2RJner3Ca+XzsNFuXVYA5QhyMStBJxpXkaPqa82yDSJwGnaHixmuLQnxf/suoE0bpd6LeGrCJmBAYUqK5YfNXC654KRs= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by CH0PR10MB7437.namprd10.prod.outlook.com (2603:10b6:610:193::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Tue, 22 Oct 2024 20:41: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%6]) with mapi id 15.20.8069.024; Tue, 22 Oct 2024 20:41:19 +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 4/8] mm: resolve faulty mmap_region() error path behaviour Date: Tue, 22 Oct 2024 21:40:55 +0100 Message-ID: <3bc3ef7520eed73472f7ffdce044f2e94f809b32.1729628198.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0633.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:294::20) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|CH0PR10MB7437:EE_ X-MS-Office365-Filtering-Correlation-Id: 6427b3a2-45ed-45c5-8092-08dcf2d9e218 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antisp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ewLC24NcHZZkHJqaDO2UZoFKK4OXsgs5s0ghnaKs9AD9p/y/D/+qCzZ+Jl7V5CIlGI2AI4lHkb6YZ94kRDQomwUZZKCteWBBnt7UIAXJWwyMhqa1dLHQi+77NgrmyKk2rU4lmo39qJjWaBtIwQX/wOBU5zl9nyPAnTFy1miicIbOPfEBf1qBjSHHz2SB1a136iO7Ntn4H5zTd7MgacVidD4EXtCEuSIfMN5+o4HIVRo85DJ+GDG3Ma1O17YUPHnRXBnTAc+nGp8Mvbp7yxjvJJzyUdgOAZ5DOJbC4fQIx124IFAwZ1qAO6POhamQ2hE5oYBWzO7 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)(10070799003)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KwoFQ5PGL98qQ7xrRYK1DLKI5Rt7treR0GznHboc7d+ItlODxeScuv6QXRqhfdMm9T+cACiBgyZfzAcg0FecWM2enbEHw7hdVe5FOrTHhJvuzhWDN1sYLAQihXF2Rha6xLtsMccQzvJ3SSwrT9BrLFX4kwj/P/xlaRO5gZQTjMIVHkfhYlvYNsxI9hd5FmbY3y5Qot2K8PGevowOwhDYeCpmUziy0KIHr/ctVAjkWf4EJa49XeQIZ25EbeCHRIhvJCijBl858FcXC1wq7jHEtYAFOUiL8lWsaYh5UqOdJaQ6Ui28mqyXLVOnNmOPpXlLBE8qcqRcDn/jIw58WWlwl+yOZy2hJgxF393sepvGqV6D1T34EvfhoL76GiYT34FpTss9YKOTor20IewxymQ7j/x31zZhO/AxZmxfL6DZCbpEMPFvLKSErM1fNcbshxfyqIUYbt5zAKUdp2/7Z3MEwuF6REu0z8reEDW7DmErAfS8x0XZ9+AO9T1cdiTK3v+hRdAhxmJzSsB/wtx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2O2vUfT+TuicBLR2aQq6VVAYSapeQpjR6IPHx0xMwI4MIrgET08VrS1BLRDvznbz7Ge4ow== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: BIWeL5MHZ6d6nahzchFqVJcoL4I/PIzHv5DxOVOHuz2cbpu3R4rOFk09s00qbH8FeDz+M2EGJaPKHE2plNyifpMU5eXCL2KN3iu5skqgz4IKBBlS0Gdfj4RJbEnbhH6kox1+jZOL/bda/bZSY81QTMMlTA8K4/+U92aU4UIzFYqVD1T7X/03O8FFRP5MhnkzBN3k8P313XjYW2Xx6zalbCc4LR8Yyaowel5kiMHL7owkMIotpeJF2izGrtboFUubvCPlmqBH0WgL5sTZZisadr9I5Vq0qQmW+wF8WeLHHGlOATiJ/danHlueCaD7xyK3nGQC8fkB2p8T38DKaSZiO8jN9e+yNyOy06efFMd3AHcv39NL9gEGLitHz8IXYBnyEW1BCzh59l+pEXTIPXqm36B1XTNjeLHc7NQAaH7MCocaIyiJWzcGtT2zmLrgRetnBhF4EgUks3QT0Fhf7WT7DuktX3Ojer5g0rowfX5iZztpbms4xSTsAW65aHfT+CQGmRHc8Q/zXmX3Q2WU6UWc2n3XgV1T5A2oufQSKo0CH3GFF0D+5LE7oa0VrE3qnj+G21LsmmphODJvn/xJqkuoKQg0l+zh+sgjrLA5Fdl1v9Y= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6427b3a2-45ed-45c5-8092-08dcf2d9e218 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:19.5753 (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: DDXZ79c0ZXi1o+vanivQyNg+JbbksZcexj9T5gLMvbZ7pbgZiRxM4q+Sb9xy5IKofEX0KZsTGrOq/ztkq+EhAa71rUZSr2hJCNnf1AKXuIY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB7437 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: 5g-7dUENjQSk1UQvQiT0UM6KKFOhrXLx X-Proofpoint-GUID: 5g-7dUENjQSk1UQvQiT0UM6KKFOhrXLx X-Stat-Signature: e5csh7b674143fuqi7oztbbaj8rf6fwg X-Rspamd-Queue-Id: 6729040018 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1729629677-497184 X-HE-Meta: U2FsdGVkX1/qg8jF+y+9k2K71tVEzayPvSqOtNUQNoOqA819S1K2sGsDUE7TN+Qx/SbYnQnP3ZNvZvh7zFWbB+aCZOgRx6IEXJkSUKkbEsTQf9wpBdpPZAYElNDxi/HljW9sw6qHBoU1YRKitmlg+lLiNoQOcSZ/7yDj4Hi/HoKGuObhnI46eK+5syAzAD9b/sm2uPLcyAiyINmiYqd8x8p0Z0ZCApbgAX4++I+K/sn2rR6yPiU7p5MSwSTdvQYtt8JZ3uoQn/pSXrtScWRYs7bE5PTTDsiYnvEuDZrKuUzpOgJ6fd7x1vrGbJaCBBRNIsTj3ccNKhuSwGkYmOH0D/GYoLKE+AXGBCKvLUICQUZsSEv6EIi4sVau/qkjzMxBUwscfyPZppYXrNygyGIFx5MhwvnWp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SGzSpsJzz9tDKcvsY7BhE3Mgc3aFBkVOnyFzLd8Rj1qNh5asWtoBiUCMTv4I0OnRzS8FKI/u5/xVN0ETyS/qak5eTVFjcpfTMyCqHTkIt4+U2qgE/2eYX0uHI= 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: 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. Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka Reviewed-by: Liam R. Howlett --- mm/mmap.c | 120 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 54 deletions(-) -- 2.47.0 diff --git a/mm/mmap.c b/mm/mmap.c index 66edf0ebba94..7d02b47a1895 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1361,20 +1361,18 @@ 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; pgoff_t pglen = PHYS_PFN(len); - struct vm_area_struct *merge; unsigned long charged = 0; struct vma_munmap_struct vms; struct ma_state mas_detach; struct maple_tree mt_detach; unsigned long end = addr + len; - bool writable_file_mapping = false; int error; VMA_ITERATOR(vmi, mm, addr); VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); @@ -1448,28 +1446,26 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vm_flags_init(vma, vm_flags); vma->vm_page_prot = vm_get_page_prot(vm_flags); + 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; - - if (vma_is_shared_maywrite(vma)) { - error = mapping_map_writable(file->f_mapping); - if (error) - goto close_and_free_vma; - - writable_file_mapping = true; - } + 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)); vma_iter_config(&vmi, addr, end); /* @@ -1477,6 +1473,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * vma again as we may succeed this time. */ if (unlikely(vm_flags != vma->vm_flags && vmg.prev)) { + struct vm_area_struct *merge; + vmg.flags = vma->vm_flags; /* If this fails, state is reset ready for a reattempt. */ merge = vma_merge_new_range(&vmg); @@ -1491,10 +1489,11 @@ unsigned long mmap_region(struct file *file, unsigned long addr, */ fput(vma->vm_file); vm_area_free(vma); + vma_iter_free(&vmi); vma = merge; /* Update vm_flags to pick up the change. */ vm_flags = vma->vm_flags; - goto unmap_writable; + goto file_expanded; } vma_iter_config(&vmi, addr, end); } @@ -1503,26 +1502,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 */ - if (!arch_validate_flags(vma->vm_flags)) { - error = -EINVAL; - goto close_and_free_vma; - } - - if (vma_iter_prealloc(&vmi, vma)) { - error = -ENOMEM; - 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); @@ -1536,10 +1524,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 (writable_file_mapping) - mapping_unmap_writable(file->f_mapping); +file_expanded: file = vma->vm_file; ksm_add_vma(vma); expanded: @@ -1572,23 +1557,17 @@ 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(&vmi.mas, vma, vmg.prev, vmg.next); - } - if (writable_file_mapping) - mapping_unmap_writable(file->f_mapping); + vma_iter_set(&vmi, vma->vm_end); + /* Undo any partial mapping done by a device driver. */ + unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); +free_iter_vma: + vma_iter_free(&vmi); free_vma: vm_area_free(vma); unacct_error: @@ -1598,10 +1577,43 @@ unsigned long mmap_region(struct file *file, unsigned long addr, abort_munmap: vms_abort_munmap_vmas(&vms, &mas_detach); gather_failed: - 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; + + /* Check to see if MDWE is applicable. */ + if (map_deny_write_exec(vm_flags, vm_flags)) + return -EACCES; + + /* Map writable and ensure this isn't a sealed memfd. */ + if (file && is_shared_maywrite(vm_flags)) { + 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; From patchwork Tue Oct 22 20:40:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13846151 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 F178CCDD0EA for ; Tue, 22 Oct 2024 20:41:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 835C36B00B3; Tue, 22 Oct 2024 16:41:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E5086B00B4; Tue, 22 Oct 2024 16:41:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6119F6B00B5; Tue, 22 Oct 2024 16:41:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3C0806B00B3 for ; Tue, 22 Oct 2024 16:41:32 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9B85AA04D8 for ; Tue, 22 Oct 2024 20:41:01 +0000 (UTC) X-FDA: 82702407732.17.D012660 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf16.hostedemail.com (Postfix) with ESMTP id 79E69180010 for ; Tue, 22 Oct 2024 20:41:12 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="L/wKDuUd"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=qPL8U3pU; spf=pass (imf16.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=1729629637; 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=IYEq217ZQe6BhqkHPhji53xMVlBJZl7d8VhT2IXVRxw=; b=Y5xkk8t+zIc8FxG7GjjwOfBTsY51tT5j83N4YakxsKoJDsVPgrr9zhZ1/pzEys1SVlQgyg v8JdPcp/aUIsddWp4x5LKbLNFkzPX3lO/NG6jKtQ2NZM8ZJMl/3/0AdSgkl8RCkX8NOkKX PQrwCXtpITd0aD0uEMx5nZQalfQhcJg= ARC-Authentication-Results: i=2; imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="L/wKDuUd"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=qPL8U3pU; spf=pass (imf16.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=1729629637; a=rsa-sha256; cv=pass; b=QoUNg8AN7FutaDpO405zX+lfuuzLY9OsS9fYBpYYoq6LnGSYXazywXpdhdsNIrmAqpE91v iVzYMw0EedbGMqS0EAuYnkVp7PJKbRt/oDqEZGVVteGTmCB2+Q8jE8JZLtTQ6cGlEMYEo1 DLR9T0/dY2sctg6rBbR0jq0lflVtuPI= 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 49MK3XDW025813; Tue, 22 Oct 2024 20:41:27 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=IYEq217ZQe6BhqkHPhji53xMVlBJZl7d8VhT2IXVRxw=; b= L/wKDuUdbU68Zrv5TqWOnYDmQh62U8K3xVF8sGWtCmTpPCSu7cCUQFmQrVjc2HEq 26B613sSVob/uOs02fQafV07K1B19let53bHKyZhLEVsWBluf8g9qXjlFt9yGVVC 591uL8omVJ5XtTAP/4K/GfgQ+/PXAWQFJsP1Q5i/MTnZ9wpR9B6wycrSK00iKQNn 06JTee7X6i2Sz7C2i2GaUkfsfxsCFjQmX6krrs3Od24oCkZgNYVfIbPMlbryQKgg ucjwstHm/MBsb71Rq4pf3Azv0a65/Lh25Ecs0DoqQcsA8cA+ZVep9F/wAtKikJis OGFW9/bjXgBveW1aisBqdQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c57qene1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:26 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49MKDugL022727; Tue, 22 Oct 2024 20:41:26 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2174.outbound.protection.outlook.com [104.47.56.174]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42c8ew34e4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JBo2qVHpxX5nKQ/y+q+1qlYDO0Zt31YpZhWD2n0yd9WN7PnPgwSTqgnzfSNlt+RSzWt2iZaDJCXfCFM0nZr2hmI+vpXCxcjEwRdKLaH/fxZLLTMmjLLqOuS3iqJE9VS8BtWQNUFqTSQ3VAIiCdti3q8GxSiZREsFIgBGUy4OO6unxJ1rigG7e6MCQ4+HFiIrgRj6xLihzv1m4k0Wm6/zX1bpyxGDShphqwDwY2ghvoxbOHjRHqKMsrYLzGv98n3PsZAKtDNAlD2y6O080gB+/o6kNNXfKlbgCHXxxcwRoskCFvGEG+8dXBZQ4N5+snXoanOof1vH9kctsCm/IZicIw== 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=IYEq217ZQe6BhqkHPhji53xMVlBJZl7d8VhT2IXVRxw=; b=a7pIYJ+bnksrgAu2daDJGGLZOPPHvtLfhhsC8WWLVXEyzUfawFgosmbdETfu1+PHsNDy7jWsgLu3KyhRbXt/X8O+KStw2qU/tTMbUVK9y+YQ88GHXxTZufC8fSLQUtAuzYgl8Oc2MGRgYzCphV2B6LcbkDApjQponRquUGgH9jPaL+3hWsF+MQPV+bcQ6IoN2Z3yBKf0DLn5ksM7nO+jVx3us5FnDszF6RAY2LhWBCgngucnce25oYKFhjaObFVWIBhz00ocnuYbrzdQnBhT7M4IRZkH0r4m2wCdBJSfCmG7sUrs12lgILLOSV1b2mdf3yWqXP2KjpmXzGydtG6r3g== 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=IYEq217ZQe6BhqkHPhji53xMVlBJZl7d8VhT2IXVRxw=; b=qPL8U3pUVRD02G3BLz4TZur3jkgb35Naix5D/QApbFulmzdc07oXT7QCDoHv5dZtywAnM5bECCTuYgKYZfLc48fVckS0RicwXJni7qpQWnWGBvyKPA/EG7v0vuxTOvu6Zylv6NCbmtWKaCXbU8dx36zwJcIFsc9ebUZc38n8C9E= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by CH0PR10MB7437.namprd10.prod.outlook.com (2603:10b6:610:193::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Tue, 22 Oct 2024 20:41:23 +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:23 +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 5/8] tools: testing: add additional vma_internal.h stubs Date: Tue, 22 Oct 2024 21:40:56 +0100 Message-ID: <1e039f29776bbb7df5878f3ac85ef6732f450fc6.1729628198.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0657.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:316::6) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|CH0PR10MB7437:EE_ X-MS-Office365-Filtering-Correlation-Id: 41598306-88f6-4e39-5526-08dcf2d9e40c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;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K/SZO9OpNLdRpcpP8l8VzuqPAd8aFqrUt4AtuyrNKrJwuS0QV5+jyFX0UT8z6l2i/jWTumQ3aYxZS06EgLO2x9O3AIjEGBV5eK/oOQKgD5ajz5HFPKyPBJadEJq17e3X5A3TU2E64b4rJJ2PwAkBS/VoYxq5/vPvnuKc/Ha2G0yMbcMjYn3pC4w7z5SWEewH5RZpv7BpHOv17ZlnF/zvj8wI13/5Ev15ulxsilHXYl7rYwDc9epRaFiO6o53lnu8/2acZlFdBEFb3DHywPSIp9EUvGjHJ9vCt16z7U210e/c3CPQOrn36vrR6r 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)(10070799003)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2gE+e8nSObt/suGu0nf0Y5h2ODwQBeTfgfHRd5vMSwtR50Ids1//k9llcB9YbwrMAgne0AfRKrRsX5EgJapKT2k3QqSG1U8Xoel5du39TFKiVIYNEUaJm6mpgxf9mclDD+oZaHVL1elyfEl6IHwc/0svF+JzVLiU9Bl51Hw2Vs2IGwGIzy/I9V5atnDuQRxpCqK+35ZJD+UHR0PCKZ02/7P0mvEpQrbOx1vuPLfWJaOtY4aTMwyokYU5Te8FvNWmIw1bKdphkh3VRndVGitr8vHA1u+ghyabpJ/fVN3YUhaRF3h1K6uBPWN48es1+pWLm+wVeHC9MipkpIuJFGkLx6cNAt5Y4VVKDkfgQnCd3qU7wGHoIGCBJTEX/9F33QgykAKnCM/QpugG61A/bCMleuzHXzhg02Os1q9/pJ3+u9TveE2WZm08RERql2BKwDYt4wZnF0bSPwhGxWze5b7HpCMVOkqZjplVJH+GP/rL7XSem95v+R/PGEY+Cu5apDv8fuNO06tQImO2A82JTAD3yD+9MTVefELGJbna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YScSNH9QBjdqwEiayzT5vLaKKO1hraIwkW9EhU6IPkOKStLR4BM3DupTed9yRhn97g== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: DJLIKZUiyiX8zxlZCPxUmJv4ewZQw0qgqP0H+vjAzUwlLjT0uDW2yhZIzKVKqmOaBmsAci2J8/aFyfqT8XYgasehWoBNI29js9KiYHJcWOIYRbZRVNSP010Bi60ObqenRR0G/R5JB2XHhqoema5eISutm9eTm4mq93sd8OJB/m5sPcwGciu0MYpGumsLkkwR21vLQaiW/MS0BAFAJp3m8acylx0zQvFt8HyMGHfqu+rUDPAQ4Teia2V2Hy9BYrqOPpu+WNOn1+4ClHN20pafFz7IgYH9iO3Vwp1hOoIyTleV682uDG4M1dTIglTpnGuD+DWEG2Huojo3dhg3iEILtkj30TFt+UCmcc57LiZwNZ/Iox1nbQJ9qJzjznj1E6yOgsdknTpxqMm2IBq4m1TLSnsi8yoxQ0DXW1F01G7P9p7738lPKvot2zi7LgxCjSLHx5cs9g126vREIJA2zjDnfpgzL4S+UaFS006q3JDoVMPVJ6ZrrorztSsbHmOr2oxUIRlJ5b3xZskkMaKsJn4NKYgP45M7SrBYAtt/bUrwcLqmHGzKqxKWtYcb2nROyLBvimRlhUwXkxkgmYbOuBZpbo/IuTXZ+M4/0Zyys3SA87o= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41598306-88f6-4e39-5526-08dcf2d9e40c 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:22.9831 (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: 8SD7InpWsUJAjLH18KUButYk6O1qgTWTPfBUGJtAc2m3eoP+4pSJuDZlQl8Nb7EZLzjlrCOlc2ZTXlGe9+Yg6CyXPs+bsRgO1UJ0Iy16JI0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB7437 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 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410220134 X-Proofpoint-ORIG-GUID: f9GLMFmV_wR4uE2WylsAauF2AlkWZZRf X-Proofpoint-GUID: f9GLMFmV_wR4uE2WylsAauF2AlkWZZRf X-Rspam-User: X-Stat-Signature: st15igk6jez3oxqgetn94ekrtw5c5fuo X-Rspamd-Queue-Id: 79E69180010 X-Rspamd-Server: rspam11 X-HE-Tag: 1729629672-599098 X-HE-Meta: U2FsdGVkX18fQRpOlrxoiIU1uXfD5uAhOgW673HJoiFKH4qCgrQt4EH3/Bhf23O1S+HJHSBAhr98c+URmxY7MaWNUA4nEkRmJqZysPu/1HF0M3sbwGEW6upz0/07NXHBfrs30OIxlL0S7DAXyYIhxRm1J55WGZE32DbyIzHeRAcRXAAUA4cBxeurqLa4q4Y5nz5XzLlhmofIb1VJsQDAor5W5RuTmFFuTCJeCgCi1fgvQJINFhmBG64NmK+aAp4CkXlVbL51SYzIS96GgsZVLhnAqCS+2q7JphxqxpcBR/SOMc/LL6+IYz9cjQXr1UxmwdZHY4ua25ieEuEupThT9IQFaSF3SDMawsf7daFPVUnEOvHw4101Ecss5T0om20qO049RYqY44gwGxqokiPeDcDkPOvhD6uBk8xUMnE5YVWAC6XYl7d9M8kqD0P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Pisyj8GS2A+ULRXn0hVLiXrMiS9ygdFZFH8JaPJ4KGKWJnSaiHSUMg 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: Add some additional vma_internal.h stubs in preparation for __mmap_region() being moved to mm/vma.c. Without these the move would result in the tests no longer compiling. Signed-off-by: Lorenzo Stoakes --- tools/testing/vma/vma_internal.h | 106 ++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) -- 2.47.0 diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_internal.h index c5b9da034511..bec50a8c846c 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -44,7 +44,9 @@ #define VM_LOCKED 0x00002000 #define VM_IO 0x00004000 #define VM_DONTEXPAND 0x00040000 +#define VM_LOCKONFAULT 0x00080000 #define VM_ACCOUNT 0x00100000 +#define VM_NORESERVE 0x00200000 #define VM_MIXEDMAP 0x10000000 #define VM_STACK VM_GROWSDOWN #define VM_SHADOW_STACK VM_NONE @@ -53,6 +55,14 @@ #define VM_ACCESS_FLAGS (VM_READ | VM_WRITE | VM_EXEC) #define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP | VM_MIXEDMAP) +/* This mask represents all the VMA flag bits used by mlock */ +#define VM_LOCKED_MASK (VM_LOCKED | VM_LOCKONFAULT) + +#ifdef CONFIG_64BIT +/* VM is sealed, in vm_flags */ +#define VM_SEALED _BITUL(63) +#endif + #define FIRST_USER_ADDRESS 0UL #define USER_PGTABLES_CEILING 0UL @@ -698,8 +708,9 @@ static inline void tlb_finish_mmu(struct mmu_gather *) { } -static inline void get_file(struct file *) +static inline struct file *get_file(struct file *f) { + return f; } static inline int vma_dup_policy(struct vm_area_struct *, struct vm_area_struct *) @@ -920,4 +931,97 @@ static inline bool signal_pending(void *) return false; } +static inline bool is_file_hugepages(struct file *) +{ + return false; +} + +int security_vm_enough_memory_mm(struct mm_struct *, long) +{ + return true; +} + +bool may_expand_vm(struct mm_struct *, vm_flags_t, unsigned long) +{ + return true; +} + +static inline void vm_flags_init(struct vm_area_struct *vma, + vm_flags_t flags) +{ + vma->__vm_flags = flags; +} + +static inline void vm_flags_set(struct vm_area_struct *vma, + vm_flags_t flags) +{ + vma_start_write(vma); + vma->__vm_flags |= flags; +} + +static inline void vm_flags_clear(struct vm_area_struct *vma, + vm_flags_t flags) +{ + vma_start_write(vma); + vma->__vm_flags &= ~flags; +} + +static inline int call_mmap(struct file *, struct vm_area_struct *) +{ + return 0; +} + +static inline int shmem_zero_setup(struct vm_area_struct *) +{ + return 0; +} + +static inline void vma_set_anonymous(struct vm_area_struct *vma) +{ + vma->vm_ops = NULL; +} + +static inline void ksm_add_vma(struct vm_area_struct *) +{ +} + +static inline void perf_event_mmap(struct vm_area_struct *) +{ +} + +static bool vma_is_dax(struct vm_area_struct *) +{ + return false; +} + +struct vm_area_struct *get_gate_vma(struct mm_struct *) +{ + return NULL; +} + +bool vma_wants_writenotify(struct vm_area_struct *vma, pgprot_t vm_page_prot); + +/* Update vma->vm_page_prot to reflect vma->vm_flags. */ +static inline void vma_set_page_prot(struct vm_area_struct *vma) +{ + unsigned long vm_flags = vma->vm_flags; + pgprot_t vm_page_prot; + + /* testing: we inline vm_pgprot_modify() to avoid clash with vma.h. */ + vm_page_prot = pgprot_modify(vma->vm_page_prot, vm_get_page_prot(vm_flags)); + + if (vma_wants_writenotify(vma, vm_page_prot)) { + vm_flags &= ~VM_SHARED; + /* testing: we inline vm_pgprot_modify() to avoid clash with vma.h. */ + vm_page_prot = pgprot_modify(vm_page_prot, vm_get_page_prot(vm_flags)); + } + /* remove_protection_ptes reads vma->vm_page_prot without mmap_lock */ + WRITE_ONCE(vma->vm_page_prot, vm_page_prot); +} + +static inline bool arch_validate_flags(unsigned long) +{ + return true; +} + #endif /* __MM_VMA_INTERNAL_H */ From patchwork Tue Oct 22 20:40:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13846152 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 4CA5DCDD0F4 for ; Tue, 22 Oct 2024 20:41:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA2D06B00A6; Tue, 22 Oct 2024 16:41:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C2A796B00B5; Tue, 22 Oct 2024 16:41:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A09226B00B6; Tue, 22 Oct 2024 16:41:36 -0400 (EDT) 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 7B0886B00A6 for ; Tue, 22 Oct 2024 16:41:36 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 214971204D3 for ; Tue, 22 Oct 2024 20:41:21 +0000 (UTC) X-FDA: 82702408278.08.215418D Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf28.hostedemail.com (Postfix) with ESMTP id 6A310C0013 for ; Tue, 22 Oct 2024 20:41:16 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hScche31; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=lh9nQm6b; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf28.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") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729629526; 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=6OaAYLfv3ucTeWXw9L1215jPvy4GpESA8WWmWuVuaUE=; b=2dXmJEGnzF1yrEIK/CEh7tJJcEqKaIZFQdkxWIpSthz2pHMDL22rUIv87a8j1CfTZatk22 DsTxKMAMb7hGd57jBZtzlwn/1NRknm3VBN7ZQ2YHxt175K3gjw5GocRCwnftWydJrFSlNq +lKq9AexvVHr1kO3X8YoSn0fJ7+VhqM= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729629526; a=rsa-sha256; cv=pass; b=PpnJZ7G7IVY3S+d9a1XULjoaPB2pHTHP9A09wP2ljhvqnScygcqX5vsNBqoHQEYaF5n1G3 HJ7NgvvYYenKtzpzhZU6WgoWqaj1zlDl309ri9QD/9ayf4RYuU/lxCp7SthLBZVwd6DGZM Qz+D4OTXtNlBj2coyEZhrfoUmw6kIDU= ARC-Authentication-Results: i=2; imf28.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hScche31; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=lh9nQm6b; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf28.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") 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 49MK3XLj017466; Tue, 22 Oct 2024 20:41:31 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=6OaAYLfv3ucTeWXw9L1215jPvy4GpESA8WWmWuVuaUE=; b= hScche31GSNLLsXMjENWvE+re7clPwY4OOZJHzH7RPyymwXU28uuKkRCLx0mIuqQ /RWQnnqy13AhfQe7F58fYAvjdoP0GNLDcMb/8OF7vHKi41YMRUQ6GuJ3M3+gUh5z UqGG6mSBeXpOXTYWJXbqLqMwbZ1AU1sytwxB62lg2nVEPEEKwS6I+XcwLUFGOa7m ytLLqbP+tE5j2IgiBogkTif7P7wxpUcCQbjZ8ErIJLlBrqI91sXfBYFc260UjNKh bgvG1fZWlSCnt4hmeg6gTGVdYFuTjccIH39Ew1/iRtnSBG9lvSAp03Sz9w/fLauj Z3mir5/Hwec9O4u7MrrboQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42ckkqwy26-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:30 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49MK26bU020317; Tue, 22 Oct 2024 20:41:29 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2168.outbound.protection.outlook.com [104.47.56.168]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42c37ef3r9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KOvA59Upmf2U2dj9/HlbjFJg74T+8e5GXr0wnjeChbAcGBK1ldfmmPwmhG0nhHiAiNIpD907sMdASMfxvhPWcUzqg/aZ7jXGwV91rJepM8Or4mbW99qLb1ZhcbFHz4aE/ITQVSYiFv0xpzPvqBLdKZpFGPUWIN4BAHY/rlXDk6U4QYFI53o45Yy5Jpb/WT2X13Bad+Ijr5rup1UNrz/ioalQbjTZdG+y+FW0dFh9PYMj+v0y/EPkNsZvgsCbEFn4Ho/0CC0xYJypY7UhcCbZtNWykjzfuDLuijlVxYBB+gFGZQSkiS4kdpAqpwcF915DFxCE7qUiD3kGRSU9zhLMTg== 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=6OaAYLfv3ucTeWXw9L1215jPvy4GpESA8WWmWuVuaUE=; b=BWYt+2seWqL0UdBjDrYj+k5/EG4/3bcvoM5BKP6Tup4xBJpNpxF52BWWpxWLwC4U3n4Is61DS7329hjnTldRQ3WtTNGRI6KdSGpUF+7mTswTrFvYsdQJArnbAFC7CcpX9YCgIe6SbNT8loeqtxmh5x6kZOpNiaCM7TxFaCZdin9kucguZSvobZPEmd5XxWGFUOJ0gVsotIf82TOOnG6PWwnux75mK4mJPagKvmlcyIqjQc1KVmnQwrChlSw8CokRVUEfmWmu2wsjC17ZG/z/Gr+ccBC9TWSE31pt6ojnM1RcpeiXLytlbF/mvl4o4DbgKmue1f/Bv2qs8V1EUu7J9w== 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=6OaAYLfv3ucTeWXw9L1215jPvy4GpESA8WWmWuVuaUE=; b=lh9nQm6b9q21rQgYYucr58ISykTs7rlpS/uUxy8CHsPoC80S2x6p2pdQl9kfZtHmjqfr/M6GG8ReXuED3jQkQ2meQhjkjPV6t9NXQVcAov79/58L25j5YRReaeR5ZkCsb5jWlgcNErltucUiA3SVEs/2WUJdEW1xDFgM2Ym9Mc4= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by CH0PR10MB7437.namprd10.prod.outlook.com (2603:10b6:610:193::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Tue, 22 Oct 2024 20:41:26 +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:26 +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 6/8] mm: insolate mmap internal logic to mm/vma.c Date: Tue, 22 Oct 2024 21:40:57 +0100 Message-ID: <0b90285f68de7d091595d78422f9e48eb8600b7a.1729628198.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0661.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:316::15) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|CH0PR10MB7437:EE_ X-MS-Office365-Filtering-Correlation-Id: e2b3d9ab-fbcc-4cdc-9d4c-08dcf2d9e64b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: MiGhNlcxffPlXRydNIxcInTUpWa8tHtnmTt4vA1MQfmFwTVavKjz/kcUzITDBf/F/bZl3wk1naIGDyyADHj2vOaACS6OODmIbncFg64IChWxKKN/PNa9+9b+8tkRhsG5TjC0mB+zw1j95WqaRMZhD1ify+pOmd9GXJCIJIbmnMQM4vLFwUMLShbZ5kVDA0o2TylsXfcnTm+lbD6CYceqUM6bhKmE0+URv8xX+Ev6akUg5MnEqVt5pO/B7FEraLelRJFFn4MWUI6uIn2uf+GCK7WIPutI+8/zNKzWm3sCDKNOknt4b/74dQaX1DlvNmUigAbF51YWEr//FB+Z3GYKOduY/ACPY2v26jijKN7xhQJW2Eq9qgi59HWktwRUz2gRbkBKNs8ww/mXRajWoNi/n6ZsQrcLC34ISpCOTU2QY+bu63H2Oon5jn78wnWU8urrNFEQ9KPOJtQHc0hhuZx3hSmcMxobqDFNq+/zoNL+1NrHJFpLek7Ev8IRJLi28PivIoPcYDvjWXoer63ZdJges35Tvup3Bhm/rjo7RoIjRgpK8kj0fCrIYr98uUbJppket49Tt1XsEl6jo9yl0YMjQjtTBbbq6gevet3vLDbVxzFfllWyA5hwOLM87boMpQYLRgaHeQt4aV60WS8k7ooHC6r1TxnUquKzNohExhUOkxa2WB28A8BUwmOqLTrc5PS+PQ/tcgVDePjDsD0Jn3WwC7e1APAJCRqjTsQi9CkqXD4bF+2D3/37J7eny0hrlZ83cLcv/ASsR65pdxJEbjHovYO1zdm4VaY6a0E2VcWBoqFnNP2mUWJvUIt+ddi8QDkRs6qUgvQQWo9BV2c2ipk65msAjBK6l0CZUouplRjGfok0aN9Va/vE+bZDslW7J79Y9DFAiFw2XNurOK2fzvRVi3VpniIAVLT+JOoaypJrnsQ+h/ogesYrgdB+vpjFNspXOGmjeXK1hi1cceVYpXqMrRHXcWhdLnGYVZZP/87cC0UV0o9Cc13V51dPrupc4wWdSQXaHLBYic5LFEUdsp58RK0yoRJbNBaLSAhTnU7GxY4Nb5hSjAmFzcYcQaTr0lBwzj6bvgzI9HGJzLpaJ68+oI2gC/Kn+7NsgHFPYB/BQq02dWpGtddvk6vMBvrnX/MMpiDpEoso5gkINu+lwZa0yQCnV34NXRbXYpGzU7H1wyvxd59yrOBlNHAda4a/qxR4LAzgps4ky1y7jrCZIKsueZ4maDKz4aJCXJT16XwwOvE4FmbaGXlhbqfaPTuas1ldVGUxueNLSQWFKtMQ4cinRi5n+Dibc3cfBiLlM8nGN4XmbOlqucVUhlSf4kBHrzgz 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)(10070799003)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rn/wtlHiuW1SyKoh26wb47uJHyJCLBavHNQ0Ibu9PYTeGy1n1GEOnIYU4TnpKnYUeO/PjglCHN9u1SFT7Dwo+1Z8W/0Pzkild7s7j9+MUw3GlZj4pLSZHnbDBIfHqXZdeXPa+3Cp8n1mbFVaBWwVRkReYeA0XbGUA51TxyCX7i7vSkwYDbODb+PGv5AHrMhGq6KNpHO53nCv4IfHhF0+8xkVs0KxqtMOU7AC6quLTSgRTeWTYrHcCr9YWoIjdEemsUJ7A/dgmMLme/4tdxlsGAt4bFQlph0MdqvKjrhrFyu2eQgHF5A/gFFrb9x7qQGzGwd/GcvDALAP71V2Mit5XL5CVv9ciB22Zg/dsYBXUySG0UpMN273+VAYEi082cqaRC9Uzw+VD1eCXFhmlkinB8tvRghDyO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Q+wzBM1uyYCs4KVvcbIbZDJHHOsPfE6UcfIU/4LtBO4+a6N/sXKv4cSDD8Ui8au3Iy+Yee2jitt2syFVbai5mL0kiDZWhXxgHykg8FLr+UZzTVUBcIGIAd3LYWHrvN6lEA3qjL8VIDxdn4NqMhpAxJMBJMgEtZ4SmqF6/RdkRno+69cQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: EuZ55C6AMsbmH8W9f1jWu+VWJ3b+0PqFqaHvfshQVonl/XXD0Hs17nP/SVh0JuSXcYGYUSff+kFMEuAIEMGYGxXPXGeAz6FJ8PBk3Siw5V5FsaWMAvd17CLSuBylJLCJ5aWW9M1z5Bpy4m6JQySygI25sb+qu8SL4FZDlvSkJsxfOAnjldahoTB5Js7KXQRf6KMiViBGPC/q+ZHmKLQc18ypbnW1xSRV22FJMDddCxhHP79goDcyIhjZ9HqDlFrKG7zOyhEEHibh2ANHsMeTfe16MEihW9VuLJHkKk80JqJF6l82NuoeGkpjjTeWsvPf7ryLgije7C32ef0DyF/BWjgsGa+nKFTPOp/YcUYxMkydK1p7ui/ujb6nC0mdptbnfce2lLwkYUaj3AFMkelyWbB358CGetJG8tXuQ1iUJloHv5g+PsuJqzd1b3sonb8WkzZ85y9fMZACQVDQzUlNgDKprZsRhtXGPcESZfmDzRARWPFQb5T4fgmlxmvi1KU2CBYSpcAA1OzWhLzBqdoLUCm9FfTCAzX/j6F/Hyza7qmyaojjKAE9rXuFDBr9Xv5fXjr30vbLTX9lwM0eOd4Ays3k3UGB4dwhmD88zxaUThE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e2b3d9ab-fbcc-4cdc-9d4c-08dcf2d9e64b 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:26.7792 (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: F3NAY8d/jsBs221Kg11m0goz7qOrCtGOQISK+dA6ORobGb4TiQfiJigeLUQBoPS43BDalRYkukuR7XdX/7I4vCcuhy+0voA52jtr2drqkwc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB7437 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 suspectscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 mlxscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410220134 X-Proofpoint-GUID: FfHMgnH1wUJLWAEkO_MGPTBhVvof2AfG X-Proofpoint-ORIG-GUID: FfHMgnH1wUJLWAEkO_MGPTBhVvof2AfG X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6A310C0013 X-Stat-Signature: z8pbzo5tg1h8o6xtrx456191yempi5mo X-Rspam-User: X-HE-Tag: 1729629676-969160 X-HE-Meta: U2FsdGVkX1/mxS9zFfZwhQg2sbABuI0P8lTv0/l4aQPAsP/HOAyf2sm1I2Jyd2JcP+lR7M6B9/WDxAZHMm21MbtHkcvaiGr9XzQGEzCravczoBC8iWCpiiZ8eWOIoR73l4kXEVoSa1NV8mPOkdQKQBtHZFnnE1bv4q8HVZHhMcvRckMJKXNQSTv4oRJ4yWgQ3qa++hxWCsobhERLf2cbiIXpllIXoe92OkEkT1ps6I6VKG6uyR0QK1OPEsPzU5S9yxhoU0bu/DVeSsuDr+F8SDqA3ztaXOUMx0z/wuTOnWgp5CU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a+h9i5JiT8RmnRou34harqgcnc8A70kEfqUksTi7PlYBj+qlZyRetM7GNIjP8UacwcHqXd2JHmGay7zo9shOOKv3tXdKvE+eOTqLfEpeoibYyxBp85qDcXc48RKpPQgBogicN9zcqZuTdw== 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: In previous commits we effected improvements to the mmap() logic in mmap_region() and its newly introduced internal implementation function __mmap_region(). However as these changes are intended to be backported, we kept the delta as small as is possible and made as few changes as possible to the newly introduced mm/vma.* files. Take the opportunity to move this logic to mm/vma.c which not only isolates it, but also makes it available for later userland testing which can help us catch such logic errors far earlier. Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 235 --------------------------------- mm/vma.c | 324 +++++++++++++++++++++++++++++++++++++++++++++- mm/vma.h | 97 +------------- mm/vma_internal.h | 5 + 4 files changed, 330 insertions(+), 331 deletions(-) -- 2.47.0 diff --git a/mm/mmap.c b/mm/mmap.c index 7d02b47a1895..1adf2c1cc3c0 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -577,22 +577,6 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_arg_struct __user *, arg) } #endif /* __ARCH_WANT_SYS_OLD_MMAP */ -/* - * We account for memory if it's a private writeable mapping, - * not hugepages and VM_NORESERVE wasn't set. - */ -static inline bool accountable_mapping(struct file *file, vm_flags_t vm_flags) -{ - /* - * hugetlb has its own accounting separate from the core VM - * VM_HUGETLB may not be set yet so we cannot check for that flag. - */ - if (file && is_file_hugepages(file)) - return false; - - return (vm_flags & (VM_NORESERVE | VM_SHARED | VM_WRITE)) == VM_WRITE; -} - /** * unmapped_area() - Find an area between the low_limit and the high_limit with * the correct alignment and offset, all from @info. Note: current->mm is used @@ -1361,225 +1345,6 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, return do_vmi_munmap(&vmi, mm, start, len, uf, false); } -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; - pgoff_t pglen = PHYS_PFN(len); - unsigned long charged = 0; - struct vma_munmap_struct vms; - struct ma_state mas_detach; - struct maple_tree mt_detach; - unsigned long end = addr + len; - int error; - VMA_ITERATOR(vmi, mm, addr); - VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); - - vmg.file = file; - /* Find the first overlapping VMA */ - vma = vma_find(&vmi, end); - init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false); - if (vma) { - mt_init_flags(&mt_detach, vmi.mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); - mt_on_stack(mt_detach); - mas_init(&mas_detach, &mt_detach, /* addr = */ 0); - /* Prepare to unmap any existing mapping in the area */ - error = vms_gather_munmap_vmas(&vms, &mas_detach); - if (error) - goto gather_failed; - - vmg.next = vms.next; - vmg.prev = vms.prev; - vma = NULL; - } else { - vmg.next = vma_iter_next_rewind(&vmi, &vmg.prev); - } - - /* Check against address space limit. */ - if (!may_expand_vm(mm, vm_flags, pglen - vms.nr_pages)) { - error = -ENOMEM; - goto abort_munmap; - } - - /* - * Private writable mapping: check memory availability - */ - if (accountable_mapping(file, vm_flags)) { - charged = pglen; - charged -= vms.nr_accounted; - if (charged) { - error = security_vm_enough_memory_mm(mm, charged); - if (error) - goto abort_munmap; - } - - vms.nr_accounted = 0; - vm_flags |= VM_ACCOUNT; - 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 mmap_file(), 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; - /* - * Determine the object being mapped and call the appropriate - * specific mapper. the address has already been validated, but - * not unmapped, but the maps are removed from the list. - */ - vma = vm_area_alloc(mm); - if (!vma) { - error = -ENOMEM; - goto unacct_error; - } - - vma_iter_config(&vmi, addr, end); - vma_set_range(vma, addr, end, pgoff); - vm_flags_init(vma, vm_flags); - vma->vm_page_prot = vm_get_page_prot(vm_flags); - - 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_file_vma; - - /* Drivers cannot alter the address of the VMA. */ - WARN_ON_ONCE(addr != vma->vm_start); - /* - * Drivers should not permit writability when previously it was - * disallowed. - */ - VM_WARN_ON_ONCE(vm_flags != vma->vm_flags && - !(vm_flags & VM_MAYWRITE) && - (vma->vm_flags & VM_MAYWRITE)); - - vma_iter_config(&vmi, addr, end); - /* - * 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)) { - struct vm_area_struct *merge; - - vmg.flags = vma->vm_flags; - /* If this fails, state is reset ready for a reattempt. */ - merge = vma_merge_new_range(&vmg); - - if (merge) { - /* - * ->mmap() can change vma->vm_file and fput - * the original file. So fput the vma->vm_file - * here or we would add an extra fput for file - * and cause general protection fault - * ultimately. - */ - fput(vma->vm_file); - vm_area_free(vma); - vma_iter_free(&vmi); - vma = merge; - /* Update vm_flags to pick up the change. */ - vm_flags = vma->vm_flags; - goto file_expanded; - } - vma_iter_config(&vmi, addr, end); - } - - vm_flags = vma->vm_flags; - } else if (vm_flags & VM_SHARED) { - error = shmem_zero_setup(vma); - if (error) - goto free_iter_vma; - } else { - vma_set_anonymous(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); - vma_iter_store(&vmi, vma); - mm->map_count++; - vma_link_file(vma); - - /* - * vma_merge_new_range() calls khugepaged_enter_vma() too, the below - * call covers the non-merge case. - */ - khugepaged_enter_vma(vma, vma->vm_flags); - -file_expanded: - file = vma->vm_file; - ksm_add_vma(vma); -expanded: - perf_event_mmap(vma); - - /* Unmap any existing mapping in the area */ - vms_complete_munmap_vmas(&vms, &mas_detach); - - vm_stat_account(mm, vm_flags, pglen); - if (vm_flags & VM_LOCKED) { - if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) || - is_vm_hugetlb_page(vma) || - vma == get_gate_vma(current->mm)) - vm_flags_clear(vma, VM_LOCKED_MASK); - else - mm->locked_vm += pglen; - } - - if (file) - uprobe_mmap(vma); - - /* - * New (or expanded) vma always get soft dirty status. - * Otherwise user-space soft-dirty page tracker won't - * be able to distinguish situation when vma area unmapped, - * then new mapped in-place (which must be aimed as - * a completely new data area). - */ - vm_flags_set(vma, VM_SOFTDIRTY); - - vma_set_page_prot(vma); - - return addr; - -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(&vmi.mas, vma, vmg.prev, vmg.next); -free_iter_vma: - vma_iter_free(&vmi); -free_vma: - vm_area_free(vma); -unacct_error: - if (charged) - vm_unacct_memory(charged); - -abort_munmap: - vms_abort_munmap_vmas(&vms, &mas_detach); -gather_failed: - 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) diff --git a/mm/vma.c b/mm/vma.c index bb7cfa2dc282..7617f9d50d62 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -1103,7 +1103,7 @@ static inline void vms_clear_ptes(struct vma_munmap_struct *vms, vms->clear_ptes = false; } -void vms_clean_up_area(struct vma_munmap_struct *vms, +static void vms_clean_up_area(struct vma_munmap_struct *vms, struct ma_state *mas_detach) { struct vm_area_struct *vma; @@ -1126,7 +1126,7 @@ void vms_clean_up_area(struct vma_munmap_struct *vms, * used for the munmap() and may downgrade the lock - if requested. Everything * needed to be done once the vma maple tree is updated. */ -void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, +static void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, struct ma_state *mas_detach) { struct vm_area_struct *vma; @@ -1167,6 +1167,23 @@ void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, __mt_destroy(mas_detach->tree); } +/* + * reattach_vmas() - Undo any munmap work and free resources + * @mas_detach: The maple state with the detached maple tree + * + * Reattach any detached vmas and free up the maple tree used to track the vmas. + */ +static void reattach_vmas(struct ma_state *mas_detach) +{ + struct vm_area_struct *vma; + + mas_set(mas_detach, 0); + mas_for_each(mas_detach, vma, ULONG_MAX) + vma_mark_detached(vma, false); + + __mt_destroy(mas_detach->tree); +} + /* * vms_gather_munmap_vmas() - Put all VMAs within a range into a maple tree * for removal at a later date. Handles splitting first and last if necessary @@ -1177,7 +1194,7 @@ void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, * * Return: 0 on success, error otherwise */ -int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, +static int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, struct ma_state *mas_detach) { struct vm_area_struct *next = NULL; @@ -1315,6 +1332,39 @@ int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, return error; } +/* + * init_vma_munmap() - Initializer wrapper for vma_munmap_struct + * @vms: The vma munmap struct + * @vmi: The vma iterator + * @vma: The first vm_area_struct to munmap + * @start: The aligned start address to munmap + * @end: The aligned end address to munmap + * @uf: The userfaultfd list_head + * @unlock: Unlock after the operation. Only unlocked on success + */ +static void init_vma_munmap(struct vma_munmap_struct *vms, + struct vma_iterator *vmi, struct vm_area_struct *vma, + unsigned long start, unsigned long end, struct list_head *uf, + bool unlock) +{ + vms->vmi = vmi; + vms->vma = vma; + if (vma) { + vms->start = start; + vms->end = end; + } else { + vms->start = vms->end = 0; + } + vms->unlock = unlock; + vms->uf = uf; + vms->vma_count = 0; + vms->nr_pages = vms->locked_vm = vms->nr_accounted = 0; + vms->exec_vm = vms->stack_vm = vms->data_vm = 0; + vms->unmap_start = FIRST_USER_ADDRESS; + vms->unmap_end = USER_PGTABLES_CEILING; + vms->clear_ptes = false; +} + /* * do_vmi_align_munmap() - munmap the aligned region from @start to @end. * @vmi: The vma iterator @@ -2069,3 +2119,271 @@ void mm_drop_all_locks(struct mm_struct *mm) mutex_unlock(&mm_all_locks_mutex); } + +/* + * We account for memory if it's a private writeable mapping, + * not hugepages and VM_NORESERVE wasn't set. + */ +static bool accountable_mapping(struct file *file, vm_flags_t vm_flags) +{ + /* + * hugetlb has its own accounting separate from the core VM + * VM_HUGETLB may not be set yet so we cannot check for that flag. + */ + if (file && is_file_hugepages(file)) + return false; + + return (vm_flags & (VM_NORESERVE | VM_SHARED | VM_WRITE)) == VM_WRITE; +} + +/* + * vms_abort_munmap_vmas() - Undo as much as possible from an aborted munmap() + * operation. + * @vms: The vma unmap structure + * @mas_detach: The maple state with the detached maple tree + * + * Reattach any detached vmas, free up the maple tree used to track the vmas. + * If that's not possible because the ptes are cleared (and vm_ops->closed() may + * have been called), then a NULL is written over the vmas and the vmas are + * removed (munmap() completed). + */ +static void vms_abort_munmap_vmas(struct vma_munmap_struct *vms, + struct ma_state *mas_detach) +{ + struct ma_state *mas = &vms->vmi->mas; + + if (!vms->nr_pages) + return; + + if (vms->clear_ptes) + return reattach_vmas(mas_detach); + + /* + * Aborting cannot just call the vm_ops open() because they are often + * not symmetrical and state data has been lost. Resort to the old + * failure method of leaving a gap where the MAP_FIXED mapping failed. + */ + mas_set_range(mas, vms->start, vms->end - 1); + mas_store_gfp(mas, NULL, GFP_KERNEL|__GFP_NOFAIL); + /* Clean up the insertion of the unfortunate gap */ + vms_complete_munmap_vmas(vms, mas_detach); +} + +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; + pgoff_t pglen = PHYS_PFN(len); + unsigned long charged = 0; + struct vma_munmap_struct vms; + struct ma_state mas_detach; + struct maple_tree mt_detach; + unsigned long end = addr + len; + int error; + VMA_ITERATOR(vmi, mm, addr); + VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); + + vmg.file = file; + /* Find the first overlapping VMA */ + vma = vma_find(&vmi, end); + init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false); + if (vma) { + mt_init_flags(&mt_detach, vmi.mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); + mt_on_stack(mt_detach); + mas_init(&mas_detach, &mt_detach, /* addr = */ 0); + /* Prepare to unmap any existing mapping in the area */ + error = vms_gather_munmap_vmas(&vms, &mas_detach); + if (error) + goto gather_failed; + + vmg.next = vms.next; + vmg.prev = vms.prev; + vma = NULL; + } else { + vmg.next = vma_iter_next_rewind(&vmi, &vmg.prev); + } + + /* Check against address space limit. */ + if (!may_expand_vm(mm, vm_flags, pglen - vms.nr_pages)) { + error = -ENOMEM; + goto abort_munmap; + } + + /* + * Private writable mapping: check memory availability + */ + if (accountable_mapping(file, vm_flags)) { + charged = pglen; + charged -= vms.nr_accounted; + if (charged) { + error = security_vm_enough_memory_mm(mm, charged); + if (error) + goto abort_munmap; + } + + vms.nr_accounted = 0; + vm_flags |= VM_ACCOUNT; + 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 mmap_file(), 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; + /* + * Determine the object being mapped and call the appropriate + * specific mapper. the address has already been validated, but + * not unmapped, but the maps are removed from the list. + */ + vma = vm_area_alloc(mm); + if (!vma) { + error = -ENOMEM; + goto unacct_error; + } + + vma_iter_config(&vmi, addr, end); + vma_set_range(vma, addr, end, pgoff); + vm_flags_init(vma, vm_flags); + vma->vm_page_prot = vm_get_page_prot(vm_flags); + + 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_file_vma; + + /* Drivers cannot alter the address of the VMA. */ + WARN_ON_ONCE(addr != vma->vm_start); + /* + * Drivers should not permit writability when previously it was + * disallowed. + */ + VM_WARN_ON_ONCE(vm_flags != vma->vm_flags && + !(vm_flags & VM_MAYWRITE) && + (vma->vm_flags & VM_MAYWRITE)); + + vma_iter_config(&vmi, addr, end); + /* + * 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)) { + struct vm_area_struct *merge; + + vmg.flags = vma->vm_flags; + /* If this fails, state is reset ready for a reattempt. */ + merge = vma_merge_new_range(&vmg); + + if (merge) { + /* + * ->mmap() can change vma->vm_file and fput + * the original file. So fput the vma->vm_file + * here or we would add an extra fput for file + * and cause general protection fault + * ultimately. + */ + fput(vma->vm_file); + vm_area_free(vma); + vma_iter_free(&vmi); + vma = merge; + /* Update vm_flags to pick up the change. */ + vm_flags = vma->vm_flags; + goto file_expanded; + } + vma_iter_config(&vmi, addr, end); + } + + vm_flags = vma->vm_flags; + } else if (vm_flags & VM_SHARED) { + error = shmem_zero_setup(vma); + if (error) + goto free_iter_vma; + } else { + vma_set_anonymous(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); + vma_iter_store(&vmi, vma); + mm->map_count++; + vma_link_file(vma); + + /* + * vma_merge_new_range() calls khugepaged_enter_vma() too, the below + * call covers the non-merge case. + */ + khugepaged_enter_vma(vma, vma->vm_flags); + +file_expanded: + file = vma->vm_file; + ksm_add_vma(vma); +expanded: + perf_event_mmap(vma); + + /* Unmap any existing mapping in the area */ + vms_complete_munmap_vmas(&vms, &mas_detach); + + vm_stat_account(mm, vm_flags, pglen); + if (vm_flags & VM_LOCKED) { + if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) || + is_vm_hugetlb_page(vma) || + vma == get_gate_vma(current->mm)) + vm_flags_clear(vma, VM_LOCKED_MASK); + else + mm->locked_vm += pglen; + } + + if (file) + uprobe_mmap(vma); + + /* + * New (or expanded) vma always get soft dirty status. + * Otherwise user-space soft-dirty page tracker won't + * be able to distinguish situation when vma area unmapped, + * then new mapped in-place (which must be aimed as + * a completely new data area). + */ + vm_flags_set(vma, VM_SOFTDIRTY); + + vma_set_page_prot(vma); + + return addr; + +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(&vmi.mas, vma, vmg.prev, vmg.next); +free_iter_vma: + vma_iter_free(&vmi); +free_vma: + vm_area_free(vma); +unacct_error: + if (charged) + vm_unacct_memory(charged); + +abort_munmap: + vms_abort_munmap_vmas(&vms, &mas_detach); +gather_failed: + return error; +} diff --git a/mm/vma.h b/mm/vma.h index 75558b5e9c8c..eb15616e4e2c 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -165,99 +165,6 @@ static inline int vma_iter_store_gfp(struct vma_iterator *vmi, return 0; } -#ifdef CONFIG_MMU -/* - * init_vma_munmap() - Initializer wrapper for vma_munmap_struct - * @vms: The vma munmap struct - * @vmi: The vma iterator - * @vma: The first vm_area_struct to munmap - * @start: The aligned start address to munmap - * @end: The aligned end address to munmap - * @uf: The userfaultfd list_head - * @unlock: Unlock after the operation. Only unlocked on success - */ -static inline void init_vma_munmap(struct vma_munmap_struct *vms, - struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long start, unsigned long end, struct list_head *uf, - bool unlock) -{ - vms->vmi = vmi; - vms->vma = vma; - if (vma) { - vms->start = start; - vms->end = end; - } else { - vms->start = vms->end = 0; - } - vms->unlock = unlock; - vms->uf = uf; - vms->vma_count = 0; - vms->nr_pages = vms->locked_vm = vms->nr_accounted = 0; - vms->exec_vm = vms->stack_vm = vms->data_vm = 0; - vms->unmap_start = FIRST_USER_ADDRESS; - vms->unmap_end = USER_PGTABLES_CEILING; - vms->clear_ptes = false; -} -#endif - -int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, - struct ma_state *mas_detach); - -void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, - struct ma_state *mas_detach); - -void vms_clean_up_area(struct vma_munmap_struct *vms, - struct ma_state *mas_detach); - -/* - * reattach_vmas() - Undo any munmap work and free resources - * @mas_detach: The maple state with the detached maple tree - * - * Reattach any detached vmas and free up the maple tree used to track the vmas. - */ -static inline void reattach_vmas(struct ma_state *mas_detach) -{ - struct vm_area_struct *vma; - - mas_set(mas_detach, 0); - mas_for_each(mas_detach, vma, ULONG_MAX) - vma_mark_detached(vma, false); - - __mt_destroy(mas_detach->tree); -} - -/* - * vms_abort_munmap_vmas() - Undo as much as possible from an aborted munmap() - * operation. - * @vms: The vma unmap structure - * @mas_detach: The maple state with the detached maple tree - * - * Reattach any detached vmas, free up the maple tree used to track the vmas. - * If that's not possible because the ptes are cleared (and vm_ops->closed() may - * have been called), then a NULL is written over the vmas and the vmas are - * removed (munmap() completed). - */ -static inline void vms_abort_munmap_vmas(struct vma_munmap_struct *vms, - struct ma_state *mas_detach) -{ - struct ma_state *mas = &vms->vmi->mas; - if (!vms->nr_pages) - return; - - if (vms->clear_ptes) - return reattach_vmas(mas_detach); - - /* - * Aborting cannot just call the vm_ops open() because they are often - * not symmetrical and state data has been lost. Resort to the old - * failure method of leaving a gap where the MAP_FIXED mapping failed. - */ - mas_set_range(mas, vms->start, vms->end - 1); - mas_store_gfp(mas, NULL, GFP_KERNEL|__GFP_NOFAIL); - /* Clean up the insertion of the unfortunate gap */ - vms_complete_munmap_vmas(vms, mas_detach); -} - int do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, struct mm_struct *mm, unsigned long start, @@ -336,6 +243,10 @@ bool vma_wants_writenotify(struct vm_area_struct *vma, pgprot_t vm_page_prot); int mm_take_all_locks(struct mm_struct *mm); void mm_drop_all_locks(struct mm_struct *mm); +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); + static inline bool vma_wants_manual_pte_write_upgrade(struct vm_area_struct *vma) { /* diff --git a/mm/vma_internal.h b/mm/vma_internal.h index b930ab12a587..fc5f172a36bd 100644 --- a/mm/vma_internal.h +++ b/mm/vma_internal.h @@ -17,8 +17,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -32,11 +34,14 @@ #include #include #include +#include #include #include #include #include #include +#include +#include #include #include #include From patchwork Tue Oct 22 20:40: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: 13846153 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 96852CDD0EA for ; Tue, 22 Oct 2024 20:41:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 241666B00A3; Tue, 22 Oct 2024 16:41:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CACC6B00A7; Tue, 22 Oct 2024 16:41:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9C9C6B00B8; Tue, 22 Oct 2024 16:41:39 -0400 (EDT) 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 C31D26B00B6 for ; Tue, 22 Oct 2024 16:41:39 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9EB36C04F6 for ; Tue, 22 Oct 2024 20:41:21 +0000 (UTC) X-FDA: 82702408656.12.EAA6EE0 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf17.hostedemail.com (Postfix) with ESMTP id 8166240004 for ; Tue, 22 Oct 2024 20:41:23 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="SkM/NLbI"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=c4qV4smk; 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=1729629658; a=rsa-sha256; cv=pass; b=XJ7cCBCbit2BXMoO8ebr1qEUeisGyNXHPAySuAsn8vqt0zfwcdTaZ5DXyBNT/6Xdmjv2yx y3zaVVSJTybwLDcVq5CoZeI1k4iA+9O5FsX9H0yOTeZMq+wCqOZoScenknBFy10+honnsH BgePzRIF3HIVYUHtbq858Z6QhW/vimU= ARC-Authentication-Results: i=2; imf17.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="SkM/NLbI"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=c4qV4smk; 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=1729629658; 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=BXayzKW+JRbaXCboa+yyboq8km8gURUeWkwUdDs/fdk=; b=Pg0l9h3dgcUZgg4p3LjCoH/Wv/0JAyj8sa5J8hZJ8XJP60sAEi6xGtovAwvDe/iJg3DnTK ErAMhVyxP1k50rUZH04ZsYQ44VfWjcoOO2yBbML0KrjZ4k9sjrjwJIoTfK68E4UPvvuZt2 dmjXntFuilp+7cRFQ9QHR7qA5hWEbP4= 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 49MK3Xbs017462; Tue, 22 Oct 2024 20:41: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=BXayzKW+JRbaXCboa+yyboq8km8gURUeWkwUdDs/fdk=; b= SkM/NLbIKZvJZytfp8LZxqN7GLkP/FhhOq5fAB87fothJ2oYfI5PeG+fUySpOcn+ thOQD4snAlfIgqie7O4qw5xPTF8LBsFMD6SeFznxRc1MVmfxDS71cqN29dBH/Pxj 60Z0AGRD4xheX94Pa+PJev+JNd1Fad9EXEhixB0sEQL6aN5EGVg2CUttGlI9XFGZ d1Z8iOO8NwDLfRAwUgLEGzF5ThbU6gLzD0pbkAIRFEhZK3PRRH6I1kaeyfzA9Zu9 p8HCC+GCPlWDYPcOHiXQRqiA++ZYXmtxeuCwbPIMZar1LY24BT0RHo3GqbypjZwn 9SfUjcLZj3fZsrNz5HUxwg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42ckkqwy2h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:34 +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 49MKSeQk026202; Tue, 22 Oct 2024 20:41:33 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2174.outbound.protection.outlook.com [104.47.58.174]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42c3786y7d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gY6QxKPXFX8E+lrcmGp3tDK23TrNE/otmDQOKyLY552yvz9teqtWdUvbcdwVDNHKk/dvkYo2qhoxXOSk9QCLK6/UnYRG9RIiB8Kv+JGBNWbo4F7OsVhzUlsDAKUf4DOKKFsnX3+VSGcaLAYG1gYQdxWV6Y7TptKmHhgo/BUcIyqsaKXYoBgwQATGR8IuWBlTVK6w2gXTYWSw+n8SfjDQ4sSmYKv2EZCzyW2uP/jWyekrlcxm/PX7egWeikzV/zE3PAFcf1zKi0dDt61lzHteXBGaAZ64pvngBy4YoE0YWmrQI3LoYAClzcuZFxh2fUlZ8jihy4JtU4jXwGxuHHsQrA== 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=BXayzKW+JRbaXCboa+yyboq8km8gURUeWkwUdDs/fdk=; b=a+BcHNbMHHUL6mXiWIs1Srm/FdA+7FWvdjElPdxuNHA3TziSjzKrN3Fa4cfbtyKv2jCuL3bJLn+GEdvZmAnd8pzqvIGXfEEL/FPzhaw0NZORGqQyOS3+woa2CI2MePli16ifHCiXZs5k7TBfb02D/rakq+8KDnung1xWoIkPvW+mKA4iLzaVBKZ0EP4L96avAojJG4e1FOkuaipOGqZyKp9OSnYJoTFXryzOn/uQwT54tebmuk/IOAtQcgjpacUKblIyPVbmkk7+Z+J6g07YjswW7V/0nwtV97eAX8ixDVghdKaaGnFl9a2zbrsnQzs0P8ulgJu243XJ1mFoHspUHw== 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=BXayzKW+JRbaXCboa+yyboq8km8gURUeWkwUdDs/fdk=; b=c4qV4smkZY5UjJ1Dq6ke3R+GTmzDxI2g9LVdCNqmCATFiodiyP1kRb+dlcKdv8CJZPZ/BfIKYq66bjDTIkOkGdBvN20rPfUlFjevOy9kAvlTriHNSlDD6apPkvJoXPOW9VfqrTteAYM0Dn3ZRpcXWtPwLFe2s9oR+2Unz2hfMN0= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by CH0PR10MB7437.namprd10.prod.outlook.com (2603:10b6:610:193::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Tue, 22 Oct 2024 20:41:30 +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:30 +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 7/8] mm: refactor __mmap_region() Date: Tue, 22 Oct 2024 21:40:58 +0100 Message-ID: <125b6ebddc7ae8790b8b10b47906c2d39e68f3d9.1729628198.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0057.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:60::21) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|CH0PR10MB7437:EE_ X-MS-Office365-Filtering-Correlation-Id: 7094f31e-58b4-4183-2383-08dcf2d9e890 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: obceIAltgyCD31yP6ZP/386kh/meg4pu082wVpMLK4a+nvzWl2jwZIo1OT4hoPGLbA5jntQfX3IXhAUa8ujKvWDY6O4WmvzSXspoILLXguAeheKx3U9HgimMN2OK1PcsSpaGVOjIix/gL2f5ML/A6Poi/LqNre6lzpbnowEdq89l99R6lvl90l4mu4JQ9lfk1k/pd5ba6MJ1mYKi/6C1zeA3mwcvsxcvx1ylTwoERY4CiqezXBuyV4IrWYOqgr2uVikHeRpN2ryCslmxK7jpufgIcNVHCAr/p8XE8840eTejl/sHIU+lI5pcn8CBhz8YsZlXV8NO/35U6raV1/eP4LD2HfgE4mn4tZw/Pe0iB1jykqqlAgS/gTUhNaGzZ5kjRSNmVzlhjWvZQMEPdGUe6Lx1agekykgf0nfUyRGUw2ahRbTI75BZak8U98OK/jAUeYOD3TxKF05MTeP++Ji70WHHWqQsu217kejwidQCEirwqRUs4okbHM5UUjhMhvueoRN+IcABwKJMHp2pKD7/8L+vapznmcKe6pNqUJGH309iEJKBD6exu53wAK3yBoYptvrXFo/gEhHlS/1pJhIEAl4hEb+kGC/8Z5HFE5C+Z9/+e7E5UD70OfU+lqdT1C6o5jASusErAfCENKyKTIOdLp4z120EE+7SWCC7DCTPlmr23L3rTz7fHvMe8FCDq8IIR0p+qPLORuKtsSCPTnSIPiHMGsLrWKculmUetTt4Rkw2+U/dX/JI+PrUdSQdfFQ/Y9cutCo5wg0us1mS9/L0yp7zy+uv36g/6JXJn3AP8dbNG2smFw5R5FQcdE30DGr8FK5XOFlcSbbbEhKJi6ruTbHZhOkKBk3xzLQx+gXPkUV9v/aSxsV4lehcy808cRsGhk7T7fSzSFnXKznVrCUh6TFIslUM6gf0/K93iukxQfYL4H6Js4YqqtMYNETEzuHSK12eKjAm3qDQV08K6KRMgM0WP0e4s9O8tlbSX1fnG8e4CzbyZnWLmUBcuw/QJhw/y3zR6WP3vhwgVzJjbp60EEKFCPlXqeCEDsFzEQnIWdw+o6qzGmh1eHspUbN4tPhYckRvk73Ot9OTm2YpPvMB4x5F07oOV67hrHoo8ECZmmNwM+0eZs38PTHAsP+ZwjYjPlBZcFq/1orQx0wiCvH7s5dTIVcPwb9FzM2oKG/vaH84knD6vGyqmMmG5yzDVgRSeq4HLtLjdhIVNBdELEj47p+isxhpOn/QBRqDzY5TQXBuF/GY7POcXPaTRwJy4JpT6H5T/FsLa0enz835I1yssIuD/W6+TehSA2fpB1o+8hG1gS6ubh74tDp6ez4+8Awm 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)(10070799003)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GHxcu/iUi/weqrkN44zOKWZcQJHOVKLFhAFChx597TwgqMq4Qh3Fb6nB02aUpxedbbcfS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1pGWFD04wWfIvnVnxGFu/pJi1nFX34A4r9LpyMZK4GrVySMNMO371ze3Ok2EUtDAMYUWfJv9ZHcZMcnkhEnMsCCwhehTVF8nA9KEvKOem9Nl4L0e6gl+gTDXLmJF+r0c= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7094f31e-58b4-4183-2383-08dcf2d9e890 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:30.5614 (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: 7doej8ELU+6U+B8YxRsSOKY/LqCp26xmSGq+RjA4+2NlwMK0X0DnyjD/n8o+UjlxEiIj7wxItfcJpEToFQ4gq9qZR4j99c7BRbJQoDOr2Go= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB7437 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 adultscore=0 suspectscore=0 spamscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410220134 X-Proofpoint-GUID: XNdwUTDDwNH2hKNDT-2pUgCrDl7KjbfC X-Proofpoint-ORIG-GUID: XNdwUTDDwNH2hKNDT-2pUgCrDl7KjbfC X-Rspam-User: X-Stat-Signature: y4zopp8xfzdc533auonshqpqq6956a6z X-Rspamd-Queue-Id: 8166240004 X-Rspamd-Server: rspam02 X-HE-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WpTAIQFSzY6inbvhKDf9cm9n0vJ7TTkoGkGZBajl10XPlLBWImiGvb0URpSoUnsJ6lFivYS/q93NKqmNZ4FFAcgzQTzZw1pr330H2apj+TkQQoykeNpraVkfEd9Eooy+xqu+ZB2sKDl9jmF9SZd+6q0t5ZJ2t7C6SN4No3idFmDTzvq3WfytPKM8eiT4wjIrqu4f76ICSj2OJ/uuX5swrtZug9X8KGoOyZ58iO/IXbwWLtFWzyF1wEifIeXFqvVla0h2F6D8/NV7i0reLyuwP7BhSrDroOgdezegvKGzH6+kPf844T9uMeih7Os5DgasgS5QhfmOITjoLHMnYJkGpM0zGrgOC7MOSNsLXgsP+ShujON4auMAQotHBgSBr+Lz3IAmaysZH/cOtzj+aeYQ4VrQTNSvlAnf4EjDBWa6wjg1X37AZCwEsg6i329RxocijwWwWLlg5iTeIopZgqd5y4GQwLRYZ5Lb6Zkt5UfnwSBugocN2sLn6xzQ== 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: We have seen bugs and resource leaks arise from the complexity of the __mmap_region() function. This, and the generally deeply fragile error handling logic and complexity which makes understanding the function difficult make it highly desirable to refactor it into something readable. Achieve this by separating the function into smaller logical parts which are easier to understand and follow, and which importantly very significantly simplify the error handling. Note that we now call vms_abort_munmap_vmas() in more error paths than we used to, however in cases where no abort need occur, vms->nr_pages will be equal to zero and we simply exit this function without doing more than we would have done previously. Importantly, the invocation of the driver mmap hook via mmap_file() now has very simple and obvious handling (this was previously the most problematic part of the mmap() operation). Signed-off-by: Lorenzo Stoakes --- mm/vma.c | 380 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 240 insertions(+), 140 deletions(-) -- 2.47.0 diff --git a/mm/vma.c b/mm/vma.c index 7617f9d50d62..a271e2b406ab 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -7,6 +7,31 @@ #include "vma_internal.h" #include "vma.h" +struct mmap_state { + struct mm_struct *mm; + struct vma_iterator *vmi; + struct vma_merge_struct *vmg; + struct list_head *uf; + + struct vma_munmap_struct vms; + struct ma_state mas_detach; + struct maple_tree mt_detach; + + unsigned long flags; + unsigned long pglen; + unsigned long charged; +}; + +#define MMAP_STATE(name, mm_, vmi_, vmg_, uf_, flags_, len_) \ + struct mmap_state name = { \ + .mm = mm_, \ + .vmi = vmi_, \ + .vmg = vmg_, \ + .uf = uf_, \ + .flags = flags_, \ + .pglen = PHYS_PFN(len_), \ + } + static inline bool is_mergeable_vma(struct vma_merge_struct *vmg, bool merge_next) { struct vm_area_struct *vma = merge_next ? vmg->next : vmg->prev; @@ -2169,189 +2194,247 @@ static void vms_abort_munmap_vmas(struct vma_munmap_struct *vms, vms_complete_munmap_vmas(vms, mas_detach); } -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) +/* + * __mmap_prepare() - Prepare to gather any overlapping VMAs that need to be + * unmapped once the map operation is completed, check limits, + * account mapping and clean up any pre-existing VMAs. + * + * @map: Mapping state. + * + * Returns: 0 on success, error code otherwise. + */ +static int __mmap_prepare(struct mmap_state *map) { - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma = NULL; - pgoff_t pglen = PHYS_PFN(len); - unsigned long charged = 0; - struct vma_munmap_struct vms; - struct ma_state mas_detach; - struct maple_tree mt_detach; - unsigned long end = addr + len; int error; - VMA_ITERATOR(vmi, mm, addr); - VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); - - vmg.file = file; - /* Find the first overlapping VMA */ - vma = vma_find(&vmi, end); - init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false); - if (vma) { - mt_init_flags(&mt_detach, vmi.mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); - mt_on_stack(mt_detach); - mas_init(&mas_detach, &mt_detach, /* addr = */ 0); + struct vma_iterator *vmi = map->vmi; + struct vma_merge_struct *vmg = map->vmg; + struct vma_munmap_struct *vms = &map->vms; + + /* Find the first overlapping VMA and initialise unmap state. */ + vms->vma = vma_find(vmi, vmg->end); + init_vma_munmap(vms, vmi, vms->vma, vmg->start, vmg->end, map->uf, + /* unlock = */ false); + + /* OK, we have overlapping VMAs - prepare to unmap them. */ + if (vms->vma) { + mt_init_flags(&map->mt_detach, vmi->mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); + mt_on_stack(map->mt_detach); + mas_init(&map->mas_detach, &map->mt_detach, /* addr = */ 0); /* Prepare to unmap any existing mapping in the area */ - error = vms_gather_munmap_vmas(&vms, &mas_detach); + error = vms_gather_munmap_vmas(vms, &map->mas_detach); if (error) - goto gather_failed; + return error; - vmg.next = vms.next; - vmg.prev = vms.prev; - vma = NULL; + vmg->next = vms->next; + vmg->prev = vms->prev; } else { - vmg.next = vma_iter_next_rewind(&vmi, &vmg.prev); + vmg->next = vma_iter_next_rewind(vmi, &vmg->prev); } /* Check against address space limit. */ - if (!may_expand_vm(mm, vm_flags, pglen - vms.nr_pages)) { - error = -ENOMEM; - goto abort_munmap; - } + if (!may_expand_vm(map->mm, map->flags, map->pglen - vms->nr_pages)) + return -ENOMEM; - /* - * Private writable mapping: check memory availability - */ - if (accountable_mapping(file, vm_flags)) { - charged = pglen; - charged -= vms.nr_accounted; - if (charged) { - error = security_vm_enough_memory_mm(mm, charged); + /* Private writable mapping: check memory availability. */ + if (accountable_mapping(vmg->file, map->flags)) { + map->charged = map->pglen; + map->charged -= vms->nr_accounted; + if (map->charged) { + error = security_vm_enough_memory_mm(map->mm, map->charged); if (error) - goto abort_munmap; + return error; } - vms.nr_accounted = 0; - vm_flags |= VM_ACCOUNT; - vmg.flags = vm_flags; + vms->nr_accounted = 0; + map->flags |= VM_ACCOUNT; } /* - * clear PTEs while the vma is still in the tree so that rmap + * 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 mmap_file(), 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; + vms_clean_up_area(vms, &map->mas_detach); + + return 0; +} + +static int __mmap_new_file_vma(struct mmap_state *map, struct vm_area_struct *vma, + struct vm_area_struct **mergep) +{ + struct vma_iterator *vmi = map->vmi; + struct vma_merge_struct *vmg = map->vmg; + int error; + + vma->vm_file = get_file(vmg->file); + error = mmap_file(vma->vm_file, vma); + if (error) { + 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(&vmi->mas, vma, vmg->prev, vmg->next); + + return error; + } + + /* Drivers cannot alter the address of the VMA. */ + WARN_ON_ONCE(vmg->start != vma->vm_start); + /* + * Drivers should not permit writability when previously it was + * disallowed. + */ + VM_WARN_ON_ONCE(map->flags != vma->vm_flags && + !(map->flags & VM_MAYWRITE) && + (vma->vm_flags & VM_MAYWRITE)); + + vma_iter_config(vmi, vmg->start, vmg->end); + /* + * If flags changed after mmap_file(), we should try merge + * vma again as we may succeed this time. + */ + if (unlikely(map->flags != vma->vm_flags && vmg->prev)) { + struct vm_area_struct *merge; + + vmg->flags = vma->vm_flags; + /* If this fails, state is reset ready for a reattempt. */ + merge = vma_merge_new_range(vmg); + + if (merge) { + /* + * ->mmap() can change vma->vm_file and fput + * the original file. So fput the vma->vm_file + * here or we would add an extra fput for file + * and cause general protection fault + * ultimately. + */ + fput(vma->vm_file); + vm_area_free(vma); + vma_iter_free(vmi); + *mergep = merge; + } else { + vma_iter_config(vmi, vmg->start, vmg->end); + } + } + + map->flags = vma->vm_flags; + return 0; +} + +/* + * __mmap_new_vma() - Allocate a new VMA for the region, as merging was not + * possible. + * + * An exception to this is if the mapping is file-backed, and + * the underlying driver changes the VMA flags, permitting a + * subsequent merge of the VMA, in which case the returned + * VMA is one that was merged on a second attempt. + * + * @map: Mapping state. + * @vmap: Output pointer for the new VMA. + * + * Returns: Zero on success, or an error. + */ +static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap) +{ + struct vma_iterator *vmi = map->vmi; + struct vma_merge_struct *vmg = map->vmg; + struct vm_area_struct *merge = NULL; + int error = 0; + struct vm_area_struct *vma; + /* * Determine the object being mapped and call the appropriate * specific mapper. the address has already been validated, but * not unmapped, but the maps are removed from the list. */ - vma = vm_area_alloc(mm); - if (!vma) { - error = -ENOMEM; - goto unacct_error; - } + vma = vm_area_alloc(map->mm); + if (!vma) + return -ENOMEM; - vma_iter_config(&vmi, addr, end); - vma_set_range(vma, addr, end, pgoff); - vm_flags_init(vma, vm_flags); - vma->vm_page_prot = vm_get_page_prot(vm_flags); + vma_iter_config(vmi, vmg->start, vmg->end); + vma_set_range(vma, vmg->start, vmg->end, vmg->pgoff); + vm_flags_init(vma, map->flags); + vma->vm_page_prot = vm_get_page_prot(map->flags); - if (vma_iter_prealloc(&vmi, 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_file_vma; - - /* Drivers cannot alter the address of the VMA. */ - WARN_ON_ONCE(addr != vma->vm_start); - /* - * Drivers should not permit writability when previously it was - * disallowed. - */ - VM_WARN_ON_ONCE(vm_flags != vma->vm_flags && - !(vm_flags & VM_MAYWRITE) && - (vma->vm_flags & VM_MAYWRITE)); - - vma_iter_config(&vmi, addr, end); - /* - * 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)) { - struct vm_area_struct *merge; - - vmg.flags = vma->vm_flags; - /* If this fails, state is reset ready for a reattempt. */ - merge = vma_merge_new_range(&vmg); - - if (merge) { - /* - * ->mmap() can change vma->vm_file and fput - * the original file. So fput the vma->vm_file - * here or we would add an extra fput for file - * and cause general protection fault - * ultimately. - */ - fput(vma->vm_file); - vm_area_free(vma); - vma_iter_free(&vmi); - vma = merge; - /* Update vm_flags to pick up the change. */ - vm_flags = vma->vm_flags; - goto file_expanded; - } - vma_iter_config(&vmi, addr, end); - } - - vm_flags = vma->vm_flags; - } else if (vm_flags & VM_SHARED) { + if (vmg->file) + error = __mmap_new_file_vma(map, vma, &merge); + else if (map->flags & VM_SHARED) error = shmem_zero_setup(vma); - if (error) - goto free_iter_vma; - } else { + else vma_set_anonymous(vma); - } + + if (error) + goto free_iter_vma; + + if (merge) + goto file_expanded; #ifdef CONFIG_SPARC64 /* TODO: Fix SPARC ADI! */ - WARN_ON_ONCE(!arch_validate_flags(vm_flags)); + WARN_ON_ONCE(!arch_validate_flags(map->flags)); #endif /* Lock the VMA since it is modified after insertion into VMA tree */ vma_start_write(vma); - vma_iter_store(&vmi, vma); - mm->map_count++; + vma_iter_store(vmi, vma); + map->mm->map_count++; vma_link_file(vma); /* * vma_merge_new_range() calls khugepaged_enter_vma() too, the below * call covers the non-merge case. */ - khugepaged_enter_vma(vma, vma->vm_flags); + khugepaged_enter_vma(vma, map->flags); file_expanded: - file = vma->vm_file; ksm_add_vma(vma); -expanded: + + *vmap = vma; + return 0; + +free_iter_vma: + vma_iter_free(vmi); +free_vma: + vm_area_free(vma); + return error; +} + +/* + * __mmap_complete() - Unmap any VMAs we overlap, account memory mapping + * statistics, handle locking and finalise the VMA. + * + * @map: Mapping state. + * @vma: Merged or newly allocated VMA for the mmap()'d region. + */ +static void __mmap_complete(struct mmap_state *map, struct vm_area_struct *vma) +{ + struct mm_struct *mm = map->mm; + unsigned long vm_flags = vma->vm_flags; + perf_event_mmap(vma); - /* Unmap any existing mapping in the area */ - vms_complete_munmap_vmas(&vms, &mas_detach); + /* Unmap any existing mapping in the area. */ + vms_complete_munmap_vmas(&map->vms, &map->mas_detach); - vm_stat_account(mm, vm_flags, pglen); + vm_stat_account(mm, vma->vm_flags, map->pglen); if (vm_flags & VM_LOCKED) { if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) || is_vm_hugetlb_page(vma) || - vma == get_gate_vma(current->mm)) + vma == get_gate_vma(mm)) vm_flags_clear(vma, VM_LOCKED_MASK); else - mm->locked_vm += pglen; + mm->locked_vm += map->pglen; } - if (file) + if (vma->vm_file) uprobe_mmap(vma); /* @@ -2364,26 +2447,43 @@ unsigned long __mmap_region(struct file *file, unsigned long addr, vm_flags_set(vma, VM_SOFTDIRTY); vma_set_page_prot(vma); +} - return addr; +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; + int error; + VMA_ITERATOR(vmi, mm, addr); + VMG_STATE(vmg, mm, &vmi, addr, addr + len, vm_flags, pgoff); + MMAP_STATE(map, mm, &vmi, &vmg, uf, vm_flags, len); -unmap_and_free_file_vma: - fput(vma->vm_file); - vma->vm_file = NULL; + vmg.file = file; - vma_iter_set(&vmi, vma->vm_end); - /* Undo any partial mapping done by a device driver. */ - unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); -free_iter_vma: - vma_iter_free(&vmi); -free_vma: - vm_area_free(vma); -unacct_error: - if (charged) - vm_unacct_memory(charged); + error = __mmap_prepare(&map); + if (error) + goto abort_munmap; + + /* Attempt to merge with adjacent VMAs... */ + vmg.flags = map.flags; + vma = vma_merge_new_range(&vmg); + if (!vma) { + /* ...but if we can't, allocate a new VMA. */ + error = __mmap_new_vma(&map, &vma); + if (error) + goto unacct_error; + } + + __mmap_complete(&map, vma); + return addr; + +unacct_error: + if (map.charged) + vm_unacct_memory(map.charged); abort_munmap: - vms_abort_munmap_vmas(&vms, &mas_detach); -gather_failed: + vms_abort_munmap_vmas(&map.vms, &map.mas_detach); return error; } From patchwork Tue Oct 22 20:40:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13846154 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 85393CDD0F4 for ; Tue, 22 Oct 2024 20:41:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E4006B00B6; Tue, 22 Oct 2024 16:41:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 01CCA6B00B7; Tue, 22 Oct 2024 16:41:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3D446B00B8; Tue, 22 Oct 2024 16:41:42 -0400 (EDT) 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 AF9CC6B00B6 for ; Tue, 22 Oct 2024 16:41:42 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7F29D1A0490 for ; Tue, 22 Oct 2024 20:41:12 +0000 (UTC) X-FDA: 82702408782.22.296D2CA Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf25.hostedemail.com (Postfix) with ESMTP id 8A315A0024 for ; Tue, 22 Oct 2024 20:41:27 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=RRkHlGTE; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=K1gq3NQS; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf25.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=1729629549; 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=/O91e0wD9LofGQVbbD9R68Czyy5IEr6OFCxJlloVhbE=; b=OIb8BrUFxcv9lDMOT3CAJgXCHuTi7otMkSLK/uYn+vd7YzTpbBXvkSVsi6UP5k2SvFdczT yJvj3QRCKIZScYjOB4cAJ36bbpYx8ZAE6bWDSd8/f5/k3p1FqgZI3M350kvPEv1jkkHZ97 cDQTVqx7WY11cxYysGXSEG0EFdaRFy4= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729629549; a=rsa-sha256; cv=pass; b=3bqmtGlOKStofsh4zz9MniKiJiOEu4cAcTOgvSVB3o3B6ZOkDxW0NFBd0/cf/VELkkEVXS xFG9CsUSdBR+nQ06rDqfguZ5+DaI2J/lzTsgWYzCD1lACc/YTDpm9Dg3W3aqERAp3Qe1y2 fTNAU+nctmzBtawjwZ/rHj9u23Om2PE= ARC-Authentication-Results: i=2; imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=RRkHlGTE; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=K1gq3NQS; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf25.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 (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49MK3a9U013287; Tue, 22 Oct 2024 20:41:37 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=/O91e0wD9LofGQVbbD9R68Czyy5IEr6OFCxJlloVhbE=; b= RRkHlGTEceW9skLKTCkH2+KhyGz6ZTg8oXFYJUsyjsUyu5wSeGkZd9wJnP9D1gEK T5c8Nc1/Dl6N6pNdEHPuQWLwJ2ruLQrWrRiwu3Ckjpkg1AgoAgV0myqOe/AyJOap XOmoE3AlhnI3kSjmSEDFNxO7s9Jajt1gBC2por4QgDbkMmdH2gEFtL4UivN4C/ZM sPXE26FS7CpwU0bL+spQUkbrz68JigCLh1omuECLrIyd9hReXQyXg94sGGO1mFJ9 ZzriUxGqRaMutWCP8g542X4xi3lHr2VAWGugqtqolNPtgNMRYM8EDS7ZIU9OGAZ9 u/8HAMM+cqwwbwepyl+QCA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42cqv3dsvt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:37 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49MKXDcN019706; Tue, 22 Oct 2024 20:41:36 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42c37ef3v5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2024 20:41:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=H/DpYTFyLyVZWco+dKmJRNaMlTFPjjd9WJ43j2mVvHP0zO+Gqf5H3b/T2ujrqcCQcFsNdJw2tyUynSrb7TcCb1eyLgYjgL1FflC4X5BlJuktBOvDJ2oDQaDcb2R+IdMTxcoUAWVy7AQhto1gm7W6o9pwIHI+A4NxdUPG7HwjR+QvinuccyyTNhefiD0UUnt0+ftNtckxTCT4pDUfDC8fJP5nuA994KOPSicAfZFQ1j3LsDkfvvYx/iVmlFKtwdgOYp8HgV1GKZJNuiAIg9QjJnQ+sosCxwSqMiRkR/7E9QUhITEXUBrS0TEcZmlH7U//JOGrPGVqilcQtSGjwBflmA== 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=/O91e0wD9LofGQVbbD9R68Czyy5IEr6OFCxJlloVhbE=; b=uTPvxf+m3yYwoBV6gOb1K/PFFlQO6uQca/NHHF9gprsrS2Zo7JMqfrn/9OPSeoqqoYg5xpwaw3ol5qEiqEMN4xrDxbHZoYQOQ00jhC8tnbkxc9nbE6xYMxCdJZkD4VzsqhRatycsvP6ovTeHPPch8ZZqFJQriQwrPDuU+yFqII9dKve/1+xAR3gmYLxwgT19h1USZVBdz2qv+wc2v42FhCTbCHTYBG4fYiHwrn1kU6D/qXytfR9zxUQYe8J8QrnSHROpJxJdJb96cGvJzky/Tv3Da7hhqB4YQVJTOIdfm1du/sOZoRU2Coa5uoEGfyZZEcn+/HtYXO7jmV8rSIJPDw== 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=/O91e0wD9LofGQVbbD9R68Czyy5IEr6OFCxJlloVhbE=; b=K1gq3NQS37Q0/SLRmmZlxIHc8dLbnsVMu96/8g5E7y/FEBtqGh3rU4c349Xk702+uD0RpZ/Fc3DuDS4fpP0XHoI4jxnrt8iXnRtxLDpcXckpsQxe70sxXOlYCSbSQsR4i9w3wHFlTSkdH5mIktFH7CzEiLPazW0yGkAnnRinIC8= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by CH0PR10MB7437.namprd10.prod.outlook.com (2603:10b6:610:193::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Tue, 22 Oct 2024 20:41:33 +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:33 +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 8/8] mm: do not attempt second merge for file-backed VMAs Date: Tue, 22 Oct 2024 21:40:59 +0100 Message-ID: <7b6bf6165080505feb5e00b313d2c84c25015e45.1729628198.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0215.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::35) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|CH0PR10MB7437:EE_ X-MS-Office365-Filtering-Correlation-Id: 086c1ccf-e4b1-4bcd-c404-08dcf2d9ea93 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BC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SLxhCF00Ly5i2dR/IDXcHiSNikYUws/i2KMZXsAWmpiCILp6j0g2mM5DWxBRT1Un1OWlDB7ABARRQdeCx8Gao+gXbszCFDtHdG9+n7sjkEnvs8zlbSUYwzL4Xdr7HJGhvF55zmMUY/hEwZ2aDI+6iXyrtO4wZLyJgqM+zqoK5ZnzpLvIXZ3THRBOlUHFD/aesYlFg1W4XuTsKKz7S12nrmHK05sqqbpS8hwZO1RkWNVqRAK7+iEZTefxxzjvwnNBFeFBIdp46MGYsr5iqSTkNHFyDpoUcZDjW5T/1Vg9Jh7wqKhaKtABgGDpE+rF 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)(10070799003)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AL1jjUIabVKfMDMQTeKS+NOLB8EOHKyOsY/NTdLvvMbwsROD47kpxFDxBNdTvlUYDx2SeCXYalVPQM2iB90PDX5x2rScJNPsLih2tvU+N3fjwx2Bjv5Ar2v0GZ882ENPoHObBSu/b6de/DZDQMDUN8PkiPpfUtmA/iRTsdWdts85Lq50MzwNpgK+qLeyytLMfmlqLdT6e6d7uskl4fvknXST6BtlorK7yyzcnLCMUpl/VM+1eX22mA5+JALeDuW7nrLay1aaRb0zWyALfVObWkBH0P3iKk2Zzp3HNoHPO4b0QghNATT2Vio65LXte165ksHm2Ed9v0soQvQ1YHgfoggcZjg1d0G7Ndtvik4kuipCaQVxP+X0ZPqRVMbMcqFhqnIU67SmBFahJZ+feZqplly4L7C04XPKf5LNVNc4pxfpH0Du7hK9xRn8lGrVTWr07vTLBm9As1HVC8vteqptIS+SQmvVPAdTDBPcyB/I5YGTULHe+zZuprawo7YdDG1sbCUzktOxL64yFdEt072EF8hMRG0Yc5AiSON2R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GCtuCU9CfIshNwexs9fAKxxAsr2XDYvopyLmYbKWkUsbWLik5jVjCdgIvubw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: PI4UNchyM4NbA/8ErWkLLyxGB6P9UW9HFzArjkL5yLCx5wmrqD/xhUuUpXd1FPajN480V0OL7XLTFCdtcgOe5lpXbFWQjoo246zoKuhhG2r51NrKnU4zl3QNR6oceTOhtai0NA0gZxnSQlp1qZRFlkfNcRTXlT5qGF8lZ15SvKrMdEym6JCCh8ya+y4hOgCVLMiZ6A7ys5SW4HJ4q9tNQWu5DlvaCN6+BIU7lGn+xgskFKW9bvagIaBoZfkLZmz7PsPuT/QJlmhn3/rfoGp50O1EWcpjgrlP7uvPbozxkkintupwMmT5kTD4clLVrYb2FUxxudomjRZ4H6xSuw5Y3/2xhHa1oKzHvKIBIHQh6Zn5LhhjB0UsVDF376zVdd0vunVBTEpasdzWpPHqzDgXDNbB5v0WlDuyZp1sAAobU3gHtFomRY5ULdM466CNZ5stXz7/qmUP2b03gW1Vdw0KI0uQfpvpM2rfRvm4ouol+0SQd4v7apylEuGVsb/zwNxsgzg/m6ApIhDJ4ah2dBDINGMuNBZrDjkSyRHpswcAjNY6CCi3ufHKAZkSUTEyc3s9e5Ub6KHxhx+c/+mOrjyW1+AGL8Hm4D8o+u0F5YMSAvs= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 086c1ccf-e4b1-4bcd-c404-08dcf2d9ea93 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:33.8002 (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: 7CaO4yRoaSo8UfW9TQwfs6gbS3SkNp/fR6bkfN/k7mVFpgkYQHnCEqZmO8A7XL7i9mN0cFhu+xtVC1gpp5LfjlhVKrJo0vsBVSFt8EId/bM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB7437 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 suspectscore=0 mlxlogscore=999 spamscore=0 malwarescore=0 mlxscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410220134 X-Proofpoint-ORIG-GUID: 0SYT3gDCiej8Hdw2SYk-M3WBSiCJQ4cQ X-Proofpoint-GUID: 0SYT3gDCiej8Hdw2SYk-M3WBSiCJQ4cQ X-Rspamd-Queue-Id: 8A315A0024 X-Stat-Signature: 86b7czqqn4e7tk88y8o586yrfefsiej7 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1729629687-488407 X-HE-Meta: U2FsdGVkX18hnSRx0+npKUY0pRLjVxU/bKynxphpZ0iPpyg2yFxXjJ02oBvaAFLren3gzSejSyI66jSX2VSyb1dwUbcNZ8jZxd9zG/Tdv1+bGL1YslAwaLUHDi1qZtOW8NOD2JfPg97y+QqzXdrXPYByBap39whV0vC43ivTRfEoDvKA+4JPysuxgUzosv98D/HSrLXntY5pw3L8kVdU2Kqp7MZlwQkrULj18zX8OG01mctEN4LC/DFhggBGZSizIzEvf+0KJehgirQxnQ7immrkpWjmQMvvme5AB52oHennpXdNevIS7zSsLOOceq+Myv4spz1DG7OPYhsb8CLdodAsoccgprGK8+yBDHt3jds3MuYn948x1+ALjY3eivst5m0RSQy3bEvZIJnTo67pJs+opP+pIXtP8KLE2VgSizF+Pj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RX7tFSLtWyTX/hnze0hnnN/jg+FcuL5jqxFF81jtEI4obrKmuabL3oavkWkbwJ23ISXCfye1IVpdFqjKGDBUxhdbWSS7yccRP/ZV2lajLq1gMQsun9id4= 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: Previously, we'd always try to merge a file-backed VMA if its flags were changed by the driver. This however is rarely meaningful as typically the flags would be changed to VM_PFNMAP or other VM_SPECIAL flags which are inherently unmergable. In cases where it is meaningful (for instance DAX) it is doubtful that this optimisation is worth the effort and maintenance risk of having to unwind state and perform a merge. Since we've observed bugs and resource leaks due to complexity in this area, it is simply not acceptable to have a 'nice to have' optimisation like this complicating an already very complicated code path, so let's simply eliminate it. Signed-off-by: Lorenzo Stoakes --- mm/vma.c | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) -- 2.47.0 diff --git a/mm/vma.c b/mm/vma.c index a271e2b406ab..fe1fe5099e78 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -2260,8 +2260,7 @@ static int __mmap_prepare(struct mmap_state *map) return 0; } -static int __mmap_new_file_vma(struct mmap_state *map, struct vm_area_struct *vma, - struct vm_area_struct **mergep) +static int __mmap_new_file_vma(struct mmap_state *map, struct vm_area_struct *vma) { struct vma_iterator *vmi = map->vmi; struct vma_merge_struct *vmg = map->vmg; @@ -2291,34 +2290,6 @@ static int __mmap_new_file_vma(struct mmap_state *map, struct vm_area_struct *vm (vma->vm_flags & VM_MAYWRITE)); vma_iter_config(vmi, vmg->start, vmg->end); - /* - * If flags changed after mmap_file(), we should try merge - * vma again as we may succeed this time. - */ - if (unlikely(map->flags != vma->vm_flags && vmg->prev)) { - struct vm_area_struct *merge; - - vmg->flags = vma->vm_flags; - /* If this fails, state is reset ready for a reattempt. */ - merge = vma_merge_new_range(vmg); - - if (merge) { - /* - * ->mmap() can change vma->vm_file and fput - * the original file. So fput the vma->vm_file - * here or we would add an extra fput for file - * and cause general protection fault - * ultimately. - */ - fput(vma->vm_file); - vm_area_free(vma); - vma_iter_free(vmi); - *mergep = merge; - } else { - vma_iter_config(vmi, vmg->start, vmg->end); - } - } - map->flags = vma->vm_flags; return 0; } @@ -2341,7 +2312,6 @@ static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap) { struct vma_iterator *vmi = map->vmi; struct vma_merge_struct *vmg = map->vmg; - struct vm_area_struct *merge = NULL; int error = 0; struct vm_area_struct *vma; @@ -2365,7 +2335,7 @@ static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap) } if (vmg->file) - error = __mmap_new_file_vma(map, vma, &merge); + error = __mmap_new_file_vma(map, vma); else if (map->flags & VM_SHARED) error = shmem_zero_setup(vma); else @@ -2374,9 +2344,6 @@ static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap) if (error) goto free_iter_vma; - if (merge) - goto file_expanded; - #ifdef CONFIG_SPARC64 /* TODO: Fix SPARC ADI! */ WARN_ON_ONCE(!arch_validate_flags(map->flags)); @@ -2393,8 +2360,6 @@ static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap) * call covers the non-merge case. */ khugepaged_enter_vma(vma, map->flags); - -file_expanded: ksm_add_vma(vma); *vmap = vma;