Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3018212rwb; Mon, 15 Aug 2022 16:14:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR6oVYf3QKfoX06N/IgJD8p2zaFFjh9lCM0QeXMLTnfbpZecd20w8NRZNHsHSLpyy5kngKKi X-Received: by 2002:a17:907:6930:b0:733:621:8437 with SMTP id rb48-20020a170907693000b0073306218437mr11710025ejc.111.1660605297610; Mon, 15 Aug 2022 16:14:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605297; cv=none; d=google.com; s=arc-20160816; b=Cz/UkY/BvNviRQcBb9NUfKdrQbzBS/6U920P0JwzDbBZx2lFtLJPf9b/EWjgPvwMg+ v9ChhjFkDdVPdxPS45Ezn/+vLg2uCn0Fksadj4n6kLqOcitjxvo+1Jy8//aQmTepqwSs FCv4sBKeapxHnz5T53ztFaL1SvESp3XjOYTmRaJQf/WZ3MCFXA5DCx/eoNzb2b01J9su EP+3TE6c/2Ikr8tDGW2LcE9ln3YCTrIBp80UaQMFhYExakI7I2dt8V29vFHXDyq0l6cB y/31M/5CelR1wcGUxDSfyZmAdhS6IAkVc3tydg7Wwn5A0l2Uuw8ILraHK4jE02w563PW pcUA== 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=I+0nhU0Ppso8V+7hjA27oNiWrqTYISec/YrXnPAsQuUMK2eS6gZiH6PwJeDttApSYf gyzz3uFDeyvDVxbsBCTIWKuMKjjNaxTHz7CGq/MztcpcYE3muJ92DC3f+Q8w8tYoAaYz kQGXHGi4w6oA8N2q/f97qu/ageqXPSTUtE7CBa8rOhs1Kxg/LwISM3csRkD+gXcRFQv/ biRfNmtBzFl+eOHJxc2usljQ0uGwX/eY25+FsZ4Z+uNRXz+c9yn10Gq0wRf6v8s2Dfa8 CzbTryzSMYrgUZvpUbH5TzKiwciZ9Gyw3NBZlachMFc5DBiJ5puxUb2UsDQ5IRNWe+U+ /DYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Amv5AsxW; 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 h19-20020a056402281300b0043def0e25c9si10171392ede.20.2022.08.15.16.14.32; Mon, 15 Aug 2022 16:14:57 -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=Amv5AsxW; 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 S244469AbiHOVQ3 (ORCPT + 99 others); Mon, 15 Aug 2022 17:16:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348014AbiHOVH4 (ORCPT ); Mon, 15 Aug 2022 17:07:56 -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 E4CAC2DABE; Mon, 15 Aug 2022 12:17:47 -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 A48C7B8107A; Mon, 15 Aug 2022 19:17:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA626C433D6; Mon, 15 Aug 2022 19:17:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660591065; bh=4Ad6WHw+VEo7Yt24zjkg9al8JR/d0E217Ezuc9hpe3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Amv5AsxWYHSfZ87qjf5Zz6+mUd+BWMF4HikuKyt9IgpFGS3/Mo6h7v9nFFYJgeKJ6 pl7H+WdFpChSQqNL9BDdtcVkH7O81Du93YEWCrQbgHfMSSc8fZlGO28XjhQVhxlspH 6J+294X4cDmLRtf/2wZTYBE2LQbvNl3MLKrXqnDc= 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.18 0459/1095] kunit: executor: Fix a memory leak on failure in kunit_filter_tests Date: Mon, 15 Aug 2022 19:57:38 +0200 Message-Id: <20220815180448.591050196@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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