Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1029535ybe; Wed, 4 Sep 2019 11:23:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPmBJAlH3ePnyXyr+9oKPoHu3KOjprenP2bJFmstSNitcBaJBNjMOHPnctqzfjTtBowPsu X-Received: by 2002:a63:ed55:: with SMTP id m21mr36455918pgk.343.1567621431724; Wed, 04 Sep 2019 11:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567621431; cv=none; d=google.com; s=arc-20160816; b=0+mgWoPxamGv09nknO/QScPNaLzaNhoSfMogED+Paiq/Sfgzd5dioNxWvvPuGak0wZ t1poDh/5EB+zHDmHaf1KWLbfs+yUNw6c3HQ9iogaTcIHzKUkn0dap4A6/TnsOoR2T3K0 vkPRmho7mNIa1eSAgXviUcvNDUGrhhpyzE1ULsmdKbBGplBtt4/QojQP16MaO+Xhp7Fu hTq3D8ik2zCfEYjfcnFcr19UgUU8Oh49jJLDgix76YZCL5EB3GOeULrlHFStaEGqEBti ynhSEjTQTKxqyH/bcSsyfU8cTz9FBQ7JYFROZg1ymH1gRpKnIXDeM7lGbVj01uw6FxQ5 rCfA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IAyj3ghM2PvF/hrv0R8qc6p5TP7AmuxDxwCXp8fDEV8=; b=lCzVqWskOEqSq2By6VtJwk0zs8P4xi2ChiQsKoSHFd2Dj8RwoTQcUDf9QQpsChHz4z 2wqi7TacBJd/IXlejpBwGow/t3J4B7EVHVUVcbuD4TWzDGGzZdgPaEpZEDAb5qVIToyP Pgb4X72j+/p0jQv8bm2OTcX2JlWCfn1NOAu1gzeX7e8xj90xVwO2jFVWMXv/sK9naes7 t2K3cnCBhcRQ3l2vhRSD4NL1mJZ/WfcQ6/itsT+kWCRczYuz5u7vEvx2jkapzdO7m79U kKUvj5UqCuRKGZaCix1tcYuVcrW/y+kVoatpSUGS+23LsOt3Q4w++YKR49WUpc/zqOeo 7BHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fMDAkN63; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w15si17982139ply.218.2019.09.04.11.23.36; Wed, 04 Sep 2019 11:23:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fMDAkN63; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389267AbfIDSFc (ORCPT + 99 others); Wed, 4 Sep 2019 14:05:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:46990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389262AbfIDSFa (ORCPT ); Wed, 4 Sep 2019 14:05:30 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9AD89206BA; Wed, 4 Sep 2019 18:05:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620329; bh=u5ck0fkX3qv3H5phSRhaxrje/C6WufWq1kccdS4lqLA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fMDAkN63xp1K+deE9i+fK/kbX9bbCDcuoBPPblHiAWMwiXwuJpn0Pu+wzX6OnXLng DIpGPF/YXxTh8AalUcslJ26ZoMnH85k44WbINjDQK8yAfLnoKFGaK4OGtG5CHfvu1u o7y9xt7K2/uyL/AJxp1Hv5Mbtt+TtGwz7ZyhjJhM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Boris Ostrovsky , Wenwen Wang , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 18/93] xen/blkback: fix memory leaks Date: Wed, 4 Sep 2019 19:53:20 +0200 Message-Id: <20190904175304.932938222@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175302.845828956@linuxfoundation.org> References: <20190904175302.845828956@linuxfoundation.org> User-Agent: quilt/0.66 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 [ Upstream commit ae78ca3cf3d9e9f914bfcd0bc5c389ff18b9c2e0 ] In read_per_ring_refs(), after 'req' and related memory regions are allocated, xen_blkif_map() is invoked to map the shared frame, irq, and etc. However, if this mapping process fails, no cleanup is performed, leading to memory leaks. To fix this issue, invoke the cleanup before returning the error. Acked-by: Roger Pau Monné Reviewed-by: Boris Ostrovsky Signed-off-by: Wenwen Wang Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/xen-blkback/xenbus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index a4bc74e72c394..55869b362fdfb 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -974,6 +974,7 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir) } blkif->nr_ring_pages = nr_grefs; + err = -ENOMEM; for (i = 0; i < nr_grefs * XEN_BLKIF_REQS_PER_PAGE; i++) { req = kzalloc(sizeof(*req), GFP_KERNEL); if (!req) @@ -996,7 +997,7 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir) err = xen_blkif_map(ring, ring_ref, nr_grefs, evtchn); if (err) { xenbus_dev_fatal(dev, err, "mapping ring-ref port %u", evtchn); - return err; + goto fail; } return 0; @@ -1016,8 +1017,7 @@ fail: } kfree(req); } - return -ENOMEM; - + return err; } static int connect_ring(struct backend_info *be) -- 2.20.1