Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp569391rwd; Sun, 14 May 2023 02:19:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Gy2zbxTWnHqKhmzv9UxwQpv1ZGGAKPI9wjqwESuoehC5MF5u2XgHM5VmyPJcVRl16Leml X-Received: by 2002:a17:902:b110:b0:1aa:f6ed:973d with SMTP id q16-20020a170902b11000b001aaf6ed973dmr26504478plr.55.1684055960247; Sun, 14 May 2023 02:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684055960; cv=none; d=google.com; s=arc-20160816; b=cBkCj4facbI+kmiHvhRtrbS+D2VDGOlKA5LMgHqJt6VjeexXkoLuagY9F2tEfUGVKO kfAZPPYFOPkhhNvGJ2cvdrAnZog3OPWDJI6W+LzuzBMB8NGCQ9BK9pNxXaSyOeo2ABQT wkrT5RHIpvH+0h+IyztLpHvUCtwLO/S3S+2GN/SA8u3A6DrZt4xkX74tzgd4Pvtzrmn2 8+PJ2Q+n3O3q8bDcu7J0Dn8THcWNoyvwWKCEuuEiyOdyVa6gMu1nAxcRKeJroYmX/Coj ojeeggbQMLapZ1g5ZVOBiZQxUj4WS9wRYthh5GimXqvrzlqr5/Hx11B3LXbKmvbmFEM3 xA1A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0K2hxJnKNCjnCXURMsK3z4/gz2OvYaH6h9aSe6KckyI=; b=z0+kgafyBhIhv6qXzfA55+PHOhVCaWSIHeR298OoTQ25bjhpQ5Rxr6d97duMxE7NwM B3z+bBGRKyNdjlEU3C8Lr6AymeCQmuVdy90BXi92hainAQvr6FMDqTeWWI1wmgjhiO6e GnfLQBySBZGC0WAn++YqJkjOZ+WehgrObzwkJ2N5/hR3IzXElcX3pupPbtS/LxgD9Wny lbZDEJ4jCuOV58Pon0jOAG7tPCvjojGZbFYJK4MLwq4Vj5fSod5uoEjk2XKMsxkyIDzj oCYbL9JrPNKox0R51RtFdpFHLkdMq1i/dAVfPlmOvcFO7/gF/j1UXZly1diL+Hb9YcLh Vi9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="lDnhu/Fb"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b191-20020a6334c8000000b005303b08eb16si13798792pga.631.2023.05.14.02.19.13; Sun, 14 May 2023 02:19:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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=@intel.com header.s=Intel header.b="lDnhu/Fb"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231637AbjENJQp (ORCPT + 61 others); Sun, 14 May 2023 05:16:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235354AbjENJQn (ORCPT ); Sun, 14 May 2023 05:16:43 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5584F1BE5 for ; Sun, 14 May 2023 02:16:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684055797; x=1715591797; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2a0c6csWwNKpik/AcjqzmB2UjxQ3OYfVNuG+Gfm5mC4=; b=lDnhu/FbPkkhQXXsQekP1s4TERlCje0JfEEmpJN4iQRwmCowtv2njixA +U932YmYG3QEamCZoXfTJEwslPrEID7XHVkiya+5YFAs1Ugg81g3xmQhn GEsQUJLbf+OM22sStVHE3YW0a1kY/MtlyNjx04T5xK1RZmhQvaKRl1pfR 95630fsVNADC1dGV2O1okGXAfETgsqIuHkT1q3gi3V2xiF2RPa6SaMKFi VU5ioY1SAnhQpZlnGY6BJqZ48Y455DSXP55DGJiiZEudkCzcDPCcKNKZA niuMc6FoCR6Vfv+w3iOsBM7/fPvJ4kaXnddHFw80X3prEMcLSOhUrYBKs w==; X-IronPort-AV: E=McAfee;i="6600,9927,10709"; a="340366863" X-IronPort-AV: E=Sophos;i="5.99,274,1677571200"; d="scan'208";a="340366863" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2023 02:16:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10709"; a="731300458" X-IronPort-AV: E=Sophos;i="5.99,274,1677571200"; d="scan'208";a="731300458" Received: from seran-mobl1.ger.corp.intel.com (HELO ggreenma-mobl2.lan) ([10.214.239.223]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2023 02:16:35 -0700 From: gregory.greenman@intel.com To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Johannes Berg , Gregory Greenman Subject: [PATCH wireless 10/12] wifi: iwlwifi: mvm: don't trust firmware n_channels Date: Sun, 14 May 2023 12:15:53 +0300 Message-Id: <20230514120631.d7b233139eb4.I51fd319df8e9d41881fc8450e83d78049518a79a@changeid> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230514091555.168392-1-gregory.greenman@intel.com> References: <20230514091555.168392-1-gregory.greenman@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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-wireless@vger.kernel.org From: Johannes Berg If the firmware sends us a corrupted MCC response with n_channels much larger than the command response can be, we might copy far too much (uninitialized) memory and even crash if the n_channels is large enough to make it run out of the one page allocated for the FW response. Fix that by checking the lengths. Doing a < comparison would be sufficient, but the firmware should be doing it correctly, so check more strictly. Fixes: dcaf9f5ecb6f ("iwlwifi: mvm: add MCC update FW API") Signed-off-by: Johannes Berg Signed-off-by: Gregory Greenman --- drivers/net/wireless/intel/iwlwifi/mvm/nvm.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c b/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c index 6d18a1fd649b..fdf60afb0f3f 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c @@ -445,6 +445,11 @@ iwl_mvm_update_mcc(struct iwl_mvm *mvm, const char *alpha2, struct iwl_mcc_update_resp *mcc_resp = (void *)pkt->data; n_channels = __le32_to_cpu(mcc_resp->n_channels); + if (iwl_rx_packet_payload_len(pkt) != + struct_size(mcc_resp, channels, n_channels)) { + resp_cp = ERR_PTR(-EINVAL); + goto exit; + } resp_len = sizeof(struct iwl_mcc_update_resp) + n_channels * sizeof(__le32); resp_cp = kmemdup(mcc_resp, resp_len, GFP_KERNEL); @@ -456,6 +461,11 @@ iwl_mvm_update_mcc(struct iwl_mvm *mvm, const char *alpha2, struct iwl_mcc_update_resp_v3 *mcc_resp_v3 = (void *)pkt->data; n_channels = __le32_to_cpu(mcc_resp_v3->n_channels); + if (iwl_rx_packet_payload_len(pkt) != + struct_size(mcc_resp_v3, channels, n_channels)) { + resp_cp = ERR_PTR(-EINVAL); + goto exit; + } resp_len = sizeof(struct iwl_mcc_update_resp) + n_channels * sizeof(__le32); resp_cp = kzalloc(resp_len, GFP_KERNEL); -- 2.38.1