Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3599805pxb; Mon, 24 Jan 2022 13:12:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbmAcBGRrovhI+NQFnnfCagJ1MOiU0CF2dMOF9rPIGYbto/l4R9wkQNRFK2SXaHn7TZEbx X-Received: by 2002:a17:903:18b:b0:14b:2aa6:d36 with SMTP id z11-20020a170903018b00b0014b2aa60d36mr12688311plg.127.1643058773941; Mon, 24 Jan 2022 13:12:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643058773; cv=none; d=google.com; s=arc-20160816; b=Rhak/4lOx68aDG5Gcxyssq6hIO/nAzRiBTzhMhj2nVAPetXKg1zucwmdIBdqSGyhIS D01qopgYV/x4LwHabGx0rSJmeA+dyixgzSm+Og+hXy+BpchTgGAOEmaNPHGdAmgAtyC4 C1f0rMRPJbYSEouoSPBxt7Z7e2LV7F/j/6ErhS81bbnUH+39Mdv0DJ0pSHlmq3Y4yREQ 4mVaoJ/aePXHsGTaUqpQkfUJmsNPAaLKiRceaDKM+qexzixFOTxgwRX2tNHQOLcKEK7U tfjXvfdjtL70KCU8beq35tUXrMrAdt3m4/lntjSKW5xUTj6sDT6cjoMd+7fViFJNXoqP 6aXg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kTVpc8zTUVhyJNBZputwlqlM0yYqywqHEqUxxDHDGgg=; b=xI30KGXGKaSnDPHzXNA2cLPsS+Ye9/uPgk3CbzFOLvxzfL23WUPyfBcnN3GlgsIkFS uxiMuwhSp20z1PHG9OhYPzYVrYcmMYJBas2WB8Uf6TAgmSkmvlCHj4vEI1c5ddOKU4di WgnW0rPDLu0mN7TitEayGbLPiqwbxdVZtEHwvSOUy3zXxGspz97Tjy9doLjDX8x1gAbL 2XxE0NOFOy7dW8Ny9QgJw2+WIUPQoU1BKap7Us4nSembbyUuy100mZvqlEDBdA7+dQjq LMVzC25+iRd6H/JgDza0G93GamOx55hzrliFeyZm8KuqzGnE2WSJYkhjhcPcj+lsWExP hoOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ku7Efkn0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q4si3275392pgq.613.2022.01.24.13.12.41; Mon, 24 Jan 2022 13:12:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ku7Efkn0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386559AbiAXUfk (ORCPT + 99 others); Mon, 24 Jan 2022 15:35:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355214AbiAXUNW (ORCPT ); Mon, 24 Jan 2022 15:13:22 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B52EC01D7CA; Mon, 24 Jan 2022 11:34:32 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 53244B811FC; Mon, 24 Jan 2022 19:34:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71581C340E5; Mon, 24 Jan 2022 19:34:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052870; bh=TcxqqP3k9ttYzsoT+++OolzMeJ1YguBUZ1x8o29WZxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ku7Efkn0xzFgM22oLcm1cJ3gJf7aDlY/NQ5NMufPiVdUHsdDSoX0ORo5rWNp1PvPt iJVvhbqsEkw7DvenL4uHHrhEcckW5QkiFWVqwYxwKzcOiD7mFVrTgig2j+CaQIAZzS b5iOFG/oryM1Ld/VzDPPAYmv7WAIBQxuEKjlK6Zk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Berg , Luca Coelho , Sasha Levin Subject: [PATCH 5.4 199/320] iwlwifi: fix leaks/bad data after failed firmware load Date: Mon, 24 Jan 2022 19:43:03 +0100 Message-Id: <20220124184000.405209110@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johannes Berg [ Upstream commit ab07506b0454bea606095951e19e72c282bfbb42 ] If firmware load fails after having loaded some parts of the firmware, e.g. the IML image, then this would leak. For the host command list we'd end up running into a WARN on the next attempt to load another firmware image. Fix this by calling iwl_dealloc_ucode() on failures, and make that also clear the data so we start fresh on the next round. Signed-off-by: Johannes Berg Signed-off-by: Luca Coelho Link: https://lore.kernel.org/r/iwlwifi.20211210110539.1f742f0eb58a.I1315f22f6aa632d94ae2069f85e1bca5e734dce0@changeid Signed-off-by: Luca Coelho Signed-off-by: Sasha Levin --- drivers/net/wireless/intel/iwlwifi/iwl-drv.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-drv.c b/drivers/net/wireless/intel/iwlwifi/iwl-drv.c index e68366f248fe3..c1a2fb154fe91 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-drv.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-drv.c @@ -183,6 +183,9 @@ static void iwl_dealloc_ucode(struct iwl_drv *drv) for (i = 0; i < IWL_UCODE_TYPE_MAX; i++) iwl_free_fw_img(drv, drv->fw.img + i); + + /* clear the data for the aborted load case */ + memset(&drv->fw, 0, sizeof(drv->fw)); } static int iwl_alloc_fw_desc(struct iwl_drv *drv, struct fw_desc *desc, @@ -1338,6 +1341,7 @@ static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context) int i; bool load_module = false; bool usniffer_images = false; + bool failure = true; fw->ucode_capa.max_probe_length = IWL_DEFAULT_MAX_PROBE_LENGTH; fw->ucode_capa.standard_phy_calibration_size = @@ -1604,6 +1608,7 @@ static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context) op->name, err); #endif } + failure = false; goto free; try_again: @@ -1619,6 +1624,9 @@ static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context) complete(&drv->request_firmware_complete); device_release_driver(drv->trans->dev); free: + if (failure) + iwl_dealloc_ucode(drv); + if (pieces) { for (i = 0; i < ARRAY_SIZE(pieces->img); i++) kfree(pieces->img[i].sec); -- 2.34.1