Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp611774ybg; Wed, 3 Jun 2020 09:05:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyz9EyqVeHHjGj8BlCLBh8UIfrfyKbcpKqy5U0rytsAFV4EPn4aUWZiMs7nSrdUfCdslJfi X-Received: by 2002:a17:906:971a:: with SMTP id k26mr42305ejx.230.1591200325071; Wed, 03 Jun 2020 09:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591200325; cv=none; d=google.com; s=arc-20160816; b=rCs/335AqvDmQ3Q+BS81Qgf7LWH0EFzec7IboM+K5+BdUhR2sXKP6HrRBN573HyUOC +bhuqw2+nnQVzrDvQf7du7DpsSrFSngVEr+vbf7+NL1g3recaArPnLkfk8WWDIbs6FUI w3ppEbCk83PufSMDLA2V9WPSADR+Hkb36LLvxu1WMarJWKP31mmFwYhRN+Pk8X6ao0KC jasMBPIQpEOWsp2L1dszbEtfCyJrdh0/5aL6SW4bPLtQC5qBFqGEDOSJ7+vG+IlxjiO7 8QYYuw7sVbynAl7d2OMnnzCm0uRMAKTSVYhwcBIuO3JjxBtYOM8StZmepgiPMwNGJ9wT UOQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Bt5Igct2/+Q1xvvWi2fPpQV0y5lZvkV1LTEUCIIRus4=; b=ZVcLCTFb0HmXJKrFkp/GID3gVcxvXmZ+j4PzEpSOReVW54ChCT89snfvsTkySb6A7V kON25SGYc8oXETsd7XTZtDdg6lMfF4mFIA4oVIkO8doDGicSBO9mEMq7JAfSkrYsX08T f97FIbPriRHfVsNwYjXWKmSBqdlRn9RPGkIUIph55FTnjzI7c2llMXurGlcpcIRJiXMQ yktp3EUNJOxfzZyldtIRXuO96OaoBEleYhxcktVYdsaixid4513AWrO+91TPgmpqNpfF CMP9cbBocuVC2mPwmrsm9SLojUbjZLjymg4NQm7qPXzKvY0fUWysv9TVVhYAVDwYzm/q Nv+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f12si1424056edl.157.2020.06.03.09.04.59; Wed, 03 Jun 2020 09:05:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726072AbgFCQDB (ORCPT + 99 others); Wed, 3 Jun 2020 12:03:01 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:57469 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725810AbgFCQDA (ORCPT ); Wed, 3 Jun 2020 12:03:00 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jgVqw-0006Bm-JU; Wed, 03 Jun 2020 16:02:54 +0000 From: Colin King To: Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Damien Le Moal , Hannes Reinecke Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] dm zoned: fix memory leak of newly allocated zone on xa_insert failure Date: Wed, 3 Jun 2020 17:02:54 +0100 Message-Id: <20200603160254.142222-1-colin.king@canonical.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King Currently if an xa_insert fails then there is a memory lead of the recently allocated zone object. Fix this by kfree'ing zone before returning on the error return path. Addresses-Coverity: ("Resource leak") Fixes: 1a311efa3916 ("dm zoned: convert to xarray") Signed-off-by: Colin Ian King --- drivers/md/dm-zoned-metadata.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c index b23ff090c056..130b5a6d9f12 100644 --- a/drivers/md/dm-zoned-metadata.c +++ b/drivers/md/dm-zoned-metadata.c @@ -313,8 +313,10 @@ static struct dm_zone *dmz_insert(struct dmz_metadata *zmd, if (!zone) return ERR_PTR(-ENOMEM); - if (xa_insert(&zmd->zones, zone_id, zone, GFP_KERNEL)) + if (xa_insert(&zmd->zones, zone_id, zone, GFP_KERNEL)) { + kfree(zone); return ERR_PTR(-EBUSY); + } INIT_LIST_HEAD(&zone->link); atomic_set(&zone->refcount, 0); -- 2.25.1