From patchwork Fri Nov 15 12:36:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13876166 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 08230D6DDF7 for ; Fri, 15 Nov 2024 12:37:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72B176B008C; Fri, 15 Nov 2024 07:37:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D8036B0092; Fri, 15 Nov 2024 07:37:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DC586B0093; Fri, 15 Nov 2024 07:37:31 -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 293B26B008C for ; Fri, 15 Nov 2024 07:37:31 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8FFAD121456 for ; Fri, 15 Nov 2024 12:37:30 +0000 (UTC) X-FDA: 82788277740.09.E79D912 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf01.hostedemail.com (Postfix) with ESMTP id D838D4001E for ; Fri, 15 Nov 2024 12:36:51 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=QH9ietNe; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=lvhEGq1R; spf=pass (imf01.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.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=1731674070; 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=lcqVyGR2Ie4RX5B2PFQeOoDGKUd4H35f3scPpB+0CAw=; b=TZjVWBKpodNDeR2uWVPXsfCtoLx4vZgow/T8LhRNtobPXMltG0Ghm+01zQl02LIhrCZw8t caAqPBIQAepGNTDy+sYbP2XS43w15zjSFdLa+Hu2P1htz1dOTiWVyu15Ak5/hAcaUgRdAd l9P8WJAujlKeDOy3/aUF+iVV8Db25K4= ARC-Authentication-Results: i=2; imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=QH9ietNe; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=lvhEGq1R; spf=pass (imf01.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.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=1731674070; a=rsa-sha256; cv=pass; b=H6kt+CuC5gSxsxJPUMLilwPe9LxZMOqOCGxkt6++ozxNh1Ly1v2jufqUmghrRLDCaR6PDN Gs62lH8wyskzwtGqna3CpKN08yp2Jx0C/03QqzT6o6BUbXU8mEGfIUo7AL/+H05Ib05ZSo hXGeThpOlfzF7SfZ2jYclQn5uHJKFMI= Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AFAHHHN030318; Fri, 15 Nov 2024 12:37:13 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=lcqVyGR2Ie4RX5B2PFQeOoDGKUd4H35f3scPpB+0CAw=; b= QH9ietNeyYDtg8505G2LIz8MqSlrqw+Yl9437iMoV7gSq4kWT3jHOtOnurJ9AnTk rYyb2/EXEiBv7fsXfPC5RtMP2Uasz+Unp7BENqrhQMx0UKT8U/c0yh8hEPYrjgIK crqg+tQu2MW7eXBrYzC4yS1D9WunSpi07Y+DoDegJPo5LcvsiK8adQuK2g8jR0/f EigdgirQQXoPnb2uHGCsRFRMvMOnHnCSA0OHpNdk5V+vSK6k1lm8uVTeDYlOAiFP QZVK9QP0VuiIxuteG/hod1fCYAI6Xf19V8EkERiQsNjxjwgN+W5GhRrEGpKxRj7T HsmjhEo7C5+vAQjYpdjSBA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42t0n539t2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Nov 2024 12:37:13 +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 4AFAVLFL000376; Fri, 15 Nov 2024 12:37:12 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2171.outbound.protection.outlook.com [104.47.58.171]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42tbpbjcxt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Nov 2024 12:37:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gaqEsaUZBgsLeUMM5LkOvfUL1X0V5CxFVXUqOlD9L2zokhyuDlZ8FyF1tPGD/3odXltrQnmeQuznkxvEIQ/DM+nIJTawBnN10oSjrS25q+kZYV/7nNQXZhpVrgHGumXFm6Rtw8YjALQq+t2uob0sZh2SxSnK/U7o9I6p9ZwxjogTGhoRqKNNTRwjncOZ4nZb95RjcHSLKoqSHO+zHY9cKEQeP+nJoCdgNG6YxJq1ogtA9abCVgNU6Cas+ShfLo7jW/qJDKtD2Eyu1dgo35+y1npRPdJ/OUVRB7L/XnZj+3xh/1a1tSY/7fVxAjWM/3TV4y+mnKnUJQOlDJgQ2a86Ww== 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=lcqVyGR2Ie4RX5B2PFQeOoDGKUd4H35f3scPpB+0CAw=; b=pvZxGwJg3TZq/y2VySBIpk/zglY9RFm3CCQR08FZvMrEKJJ+2sexqOJ3BiY6W0GxmxV+2nJ2TwBEJvdsXFEBRZ+UYnTpNuBM65ZJR6Mre6Z/IOgiqnfGvkYcSLfNp+9WbuVGv7WzyXcKJBXyMAdlW4td3V6fHqrKetXjVeOyrp3+hpPhegw+ejQvgKVTgYoqOrl/k46vrnvHQZjC6c4v7Usz1Dbq1Nv2AGcizJ0N7CcP99QvhzKj5+Yg4zl+CLj7DJ0go6vXJPzqYFEUekwCi2Pw4h2Vjq3r93tDEdIZ1RbPKopkyoTu0Fnmhczfzw3rpqKgZWE8Ac1qoW2a3tvWKw== 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=lcqVyGR2Ie4RX5B2PFQeOoDGKUd4H35f3scPpB+0CAw=; b=lvhEGq1Rk+Rj9yoEYJwb4LiCbFo9ohkp6p0a6Fj4STZF6jVSIeq34OmEtBpEd4Iqe5ssTNo6fI5blkTEKx24Enz38m63yE5fvWjXYbYEfNZaJZYvUdoWrQSBTOXKJvq1JthBfDhYes5FUVcqeWWh3hW3ZpVZft1DjIPe/1p0oBk= 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:37:04 +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:37:04 +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.10.y 1/4] mm: avoid unsafe VMA hook invocation when error arises on mmap hook Date: Fri, 15 Nov 2024 12:36:51 +0000 Message-ID: <3a4ff9ebcc085e0074711ae883fa5ea11e6d7a8e.1731670097.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0165.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:312::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_|SA6PR10MB8136:EE_ X-MS-Office365-Filtering-Correlation-Id: 59ca1d38-1a74-4ed7-0ba4-08dd057235e0 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: JF9VHHAz8zQdXGfBOn6oXH598n+rDaDmCesiJTAtYy3e+0jhAFqwFhCZ88Fn7UAm0ZRlM0YQSS6g6UeiRjDE0Z0Wj73HT2hlDofwBNmZLNm9uSsqRSU9G7ROWvWpG4kkJpSNIdIlOy3gEiLoOeAW/uJeTlb4nplZxyn9jEG0H0oxED1hiN5BamvtUJ7O0GQFfOTkqhuRuqDzwvic4J0D8P3lMvf/CItQBXSwJtIil75uPELRcMxZ/5SLT/xiiub/+Jb869o240Ww15uh31DqJk4q9iB5J6mvVVgqQdny9BoJeOI5kjqobgYB+ZbIaMv73CzmfcST5vtnJGgSVkq4+dqhaTq06D8DjP8q+6NZTR56/nNfPPuYwRBmXxC7ZSufv7gHe/fDykOLPsuxO0cqCYGLVvapo57rabGylo6HoQ+GwERA7iHeRnxTGFB+KsiSecJGXMt76QoOObM3J8ZMcTYGQKCwFcfGkcq/4Xwo1J33othgTuTlpDMq8M1VaLXwtiar1lxTUEmi+j8NpThdcSnxOBS45HtiaIExguuQcu1w3ialy2D5UEigaXQjtnBwoqkcWBvJJjIWNjf6jsCK+gE5fktssQe7onJ+ZVwmAqItHTnHYRIPF8YkEKxOeCid0aARG1uMyRuqC3ytnJQ54+wttjZJ9bcK75DsQHFQlWRrXhx0Y6hr6AvkpVXZIZvpHiUFBFAK41ZDuizRzljD2nJxz22hjY53NASb7SaSE+pNkyEYi3ZYhpbv90vw0nDn9dQnDOkMWMvrN0iFED9/WHunXOm9TD48dTtHtNVYLUAK4fNDVl2cqjrmK7w+NiDuH+vzyDG52QVy3RO6qWb62ZJnaFPspQ7E52bpXSNwGx77LI/qF/V3UuvLQR727tI/Lpf11RAhmPMXF/J7oIlEs4YhJ2BA4NFtZC7IjGQMBy0H5gcN7NPdoxWLaCdVh78gJQG69aNcvravigv85m+rvlzlYtR1B10aX8J0GV8QNfNmFVPCmaAcU2hgNZsxiRmvtGSgeJtlVq4gxD1DsMdrc0xJ0u09IHTZVXOlH7YO+/ci8ysN7bj94Yg9wJwegq42CNxS9OI2PIJ4tAfW1avzTRIXY9uGjxhtrYDZk+c0pHB3XuVyICyiPxQPTL0MwOalfzIEYUXfdYg3nhkJ6XFh95IEdp2g4Z7r3mGtDQELWeD4hX7dENnRcJAdzn/Y78mM9Tt2gYRKz9UuROaGNoloxc3IIUF+kE697jDfUsBsw69qt3GkB2J9hIEbHQZjj5RvsPkRKXFM9dCLu3Da/FuPBn39mtO+Cbzd5ACTFiCNlCV062n7iNKrz6Os7/ECvQLy 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: fqwdnypkYd50oxRvFhzJ2zeMXVjDISfDZbHeRsp9RQUaICyi0rDngFNUGq++826373vjzQ9FTP9ELLNGLnjyYu7FqXyVbN/07TrxKUeqCuxtjdxZdVpKo+kkouTSo2TXIsF/XhVB6AZARZ7DldTSEAKpkYCU08cslNmrh79W0M59BI3gPCQ8k1yUCx3VPx/VH95WYsMXG7+3i7be84k+WBqup4nxKT/hkn2+blXWnsH22E2U7ozsG4wNN3I2TXR+w1xo3d/dcTngiZ1a9I+NCew9GhHYw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YS32WTu4inyPQyU3sliOZ20a2jcS5uKckqj460vEY7XhGMVSrwydAWw/VN83FthRQ+vdFCQKONerTKoGrGLL0BKOFM1ezJxbQRjvjGvFmeG4qbGEvTGDH3pl+XzrBAIG2yOZ30XFtHqZWuoDjEb8Cf3bvsCkkoFaLzj70m/1pMjIj93FYVAwr59kqIvxuUpNnPuLHOVbEPg439jUcTifUkDs99zeBik8zGXguS/Tpa6b09PjyAOzNRorQwrBakQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 6YVoWqV6rPXkYHEFm/efmy8Zs6xf/bkVX1x3Env5Sgx4u8Tyzb+g4CW5mgODz9wEmLTIN27SpWHzaIWYZLoMtTXAKtkUxErjxZxTNYOByIoP+/jy7RNFZ0/UNdPna9CU0NERHnwvAIlzGwipmdvFvUn8oU5PRrAbPirTY15MiXjykotTy+Xupzd1jZjOC+yJ+Lux966+qX7Dh6cxdY3kWNyzLINW0b8ecQzKNv5beB0ycpwCX91z80K1lL/XWRiQHFMEklrs4FqU3oKXj+56vcg0U5dpQbDhjA3LRAyLWD/Iq7DnZ+yr8Z7aLxu8Bshqh045K38tkT+UO6RH/H2ZqEWBNcSI0Y462Ewrtp1hnWjBcu+YT48n6lr8Qz/ul8DtNx/xz3nDZxJW+PjLuVXVXwps+WtXOfJQb3F2SkreKLG+Lpg0bFKpyLFEnX27lvV3bmFBNHAq1ySjGW0fh7ep9etOwup45U8SzmCrPNP2kEpTZy4jb+ypHb9aQiWKFBArnC4vXevS9DVnIylKnJB51Yuu8I9dwB4ce1Pj0JcFkBRrFgX0AzBhwT9qU8NkKbCxRUjBdkW99yHWBexrNCSVwuCaOj6OC69z8qs5BzzImUA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 59ca1d38-1a74-4ed7-0ba4-08dd057235e0 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:37:04.7861 (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: RfCQAmEElMFrFzd+lKA2DQ1yCaIanAMWmiI/0Jp1PtWx7rVWGNM+wrXpBhdCvV6qT9Nhf9OLHtsj/lAdOSNpED/UDHTGKT9dFZ5KCxFDBtU= 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 malwarescore=0 mlxlogscore=999 spamscore=0 phishscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2411150108 X-Proofpoint-ORIG-GUID: dNe-1qRMSXA8Xw9ueu8mH48DW-0ogJiM X-Proofpoint-GUID: dNe-1qRMSXA8Xw9ueu8mH48DW-0ogJiM X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D838D4001E X-Stat-Signature: oexssmbrtykw6esjcimitym54ka6o6xk X-Rspam-User: X-HE-Tag: 1731674211-550343 X-HE-Meta: U2FsdGVkX1+pzZdXkPfaCamufCO9xIfMKy1J0v9lrRqg68fMI9f0slZfWpqERo98+ibwZqFzGYuLQkr0zUyUf1RW/mXNTwPo6behuyPjW18YvozFiFNGwDnhMVQp7irET2qfikupj4QK54iXDI3//KSE+hvyoo9YBLUrQaoAWYYuLHgr/IdA4FkIXneJle+v1Ltgss8WA+jzN8/liOu0CWzljYqboByDrIjaOWz86HsvLBhZ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fdLWMe18tommD8mtj1UTBd51JlPQGXq2uekPAwwnfmVhUlWBbxTiAzQ7TgRkpZYM++bvpk8Rpzfqn+1/Wa2Hrj5jyVJyqlI/8ym0rW9MkYTrAjWnxezGMyllUyiHDMe0tBD5T3ZAPAU9ewS8Zf0VPO6yk6nodcD+sgYCAOOUv3qUNOTJ2i4EjRueI0wExY5Rciw/CJXirfYjlYFsaCH41Y/9wal49x5jQGuaiNDIlbqvLw2E2fcvIL+LVDUASEWNNHUh13TuYz4s5jijJCBtAVOHSSpckn5fT4i0f4bKcCJf097McHZ52YYNemDw3dcEBvr4Ao2vCLTgVrbLlCBBPdJqgXBReJv9hG18HggThBJAU34Lk9DK8XPeZgqCOa70pLKnCdvRqXKU+AQPiZXOmX9jfDhDpRI13zcLZLXhUCZ+V9i3/qnByNvWmNPhikNFZlgntaNkR37Ysir+Mez00YDrEg3BjeC6so98Xm60O412vuU/SRAhFvBG/bgSRYshM0BkGN8ZTeGXNxHDUHfneobxV37VXbUiR8JmXry+Dc+F/09ETL1+YlqLQ6PSl+kYkwzFcAVnKFSmLHOcsHT+mAAKC8jV+O+fe2JNS5NMK69MM0jgl7Yaqn3nFDYuc1sitkPQgfro0l3YO5SaD G0PdPF55 u2hxLQhBaXryPhk3Cpn0iLHOackmOEObOPeJ24wfmhs= 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 840b8a330b9a..e47f112a63d3 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -34,6 +34,18 @@ 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); + vm_fault_t do_swap_page(struct vm_fault *vmf); void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma, diff --git a/mm/mmap.c b/mm/mmap.c index 33ebda8385b9..f4eac5a95d64 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1808,7 +1808,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * new file must not have been exposed to user-space, yet. */ vma->vm_file = get_file(file); - error = call_mmap(file, vma); + error = mmap_file(file, vma); if (error) goto unmap_and_free_vma; @@ -1823,7 +1823,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, addr = vma->vm_start; - /* If vm_flags changed after call_mmap(), we should try merge vma again + /* 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 0faf39b32cdb..fdacc3d119c3 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -955,7 +955,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; @@ -986,7 +986,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 ad8f8c482d14..8e5bd2c9f4b4 100644 --- a/mm/util.c +++ b/mm/util.c @@ -1073,3 +1073,21 @@ int __weak memcmp_pages(struct page *page1, struct page *page2) kunmap_atomic(addr1); 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; +}