Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7353003rwr; Tue, 25 Apr 2023 11:36:54 -0700 (PDT) X-Google-Smtp-Source: AKy350bo+ROgjy9PQFIlPQH1PrMw/8SD3eULO/uRwWw0vzdIZi3L8uyjglj37J3Y9zc+U2k6/Iqh X-Received: by 2002:a17:902:ec81:b0:19d:20a:a219 with SMTP id x1-20020a170902ec8100b0019d020aa219mr22417788plg.66.1682447813832; Tue, 25 Apr 2023 11:36:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682447813; cv=none; d=google.com; s=arc-20160816; b=X0kFDComaMn6yPEebnAL9mG92bZc8eH1RRS5i96EJg3uEAwaxyK73a0lBj6ytQ32lY crEpjT6W8JrmcJ5GMRzZcntMQ5023vh4P5trXAVv+tNSwKJnMJK9gYqcyQ3emOfnPKH3 cAuhJl2zp1XDTN68e115g9zVnRlE83QZV8IpY2zmtdqDDX1h+EQhLyXm3wpkqaSIw3nZ 2ooZXjChueLR6vSVQvyFT/1582SgG1yAGeqwLb+jO8EQYr+FelmKUS5A/0nuVu6mfywi K3+Nd1Ow2fddzSon5A2bfJr/3jLqdtde5IilO8hZKntwu0doQqzDI21t4diQgjECQ+C6 q/sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=TEh7JnhuVuuTnUG+hm/DecBEi8WL/KaovpCpd2tiDHI=; b=AjOWrjVtZR0+wLISRQtGyYunFNdYx99GOdtS9xuBJREaZxzdwqVqt5z5uXaaMiCwo3 qzkOOQ9hlduMT/AtTBmplKVCL4zB8Mh/elRWcdTTHVEcB2JcjjNFSBUVe4k3DsJmcsb9 OrTcGRf9sz+WcCw8jjZSiWwNtIgIAXCDhVxsfV7uEcNUDuG/ZpO/deh+5tKhOft6EUW1 5o1ZZZHnQ+ZBaSqeHexofUYWOMH4pR4qiY1iar94mjKEKpA3gMaY0/oWwPcvIWQrrY5K +3WcW77EIJL+YZBIbYxxdjzJNEozoV1gykbav65giMKLAafxMqArZcUVhWhvDIMxHATz ABKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=HkAf0GrU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bx15-20020a17090af48f00b00232f57260c1si16654431pjb.1.2023.04.25.11.36.40; Tue, 25 Apr 2023 11:36:53 -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=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=HkAf0GrU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234284AbjDYS1m (ORCPT + 99 others); Tue, 25 Apr 2023 14:27:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231337AbjDYS1l (ORCPT ); Tue, 25 Apr 2023 14:27:41 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50DA58A5A for ; Tue, 25 Apr 2023 11:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=TEh7JnhuVuuTnUG+hm/DecBEi8WL/KaovpCpd2tiDHI=; b=HkAf0GrUku1bE3kLD0TZFNsA7B R9Lrqqq5MKMsjabWsKrP0nVnC325SdUphN8XqM8bDyNGtRgjRNqSNmApVAj+VufJURnuSrNUk/9Ra +V8QVw0uOytFMSHjSB6SSMc3zfDrm4sSyhK0SieIr0+tmECO/tphVHCm4U63sjO9fiEqWc/GBiu3i q5La2F/f/PV6eZ+WiCxFB9lJ9Bi3MibSQAV8smsbVd2Fxz9685zdUS66wyD+Xp8OPzp0pijoeOoKn Nmsj0BdO+X5dhIODc1zS0Q99ufXF8j6c9gEh5CJhyhoSO1WTKX4CU1guwQ7RmaK2ILrEdURD9gb4K 4e0utL7Q==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1prNNy-001wm4-2h; Tue, 25 Apr 2023 18:27:30 +0000 Date: Tue, 25 Apr 2023 11:27:30 -0700 From: Luis Chamberlain To: Mirsad Goran Todorovac , Scott Branden Cc: Greg Kroah-Hartman , Russ Weight , linux-kernel@vger.kernel.org, Tianfei zhang , Christophe JAILLET , Zhengchao Shao , Colin Ian King , Takashi Iwai , Kees Cook , Dan Carpenter , Vincenzo Palazzo Subject: Re: [PATCH RESEND v4 1/1] test_firmware: fix some memory leaks and racing conditions Message-ID: References: <20230421185205.28743-1-mirsad.todorovac@alu.unizg.hr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230421185205.28743-1-mirsad.todorovac@alu.unizg.hr> Sender: Luis Chamberlain X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,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 On Fri, Apr 21, 2023 at 08:52:06PM +0200, Mirsad Goran Todorovac wrote: > Some functions were called both from locked and unlocked context, so > the lock was dropped prematurely, introducing a race condition when > deadlock was avoided. > > Having two locks wouldn't assure a race-proof mutual exclusion. > > __test_dev_config_update_bool(), __test_dev_config_update_u8() and > __test_dev_config_update_size_t() unlocked versions of the functions > were introduced to be called from the locked contexts as a workaround > without releasing the main driver's lock and causing a race condition. > > This should guarantee mutual exclusion and prevent any race conditions. > > Locked versions simply allow for mutual exclusion and call the unlocked > counterparts, to avoid duplication of code. > > trigger_batched_requests_store() and trigger_batched_requests_async_store() > now return -EBUSY if called with test_fw_config->reqs already allocated, > so the memory leak is prevented. > > The same functions now keep track of the allocated buf for firmware in > req->fw_buf as release_firmware() will not deallocate this storage for us. > > Additionally, in __test_release_all_firmware(), req->fw_buf is released > before calling release_firmware(req->fw), > foreach test_fw_config->reqs[i], i = 0 .. test_fw_config->num_requests-1 > > Cc: Greg Kroah-Hartman > Cc: Luis Chamberlain > Cc: Russ Weight > Cc: Tianfei zhang > Cc: Christophe JAILLET > Cc: Zhengchao Shao > Cc: Colin Ian King > Cc: linux-kernel@vger.kernel.org > Cc: Takashi Iwai > Cc: Kees Cook > Cc: Scott Branden > Cc: Luis R. Rodriguez > Suggested-by: Dan Carpenter > Signed-off-by: Mirsad Goran Todorovac Mirad, thanks for this work, good stuff! So the patch just needs to be adjust with: Fixes: 7feebfa487b92 ("test_firmware: add support for request_firmware_into_buf" Cc: stable@vger.kernel.org # v5.4 Then, can you split the patch in two, one which fixes the memory leaks and another that deals with the mutexes. The second patch might be a fix for the original code but I can't tell until I see the changes split out. The commit log should account for the memory leak and be clear how it happens. The other commit log for the second patch should clarify what it fixes and why as well. Luis