From patchwork Fri Nov 15 12:38:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13876177 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 3B3DFD6DDF3 for ; Fri, 15 Nov 2024 12:39:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0C7B6B00A1; Fri, 15 Nov 2024 07:39:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B96356B00A2; Fri, 15 Nov 2024 07:39:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99A386B00A3; Fri, 15 Nov 2024 07:39:08 -0500 (EST) 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 755996B00A1 for ; Fri, 15 Nov 2024 07:39:08 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 254CC14163E for ; Fri, 15 Nov 2024 12:39:08 +0000 (UTC) X-FDA: 82788282990.26.6B3BB0A Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf19.hostedemail.com (Postfix) with ESMTP id 9727F1A0014 for ; Fri, 15 Nov 2024 12:38:07 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=dGCFj9Ea; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=HICE8gzk; spf=pass (imf19.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=1731674148; 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=wSSFsDJKNEnL2Ec93aXMbwQXwjo0SGvX0HMoMi4GdeI=; b=3M47V6FA2/rE+rwHfvjXUyDI4DM+skW35t7d2YjzL8EXGkM4sfRvCCTiGm/X0QnhQRd4Ys vzQ2s1PpxkBFgVDg+UFqrvp5caCA62biA7XOouhuftpQz1Zu4da1LBrc62urAW5w4LleJU erJMSNyai31I3cv+qykgjcVNxmt4cms= ARC-Authentication-Results: i=2; imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=dGCFj9Ea; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=HICE8gzk; spf=pass (imf19.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=1731674148; a=rsa-sha256; cv=pass; b=g0HUXh3n9A4uTtR6E1VvzH//cvPeMvH4nrx2PvE/eE3oSP0Wwg1aV2RU5XzgTGEHoydoex aSPw8lCZdZ64dwBDBDpfTZsLB33Un8ShJGd7LNxa6zCjoy687Eegc//GLmo4O0B2lVIWfv HzFq7NwCXXhWYURkypTKznTPn4meQ4s= 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 4AFAHAGc014379; Fri, 15 Nov 2024 12:38:50 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=wSSFsDJKNEnL2Ec93aXMbwQXwjo0SGvX0HMoMi4GdeI=; b= dGCFj9Eanr0yGHt4VxkQ1iqtT3dIzpkMsusb/gegyjtrY0SihgFmGZdcq5QMvTeF Iit7Az8zeRttXJ3prCSufVcONJe2kvNJdjyGWkj3X59jf8iS9/waPcn10lfVod0b iuXaMKwe+UCF13Ab98TOU3yKwiW/OH+0ApEpRMWWhqdNOfcQbQmO1B5rnOpbSoan dsWJYc7PeZsat4PIRK1jkeao3cZiaMGqXtkqGj2pSHhQuUt0YMwWnKlabZTJYg4A nOle1mKZUhC0VNgRXOLU9GynpYolx3S/oL9Ycru72yD4k7yV1mpm0mpoXV4h37vw A/1fnfUgmrA++pxsinYvSw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42t0k2b9fx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Nov 2024 12:38:50 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 4AFBQQPT022877; Fri, 15 Nov 2024 12:38:49 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42vuw2mq3t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Nov 2024 12:38:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=D3I9u4HA281oswvX/PdmZYHAHKKTjqzKNFizhRgDBQRA8xooPfMC2FejuKsLs9tjmpT2IxXdBPUGJZY+nK6vOFqgc9C5z6WeToRnjnCeRRmGhiAqHkDYpCrvle/98Pp0KfqZr7wyBIWYwgkmcHCuYjH3uBG3ulsHh/T5ustqfQ9GSFg1orpU2lgMKbdAo4RF2xUwoYPPGO9K0OIg1R8y2gee9/DQGd/p0qmQWP8cxkafW8XSoM0vBxthR9wSjqyJKaDBXRpK5GOMKUQdP0rxTJc7XiTCDW1C31B2iPCwoOt5inQGAhjHc86vfly7ib5Dfm9nyZ2nDkCsB5fZN6+RoA== 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=wSSFsDJKNEnL2Ec93aXMbwQXwjo0SGvX0HMoMi4GdeI=; b=LMhnpdTmUyZkCJrofxGZaPCC2Vu2oLMizYmUeIzCW1Z3zBsBf3PloP++NiKYqTlhJA8oSGrL6HuR4EcIeuHrCzVlZKp6NiQ3VU70zLy2hIQVyb8Brij+rtsYyWUH4oSwTEnVDXLLQ3YcU4hEU43icm9IVlV45JIMeniGU0N8Q8ylwMxUf93tZn3aqJdIRzAhtFZPOJhNVIXKb3rHFF828OKTqzzsYqiZinm/Cvnnj34mJNpggB28K7bSow7nw8TTc6mEyMSjXJkpjr/gRxlizyqTZIeFnIC7cIdWa+LXoK1drN6gymG/rOjB5z3exTS9Fegp4n7X3AcOInAyIV78eQ== 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=wSSFsDJKNEnL2Ec93aXMbwQXwjo0SGvX0HMoMi4GdeI=; b=HICE8gzkLcl71zT+fEiEuL4FbBqoowOyaLUiPyG5iAueKOErowPqVSGGsB072mHZak9tMbl8KNPUgAjoI6d615os6VGOfWMGKu62xoSq2yj1/f/voShDFe8okC0J3qZ4CHOQP4x3gtnVnaw9MUPtIIAENpAu16RtU6FL3YGjdYs= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SA6PR10MB8136.namprd10.prod.outlook.com (2603:10b6:806:438::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.18; Fri, 15 Nov 2024 12:38:46 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%7]) with mapi id 15.20.8137.027; Fri, 15 Nov 2024 12:38:46 +0000 From: Lorenzo Stoakes To: stable@vger.kernel.org Cc: Andrew Morton , "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson , "James E . J . Bottomley" , Helge Deller Subject: [PATCH 5.15.y 4/4] mm: resolve faulty mmap_region() error path behaviour Date: Fri, 15 Nov 2024 12:38:16 +0000 Message-ID: <03d88781b023104684f07a920a3e3b205461e419.1731667436.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:311::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_|SA6PR10MB8136:EE_ X-MS-Office365-Filtering-Correlation-Id: f8fa5182-2064-4ac1-c58d-08dd0572727a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|7416014|376014; X-Microsoft-Antispam-Message-Info: lFQTBR+AWM5L8MbdO77BT1RAuyq6E0TAe/eOr7XYtA2sO5GYVbMBblAI0UbCpOtFDnfpljZOTBU1B0Sxo31Yzih9er2GmA2Z7+sbFNnPoJwZMMiiv6VSqfIeudKh4LrbsjjpbOGNx5ym04JQp5qAc66jJHhRa1OIgakCoBbIWbyo/A295mAIRjrY3RgyGOwBEnw5eOzgGH7KIZFKQFjoXJ8nP4bT5QjNktO/af5CpJBMU78EDdiUTmZYza9Ker6rwZFePuC3NMmq/Ipd1jASFP8zjgs0NQSnKznnK+eNcxhEmhfrMgdLiQMm275g2RCDk6ohanTdhj69XDRIy9OLaQmOpq1nF8arxyZwMeKapvjbt1TTqn/H98fWGgmScIvT+LwDHolrbox+q8j6LdjT3UIe1E6qvkmDqSdPaiA52IsOYWMvDtPAcgKAf38Rt+Jen6oeVM+OoKinQBEw5+xtZIj1WZExQWoR5So5858ZvOOfLbeuzDIBcfHbb1IxPYduEJp0g3v9nAmK1NxTKRqTbK4oykKErpWhmii237WiymWlAVibiJCE8b3EPUsOl+HVsvhxXVEp/eLHFH9kRAshsrlRYv/G6anOlRooIxxiaxaFAB6re+rfwOOr6K8psPsH1jn6oIycWE6vB9eFSiskHyQYReg4QLGW3986gJmgxvTghMi6LGT0iV3BfAgh66XUKZwqrARCn2vcRIGXpcA5xTnTa1fGel0TshaJ9DTruOsrNlMg1gwRFYXTWlmJTPFz/XMMBKGkU16IsLc5C2AUGrtPO4RCPt+04AevmVKx+Sp0UZWr1GCAQJseTI+XJSHB8x+RfUGuYsf3Zhe3NTsDZZYf3BA+uzzoo/o/EZLgA+UkEukNpvK/FwDv9irfv2ngwiMFxPPFVv6l7Jhm6aQ+NhrmwkCpS9SLTig9H7j5X4JzsqalJJwFmYRq9RG0KwWFW8BXK/FyDnql6DgP/0HgAfYrsSchczIslcgagw8tIfrky4Su32E2KjhdjrnDbJs5Ou60xNxdUTtH+nI5oaDlXMZbAWXeZW4IaCVgboHGXg8JSycb6WgCnYbsG2pZKYlKdvuIN9Qxf7uawmeR/A0ay2LRzeeqPAb8ymOyw6RqKg/d2ukJzaEM994VJrCJLdY77JnHdl/Cg7xW+PztgyVQaWWWxCqu8DZjZO2pocwJ2doop8xD+BqEiGykTL0pGliGu9iAo+61KjUxKXNUSQOKJZuiChX/fvNdHEd+/e5qJ+H3s9VZ1uUb7DgkqbKHpC0iJxXYFu97Q/MK+i+pel3YnsrU97nimmVABFNzasOa+CBVVTY/DTmV9R1vh6JAPg+v 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)(366016)(1800799024)(7416014)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: J3uisKQgjNeybK7ds6dmgipOZznrAQoUoejotMjp4pz2yyyTbPcfcv3OB4E4FDoBD4+wv2JevNAZLXAGuCm7a3JK1XtE6P3RJbv/sdi75KHlPd/dlwxOZXT7iGd0qWWjpyIvGztptdNOTp+LgTFYtA7DNuhpK3px8nwHtQmfMY7a274A9HPGEjj48X3z8YNVUhEgJEc4XjaBA1iFTjqkRwLqLZ1IH32QjNEkjAWNPvlx+r2UIDmzjCa0XSqF5m1H9ajtVV/1kMzsoBMOsZy+IdZOwmNyX2w1JcztdP2LDZlN26hqvjYy6r/VgMR6A4HRZkY29RT5tgaYnOzuqgIodfT79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rHacZEPGG9s4FYcg5ZbRflaQOllBU+edDWDhmjX7VaUlb01WGzUSCru+qNgLkwpw0KCujJL2ArRXgURRxVIor3Bku/2FjIlPNCdouQ+22pCYTzSYAkBiZ2sFO5Sqi96wR16zv9UJJyH7nfIJde6O/S/xUlrDOaRukI4CrkF/KxzEuToY6J7On0GpK5+qE16wA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: W4UkWlZ0k57EQha/BFUsp8l8s9ResBKQi5KTXK52w5B1XaPxvJhIHHBVvRSmzpYzQSRUQSm6htMKXgz53cPwQXZuqhu+6TDqPfzpnKKkzJOveIIMAf/wivEcDh2Mo3EzpGsbIlPlrMLnae0vmx9MOwCi71DVyokG3fGP6hbMHjjkF4KaG+adwmtpdG99wZFR4pGJV3tie55GUrDUCjWuXpXY9Uh2T3m4iRxtFblpnVrOdkYLIoqh1+B3+HG8tQnrqCNeOJanO2oQKnrwXn+nmWjXzpDMoUQKqz46wDElEQicja+eeozCcux5CQqvf5pI+4bacTjPWvv23NRSRum40LBj64RP4H7Wdt+Is22Dr1gXSPSPCxbPVrquKd3JA2d+LpvjVCmAhYktTJ5gBaJS5hdmk1jNTot1l46ldBWYEeeESpX2XVVc0zMlqNnAaIIU0Ip6sno+v+T88QxMve/s8g4JARzmllhjMHcy3WeqOQk0p44kzcFm4RuWQhSbF0Y6qnspy859o4Du+lz+xK1N1O8HRed+SH5TBH9l/DMRTwRKgSbYbexiVySiwHjLfPJ0yB6zFvDXxjJ7bCdHValx7lQVpR7oWq4kHVO9svNATM4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f8fa5182-2064-4ac1-c58d-08dd0572727a X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2024 12:38:46.3757 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vBxiwkzia9itGhMMAXhDwnUT4S8YP+kgwA/m4+xq8tLjaF8zba6dtJwefKqPpgQKGe7o8SLpGdrmWSuhB7wTT8ojaV5NCqQebzPAnS9hOMs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA6PR10MB8136 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-14_05,2024-11-14_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2411150108 X-Proofpoint-ORIG-GUID: w87bDAH_fk5vjFbiXSmyj2LX9qoRCoGr X-Proofpoint-GUID: w87bDAH_fk5vjFbiXSmyj2LX9qoRCoGr X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9727F1A0014 X-Stat-Signature: dy57najdxu9whjqt8pspmx16kshrntxb X-Rspam-User: X-HE-Tag: 1731674287-727761 X-HE-Meta: U2FsdGVkX18dHrxTtIrXkQqW0vD6DAXNSkPpKJP5wsIfJfa3i8lEziOpCztORXpuKZsBQaOKHLwq96Jfnu2nYWi1cM7s6XTSpryRJhpldkCTAUXbmVaUFY8ppv7WkqRF+zy4eVkxxGV19gFK+7BEI8HvXxIVegLHQYBtjikBVy2fWVMuVXlU+a1CO/if1oaX/yxlkqlshCu0SiNCTq+M+vuQvxic/mQTAk4HOQa1yewfteIlbNPKl5FdsGKvrCgVfgpXoGGdCnm0A9lvd7+RNx9J7DxkvB2XGbgb3y0PuNhBvAW2vfxMpw8jv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ifHDYVAA09WNoFnmOiUXbd6xVI6WGqeNyz6tmH3tVk/2D7eS51wXNYuwZK/tGfCB3BlbkbhTfpR/XHZznsx5q+CHYZHUR305XNbadgiAbeRNFjRFvFulDs8tLxK1w+R+XOcEw0KHQsQdu8yOgAU+LDN8PdZJX43yZWjTrAhMBFzYI/2yhq0AjBtNqCKPWvK/mgs9++4xymydHqw8uBdwcMj+43YAKLm5vxxyojzu2Qig14MXiuHNbMa1jrKo1u6Uio0uFHO40KW+Y5kDCobQXhLUfOU35DLGA5p1VmzBVbhspN65WqoUzQzP33vxAtyOK/rE/caOII6T2NkoJaEVMZgYNDjVMIZBdkFoTnt2aCXgLM89JT3Hqs8BHbHDNXj7rT1RdZY2PvfiM1mTBAC0Sw/Geh8YDYN0BUoqdOU5tGq8/0GvBzZHs4DDG0/fYP/QeliAOhIOxrDYm/ikerpsH7TJw5KUXSw1s9480i6+vR4Vi2AYdxquQ1kxUDnDJ/u9hH+27mbBRQnawfijrOI9vDkeMpz9cVaBpAxFF+tNTLLuiGMtOcVzQKlJlMCYfTq+9 xKyoX6RC X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: [ Upstream commit 5de195060b2e251a835f622759550e6202167641 ] The mmap_region() function is somewhat terrifying, with spaghetti-like control flow and numerous means by which issues can arise and incomplete state, memory leaks and other unpleasantness can occur. A large amount of the complexity arises from trying to handle errors late in the process of mapping a VMA, which forms the basis of recently observed issues with resource leaks and observable inconsistent state. Taking advantage of previous patches in this series we move a number of checks earlier in the code, simplifying things by moving the core of the logic into a static internal function __mmap_region(). Doing this allows us to perform a number of checks up front before we do any real work, and allows us to unwind the writable unmap check unconditionally as required and to perform a CONFIG_DEBUG_VM_MAPLE_TREE validation unconditionally also. We move a number of things here: 1. We preallocate memory for the iterator before we call the file-backed memory hook, allowing us to exit early and avoid having to perform complicated and error-prone close/free logic. We carefully free iterator state on both success and error paths. 2. The enclosing mmap_region() function handles the mapping_map_writable() logic early. Previously the logic had the mapping_map_writable() at the point of mapping a newly allocated file-backed VMA, and a matching mapping_unmap_writable() on success and error paths. We now do this unconditionally if this is a file-backed, shared writable mapping. If a driver changes the flags to eliminate VM_MAYWRITE, however doing so does not invalidate the seal check we just performed, and we in any case always decrement the counter in the wrapper. We perform a debug assert to ensure a driver does not attempt to do the opposite. 3. We also move arch_validate_flags() up into the mmap_region() function. This is only relevant on arm64 and sparc64, and the check is only meaningful for SPARC with ADI enabled. We explicitly add a warning for this arch if a driver invalidates this check, though the code ought eventually to be fixed to eliminate the need for this. With all of these measures in place, we no longer need to explicitly close the VMA on error paths, as we place all checks which might fail prior to a call to any driver mmap hook. This eliminates an entire class of errors, makes the code easier to reason about and more robust. Link: https://lkml.kernel.org/r/6e0becb36d2f5472053ac5d544c0edfe9b899e25.1730224667.git.lorenzo.stoakes@oracle.com Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Signed-off-by: Lorenzo Stoakes Reported-by: Jann Horn Reviewed-by: Liam R. Howlett Reviewed-by: Vlastimil Babka Tested-by: Mark Brown Cc: Andreas Larsson Cc: Catalin Marinas Cc: David S. Miller Cc: Helge Deller Cc: James E.J. Bottomley Cc: Linus Torvalds Cc: Peter Xu Cc: Will Deacon Cc: Signed-off-by: Andrew Morton Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 73 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index a766b1c1af32..f8a2f15fc5a2 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1716,7 +1716,7 @@ static inline int accountable_mapping(struct file *file, vm_flags_t vm_flags) return (vm_flags & (VM_NORESERVE | VM_SHARED | VM_WRITE)) == VM_WRITE; } -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) { @@ -1780,16 +1780,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma->vm_pgoff = pgoff; if (file) { - if (vm_flags & VM_SHARED) { - error = mapping_map_writable(file->f_mapping); - if (error) - goto free_vma; - } - vma->vm_file = get_file(file); error = mmap_file(file, vma); if (error) - goto unmap_and_free_vma; + goto unmap_and_free_file_vma; /* Can addr have changed?? * @@ -1800,6 +1794,14 @@ unsigned long mmap_region(struct file *file, unsigned long addr, */ 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)); + addr = vma->vm_start; /* If vm_flags changed after mmap_file(), we should try merge vma again @@ -1818,7 +1820,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma = merge; /* Update vm_flags to pick up the change. */ vm_flags = vma->vm_flags; - goto unmap_writable; + goto file_expanded; } } @@ -1831,20 +1833,13 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_set_anonymous(vma); } - /* Allow architectures to sanity-check the vm_flags */ - if (!arch_validate_flags(vma->vm_flags)) { - error = -EINVAL; - if (file) - goto close_and_free_vma; - else - goto free_vma; - } +#ifdef CONFIG_SPARC64 + /* TODO: Fix SPARC ADI! */ + WARN_ON_ONCE(!arch_validate_flags(vm_flags)); +#endif vma_link(mm, vma, prev, rb_link, rb_parent); - /* Once vma denies write, undo our temporary denial count */ -unmap_writable: - if (file && vm_flags & VM_SHARED) - mapping_unmap_writable(file->f_mapping); +file_expanded: file = vma->vm_file; out: perf_event_mmap(vma); @@ -1875,16 +1870,12 @@ unsigned long mmap_region(struct file *file, unsigned long addr, return addr; -close_and_free_vma: - vma_close(vma); -unmap_and_free_vma: +unmap_and_free_file_vma: fput(vma->vm_file); vma->vm_file = NULL; /* Undo any partial mapping done by a device driver. */ unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end); - if (vm_flags & VM_SHARED) - mapping_unmap_writable(file->f_mapping); free_vma: vm_area_free(vma); unacct_error: @@ -2907,6 +2898,36 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, return __do_munmap(mm, start, len, uf, false); } +unsigned long mmap_region(struct file *file, unsigned long addr, + unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, + struct list_head *uf) +{ + unsigned long ret; + bool writable_file_mapping = false; + + /* Allow architectures to sanity-check the vm_flags. */ + if (!arch_validate_flags(vm_flags)) + return -EINVAL; + + /* Map writable and ensure this isn't a sealed memfd. */ + if (file && (vm_flags & VM_SHARED)) { + int error = mapping_map_writable(file->f_mapping); + + if (error) + return error; + writable_file_mapping = true; + } + + ret = __mmap_region(file, addr, len, vm_flags, pgoff, uf); + + /* Clear our write mapping regardless of error. */ + if (writable_file_mapping) + mapping_unmap_writable(file->f_mapping); + + validate_mm(current->mm); + return ret; +} + static int __vm_munmap(unsigned long start, size_t len, bool downgrade) { int ret;