From patchwork Fri Nov 15 12:40:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13876182 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 028BBD6DDF7 for ; Fri, 15 Nov 2024 12:40:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BA696B00AA; Fri, 15 Nov 2024 07:40:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 640526B00AC; Fri, 15 Nov 2024 07:40:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41EBA6B00AD; Fri, 15 Nov 2024 07:40:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1C8046B00AA for ; Fri, 15 Nov 2024 07:40:47 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B6E121C766D for ; Fri, 15 Nov 2024 12:40:46 +0000 (UTC) X-FDA: 82788287610.16.6D8EB44 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf06.hostedemail.com (Postfix) with ESMTP id 047F6180008 for ; Fri, 15 Nov 2024 12:40:10 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=bw1MasTN; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=kQ7TgRNF; spf=pass (imf06.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=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=1731674246; 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=Rp4/S+tmW8/2EUOVCLf3AsFg3DSHJEhOXEcoD1rcL1I=; b=fWtmrAWStItmNXrhoSk+kQfBNBjkEOYiBN+t2qlqrqZLVBnCDvQs2MZiTNjA0wt09V449H aacPhKz8VouCfdAfQ/9d6CGBPMkTdhPKC/i1gE6w9torWP7HV9rJ+g73IiXKO1X8uCkkip ufHe02K3XksJpatQmxSvTIdWWR3ds20= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=bw1MasTN; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=kQ7TgRNF; spf=pass (imf06.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=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1731674246; a=rsa-sha256; cv=pass; b=UziGgP0xHNDghU3IwOGKf5h3s7VKRK/I97xjfpsHf5QqrcHm1XJJW27XlfxMSKmXfMOX3w RHI71v5zRSit2wYlZQf9NpS5xZiKFM5rhA3NbgN2Ppv0ynxysrPXLadvohG3F9/ryIzqmz ILQn1BLU9PnQuT+3yf+Ggr5LMZrBYV4= Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AFAH07R021277; Fri, 15 Nov 2024 12:40: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=Rp4/S+tmW8/2EUOVCLf3AsFg3DSHJEhOXEcoD1rcL1I=; b= bw1MasTNWkFuZVbR3o6XxN66ieQ/YX3QDBIvvWsNaza+Ox3Ryru+De68e9uWYeb6 leAD4twaKOx+SWjdDDpE90+8BBffILVackfYgh25eElRfbdET9CPSdszQYd4IBcl CyG+KrsLaHXlqXvT4MtsSRSaSwCzGy/Ei/vJuhoLw+RdLFsfHzsIsv/K3w6cbUKr MFYzTxDCE6ctWvaURJzn48BPFTJxNA0PlANUXoVup2D22xP3SeuOZGemdHMKA98P sG9HKEFHEXzfXJzRG/gxb5ztArKZys7/nxtefJsM2HHzva/edQ7JqInpnySGaGBF r0EGhS4VJmfLrcawPwjN9Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42vsp4n13p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Nov 2024 12:40:30 +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 4AFBRFUS022725; Fri, 15 Nov 2024 12:40:30 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2040.outbound.protection.outlook.com [104.47.55.40]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42vuw2mrry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Nov 2024 12:40:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=l2s/0hOMQUVF8gqu8v4G2siJBAmbt7kxoMnSjeuq3cKGUhmBrlKJcF/K2Hn1zl7bQYQyblcnbshrqm+xn3ukQsxrbwSFHV9pfKKmA30SCKpguOyUGLae2JIPFwP9BdIgPey5xlp4JxOycmN8DPvjgr6ebNC2Qyesy18YlWe2iV9/+Oq1b8KuZzAhHxnJx1Rx22e962LouDww3DI6D1MfNzt6bVNx+FkSqMeP2bkjoGoNWCNg0ig/Le6OxHvw4z5xsnoryvBS4m3EvPfnMF6JK0Wp50T6Ki5yu3cyqk2gViT1u6y22coSsCzAgmCxAxxAnFSBpYiB1k77iuLqQSDttA== 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=Rp4/S+tmW8/2EUOVCLf3AsFg3DSHJEhOXEcoD1rcL1I=; b=xotfYH7Sp6dp2dt6AD2NZ6ugWa8ReplCZqQAckkjvqUSB2zLWa1keNLrgFYxNQueh6L1VijiVMF4gQPiuSgDLgjNiVcmU3+3BHp4Gn8ycNR656xh/9BlBrUJzoIW8+CQs6iWPScaXYeW64Ls98/IWO9lp+OPbuOeVLJrmLSSdUZ9mX1X+Ub7Khz+y0e0KOura6Vr+L3vIy41U+73NxKfxY3spwHCf9Y+AffxCnJkEpdFQ3d6xyT/BSVKhzxf+BfsCUICvcTuGG9vYtIGUfwFRR/yIDt8D4+KpDH05qtY7+cU8atRu0S1QUIdwa9nmFuTmno/50uC7k8UpTpYJ5SspQ== 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=Rp4/S+tmW8/2EUOVCLf3AsFg3DSHJEhOXEcoD1rcL1I=; b=kQ7TgRNFWmh2CGOmBWM/rcgbip9k5ZO4a99J8ATnqQSarefgh3iY+k8A8F5L9szzh0970x4rJZx7Ghe2TmsFRhZrRwchvZ+c/ysQWLlCfRpioE2OHjjv+bNkdRTRitPiwlPPFHLY7UDKR5mqLeOUldxwE4p1clOR7TuGb4jwQuM= 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:27 +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:27 +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 4/4] mm: resolve faulty mmap_region() error path behaviour Date: Fri, 15 Nov 2024 12:40:10 +0000 Message-ID: <4cb9b846f0c4efcc4a2b21453eea4e4d0136efc8.1731671441.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO6P123CA0034.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:2fe::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: e08f1448-0deb-4c8a-89bf-08dd0572ae9a 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: 68+7svkN7IVwsMmdsMGYPkSTXSEekuHO6bl/h0ycUqLV+lEfdDYdrbAJSlb348MJbivo6MaTM1LQj821tPoJIVqVgiHs2zELW1u7AXDQFbLDRUWVRSzUVCAqOl8RZuEQoWhiVDQGe1ECRvLmXCUlSu2hi8iPm3kAkBgeBOwWQi2LFJcaoKmtlkwxXR/5tuhdi9t0Dji2hCwRpWGl9xKo1+YE5h/Unmv2YZS87rRmOlVqbxjVOftJlCp48qy9U+dZZN6nhR6QGzjFKOzinUidjKFO3H9KEVHz3+L7/BjKyK8VfKRnLZijd3qIuGfRqtFwxuoMVe6LrqSlq645NGvNVs2TO46L3YwKMPKVXRtpRm7oX61hp/QWfcmcyb23pV985F8VJ7RiqlUOWK8JP7f9nZ1sakfGBan5cXuJrQnq7m36+u25Bz7FwPbX4gnbSGr/2+CuHNNNtoJYOCgV7mXp43AaTTUg9pFcZVlDHRMH3B2vwZW7vtzQgQj9cPJJUisMtjqPP2Hvu3KCb/sAHm3OoFQCtOrlA8wOvQPtFO/M4Q0iuSCI5+7ehfHVQY2ozRl7FvWWUilM6btVKESnpsPPEeKVhXyD3WeNtbWdnKZvTUrXDHeQKW5AzzG2TRwU4xPRHkKE0izYQv4RVyqDK968jeHbTyNWEt5RisWu3TpkEIgPXSElv20nZL0MtZ5ALqhAABN0jN42nDkBF8zfGGwr9QoC6pOSfWhQaET6V8YKqGoHAUbLvyNyjRVQpZzMHx+s0kXjrBx+0fJcd61CETrRfSrKqzc+TOQMHG9D33+katMUu9b3+Cqg5N0KvANfdKF976c84DIq6nY8aXzdiDNilMnjqRcwshSk9/VyqoaUxSPjdD105fhgv+Rivzr6Pk1PHnXCq5sQAfbZQ9P/PZmRSC1HwSPhafJPWq1P92ffOV8I1Avlef2LFBKah6S+tSTDyBPHFKGSPCRnczeOU1MydH8OZ4XwNUAn6Tj65G2ZMwOC368VRujP0q7RKtgDsvL5uur+8wd/1hPqv9MoBGvjR4h6JfGdh5Yrqe1FYdRYdbcahixtcG3qOyavGLdRMCk3Bu8RW/C9H2HnvzoXfi6SpPZ1kxsqIGAu74fYGk1RGC8OM742cShkuI6TbJeH5EGLYnydSlIU8NqZE1dfq3FXffyW/s/N4SepKEXM2x3yL/xb5vXJQFdA00+RyYhv9DKXoBk9TnVT6nTToHOC1e1tphbRv2r/DaTq0Zb36xeykjpsZMHKxcTjNYpShyz3v6r4vQaVV9BxpukIUdYO+K5t6COiCV/ellWOBzJlKFjf9KXjl1NuxurXtT72bnA4Lnkq 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: O4MrEOe60ySYNRs16IM4VKIIp+3X+p4RneeSSYlgI35Z69ZO8j7bK9UEpDSdmKNf5WoRjqYuwXWJtb9P/umkgB5iILwYz9JjXETM9T/vLo3p3WqYqf0e4UWEcFrfgVKGun/nsWMi9oOD6en9jmpbmUA1/bf+OKhdoHdgYQAj+ERJNPYMBilry4OpWO4Asg7PvL0j6Zb9EVirjgifvtscc4/BMNs2Bt05T/4GsO+VjsbsOmtXXQIzjnLxv4mEJldB3sL8Mn7t+gE2tRCmjtd98iQUx7zGfMIzbzmPPdABM9AJmjoc4vR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0FYCtAWssr2iF8lUmHC+qbMH3lGDsGnXcbtmFI8HYbqJTIO/Wa7/2dcpKHmKszo8tkLM2EhBVqUXXABiRZ5N356FRP2sjf39nd8CQX43zM+cHAOgHufThPiwGSFpqqeBQvoDKgLU6rSZJXBhpPTRlwBwSA4Q++BB/YbsyVJ6aglZyqgT0FcalxSzUBiHWt/wychEUQoteUI/6MeZyB2E4jHQ4Smk9J3mJ10Nnsl8rN8ruk6kAJnqvw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 54DX0BpqaS3fSkEVnfivT7XgEIeJVfeDYFr6CE0xC5mErLMVSamWSeR3PWf1S+hfcSDP/FSEani2bffB+sG+z5CYhvij0+K4TnRPrh4DZEE2WyUj202BMNBDi4LqzHTKSWnEugLJ2bUzHzOmFmsLaBP39aLApMaokQ/noIegpGE3yb/xI2t+BMkBoNNL9GKf+GUS0EFsPTDjKtsEdLXRNeRi9B8LnDroL1LG09c0RuBDKwLQHa4VJ/AvAvBrtiSjIryQfPnGC5lhdNhg7xNfvAAL/ORJRp6AC8iERP901ODHXAct090oMwRK5UShfUJFa3ewiCc9ZkpmxdUKi0VntBsE8u/qFQJW6AfzVQ0oV8Decu8/2RvabTEYfSkzcIhJaY4jt3nqPD7+/z/Hh+s8aDI14rqHVBmiF0WKYWobdTIVEqxR5F/n4IqRgnVathwIYzBhWQ2fR7m+qZA2ZEF4N1ypPLJjfQ7kLS9CE70eLVVo7jKs0GaJ3TqTeIC9bYMnkWML9LhbkKqj+mwO8sGM39vN1SRx/28UyOBClOIP9dj+pzT1ukUsDUJJTPQ4IluqMD7wauvJBdkjUDnuWOyQvcPFzmw5NoSkvJ/oOx1NeOU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e08f1448-0deb-4c8a-89bf-08dd0572ae9a 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:27.1288 (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: sSrmZdCLWUlCeJt/Q0SxWChwmYJ0w0pcswxmNRDl1KVh+f/z4SX3ahzSCJaFmeqcCluG2+24k+a5j4877plKc2wzsoA27W5HIR1nVf8gnCE= 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-ORIG-GUID: 6c584fQVSkwUqMk5NVXNBP2KtXnSjkYK X-Proofpoint-GUID: 6c584fQVSkwUqMk5NVXNBP2KtXnSjkYK X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 047F6180008 X-Stat-Signature: qo133ze6jjaqm6rpxzt77e3ujxjykfqm X-Rspam-User: X-HE-Tag: 1731674410-429405 X-HE-Meta: U2FsdGVkX19/Bj6jcdqt48v3a1MzmHHtAwjvruPQy3Zx5MV//XmwYmh07QP6l87LtTmfQHautQpwvI8RMhxnnUfF3D9p1XFif8As7SaFfn1LaDEiVufZ/Ucd4nddcn2QjOfkGE99TMmqJCwzHR08UtHJ/5XdlU1wDS0qDhJkw4vs0dhzgWcZMfGli6zn8jmSVgt2t534FJKqKZ/TdDuz8hLQQIJNn8W8Eif4wP8OwXT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NMbZCw2NbDZi2b2mTCiyPlz4MT+idM/8xl+F3oDITqOEHPSSLbt/hHZ25JfhQUcLFTgzex8rdgEsXBimNVcEXhEa+uazoLQd47XJIFbn/VoNTB7a0hjYAHIqW2x9z6duifRlWyGGfQ3tMPdxU/Pvpa4YQRozGxLoIIrUpHmP/vavzJNyjXxBl/L+JN58ZHMT1q+I6uT1lYaevO8nfnIATvLgQArmsfpNjJtN7wjPiEtuoT6EI53Lfa9Tusy7N/eQBEq+p/pMrZH5BlPakN5V0Gqst6HKgq4vobj/uH/wqngTQx3gZZct0M1nW5Yt7QkI/z8tvSPtNyefxaKjHWs3BDpFsWQKJnBJx4HbImLvA25KxhQtLC4YumZJVwVfZn/caMc0o8rKvndWKIza8japh7tz6Kp2XXUqWDGZzu+XlE09HMZxHdTh8FTEvUOtIa9V/bx98XWjSQLCqFBx/cUrwQB2/sLP0KStmj8ZfGGXoQmijZt5eKTK6rlMHxcvGIDvIeoZgkuLGVcAArAL6+5I3SIZnHsem33J76JNuGRDEw3yrm5Y28M8L8tJljxNtNWNPZo3FGGwiC+/RYQLNT8+2dO8wICp06cNXS3O0EtIkKJWE3tilLTw8kC7sJk5p81otgDJrNulXwOkS2DVJWaHe2w PQaySc0S 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 | 103 +++++++++++++++++++++++++++++------------------------- 1 file changed, 56 insertions(+), 47 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 322677f61d30..e457169c5cce 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2652,7 +2652,7 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, return do_mas_munmap(&mas, 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) { @@ -2750,26 +2750,28 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma->vm_page_prot = vm_get_page_prot(vm_flags); vma->vm_pgoff = pgoff; - if (file) { - if (vm_flags & VM_SHARED) { - error = mapping_map_writable(file->f_mapping); - if (error) - goto free_vma; - } + if (mas_preallocate(&mas, vma, GFP_KERNEL)) { + 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; + 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)); + mas_reset(&mas); /* @@ -2792,7 +2794,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; } } @@ -2800,31 +2802,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); } - /* 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 if (vma->vm_file) - goto unmap_and_free_vma; - else - goto free_vma; - } - - if (mas_preallocate(&mas, vma, GFP_KERNEL)) { - error = -ENOMEM; - if (file) - goto close_and_free_vma; - else if (vma->vm_file) - goto unmap_and_free_vma; - else - goto free_vma; - } +#ifdef CONFIG_SPARC64 + /* TODO: Fix SPARC ADI! */ + WARN_ON_ONCE(!arch_validate_flags(vm_flags)); +#endif if (vma->vm_file) i_mmap_lock_write(vma->vm_file->f_mapping); @@ -2847,10 +2833,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 (file && vm_flags & VM_SHARED) - mapping_unmap_writable(file->f_mapping); +file_expanded: file = vma->vm_file; expanded: perf_event_mmap(vma); @@ -2879,28 +2862,54 @@ 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); -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, mas.tree, vma, prev, next, vma->vm_start, vma->vm_end); - if (file && (vm_flags & VM_SHARED)) - mapping_unmap_writable(file->f_mapping); +free_iter_vma: + mas_destroy(&mas); free_vma: vm_area_free(vma); unacct_error: if (charged) vm_unacct_memory(charged); - 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; + + /* 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;