Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3679018pxb; Mon, 24 Jan 2022 15:09:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJTVgGk2gZ64jpqzem6dsnXzzq66mV+VmXteSOb2UpDFDjqZ5GH+fENJLj38eIEMk1KYr1 X-Received: by 2002:a63:5355:: with SMTP id t21mr11126030pgl.625.1643065661506; Mon, 24 Jan 2022 15:07:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643065661; cv=none; d=google.com; s=arc-20160816; b=yp1JgHQqYtxWDPQo3w089kEpYIQSCCqCAdhHVmyc7rmGm6kZouysRwRnGJr2nMp2H4 u6IjEsNmia8YVYsnaon5pFMDtxdsQ/Q6Y+mDu39GnAut++YtqG468ZDj7aENWqmgP1JG tUWhn6a8t3aolg+04UqbTPq4d2br+xOllZzaQ1rsln9qKDxs6njyKaPoQwRMYtftwIWk HQRNa2t7Hl45iijCW97Kxk2JEsgFnFT3zqI1z+Tq2mt4Fng6gUnCtSbkiN9/Vz9BgaU0 vxUEeQTCfbPB8Ijn2IM+QpVbDWxMt3DMxbCdHXBucsaruh1qM/I/wAgeV5CI0UZ6eAKk bQiQ== 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=ylw3/tm2+HqLASx8QXxObDgAbEY2UgQu2sd2nFI6Jh0=; b=T153BSc3AzpCIbpi/r4LEdBT1OtZMXB+p0QSICZ9uXp0hIJJdYinXHvqg/ppWh+q8U OTjAxhXVwty8xXSefMQ3P/gZM0IUerxbNy6P1Hlsj+T15e4Ck4RDemwcKIAKpYH/aWq4 JyYFvyto9YfCYKqGh0IFDKq3y4lfAUHkIW90RuT84MBopZmJUSi1Z8jEE0TrDpXgHLdN Zc7n3zqXeWxK98oK25VH/hGPx1yGaus6KIBxJzRfuCm1TBE8ys3vqa/VoEZd+LIvZvie uBQ2ANvS+i4i6Bihvv488osMV7wyf2+HMv8OwPY2NqN4q0lBxaqEgWy8ZKKjWQU91C/X L5Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mcpfA6IK; 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 p14si17373913plf.211.2022.01.24.15.07.29; Mon, 24 Jan 2022 15:07:41 -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=mcpfA6IK; 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 S1843014AbiAXXDJ (ORCPT + 99 others); Mon, 24 Jan 2022 18:03:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1577037AbiAXV5L (ORCPT ); Mon, 24 Jan 2022 16:57:11 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61B42C02C30C; Mon, 24 Jan 2022 12:38:54 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 0103661008; Mon, 24 Jan 2022 20:38:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCA1BC340E5; Mon, 24 Jan 2022 20:38:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056733; bh=eFMl/MhttaEwrV7USY7/hPWY6uI4fhVEmffTevK80BE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mcpfA6IKnocnYMhib51Px+Ip1pNqJ/GXfMvkdFL2X2esS3oO0/YRJbbIIcVErt5m0 EzmF+XtyIeN/HjcIV1y+f9Fi2mAz+4TqrkZrFSZ47Kdhev3OfropQn+6lnkNhKanA7 2bhC8D/5TZp85c+CX4JiNDnO5u0irPVbCLbfGAYU= 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.15 575/846] iwlwifi: fix leaks/bad data after failed firmware load Date: Mon, 24 Jan 2022 19:41:32 +0100 Message-Id: <20220124184120.866302947@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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 94553f272d377..2206f66f69940 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-drv.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-drv.c @@ -131,6 +131,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, @@ -1333,6 +1336,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 = @@ -1602,6 +1606,7 @@ static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context) op->name, err); #endif } + failure = false; goto free; try_again: @@ -1617,6 +1622,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