Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp760108ybz; Fri, 24 Apr 2020 08:50:28 -0700 (PDT) X-Google-Smtp-Source: APiQypJ7JAKHD7Bl4iewuLbBsTrveOSN3NSmWzdrFnjJ1N8kq1rZ+rpoPyexxsBevD+I6spwEZfB X-Received: by 2002:a17:906:2558:: with SMTP id j24mr7969375ejb.72.1587743428210; Fri, 24 Apr 2020 08:50:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587743428; cv=none; d=google.com; s=arc-20160816; b=nKwtp4fEgzxXa/F1xbQVzNKhtHg/tr2tquZxsN/DT+oimd/FlAoJH6GRCCk24rFkiR w5DSl7OukVVi8xy3ZRW5VcWiKIXUKByAnK4u5giiq1hmBybQlBNjY+GlDK0DhlJvuL0f xXncivX7DjMsDWvQdmtMoW5udnZpIYv7s1Fi5aq9mz40tBGesmoaTQ4ORx1Ofu42Uodr y35B7pZ7dmHBoiw3/zNcikkAGJoHJT05KCHADIFT3uMtS+96mQj8INQAJ6yYEu1ywW1L 6Wjzl/+aIG/0+uxlMiWIyYfeBfKMFSSczu2WdOnckNT4n3ctsoaec64Ft7BOrLD61YFl xO8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:cc:to:from; bh=llGwx3z5CxYZdibUKzY6svcde0++USAfgfr2kGLqiuU=; b=kbPlRp/ROKFh7ptKb1m2A/13uA94l7q7K0v6NLGLOllOdNdY3ZdA9kco/PlIy7B41+ g70t7YzugJ+MeJ5qvJmJHUlXHMhcl34l8exz9AYvzngRz8lEFOPYus5/UCJkqnYGla1e 7YBIndIzmJL0f9PhBZLI/3jQYKHR3vY6IeGaNyjJxRHzzuw2tmovvt7Ug/Ogq4gtIZB7 j/fLK0yReY+XyQ/i4RJQ8dGmmgt8LY6qeKwufyxMB7D/v4SqIonTbp1IHq79ZWmroj3W 0YFJhxPdx2B4wr8UDr5Mawtr/47u/6bVMmjKoIZDN2otpavOGSahacR4GRhWJKaUiQzP sWtw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rl27si3330992ejb.17.2020.04.24.08.50.04; Fri, 24 Apr 2020 08:50:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728720AbgDXPsf (ORCPT + 99 others); Fri, 24 Apr 2020 11:48:35 -0400 Received: from paleale.coelho.fi ([176.9.41.70]:57904 "EHLO farmhouse.coelho.fi" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728481AbgDXPsd (ORCPT ); Fri, 24 Apr 2020 11:48:33 -0400 Received: from 91-156-6-193.elisa-laajakaista.fi ([91.156.6.193] helo=redipa.ger.corp.intel.com) by farmhouse.coelho.fi with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1jS0Z5-000OY2-0b; Fri, 24 Apr 2020 18:48:31 +0300 From: Luca Coelho To: kvalo@codeaurora.org Cc: linux-wireless@vger.kernel.org Date: Fri, 24 Apr 2020 18:48:11 +0300 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424154818.2657602-1-luca@coelho.fi> References: <20200424154818.2657602-1-luca@coelho.fi> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on farmhouse.coelho.fi X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, TVD_RCVD_IP autolearn=ham autolearn_force=no version=3.4.4 Subject: [PATCH 05/12] iwlwifi: yoyo: don't access TLV before verifying len Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Mordechay Goodstein If we access the TLV memory with shorter len than the struct we access garbage data that was not given by the user. On the way rewrite the checker in a cleaner way. Signed-off-by: Mordechay Goodstein Fixes: a9248de42464 ("iwlwifi: dbg_ini: add TLV allocation new API support") Signed-off-by: Luca Coelho --- .../wireless/intel/iwlwifi/fw/api/dbg-tlv.h | 5 ++- .../net/wireless/intel/iwlwifi/iwl-dbg-tlv.c | 44 +++++++++---------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/dbg-tlv.h b/drivers/net/wireless/intel/iwlwifi/fw/api/dbg-tlv.h index b9d7ed93311c..74ac65bd545a 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/dbg-tlv.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/dbg-tlv.h @@ -5,7 +5,7 @@ * * GPL LICENSE SUMMARY * - * Copyright (C) 2018 - 2019 Intel Corporation + * Copyright (C) 2018 - 2020 Intel Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as @@ -25,7 +25,7 @@ * * BSD LICENSE * - * Copyright (C) 2018 - 2019 Intel Corporation + * Copyright (C) 2018 - 2020 Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -304,6 +304,7 @@ enum iwl_fw_ini_buffer_location { IWL_FW_INI_LOCATION_SRAM_PATH, IWL_FW_INI_LOCATION_DRAM_PATH, IWL_FW_INI_LOCATION_NPK_PATH, + IWL_FW_INI_LOCATION_NUM, }; /* FW_DEBUG_TLV_BUFFER_LOCATION_E_VER_1 */ /** diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c b/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c index 9eb8fbfaa2a2..7987a288917b 100644 --- a/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c +++ b/drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c @@ -165,38 +165,36 @@ static int iwl_dbg_tlv_alloc_buf_alloc(struct iwl_trans *trans, struct iwl_ucode_tlv *tlv) { struct iwl_fw_ini_allocation_tlv *alloc = (void *)tlv->data; - u32 buf_location = le32_to_cpu(alloc->buf_location); - u32 alloc_id = le32_to_cpu(alloc->alloc_id); + u32 buf_location; + u32 alloc_id; - if (le32_to_cpu(tlv->length) != sizeof(*alloc) || - (buf_location != IWL_FW_INI_LOCATION_SRAM_PATH && - buf_location != IWL_FW_INI_LOCATION_DRAM_PATH && - buf_location != IWL_FW_INI_LOCATION_NPK_PATH)) { - IWL_ERR(trans, - "WRT: Invalid allocation TLV\n"); + if (le32_to_cpu(tlv->length) != sizeof(*alloc)) return -EINVAL; - } - if ((buf_location == IWL_FW_INI_LOCATION_SRAM_PATH || - buf_location == IWL_FW_INI_LOCATION_NPK_PATH) && - alloc_id != IWL_FW_INI_ALLOCATION_ID_DBGC1) { - IWL_ERR(trans, - "WRT: Allocation TLV for SMEM/NPK path must have id %u (current: %u)\n", - IWL_FW_INI_ALLOCATION_ID_DBGC1, alloc_id); - return -EINVAL; - } + buf_location = le32_to_cpu(alloc->buf_location); + alloc_id = le32_to_cpu(alloc->alloc_id); + + if (buf_location == IWL_FW_INI_LOCATION_INVALID || + buf_location >= IWL_FW_INI_LOCATION_NUM) + goto err; if (alloc_id == IWL_FW_INI_ALLOCATION_INVALID || - alloc_id >= IWL_FW_INI_ALLOCATION_NUM) { - IWL_ERR(trans, - "WRT: Invalid allocation id %u for allocation TLV\n", - alloc_id); - return -EINVAL; - } + alloc_id >= IWL_FW_INI_ALLOCATION_NUM) + goto err; + + if ((buf_location == IWL_FW_INI_LOCATION_SRAM_PATH || + buf_location == IWL_FW_INI_LOCATION_NPK_PATH) && + alloc_id != IWL_FW_INI_ALLOCATION_ID_DBGC1) + goto err; trans->dbg.fw_mon_cfg[alloc_id] = *alloc; return 0; +err: + IWL_ERR(trans, + "WRT: Invalid allocation id %u and/or location id %u for allocation TLV\n", + alloc_id, buf_location); + return -EINVAL; } static int iwl_dbg_tlv_alloc_hcmd(struct iwl_trans *trans, -- 2.26.2