From patchwork Tue May 9 08:47:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mirsad Todorovac X-Patchwork-Id: 13235484 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 816A5C7EE22 for ; Tue, 9 May 2023 08:59:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234828AbjEII7m (ORCPT ); Tue, 9 May 2023 04:59:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234808AbjEII7l (ORCPT ); Tue, 9 May 2023 04:59:41 -0400 Received: from domac.alu.hr (domac.alu.unizg.hr [IPv6:2001:b68:2:2800::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 395D9D059; Tue, 9 May 2023 01:59:39 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by domac.alu.hr (Postfix) with ESMTP id 1086C60187; Tue, 9 May 2023 10:59:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1683622777; bh=BkbDGciTS3W//1DGsvWYvladd4chFAo6enUQtEEQQqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZiHOi8HPxzzbaMu1BjZZouEP73gvHy58Ao5cTqsMxCM4iZOXDHxWxpKrp1dLHCuaJ dxBDXLa5fe7MakoluU2y8lwJGGEx4df5P4xjhxbV8aspiHEXl6Zju8X/4WzwV5PL2Y fEsMURPTuCszyce/c/Jmw8qm9JtbOElF1SXnzJjDHpDQ4rteRW8WAP2soR5ctuAep2 4fi2kcRY/MABNk31PQSerIUCtEakvumQmOtxsJHLSjnqpHYg46OtSbkzVQOwD1RCxa Kp234zFEiZd9iRtkgfxmivI78zIallIYKfDP9pD40GySeU09gXcdZjirAuZvDby10x IWDRtcp1CZZyw== X-Virus-Scanned: Debian amavisd-new at domac.alu.hr Received: from domac.alu.hr ([127.0.0.1]) by localhost (domac.alu.hr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2KOxey4fw9l1; Tue, 9 May 2023 10:59:34 +0200 (CEST) Received: by domac.alu.hr (Postfix, from userid 1014) id E058D6018D; Tue, 9 May 2023 10:59:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1683622774; bh=BkbDGciTS3W//1DGsvWYvladd4chFAo6enUQtEEQQqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L7OVwpJpI7Wz6LVxX5Nui1hPHgVn86mc1DA5sZq8+h2zdVGiTVcG1BKmLGt5NP5NX RLEgoD3XF44dTF7b+dzcY4Z+pfbtraucHN3SUvtMP6O24fLDj8O2VcPUe7jSh/YqtA fNpTE9/Zwqh9n4BHGSr2h3wChoU8kxqcdpB+aiX7CoAJ6BFFHpHHqfIb2oWolaw8XY E5+hyZZhLdK0J/2i15jgdg7SG9Pu+gyHswwgoljCu1B9m4/H/HkBqhqqg8jzJkaU6f brGy+i6GjBNa9Wf28Iv4IojqwGuUBPGgeS0Tcbtxa84CJIO+fu+hGhhDlEkHsI9/X/ oYz7H0kiy4C/A== From: Mirsad Goran Todorovac To: Mirsad Goran Todorovac , linux-kernel@vger.kernel.org Cc: Luis Chamberlain , Greg Kroah-Hartman , Russ Weight , Tianfei Zhang , Shuah Khan , Colin Ian King , Randy Dunlap , linux-kselftest@vger.kernel.org, stable@vger.kernel.org, Dan Carpenter , Takashi Iwai Subject: [RESEND PATCH v5 2/3] test_firmware: fix a memory leak with reqs buffer Date: Tue, 9 May 2023 10:47:47 +0200 Message-Id: <20230509084746.48259-2-mirsad.todorovac@alu.unizg.hr> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230509084746.48259-1-mirsad.todorovac@alu.unizg.hr> References: <20230509084746.48259-1-mirsad.todorovac@alu.unizg.hr> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Dan Carpenter spotted that test_fw_config->reqs will be leaked if trigger_batched_requests_store() is called two or more times. The same appears with trigger_batched_requests_async_store(). This bug wasn't trigger by the tests, but observed by Dan's visual inspection of the code. The recommended workaround was to return -EBUSY if test_fw_config->reqs is already allocated. Fixes: 7feebfa487b92 ("test_firmware: add support for request_firmware_into_buf") Cc: Luis Chamberlain Cc: Greg Kroah-Hartman Cc: Russ Weight Cc: Tianfei Zhang Cc: Shuah Khan Cc: Colin Ian King Cc: Randy Dunlap Cc: linux-kselftest@vger.kernel.org Cc: stable@vger.kernel.org # v5.4 Suggested-by: Dan Carpenter Suggested-by: Takashi Iwai Signed-off-by: Mirsad Goran Todorovac Reviewed-by: Dan Carpenter Acked-by: Luis Chamberlain --- lib/test_firmware.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/test_firmware.c b/lib/test_firmware.c index 35417e0af3f4..91b232ed3161 100644 --- a/lib/test_firmware.c +++ b/lib/test_firmware.c @@ -913,6 +913,11 @@ static ssize_t trigger_batched_requests_store(struct device *dev, mutex_lock(&test_fw_mutex); + if (test_fw_config->reqs) { + rc = -EBUSY; + goto out_bail; + } + test_fw_config->reqs = vzalloc(array3_size(sizeof(struct test_batched_req), test_fw_config->num_requests, 2)); @@ -1011,6 +1016,11 @@ ssize_t trigger_batched_requests_async_store(struct device *dev, mutex_lock(&test_fw_mutex); + if (test_fw_config->reqs) { + rc = -EBUSY; + goto out_bail; + } + test_fw_config->reqs = vzalloc(array3_size(sizeof(struct test_batched_req), test_fw_config->num_requests, 2));