From patchwork Wed Oct 23 20:38:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13847893 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 BE474CFA46A for ; Wed, 23 Oct 2024 20:39:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 568ED6B00A6; Wed, 23 Oct 2024 16:39:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 518D66B00A7; Wed, 23 Oct 2024 16:39:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 345636B00A8; Wed, 23 Oct 2024 16:39:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0E6076B00A6 for ; Wed, 23 Oct 2024 16:39:03 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B4B59C0E82 for ; Wed, 23 Oct 2024 20:38:43 +0000 (UTC) X-FDA: 82706030190.20.1A32BD5 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf07.hostedemail.com (Postfix) with ESMTP id E91C44001F for ; Wed, 23 Oct 2024 20:38:34 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=mDLV1RSF; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=ncxS35y3; spf=pass (imf07.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=1729715862; 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=GoV/SXOqaoQJF6Y962A0upUaI4C5tg8OVEAFdKWNTU8=; b=avNxHLGEzZIpDfN9dmDrZU+8umYEa1YzvopON7rhOwadTfCPqGuas2sxvhKUMUZIl9S57K mz8NI1nKIcqZaXMO9xCLrlu/QnqEBhaPGeDtWdj+MZphNjBNxxwnk0WLVRZ9mNLBdxBAvR Jb8OiAfOblNPMohxuSp6B1DSx2zNMPc= ARC-Authentication-Results: i=2; imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=mDLV1RSF; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=ncxS35y3; spf=pass (imf07.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=1729715862; a=rsa-sha256; cv=pass; b=exuktpY0uEB0W9Lwhpw8DyR+KwnKOtZkGllZHv4mbHZSuNv0j/NAaKbi/83tYDSgOL5nzb x50fm0Ggi3JynRPUyCQIOY5epTkjQaNqy21fvdloWaBPDcs/wUGsgodNnao1iEAryNDu1D CxZcmFYQfNCP3WzAgOZDbPq6QS+JC5Q= 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 49NKcaVB026722; Wed, 23 Oct 2024 20:38:56 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=GoV/SXOqaoQJF6Y962A0upUaI4C5tg8OVEAFdKWNTU8=; b= mDLV1RSFcwAqq0lHdBl8LBxAJeqYvj+hjmbIEIjxiO5cOb211FyG7zHA6X09W4pJ Mt545YKd0HNS0zAGdbMbXjdT4J3Fu1esPtrJ5Qj6x0k8elW8SOhbr14cQ9/GxZge XNh8wg1zxG6SQ4b+A2CSFkykoPIPt2F2HsEBAwXhJ4Sb0NXP26os4lME1p9EOXJ+ rb/4gUuewS7J4b4JTOy47NFyYpknKiKM8lFKQ31WgrfvjrXDSQr7hzVHKmPknlYH mLmazHk4b5rNSERD7d0191yyb+amxVztPBHJzpuQmTEQmsGJG9AJbDoE3PI/3gSX 802bH8QnpdP6PEgHUBonXw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c55v14fv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:38:56 +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 49NJ8ndL027496; Wed, 23 Oct 2024 20:38:55 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2042.outbound.protection.outlook.com [104.47.55.42]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42emh3bjwp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:38:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=L6YR/W7+tVMaZTrxwZKJRP09virM6kTQGbGO32O5li79bMi44RQtiQm9Hy1Vlbo3sC84nThclgr+dqnm/kwCwhID/5pehiV03+AhCzrQgWadtI+KuL5RoSvaW3cH7RBiyYqzKX45Y8s2Rys0R+pOLjikb23PAtS5P6XMKr2gvnu5vsCsL9TRsOsGGVppR2S6HMszTcPVT3rDao+r/1anu8H5ceNXmk6HePnzFw8cZr6GMGUTkx+UOoTJ+be1ecf69XxO+oP887w/32EdWDlvjhntrga7ou5C6fMu/8xBT8srnyKLpFACfyMAvSqvagfsbSRkqs79f5J4BeV/pXvsag== 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=GoV/SXOqaoQJF6Y962A0upUaI4C5tg8OVEAFdKWNTU8=; b=S56PHo9kk3XqtuW1igiW/eFZxNGCihVFzpiTJjiN1ti0gz19Ieuju2SGaLMWbGqRYcPnygJ74zMhlGxMkOOttiLSZmwFfZLjDlwSI8Qbc+q6yxBvYXJq4iskM2akhHNjqGG6DyOgpY9+qOYNfAonCCjxtDKLPGdPblXmkZ8OFUVETxkhUqts8pGAyMwfum2PdFX0sBCv8tuxZ8FMPNHA5+3HJeNZtgkI4Rdjfw8pN7AwCQPXZa6gWrL5ITecFNv7Kf7kH033mGOe4U07j4k4OkpSJojDVPjI52c5UESeAor6Ev0PGKW4/yPDIpcIda6r+fawzHsLzvcPrPpdEy5hSA== 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=GoV/SXOqaoQJF6Y962A0upUaI4C5tg8OVEAFdKWNTU8=; b=ncxS35y32JBpihG9WaLuv0ymC4l/nkwVtj32Sy81dL1WWA+44B+ijyfNSbWYGeQ8vxiTztK6O5DtWveO2BY9XJ0ig16QwUkQcxASAmLk+T2vbeVpmTC0eUVw/9L4Dv1AfZa/samrcY7nzeCSomr9rTbGniulTgChqHnNwllqLyI= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SJ0PR10MB5833.namprd10.prod.outlook.com (2603:10b6:a03:3ed::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.17; Wed, 23 Oct 2024 20:38:52 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8069.024; Wed, 23 Oct 2024 20:38:52 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH hotfix 6.12 v2 1/8] mm: avoid unsafe VMA hook invocation when error arises on mmap hook Date: Wed, 23 Oct 2024 21:38:26 +0100 Message-ID: <69f3c04df1ece2b7d402a29451ec19290ff429a4.1729715266.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P302CA0012.GBRP302.PROD.OUTLOOK.COM (2603:10a6:600:2c2::19) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|SJ0PR10MB5833:EE_ X-MS-Office365-Filtering-Correlation-Id: 4b27283d-c3df-483f-f08e-08dcf3a2b479 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|10070799003; X-Microsoft-Antispam-Message-Info: 5FMzz/agnPPgTvbwQPjJjvoTCLL02RKS9WTSlDJDr++1bRblfAge84g4xg3rWuSoDBs+FHgo9lfJ52CM1COyc+V87TT2OrBns/WPDE75Ylh4KOZ+fmq44DqtyoacgSxJxd23G1khMTnUGl7cyU7jVBQzqBUVZn6n87ykncRYm1O7MmCjxH2pbsLxPrSoscAUWpe+HilBQy9Y2DjNHZ4U/hPnaw1VVBfcsdltPZ9KoBqbZHtv1XzJA/v5SipeUeSSlMwZVD6GnK1fobd34xsbYy7T8rFzaeBWSzDi77PdSiIImo/hXj6o+cNr4a61WzfgEMNGh7b2K+w5zb3tmqfCwzv7JdZckSlG6LGhdvztzu0hs78OAu0BjUgKQrAyO6fOMvcXp7+RtGRtE3Wf6BpXJlu04OR0jrNs/6LtQ1ynLI2Au+aeVFGrhQ39h4aP6UYLRVD/+pyOacifjDEcSBVgmDs8v0lYUJDTibuu6a9X2itlgzS3yLPSHkS+k3oTb2FBJXlUzjUULuYltTRDMTBmHXPpINlwBkIxGaH8Crtke1NhKddL5WBq01M4FYafAB+1ktayJcPsJpnsIyD9Ms3C0Zjfihn9ch+ooG3gxxu6T1OoCtl/lI1lMrhDn9sl3AepFIa5IwAGArdnLOuQpzW9osp7ZZROeJ8vBEAPBFf7VBCDHn+b/8gIuq1FsZYND2dquhEKtEBYWFslk4VjgbjLOt0OFoI7Zry2vVdqvEvo2xkq4wpW9A/C9wv+wEEU+B8g9hp9p4Me7j99ac35GAcico9VswOiTwS4eDtgs4AYDqSwkTsjWd/bVCGrbp4Mo9EbQ3t3KDDbivbz04/3XQ3o7OOKlqzmQzHJAFCUVwRgKAzjJ1htDyLg4WDn3v2Jcm6QE8e2+/FZ5+SjfhcAJT9mw+BqEr9w3MNAQM/7/mcorkMaXnb6pXCogwJ4qtQj/p3u1TWMdpSJQ2czE0jRKoV5JzWlVxK+vn2qnu52l5ZPLn3uuawoYKTSDQoeUqGtNQXk18qKiG+MgxrsXf4QoIsRJw2Vvfjzc1mct4+LtYD0jj5DZ9lnpSbsHH5b5KP8UxT3wkg+8U0SPE/hYsFjFzKU+8HeXz5efNanqKSb7ZXXyrhxE6fH7k9ueYS4/QCsHQfyY2s+Pr7Trix1qX5casA2lyX3LTIyHpmnbc55l8iYzNWe7MGjFfP4Djs8w7tztHhigHkH0bcORD4PY+bITZljWT0elkTZZFU/E5xR2lrBaHdhxX2ee9EGdqyrRwSX2e8aaegY0uQCYW89Rm8JlFfTIFFL9XFBn/qghXg+UYK0YTQVYv6f6+T8ceK4nZQWz8LG 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)(376014)(10070799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZMQ1Gvd6zCBXXxtzXig2Frz3zU9AKhAbnEhHOfc2H/iZ95Uuze+EX2IX8lz2Nb1OL+uS19rMEA/Uq6+PW9dXTCs+NE88HBUSjrw902xMBYtaB9bwGnmDdL1V6JxFAPMV7b+nlwtm0peRdxj1Ir9OxGSaOJRgf/9Brie2F1JLswFc9IWgtnzYJfDDFTD1Jz47+uAbSgit5OSPA4C6mi6qGVq1pj7wRkdpSShlEc0QytggG0E1IcFITZa96kSvibGN0UbmbjF7WPw+s4zsV464L4vQnco17NzMcYOla8dTQrjJMp7nLt4SWbOJpfJEugpgI5rKaDxOr9NsSD6uxJ869/LZXDkQLgoV6AOABKN72iiEydxzBPeXCG5lVF5as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Hli3kvAwchk2v6X6MFNN2Bp8kE7CThF4ikisqR70I1IHa3oGIvuLGuklQo/8+lmL4DdDzk03uPmWlvCFZj4582nOaQ9uxeOg/9v8tK5MCsiH+Isn95/Vep/giMOQ+Rg3lXYdt5MT+wCmDN+VmccrMmb6kaSiWY8B+xiGwa4PK92rLIL0orvVj2pm1G9wzAvHefOIk5Zfxt42TO22oOQbVO6tQ6yIpW40UJvNvvFRU0rg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Aou/9qqGc0ReEn9gOXVADm31mcSjK85tauEwTvkT6x1Ywv/Z7ZJDn2espdSmNpbwhSJccawy6Krvc1ChCOm9/nnUj5+zrKpPakhEEq+5zpcy5lczvudacdzi80GPab1i+oaXrdaf8z6vYDRgMLwvPGfr8S/XTLSiJ6L60iXc203q9uRC8KSda6/92dSHYD1+/dD+Dj2rExUfxY0CG8HDZhDiR72bWpdsyY1AD343G73ssKqYtJKMuzaiLgttvt1INNS1o5KMX8R55ZAk5xTCYlz1yMkBhfUpkUEKMCEVGCZ1jXE4X1RtcA/mNX1zIzb9M1o4w80pJHr4OLIkEi74q5t4q64SwlPKo5WiTAFwW8ZXxaMPKYCfFfw7aj3Z3AwSICHkG3Jap5u+F3wqyogzA07JA3J6bDLjY6tw24ngd/vb13Of+okoqA44wsolyMMIBQskLMxYFNvjkJWZG2v4DxazNX81UVw1sgDWIa2C/497GhORFamrsYTN2QSqflahJ4chbltjrpmJANmkKnYxwZ2vktbAI1FC42I46yRVYnTuUM8RV7Gqh+sL+HrtEpP5r7V8t1wvNKLhJjw1q0X9x+JSTOSPVYaKq7q6ZTYeW68= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4b27283d-c3df-483f-f08e-08dcf3a2b479 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2024 20:38:52.0661 (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: uIA4w2DI3F9qNt+lZNffz4TVxRCEz6XXtN+4FM2FuiLKuMOCANnJNIjZkypxE5ydWJNPlVmlzcxOrxhc218pXulGWx6P86cmPVK1aFB/8DU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5833 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-23_16,2024-10-23_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 adultscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410230132 X-Proofpoint-GUID: 9UzNX2otY6yG9b7VdoE1gg2T7uVYINpX X-Proofpoint-ORIG-GUID: 9UzNX2otY6yG9b7VdoE1gg2T7uVYINpX X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: E91C44001F X-Stat-Signature: 77bepkowxgww4a8isjaiarojjkzpowib X-HE-Tag: 1729715914-807604 X-HE-Meta: U2FsdGVkX1/aPwlUfz6JUz1lBYsQSRB/48VF7GTxPUmom9/fkhOqFLqbou8IR6sGHrX9LE4KJkN84+sWddsZJmsTnjFabxqjRk0tdtTcMc23/xwrqnHxJOZdJA0R8/3pCJNvR6iu/wBqdazs8HGmc6PlCAbif2D9cvXJ008FEFcD/hcK51Py/vufQgdszmGz/SkAAksyVQ+W0qXa0eJIIermL2B+C1KPdIVVf/ArNLOkx77IMJTPwcAOVB7d8f3LMlcywGo9VMXcIrf57m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zMjZ7p6dvc9Ry0K7d3rvW0U9JLvovqckaCpihy7ec02EsZdy0oF7hpbozTe6xanfb+SgRnBfMW57hynl7i7oXGRonLoBwFyxke4jilHqqg5yAmPXeLxuMzl89OGaDK2y0wpEFSbA0Y3EPBygDN8KAUxL4vw0RIPlesiPYFs7aT9L+B26+Z00kG94h63uAsWa1crEX2yN7+Pz180D 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: 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. Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Reviewed-by: Liam R. Howlett Reviewed-by: Vlastimil Babka Reviewed-by: Jann Horn Signed-off-by: Lorenzo Stoakes --- mm/internal.h | 27 +++++++++++++++++++++++++++ mm/mmap.c | 6 +++--- mm/nommu.c | 4 ++-- 3 files changed, 32 insertions(+), 5 deletions(-) -- 2.47.0 diff --git a/mm/internal.h b/mm/internal.h index 508f7802dd2b..af032e76dfd4 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -108,6 +108,33 @@ static inline void *folio_raw_mapping(const struct folio *folio) return (void *)(mapping & ~PAGE_MAPPING_FLAGS); } +/* + * 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. + */ +static inline int mmap_file(struct file *file, struct vm_area_struct *vma) +{ + 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 = &vma_dummy_vm_ops; + + return err; +} + #ifdef CONFIG_MMU /* Flags for folio_pte_batch(). */ diff --git a/mm/mmap.c b/mm/mmap.c index 1ba0878bbc30..10f4ccaf491b 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1425,7 +1425,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* * clear PTEs while the vma is still in the tree so that rmap * cannot race with the freeing later in the truncate scenario. - * This is also needed for call_mmap(), which is why vm_ops + * This is also needed for mmap_file(), which is why vm_ops * close function is called. */ vms_clean_up_area(&vms, &mas_detach); @@ -1450,7 +1450,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if (file) { vma->vm_file = get_file(file); - error = call_mmap(file, vma); + error = mmap_file(file, vma); if (error) goto unmap_and_free_vma; @@ -1473,7 +1473,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_iter_config(&vmi, addr, end); /* - * 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 && vmg.prev)) { diff --git a/mm/nommu.c b/mm/nommu.c index 385b0c15add8..f9ccc02458ec 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -885,7 +885,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; @@ -918,7 +918,7 @@ static int do_mmap_private(struct vm_area_struct *vma, * happy. */ if (capabilities & NOMMU_MAP_DIRECT) { - ret = call_mmap(vma->vm_file, vma); + ret = mmap_file(vma->vm_file, vma); /* shouldn't return success if we're not sharing */ if (WARN_ON_ONCE(!is_nommu_shared_mapping(vma->vm_flags))) ret = -ENOSYS;