From patchwork Fri Dec 2 04:53:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13062171 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 39C52C4332F for ; Fri, 2 Dec 2022 04:54:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD1F96B0071; Thu, 1 Dec 2022 23:54:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A81456B0073; Thu, 1 Dec 2022 23:54:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 922D86B0074; Thu, 1 Dec 2022 23:54:31 -0500 (EST) 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 839396B0071 for ; Thu, 1 Dec 2022 23:54:31 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4ED7A160E4A for ; Fri, 2 Dec 2022 04:54:31 +0000 (UTC) X-FDA: 80196150342.07.E43EE25 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2069.outbound.protection.outlook.com [40.107.237.69]) by imf15.hostedemail.com (Postfix) with ESMTP id D8999A000D for ; Fri, 2 Dec 2022 04:54:30 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Zpgw7dvl; spf=pass (imf15.hostedemail.com: domain of apopple@nvidia.com designates 40.107.237.69 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669956871; 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=eYItnzdsiY3AEfcdQW8RpuMJ0B/+tTQHWpJ8gVWAbE0=; b=xhZ675/u8qQLT+gklnMSZKKzmufg6jTv4DXn8CzPDzVylBD03kiKBDwWtliZC/uB9mhUHv Q72RkDuNhNbeJ+SQb3mAHzz+vCfCv7pvWW+czZD4sBtCvtx9h0iT0PtecZcx0AqcTR64UI LQBMwNNkoZA1jSKFbqz2J6qQO02A2Rw= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1669956871; a=rsa-sha256; cv=pass; b=hsOc76cMaQ2PMUrULdaBoX62Uu5IWCctqsPQJ1dcxPal9w2UiMBAtj2SQO5qmcEOXL6DZE QoqE2u8RvZ3u4tKyO/dNm+nGwZATNREg9CL3fKAXoTRsPxkhm4Ve4NeCZUYN62yvb+B5tU 7NlYvJsKohf7FinvwXXkhvDbUFbEHkg= ARC-Authentication-Results: i=2; imf15.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Zpgw7dvl; spf=pass (imf15.hostedemail.com: domain of apopple@nvidia.com designates 40.107.237.69 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h5UdCvg0JOGXlaDjFIfRkgvSx6TcWxUZghufo49NW5UcjoTO+b4LK7S67FbFEit7TV3PhCM2/yg4hUYTs+J9oEuhpCW4qrkEZayU9ppnVUVKmKGRX1HvfTaZQ9vW/GqK1uv4j5SQU10I3eJcBB6JreZYGM/DQfxGOQCz27BMOX4r7Dr9ldDQqjJoR2Y0WZZSwfspXHnfoS4vjNdxYTNl7SVI/hNT41/f6g7K4fal/0sSsAymcsZnytaGIjE/sXEk4kruxlAN2cqzUOILwpdOAa1DSsWEOv2w3rIlYSMVOuRWBtskIX74I5HwB1mUCTxb4pLmo2QEM2tjWHb4nXQhSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=eYItnzdsiY3AEfcdQW8RpuMJ0B/+tTQHWpJ8gVWAbE0=; b=areq55xvDkdrkZrZx1Vv3OVNQWI6VHTLa7HUDBJ0zQXnCw+N5WIRV3zc//mk/LhiRwi4l1AK4mtUibYrkOki9p/t6RQxMTsZzNyMI1wmU1T8ZrAUkJZ1cPLzcWEXeARaI+9YDDWRqxd4JVztZTNxHMvV+fSa4fV/7tVcAOZk2deae9V7uAVJqB+3XEyDJ23GZT/cZSuxPTLCDjeRyIU6TV1RP997eP+5eFmc2+rnZ2Q+uisXHclaZeGWc23pk7PY/NG2WliWNrHGXqLqwjXcigEhco2hoUs/Ahb8jmUyyB+vPV2yD6t/CRqGazOgI8m+a/77l7sc3SIfZsBUeitzeQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eYItnzdsiY3AEfcdQW8RpuMJ0B/+tTQHWpJ8gVWAbE0=; b=Zpgw7dvlaq98UwjcBgWtLh7KBjNSnYDYFKshBjUzSTVFLFogjRMgLRHfcStjYumQTtLkPm4aNnghmpd9sG/aQFuL/0eDbjX0RYuaG7Vdmo/jG4gT7gbc8iO1encEe99EevRKTwdyEOOi2Y4myN1N84LpX++DBhtxy0PFJYh/Zj8hAGJ+uToE2NbpHUT3C2SAIXuxD7MQX/bPJVHro0PNd5gox5mk6o3B2f+j9SOFubZS3CSXRs5yxuyadazrVGWcLFtuYGGM1UFR+rXhN7ZbYqjlADHklFBQ6LHNL0IsHGyjORRrjM1HLxGZeYDNB7xxkFrQh2Td8h+oynZlCDJQTA== Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by BN9PR12MB5365.namprd12.prod.outlook.com (2603:10b6:408:102::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.8; Fri, 2 Dec 2022 04:54:28 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::ecfb:a3ad:3efa:9df8]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::ecfb:a3ad:3efa:9df8%3]) with mapi id 15.20.5857.023; Fri, 2 Dec 2022 04:54:28 +0000 From: Alistair Popple To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, liam.howlett@oracle.com, Alistair Popple Subject: [PATCH] mm/mmap: Properly unaccount memory on mas_preallocate() failure Date: Fri, 2 Dec 2022 15:53:39 +1100 Message-Id: <20221202045339.2999017-1-apopple@nvidia.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: SY0PR01CA0002.ausprd01.prod.outlook.com (2603:10c6:10:1bb::6) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR12MB3176:EE_|BN9PR12MB5365:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f1de8f4-ec48-45ed-6519-08dad4214adc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uH1z3Ra64mFdBZDSENTchW3XEaq3/TCUNQI5z+A+y+biGtg4en+Bl9+PknK7Wz1hK3Ef5LpP8UjRgKrVODEEoTlWfoBkE10h83llINT6KOpebDMIWMF1yv25F1pWQfAouBMqs/+bJr5TyzdIAtUqyVoJUBTTkUnKea7w9aludT3nMsqFXFjnXPmOuDSwiILeXIS/LMfv9f7GdFFVjWHvV2Ct8DFxCR5l7VFDHjvbDRjb0O1gxci2dGeLnp37VfOFQU5oM+R+fH6iZRbQZGdjYi30+Zmn9ZDHSFlutwj7nb56Lek5strV0WEGwA0SmzMeC3YX5Cam52ALXQP3ijN0T6uZqNaLfU+Br17OOn1bVJaBg2t77Tfzc+nq5piclTkgl1DGVaXKZ683qTiz4Xh8hAXBKfkujpUaBjzM+G18hwXxj1rno2VdA6mlInLe9CFCaujq0uEjB4d8J0MHPdSV2WBA9CCYdaSQuw/kUxWbo0kjcLNepFiFqHdaI51eF4jLPyOOCsJhvy0fPWU0QpHpNW2a5RSGCvssVT7N+qFSoy263m9e4ehgNi1dwVVs81oUaRYutKkajsI1Q3Z+ikoAw4xoC4ooBCzfn3NxLUqjf14xGpuOoXeV9McTZs2bLe5kHCa6cNehHwW4SaqpvBW0Mg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR12MB3176.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(346002)(366004)(39860400002)(396003)(136003)(451199015)(38100700002)(6486002)(36756003)(2906002)(66556008)(8676002)(5660300002)(8936002)(41300700001)(4326008)(86362001)(6916009)(66476007)(316002)(66946007)(2616005)(478600001)(83380400001)(6506007)(6512007)(1076003)(186003)(6666004)(26005)(107886003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WWTF+z1+mvmWkRNvzHSzr1J4w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x72xX7yegM+92GpaRTQb/9JuysK1YXtntctgpS+pO1C7LM/ka+CjO5ZtEiW5V9xZTNN4nJ5HHH81GvDXoASDvYHbftXGsLlhkCfP4FwUYq2PQD6CAGhHA0gS+qrUSo1fODArHjaR2qOwCjS5ge1zasX4i5OYQzdmEn52kW6WT64AJetrz6ZdtKJL0w1R8XYL7Ue1CvkZUd/duuhqJzgQdQANnPTCGCmT/8Sjwyz2GXoX74dH9y88cMaX2aW/5uJsyrEgWc8Y5kI+swdUJXqkhudbVZ7NzG1V/2D69ovx7AlLV/rKozjupBReGKM0wpINylJ0PZhKFzWJKpe8ensJxfdM6gQ8Jy2wlM+KHotDvEgiCqbP3FOGr5yW295xifAe6+JJd8qdq7SBbTuZEsgJS277zdNwTmksVpCzaTTYOvSzuY5Dss63mupDxjOAmdG612uVsppqRZY5zNZJigqEmbE1WIxXCbsqI9AXDW3SkyGuweDCr40SZC X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1f1de8f4-ec48-45ed-6519-08dad4214adc X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2022 04:54:28.5219 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NHf4E7bOco7COCPRdHU9zoY3l0shxBlsKGibjwIl2Zz2UeT+1pLP9qaCetmknF+ZGlnrX6ghl97I1hqTrAR1wQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5365 X-Rspam-User: X-Rspamd-Queue-Id: D8999A000D X-Stat-Signature: da333b1yrdums9cyc5iwo5oxb585sy5r X-Rspamd-Server: rspam01 X-Spamd-Result: default: False [-0.22 / 9.00]; BAYES_HAM(-2.82)[99.22%]; R_MISSING_CHARSET(2.50)[]; ARC_ALLOW(-1.00)[microsoft.com:s=arcselector9901:i=1]; MID_CONTAINS_FROM(1.00)[]; SUBJECT_HAS_UNDERSCORES(1.00)[]; DMARC_POLICY_ALLOW(-0.50)[nvidia.com,reject]; R_DKIM_ALLOW(-0.20)[Nvidia.com:s=selector2]; R_SPF_ALLOW(-0.20)[+ip4:40.107.0.0/16]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; DKIM_TRACE(0.00)[Nvidia.com:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=2]; TO_DN_SOME(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_THREE(0.00)[3] X-HE-Tag: 1669956870-747939 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: security_vm_enough_memory_mm() accounts memory via a call to vm_acct_memory(). Therefore any subsequent failures should unaccount for this memory prior to returning the error. Signed-off-by: Alistair Popple Fixes: 28c5609fb236 ("mm/mmap: preallocate maple nodes for brk vma expansion") Reviewed-by: Liam R. Howlett --- Pretty trivial fixup that I noticed was needed while working on the code. --- mm/mmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 74a84eb33b90..3e50a571c3c4 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2954,7 +2954,7 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma, ((vma->vm_flags & ~VM_SOFTDIRTY) == flags)) { mas_set_range(mas, vma->vm_start, addr + len - 1); if (mas_preallocate(mas, vma, GFP_KERNEL)) - return -ENOMEM; + goto unacct_fail; vma_adjust_trans_huge(vma, vma->vm_start, addr + len, 0); if (vma->anon_vma) { @@ -2976,7 +2976,7 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma, /* create a vma struct for an anonymous mapping */ vma = vm_area_alloc(mm); if (!vma) - goto vma_alloc_fail; + goto unacct_fail; vma_set_anonymous(vma); vma->vm_start = addr; @@ -3001,7 +3001,7 @@ static int do_brk_flags(struct ma_state *mas, struct vm_area_struct *vma, mas_store_fail: vm_area_free(vma); -vma_alloc_fail: +unacct_fail: vm_unacct_memory(len >> PAGE_SHIFT); return -ENOMEM; }