From patchwork Tue Oct 29 18:11:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13855275 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 3D9D3D3A678 for ; Tue, 29 Oct 2024 18:12:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1F026B009B; Tue, 29 Oct 2024 14:12:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BCC916B009C; Tue, 29 Oct 2024 14:12:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2A6E6B009D; Tue, 29 Oct 2024 14:12:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 803636B009B for ; Tue, 29 Oct 2024 14:12:37 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4759AA0362 for ; Tue, 29 Oct 2024 18:12:37 +0000 (UTC) X-FDA: 82727434692.11.E9F0304 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf16.hostedemail.com (Postfix) with ESMTP id 62D5C180005 for ; Tue, 29 Oct 2024 18:12:09 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="oOw/oLtD"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=s2nGUf9r; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf16.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@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=1730225378; 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=woqMSvLgvosQjv/MfE1WcUuMqxJfVahDJ68XrgLxxKs=; b=HqptScLTECMk1pNuVxFY4cGOIGqSAE+7ZZF0dKl2MjyngRTVVh0w2KlrarP+i7FOQ4djFF n6nrtY79dAoi3oQF0f/oOpmz8uiEmZcS4iU1VqclnWvx+hfvNwvqOxJNTMOGPKTy1X665N F+31Aw2INLth82LeCI629EI7UQyu/z4= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730225378; a=rsa-sha256; cv=pass; b=oDTAkLoZUIRYbIKqQiC69fCxYf1QmUrfWv1oZkvdiwZoUhBjHcL+yVeges0J2FDSasw3KW qEqs4IEju9iqNc+W08uZGBQbME4Bb2DW6vnFS0qXw3pZBHXu8Mqe2C3QY/MM+JDsUEW56D CYfbokKzMWjXFRrb37IAnPL8qWYwMyo= ARC-Authentication-Results: i=2; imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="oOw/oLtD"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=s2nGUf9r; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf16.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49TGfXGC004044; Tue, 29 Oct 2024 18:12:20 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=woqMSvLgvosQjv/MfE1WcUuMqxJfVahDJ68XrgLxxKs=; b= oOw/oLtDddPvg5UmO5QvX97VwHKpEMPEND7mRWBBTHIfz/UF5CXI3N0W9hM17JE4 NIDexyLlQ2picSNo6rPwqr05IvmH9uJakEn3GZwf7a09tjsqS6Aj4CQSUCaOdAep tRl3iS5YyXu9e3flRCjy39Z0ld+G2ELrvVX0//insHsxS4N4EsmOmAstulJouBOn adChwPoWUBG6dvRsbgIGb7hH4aFShOYzWjfrv+n+8xu6xkNkjm5+JBEKpx6bKttQ j6ptyGw+9Wsvdju2/0T5nbglwFDUqBsugWEUy1Z2qomx5Rpeg8UTherzXrxRnj62 rm9ceI62ESvWERC17K0bQQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grgme9k2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 18:12:19 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49TH0i3c010118; Tue, 29 Oct 2024 18:12:18 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2171.outbound.protection.outlook.com [104.47.55.171]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42hn8x8ww3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 18:12:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rX7MbvU6+YOK+/7nVvglQNGmSaYn8vrdH+opiSwKJmbS+HGiCue5wttqTc409lpLuB2hu2daaD3btLwxmbJIoe/Y+SzYGesUkAJ/vzme8bQCi7TdvuGpzK04e6dJ7gYpW8b2ITF+esf1zYMSHNXB4A4PHdZAQY1sYacDKKCFEHqVtVFuXf8wnXuY1vFrj0VSuqXnk3YjPOqdS15L5OnWKcyb1e7Ht5j2Tc3qJlgKkNmxoKjuffYqnrMa3dalmnF6WymaMfKPLuzxXjf3L+oeCDJRLHI4/OVOdeB3pk7IVxU919+74o9hk7G/W8X6RhhOOZQiftPhvi182yLTsmMOHw== 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=woqMSvLgvosQjv/MfE1WcUuMqxJfVahDJ68XrgLxxKs=; b=BRCMqNElUdSoD/4mKgk4Ta+TtO1meSLsU2dGGB6SxXXq9LkCZvOoezTLZyLt9uPJ51f7d4ySvZkGAJPJtnNZl7q3sBd3UY7v0iEZ1/vVALI8CJSJviWL+3KVijGnnHnSYWKFzz/O9b2ccxo5wvbtlaeN9b2iomoHkmFXyaCx0AzssDcwPRdcB/Cd58mBoPzmFcadDUxQi+j7agGg4u+hkADS75ekpeka9jTnyiAYIveDLF/Gs8Q5oU+y9GSdXj38SGXvXQ3wYO2b4OlObEJ7ueqk4bHMgxDY9cdPzs77v9hP6i7tuyXOeAfw4ske6gcDQqcPnPuV+BZId5ZKvmTopw== 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=woqMSvLgvosQjv/MfE1WcUuMqxJfVahDJ68XrgLxxKs=; b=s2nGUf9rEuVOivqz3aYynzenZEYw+3cI/0YJKm8MpaORRu4egZw/kqQnCI8JjCga7kwxPYjnJvfWlaHLTe3FtUOOEqCkF8fd+grIWnXUZJcRzo9nE4AkSeb9UUFHAyXyJe7RAz7piWx1qMR+F/7Ys01BcY1fgVfadxIsYnTu7Xg= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by PH7PR10MB6966.namprd10.prod.outlook.com (2603:10b6:510:277::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Tue, 29 Oct 2024 18:12:11 +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.8093.027; Tue, 29 Oct 2024 18:12:06 +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 , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson , "James E . J . Bottomley" , Helge Deller Subject: [PATCH hotfix 6.12 v4 1/5] mm: avoid unsafe VMA hook invocation when error arises on mmap hook Date: Tue, 29 Oct 2024 18:11:44 +0000 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0477.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a2::33) To DM6PR10MB3372.namprd10.prod.outlook.com (2603:10b6:5:1ae::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|PH7PR10MB6966:EE_ X-MS-Office365-Filtering-Correlation-Id: 194d5e32-2493-42ec-11d2-08dcf8453199 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: bQfAxVPzYc4eZ8KW5XCFDbdX/lqqONgCAESSrQuE6L1aBFFuqHcxjZtQeuxcsm6bfEkU6nPUx+P68zDp0AJXc2/zcFjtGUurGkuwZnYAiukLaScjnsHHz2zpNzn9h8e9yhgR4qXhk5VleAV4waTsFa5mQQ2yqja0NbtK1Wx0kGNdRSFmMEK0sJKl44Ca+kxMigiPT+rnJeuTCOLBdRVon254VkKeDVc3aePMLzFO9awSwDwcAtEvdaOUQVRLtS5hqQk154yb4OroXAob87Sx4xbBNycJDrksOVICdDLGjF66XV7GQ9vLBlS4DMF1zbCxDdbbgTA0lbZidtBSgOAitgfGIvSZXR17lPr3N6EJTq/jPJ1z1upn4Dnoi7cpV28U63LNW3rhPEwkG7TfTS+iTb8Th0k7sr8Yj86JbldIkYVC+I5snXbZsF3g/+2+nohIQ6gqdvpL5yLPl/ctYWbk8z5E5pZyMKFk1uJSzd24iZjSuG62WEOyErBsYYcBTb3cyM5+bP/PKjkEEvj78yAwQu8v9Cotpk5tHRe1O3QtCae8LRK1PooGUxh0hvX1iCgPUvNyxUGgIvjqq5hqJApJ4lJMFdj48aGU8zGqATHyi93xgrJCgUJ10ifRM1RmWiAez/Ogm+Eotzt0bQw+558wbow00hqqJrGERYAktJnoLzaBDw4dLAzUWgVxrEUmNWy0OQ4RO+WCGayUfiLe0BgFXiqRTijN/w5QxhIWOXJ8a9C93bJ/KC3RuvGHIUn7O8PI5bhQr87Ys0tgiJukSY9b93vm/b54/IdZSCORllonkeRMN3pwid+fWRayi/lmImaYToMrUQtSMxzQv54cjEd7VAbB5grgtAhQN56pcs1B3pPWgaVnpwZxHVNPbIEK+RD55edR30jnY2kdj/6gGelzODMm4nvL9IFLr91Gl4Bunb7XSoI8wa3Vmw/KM0i99h9crB0xrhenrxarY3TJ6puxE8xuM8FwSo+6WQsvqgA+JATIeeeDHVq8OslD7gxIIrzTREsc7J/oPSV8sXgRRDqBPmi+gv8RHNMiEwuCsaziA/VYpG5K0FS2Coro0lt1WYh+bpVF7K24k9H+OxZlgxTpff3i7wvzVoWIbRoiVzxeusDG9UX1jUMvwRmoyL4j5su76GkzSE0GmVWSzeVXD4ATVPkLtRgaMfaKdJ1RH2gEYLK7ekhRv8e331DDerqr5MEvRGd2IGf4/T8wwYuXUKpm4MABP4uwASqmr8FcJmsTsCUWZg1JS1Ag5fE+2aqN6YonkzHZ09yOvRf4HbzSLoHrfEEtKTqALkRy6oDigj1EhVEmqplFuHbkUaZ//drYQWrx 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)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NJa4lLcb9N8Z6CdwaT/ZPR6hgkxiXEhuy+OfPQvWMw1Wu2eVDWs6Vpw1U/raMJf+hlxCQ4hJDj5/9HceK1dXkffJeYYvfMrcyRIkyTTm2OufDDpC+vXggiuBUO3dwtHDg1aWGcAkBR0U3Qrgq60FBX1lBRxuVv/OEjn3MzdAjCWaRJilQk3yNPRsasKEFL96VuV/Pos7wb96Hm8dVN2+qnD70qz7wwSjEV+f1QnJDuN5yZu6xR2B197JsEde8R+X2Vzbtq/PJl8JlPHnZAm9j2amBH1k51qjjtC2daz4UXK9Hcc6yclz4l3FUEOQnt7xJYE6Q/n0OMPTQ3WlWrv7ZYMfMHSmjyEufzOC9iJn7TdmCAAlzfSNs5NNx+9krqhBoUlIs6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IL7XFxD1S00+5JNPIAXNqpp+1jCVG1P1n5CLLgP3Mufv8JeMAQ5+dLS/i9bts04bNv1IejbBQxvxSk8tjflLxurzCf9r+zNDN6txygenkugpVuMwTt/Z4SUmgZZoV8z0377B3LfA3Q== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Jb9YVM9RR6gOfagxM9NROlWcGpVaEqIxk/pA2TsV3dtyhDW23gw00R1Xxv6o0TPWJ+xb0zhdWYbdwx6HxFIr9YJLYB76F4dkhmKJLLB9M0lQb0RfNHQqaeWYC/XLI9yhbtvgYO+0jRhnwYMnx+uX+vHv+vfXh4f+XLAzK+h+1ryEg8x+Otcdefroe7Gj29z1hTGDj2WnFHYspi5r9+MDeDXCQbg7qjvxuUloJFKA7/zqVw+Qk73h3BfvDZbuaQwsKeP1+jtc9vcfyI8GfDmBNZF7vDMy7+Mt04oo8HJXPyB8mEJIDFurqsE2LzpGioELVPCzdK86XD+qkiYYphHTjRO4T+4PltQfHV0GW5x+J64sLY/S6uxKAY9i7FEZd723icwnpU1UiNhxnuCHrVf7Is2XtqVysa7CScvfDesmSULkj1XHM595C9Wpg92d4yFN+/SHLlkDwXVn0gcq7cuqM14nKMUAxi6/BuZblIxbkH5djy4HvxLLwEYhcmQ4uVzBhyn2b3VQ/xqtKSWHapTZU2FRblcu9/pRZgdACGhDNEYUdXwoNtqFePrcT46iq360nLfojqr7fh1RAsUn+EWbR/RQ/oE9BKHbB9F9n0qxl0k= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 194d5e32-2493-42ec-11d2-08dcf8453199 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3372.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 18:12:06.6439 (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: 5xJbjUIugUDVHmzsE+DItTqZOekyKatPTNw/UyE+5/ThqFsd2siIBGfXuADZom4X1K0GOYp2Hg0QqQobdingvfwYIlhVTiPXGVO1eTfYYH0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6966 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-29_13,2024-10-29_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410290136 X-Proofpoint-GUID: B1eScH_Bx0LjuE6DA4G7ap2Qg8T_BSOM X-Proofpoint-ORIG-GUID: B1eScH_Bx0LjuE6DA4G7ap2Qg8T_BSOM X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 62D5C180005 X-Stat-Signature: actcpw9d7fhx98kyp3htfyw6aeupatsw X-Rspam-User: X-HE-Tag: 1730225529-400616 X-HE-Meta: U2FsdGVkX19ODhig98AGMDZcuJatVPnD06N1r8P4xi3KucMFHv3BMxn0p5lojxh8qpyLrBkdqUpumGP09PqQNaXqtafKgRty5ICKzs5GEcL5EXMbfBRIEpW7zjlsbsTXBZQALKMmOnEH0Ww1KZ3GAukZ+a6tYcfbLPfub/cJTVfiNZiQploOZ6YMRhpThRAj4/gYniwhHhzQ/f3JHDoQQyTsif4m+rI0xNvMxbBtJS98rbLToOYBsqbdPTtbHXdL7P6gkVPkjwz5ccZk36upmSWlKVqFO3RHU4mZVhDRZJHQYnhMNYFvbxddH6khOY5SjNyTOkB41eMrkDhwO4FyaLV39BE5WdfEhK4d6OR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6soj0m9XSieHyeMPh3ZqDOZIHEGBREs1Zz2ideXXrlIRR3ZJRyFv6a1TDd3//u2qLg8h4iKXI1KNp67v3olGtXMR8/w8D1YwJ41iZRIO6cSlMA== 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 16c1f3cd599e..4eab2961e69c 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 9841b41e3c76..6e3b25f7728f 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1422,7 +1422,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); @@ -1447,7 +1447,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; @@ -1470,7 +1470,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; From patchwork Tue Oct 29 18:11:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13855276 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 D2D55D3A67A for ; Tue, 29 Oct 2024 18:12:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6514A6B009C; Tue, 29 Oct 2024 14:12:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 601616B009D; Tue, 29 Oct 2024 14:12:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DF236B009E; Tue, 29 Oct 2024 14:12:39 -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 13EC46B009C for ; Tue, 29 Oct 2024 14:12:39 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BDC6E80380 for ; Tue, 29 Oct 2024 18:12:38 +0000 (UTC) X-FDA: 82727434608.15.DBF6166 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf19.hostedemail.com (Postfix) with ESMTP id 7A60F1A001D for ; Tue, 29 Oct 2024 18:12:04 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=n4UZjoS9; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=p42NuNDp; spf=pass (imf19.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.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=1730225500; 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=n/a5qI/qPIV7EvCPopGmVIpb6ZM0YGR4l7zVgmrebNE=; b=CbJ7lvlW4eLH0dgDA+2F8ATciNKDIe/UwD1YhrU/dd3JGkM7RLf/hKfnIxl41XngwyNBJW iaVifKKOs0HoCngG8sjL6HStb7HWaKb+qtV344jSFqAE8LwaJzMfs4X6cyPAPNH+NdIqVw wNugFmksv6xWGdn6ccTJtsPBX+W5mug= ARC-Authentication-Results: i=2; imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=n4UZjoS9; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=p42NuNDp; spf=pass (imf19.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.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=1730225500; a=rsa-sha256; cv=pass; b=gJL8J0iuMxu5P8/pDmMLR4MBaBj+bE+enoQMG5AqNOXDARJZC+Sf7rp9GzZQOflwpUo0x1 zDi8EsG9PvD26EE7YQurx5a4m8geCJz6oT6bBxc3ni6YVOccT9pcGWPKbmTHwMZzFknJfH zei2qOkoaUrNuLbWpHaygXFQnKfIt+Y= Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49TGfYZe028562; Tue, 29 Oct 2024 18:12:20 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=n/a5qI/qPIV7EvCPopGmVIpb6ZM0YGR4l7zVgmrebNE=; b= n4UZjoS9D3khq/DjBOCIyJIK6cJTi4yu5yjMUNj6u90AIc3M4Fc79eWlKPFfdAyc Nbh7mKgv4/iGqXIDXvCJKoWhJvPucj7chMw/Jq+1bXPWeJJ7+aNMKHhouPv9TTdu ArBq38mKXFrMvqUc247dIAZyUXO7ZB6XzcM4mZvfF2IQPaeb40GOG8LshCabpu29 52pGZUhp9MvtvMNYMmlk+WpvDXbbNmazk1be6t58gRCOj7TMgg9SRt1vfp64+KYy bT9ZNdtklUBupfMP4AAoxC2b5Ug49CXWeRjQqh2hadrg876CHTarGBznH4G/5q6k HLH04YuYVKAEjxFFU+B4eQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grdqe5xq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 18:12:20 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49TH0i3d010118; Tue, 29 Oct 2024 18:12:19 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2171.outbound.protection.outlook.com [104.47.55.171]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42hn8x8ww3-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 18:12:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=R//vmjpoxzcvTXtvSLKyF61VLqg3wAx+5aXRmxYy5JIyjPYJndonD7Mx+R5PFNOWsxqcIWea7SHxPMcPWAeFgQXw5xlx+MX7BhSXh1VTmpZ9xxdvtX49/tIf1/JCLuGeUmWwu9oh0l9xOrBQbqDiAuqRyicuk4xjN60WZK7Uco3ikx6RSvCLFOuBIqAgfRw1Eo51IlZ0StpNXPEB4Ab/9KH+30HI83dWnlhs5sTBs4ATG+G9LhH8/Yn0ROzg6lvJ6NJ1YrSLHfW1lnBgauhbPbZzs9HKbdyP1/EH2rpSOtXlapRkt/+ZZ4BX7IdbYzm2v+3ZjdWmZkCq5JDSeISbqg== 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=n/a5qI/qPIV7EvCPopGmVIpb6ZM0YGR4l7zVgmrebNE=; b=TjKY8OmVryf6BSNSFQMVi67c5XJlU5joWLS09vyy3p9ku880UGSDtbS9AySh13keIRSdxGxvDNTxT6/5Gka9WnuXnssxTOY6uRWRRNBy/WtTi0gXATd0f3DGB2HEFoPn4z3y/W1KiEobGqCRy5AQWSpjFrAA3SUEUuy4XimBdepJgrcJicjegITdlOtBGWD/l2wThW+E8GTaFeZL4WUiq7FfdH10r1n2zYm1N6stcXakPSyZ1qJ7JaDbuiHiZnTEJdlIw1yUDx0ic0phdblGTZ/D5D7paebhR0WJECIxSDv8t+Z/TcmTYTvtfA9h1elBweuX1Zs1bsNodfD57WSPHw== 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=n/a5qI/qPIV7EvCPopGmVIpb6ZM0YGR4l7zVgmrebNE=; b=p42NuNDpBm35T/Hu403uX/30VEARByAEhFTgEE8GPcD3zUDJF5Q+P2TuB7naQbhqWSVE2UMWDESAUFAaH+ajPxMGpY/UwWZEhdWqhKds7qXNzl+hd9fg/1inl8T4T1b028y+S9rWpjqUSES+zuJSyC+IkU4gFY2mCxZZjOhLiXk= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by PH7PR10MB6966.namprd10.prod.outlook.com (2603:10b6:510:277::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Tue, 29 Oct 2024 18:12:12 +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.8093.027; Tue, 29 Oct 2024 18:12:12 +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 , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson , "James E . J . Bottomley" , Helge Deller Subject: [PATCH hotfix 6.12 v4 2/5] mm: unconditionally close VMAs on error Date: Tue, 29 Oct 2024 18:11:45 +0000 Message-ID: <28e89dda96f68c505cb6f8e9fc9b57c3e9f74b42.1730224667.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0546.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:319::17) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|PH7PR10MB6966:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b5f6cf4-72fe-4f5f-4ca2-08dcf8453561 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: lVTKyn/UniBN8nhqViHeq6eD5LQOzvvduO5ASVCOCDd+k7EkDp4Kh6sHOLNJDAk7ICHBpXpvFw+afw1MH6ollc1k0pNFtiytni7y55yZDfoSZ7wiRE40DZeNNTeNHnjF91ZPXutmmDYTH8XSrSTEiYeY+OZ5fYJXnDcQiKoaTUF6x44as3UWWyKI9G3+Pg86y+96yLwIpZI+1CKv6pW19CBIpXwBuKO56LILvZt1vaO6bwlo0oPIxPBdI9HWKzEmnglNx4Z7JS3jG3Y2NJyPEMPoKz4U9NXXjWiGjsXbKccurWdZs0GjetdBrLmiLCE3Rew+KngPCU3s9Zjl4rXetQviUIa+gmyDFkGJbzV3p8VefzfBF99YmGpVmAvmt+MC+4wQTf6Vb6UNW5RwHJpJ1ynK4cweU4IqaEP9Pu/ukSejM0ayxt7VkTGCVQqpESH7SzQeLhsVlPcv+3xmTbP45g5YJNZGo7FzuEwTFBEy/rW/CQIiutz3DCmaZTbfMaAAT/UMXqKsEP2wEB5ZE8mhVgpRnR5KI02L1goXhFYQA7hF6FOhI/dl8DYZeLBnjHH2KUeaHluBiY2MtP4G521M6ZeLQr6Vdv2nHo46mpa3BzGKJk/RrWpxlXJZA7UYR5DzrOKjw4+AgKo12wukf9u2mrpG7M1aje2+CaeveDTpBCFf7xfNsnQ/kVgUVPzoutoZ4K+NMuhRhRH6WnvUsZOE6/+F+0k9TsDkObz4q0hsYY+DkYPqIf5g1iQmwfAchoi76sYSK37YQ9J3cHv0qRdCuO9lQsLzRNgXX6L8gY4ylZH9sSbYVS/qtk8fj1yvfJE6keA6zRoFrPP25at9aBssU8cwByWE6CrlLb6f7oNWqcTaVIrkEH2lBKfGqYNZ7Yb7CzJfVXiZHV9NkG3c3BppIerpXsWwGq801H71/5fn8nz5MNbfuoJrEeyCiodLWhtxbbLjgvQyY6suguSgsOBYnNhGgKgr6wpn4LSFbAs4ySNaW/obbUiZ1sFTEglWRVY1MTg+rMItoiKGuZaVoat2ltWHlNKm3CZQIOv+nQBDvxGkCkN5Dr5bAC5JGVF5FmGQJBhg0SGKt3uUgJxHVdifSW/OoCanPxgGK2wxbw8dpv1yUjcrVu27fFFqTUUtuNtEZ2XyKVhFQwZgfXStADL4eEbRu9rXf/kn/VApwTAnuwQ+8gc5G0N0GrmG2pMve7mR+cXkuUoRks78bCh4ynlremVfta5HHwh8bW5pTAG8+5PE0x8WLGK9hvwMKrVhdK/xaIXg7Ly+lirjP+Ji9Xs4Sj3D51QIwD51UTiOYIC6Rbt3wgPwG/u9OxOP0bLqEOx+ 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)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: l05g67BRhYr6lt36+LCPE3cwtFD3Kc1W+OF7kSPhVuwNjpAvRmU3zFUvCahlHOlZGnLFHsELsBD3xPuqmClPs4pUWmTZvY9PRY7O50cPjPzMAe8iD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DbJplYLhyFOxDIFgo7un07oFztQJ8rLuAdha5kKbIHDRc5w0KKB8hOm4OhHTanaIyQY0K6v/QFJZMVNYY9S7GYyUf/3wXiTCSedFttLau+zjYikhhQV7oSktPISzYEJDPr0y5a2wN9TKcTMAskugllSXlBe2NeOCZITXzhALLjAuZsnpKDjLZY31QfpwlbN/JEFUdBoB9LdENwYH7nTp36FZ2Fy2Y5c4btT159UhAKDhe6/YywIKJ5QJm4JdTeBlIRuieNsc1vOtebB25eeSNRqYxrFMBccYAsJvZjLg6/qsWHSxoZu453FXiGUv7c9v03w5WxsknGOY1ECkV8xC20imtko0Rp/iaUPAzF+Iii8d0GLer7AoM0cET4c5sDQN0A8lnr9FcK+5z2TJTZFMen3JGG6cWVtXwOmg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: efByVV7VyxrdRD/Bvcshi/5QZ0E2xRaNgxYJK/JisTyDpLCQ78p7qa/hwWuUM6k7v3gAWVxIK+d2F6hQNGb7+CNh5EI2tX3JcI2USwLFi4KhVB10mWLWDCvJ1f1z1kjzjsjMzgcqph7W2gY287pJq9NFn2L0zkjE3H3rxVFuXcct1JBCoQUW49dhFLObvvtAhiFX1Nl3+1Yuvtzy+IjPunobhFrPWIG54MJMri21aj50I5hDPIBk2hjPP24jCAL5RxcTYWpSacbFPsKBanRILIVJuKX1OKvJdCvyewr10yNLVW1iJM6lv54ltHlbHvc0oM9eGijURihJ5xKq20tOUsUxmTWfeGiokU1S5pUs9SkaT/ms9aH4rpK2Ozj0HEJ8qpVhtVZwH1e1EbYYwp4/bTCxKsf/TC8dk7MIGCmQKjBO5QGTsyJyoVXYp/j/BXsSmXFxY34ufMC9nj44a0O0a6g9R2bISTG+L3k1ts1GthzHycK/xmX+YFZzDFKbBEYxgD7m7TJENgryMZ18qtKwcaBQJEzOlS4pUQG4DaZw37j1btN+DMJBIMQyL8wLdPl4QzQxdbYTWj85l1Nm5HKOeU/p8DhZWpLTJBhaAFBUFy4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b5f6cf4-72fe-4f5f-4ca2-08dcf8453561 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 18:12:11.5867 (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: fSJ77UMuojcsCsd49mkvf4oA6aQr22nT2K5ufIOjxX77j015NsI5qYlui+LWM36smLT0QpolojI0BHsxeP8ZheTNP+6YiizpQUkYsS8GQE0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6966 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-29_13,2024-10-29_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410290136 X-Proofpoint-GUID: t7dVrWr3N08Q_sPkB-9aYMw1QthhsncK X-Proofpoint-ORIG-GUID: t7dVrWr3N08Q_sPkB-9aYMw1QthhsncK X-Rspam-User: X-Stat-Signature: wqmhknts1zh36qrfenoybbu19hwpk9qm X-Rspamd-Queue-Id: 7A60F1A001D X-Rspamd-Server: rspam11 X-HE-Tag: 1730225524-771253 X-HE-Meta: U2FsdGVkX1+Q0D/QUncnFiuCsJhxm9eh6sNWcV0OKdBy44fopqW3+uhmbEVikFdXT4zJ0nKgc2854HSwVZsRw5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7IkBFcOxjP2p+DBPgWHb9xFmnzjo6w9/SqewNEhciYSW96LzB/KDVqwnhC6zTCkBeT7Fv14lxXlajrQWMjZUzb2ic+FRdEWqg0Azpwww7kSeVnwD8x8FmyTQxDc1POg497HsaXpwDeY7lnqU320JP+BAT8qrGDoeTOl3VN3TRl8GSIWuOBBAXYqN2u4OPkBLr2B2nRK22ffOVVidKPHH7R6+QFumThrMWvjf3JNvys8damf6+sAAUfVTBa3eVgXl6ABKa+Xdqpf9Ycf8wN6t6veWHG8cTCu9BLdOuPZGWYwuiErHxtMlGWK2x/6FkORLauIrsPipU6XkKgMwDxkplebwvcGzKQMN7Z9vHjf0XTfFDKTKduGSA== 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: Incorrect invocation of VMA callbacks when the VMA is no longer in a consistent state is bug prone and risky to perform. With regards to the important vm_ops->close() callback We have gone to great lengths to try to track whether or not we ought to close VMAs. Rather than doing so and risking making a mistake somewhere, instead unconditionally close and reset vma->vm_ops to an empty dummy operations set with a NULL .close operator. We introduce a new function to do so - vma_close() - and simplify existing vms logic which tracked whether we needed to close or not. This simplifies the logic, avoids incorrect double-calling of the .close() callback and allows us to update error paths to simply call vma_close() unconditionally - making VMA closure idempotent. Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Reviewed-by: Vlastimil Babka Reviewed-by: Liam R. Howlett Reviewed-by: Jann Horn Signed-off-by: Lorenzo Stoakes --- mm/internal.h | 18 ++++++++++++++++++ mm/mmap.c | 5 ++--- mm/nommu.c | 3 +-- mm/vma.c | 14 +++++--------- mm/vma.h | 4 +--- 5 files changed, 27 insertions(+), 17 deletions(-) -- 2.47.0 diff --git a/mm/internal.h b/mm/internal.h index 4eab2961e69c..64c2eb0b160e 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -135,6 +135,24 @@ static inline int mmap_file(struct file *file, struct vm_area_struct *vma) return err; } +/* + * If the VMA has a close hook then close it, and since closing it might leave + * it in an inconsistent state which makes the use of any hooks suspect, clear + * them down by installing dummy empty hooks. + */ +static inline void vma_close(struct vm_area_struct *vma) +{ + if (vma->vm_ops && vma->vm_ops->close) { + vma->vm_ops->close(vma); + + /* + * The mapping is in an inconsistent state, and no further hooks + * may be invoked upon it. + */ + vma->vm_ops = &vma_dummy_vm_ops; + } +} + #ifdef CONFIG_MMU /* Flags for folio_pte_batch(). */ diff --git a/mm/mmap.c b/mm/mmap.c index 6e3b25f7728f..ac0604f146f6 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1573,8 +1573,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, return addr; close_and_free_vma: - if (file && !vms.closed_vm_ops && vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); + vma_close(vma); if (file || vma->vm_file) { unmap_and_free_vma: @@ -1934,7 +1933,7 @@ void exit_mmap(struct mm_struct *mm) do { if (vma->vm_flags & VM_ACCOUNT) nr_accounted += vma_pages(vma); - remove_vma(vma, /* unreachable = */ true, /* closed = */ false); + remove_vma(vma, /* unreachable = */ true); count++; cond_resched(); vma = vma_next(&vmi); diff --git a/mm/nommu.c b/mm/nommu.c index f9ccc02458ec..635d028d647b 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -589,8 +589,7 @@ static int delete_vma_from_mm(struct vm_area_struct *vma) */ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma) { - if (vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); + vma_close(vma); if (vma->vm_file) fput(vma->vm_file); put_nommu_region(vma->vm_region); diff --git a/mm/vma.c b/mm/vma.c index b21ffec33f8e..7621384d64cf 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -323,11 +323,10 @@ static bool can_vma_merge_right(struct vma_merge_struct *vmg, /* * Close a vm structure and free it. */ -void remove_vma(struct vm_area_struct *vma, bool unreachable, bool closed) +void remove_vma(struct vm_area_struct *vma, bool unreachable) { might_sleep(); - if (!closed && vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); + vma_close(vma); if (vma->vm_file) fput(vma->vm_file); mpol_put(vma_policy(vma)); @@ -1115,9 +1114,7 @@ void vms_clean_up_area(struct vma_munmap_struct *vms, vms_clear_ptes(vms, mas_detach, true); mas_set(mas_detach, 0); mas_for_each(mas_detach, vma, ULONG_MAX) - if (vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); - vms->closed_vm_ops = true; + vma_close(vma); } /* @@ -1160,7 +1157,7 @@ void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, /* Remove and clean up vmas */ mas_set(mas_detach, 0); mas_for_each(mas_detach, vma, ULONG_MAX) - remove_vma(vma, /* = */ false, vms->closed_vm_ops); + remove_vma(vma, /* unreachable = */ false); vm_unacct_memory(vms->nr_accounted); validate_mm(mm); @@ -1684,8 +1681,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, return new_vma; out_vma_link: - if (new_vma->vm_ops && new_vma->vm_ops->close) - new_vma->vm_ops->close(new_vma); + vma_close(new_vma); if (new_vma->vm_file) fput(new_vma->vm_file); diff --git a/mm/vma.h b/mm/vma.h index 55457cb68200..75558b5e9c8c 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -42,7 +42,6 @@ struct vma_munmap_struct { int vma_count; /* Number of vmas that will be removed */ bool unlock; /* Unlock after the munmap */ bool clear_ptes; /* If there are outstanding PTE to be cleared */ - bool closed_vm_ops; /* call_mmap() was encountered, so vmas may be closed */ /* 1 byte hole */ unsigned long nr_pages; /* Number of pages being removed */ unsigned long locked_vm; /* Number of locked pages */ @@ -198,7 +197,6 @@ static inline void init_vma_munmap(struct vma_munmap_struct *vms, vms->unmap_start = FIRST_USER_ADDRESS; vms->unmap_end = USER_PGTABLES_CEILING; vms->clear_ptes = false; - vms->closed_vm_ops = false; } #endif @@ -269,7 +267,7 @@ int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, unsigned long start, size_t len, struct list_head *uf, bool unlock); -void remove_vma(struct vm_area_struct *vma, bool unreachable, bool closed); +void remove_vma(struct vm_area_struct *vma, bool unreachable); void unmap_region(struct ma_state *mas, struct vm_area_struct *vma, struct vm_area_struct *prev, struct vm_area_struct *next); From patchwork Tue Oct 29 18:11:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13855277 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 EADA0D3A678 for ; Tue, 29 Oct 2024 18:12:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73B1F6B009E; Tue, 29 Oct 2024 14:12:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C6BE6B009F; Tue, 29 Oct 2024 14:12:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4058B6B00A1; Tue, 29 Oct 2024 14:12:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 18DEC6B009E for ; Tue, 29 Oct 2024 14:12:41 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D28501403C6 for ; Tue, 29 Oct 2024 18:12:40 +0000 (UTC) X-FDA: 82727434566.30.46293E4 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf13.hostedemail.com (Postfix) with ESMTP id 9FA0120026 for ; Tue, 29 Oct 2024 18:12:11 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ncXCmrn8; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=WlmeFrJF; spf=pass (imf13.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=1730225345; 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=gD3/8yFb/Fj1edTJvrvVzYBFOVmebuxOTpOZBoSXr+c=; b=Q3ZOlhuD9c0nXHh9tbGPEuiBzPsDGb420tWtzIN/Ex3WL+tswmUTWMIRNQ6DZkxPjHNc69 m6ETXtrtlDHvaBWpUHMvzRkAcle9CpJe3VC2JX8lHD+zoTB55RYwpMrYZ83tAByqDXfNoG Gn+MvbzqE32jIg7NqReWeNOQkjwkHV0= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ncXCmrn8; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=WlmeFrJF; spf=pass (imf13.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=1730225345; a=rsa-sha256; cv=pass; b=eldNzhbgtBeQVtpWvPpWoLXwGui7fHbz12YE17hqetKLoM0wPhUMTPNamjG55ziRveaFqa 7BjIVPATKPPOIsPvNd/qsPKH4WQHqWxFiCT/1IAtGq2O2/U4GY3dpoCCuuhIz8adJt6xd0 QeavPGbmwUAWT8Z14AhyLdVmEEVWlW8= 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 49TGfdn3003433; Tue, 29 Oct 2024 18:12:21 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=gD3/8yFb/Fj1edTJvrvVzYBFOVmebuxOTpOZBoSXr+c=; b= ncXCmrn8C/XAWKaT5GpUg8c4Aj5WFb3G6K1ms0Y8iqfm0Qru/HwBxz9OF2XRF85j aAYhniVK6CumoP6ZCT+e5B0+x47OPQ6iKyZBsLTu1Sl+pQFVzzchSPrYRTHvgyGU 9SLpJB6f0Cj05qnd4OKyBjydbv6t7UjAlTDzw3dgwqqT7i5KY5BxjOfrPsEZI40m CRclVIj9TuDu4pVvKLy4oefflI7VMuotyExL/oNbbt27PmsTF/2A+okpeFmeHpKQ CtMTVyIgUR6ZO64YDzff7cNbJ9YqkOfjXq4u/IZ4N/qNFKDpZDKK1on3pq1JksjW czdh4nqrGThW4p33I2Bc2A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grc8x83j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 18:12:21 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49TH0i3e010118; Tue, 29 Oct 2024 18:12:20 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2171.outbound.protection.outlook.com [104.47.55.171]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42hn8x8ww3-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 18:12:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=M0I8h/buFrWBydFKRy4LuNnJpGdXY1nZJx9nCeYmn+hJJKZrwDzQ9Jyd0aUZga8oNT8snZh61aOPI/LE/52WLjMiE9MGIV/YgriLVaB47QMBZVC0iTLfu6GJDdNrsJXZ9bJGbmLzRpPGr73/Edcf/Z4nkXTM2BAzA0uvHImuc0eLg5W7ziEO6YHVv7rjgkZMu0wJIU1LKhN2gUHxIX01ctleCRyH/Nbb5I8i7yS1ZDLR8zJxo0303FsSONhbIlRu/2H4emBaSLGst3m28ZRitiPxrHH0pX57oyLDH9paduZWTtWrE/I7iJ7ULlE7cC5U+gvbLAJav98EhBBtK4YTiw== 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=gD3/8yFb/Fj1edTJvrvVzYBFOVmebuxOTpOZBoSXr+c=; b=UdBouwznFwC+ngpzbvRR3xtNKbBrTI1cmPw5/m3ZgqYMwlJAxzr6yk6zL7eGMt0sESevW7y/N3uDBt3IDg9kzvSY2dhmA/na5HC+gBQdZB1Bj+PnbA8QYs6HrVYCTOx8SzPZ19NrXgwADiao6sWOL5M/2pVkrboRnl4hbPrip+jGSZwITYIqs2iZKh9BjZsXLUwVqMm/7kc2jdkZKiY6JIaP2/icZX8rq69w+bPz8qIFUata90f73nQRFNFTxqHh3QaBclykujGVzRBwt+YDaz+nGuzd3PEP6QlOGjht8HZeS6qrw4CT6Nt9rX+g7YWgI1csMWo9K7vGIM4tP6pIWg== 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=gD3/8yFb/Fj1edTJvrvVzYBFOVmebuxOTpOZBoSXr+c=; b=WlmeFrJFcri1phHg9WLUMt4sYlc+pRmZXLXt4+EZDUhKTVzfXtCV7sOhBL2yk4AgrmBUt9xufTIamvoiQv/VEqmlkRZFrMReSCICLTGHAYhZsIgyGYxYmqkwlqXgvsUDvEe594SJ/pb8u2dSAz0nYNmm5oWYQiOsihhzSwNUw6A= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by PH7PR10MB6966.namprd10.prod.outlook.com (2603:10b6:510:277::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Tue, 29 Oct 2024 18:12:15 +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.8093.027; Tue, 29 Oct 2024 18:12:15 +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 , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson , "James E . J . Bottomley" , Helge Deller Subject: [PATCH hotfix 6.12 v4 3/5] mm: refactor map_deny_write_exec() Date: Tue, 29 Oct 2024 18:11:46 +0000 Message-ID: <6be8bb59cd7c68006ebb006eb9d8dc27104b1f70.1730224667.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO2P123CA0072.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1::36) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|PH7PR10MB6966:EE_ X-MS-Office365-Filtering-Correlation-Id: 8edb01d7-b2ea-42f1-d4ee-08dcf845378e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: Ozz6nisSp2OI2Iyq5RrJInjUVdUcqD5Hg5zC1pYn7cpQ8qJ9nRZ85wtt9sB4FEdq1rSKfqZ6Wom6Oj2aWZkxcCYLSczZtMQ2UICdKJbdJD90F7wFUu53wbHD/DN7n/YXCEl97ajQr8QcSHCSq4kMBFKWIlux/6mfl+7jI0+MAsswSsezNh/rL8uwdbzR69V2wToVMLErokpZrUMV8Xx7PFDtWzjRvRaZxauO2SWDuZkjLBBe88aYA2+EI89eXjPs3Qj4y/ssDFeDyHZPC480GNEfDmLHoD5RWUMyWh31IjR1Moqtryhet4gZQ9xcKpJHYtu7JjqU+HDunOQXA71syQ95eJRJse2aTfyA2TRqxeljTzzrswvnDYV7CFcYPsBMtHKIuCxrfO5qEX05kY/PQ2RDwDnWurHxPOEE66+xI9sVetvmNtkuA1ybK581zgULjkZk3V+/8DjrgQ1IXDcxAFPhfl4SL61fP9U3a0dX2ABUR214VGvY1aUL0xo5lGr+xPNO+Pm9mPmU3JuientyBIC1ogjpt5Y6Xc9Vf9q5zeRjRqneB2BymTeQYARRvUIJutO1X9vUAvJpDyx1zSJwjtDPjy9bMIRe/DehBqSCT/yD0dCWGSnqw2vGFm5ax6CBBqSJ/lriB9Owt70kwqyyUSiuI8NeB2qV+V92v0+CMuwl/k1JrRR54TnZ/vWHxGyevpa5cBwXASl0QyYMm21LfSTtwdY0PBUNYoCyVPZhjZeimHosA1cDqaPeTerwxvdHTWrWxlSINLiopPuC6w4SP3Og/MSxIJHzNS0BdSakBPSEuuKiokc40uFjJJ/81zSzDnb8GCzwNa4O0elHh/vHvFIqBBZofuYOU9sKMnlIyYpW5EUAruSrkjd6MA+G0Dp2QkY4H4vnfgyd216jqBPyUGN2liN/BdviDamZ0HZSZUStHWJZxnoO0yiCcwALSVcDlTVWs5BsFVTr1eLZDPj9cDBx74G24Yx5NPZbS0rDymkDimD1jZhtIX02+etajrhlBBhOKTSp0gSUJ1GRvxfivhVeiJ+BLbEqsWe8k54UJxtW4U81dTf8TbNhOzFXd5Ko110ypqu6oxf2Dssx/UjR4GXx9zKFcSh3ltaYux+Qg1hHyh7GQO3RQFZfgqLIAC5sitXDUAkWstV6m+orcke0G4cZPScJWEcdk0RvIyY1U2bSxRi1WxZel3QCtQpiOo5iyWANfHulm0Ll7e2MUDWO03h1m9ypxb2/Hb3zbKP4f2+0iCbXa3lNM++Jvi0T3KExOkQs8NSXUZiBNP0oqPYtOnGNu0elHxBh2s3tG4aAC8pPx6etxmyUNzfKzV78L4Pt 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)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sLc5jIUeuf/mv48876dOaYoqEvrUsLE85BrZC2Po1U0MJJNkv3fmI+l5FeR7ifyKet81d6AYe+HcBxWUAc+ZnSaq4GqpfiMD9l8jjm6p2k2re5Zzd6n0cM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mp37hzY+Ii44aDHdO1YRC3iHExhe4FdyAezfMUa96lAUu6olOxTTB6UwJRN/OotwmfxKDtEYplOBzOnCu2HkenMgf2a5B9dY2jnZp6HojT0436189cb3hFSsvgUevGLTo9ch8Xzg7ug6vBvil0Chs7PGE14P9CErSGSrmW9sjzMFABnMnkYJtH2CWzlooYcZJMGgRld7P9Kgnu6mPb/iigtOPGZiX0JZ4DrL2hilwNzqVs8TYHDLLkHJJwDJSjJGaqimYXaVPh5H158w1MI+IEEzDZcpfjJaSwvQKrMWXHXWgeNTAYgFKD3KCnI4S4v8yYD45awwziNhiBOhr0MWxZ3FpKhUG/lfMbiWPOSsqAG04U2vH1YvwxR6fqYt+vlB3VaRW9HoZBcuK0r38haTwDFuQzwUdhvkxpcUGQA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: vk49IzcWjbgHVXL9sXMeFlB1G5v2z2EW3tgnwEkob+TmIjzNKSKZ7XwH733jZ9IuBbncL1rJxIbzaDyETZuRIafeSfFyscCMnnE/7WCNvcBhfxiAlJNP5McIxARWlFFw913dDjI6NjCdXrxk2B6XZ/st5enaAu1JA6ZskuBnwAkmWxIuTMsmurZc/wCSQYiV3UhYthd7oCRMO8fYCQWPb1Zyc1yEPEiLbJnir98rxBiUMLc77HMoLYlDjbCA5MkWsyZeCOPIWsMZlH2LWQYLS7BaSxF4czQk6BQjonL114hlXZSxQsSk/hIdzFC0VEkmB+EZwlAfRqjAU2pGrY+E/BSJ0ukKTReIcaiErmUCQih+p4eZX2ffeYD0j5lQduc82+YA63GgaQtV56a0uvFilQyol1ReG7nMJbtG6zhN1C8pJ8DL/Q6Wd4wn7FD4+h4uHkIWqNiDkrD1/y470U0yFWrc5BO03PxPy+qlewApyBvBjnRePqi8k7/vW/lebj9dlbFesWgxdlbkoExDvz41DA6liMzK2mfuD2oswWqfGYXi/0NSympW5JsqAaixHDZI8BUh15ZsodzMse8UzmPhV65cc1Um38FI40hnu4ULzw4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8edb01d7-b2ea-42f1-d4ee-08dcf845378e X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 18:12:15.1038 (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: lTKoRECnVPFzNOJmnuBPYsiA56//lpY14uLHNsttg0K8IeCj07G2mqGXDOpsFq/wuPTtOOgRD39qa9fJxxRuItz2O+O4Z96L466N1j19e6o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6966 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-29_13,2024-10-29_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410290136 X-Proofpoint-GUID: X6SHYljO0tOm8muJZfY4ssgyH0KkU9P8 X-Proofpoint-ORIG-GUID: X6SHYljO0tOm8muJZfY4ssgyH0KkU9P8 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9FA0120026 X-Stat-Signature: 8yg8dkdeznft4e5xumsyys5g5k8p4amu X-Rspam-User: X-HE-Tag: 1730225531-435010 X-HE-Meta: U2FsdGVkX18vE+Fg8vDfUdaeHQsxEPGQldD7+SLuuZFa+6dO+puDfxGiCRhF3MGSvbHczMpeEyW52g5PJLtW64w1kBk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6H4gA+GM33cEnZvNMF6ubmsj4/xCDC2m03Y8C9Eqv4iN/ImcGMwesJEXGG/jItAQeh8TJaCtJCyLMa20RMwlCEj56wJwrnVLCqY0gmZgKRufuaR/GSHMl0kwWFjmKv7nboZU7RmxeYjndrcgpZzZHCrUE2oeVxTQL+ou1Xs3rSrd8UJkncD2C0ICBHzKh5z27he4rzEIcOYGO6MES94Akvxe5T9prDKsieVmTXO2WA4HXz1yc3JL2b/A8WJNlnC9SXIBharssx7Eaet0JvFiBaDVnAnHs1nQE+q1dpL4DYVSYNEqHUUkLFU0y/e+OhmB6cb6UbbGmdDy0kLtOyy6Rrb1jaN9ShUcZek8H6mUJbpzKka3IT4q7LSIcoGa8NSEcpiUFm5E4zz6o6OXkoT9+ivIPGLy6A2NlgpekcTt/VrDFS4fZ6Y7Q7GznEKdJ02fMR0UY= 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: Refactor the map_deny_write_exec() to not unnecessarily require a VMA parameter but rather to accept VMA flags parameters, which allows us to use this function early in mmap_region() in a subsequent commit. While we're here, we refactor the function to be more readable and add some additional documentation. 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 --- include/linux/mman.h | 21 ++++++++++++++++++--- mm/mmap.c | 2 +- mm/mprotect.c | 2 +- mm/vma.h | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) -- 2.47.0 diff --git a/include/linux/mman.h b/include/linux/mman.h index bcb201ab7a41..8ddca62d6460 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -188,16 +188,31 @@ static inline bool arch_memory_deny_write_exec_supported(void) * * d) mmap(PROT_READ | PROT_EXEC) * mmap(PROT_READ | PROT_EXEC | PROT_BTI) + * + * This is only applicable if the user has set the Memory-Deny-Write-Execute + * (MDWE) protection mask for the current process. + * + * @old specifies the VMA flags the VMA originally possessed, and @new the ones + * we propose to set. + * + * Return: false if proposed change is OK, true if not ok and should be denied. */ -static inline bool map_deny_write_exec(struct vm_area_struct *vma, unsigned long vm_flags) +static inline bool map_deny_write_exec(unsigned long old, unsigned long new) { + /* If MDWE is disabled, we have nothing to deny. */ if (!test_bit(MMF_HAS_MDWE, ¤t->mm->flags)) return false; - if ((vm_flags & VM_EXEC) && (vm_flags & VM_WRITE)) + /* If the new VMA is not executable, we have nothing to deny. */ + if (!(new & VM_EXEC)) + return false; + + /* Under MDWE we do not accept newly writably executable VMAs... */ + if (new & VM_WRITE) return true; - if (!(vma->vm_flags & VM_EXEC) && (vm_flags & VM_EXEC)) + /* ...nor previously non-executable VMAs becoming executable. */ + if (!(old & VM_EXEC)) return true; return false; diff --git a/mm/mmap.c b/mm/mmap.c index ac0604f146f6..ab71d4c3464c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1505,7 +1505,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_set_anonymous(vma); } - if (map_deny_write_exec(vma, vma->vm_flags)) { + if (map_deny_write_exec(vma->vm_flags, vma->vm_flags)) { error = -EACCES; goto close_and_free_vma; } diff --git a/mm/mprotect.c b/mm/mprotect.c index 0c5d6d06107d..6f450af3252e 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -810,7 +810,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, break; } - if (map_deny_write_exec(vma, newflags)) { + if (map_deny_write_exec(vma->vm_flags, newflags)) { error = -EACCES; break; } diff --git a/mm/vma.h b/mm/vma.h index 75558b5e9c8c..d58068c0ff2e 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -42,7 +42,7 @@ struct vma_munmap_struct { int vma_count; /* Number of vmas that will be removed */ bool unlock; /* Unlock after the munmap */ bool clear_ptes; /* If there are outstanding PTE to be cleared */ - /* 1 byte hole */ + /* 2 byte hole */ unsigned long nr_pages; /* Number of pages being removed */ unsigned long locked_vm; /* Number of locked pages */ unsigned long nr_accounted; /* Number of VM_ACCOUNT pages */ From patchwork Tue Oct 29 18:11:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13855279 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 6D9B2D3A67A for ; Tue, 29 Oct 2024 18:12:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A6EF6B00A3; Tue, 29 Oct 2024 14:12:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8502F6B00A4; Tue, 29 Oct 2024 14:12:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6373E6B00A5; Tue, 29 Oct 2024 14:12:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 391656B00A3 for ; Tue, 29 Oct 2024 14:12:46 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 23474C0382 for ; Tue, 29 Oct 2024 18:12:45 +0000 (UTC) X-FDA: 82727434146.09.D26E191 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf13.hostedemail.com (Postfix) with ESMTP id 42B6A20025 for ; Tue, 29 Oct 2024 18:12:16 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=fENiiWLq; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=BQdOGxr9; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf13.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730225432; a=rsa-sha256; cv=pass; b=0nQI4Cz6v1MOHDhNICkNNZNabG4j5koYoIuTR+GxOMfFshzY0KcQlfaLCGfQ9a91eTG0wY OD7WMr/HHr5J4+pavWuAClU2+Z8/KNFY66nfHoYDDoIbQNTgK6SdAuwt2b4A9lc1OBoEjN epweIQ39gaZt9srjaaUlaB4pBN7RvwY= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=fENiiWLq; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=BQdOGxr9; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf13.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730225432; 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=lnRs8fMf9CA0ufwxjVoxof7qX+F6sbCgSJ51HkqymKo=; b=dvm5Jk04dzoXchIjDuxa6T6pZm5CTbPFYwgz9QvgFfAnhb4WAe9RmO7ZwQ081619fHuIdV EG+zkbLozKYka4DGaLrnKgphavCVnZdRIetRKRtDcIQk8J6YlwqVLXD+OkuE1wBZkt9Ysu gE8J6PBt56GLkMLKackqj25wcKfdDbE= 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 49TGfVk0030916; Tue, 29 Oct 2024 18:12:30 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=lnRs8fMf9CA0ufwxjVoxof7qX+F6sbCgSJ51HkqymKo=; b= fENiiWLqfdlZcdOFO9XKHGnvsnRwZE9SpudvzJjt9owZRs6yhrc4KpbEpdVmFAAn i/62POOc5E1+zl6vCNE4X9cpEHP2wz6HPqPM4jOiGbhRsWxi4M7Yb4owB+N0e98W N7hvOK91kTwrObrKYlnQRj1QxBD6ktQPn59Kkva46MlwDToPHlmCoqTLNX21GaOW YumasfNjmkjLX4EHxoAdnIxpuZHwWvSzwL2Ml/6c4VpTwIadXzly/SK/3Fj22O2x rBa8nUeKQcF6LLjMSh/GDBqwPWNf0Vgkd9pRkc95sSFH6Rxdwo1j5zmJ+tF1PyB+ f0t/Kn7PhaZqMqgFW0xMvQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grdp67rj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 18:12:29 +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 49TI5Ogr011848; Tue, 29 Oct 2024 18:12:29 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42hnacx88r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 18:12:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=y0OyqhiCbFKWKquqpkzWgjBD4laLlaUcWCW39ZG7BOdYnxTXzpitiFMF3GSD7UrSJX+HsrFCj2TIsZVME0yE3CRnYHzs7NgI5dwivoztolIl9sf/xnUnTbtdxsC6lzs+CRggkfjLsiQUo93vfZFEFs2s+bXPqkVtz/UX3RywE86IiYBtOeEu1IORxuQ5BZNyVR06zop01H/cKjQiVbCXZ2T+Yhi9ocnpSvVnjl45g/BlO9V81nhR0pLWza1htLbnQ/wqgGtnMc/myoiP0UrGtOr9d8BYFVxnayfhUTBS9D5mozCuN2m1wU+EGVNWHJ5GANA+249LXjfERoKeoZKmIw== 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=lnRs8fMf9CA0ufwxjVoxof7qX+F6sbCgSJ51HkqymKo=; b=OTmjbia0O7WJDyilud20gR8nuABgI1PdtcE8/UzyhL11o5omAtMn3sp4+lfiSSeFBn/F3UUy51h71Xl417nShbpLhGJQEcQ/oJZetTxxGFQGvJTqIrjold+cpD63OmCK4aY4oo6BBv74izNuGLSsAfSFF405hOqP61ZrOJrE9qFkQAOQHfLKPrHIiWQGrpt7TQYxBw0HdWy/I1DJok6iV/Ch7Kh12mVz6lfjtLmgxtqY9vlGWuP/gltfZibXKFrXfAkY3T6df3nytKs206mgKeVfpnu6oUbl6a/UUyjWBClZLN/VYoSmyduszN3KBxe+zYHip5O/sD196ezokks+vw== 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=lnRs8fMf9CA0ufwxjVoxof7qX+F6sbCgSJ51HkqymKo=; b=BQdOGxr9NbmFcANwuFt9+/v7hsa6xZppNyw8FSB3p0REn8ea9asNd54Nhj1oJdeL1mmfuSEhhhKUfptFx4GFYhn/h4fV6aYGW+N178hZ/7q0o8KHFPRB5apwdnNQ0MyhjHLO3VlHyq5fvaw2/iLiYkDR0PweyPj1O6rkYmKJjjw= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by PH7PR10MB6966.namprd10.prod.outlook.com (2603:10b6:510:277::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Tue, 29 Oct 2024 18:12: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%6]) with mapi id 15.20.8093.027; Tue, 29 Oct 2024 18:12:18 +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 , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson , "James E . J . Bottomley" , Helge Deller Subject: [PATCH hotfix 6.12 v4 4/5] mm: refactor arch_calc_vm_flag_bits() and arm64 MTE handling Date: Tue, 29 Oct 2024 18:11:47 +0000 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0273.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:37a::10) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|PH7PR10MB6966:EE_ X-MS-Office365-Filtering-Correlation-Id: 8ff592e2-4815-4648-7436-08dcf8453959 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: j1ykXFkbGhYmgLsyys03A+qbpQgYmn6VFBUDrpdALPOwOV9sXhp3s3JYriv4lT9NC9jEoUWvArmeCkakbO4l/dKTbLl4cX9wfzjl7Ei6AwzPM2HG1rrT4rNpbtxEopUFZxSPBeltBwDmw56Ixv41TBhIJl+fIWLM8hX1/IpBtlKO8I2pQfw9K4hpYP6HpU4ltN2fxZfCHP/YuCKHGlRra6Ve5gL72YRJn3pvXrJ/tGqLk2nX+1uOxqEyAPebpi0PdJQhXnWJ7hFfO+iPphtoYiavXPb15o3m+C8D8cWzE+sQ5mWGPy0M+/6RUNTpU5+Gr9Jc4tVzWqonaa10uDYfFsuvDNSidXFsS7/qtjqf41rFYPSE1RwWDJh/7H8ww6lNk/69Jo4GbDFgol+ZJsWG5kobEqtLQRxKnKh4aUDLDCcMwY4AdSoawYA+MWNR6J4dobWjIXs9W4s1skh5ONIMDVtH75UTYSqO1fLjI4HcmMhgctPChBZ4KvdWKcsEkokG2ENP0Oo7/pQ/0Jk0OYruAAf0Un5rNjegXYvNE6VGeRY77W44paNIjyD86dRFQ/H65yeH1k8hQTCxq9r6aXXTQ8FwW5iymcM73Q1FTb5F2btL4bsXmkvXn4aqfPLtSSGRqd0ABanUG1jHpsF6iSWeT6wbUhncRHAgVJvuut/X3N46uxTO86EmFxcrygndJuoR330m1LX+Iquq9YSYiXeXSIx7EPsvKf+nnHIY0BhM5dPrymA5fancPTLuljTdAzqpj+31V9Brk8F1/O3ZzwyUBT/GLpTDkw8sPKvMz6guXS7daKm9pzsPNhW3skeO6P9tDFGlhxk1ZKORNx3IIE0ioRRONzqfGWZNIMjcl5i/GtYBqbsByS0CEl4Fj0B/nu1VAXOVLmH8oi40NeXRY1uh7GafMnRmMdWHkT5ylnRvtfAXEUjsWsvtfWX4mGNQWPQ0/5BGBeiFLtWfzl0ckOOiOvKeL6bjPTPuwC0Nafep2bAaGvuS5KQ3Jk9P2PWRcj27g0x+at/x/j4jtS2Sfz9Mxc2G7qXjFxyDUhVxF7gsSp1oAEjqQq5n+56SHdacEGoXJoxnGQ/t/IMC6Lf7n8q+2eaZz0twGorcLtpuLb99vZp7MDOosG/aBLVpNjkJa06yX0tPsDqdof++ux4knKKYw8UXIlw2ZzAR6kurKqiKgUOmNWWc6CZZL07SupblXTf9tb51n66XTTv7R6gyYdIL59AjgsnSv/yhxzmR9Xj/HXaRUHcC6CLnnNqNqNP5iBYE50/rb5SAkxwSVHusrPx5Yq6dAt7vzYufsiqydQeY75qKAuaDxAMTBq+ZSBr/jCM5 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)(7416014)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UUCB8QqDcve+1US/fnx1WJuA4nrep85tXZm7cnBe+lEfnDokbQbBXDM2wlL5/m9aRzeEX7nrvxy6Mv3HqGSwl9fhtuXEm6s9LIqG17ssDRchZT6F4THHeCcboQ6oXEl78uIfsTkQypjNAgVRmDfqa+BGGlzgj/N0cBVix0len8pF7a3nuCtmWygpmbPfQlnSPSmKxLRBjcCzsbZCN0XmbRyTCkYgzy4rre6j5gspmkXL05n1jJD6THyWx/qAyC+FrsU/5UVgreCFm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Eqiy+VHVOYl4ty3QJOZb6smhIU5Zd9it06aktORd2N1deCg3K76ZMLHdYmKrgNjuoy0Ty82yAUd3jWcw+V7h6hsIVyZLvSXQNKHLOZrScmu7NHIroF71OlHl+S9GHlUNHdh4J0Sd/3Qqpob55cSiq60ngrUczl1GmPSPrnPCFf2SwufXxBXPoscok+LKh/7xAIVhHy6QUh1hr2G28WUi0+DtZCQhns/PSX2x6TqONhnrj0ymCOHF620zF/vMAl3eyxbt6vhrHrsecT4FiwjWRg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: RPwsYbLN9RnGPqPF8LwxiqgSI8GOOOZ91eB6vzeoO8cqQ9ku8X2NUmtfTLIbui4AkoE9mhzDheCg2hbeOFWba11/YB/2P858MhFyd+55Obw6OcJJsBXz5KGMNEGTpmoSQKHFMkDvpaaAp3sR/sULxZvesf32pRtjbHlxJI6uW5tvy01pkRt6vV+nVl9iheVGKip8vU4B4gfz5PQ2vRvZhrpJq9nYi/Zr1EkVTE9ewyCQp1HvEeFW+i2CQfth9sQc2cKboa6qqYY7RZ4la+/MIiljyWBSOI6wW+ZpNoT06HIMQ8xohpL7aTwur5yN39ou5WA1ju4C+zJdACZrjdwqvoMn+rkKIBAMh+Spt1j+8/q2HNnJQJl9h5gDrSvMzWstcfEiEQPz7tjkWzH/ts4BVkmalaVEF6fkLTXDlXDQjKaxIBgGjUOqjMpWddJW1oEoXriDeaHIi6/74DwaR41nOd0sJS7Tr+GgIuw2Iyrs2++1SJUBLKrOVLklFErjXYuRcPeGF3y9dH5zdHDBaM/nSC8/Nvhp06Ftf/XuOJFHWtd1M+EXw1/ibJ58j46cyxJFEKRXS9NXWPQ9o6uXrD5vlsw4zfDo6OKBklBaSgKgxfo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8ff592e2-4815-4648-7436-08dcf8453959 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 18:12:18.1191 (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: 1MCe4rgkAkGNUXlDVOUTm6g9CqXMgwZD7wmOItUU2up6cWOGsGI2YA73tr4Q5gFLdwkhUHd2VAQejov4UXNeFjUPpLyd13tpPiUvpPlKbrc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6966 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-29_13,2024-10-29_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410290136 X-Proofpoint-ORIG-GUID: Mq8pEVXT8P7w0vZGyztvhoAyIMls4F-D X-Proofpoint-GUID: Mq8pEVXT8P7w0vZGyztvhoAyIMls4F-D X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 42B6A20025 X-Stat-Signature: 9tehmdq6ej8ru43uiekeic3d6tjphdrk X-Rspam-User: X-HE-Tag: 1730225536-531707 X-HE-Meta: U2FsdGVkX1+OYJi1bkd/b3+C2rJywwmmIFFxt79WPtvfkaPAh4MRLpOohel8jESzv2YqMFaAxZQT10QRhAcw/9M1WM8lvOYXgpp6Th0F690wyUseNrDsEw4m5BDjafdwjMriyhxU42KOF5yHy9w2eEjV9GKTCoJLn2inPH4y0Vby6ju8sX1s3J8QF/y0fqj4UzBZ+6nMP7hlqeeAXsB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h+hY+Vi17CHcVubOaBua++GP8mNGa1VZczwhHUDK7v3V0We23a8LMSYb/zoRPlp+Br9Oz7FrwtMZjbipQ1fSGW/At5tMzHAnqnoAov5OZd7tst/HQawaHb1QXOQEr7Yi1Ybpom31tl+k/Fj/dc96CpbhKUtmUF6qMdeuq6FYc8Fn4mHtpljMrbRAAiiXnBpxNtaqm5vf7o1dQ4NoNmefLJoDN3PSFsrsIjUJGI/K9kUx3U4kWVr8WvumvmbNzCr8xJF/+/0epnObO/s7M2fwz7zQSq64dZ7wRIKG7PzKu5blk2NGrGrAD2UPFMEqz0UG20YV6LqI2ZI0U7BdTQcRzSd7T9M1TqwAtglHPoCbeZ2nSHwiqwfs3x3WEwidYFmPusw9So= 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: Currently MTE is permitted in two circumstances (desiring to use MTE having been specified by the VM_MTE flag) - where MAP_ANONYMOUS is specified, as checked by arch_calc_vm_flag_bits() and actualised by setting the VM_MTE_ALLOWED flag, or if the file backing the mapping is shmem, in which case we set VM_MTE_ALLOWED in shmem_mmap() when the mmap hook is activated in mmap_region(). The function that checks that, if VM_MTE is set, VM_MTE_ALLOWED is also set is the arm64 implementation of arch_validate_flags(). Unfortunately, we intend to refactor mmap_region() to perform this check earlier, meaning that in the case of a shmem backing we will not have invoked shmem_mmap() yet, causing the mapping to fail spuriously. It is inappropriate to set this architecture-specific flag in general mm code anyway, so a sensible resolution of this issue is to instead move the check somewhere else. We resolve this by setting VM_MTE_ALLOWED much earlier in do_mmap(), via the arch_calc_vm_flag_bits() call. This is an appropriate place to do this as we already check for the MAP_ANONYMOUS case here, and the shmem file case is simply a variant of the same idea - we permit RAM-backed memory. This requires a modification to the arch_calc_vm_flag_bits() signature to pass in a pointer to the struct file associated with the mapping, however this is not too egregious as this is only used by two architectures anyway - arm64 and parisc. So this patch performs this adjustment and removes the unnecessary assignment of VM_MTE_ALLOWED in shmem_mmap(). Suggested-by: Catalin Marinas Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/mman.h | 10 +++++++--- arch/parisc/include/asm/mman.h | 5 +++-- include/linux/mman.h | 7 ++++--- mm/mmap.c | 2 +- mm/nommu.c | 2 +- mm/shmem.c | 3 --- 6 files changed, 16 insertions(+), 13 deletions(-) -- 2.47.0 diff --git a/arch/arm64/include/asm/mman.h b/arch/arm64/include/asm/mman.h index 9e39217b4afb..798d965760d4 100644 --- a/arch/arm64/include/asm/mman.h +++ b/arch/arm64/include/asm/mman.h @@ -6,6 +6,8 @@ #ifndef BUILD_VDSO #include +#include +#include #include static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, @@ -31,19 +33,21 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot, } #define arch_calc_vm_prot_bits(prot, pkey) arch_calc_vm_prot_bits(prot, pkey) -static inline unsigned long arch_calc_vm_flag_bits(unsigned long flags) +static inline unsigned long arch_calc_vm_flag_bits(struct file *file, + unsigned long flags) { /* * Only allow MTE on anonymous mappings as these are guaranteed to be * backed by tags-capable memory. The vm_flags may be overridden by a * filesystem supporting MTE (RAM-based). */ - if (system_supports_mte() && (flags & MAP_ANONYMOUS)) + if (system_supports_mte() && + ((flags & MAP_ANONYMOUS) || shmem_file(file))) return VM_MTE_ALLOWED; return 0; } -#define arch_calc_vm_flag_bits(flags) arch_calc_vm_flag_bits(flags) +#define arch_calc_vm_flag_bits(file, flags) arch_calc_vm_flag_bits(file, flags) static inline bool arch_validate_prot(unsigned long prot, unsigned long addr __always_unused) diff --git a/arch/parisc/include/asm/mman.h b/arch/parisc/include/asm/mman.h index 89b6beeda0b8..663f587dc789 100644 --- a/arch/parisc/include/asm/mman.h +++ b/arch/parisc/include/asm/mman.h @@ -2,6 +2,7 @@ #ifndef __ASM_MMAN_H__ #define __ASM_MMAN_H__ +#include #include /* PARISC cannot allow mdwe as it needs writable stacks */ @@ -11,7 +12,7 @@ static inline bool arch_memory_deny_write_exec_supported(void) } #define arch_memory_deny_write_exec_supported arch_memory_deny_write_exec_supported -static inline unsigned long arch_calc_vm_flag_bits(unsigned long flags) +static inline unsigned long arch_calc_vm_flag_bits(struct file *file, unsigned long flags) { /* * The stack on parisc grows upwards, so if userspace requests memory @@ -23,6 +24,6 @@ static inline unsigned long arch_calc_vm_flag_bits(unsigned long flags) return 0; } -#define arch_calc_vm_flag_bits(flags) arch_calc_vm_flag_bits(flags) +#define arch_calc_vm_flag_bits(file, flags) arch_calc_vm_flag_bits(file, flags) #endif /* __ASM_MMAN_H__ */ diff --git a/include/linux/mman.h b/include/linux/mman.h index 8ddca62d6460..bd70af0321e8 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -2,6 +2,7 @@ #ifndef _LINUX_MMAN_H #define _LINUX_MMAN_H +#include #include #include @@ -94,7 +95,7 @@ static inline void vm_unacct_memory(long pages) #endif #ifndef arch_calc_vm_flag_bits -#define arch_calc_vm_flag_bits(flags) 0 +#define arch_calc_vm_flag_bits(file, flags) 0 #endif #ifndef arch_validate_prot @@ -151,13 +152,13 @@ calc_vm_prot_bits(unsigned long prot, unsigned long pkey) * Combine the mmap "flags" argument into "vm_flags" used internally. */ static inline unsigned long -calc_vm_flag_bits(unsigned long flags) +calc_vm_flag_bits(struct file *file, unsigned long flags) { return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) | _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED ) | _calc_vm_trans(flags, MAP_SYNC, VM_SYNC ) | _calc_vm_trans(flags, MAP_STACK, VM_NOHUGEPAGE) | - arch_calc_vm_flag_bits(flags); + arch_calc_vm_flag_bits(file, flags); } unsigned long vm_commit_limit(void); diff --git a/mm/mmap.c b/mm/mmap.c index ab71d4c3464c..aee5fa08ae5d 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -344,7 +344,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr, * to. we assume access permissions have been handled by the open * of the memory object, so we don't do any here. */ - vm_flags |= calc_vm_prot_bits(prot, pkey) | calc_vm_flag_bits(flags) | + vm_flags |= calc_vm_prot_bits(prot, pkey) | calc_vm_flag_bits(file, flags) | mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC; /* Obtain the address to map to. we verify (or select) it and ensure diff --git a/mm/nommu.c b/mm/nommu.c index 635d028d647b..e9b5f527ab5b 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -842,7 +842,7 @@ static unsigned long determine_vm_flags(struct file *file, { unsigned long vm_flags; - vm_flags = calc_vm_prot_bits(prot, 0) | calc_vm_flag_bits(flags); + vm_flags = calc_vm_prot_bits(prot, 0) | calc_vm_flag_bits(file, flags); if (!file) { /* diff --git a/mm/shmem.c b/mm/shmem.c index 4ba1d00fabda..e87f5d6799a7 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2733,9 +2733,6 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma) if (ret) return ret; - /* arm64 - allow memory tagging on RAM-based files */ - vm_flags_set(vma, VM_MTE_ALLOWED); - file_accessed(file); /* This is anonymous shared memory if it is unlinked at the time of mmap */ if (inode->i_nlink) From patchwork Tue Oct 29 18:11:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13855278 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 8FB87D3A678 for ; Tue, 29 Oct 2024 18:12:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E7A36B00A1; Tue, 29 Oct 2024 14:12:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 196B36B00A2; Tue, 29 Oct 2024 14:12:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E8D296B00A3; Tue, 29 Oct 2024 14:12:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BF7156B00A1 for ; Tue, 29 Oct 2024 14:12:44 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A386EC03CC for ; Tue, 29 Oct 2024 18:12:43 +0000 (UTC) X-FDA: 82727434944.04.20C788E Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf09.hostedemail.com (Postfix) with ESMTP id EB811140006 for ; Tue, 29 Oct 2024 18:12:22 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=SR+gmUdl; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Fqfq+TgV; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.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=1730225402; 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=owPx6h3RstDUuQfnccozZWYC1C6lZczWO8TgNEoLsp8=; b=62hckHy6bRbrixKqXgu0ENg4547tn3slqlIso9/rLskcb/EvYUWqKQOxM4vquOpWZk5NyX AwNoughatqpvqj0ZYLBWST/OnDwDbTQDGxKX4ALpi7tL1UQOoxXHbmsjXRdLRjhp4aW73R K8KI1XbJxGDYKIMqZ5pBKB1VWZgUJug= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1730225402; a=rsa-sha256; cv=pass; b=7kT7p05f93UP+c8F4JjtH9aoJ4BOPtIad0HYZgh0NExouR7kHnY31hYFSD7X1NxTM70I70 WR+CpoZiXodiz7uV6mVG7QIVI9cID6x5XFncLvyJIucH9FLEQl7MysAngyNEY5YPeWUBL2 iayhM9e8UyHovTTExs+QLQLlkmAs8Zg= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=SR+gmUdl; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Fqfq+TgV; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49TGfWQj004318; Tue, 29 Oct 2024 18:12:27 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=owPx6h3RstDUuQfnccozZWYC1C6lZczWO8TgNEoLsp8=; b= SR+gmUdlVfBgvcFalfHKU4mmj3mK/Yp7POmhHyTzAutf9dhYdDpU4N2M+Ez1WJG5 K5JPHTm8kOi8yBvBaCoH5QgHvZxaiSZJsLdx3AFUmCzihD02UBqcpYBHV/OgIwOr +4oB4vraffjO03AcE8kmiHcR2dA8dz0Va42TuhNb9Di6UJqKtPztS+dosbLK8Ztc ml0hMjINF176wsLYu7QNmpHjrSSNgpUpQfkaq3dSWAWETYU4bDdmQPAjmRYsXLxI x8MiPdSwppivRnfYMs++piPxapY2iIdAe+rbbejU+C1WM/+9CjtfoxhdeSCq7I/S /6/Yd/lFsUyrUI4xB+PUyw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42grc1x5s1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 18:12:26 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49THds0N009964; Tue, 29 Oct 2024 18:12:25 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2048.outbound.protection.outlook.com [104.47.73.48]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42hn8x8x0w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Oct 2024 18:12:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RgrPpD6HvGJNDtys2IPEzNUxrf4tUGIR67eMgAAAWe3Vqz0C5i9W06Jw2sMIWN/u63a743O9AGjZr54bXa+aNhrKyfPoOYsY7IXFEqT5Ls9ZE5aRhR2p7C+rPsTd/mszpKrK9IyddiabTBd2WTY3uOP5+vU83+8ERxGaNMY8ECX1ReZi5SweieH8box9Ao23dehkCmHFL7BFyYJNncUw6ifYNTBLpWPXmiVqxs0rT04IjwdKZruy27MwO36h0KqGcwpBzu7Nuh7mcY6hk1WaUlBEvt9NQSUmFFEwRwSlRMj0HSZ+nnzAvKGdmsTJ9aGmkSdLdIxD/GuRtHJk7EbnhQ== 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=owPx6h3RstDUuQfnccozZWYC1C6lZczWO8TgNEoLsp8=; b=fteWYrB398HqzZF2nRIBfKBAm7GFQGuQO3LoliPSdK0r2ZjlvERjsbYH5+v7mUpsUQ1yFGnyAP2bX8PCmEVvYAoyXWYawhcHWsE8s5jnXrB+tdBQ3eps2dAvQ/aZ9e4+pPQ1XyQztqZ8aedc9GGReXX+2EDhTnDfgh8jYg09HdNGv2f0yw/IpAuRsWtN7Cvckks/nkDRBu4zeDvbVBuZAeo51Ty3vtc7XyfG7n+xM5nITv/4euiKFDx8YYcBoF0A60H6TPdD9QXVZcZwUbIN+f2pVJJmSNpvuR1vS9yYDgtimGCNjOJo/xbgTUaVWXKLHtEcqMKbK+KO/x5+nH/kfg== 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=owPx6h3RstDUuQfnccozZWYC1C6lZczWO8TgNEoLsp8=; b=Fqfq+TgVfeuN2wb649JKPbkMw8RTHDyuHv20VES/hlt5sObrd4zQa5O6btlnteG0klQ7G3So6rJmM34WapOCHAgaByxTWtxgNOdNQNwTeLFnBKYCfA2dBRB/0iX2CbTCVbma3bx7tXJjNjJnea8ZByHMcvv5WLf5MAhwh9Nfwl8= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by MN2PR10MB4352.namprd10.prod.outlook.com (2603:10b6:208:1de::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Tue, 29 Oct 2024 18:12:21 +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.8093.027; Tue, 29 Oct 2024 18:12:21 +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 , Catalin Marinas , Will Deacon , Mark Brown , "David S . Miller" , Andreas Larsson , "James E . J . Bottomley" , Helge Deller Subject: [PATCH hotfix 6.12 v4 5/5] mm: resolve faulty mmap_region() error path behaviour Date: Tue, 29 Oct 2024 18:11:48 +0000 Message-ID: <6e0becb36d2f5472053ac5d544c0edfe9b899e25.1730224667.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO2P123CA0055.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1::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_|MN2PR10MB4352:EE_ X-MS-Office365-Filtering-Correlation-Id: 540479b5-8dd8-40cc-24aa-08dcf8453b49 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|376014; X-Microsoft-Antispam-Message-Info: UfE8/N7Z+kFkE30UcF87DMys1UL847X4lHyHEq8JzaxvsFO9eCzgHL1dkUeYF/Cmiha4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A8WPwQWmkjMjJcOLtIFU7zq+G6nqm8Xdhcr1ECwKUiFXtOQmQCcimhr/sM7U6HLgO77fcX1jDxKCTrMGOb1MCTKVWqIP8ItYDBh9WBPcPslZjdK9u1u/Ekn1iqo/id7vXkimdFRgnNAIABPR1GdGWf+PlPwJPAK1fXEoc7K0yWjf0iDLYC/cjBLQ3M 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)(7416014)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nRT4ho7PzZNXVOiXyfzgTlGtWjAqj0fmds17AbQZczj+rrOR6a129X+mFGNxsN3QGXAljDugN57xLjnmXdJa+zVEe+eRp6lrLU7IqmtaW+RmHIMJhZXVAnNQW7OIdLAwcogJepdPei6t+cbQ9iLY7gTQ2Hz5pAo23txLcsyeCvAtFY6/kqS+YM3ewEA6eeLlK/QCMpd4bNgB0kGv4+VQEtYptTnesOVcRM9wPfJa5jjdwFHVgHYlzzt+Wgs8n6ql17PNbsrdUJmkq9q+AOP55HVX4sdCXjCrZFBoSOjYOpSwuERKOsdBMt4TVZobKf4UDD24rpBCviEyzf8ZC/3MG1X0NfXoIBHQKKgQefIR5jcWLwTwKWV7Gt8OIcfwNIS0QSJrpkFjhPlXoWqQP5wRHejMCIVzRruofxecfFcwYMV0W0zOFtKpTdthly22Zy2SNsR5/MVnnHU4qJYjWJwaVydayI6QgTfXGggNdeIv2yH5ND5QzQJEnoi9JBovWJuiB+Aewg/0ZEfXhIDIT+4BoldVdw/4DgU6VyuI420foSnLLVJl1pF2eC7VQi3BjIxBGR3amV5F3wwFtX7J7issLd7Ebe/rljks/c19/6LWy08FyxzSMcj3jI//h/O+G6/+IRHAyJUTqSLnDdcZv1eJiG8/AO5x9oY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InzKabs0N1Bm1IYBhafgYqdNp/DCoqJWdqAoCWfl0EtD+IeRAwIEJWcSV3uIRXwgjcvCMFDF3HZWL7TY+BUFjfXGRJ79IyB+m9ZJio1z9yeO86tT/QZN1Tt8NtGniQfolCm1DcVQoz6MgjsmN3GqZHvJ/USK8+DhKSkywpJP32nBIqrgid3glsUN4ykB8XEpOXRbybRQkYmGcP+98etc51yf8auXCKXOp3E1XpxApjZhDdg9GF06KIZk6+KuQmUEV2fcK4DDU83atGTzmtz9wEOVSF68G5dNFotd6qeQYy5EE1Hz56WHPN2YdxCxdSGQAxKORFTTDpJYlUQ/G+9TQrv/KRyFyhbupmuMDrFQxM9nbO5gtU9uv5cmC8J0u3X0DE9Ys6Awdm/YRUJ8xeHwFrmiXrSCzUcPjicaFpqMVmnfIwguAM6KgjFLF++I8oUEYgTQjZaLvDFJZKnhsw2ro1oJuvcnHgMmlEpZaZ1K3Dmbp1iJknNWm83yOhtRQhmC+c0hfu/TNtj4ybRTDnKVRgcNb+C8EESP8PeZcZwrGC0oytIAeEdLXE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 540479b5-8dd8-40cc-24aa-08dcf8453b49 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Oct 2024 18:12:21.2453 (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: mqkJRtjJEuSgu0lginSrRHpL3A/MwiaGEQk5BI6o51ZN2VInWVtzVba1hRQk8f82RQMc63t5TO2Sr2D+6p11QeaPjGCviHS9ZsUTK5E8rRE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB4352 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-29_13,2024-10-29_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 spamscore=0 phishscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410290136 X-Proofpoint-GUID: bSKqrEvuivnys9q9WEM4Q3zkY6K3BS6f X-Proofpoint-ORIG-GUID: bSKqrEvuivnys9q9WEM4Q3zkY6K3BS6f X-Rspamd-Queue-Id: EB811140006 X-Stat-Signature: ot77yzrh4esdfdoa46uh14kcknemimjg X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1730225542-989953 X-HE-Meta: U2FsdGVkX19Ir7vpOLKVUG4sj/9QhTELaFFyfZ+6OfBUFhzuXa29zvbQmRKWsX3ypK8rvRcFlwYR5Gaz4gQgXeIMqjH9uSEJSGY8Vio2zLpX/wX8vFr8xiSQPq/goRlpHyXN17W48p3IaJrLGKgbDQWp8UxvPy1YLzopaaOo3BqaaQobmF+zkeOCgt2c8U5d6to1f0mgw/+yy1e1TxUMnMbIrUpv7Lbqd6OvhbNZf+Q0ao2UCo6g2I67xs5TDXlrmPM8AwQpsFYzOhIyQ4iEKgatC5v/SDhA2MiBASGf7YhDmdwE8qRTWtqY8WMHWo7yqOfJaDXTx4zBn50yOsEvlXYgzkWswNZ5vquaLkvh5p4BcUKrF4Zfde377/il96nSdrbK7fsNvbqpw7AqIFSwZ+2Ghycb97DMTm6BdcpbabdYb3jeUoHlUPY3bPcaNsz2WSaLQYgnsZpJYikO1QRhmw0/+hxZxyQw3dZI9sq9+SBEVd7iaw2hOJGjoHwwIPyQMXU3iy6d+fxDFaJybM08UDk5dRN5kdAsooHJSK7iry1JGS+O9cnFJIDayS1X2NdqznCMx0pPE6Bb3cXFGe4tOh9b0ubjZkpBQr9juxa1xdaPNGaKDsRg/Rw5/6k+umtaOKXPHDCF5im2PwV0kMDn0Y3j58JhQUzH6KKWqhG1fpp5YcEE69HOJhkT9zgdqbEXs/Cx5KZb+Y+9TepRt1EZsKwbmIH6k5vFipVdNxr14y6c6XVukr/Uzbgh/QM3svPUvWT0s/K/URCz86O5X3YUXH5l8VFHMkazYfGIuGxRp6lLKpE6LO811HACJmEfnQoIQimD20wZhm7TPnUNSRWpPc14iU68HsAO+HBQaplMmsIJ9eCHUVCS/OBscf0IXqEFuefGKfgOGTo9GRIo4221AGBg/XamUUWQrrCQizt1WPMZa6Og2xw4YM4ZaodiWPGqA51lqRKMmjlyFDHg5c2 Z84hF7xs FVa3jroesjzumNAL0sSBJyNASY8440EfrCRsKeSU3zFodUuJxNKJ8DZwkxBWDhS4ViyRk4QZaXske8F/u0YTVvil/gNkcgw/maht6zIRw6Qgg7QwDVJzmypRnpUtvQMg3Vj7gbaduJeGLCYaLnrB5ApckTuZJyQH8/y74fvvPKkCOD5SxES3R53DUMWwH8KO0yop3kJfxPZvgrGVGgIGwnEX134DLefbqGwtX35oOEuFehfsUOvAnD96/xB34w+VeeOZS7ERuoynxHvJpXuBhZgDRoKDQYHiwsyuy+a8Ma8QcE9+ymCMM0GAHxJ4w7/6h3qcIfKwgEcmIHmNKbtaf9rUxi1WTXVvF23xKvUxCAoqo90K3Wh0ZewDf4Khb6gBom4ZSkC3dGSVhYi1bHnayOS7Lr2IVwdgIqZQ7/xO4TtHU0arTn0S0zHs/IuTgax6/yqdXQBsy65xvgwT6v/Q1mf0hyT9iYZgSzSqYnTp04Qy9/YRLEqKKmpSmlS+Q3lR/suXOi1olvljUhCi0ifwN5i+W7wg6FVVPk3d7olJLQSSnquGztGHBkh8sUPLOdcgzJffWWM8Ef0NKKEQ8G7MsvNiXRU7H95xHp+DZbKPT58hrBUQ= 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: 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. 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 Tested-by: Mark Brown Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 119 +++++++++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 54 deletions(-) -- 2.47.0 diff --git a/mm/mmap.c b/mm/mmap.c index aee5fa08ae5d..79d541f1502b 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1358,20 +1358,18 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, return do_vmi_munmap(&vmi, 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) { struct mm_struct *mm = current->mm; struct vm_area_struct *vma = NULL; pgoff_t pglen = PHYS_PFN(len); - struct vm_area_struct *merge; unsigned long charged = 0; struct vma_munmap_struct vms; struct ma_state mas_detach; struct maple_tree mt_detach; unsigned long end = addr + len; - bool writable_file_mapping = false; int error; VMA_ITERATOR(vmi, mm, addr); VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); @@ -1445,28 +1443,26 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vm_flags_init(vma, vm_flags); vma->vm_page_prot = vm_get_page_prot(vm_flags); + if (vma_iter_prealloc(&vmi, vma)) { + 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; - - if (vma_is_shared_maywrite(vma)) { - error = mapping_map_writable(file->f_mapping); - if (error) - goto close_and_free_vma; - - writable_file_mapping = true; - } + 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)); vma_iter_config(&vmi, addr, end); /* @@ -1474,6 +1470,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * vma again as we may succeed this time. */ if (unlikely(vm_flags != vma->vm_flags && vmg.prev)) { + struct vm_area_struct *merge; + vmg.flags = vma->vm_flags; /* If this fails, state is reset ready for a reattempt. */ merge = vma_merge_new_range(&vmg); @@ -1491,7 +1489,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; } vma_iter_config(&vmi, addr, end); } @@ -1500,26 +1498,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); } - if (map_deny_write_exec(vma->vm_flags, vma->vm_flags)) { - error = -EACCES; - goto close_and_free_vma; - } - - /* Allow architectures to sanity-check the vm_flags */ - if (!arch_validate_flags(vma->vm_flags)) { - error = -EINVAL; - goto close_and_free_vma; - } - - if (vma_iter_prealloc(&vmi, vma)) { - error = -ENOMEM; - goto close_and_free_vma; - } +#ifdef CONFIG_SPARC64 + /* TODO: Fix SPARC ADI! */ + WARN_ON_ONCE(!arch_validate_flags(vm_flags)); +#endif /* Lock the VMA since it is modified after insertion into VMA tree */ vma_start_write(vma); @@ -1533,10 +1520,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 (writable_file_mapping) - mapping_unmap_writable(file->f_mapping); +file_expanded: file = vma->vm_file; ksm_add_vma(vma); expanded: @@ -1569,23 +1553,17 @@ 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); - - if (file || vma->vm_file) { -unmap_and_free_vma: - fput(vma->vm_file); - vma->vm_file = NULL; +unmap_and_free_file_vma: + fput(vma->vm_file); + vma->vm_file = NULL; - vma_iter_set(&vmi, vma->vm_end); - /* Undo any partial mapping done by a device driver. */ - unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); - } - if (writable_file_mapping) - mapping_unmap_writable(file->f_mapping); + vma_iter_set(&vmi, vma->vm_end); + /* Undo any partial mapping done by a device driver. */ + unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); +free_iter_vma: + vma_iter_free(&vmi); free_vma: vm_area_free(vma); unacct_error: @@ -1595,10 +1573,43 @@ unsigned long mmap_region(struct file *file, unsigned long addr, abort_munmap: vms_abort_munmap_vmas(&vms, &mas_detach); gather_failed: - 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; + + /* Check to see if MDWE is applicable. */ + if (map_deny_write_exec(vm_flags, vm_flags)) + return -EACCES; + + /* 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 && is_shared_maywrite(vm_flags)) { + 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 unlock) { int ret;