All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jinjie Ruan <ruanjinjie@huawei.com>
To: <brendan.higgins@linux.dev>, <davidgow@google.com>,
	<skhan@linuxfoundation.org>, <jk@codeconstruct.com.au>,
	<dlatypov@google.com>, <rmoar@google.com>,
	<linux-kselftest@vger.kernel.org>, <kunit-dev@googlegroups.com>
Cc: <ruanjinjie@huawei.com>
Subject: [PATCH 3/4] kunit: Fix possible memory leak in kunit_filter_suites()
Date: Thu, 31 Aug 2023 15:16:54 +0800	[thread overview]
Message-ID: <20230831071655.2907683-4-ruanjinjie@huawei.com> (raw)
In-Reply-To: <20230831071655.2907683-1-ruanjinjie@huawei.com>

If both filter_glob and filters are not NULL, and kunit_parse_glob_filter()
succeed, but kcalloc parsed_filters fails, the suite_glob and test_glob of
parsed kzalloc in kunit_parse_glob_filter() will be leaked.

Fixes: 1c9fd080dffe ("kunit: fix uninitialized variables bug in attributes filtering")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 lib/kunit/executor.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c
index 25ce8d6e5fe7..7654c09c1ab1 100644
--- a/lib/kunit/executor.c
+++ b/lib/kunit/executor.c
@@ -176,10 +176,8 @@ kunit_filter_suites(const struct kunit_suite_set *suite_set,
 	if (filters) {
 		filter_count = kunit_get_filter_count(filters);
 		parsed_filters = kcalloc(filter_count, sizeof(*parsed_filters), GFP_KERNEL);
-		if (!parsed_filters) {
-			kfree(copy);
-			return filtered;
-		}
+		if (!parsed_filters)
+			goto err;
 		for (j = 0; j < filter_count; j++)
 			parsed_filters[j] = kunit_next_attr_filter(&filters, err);
 		if (*err)
-- 
2.34.1


  parent reply	other threads:[~2023-08-31  7:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-31  7:16 [PATCH 0/4] kunit: Fix some bugs in kunit_filter_suites() Jinjie Ruan
2023-08-31  7:16 ` [PATCH 1/4] kunit: Fix wild-memory-access bug in kunit_free_suite_set() Jinjie Ruan
2023-08-31 20:29   ` Rae Moar
2023-09-01  5:17   ` David Gow
2023-08-31  7:16 ` [PATCH 2/4] kunit: Fix possible null-ptr-deref in kunit_parse_glob_filter() Jinjie Ruan
2023-08-31 20:34   ` Rae Moar
2023-09-01  5:18   ` David Gow
2023-08-31  7:16 ` Jinjie Ruan [this message]
2023-08-31 21:01   ` [PATCH 3/4] kunit: Fix possible memory leak in kunit_filter_suites() Rae Moar
2023-09-01  5:18   ` David Gow
2023-08-31  7:16 ` [PATCH 4/4] kunit: Fix the wrong error path " Jinjie Ruan
2023-08-31 21:03   ` Rae Moar
2023-09-01  5:18   ` David Gow
2023-09-03  6:37     ` Ruan Jinjie
2023-09-14 11:46 [PATCH 0/4] kunit: Fix some bugs in kunit Jinjie Ruan
2023-09-14 11:46 ` [PATCH 3/4] kunit: Fix possible memory leak in kunit_filter_suites() Jinjie Ruan
2023-09-19 21:18   ` Rae Moar
2023-09-20  2:34     ` Ruan Jinjie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230831071655.2907683-4-ruanjinjie@huawei.com \
    --to=ruanjinjie@huawei.com \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=dlatypov@google.com \
    --cc=jk@codeconstruct.com.au \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=rmoar@google.com \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.