From patchwork Wed Oct 2 07:39:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13819418 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 B9F7CCF319D for ; Wed, 2 Oct 2024 07:39:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A62D6B03D8; Wed, 2 Oct 2024 03:39:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 455626B03D9; Wed, 2 Oct 2024 03:39:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2814E6B03DA; Wed, 2 Oct 2024 03:39:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E71DC6B03D8 for ; Wed, 2 Oct 2024 03:39:57 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8AED91C6F33 for ; Wed, 2 Oct 2024 07:39:57 +0000 (UTC) X-FDA: 82627863234.16.F79E3F7 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf11.hostedemail.com (Postfix) with ESMTP id 3330C40014 for ; Wed, 2 Oct 2024 07:39:54 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=MjzIBUD9; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=A8fsRYf4; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf11.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727854653; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=9eUbEsxWhOhIVJAtv8eBLsX023BSzanoRbihYIh77QM=; b=fJOlztOsxQhnR0sWbUlcHiWw8HQtThV8c0Rc8I739c4a8yO7tFUlSIkcsl5AnQ+yViukB/ 0f6vZFlZ1L3TMGF6rAAkM5N7UOt2q+kxoWRBUsGuKXxrX+Vv8GaUrc/n+nzGVzLoQtQeqd LG6mFPDA/1l54+IjCdnFG+KVQfRmuj4= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1727854653; a=rsa-sha256; cv=pass; b=qyMKCN93c8x9u6ueDDyun5n/4vfKf11n6cnJYpqgAkD5wRnb04s30Q5o3h5TBwof5JREAv mGZMpTuZxsUf+/lROgaXfF4UIDqUEt51/NWs5KCoTm9rIAObc1+yIyao7v6hj8iRcwYEl0 XS+6Di7LZZWphF8fC+GriNdCsUIjiFs= ARC-Authentication-Results: i=2; imf11.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=MjzIBUD9; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=A8fsRYf4; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf11.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4926McUL031972; Wed, 2 Oct 2024 07:39:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:content-transfer-encoding :content-type:mime-version; s=corp-2023-11-20; bh=9eUbEsxWhOhIVJ Atv8eBLsX023BSzanoRbihYIh77QM=; b=MjzIBUD9oXZcEQhHPbNBnKZY39RHiC gtzLSVXrRbB834tmngU5NViPjZN30Iik5RcjA3owTtM/DgXPTg44nK88PS2TniX5 qACuyIcWcfQKxxqiFaIcMdWeXjAsWJUvXygoyIdXh+E8oKElSAGgYOp8eC0FP4tW Vi7yglYfRuIyB8v05jMkdlSDBmWbip9a3vx6/LccjuOnislOvVT711qyhxtRlEoI eRmA6yLbXiY2VPN5bRt5ofCIIuSSiS9udVlFv2NyzoqWACSDRlXKqXcCGMqcVAkB PxkGiYJfwOPpURs/4S/3yzyOitAwXD7NJjIFzpRtiH6sdOXc9+vSxFHQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41x8qb8a8b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Oct 2024 07:39:52 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 4927MZtJ038672; Wed, 2 Oct 2024 07:39:47 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2046.outbound.protection.outlook.com [104.47.73.46]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41x888kkud-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 02 Oct 2024 07:39:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qp8uXS0Pf0tADcB1/1tZuraQwtakN89zdZ0egL7eps/hbNd+7s52iKDzIFkdDcSqlkAG1/mfRIsLNf7yQ21x8uvQ7YSWn/965FxsR1O2VkD6ve/ROu5r7hj93dM88z+duk2fYRclyDoN/5SMK/PETUvbNYZJV+7+xFoRDPCc8o6tL1xEzOJ/AMVmNIs4Qc6mGRSRPCpuGYf4Ki3Z+Ptpk8LkFEmo/FeWqdZTQDyBUWTtIoPcSDE80pZdQke9GVN8Adiaj6g6QfLhwqtbwYPOeK/SQP2lijJle8s1IXjwI8RMdpJ0Vc8bby104XnIGIKiUY65GFNsgkHbQoycj8+0Ag== 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=9eUbEsxWhOhIVJAtv8eBLsX023BSzanoRbihYIh77QM=; b=Ny5x1zd8eRqZrM0Fr5jZs1YalpQs7H5c1l+2YXPLrBZr7hdhhER+XVm44KvIAPvbi67zLY7EGmS9KZrcqUCJH4m/4hihw5OQ6RFM621G5KwVRk2ZS/q3Lzsed5OlLmIiaEjRKECGQPzzaVzsNuvnxWFFBt/ewA+KivT5WAfO6nKEPSG/4fNmnDqr4yfYlEBTccTKFstN2ctBZkOtuv/MxeahIU0U/3/tLnaI3OW+eU7+xDXNeEFCm5T8xa6flEb97VBQdSORX5Zz6Av8qMwH2amrncFm6ipSsSxD8hDgWkIO0w8jbSSoZ+9HgqAfwaTuv7+HP4QEpACA/Liyh+iewA== 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=9eUbEsxWhOhIVJAtv8eBLsX023BSzanoRbihYIh77QM=; b=A8fsRYf4Nr3e5kTb71RAXsW0l3vfe/rlOuEAli7Qs/rA4wWDT3WbOOjBuiyIZiYP4snTjzwO64c7td4umiyTM9TSlSqWZFcmF05qsuX5/65vJH+JFrjB8DPjkVo1MabjkDGAp3f7p7dXB6Ray7DmJZarxVNI7550+I31EqB7gMU= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by CH0PR10MB5083.namprd10.prod.outlook.com (2603:10b6:610:dd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.16; Wed, 2 Oct 2024 07:39:45 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%5]) with mapi id 15.20.8026.016; Wed, 2 Oct 2024 07:39:45 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vegard Nossum Subject: [PATCH hotfix 6.12 RESEND] mm/mmap: correct error handling in mmap_region() Date: Wed, 2 Oct 2024 08:39:32 +0100 Message-ID: <20241002073932.13482-1-lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.2 X-ClientProxiedBy: LO4P123CA0419.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18b::10) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|CH0PR10MB5083:EE_ X-MS-Office365-Filtering-Correlation-Id: 997a95c0-2268-48b0-69f5-08dce2b562d9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|10070799003|376014|1800799024; X-Microsoft-Antispam-Message-Info: XbjEr4fL48dfUXUymiFc40XB0iov5mI4nnQQ+/Iz9iidnLoPrVqa4/t4GBOCbY0TylEHmzspuMZMmBMgg7+Vf00drSBu8GtPD024xQ3FkMTKmUSZK6pnqeztsuVu1CELuoj36tJlACMg6xbYCl2eYFEVbUSgopXY2KK3NO/ufLxvq63t4qDXaRom4PnFhvfJoqCQOyItRy67kIYX6tqjHdl2PR1bcYEtyowfClwGtKmB05hkc7K16YC6NQG3B//D9trQ/22w13auk9QsUUm3s9cE9r3NAhcwsVBhMYBRu9A8m7HJM7J13x43Koo/UyXyKtVwtbPWzls1WiS8GtekW15XjDg0P7kUc5Z5bjGBfrSeSuzU5CFsbhT8Gk1ICL1USNyuA2OsbcYsO0QFFYv22lg/LUcj7o0kbw9UH6GFRaH22lIQKtIIZKqyQtO0bkSW7YIbqLWMJVFjNMBoaRJZfJvzOrU2aYwAL+CtAG1CJD+z96QgTdQ2GnDdoJ7yQo7W3yHnv5jP0iWgnnWLypd2ejbXhknte/9QbwNkwrL6okayuqa5l9QVXEAQBr22IYpt81Nej/C4GpLNzixSuJfiyld6d0EaABexa0sLzMtIsFsAHycAuSOxD8rxuXzvyMotb42Nu3uc6n5tIhCnMbceYn37K2MX2bfI6arWyyO7UeY1elLSTlW8arcHvo3+58328T0tDOWg10vMxA2r7hdHYd3Q1NzAmryiObY+iPcpEsIup4vWT21ONRitlAZD2z/u3kaciLKp+wyP1VlTlyCzAUgi2b3Wgw+pqjkVTgXN1HNf/M3WBMw6EFdw5SjZBBe+5aLVKOzPwT1f60bs+2Osk2MT8svi+1jT1hAiFTb/BGF2W9FNMPx3zp7VkV18uzy+92TrN3fcleH2HC6T+xZij/n9WoMLtLu/SXgTXQCQ/oytxVL7MOQlnVIcVhF7IkysqNSX3yAJlf18lFQ5SZZU+Lf/Q/Q4amYR6yGjbieRsmm1fw4gSGzyRLM/8Qwk3OjNUktZm9dovjr/a2wk12KwbnXt+tkQfuhPlejKLsjj0xnUYKNF1g6TOJP3zqTn7qJNm6DIxs0wPKZPExRIUJfKT40hbm4jf6WP8zb/1JLgOpaly/C5hCaKL9NUVl0vXzk1EFSqBeBRxRzgQvnlKSIOw6Lt7c2kJB1L4CtgZc1XiuJr0jvsumFQCq5/4Dqa3HgE6nGJZsAgNzoQ4HNBv/QVBgOYUalIwVMAiAoH/aWx9RaEadcY7Lbu5zHrSFIsp9vr2fKMDePjJbmLp89xctoPdA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(10070799003)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: W7V87o0xJaFQfeYBvc2QoGLkySE7CEFs1YF6tnwwssrkk6P4bNabae8FvwAffOWM1eArvrzUyGowOeAlgHWgBkYzcvR9nrvmfSsTI9RtJgeO/VNlIJZgrUT3RZk+2gIOZRAfOrX6bhMd0pUNlTQwz5zqCA50hwHy6UElC0XqpsEmBPfIIR5oDlE6aae1SfXc2+jH5m21llRS43U9RDwzzP3RhlC9MWos1W3URmDf9F1K8a+JrX1430EsBVWe5GmRGW6QfXVEG48P3J1Jyv+se8HnwMg9IX9JWDSdON+VJa4MO/KaC56RW487nJFAuNk3lSH8w+6eQcKNSfvrA+hlnVN/TosvVBVUXhUNI6ZV7GmT2XWlpGV/nzqHR9U4m8vcyv5ylTQ/xzcRRuT7IVj7ncQ0HLxyypOrlLhJ9PEscWtzdt/CBDNAW5S34uBza0l8Oam0ne1KUCD+V8PPNIGrVbcsmgOxlA/w3Xu68NIhhmVqkv3ImfxTNr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PP8s0cd+uVagREpxuNgTKirK5SA2tXr4LYTY/vj5VWwCgunWxF2DQZrANXS7ctPd19bP3NevndauUqYxv11FO/Z262abI9Mlj4ofTMCcA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: svaGtoQBDjGzXvq5YbdIGmy3zJYeWnT+M62Z/lWRwcBkE4dVHpgyhPM3p2BSRMA48D910GK7R5BSHSjG+dPInVJZpyv7fDfkrzQyNRZ2fVibTv+aMyaeM0yW9QLkru3XCJuUpPVpEUSe6Qgt1knkuqfIH86yaVwzKAi1Y2QLbc/SOUcC+AmHD0K/uHIdZCyL6jGIFOomkTWdyKoEYjAJ6H8Xk+lyXK4wWfSjCvBl5TkYG6P0k708buMj5NqH6AppFDSU2wYQV9mn5oAWeHaNEhNsvZ9bdsGo/LoleeUhDy6NUpKr5Cj3rkiHI8tWOGxvB7FW1wlNM/nx43eDw/9pMBx1OHNpfK1RoffxCyjCOHEXfoVc+6SAIxAJweoJVWnPh36NNcirQu/tJzkUf4xbX6ybO79XhyZbmjlwKrNEEnDleIt7UFOVUtDDG1lTKHc2+czIO+HDOt0SXt9XfdWgoaAVoDje8S52XhKqBD+a2SuWJBFURRh7SuLdVphyW6GSUOCwqpK+Nb4A2mQ2sEQjFDu+SHxuCqCeDxm3OYN8tmLzn4FlnFsHWMS8V0Bw/FAHU+Gc5+h30HGD6BTSysyF1uJczduDt69TpwZJK9t8zeM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 997a95c0-2268-48b0-69f5-08dce2b562d9 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2024 07:39:45.5877 (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: GEWW5Ck7RF8luK0G9072A31i7Uv5xOofsYbU9koprLUw1xUlnNWZWDvsQGmUj7NyaRPUBfd1DfUpNGuN3K8v481kEqinJIJqN9u6VzHb6RY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB5083 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-02_07,2024-09-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2410020055 X-Proofpoint-GUID: jR_6ryQJGg9dahHtYbybRqMemjkeeJVS X-Proofpoint-ORIG-GUID: jR_6ryQJGg9dahHtYbybRqMemjkeeJVS X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3330C40014 X-Stat-Signature: dtq8wbt31fdpzbx6r5pjjr4gmjwot759 X-Rspam-User: X-HE-Tag: 1727854794-88437 X-HE-Meta: U2FsdGVkX182wOCwaZSZIMd5733U0jquc3eZqavKEytO3z6OtqbRHMMb11X51fwRWq2FOhbDEa5s+YsvZhbDscN2YNNMC92ITIsRB+vYt0UIMPhIU3JIekUYlbc57wGN7xTo2axBnQwNsV5NAEJ6Gz8heGUChayumeV7zOCW4tBGBO6H6eXVL2PsU6rD1Sr7e4QGGwYy/pvjRrX3oAeJcm1+kgi1SOykEc1UyEvg3RshazcTtReX0kZeM+MxPoDQhLe410OYfusQm2D3Ejhwz/8JokfV8e874zHEaBw1kzlfB5N3Rbs5ABto9WRHccVZ6BkTzO7c8gEmIcJ2FHK3eXpywA1dPtkqSrloMqnIL1ESTuejUnK8kXWQnGH/siJhqH7AWVs99W7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ES4EPHzkBQ4a4ADfn0f0X8P8EcGWiDfYqcNONVzjKLjjAQQGfHs2wwzevHISYtoDsaGm4y4XvkB1HLfLzTZrFa2D0zsQD4Ld0zNWROES2yjPbgpL7xLw== 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: Commit f8d112a4e657 ("mm/mmap: avoid zeroing vma tree in mmap_region()") changed how error handling is performed in mmap_region(). The error value defaults to -ENOMEM, but then gets reassigned immediately to the result of vms_gather_munmap_vmas() if we are performing a MAP_FIXED mapping over existing VMAs (and thus unmapping them). This overwrites the error value, potentially clearing it. After this, we invoke may_expand_vm() and possibly vm_area_alloc(), and check to see if they failed. If they do so, then we perform error-handling logic, but importantly, we do NOT update the error code. This means that, if vms_gather_munmap_vmas() succeeds, but one of these calls does not, the function will return indicating no error, but rather an address value of zero, which is entirely incorrect. Correct this and avoid future confusion by strictly setting error on each and every occasion we jump to the error handling logic, and set the error code immediately prior to doing so. This way we can see at a glance that the error code is always correct. Many thanks to Vegard Nossum who spotted this issue in discussion around this problem. Suggested-by: Vegard Nossum Fixes: f8d112a4e657 ("mm/mmap: avoid zeroing vma tree in mmap_region()") Reviewed-by: Vlastimil Babka Signed-off-by: Lorenzo Stoakes --- Original patch at https://lore.kernel.org/linux-mm/3de82936-2546-4bac-b8d7-76fa38811d68@lucifer.local/ mm/mmap.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) -- 2.46.2 diff --git a/mm/mmap.c b/mm/mmap.c index dd4b35a25aeb..9c0fb43064b5 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1371,7 +1371,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, struct maple_tree mt_detach; unsigned long end = addr + len; bool writable_file_mapping = false; - int error = -ENOMEM; + int error; VMA_ITERATOR(vmi, mm, addr); VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); @@ -1396,8 +1396,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr, } /* Check against address space limit. */ - if (!may_expand_vm(mm, vm_flags, pglen - vms.nr_pages)) + if (!may_expand_vm(mm, vm_flags, pglen - vms.nr_pages)) { + error = -ENOMEM; goto abort_munmap; + } /* * Private writable mapping: check memory availability @@ -1405,8 +1407,11 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if (accountable_mapping(file, vm_flags)) { charged = pglen; charged -= vms.nr_accounted; - if (charged && security_vm_enough_memory_mm(mm, charged)) - goto abort_munmap; + if (charged) { + error = security_vm_enough_memory_mm(mm, charged); + if (error) + goto abort_munmap; + } vms.nr_accounted = 0; vm_flags |= VM_ACCOUNT; @@ -1422,8 +1427,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * not unmapped, but the maps are removed from the list. */ vma = vm_area_alloc(mm); - if (!vma) + if (!vma) { + error = -ENOMEM; goto unacct_error; + } vma_iter_config(&vmi, addr, end); vma_set_range(vma, addr, end, pgoff); @@ -1453,9 +1460,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * Expansion is handled above, merging is handled below. * Drivers should not alter the address of the VMA. */ - error = -EINVAL; - if (WARN_ON((addr != vma->vm_start))) + if (WARN_ON((addr != vma->vm_start))) { + error = -EINVAL; goto close_and_free_vma; + } vma_iter_config(&vmi, addr, end); /* @@ -1500,13 +1508,15 @@ unsigned long mmap_region(struct file *file, unsigned long addr, } /* Allow architectures to sanity-check the vm_flags */ - error = -EINVAL; - if (!arch_validate_flags(vma->vm_flags)) + if (!arch_validate_flags(vma->vm_flags)) { + error = -EINVAL; goto close_and_free_vma; + } - error = -ENOMEM; - if (vma_iter_prealloc(&vmi, vma)) + if (vma_iter_prealloc(&vmi, vma)) { + error = -ENOMEM; goto close_and_free_vma; + } /* Lock the VMA since it is modified after insertion into VMA tree */ vma_start_write(vma);