From patchwork Fri Nov 15 12:40:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13876179 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 15EDCD6DDF7 for ; Fri, 15 Nov 2024 12:40:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 975876B00A5; Fri, 15 Nov 2024 07:40:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9267B6B00A6; Fri, 15 Nov 2024 07:40:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72AAE6B00A7; Fri, 15 Nov 2024 07:40:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4FDAC6B00A5 for ; Fri, 15 Nov 2024 07:40:38 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 16ADF1C7621 for ; Fri, 15 Nov 2024 12:40:38 +0000 (UTC) X-FDA: 82788285846.03.A70311C Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf26.hostedemail.com (Postfix) with ESMTP id 43975140006 for ; Fri, 15 Nov 2024 12:39:59 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=JXXWT8eu; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=x7DvoeeV; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf26.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.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=1731674289; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=n677DzD/vofqdaHKQpPiCq3teUv8/eVlhrcSr5BSnVM=; b=R8vYjPhnAnP/izaCN2/AdKdxNC4+LiaAL3DoUZyrEvl7DOQLb3b1fvqAHBumCa4iy7fgHh 099UvrYhhjE8LVgZWkI6RFcGLll0qR8sk5+O2FHtoc1d5vSk5D5V5ua4ma4rxTffmPdQxv 9BTNul11pbtS3jplQYdep88R/HSWmdc= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1731674289; a=rsa-sha256; cv=pass; b=ezqZJ5JmEXKbHWMEb3p5Rb8JyCSiIJn3sFV7abUDMcgAkW3x039c9N2qoVJgdjT3ApCNR6 BWkSYn4qZXrAhX9PAdxqf0zAHsz0HGZTfLKTMN6GPNDyJ7aiD4c/UIsC5iRmkfgRzT27rL bWMmEc+B+cNW4wk+Z6j8nb6w8h4weJA= ARC-Authentication-Results: i=2; imf26.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=JXXWT8eu; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=x7DvoeeV; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf26.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AFAHLAN011157; Fri, 15 Nov 2024 12:40:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=n677DzD/vofqdaHKQpPiCq3teUv8/eVlhrcSr5BSnVM=; b= JXXWT8euhxvgEBmCmW0g6JJ6mj6CRnmpy16oBqwWBnV4qRGwxanF+q2hx6Dyj6m2 htfOwvLGAQghZzEgqc7oIi/bmwwmfMQtTb2BLF0xxolm1BK5WZ7L/mnDT5Dx93J5 5bPWjPweNC7j/BkFwNikIsjwCey2sRFWVu8tSZ8eloT5VhWf9ZlaRQ1gs9Qwr8xw 7t16tzeyhkN+ca8JQBq6PV1X4tf0xGS6lOJZ+oTV8d1TFolevLuSbVbQEZC/Yb3I l2yiABL/zV4fb3favHDGc08OamX5RFnGjpqhjwpPvUrCHVuiUxtVT+MaoVWTMXHH KbMoh5953gf/Q/aFQO6Emw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42t0kc3dda-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Nov 2024 12:40:21 +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 4AFCdZAI022819; Fri, 15 Nov 2024 12:40:21 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2044.outbound.protection.outlook.com [104.47.55.44]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42vuw2mrm5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Nov 2024 12:40:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UIyQig9iUHcjRaorryJbTcCWY9+F3vmQQzbH6iimWbZ/8Vxbc2aWqyWjghFDPFjZpmuy2cUNezXrKB7ytQdVVJtqkWHxhdkfrrW2myMmAlDluNXMu18FLAO0OViWs1bK9MNij3e0FI4jOf5RjquZ2OJfLovE54k+mqCi3GurtNXNIDXo8cLfsVDafMEFINgJMhDbUkMp5XVfjvWp5J4m33oYR4C/GkRmybdNkIpjLzWFgLJ7LzMWDwycWuc9XzlxkTElijrgOGNN8UlXWS3Pzq52k/QSX9149lajJG0NNT+kOcVBVfwYFcB5OTPQXNlRM4OyJm7HBERFu3qJK04bRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=n677DzD/vofqdaHKQpPiCq3teUv8/eVlhrcSr5BSnVM=; b=c2bQ9PVYtqffzQawDBg7mHSkYa4jdT+s0vZ9gmUcJFlPIRI9Zr54kyTXSxcATkJBP1FmVKw49MMBVOmuYORdRLp9nRGRc/zNQR6QKya71CpF3MyEZ+4bX/9xUK6b1cD6waMmAZQ2uRv4AEOfTpIvLVrN8K3nEyVs9iHlS6jnHh1cb4PCMZvQpVuV9BmTJN6aGFmUg+rOp18WsnG0kvaTYBU5aH0V1/WeXfvsiREDGh87yezSs3VNTfpUqmcLycnw/z/w/esinwewKpDJPHHmhIR0aGjVtoNFqeWHyu+zKZEblFgoAbdldbi1HHG2Xt6Q4i9jU4T1GdOsgUJOsznIIQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=n677DzD/vofqdaHKQpPiCq3teUv8/eVlhrcSr5BSnVM=; b=x7DvoeeVCIwFO/tUej76OXgxl/ACnGelXRYwOKTpsbgbb5qu7zR9Bsl/dD+Yr+LnofhSYHKcp17hAPucQiV5ssIr8mnaePyFhOUTrMmlOLTyRhB1Mh7R6WbzSqtc6udrFz1OaFEtqWSqEord7ybFkRidmSUw1T4QBdeAWDNL6E0= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by DM6PR10MB4201.namprd10.prod.outlook.com (2603:10b6:5:216::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.20; Fri, 15 Nov 2024 12:40:18 +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:40:18 +0000 From: Lorenzo Stoakes To: stable@vger.kernel.org Cc: Andrew Morton , "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson , "James E . J . Bottomley" , Helge Deller Subject: [PATCH 6.1.y 1/4] mm: avoid unsafe VMA hook invocation when error arises on mmap hook Date: Fri, 15 Nov 2024 12:40:07 +0000 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0389.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18f::16) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|DM6PR10MB4201:EE_ X-MS-Office365-Filtering-Correlation-Id: 24c9dc38-2c61-41a2-05a8-08dd0572a925 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: 2i5T+jhegnfc9Og6bvbdciDCTF16DEKb/d70nyDuGD3SnzpjIrwpRbw+inIfc9rNBrm5xLyGSj6VgJHRWJ03w0tP8zjecQ6FVHAu9P+Z5QJIWpodJ6gDm84ZkPA285wkDrXJXMHeb3bGh6SyTAGgCIR5ymufFEvsRrkFEP39XgE7l+NmR4JywbYEloHq4izvS3GTZaDnrlHf8AXF7QaDOjIcFRkzIoMkKPKUEDsgMd7ENOlPiXW8Nbcu8jB3H8G4EyUgyJ8kwm+WoHL6a33kgCK5rtdPtAKhBzkL52Xjt7FfbvxePUuozWMkhjs6K+eLBUNKqZAZvIgbd+lWKNJjQQ0lDCYP0n5nlXc4uHjQ7+aNeELEvBDvjNcxMJMP2eLYkpUC8/lipnXwtvm6s2DwBJofKuOmlCZdv835xKwHWfcFMoZ+WWheDhThrsE4bXNPP3ZzDWQh9WBNkcV6KODjZyee900Zoe38hcJ1B1RzIs4TA/MdOVNKd2JzDwYHMszKOcy0VTWGeMdg/Zzo5vYJMKTaMw8zKU0ZFnqsmvwYzi58EVROqdqSS5R4Kdl3XV/ps5Qj0VT68l5UEcgxgSPzCxtRPzoA+21zQGg99lbr0nnjzJeyfDnyGLDGHSvwoUEY1RWB5CS3qD4zk+Zqp2P2g/xJA0qrDBiigq2EENfX7BGAlLcnEEQGVQKyHRkdgwWL9Oqr3MLSKDOa7VAmxk89dP/y7JQUVe4H+A1U6ekv3fpPzhvuq8/Zi94EEXDrTIa3VuM89emmKNgJ9xEgZ4w4ZPPRSSRlSZ0zE0DM0HBtw+LcsCapofHdUAf/u8Q5grqMRchWnMxQoph3SJmqooUE2L64LLl6l9Oryfcyeul7cP3d3hcGXehuGLNa6ZZEJRVVGVWckEdbHbebZez078bzRjm7u/o7kiF0TlD2CPil4MP+H7vpvUcc1IszGmCcScami9EOnW8rI7dkoeDeH2TrJOCbhtwGlS9RlLn/Jfbk5+f1DtjgEbbbzqPUkIq0iuV3K8JARrtVlUojJwRlobPBnDSB9y65G/uRAeEDFnF0UyLjTESvR4PodiC3RRrCqu2xi0okBE0FxM47JckqJKbYipYri2jAU73Z3oGFh4qdR6qWmmTkDqFklCTnvFdN6HSo/rU34NwR+HBbxRvak25ktF1cJQJMyyDFY9UDDrd+h/LaX3r0Z+8R6Th3uKeCO01N1Fw3OXmUi4pr1P941bdPt5WCWkZFD39PJy+B/7pZ3xSoGvfZpuJct8dz8m9ibWxl2mA9fGryz4Aqu9ZiJekcbqoRxZsnkpf0OLMx4NknZapG7DHxH4m9XAt7FGlvr6EO X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nGSF2azYbFTLcjpOhafXSpQfrkzcAx0lLf37yAJbmUHfvznJXgcv+lHDETj8knkZwX1lY0r8ddL3AMsGvxrzYpJN7a1OMvKd6BcF0kltGY9DS55+oyzPLfzXuc3AAVyPn/A/jUFO3cxbqI+G2dpfh20UIxrB/2+GyivxiQ2mxE4BGAmuyvMm0Gg9g0+Qfau0UTJFoBfb3Qh6Bdx0dJPii7TaLzjRK2DxG0kmLR2mI++bbkkuDYbzgJXNzG97OTT8iYXSd2kj9o8No6IKP3bOd5gq0ZnnrP4gQaSx3BEwEx/YMZj9KZeiyRXtzu6CnhpjOqrdruy02DYq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ujrCREFWeVTJ6NiqcSrrGShv9U1fOPu1c1fZkocMcTqZ0mRhC1aVj6GpGkZLbpABxy4CE+Uhyj9vmfQIZZbbn8ztVN4NQE5ualqa3Mxh9CZWaqIwfqlAKCN3z+JjZZYn5n+WyzNwB94Gbtewc3HK8jAU0fYq7aPGOdv4KY+WxjmdeNuUwnwjWOCjXDnQ+ak7NWDQAwD8BSHSVDng== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: w0uLqw8IJnUpg9jf49YCtd1fPc2nyP1LyZx7zW+lChJKt1lhN0iNY2MvSYF0wpvBcHgWFz83yJraZhiaJfm4UsZIsFRpiA4n26H8XcAB530uO6bHrv+c/nWYP2BV47KmUZEyKXy0WpFL7zfyQUHe5zbqZ30XeTW5D11DaIvlJRur+/FemYH3jztZkI/78KnGSpmrdcrAWDpL56JqLX3I776Fx4i5juVc83qhazwgIndNy0l1icW+X7TTxTb48BQ+lj0t76+o3uBJcXasJ+QPztCUr++HYCrsfAFnkr7/zDr4+ZHkHFFUsEMMhx3zWatG+bT7871I21PJr3Q2PoMxKhCsV1gIkRktYhz/MWqXlMYlNNUCcGVDCRHxBNSzNTNlOkIDtfgX6eH+FbhIXCMXHNQJtk31wkMK6CggYI3qWRBQs97XgaeXcVQu/FfVN8qNYmy55la/A2WqlyJAOYWYGDkn1BZWjG2wmGZ4CTRoSSvwk4YMYEkGOK+WduRrZtX+f1WhMBXAqG5tIkXwS1TE+jlP4g0VZR7gBm6E9BU2nWoNPFWwyU8s7WeXz6yiMzl84/nkMPuMUYwoz9Wf205zMxU5rQNgdzf0zRT3vjNkIzE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 24c9dc38-2c61-41a2-05a8-08dd0572a925 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:40:18.1372 (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: wbFZWYuruv+f5sgYZxWztO5qH1n0oAejy4WAMKoFlbCsobGepJ2GVglKQ62eOTXWBY9taoMdOApSjm67ksr6lFKZH/lznc4zkWLXJG/vYUU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB4201 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-GUID: x5k1YAtNbc21heM-ZQhUXpgV84gTzH1d X-Proofpoint-ORIG-GUID: x5k1YAtNbc21heM-ZQhUXpgV84gTzH1d X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 43975140006 X-Stat-Signature: twmzez9e7ni1bn6hdrzgmsyni1sxjwr8 X-HE-Tag: 1731674399-638698 X-HE-Meta: U2FsdGVkX199mTcBe/iBeS1UdgVJV0jFMtGTUjkQBN2qw+TFTs5YvC09ce72YVeQ/xXlFxibigmadRlCpRt5GJL8XdnraS+jhPxqrvOcHWh3fwFMBND5Ts/lzWVMJlQUIhkSBgWCocVWkAHIHY8YL8Vf2dW/CstA/YlHJm6XqUeLWvXqAGOkTVPukYAnxfOulGu6V9sLj1l9qSbl4QNpfEnMnlrIYtg/rLaMjfvuUg1bdhjoWiCz5lFmQXldMIJgpEmiMGbUhjoKrjpNh1IkS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odI73JQgKWUSnH2fiqhz1jMj7caQkAEkWEt8rYC3sKflOGX2K8A24NUnUZNbzCxCHUu3m9uM26rihbUs4px5ohL1+VllkmJBYIZxq5tnZbZF+YP2ivx4yUUikLd0/9kLlvpQyYK8xCcj6COlqDhiNKUi9b32qkAQq5kpdBTlMGc2vdL8Iz89B05N9eopt0WLKvndVSSr6HYmqCAkkZxUnrVaIewzu5by1xKJWXP386+eBeLFVtQbRjS+rdwzKHDu+tIem4qIEChWmAAlEyNSD7iG4RqkNLT3xYD7Nqh0ffALAhzIo93QcxYIxP4CTDy/JX+TpwrqI7V1ybq82Wot+zpuJkNRu1Qe85jRoQlsCdr+sqTdYnAAxysgMuissoxOAOtfH2SEQWspv1j4ryd90hk6QK1oS7UeF1hBI604kJTqEyk3KGP8KteHdqRunutS3PM302d5WuC5c9fa4O46+p5ep2zjl9KQRQsSRs3Z+1f9Oqkpi/a2NLGGG5CjfeRaqk04m8aN7UwZibEUoAJ1/ciqXsl7OVE5q0RvuL0RqC4yguO/mlZj3UbW5D3Q2A6mGWCc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: [ Upstream commit 3dd6ed34ce1f2356a77fb88edafb5ec96784e3cf ] Patch series "fix error handling in mmap_region() and refactor (hotfixes)", v4. mmap_region() is somewhat terrifying, with spaghetti-like control flow and numerous means by which issues can arise and incomplete state, memory leaks and other unpleasantness can occur. A large amount of the complexity arises from trying to handle errors late in the process of mapping a VMA, which forms the basis of recently observed issues with resource leaks and observable inconsistent state. This series goes to great lengths to simplify how mmap_region() works and to avoid unwinding errors late on in the process of setting up the VMA for the new mapping, and equally avoids such operations occurring while the VMA is in an inconsistent state. The patches in this series comprise the minimal changes required to resolve existing issues in mmap_region() error handling, in order that they can be hotfixed and backported. There is additionally a follow up series which goes further, separated out from the v1 series and sent and updated separately. This patch (of 5): After an attempted mmap() fails, we are no longer in a situation where we can safely interact with VMA hooks. This is currently not enforced, meaning that we need complicated handling to ensure we do not incorrectly call these hooks. We can avoid the whole issue by treating the VMA as suspect the moment that the file->f_ops->mmap() function reports an error by replacing whatever VMA operations were installed with a dummy empty set of VMA operations. We do so through a new helper function internal to mm - mmap_file() - which is both more logically named than the existing call_mmap() function and correctly isolates handling of the vm_op reassignment to mm. All the existing invocations of call_mmap() outside of mm are ultimately nested within the call_mmap() from mm, which we now replace. It is therefore safe to leave call_mmap() in place as a convenience function (and to avoid churn). The invokers are: ovl_file_operations -> mmap -> ovl_mmap() -> backing_file_mmap() coda_file_operations -> mmap -> coda_file_mmap() shm_file_operations -> shm_mmap() shm_file_operations_huge -> shm_mmap() dma_buf_fops -> dma_buf_mmap_internal -> i915_dmabuf_ops -> i915_gem_dmabuf_mmap() None of these callers interact with vm_ops or mappings in a problematic way on error, quickly exiting out. Link: https://lkml.kernel.org/r/cover.1730224667.git.lorenzo.stoakes@oracle.com Link: https://lkml.kernel.org/r/d41fd763496fd0048a962f3fd9407dc72dd4fd86.1730224667.git.lorenzo.stoakes@oracle.com Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Signed-off-by: Lorenzo Stoakes Reported-by: Jann Horn Reviewed-by: Liam R. Howlett Reviewed-by: Vlastimil Babka Reviewed-by: Jann Horn Cc: Andreas Larsson Cc: Catalin Marinas Cc: David S. Miller Cc: Helge Deller Cc: James E.J. Bottomley Cc: Linus Torvalds Cc: Mark Brown Cc: Peter Xu Cc: Will Deacon Cc: Signed-off-by: Andrew Morton Signed-off-by: Lorenzo Stoakes --- mm/internal.h | 12 ++++++++++++ mm/mmap.c | 4 ++-- mm/nommu.c | 4 ++-- mm/util.c | 18 ++++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index a50bc08337d2..85ac9c6a1393 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -52,6 +52,18 @@ struct folio_batch; void page_writeback_init(void); +/* + * This is a file-backed mapping, and is about to be memory mapped - invoke its + * mmap hook and safely handle error conditions. On error, VMA hooks will be + * mutated. + * + * @file: File which backs the mapping. + * @vma: VMA which we are mapping. + * + * Returns: 0 if success, error otherwise. + */ +int mmap_file(struct file *file, struct vm_area_struct *vma); + static inline void *folio_raw_mapping(struct folio *folio) { unsigned long mapping = (unsigned long)folio->mapping; diff --git a/mm/mmap.c b/mm/mmap.c index c0f9575493de..bf2f1ca87bef 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2760,7 +2760,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, } vma->vm_file = get_file(file); - error = call_mmap(file, vma); + error = mmap_file(file, vma); if (error) goto unmap_and_free_vma; @@ -2775,7 +2775,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, mas_reset(&mas); /* - * If vm_flags changed after call_mmap(), we should try merge + * If vm_flags changed after mmap_file(), we should try merge * vma again as we may succeed this time. */ if (unlikely(vm_flags != vma->vm_flags && prev)) { diff --git a/mm/nommu.c b/mm/nommu.c index 8e8fe491d914..f09e798a4416 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -939,7 +939,7 @@ static int do_mmap_shared_file(struct vm_area_struct *vma) { int ret; - ret = call_mmap(vma->vm_file, vma); + ret = mmap_file(vma->vm_file, vma); if (ret == 0) { vma->vm_region->vm_top = vma->vm_region->vm_end; return 0; @@ -970,7 +970,7 @@ static int do_mmap_private(struct vm_area_struct *vma, * - VM_MAYSHARE will be set if it may attempt to share */ if (capabilities & NOMMU_MAP_DIRECT) { - ret = call_mmap(vma->vm_file, vma); + ret = mmap_file(vma->vm_file, vma); if (ret == 0) { /* shouldn't return success if we're not sharing */ BUG_ON(!(vma->vm_flags & VM_MAYSHARE)); diff --git a/mm/util.c b/mm/util.c index 94fff247831b..15f1970da665 100644 --- a/mm/util.c +++ b/mm/util.c @@ -1103,6 +1103,24 @@ int __weak memcmp_pages(struct page *page1, struct page *page2) return ret; } +int mmap_file(struct file *file, struct vm_area_struct *vma) +{ + static const struct vm_operations_struct dummy_vm_ops = {}; + int err = call_mmap(file, vma); + + if (likely(!err)) + return 0; + + /* + * OK, we tried to call the file hook for mmap(), but an error + * arose. The mapping is in an inconsistent state and we most not invoke + * any further hooks on it. + */ + vma->vm_ops = &dummy_vm_ops; + + return err; +} + #ifdef CONFIG_PRINTK /** * mem_dump_obj - Print available provenance information