Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp704474ybg; Wed, 3 Jun 2020 11:21:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxry23JsEERRfASOIEo0qRcb0sUKlZySNzQ6w9lzDIgrZObR2Trycc4E6qJWfskEIwknD5M X-Received: by 2002:a50:f05d:: with SMTP id u29mr674861edl.229.1591208475642; Wed, 03 Jun 2020 11:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591208475; cv=none; d=google.com; s=arc-20160816; b=HIV8tCOFPKNAmICp77xJ3lZMdtdpM2O9PcSa5s7VKzKiay0h0RDrCT6VC/bRo2D7V1 JAPmrheZdj5ZavVdauHxH0J8Mc9jrgfCJHAKrPhrg+soV4Kz0TlRhc6fNu7Zw0DZIgRn gAZb1XHbn9uXphY0AZ66dRcHQ5aORxFs66JAKIHeB/nc0QaN74t4m9cL7bE9JIO96LVG 3xzWTSROF0c2pNos2hKam3hPhuP1nNEOO4d88yuZstrkYKJGPhmVA4oHwYLaby5nfw9k 15WMeDXF9LDgR0PJx/MzGsFDUQw1aY49H70NjVBb3+Pc/MTar4dlrzLqS5e3Ut5mZ0+l cJgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=UkKBC6zpB37rxDLDIC+RaxGcnQKeK/Foj3RIordPx/Y=; b=McIeTl2BeauK1BwFyDCJwo87xo32f+PgT7uhsZhLkpOb9GuzqmNPnvy/oaj9dGKNKG aux1B8IqDVouw5I9E4pqjgujP1k7JjDO0Z+60gBJ1V5/Cwt4jFEDSQkqHdpHV6CSEixc Tc9y0vrB0O0xTIihMbI2OxW1aKlBnVJVVEyUOQ4CftH2oxx7Km6oayDGEVTlWURczvMA UY++g9N0mMCYlEMHJloahFMaMLgP8RkatqhZ6kqNG3ekHe1dQFS+vayUZM8DpVP1qwuM UntzOmxVEmtkhndKMaPMx/8jUy52aiVplYbMJZ0OfmGzewClnxn/wEtIVomO0jHljrpT xgGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LiuEXiDd; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a63si195469edf.135.2020.06.03.11.20.53; Wed, 03 Jun 2020 11:21:15 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LiuEXiDd; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726050AbgFCSS4 (ORCPT + 99 others); Wed, 3 Jun 2020 14:18:56 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:50392 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725955AbgFCSS4 (ORCPT ); Wed, 3 Jun 2020 14:18:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591208334; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UkKBC6zpB37rxDLDIC+RaxGcnQKeK/Foj3RIordPx/Y=; b=LiuEXiDdo7nIMLuNKxS3UVUSAHM0dMvzeoJAbiJtyqH6zbT3hipQMAoN7hMvhHym/wGtiC +mxySf+wJTVyHg8xKh5saQlls9TgR/WVDAoGngLSLdHwSg46lOfoeDeGsJgxzKIxJYeekj jzgqiz+HPzLrHBUvrDMHVJAu4J65MXQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-224-fmXhd4wzOWqUKzKBFaBrEg-1; Wed, 03 Jun 2020 14:18:50 -0400 X-MC-Unique: fmXhd4wzOWqUKzKBFaBrEg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB86C1005510; Wed, 3 Jun 2020 18:18:49 +0000 (UTC) Received: from localhost (unknown [10.18.25.174]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92BF061169; Wed, 3 Jun 2020 18:18:46 +0000 (UTC) Date: Wed, 3 Jun 2020 14:18:45 -0400 From: Mike Snitzer To: Colin King Cc: Alasdair Kergon , dm-devel@redhat.com, Damien Le Moal , Hannes Reinecke , kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] dm zoned: fix memory leak of newly allocated zone on xa_insert failure Message-ID: <20200603181845.GA20491@redhat.com> References: <20200603160254.142222-1-colin.king@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200603160254.142222-1-colin.king@canonical.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 03 2020 at 12:02pm -0400, Colin King wrote: > 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 > Thanks, I folded this in.