From patchwork Tue Aug 1 17:07: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: 129398 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2827866vqg; Tue, 1 Aug 2023 10:37:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlEOo65lMDEC/PXHV7Rl12gJ6S0L1Vy0LnG1YPzC4rlEMC1DUsBEdLRc0rdeACFQwLKqmx3q X-Received: by 2002:a05:6512:3e02:b0:4f9:596d:c803 with SMTP id i2-20020a0565123e0200b004f9596dc803mr3958378lfv.53.1690911463692; Tue, 01 Aug 2023 10:37:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690911463; cv=none; d=google.com; s=arc-20160816; b=itGtYR7I7EeIDynRApItpzAvM6GrCIyC1SDunax/X/ag6f04GUtPR5kljcbVztNld6 AomoLsK/dF4uEAAS17azfAUS57lvR3fsXTUAYWVfzi3SCtuQf6D/ID31EaHh46nOmISb U7BhJK687rUQaeaRJ0yH3oXwguCWbKfCr9HYhOiQVCADiZASz7S8nwC7qJbwfUmjK9oF 2EZMXndtG6Q7Xx1pTJsrXIWJk3nEigtIvDKWCW0889FduihkXGWdsyw/fvKUN8SWpC7m OlCtD6W0yv/OkEirgIg4zR7rHOB7lTiQIwuykyg8tX0gXdsN84ZQyTxq3j2whkWM1CYb etew== 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=Mw3LV/1fGIBGyAkwdAJRnwBGB2dl404CnVrAssOGwn4=; fh=+ZgWG36qsBuAqFwb5UH697aEW48mbJUlMu/pSV1S8A8=; b=retsoWAeYVIKqkuiAy0nJaS4fjijnJOGLx3Vl2hn2K9lbtoyPgln/OrTcPrd7AcFTL e6WctKpODouFFRS1lv5awUPfwW5bHZp8CQRRm7RiXHydj2DKU011LcWvgrM7v13sdvgt yRd/R7+YuUb5wzbXXitlxO5tKcs3VaNtldsO5lBZf87EiWApsYaY8iAgTdgc4q58ldJ0 HNsC4px1l971WLkFOCM4+yS6tC/Kp7/gFD74xo5jnQBYjy16n9h2XwxgZlnAw03sY3ie mufighomz82EynEiqnVF+PZ+mKOb/E75VobPGPVM2My61y/cTxXXi+s7rgHC5kPPzRPI HOAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=FP0C+zTw; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b="NIi/IRqX"; 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 w20-20020a170906131400b0099bd58fb8c5si9292387ejb.751.2023.08.01.10.37.18; Tue, 01 Aug 2023 10:37:43 -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=FP0C+zTw; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b="NIi/IRqX"; 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 S234184AbjHARJq (ORCPT + 99 others); Tue, 1 Aug 2023 13:09:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232424AbjHARJo (ORCPT ); Tue, 1 Aug 2023 13:09:44 -0400 Received: from domac.alu.hr (domac.alu.unizg.hr [IPv6:2001:b68:2:2800::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D1662735; Tue, 1 Aug 2023 10:09:12 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by domac.alu.hr (Postfix) with ESMTP id E2D276017C; Tue, 1 Aug 2023 19:09:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1690909749; bh=e6Bszk6G8nn708Yum4V8G3z8149Ww6/gLP9EzNUvxuo=; h=From:To:Cc:Subject:Date:From; b=FP0C+zTwyvERTQuh8B2EgRRe8bKfJwUBetXKuq+9gUAIF2fOidbjm+soAfkOc8yb1 Tq93y7luRQAB/5JCxIo2UsWFYMpGjjkVHS7BpKiGkL3a7crWTVdpTQBL02Jdivz9xD NhF7gS3wEOxQG2yUoRXhoK7ZCWNq40HN/63v4H12y+Tc9HmV1OwXFEqq+DYQ0ZLJxv Vu92U9lLRFrCPX3RxvtTNV446aBYiQlLxLT3vzWg2eg/dJqXdES4bikYelz2HMQxYl uFvZAfDfOJC5XcBh+rJp3rjef6i+Qos7Q1cSSuIx+G5CvSbB6F8gmK+qfmncAXJg2N f8DUEDGpq492g== 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 o4ZKyBaRx3Iz; Tue, 1 Aug 2023 19:09:07 +0200 (CEST) Received: from defiant.. (unknown [94.250.191.183]) by domac.alu.hr (Postfix) with ESMTPSA id D228C6015F; Tue, 1 Aug 2023 19:08:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1690909747; bh=e6Bszk6G8nn708Yum4V8G3z8149Ww6/gLP9EzNUvxuo=; h=From:To:Cc:Subject:Date:From; b=NIi/IRqXTxYAZRPVtZEFea23cg+CDIvwOzVlY+RXnH1bpPpcxf00VBxCsVvRsi+xy xshyRiv/8AH3E7Pw9yyRJemwYgP3/+iK7PGLcc+VtW7iPSU5iYa7B5MUo02Cv9ACge knotXaT2tZsij0Qaj8Kybc5LWarWHZGRNnfxG9oxNMauqClqD/BprpjlT/Yqm94wfn GHGKArGl9WzUa28QOENciK4zc+UIcGpvSPmNgx5vzYebqXRuZXV2r/7wobgbEjrjt4 O+R7ByCrbB6vz05TYP2GyuNR5pXhQCveNAF4GfAD4R6rjaOAH2M4w2sR2XHdAInY8m Iuhrowt65eGGA== From: Mirsad Todorovac To: Luis Chamberlain , Mirsad Todorovac , linux-kernel@vger.kernel.org Cc: 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 , Dan Carpenter Subject: [PATCH v1 1/1] test_firmware: fix a memory leak with reqs buffer Date: Tue, 1 Aug 2023 19:07:47 +0200 Message-Id: <20230801170746.191505-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: 1773049178944432819 X-GMAIL-MSGID: 1773049178944432819 [ 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.19 Suggested-by: Dan Carpenter Suggested-by: Takashi Iwai Reviewed-by: Dan Carpenter Acked-by: Luis Chamberlain Link: https://lore.kernel.org/r/20230509084746.48259-2-mirsad.todorovac@alu.unizg.hr Signed-off-by: Mirsad Todorovac [ This is a backport to v4.19 stable branch without a change in code from the 5.4+ patch ] --- v1: patch sumbmitted verbatim from the 5.4+ branch to 4.19 lib/test_firmware.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/test_firmware.c b/lib/test_firmware.c index f4cc874021da..e4688821eab8 100644 --- a/lib/test_firmware.c +++ b/lib/test_firmware.c @@ -618,6 +618,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)); @@ -721,6 +726,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));