Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp5415675rwe; Tue, 18 Apr 2023 06:40:43 -0700 (PDT) X-Google-Smtp-Source: AKy350YKP7zsW9fux+VS/MsT7xxhvYpFvwfKn5h5g/DocCneb0uInhIb/y3AiEZXE2Ux+7BgWhAl X-Received: by 2002:a17:902:f90c:b0:1a5:2b9b:67f7 with SMTP id kw12-20020a170902f90c00b001a52b9b67f7mr1827542plb.46.1681825243070; Tue, 18 Apr 2023 06:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681825243; cv=none; d=google.com; s=arc-20160816; b=Cxw5fWHvaKM9/hDJ3N/Q8sBG0/Qputa4ZdgTmNCBBVc+oCtKt4Y2wTYfzq5Ie6zxQ/ 6odbxrUa2E3qUJVG2t+F2ghYh8tdU6TlIJ63/loK8e2S0unlEuzStQsndQxAKkOaC8zs AHB05QHhiv8qE+rTvTCeLLFYr8qtFWONu7UEbWeE2iKj5lddUc+AQfOVkISO44+fXTrD nGyGRUEOCwKYE7PdVisBaAeN1Dfe1MI47JZd6vkOq6MSk7jAJgW9NNKP+LEEuOHG0Nux Z3gB/kwQrxQn5Neqo7j0t4fAZG64CFLjU5hHkHTp6ImzPb4Jc2sqm7c83noS8Fmrj8n6 f3Sg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=vla9fG0MZ4o18UXEh97Ozv0EltgjVX0HabYSfB3NCwY=; b=MeymGexRPf0KXgAh0hoX2J98gA9UmRD/zjg6C00ygxzFKfgs/Ci8xIIfMsuDuH3C+4 KWha7+JCwd84DrwXvOKtL/JXElfnUS97Z4gg4L5QAAEKzfoLRUzVMni5rg4aW4Curo/p jyE+c5CDEZJaI9XG/72/S+PTrqGfR4DKl/t4/AVNYC36vJlrw28nEa7bHG71Vmi2IWuM WE4W54fLCTLHpv8CzXTfvEs+t6VzDaFsxo5l5J8fNSSdceoQRFVvAGTy/cdFRqoDdIVE HV7i24pPB2Hx+YiSWk2faU08m5tbKi+7VUVBmPESRlmE54jjzCEjlErrqwtQ6ifNlZf2 iKNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M4FsSJbC; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 2-20020a630d42000000b004fb7e7ef77dsi14278224pgn.693.2023.04.18.06.40.18; Tue, 18 Apr 2023 06:40:43 -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=@redhat.com header.s=mimecast20190719 header.b=M4FsSJbC; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232359AbjDRN0s (ORCPT + 64 others); Tue, 18 Apr 2023 09:26:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231327AbjDRN0o (ORCPT ); Tue, 18 Apr 2023 09:26:44 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BCBB13849 for ; Tue, 18 Apr 2023 06:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681824357; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=vla9fG0MZ4o18UXEh97Ozv0EltgjVX0HabYSfB3NCwY=; b=M4FsSJbC+ND1GSXITuEFChRQDdq7yz6j6ZESQvMt5zMnTeHind0KgrkFj7o16YqD8C4KOS CX26E9uZyO5c9FlcBJcFC6X1o4fti0d3qnYJB5l0UykAZXyxal88DRbi7MNiqcWHle8KqN NJrJpOdWLMm/KBKQU47TBWoPpBaIgqs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-107-2EB-_-KANEuED3ldt5QVPw-1; Tue, 18 Apr 2023 09:25:56 -0400 X-MC-Unique: 2EB-_-KANEuED3ldt5QVPw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EAE35185A794; Tue, 18 Apr 2023 13:25:55 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.195.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id F228440C6E6F; Tue, 18 Apr 2023 13:25:54 +0000 (UTC) From: Hans de Goede To: Gregory Greenman , Kalle Valo Cc: Hans de Goede , Johannes Berg , linux-wireless@vger.kernel.org, Kees Cook , Johannes Berg Subject: [PATCH] wifi: iwlwifi: dvm: Fix memcpy: detected field-spanning write backtrace Date: Tue, 18 Apr 2023 15:25:46 +0200 Message-Id: <20230418132546.45297-1-hdegoede@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 A received TKIP key may be up to 32 bytes because it may contain MIC rx/tx keys too. These are not used by iwl and copying these over overflows the iwl_keyinfo.key field. Add a check to not copy more data to iwl_keyinfo.key then will fit. This fixes backtraces like this one: memcpy: detected field-spanning write (size 32) of single field "sta_cmd.key.key" at drivers/net/wireless/intel/iwlwifi/dvm/sta.c:1103 (size 16) WARNING: CPU: 1 PID: 946 at drivers/net/wireless/intel/iwlwifi/dvm/sta.c:1103 iwlagn_send_sta_key+0x375/0x390 [iwldvm] Hardware name: Dell Inc. Latitude E6430/0H3MT5, BIOS A21 05/08/2017 RIP: 0010:iwlagn_send_sta_key+0x375/0x390 [iwldvm] Call Trace: iwl_set_dynamic_key+0x1f0/0x220 [iwldvm] iwlagn_mac_set_key+0x1e4/0x280 [iwldvm] drv_set_key+0xa4/0x1b0 [mac80211] ieee80211_key_enable_hw_accel+0xa8/0x2d0 [mac80211] ieee80211_key_replace+0x22d/0x8e0 [mac80211] Link: https://www.alionet.org/index.php?topic=1469.0 Link: https://lore.kernel.org/linux-wireless/20230218191056.never.374-kees@kernel.org/ Link: https://lore.kernel.org/linux-wireless/68760035-7f75-1b23-e355-bfb758a87d83@redhat.com/ Cc: Kees Cook Suggested-by: Johannes Berg Signed-off-by: Hans de Goede --- drivers/net/wireless/intel/iwlwifi/dvm/sta.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/sta.c b/drivers/net/wireless/intel/iwlwifi/dvm/sta.c index cef43cf80620..8b01ab986cb1 100644 --- a/drivers/net/wireless/intel/iwlwifi/dvm/sta.c +++ b/drivers/net/wireless/intel/iwlwifi/dvm/sta.c @@ -1081,6 +1081,7 @@ static int iwlagn_send_sta_key(struct iwl_priv *priv, { __le16 key_flags; struct iwl_addsta_cmd sta_cmd; + size_t to_copy; int i; spin_lock_bh(&priv->sta_lock); @@ -1100,7 +1101,9 @@ static int iwlagn_send_sta_key(struct iwl_priv *priv, sta_cmd.key.tkip_rx_tsc_byte2 = tkip_iv32; for (i = 0; i < 5; i++) sta_cmd.key.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]); - memcpy(sta_cmd.key.key, keyconf->key, keyconf->keylen); + /* keyconf may contain MIC rx/tx keys which iwl does not use */ + to_copy = min_t(size_t, sizeof(sta_cmd.key.key), keyconf->keylen); + memcpy(sta_cmd.key.key, keyconf->key, to_copy); break; case WLAN_CIPHER_SUITE_WEP104: key_flags |= STA_KEY_FLG_KEY_SIZE_MSK; -- 2.39.2