From patchwork Thu Jan 23 20:58:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 13948641 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 704C1C02182 for ; Thu, 23 Jan 2025 21:01:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B46F28001B; Thu, 23 Jan 2025 16:01:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9925228001A; Thu, 23 Jan 2025 16:01:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8040828001B; Thu, 23 Jan 2025 16:01:45 -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 6513228001A for ; Thu, 23 Jan 2025 16:01:45 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DB13880427 for ; Thu, 23 Jan 2025 21:01:44 +0000 (UTC) X-FDA: 83039938128.14.8F46213 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf06.hostedemail.com (Postfix) with ESMTP id 80C58180023 for ; Thu, 23 Jan 2025 21:01:41 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hzpiSYei; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=WjVjCG4B; spf=pass (imf06.hostedemail.com: domain of liam.howlett@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=liam.howlett@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=1737666101; 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: references:dkim-signature; bh=gwmYlI92KUhZ3IG7626DZ141U8TLTFHRmKNgdYAaCW8=; b=pgtS+siwd9V2t8ytwXsIjMvFW2Z45lEXqmquj5B+LdkRriuQvlkpvNQhhjl/GmLvPn0661 PLJsNHte9WTfbWqQUu37SgicTwdlWk8AfOSjXQ02rpAkGVNz6Hsn56RaoqWOCNPW0Ywnji VYDs/n1GWj600HCQqYsYCuAXUXKYIWo= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737666101; a=rsa-sha256; cv=pass; b=yeMRQA42HrlyJr13CKjm4O8LbSL5xfOARYm4XtjU+e3pwkqhKThJVv8jAr66etdZTBy7ia R2s1BMYlLHURquXsOLfjkWdl4exBF6RsqxYCCird68XgX2V3JB82wwafGSNJTmOqEgxXtO 1VIx2u3EWDto3cpWVWQlO61qco66Pn0= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hzpiSYei; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=WjVjCG4B; spf=pass (imf06.hostedemail.com: domain of liam.howlett@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=liam.howlett@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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 50NKn0dt030476; Thu, 23 Jan 2025 21:01:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=corp-2023-11-20; bh=gwmYlI92KUhZ3IG7 626DZ141U8TLTFHRmKNgdYAaCW8=; b=hzpiSYeiRXcz9eewZjdwMLvUYdpbi/vS SCHJ66y31QN6Pjc/j5mORoQYGkmGH0LHxis6wSI0hHfn3+OLLJYo4jfE38k4vP2Q UoB19rQt9mHIK5B6pOz0cGhmdttJa23hmUancNhtBKUhcFMUFB71lreMfhwzQSSK Rtyaid+W/h7YFZ5lYsGz6GNN+3P7zafpjNZ8nAzF2yn870QGZ++1uvRDR6sXpHl4 of+7HBSohvyBHydgaLpQChPpZYQoHQSH5h/lSaHQnvEnwQxPCqXr/M5QGORHUF1p Rvvs6VewW3YeAepiAI0HJFTs8n75FSmjiEXUVSJUZaQJci7fAyJF6Q== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44b96aj36x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Jan 2025 21:01:25 +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 50NKRGSW018748; Thu, 23 Jan 2025 21:01:13 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2176.outbound.protection.outlook.com [104.47.73.176]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4491c5hq6a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Jan 2025 21:01:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lAHNdE4O9gFdksyGGMbfy/8BSU87yg0mx6Saf5hDzP4OW3emdio8SyTA1aOprXczUvldi6RYujtAMMukfChsFFU7UmDAROZZyYbab8MBh96pW3gf8fdA+m8S6+BFjq8lpEykL2PN9McW2T3z35D/oOLnectGZohOfqI38RBlB50TZwkrlzjSN46EpK7WcSQG5zwtptOAxYvNsVZO+oilCSNaC0C8yxyJxzQ2C/m5uJIJTK05aQqrbtz3gNwMxDXBduKOGUPzd95214QR0h69XmsmtXsrCnzZH/X7613WSvldpG/zr0i8vME/zU8gXgO4KeRKNRkEnRKQ3L/5k6Uj8Q== 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=gwmYlI92KUhZ3IG7626DZ141U8TLTFHRmKNgdYAaCW8=; b=ezlFhnFVa6tsYgfcBOf/Mpmj1l6nRHbW2y2/7Vrs/SxVNZLvUV7PBk05WA1w4giKlRF3NS5uXNjPGf7m35qMAYJi4QAyh23mdlLjxwUCxSGkYd0x2TJ3uqOlQq271vHF2q/zI+4UOq0Nz2R2FkBdDVv2gr3+enU5i6YEK11/lXNQ66/+6DNpxEmgA0uAhFmj/g9cgQHPh0VTqcNtZUBLkmaCf2SY0nsgTlJIku1DJzmAo2wrRY6xcYE4dXIMAZCPs7qLCd6/aloRmsQF33Y1gtHdOfssIWDwbdIAxRLGgIOBJ6igKQ/hFSkaWJHKQ0OsenQoZKb7rmYyZDtcBz7FEQ== 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=gwmYlI92KUhZ3IG7626DZ141U8TLTFHRmKNgdYAaCW8=; b=WjVjCG4BBADIkwkVe+oWacbYeYcdvRAlaFObAlivMgZLqh7OlJx9P81Vh7wmhB6e4GqdV2MPyLUG6HiMhW2v4YPGxWO5O03lEpfmuacikM76DqDugQmaAUMURm91wMeRVH8oFZI/mBgxfF70sUvspu/jW8UHMXSLLUYZeok75PA= Received: from PH0PR10MB5777.namprd10.prod.outlook.com (2603:10b6:510:128::16) by SA2PR10MB4634.namprd10.prod.outlook.com (2603:10b6:806:114::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.18; Thu, 23 Jan 2025 21:01:10 +0000 Received: from PH0PR10MB5777.namprd10.prod.outlook.com ([fe80::75a8:21cc:f343:f68c]) by PH0PR10MB5777.namprd10.prod.outlook.com ([fe80::75a8:21cc:f343:f68c%4]) with mapi id 15.20.8377.009; Thu, 23 Jan 2025 21:01:10 +0000 From: "Liam R. Howlett" To: Andrew Morton Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , Jann Horn , Lorenzo Stoakes , Peter Zijlstra , Michal Hocko , Peng Zhang Subject: [PATCH] kernel/fork: Be more careful about dup_mmap() failures Date: Thu, 23 Jan 2025 15:58:49 -0500 Message-ID: <20250123205849.793810-1-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.43.0 X-ClientProxiedBy: YT4PR01CA0128.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:d5::25) To PH0PR10MB5777.namprd10.prod.outlook.com (2603:10b6:510:128::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR10MB5777:EE_|SA2PR10MB4634:EE_ X-MS-Office365-Filtering-Correlation-Id: 996d15ab-b2bd-4c4a-45ae-08dd3bf11032 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: J5BPJEby4n6RknENOdWpTueYo0nA8F33oXagrWNxleyJFpjtVRFiiq0Wl+cB12pOlbfwUz5MrAHcYoOZq7TWTsl0HA8CCukfoG9YkbHFV6AXaCzt4mQZRX8Q6KRqpDcdLUVE1tS8oRB8bvDjZM7LeY//IxFmRdR6/e1efKAQ0DRFEFAro0MqtsaxbO49rHLufbcLK6mj6/JOMgsT+bRNQskW2v9caEgnPery2xiyRr6n0CO/D90/9XmnIuw9y4Fmb9DBdDs1NCSIGwLSc41j0mUpfuJWrW28rtds9awtxhTBxpexpjjnAENk7YmF+RZL7yr+PFH8qJyPiV/3tX4/wSboIT7sksuoenDr3ZQhbt0+oSVq29cof6np7psL5u7QjbwmYo4VtLoKkrPRkoR0zLbxrFn7PAOvRIEzw9+mXTJYcZWpNcF/6aDeZCk2nNfztcCz4JEA0JpxwhQrFvtftHCyBdtcRdf/n9rJkSOV7pfAUkkmeepEEaxgFZZOw9STqC6GNFWS+YDOF0T/8U37VFXQsbHCaoJ2GKUaUoCcqzL+n7XNvYu3bGe2SYqcvy9uxnoSnpDS1avK8XPoLtNRdKqCH0PjfrhNH7wGDh4iYLZTwpAATQiB2A2ByfyIZvSIhTQFNsuRDZAgT8Ns79aEQ7X3a0lUWpn82W/6o7K/KbIh6bTH4KmjcQFqyuxcIRmwIneYoYnTfmbtYdo/POAsRgyqEIZpILWKYP0n4QbmflNsgurpLIV064GttnWog0MpL1B/+PrQTaZJKPm2onJ9yvfaVqNXVEdmXsgtPTu5qBTLiK1GOTaPvMshpcPOayNP1WlXc1ci3Kms8WWgoIjofqdJ3cx+LAjwCd/FwPX7mzSTnIl1lg0XlmrcVW0j1ewAC5ap5rzWM5/G9wQ/y+8ljZDyeZqSfW47yqs9C3K7blisA55Y16Fb7aPYZs8FMoDR3fdl4WI11spJ0tqgjHLwZ+JadG/uZjrocS/s6hvecyycKlUa9tnoQiEcqXkWdB4S/wR81YWFiW21czDLC6oUwfxKe4Jywlk9Mf8Cp4+qqF2OeYci0oHzo3fy40CJcLcEuwatTIdJ/qDAioA3fB88akk6CqnId17iWmhYiiJ6XHqZ8qJGFGoPQEnvH967/IGMAA4v174+gGaPYyWRyIMe/4WkvrGEv7bZTZ0uEmj0I4b7Faskt3SkvhkwO5Xbg9DNTbLsPLH0xGukcotl31Bn5BmqIn8Ddbc6eHW5DvGDJFa+8eCcgzXfi6/2phpZt6HRQlc1T3XCcYL/zkZCFNzVXdUFP6ScFU2wAYyJ6hOl7ev7ezHZFIg/NaMQ3AHm2iDmpG8Wq5XjP2hTnZ3Dict4hCXAJc23esTXZ9N9Rbm/sGBJUD2WOEniifzFXe+OvvGI X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR10MB5777.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tJZOyMdi9tLUyY/2KaP3IMP7WBkIP36oFnWYFMAWVDTs8vIyf4FDYwB/MJzOTLUbLiHvauUlA53E7YdKwhu5L/4k8feLcs9k68EQ5GC8q3+1o7SmrultsSQ8WlO7qQ1wU8KI9odb4yt8Ak+nQkBbWpsFpsyLS1hMPkUkXWInQbTnE0suW0g9qSxkErh5imrM1cTMRHZLgBclD5/8qQcbuqB7YTlrXtWol1v6qHMYcWAogB5sjX1kEjYSawBR6delrHHVwqorZkMGedopUSjwlFALlsGpkB413ThrWyt/wGpT79+4aaI1zqVQixV3ytqcvKqYEy5BBoA6r+sDwcs5KBm9v1afVicLHmvJMYLTqLewjGBp9CXS3ha4ffhCkaOuXRvCsBKKtRNLfn7Hl1seT4srqMT2A2L293vdbngGrA3DmpbZaz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JGyq8IKfpDYOeaCYSioQ8nh7xBm5qOQJhVfInT0Nq9d9NgqVCnuG6lIO6k7c9LbRNGBkJiXGuyTsDiR6WHzujlo X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: wz+SFJl9g7AziZkc6lOWfjtBY3gsIo/9dodJjtbIA+uP8aX1dBrH5A76Yfesy3GtPF+J+eHdlUAuztVVn+9PObeT3pdC2ZAEI8GW5h61geYMsoAFWHduIDPSOqBNKm78w4nzeGV5QvgdRKqpVB5fAyIey4B0/F1/rXiTmeRr7ivVUPYe93h1SYDBKyF6YTEYrIdzLJyNF4gsgKTNOYujasL7WQb4mWRcOskC1MkPzyeDhWiWgSi+dhzjelr9N21vdSi48ixIPfKk1TfKEm2Pgl9riYpzRiAxZFIkY0GgEG5EGUEtztQnTAMs7gfX8z54lbErI+DyJfp0RQ8kGYoM/IXBUSn1EVWk+ve88ac32OmSNhnx8tYinfCEA5nsYwrL93uCGPDfXMgpV9qVvQ+YFnzdBEjjvHGmnr7fiQXPgBQrko76IgTe8fWw3GxVy88lL3H3v9Pe2x6ubwJdHveX52VwXPuYwQimmFxY4DqqD0F4OS7ZKX7MBbc4nzH32GIETtjXAjXYO6B3kAGjWMV/zfXyUGjhxpWSxnmo2efypL0/WfjEOBg59GwvupXeDcfWR4pfBbq4ALIBn+ZPTCQN60tT9iV5mkvllZwsEit9R/Q= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 996d15ab-b2bd-4c4a-45ae-08dd3bf11032 X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB5777.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jan 2025 21:01:10.2616 (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: UPcQ/Nwiwbl4F+ZeUnB5cWLEW3HzouqjqWNif3oQlVnBYl42EilqFXsouGP+bGVMJ0pzvpcbKRBkW21PWwpqQQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4634 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-23_09,2025-01-23_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 phishscore=0 adultscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501230151 X-Proofpoint-GUID: CFxkjWyhlDc1NWXrFABRUJJSo1bsNyFN X-Proofpoint-ORIG-GUID: CFxkjWyhlDc1NWXrFABRUJJSo1bsNyFN X-Rspamd-Queue-Id: 80C58180023 X-Stat-Signature: x8zokbznnzmwkb8hnikrkwoe1kmkbt6r X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1737666101-752475 X-HE-Meta: U2FsdGVkX1+VXRbmfRqAsV42LaMebZ1Lro1u2qwDdMnrKx2onSiapJJCzr/QLotIiZR1DWySupeK/NnoxVHBG1GGAeoEGHotNjBvQol12fJD/wUdN/FSgFoD9RWmzWfUjfbfYwPfG6xUefbi2IXKokcBlPPROc8tFOe5lnVMqHEaHxqOMlURuj0jnV8xyP35l14+tivuQ74pNnoZEIgIK8ylWBJ+RUqpYGh9/eHyopjChoSJbD7zbU+kraFPlaAAGsThKb4RpptBN3Iz5MZUvAmINIErW/pD5zAXiRVlzvdswUPX84/j+Ed/kYD0ZEE6cReXaWt6CJTBNmsrxoCLxHKsvV2060aa1gXFmelB4zTZKjy+KrMfE9yNGHgwbSIV2H2Xb3Iby5VUyJsaQg8bOR9+uE+/OHBeLecI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v+mW32b1i2cPfdw6eM3vsSGukCNa10TbKCXwVDR5og+WryhXH4qHt4ug1v/IJu2Mave9m7XdMhLnWOWTxtOKLehmsms86ozXAGs5RXIlj5AG1pUcE5EHw9zJTN6Et2M8F0T6M4apqdjaLjJMVmUTtHT4Rz14SD37JgoKb9xDAxPN1ZqiFKkMc4gDiSEIVxPraXZbuhCtMvxWpr+O1l+44Y9Bh+1JH5ARDZf1KLZDWoCKc5CRcKzXfhCXDlPABJ3sWeVNS42nXhbwnQ8GVz0Rf0vSaG0M1aapDjEdzWgsveIhHQUzE= 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: From: "Liam R. Howlett" In the even that there is a failure during dup_mmap(), the maple tree can be left in an unsafe state for other iterators besides the exit path. The unsafe state is created after the tree is cloned, but before the vmas are replaced; if a vma allocation fails (for instance), then the tree will have a marker (XA_ZERO_ENTRY) to denote where to stop destroying vmas on the exit path. This marker replaces a vma in the tree and may be treated as a pointer to a vma in iterators besides the special case exit_mmap() iterator. All the locks are dropped before the exit_mmap() call, but the incomplete mm_struct can be reached through (at least) the rmap finding the vmas which have a pointer back to the mm_struct. Up to this point, there have been no issues with being able to find an mm_sturct that was only partially initialised. Syzbot was able to make the incomplete mm_struct fail with recent forking changes, so it has been proven unsafe to use the mm_sturct that hasn't been initialised, as referenced in the link below. Although 8ac662f5da19f ("fork: avoid inappropriate uprobe access to invalid mm") fixed the uprobe access, it does not completely remove the race. This patch sets the MMF_OOM_SKIP to avoid the iteration of the vmas on the oom side (even though this is extremely unlikely to be selected as an oom victim in the race window), and sets MMF_UNSTABLE to avoid other potential users from using a partially initialised mm_struct. Link: https://lore.kernel.org/all/6756d273.050a0220.2477f.003d.GAE@google.com/ Fixes: d240629148377 ("fork: use __mt_dup() to duplicate maple tree in dup_mmap()") Cc: Jann Horn Cc: Lorenzo Stoakes Cc: Peter Zijlstra Cc: Michal Hocko Cc: Peng Zhang Signed-off-by: Liam R. Howlett --- kernel/fork.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index ded49f18cd95c..20b2120f019ca 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -760,7 +760,8 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, mt_set_in_rcu(vmi.mas.tree); ksm_fork(mm, oldmm); khugepaged_fork(mm, oldmm); - } else if (mpnt) { + } else { + /* * The entire maple tree has already been duplicated. If the * mmap duplication fails, mark the failure point with @@ -768,8 +769,18 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, * stop releasing VMAs that have not been duplicated after this * point. */ - mas_set_range(&vmi.mas, mpnt->vm_start, mpnt->vm_end - 1); - mas_store(&vmi.mas, XA_ZERO_ENTRY); + if (mpnt) { + mas_set_range(&vmi.mas, mpnt->vm_start, mpnt->vm_end - 1); + mas_store(&vmi.mas, XA_ZERO_ENTRY); + /* Avoid OOM iterating a broken tree */ + set_bit(MMF_OOM_SKIP, &mm->flags); + } + /* + * The mm_struct is going to exit, but the locks will be dropped + * first. Set the mm_struct as unstable is advisable as it is + * not fully initialised. + */ + set_bit(MMF_UNSTABLE, &mm->flags); } out: mmap_write_unlock(mm);