Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp276643ybi; Wed, 29 May 2019 21:12:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJXun81z2ouC+J14ODUItG8sv2b7K9c/pp2+LDdPrmRUfB211thFaOIC7uKnsY1ldQ9SPd X-Received: by 2002:a17:90a:26af:: with SMTP id m44mr1568483pje.57.1559189542738; Wed, 29 May 2019 21:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559189542; cv=none; d=google.com; s=arc-20160816; b=iFnmsYp7sBYoWxWp/Kl8QlXbzUD2TILLhafinF6s64fCoBUoP4CNITnoU7lVP27bnx 8ABG6yyVVIM13dRhQZ2JSYlq6iIVHCfpFSOyFcqjMGb4uvdtilh5k9COj3L+YoihTELo 143tcbUAlSGXdH4+4uS84XgFXC0XRoven7Fbk9DFNKNK8KOSObzytanPvF6gQL62HyL4 b5t46bzHXmRegMif7xTOG2FX22ARe96oaITtZ0PcxHLmbdomEIZS/kGKgr7dtJiFEvP/ Ja1avRfLp++2jRVsZLY8m0phB9yWdfnfKgn3qujfheTvffJ7RM8QA+Van0mg4FAczoAi Q7rQ== 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=ly0pi00H0BIxKylCNEwXlYuCHdnZbZOVVWzpq1QkTGk=; b=CM9HHlCzZOgjbN81dx6Pu4OyL/f9KB3HHfZfI79n/hMrME+ZD/VUwoDqQ0XpdB9QVp hBkVgQPWqJfYVPeqWUnJEXq/xwqUoohrFfrBY17do+79tMWm0rjyY5jshfe+oyQU2iqt YaXvh+E9MvxAg15bP+blSVEOrHy7fvvbRODnIj+RK6G01wng8ik0PhmiUE/myriJQaWo IK9XotONS6Gx8z2LjuqCeg9qsQkgQcGE/7bsvhHkYZHC1IvEcz5+iolSyZXsF5+z0veM 1X4kt6gRz7JFdTOYEw5ky/NoDNwk13KuInzNT1PM1Hz4M2BGCSVqexs3OPO7QJtVmWzB veeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bAw4O97W; 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 k18si2270830pfd.233.2019.05.29.21.12.06; Wed, 29 May 2019 21:12:22 -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=bAw4O97W; 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 S1729230AbfE3ELE (ORCPT + 99 others); Thu, 30 May 2019 00:11:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:44304 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730860AbfE3DQ4 (ORCPT ); Wed, 29 May 2019 23:16:56 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (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 77F0724627; Thu, 30 May 2019 03:16:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186215; bh=/5po97wS94LxbvL5IYE+3mvdM2mJsq4ckfhoYofjvhE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bAw4O97WogxRNjm3Eu/8/ir3S9NrLk8j81cjGjuUOFUMXaclI5GJwQkKtryveb9c1 P/F+12D/RCVMusd23jP0gTSWiFWs08LhIwgH9xqbYgVzOXOzxhuoJIrQGxhW6h9pFL iQtwNqfnr/3cEZr6hhv8sBwaudLkA1g5V5TrE2FA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shenghui Wang , Coly Li , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 102/276] bcache: avoid potential memleak of list of journal_replay(s) in the CACHE_SYNC branch of run_cache_set Date: Wed, 29 May 2019 20:04:20 -0700 Message-Id: <20190530030532.459829796@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@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 95f18c9d1310730d075499a75aaf13bcd60405a7 ] In the CACHE_SYNC branch of run_cache_set(), LIST_HEAD(journal) is used to collect journal_replay(s) and filled by bch_journal_read(). If all goes well, bch_journal_replay() will release the list of jounal_replay(s) at the end of the branch. If something goes wrong, code flow will jump to the label "err:" and leave the list unreleased. This patch will release the list of journal_replay(s) in the case of error detected. v1 -> v2: * Move the release code to the location after label 'err:' to simply the change. Signed-off-by: Shenghui Wang Signed-off-by: Coly Li Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/bcache/super.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 2c0d35c882ed8..d8190804aee9b 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -1777,6 +1777,8 @@ static void run_cache_set(struct cache_set *c) struct cache *ca; struct closure cl; unsigned int i; + LIST_HEAD(journal); + struct journal_replay *l; closure_init_stack(&cl); @@ -1934,6 +1936,12 @@ static void run_cache_set(struct cache_set *c) set_bit(CACHE_SET_RUNNING, &c->flags); return; err: + while (!list_empty(&journal)) { + l = list_first_entry(&journal, struct journal_replay, list); + list_del(&l->list); + kfree(l); + } + closure_sync(&cl); /* XXX: test this, it's broken */ bch_cache_set_error(c, "%s", err); -- 2.20.1