From patchwork Thu Aug 29 09:52:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jens_Emil_Schulz_=C3=98stergaard?= X-Patchwork-Id: 13782925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A6287C83027 for ; Thu, 29 Aug 2024 09:55:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:CC:To:Message-ID: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=72gHZwC3K3b58K+SOCMLdlVMUV0T4Ye1Osw9/iI5SSw=; b=slmqyCYQm9rAlaFZ/38G0L48cJ qQhQnmxcfKBT0L7bL6ve8O33CBczGsE/zFcVEEaELGiLjvtUZS+WPHroraoE5e1ovSKP82s/XsORM 6MklpDVeKPtirU+ZFoF29G5R5JgOJgPduxfG4uifA5vDWfWka4t4gHpo6Hp6jy8pEPJIDoKvgMBFh 3MCD0n8jd9unqpz3GuqtWwmihkNT+t4NloyXi4WG1YwBTvZ1mfJpWYqA9/CCNfQEhHZ1aNg7mn0fU eRVSJgi9BlDU6xTZhXFh+XfvL5Hent1Ev0deWLBfS6C3JYoazbkx2Vs+O4oDjkqtVIYt+3YgD/SGK 8UGM8LFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjbs2-00000001Sue-2kYM; Thu, 29 Aug 2024 09:55:14 +0000 Received: from esa.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjbrC-00000001Si7-0vUQ for linux-arm-kernel@lists.infradead.org; Thu, 29 Aug 2024 09:54:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1724925262; x=1756461262; h=from:date:subject:mime-version:content-transfer-encoding: message-id:to:cc; bh=Gk17cpiqIhML5adE8yFx9OsBS/qqAMi2cjj/Day63Xg=; b=wC0FJErjVNTjpszpp51iYQs0GrVywzDr253hqeLTv4Am6a8yu/7DXVDe SIu669a/426hPsjQtV4NsWoHEVSyMIb5TED5qtW5vcH25mxbzDg/jrBjs mjKNw2YeLzloFqD8a91AKbfjRha50hREDzhzLm6I7SdGWKxlPZx6i4nG2 Nyc2Vdf4f7PKF3fajSnsW8hC/YJSNQN83VOod5SUKnAPinXyuFin3Bfev PaZBZbmhixX0kO8PL1ZdH9uNQCMsZ/uBItmjFOktI1Pown8w7STXy13LQ N4QvDTf4s5LtbCP4HC0EsE4uKJmONOkmk7+KdrQeKOxJTFIh8WDdelHFM g==; X-CSE-ConnectionGUID: G6KB1Yj2TT6z492XstGQ6w== X-CSE-MsgGUID: Yzs25oY3SjaweLI6DgflTw== X-IronPort-AV: E=Sophos;i="6.10,185,1719903600"; d="scan'208";a="31043205" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa3.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 29 Aug 2024 02:54:20 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 29 Aug 2024 02:53:35 -0700 Received: from [127.0.0.1] (10.10.85.11) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 29 Aug 2024 02:53:32 -0700 From: =?utf-8?q?Jens_Emil_Schulz_=C3=98stergaard?= Date: Thu, 29 Aug 2024 11:52:54 +0200 Subject: [PATCH net] net: microchip: vcap: Fix use-after-free error in kunit test MIME-Version: 1.0 Message-ID: <20240829-fix_use_after_free-v1-1-1507e307507f@microchip.com> X-B4-Tracking: v=1; b=H4sIAPVE0GYC/x2MQQqDMBQFrxL+uoEkSlCvIiXY9EX/JsqPiiDev aHLgZm5qUAYhQZ1k+DkwmuuYF+K4jLlGZq/lckZ15rOeZ34CkdBmNIOCUkAjU/TRhO9t66nGm6 Cav2nI2Xs9H6eHyZ5qfhpAAAA To: Lars Povlsen , Steen Hegelund , Daniel Machon , , "David S. Miller" , "Eric Dumazet" , Jakub Kicinski , Paolo Abeni CC: Steen Hegelund , Dan Carpenter , , , , =?utf-8?q?Jens_Em?= =?utf-8?q?il_Schulz_=C3=98stergaard?= X-Mailer: b4 0.15-dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240829_025422_285495_9F097D3D X-CRM114-Status: GOOD ( 10.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a clear use-after-free error. We remove it, and rely on checking the return code of vcap_del_rule. Reported-by: Dan Carpenter Closes: https://lore.kernel.org/kernel-janitors/7bffefc6-219a-4f71-baa0-ad4526e5c198@kili.mountain/ Fixes: c956b9b318d9 ("net: microchip: sparx5: Adding KUNIT tests of key/action values in VCAP API") Signed-off-by: Jens Emil Schulz Østergaard --- drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) --- base-commit: 4186c8d9e6af57bab0687b299df10ebd47534a0a change-id: 20240826-fix_use_after_free-eb34c0c66129 Best regards, diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c b/drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c index 51d9423b08a6..f2a5a36fdacd 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c @@ -1442,18 +1442,8 @@ static void vcap_api_encode_rule_test(struct kunit *test) vcap_enable_lookups(&test_vctrl, &test_netdev, 0, 0, rule->cookie, false); - vcap_free_rule(rule); - - /* Check that the rule has been freed: tricky to access since this - * memory should not be accessible anymore - */ - KUNIT_EXPECT_PTR_NE(test, NULL, rule); - ret = list_empty(&rule->keyfields); - KUNIT_EXPECT_EQ(test, true, ret); - ret = list_empty(&rule->actionfields); - KUNIT_EXPECT_EQ(test, true, ret); - - vcap_del_rule(&test_vctrl, &test_netdev, id); + ret = vcap_del_rule(&test_vctrl, &test_netdev, id); + KUNIT_EXPECT_EQ(test, 0, ret); } static void vcap_api_set_rule_counter_test(struct kunit *test)