From patchwork Wed Apr 26 13:14:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mirsad Todorovac X-Patchwork-Id: 13224609 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 DEA4EC77B78 for ; Wed, 26 Apr 2023 13:16:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241132AbjDZNQH (ORCPT ); Wed, 26 Apr 2023 09:16:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241125AbjDZNP4 (ORCPT ); Wed, 26 Apr 2023 09:15:56 -0400 Received: from domac.alu.hr (domac.alu.unizg.hr [IPv6:2001:b68:2:2800::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD74A5FC0; Wed, 26 Apr 2023 06:15:53 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by domac.alu.hr (Postfix) with ESMTP id 7C8E66017C; Wed, 26 Apr 2023 15:15:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1682514952; bh=BkbDGciTS3W//1DGsvWYvladd4chFAo6enUQtEEQQqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f3PBIre12N8S7+pAiYxpBnotF1xNuHJiB9WFD3DUQyy2zG+VLFAjHYCj0i4WEsu68 xMLy5h2FG9SUC/UiN9CdAfMoVzO0TVINpx3ghAH3gn/tk1EX1a1LKnogP6QZ4+9gsq N8phvi94or/bweFqGAeEKvc9SqYGmSJDMJrBJ8uRzpqaoN3jdji/uX38SxeO3RSe37 aKzRqvv8B/L6o5Znov3D9f8Ew9+MNk91ogjzZ9Toy99aLUwYI5HcGpr4pCNhtMQz+g 3etOCjfPN1MM9Nm3ZLJlosGTBadZ6tnmfH2JH8ZXl3NK6rOBEcQivIQiUwlqA66yO0 /u4MXMZRQDAYA== 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 5dbKQDu-qTY3; Wed, 26 Apr 2023 15:15:50 +0200 (CEST) Received: by domac.alu.hr (Postfix, from userid 1014) id 595406017E; Wed, 26 Apr 2023 15:15:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1682514950; bh=BkbDGciTS3W//1DGsvWYvladd4chFAo6enUQtEEQQqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W2PYGjp02QXGEwIrsbzABoB8RC9N63W+Au8q3DPzM6xAWOlUKfDgEYJZj2U/7/Iqe ANXorKJH9xllVago/Fo5zE0K6ETk4c775VIQi0letwp3q8Z8Ohk13ZdxHqxLEDuWNc Jl0/r1SJin0DWdxnJip+IPZg85KrbfhJ4h22X1DoZNUzlB5/ppKiTSa8CqJL39Ab/Z o8Cs7+KRfvogXfQx9VJtaLDdyK7k6P6jFNngjDqmbO/dysJPY8ukL8mt36OHpMiJ8H B3pv307BqdEiRfx9jyRRiT6meCiJhdE2N6q2OrsID/7TOYmPRmm4VHoXPADsVYZJ04 vxSSJJyo53LwQ== 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: [PATCH v5 2/3] test_firmware: fix a memory leak with reqs buffer Date: Wed, 26 Apr 2023 15:14:41 +0200 Message-Id: <20230426131438.16936-2-mirsad.todorovac@alu.unizg.hr> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230426131438.16936-1-mirsad.todorovac@alu.unizg.hr> References: <20230426131438.16936-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 --- 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));