Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3121382rwb; Mon, 15 Aug 2022 18:38:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR703N1Sgd6U0B9hQ0His9+tj4XMSdzQNYQVzDT7ByA/UOBtRWq+SMWFPRl3A50xt5NsYGJE X-Received: by 2002:a17:902:b086:b0:171:2632:cd3b with SMTP id p6-20020a170902b08600b001712632cd3bmr20526629plr.111.1660613928120; Mon, 15 Aug 2022 18:38:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660613928; cv=none; d=google.com; s=arc-20160816; b=cIZbHrhpHShPDqC8LL3Z57ua5F6a8tQNyEVsDCDy6a3FxUohJkfLEI+DtP8iUOab9r U8TxUmKTjsckNJqS8JwiR+2vZvjZF5czk2+CSl7WqeIdNngG1vjwdFKVmmzosM+Nl+vM 0yfWC5+817Cd+77HWpu+aaKR4aT2bsWKZldDQ8lLRfqIoPJEXvVB3QRk49nXDa+2V5MT 0itENwqCzedOUv6Jk1itOevkSLWk6dAMffXN82enchV7V3BKOyJ8XSct2D6tMWDypGma oj9U1H6zHEUYCSDIseg4WWug5CEBtkXSvdfGpYAuOHB1YezYzJp0j0nX55mT9UPJRg4c 34KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rt/3bJvp4g0bR8y9u24cHRaMUY3S+NcxWuquPfrSzbE=; b=xQ5yZzAI50WAyO5+cia93CblDW0tkRO4IlH+FtSeDRv5madrE7u2HR83zp6FRmXXkP W+ItGCRW6SKUA5hTVCKhj6jBEldftAA2x9BJaFp8wA+HS2eGdcoYQNhO1dUVWzwmG18c PZ2Bv44eyqofwECyTSt+QwItKBlo4DFVdSCRoeqSypNSo5WYo+6mIpywBObQBIe1GoZg rLMW64XY8+uC+hqcDaz7oi4Cf16g1KXGoOrXylao3sIgik0aoR//ez9fkhWZW6y4u/jf pJslHVKB7cijMiTMPYxd/oL0Wn2GrJBTJRBynCaSR1OTPa1UAEsup0lt0DORHDIZyVXG Y1aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aQTuVCQv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s34-20020a635262000000b00419dc0c2d71si12217230pgl.115.2022.08.15.18.38.37; Mon, 15 Aug 2022 18:38:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aQTuVCQv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354624AbiHOX5A (ORCPT + 99 others); Mon, 15 Aug 2022 19:57:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355290AbiHOXvr (ORCPT ); Mon, 15 Aug 2022 19:51:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9A6A91D07; Mon, 15 Aug 2022 13:16:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9CE4FB810C5; Mon, 15 Aug 2022 20:16:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F184DC433D6; Mon, 15 Aug 2022 20:16:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594584; bh=4Ad6WHw+VEo7Yt24zjkg9al8JR/d0E217Ezuc9hpe3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aQTuVCQvRb6G4kaTJBXClG30dZUNULVxnIIzdftnV382+LLcpJaXfbK4/VbctqWGY K909iC+Igd++X5ERCBAfIY/QKa45pd5q6CL6g1Zxebh7SDRSAPYsqqJRP11aB8zdA1 yKxW1GqnN/6yj2MLpfxLWFvbfcH4E5fwZpws/wSU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , kernel test robot , Dan Carpenter , Daniel Latypov , Brendan Higgins , David Gow , Shuah Khan , Sasha Levin Subject: [PATCH 5.19 0495/1157] kunit: executor: Fix a memory leak on failure in kunit_filter_tests Date: Mon, 15 Aug 2022 19:57:31 +0200 Message-Id: <20220815180459.456122374@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Gow [ Upstream commit 94681e289bf5d10c9db9db143d1a22d8717205c5 ] It's possible that memory allocation for 'filtered' will fail, but for the copy of the suite to succeed. In this case, the copy could be leaked. Properly free 'copy' in the error case for the allocation of 'filtered' failing. Note that there may also have been a similar issue in kunit_filter_subsuites, before it was removed in "kunit: flatten kunit_suite*** to kunit_suite** in .kunit_test_suites". This was reported by clang-analyzer via the kernel test robot, here: https://lore.kernel.org/all/c8073b8e-7b9e-0830-4177-87c12f16349c@intel.com/ And by smatch via Dan Carpenter and the kernel test robot: https://lore.kernel.org/all/202207101328.ASjx88yj-lkp@intel.com/ Fixes: a02353f49162 ("kunit: bail out of test filtering logic quicker if OOM") Reported-by: kernel test robot Reported-by: kernel test robot Reported-by: Dan Carpenter Reviewed-by: Daniel Latypov Reviewed-by: Brendan Higgins Signed-off-by: David Gow Signed-off-by: Shuah Khan Signed-off-by: Sasha Levin --- lib/kunit/executor.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c index 96f96e42ce06..16fb88c0aca3 100644 --- a/lib/kunit/executor.c +++ b/lib/kunit/executor.c @@ -76,8 +76,10 @@ kunit_filter_tests(struct kunit_suite *const suite, const char *test_glob) memcpy(copy, suite, sizeof(*copy)); filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL); - if (!filtered) + if (!filtered) { + kfree(copy); return ERR_PTR(-ENOMEM); + } n = 0; kunit_suite_for_each_test_case(suite, test_case) { -- 2.35.1