From mboxrd@z Thu Jan 1 00:00:00 1970 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 3E9D7C001E0 for ; Thu, 27 Jul 2023 15:36:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232663AbjG0Pgx (ORCPT ); Thu, 27 Jul 2023 11:36:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231799AbjG0Pgv (ORCPT ); Thu, 27 Jul 2023 11:36:51 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3D2A211C for ; Thu, 27 Jul 2023 08:36:50 -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=wvajyvPbGU4XnifnsA0utYtQNjjMry+vO/nxQQfxGKI=; b=qXBYn3RT9nW1HBAALBfe0c8nNW 0Sr5D/TbcmCaS4FzGkuO82k4kdOBXmDoDLPKTWUjPdBx1n2MQrF9vrQ0qUJZDm3UXl2DpUaNxwQsr 2gHLk6uXIcpUDBebDYhm2aar+NIJvYftIrLedscDTDyTXXjveQjN10cRoD8MnaLe0vrUz1ZMpNfd3 JeC7JB/F+J1dE18VLS52wpJNxCDx7TW9ggygy5adngr8+bGMtnSBDJUVcxuAfdpl4aG77iwU9FFud ulGQwbqvhK3A9XpsdFJxZoO6x4LmhjGOmy3ltPd6joWkja821v46R2OaFW4P2edPNutDFWJ0Kxqgg bhxTewMg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1qP32g-00Fz38-1g; Thu, 27 Jul 2023 15:36:42 +0000 Date: Thu, 27 Jul 2023 08:36:42 -0700 From: Luis Chamberlain To: Mirsad Todorovac Cc: Scott Branden , 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: Sender: Luis Chamberlain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 27, 2023 at 08:16:17AM +0200, Mirsad Todorovac wrote: > On 25.4.2023. 20:27, Luis Chamberlain wrote: > > 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. > > It seems to me that there is something wrong with the patchwork, as this commit > had not yet appeared in 5.4 LTS stable tree? Did you resend a new v5 with the requested changes? Luis