From patchwork Wed Aug 2 05:32:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mirsad Todorovac X-Patchwork-Id: 129617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp232379vqx; Tue, 1 Aug 2023 22:56:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlHQAbr2bzsisFf/aQaAAK+5V4qZRKL/G23QMeUcVXmI4Bk2P7R3pVpf6L88jMvkyhb5e+FF X-Received: by 2002:a05:6808:124e:b0:397:ec35:f5a6 with SMTP id o14-20020a056808124e00b00397ec35f5a6mr16476873oiv.57.1690955805814; Tue, 01 Aug 2023 22:56:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690955805; cv=none; d=google.com; s=arc-20160816; b=jkvWW9oVorlgbKIcpkQ5uwOkCTdyvcFYjQ8iNSnD2VEF1AebBSThg5MOPMnCSOO+D5 5RbJ89IlFS9A/A74t6yXyuiek4JnGbF7JGbkHDsWwI3Rj5Wi9LUwyLXmO6nP6LZ3611j F6BDYXiZJX3yFS+in3badJEAkFGZFDBp8flse8GiDn3afDaBamUQUsbApQ5z3GGZsK02 lePbbSWoyE1bJnzWU8310fu+SEuvJ0nH8i6YljTrBnLEfLsdroWnXCHetq+cr/+KIJEC mdTWMkvjmNZmQWcqlygpAH3uenYJDLjZfemmTr4v/JSLceFx+eKwZC1mxDSv9jxBl2Qe Nr0g== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=VVefZydbPBvuYMXo3mXv6go/JAHtgyA/HYqPWoaj0bw=; fh=5KvHHUcfBIBdmMH027jnTfWRuOqaKbgBg3g3ce4VP5A=; b=oHqjb1kGMJ+cjZbV/qWSR77bPpy33CKEbXzryc8oijKPUk0f+uhJSIs5u+LsgkklN4 27TS2/0h1eGXg/7KmT/OiGAICNZFw+vfOC9GYlDei53RW8h/9oLbdwvsMo2IedY7J+pC 8NEsyXQTb9A6XIDutBC1ntMG1JgrFYm+KvzydF0Z7RelNQ1tAfyKpP+w9aUkgaiKUchM ubdZYfigsce55NGT7hn/N+BxuIajgybwvUm6/lSGW83BRMs4+gWeY9z0Hs/cAEw7B3J8 7okxS70+37/mrj1L1263uodziOzLB+vw7HBedgtyEO1TRIswRZv+FPcF1migtk9rK+u2 W/zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b="icxcG/fg"; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=cIRvR0dG; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alu.unizg.hr Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a62-20020a639041000000b005639473079csi362340pge.379.2023.08.01.22.56.32; Tue, 01 Aug 2023 22:56:45 -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=fail header.i=@alu.unizg.hr header.s=mail header.b="icxcG/fg"; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=cIRvR0dG; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alu.unizg.hr Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231362AbjHBFfe (ORCPT + 99 others); Wed, 2 Aug 2023 01:35:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjHBFfc (ORCPT ); Wed, 2 Aug 2023 01:35:32 -0400 Received: from domac.alu.hr (domac.alu.unizg.hr [161.53.235.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25008E4; Tue, 1 Aug 2023 22:35:30 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by domac.alu.hr (Postfix) with ESMTP id D446460173; Wed, 2 Aug 2023 07:35:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1690954528; bh=rHsulKEUysysj8x5Cke2gqcEQZZ8Y32joe5UZz0C7uQ=; h=From:To:Cc:Subject:Date:From; b=icxcG/fgor0g4xLI7PuB+dQcgMN8y+rgod3MRL5eJMw5T1TfcXcNl4yZ7ynnQUpeA 8lyfcCI8PplJcL5qAnpSvdZeSx4qsRURk1Onb6ywrdjF+rtFqhkF7Xp0e6OwGJ90fn DEu/UYJi0pUDvInEcsy0fG5BuH/KrtlpllROF8wjqnBkTSoCFneC2v5Awe583bDHmE YFIq6SLIa0xVYukIu3WxQrefhdCNPLfGEscgB16ZNlClgdIjKxZETVZ/coJU02hVqm DpGH9qnVwxn1skVk0ATi2B3/gSNM70PwzlCSwa9x0cdibJBlualltYKt5SUJ0nSEbh WyfOTxXD5PicA== 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 YP72WSpx8Yoe; Wed, 2 Aug 2023 07:35:26 +0200 (CEST) Received: from defiant.. (unknown [94.250.191.183]) by domac.alu.hr (Postfix) with ESMTPSA id B9DDE6015F; Wed, 2 Aug 2023 07:35:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1690954526; bh=rHsulKEUysysj8x5Cke2gqcEQZZ8Y32joe5UZz0C7uQ=; h=From:To:Cc:Subject:Date:From; b=cIRvR0dG81Ev2J0lJL3CjNoNsTn0LqPgeoI8BBQhAevdjXrBEofmKAt1z4pXMiU0/ yYf0NWix9m9s8MuD8ZYQSVa0Go3AGO3ZiDlhCzspBNvU+C/lB0Kmq+oaokzhYLygCa y7S6Hfwv//hzqZyjwua763PwKKK0JVa0Khya7+PMYTnC9nTeiuTI2VjqEWbkcJzZki fI+m3Aa1GHMC1xBXSxyT4Ws+ul2ZvUJ5kNM5sqquli8sYPCB2mJUoHP/M6dRy7QKzv BSC0i+39UL3OAyeehbKulsVnIGJ6rCcu4ThwjBc5LRgdBLcDWKYtcFplDGLEZk9ne/ yrnKLOKf66iEA== From: Mirsad Todorovac To: Mirsad 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 v2 1/1] test_firmware: fix the memory leaks with the reqs buffer Date: Wed, 2 Aug 2023 07:32:54 +0200 Message-Id: <20230802053253.667634-1-mirsad.todorovac@alu.unizg.hr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773095675321005260 X-GMAIL-MSGID: 1773095675321005260 [ commit be37bed754ed90b2655382f93f9724b3c1aae847 upstream ] 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 triggered 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: c92316bf8e94 ("test_firmware: add batched firmware tests") 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 # v4.14 Suggested-by: Dan Carpenter Suggested-by: Takashi Iwai Link: https://lore.kernel.org/r/20230509084746.48259-2-mirsad.todorovac@alu.unizg.hr Signed-off-by: Mirsad Todorovac [ This fix is applied against the 4.14 stable branch. There are no changes to the ] [ fix in code when compared to the upstread, only the reformatting for backport. ] Signed-off-by: Mirsad Todorovac --- v1 -> v2: removed the Reviewed-by: and Acked-by tags, as this is a slightly different patch and those need to be reacquired lib/test_firmware.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/test_firmware.c b/lib/test_firmware.c index 1c5e5246bf10..5318c5e18acf 100644 --- a/lib/test_firmware.c +++ b/lib/test_firmware.c @@ -621,6 +621,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(sizeof(struct test_batched_req) * test_fw_config->num_requests * 2); if (!test_fw_config->reqs) { @@ -723,6 +728,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(sizeof(struct test_batched_req) * test_fw_config->num_requests * 2); if (!test_fw_config->reqs) {