Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1026256ybe; Wed, 4 Sep 2019 11:20:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxImpzzMWf1XTvNbieJwtKBCAJY64DXmRNcFPrVQqon8YC39aRPayh7FC1VqpZ4CWL30XMF X-Received: by 2002:a63:fe15:: with SMTP id p21mr36524941pgh.149.1567621243225; Wed, 04 Sep 2019 11:20:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567621243; cv=none; d=google.com; s=arc-20160816; b=HrOJqPkxE2rWibiiXh6zO0fG6AsRS567Oju4CvMujrVKhXyeW/hjlv4QORtnETnF5Z 5x88VmWo+14oDzqAyX2UsXCX5dmIQpIP3XKymW2N6QwCwWkT0Cuf4g0HuLZwBw85cvv9 eFSal0Q43PyvOwPZHv77YoIQYcqDM6NeTAY9QXS4dpiwsWZmp+zRjArJAtWA4fynA9EZ 6wT/QOjcgC5SmXf8lglIm85LGXJEVXKnf3iXGvdFp3inMQ4ymtoiXSUIX7lEKIufvOD3 20SuytjKfRcZRGM/F8oeM02mC5teHPapByPz4YUrt//mjncS84zLfaufr2b/4dZPqE5I 773Q== 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=7OR/+msAMMazdVCisopbF7PTa1SjBhFOyIXtywNItYY=; b=T2NRQhhE1dlHRtHZZEkQ3Z5H6Fln2hO735pl4XidysAeVGqbycOCzes21f/2ADqh7B Zp0fTLQSGyMs/vmG77YRCaxiYPpgrVTdpVF+EPpVRQpPmmZodxQAkIBIMrqbdaTaD3Nn 793BwHj4d1AglorlR1y+g35sx5dyhB7o2bOD09WnZBJloPylownVmUqaljlETCgatyhJ f0COkSRIu8GTkn/ssNinzWVY2nUgM6XZP65Fc5ECi4fgzmkFRW5ZoUOJkaz/gWoyIzmB h5PHvBwvVhlVoamTsyz1Ceg6GEUWokRqqLJEVkQhjkmWsvSC8oHcSdBBjwPT6IPxb8Qa CJJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mEBCCLj2; 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 h187si17291451pgc.6.2019.09.04.11.20.27; Wed, 04 Sep 2019 11:20:43 -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=mEBCCLj2; 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 S2390086AbfIDSKZ (ORCPT + 99 others); Wed, 4 Sep 2019 14:10:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:53952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390078AbfIDSKX (ORCPT ); Wed, 4 Sep 2019 14:10:23 -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 11A0B23431; Wed, 4 Sep 2019 18:10:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620622; bh=Uj4/zuuUy7gzUV351Ru+jlh1oqGrMcztChpiXKLtlGA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mEBCCLj2ET8ZdvZW0vqFzH+86nZQhIY5NUeetQKR5doeJ0dxrO8iTqXNfYEaYkoCg z2DXdJdXAfqgCO4LTWqBVQPN+3sGhn8Va0auXbouMM8RkN/WMJs+y5GHgT5yPOX7iQ 3JOlQV1dEL+1pAYWrycFpQdcyYUOKO1G91bUeG94= 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 5.2 033/143] xen/blkback: fix memory leaks Date: Wed, 4 Sep 2019 19:52:56 +0200 Message-Id: <20190904175315.347809559@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@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 3ac6a5d180717..b90dbcd99c03e 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -965,6 +965,7 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir) } } + err = -ENOMEM; for (i = 0; i < nr_grefs * XEN_BLKIF_REQS_PER_PAGE; i++) { req = kzalloc(sizeof(*req), GFP_KERNEL); if (!req) @@ -987,7 +988,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; @@ -1007,8 +1008,7 @@ fail: } kfree(req); } - return -ENOMEM; - + return err; } static int connect_ring(struct backend_info *be) -- 2.20.1