Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5976533rwr; Mon, 24 Apr 2023 11:39:29 -0700 (PDT) X-Google-Smtp-Source: AKy350YmnBF+yx8iZx42ofcHQK/7KliS9o9FWaDLdspi3EBXAYJYUwECVXVgtX9RhfoEu/g1q+vf X-Received: by 2002:a17:903:24e:b0:1a6:4a64:4d27 with SMTP id j14-20020a170903024e00b001a64a644d27mr18578851plh.40.1682361569206; Mon, 24 Apr 2023 11:39:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682361569; cv=none; d=google.com; s=arc-20160816; b=mDLMyGBnKi9zIn9cWn+VdtBJ+0YGod0Hh1TZVmZnjNRkROyI7aJhIYYp55yS6mNd/R HuQjfggjGcq+YVDYhjd+FMFVM9a1ihdo9IZX6/NtRVPAHPGQJS2mhBh7O7Au0X2iyFTT TxW3RnVeguCDxozQWJHo1SAk56MBBeb3yxJOL8smXwXEnho9rj5GydbIMfkeyDNBQa8y Vwl1IrfR6cP1eb6FYeK6oSf5Wu373OJUMIZfPypWtXFPbXcrOzwdqZ7w3QIng1oMIlM6 YVng4C7IfTPpz3x3NMsDI/7fZwSZ0RNNHP93v2rGhk/bJVT7rgojvJU2haNYWhyPKDiL Qefg== 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:dkim-filter; bh=PRIdr5ITnjkysoIatNA0p/ZUHeBN+gItyLquEJcHG7M=; b=hxSCpOjAAnCErje9IgzZQign78GmonZzfqQe+kOVtJRK4ZKpBKPcQJh27zPajYFN9f a8BqzT4TYGeJr8oZHLCzFgKU+1owBtdDgyM3rMstnx9k2FIToHnUbEgGbML0xdlP+eVI K1/I/hsqPbBR/IJB2WwULWpsjE5dhOC1hTDnn0X3kzEU8PRa6InvVVOuFtEfZ3kEtkT6 CKrmKA4HG58RDF2ZXKQWeEChMu1y0dgBJiLriHqtbCw0+d0GAAQp+3qLwizJ8vh5aGNw utW5uC7VKQOz+bocoOpbw5nqfFyEhkykSvk+WRjEcR35mq4vYQlaJlUqSulqo0Dq7h8v NrhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=arVHo42+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b16-20020a170902e95000b001a93e74c8b6si10560498pll.595.2023.04.24.11.39.17; Mon, 24 Apr 2023 11:39:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@ispras.ru header.s=default header.b=arVHo42+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232281AbjDXSel (ORCPT + 99 others); Mon, 24 Apr 2023 14:34:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbjDXSeh (ORCPT ); Mon, 24 Apr 2023 14:34:37 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8A84FA; Mon, 24 Apr 2023 11:34:35 -0700 (PDT) Received: from fpc.. (unknown [46.242.14.200]) by mail.ispras.ru (Postfix) with ESMTPSA id E9104407626E; Mon, 24 Apr 2023 18:34:33 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru E9104407626E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1682361274; bh=PRIdr5ITnjkysoIatNA0p/ZUHeBN+gItyLquEJcHG7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=arVHo42+Ms6WNHPJyjNBUnplzA0d9vVLl2ngnRfDxQfxKyEhT8O+CQ4Xcg4WqSC5t B/0auEjXE9IJtc7O+G6E9hGnvM/WO2hxv5WJct1uGgLGzaNqga2ju7YEVOMWzM15zI cDJQqWtZFJZ76UqDBc9ooPjDwclyUJ5zctUpgbq4= From: Fedor Pchelkin To: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Kalle Vallo Cc: Fedor Pchelkin , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Senthil Balasubramanian , "John W. Linville" , Vasanthakumar Thiagarajan , Sujith , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexey Khoroshilov , lvc-project@linuxtesting.org, syzbot+f2cb6e0ffdb961921e4d@syzkaller.appspotmail.com Subject: [PATCH v2] wifi: ath9k: avoid referencing uninit memory in ath9k_wmi_ctrl_rx Date: Mon, 24 Apr 2023 21:33:48 +0300 Message-Id: <20230424183348.111355-1-pchelkin@ispras.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230424182300.sw5ogmcst5suf2ab@fpc> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, 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-kernel@vger.kernel.org For the reasons also described in commit b383e8abed41 ("wifi: ath9k: avoid uninit memory read in ath9k_htc_rx_msg()"), ath9k_htc_rx_msg() should validate pkt_len before accessing the SKB. For example, the obtained SKB may have been badly constructed with pkt_len = 8. In this case, the SKB can only contain a valid htc_frame_hdr but after being processed in ath9k_htc_rx_msg() and passed to ath9k_wmi_ctrl_rx() endpoint RX handler, it is expected to have a WMI command header which should be located inside its data payload. Implement sanity checking inside ath9k_wmi_ctrl_rx(). Otherwise, uninit memory can be referenced. Tested on Qualcomm Atheros Communications AR9271 802.11n . Found by Linux Verification Center (linuxtesting.org) with Syzkaller. Fixes: fb9987d0f748 ("ath9k_htc: Support for AR9271 chipset.") Reported-and-tested-by: syzbot+f2cb6e0ffdb961921e4d@syzkaller.appspotmail.com Signed-off-by: Fedor Pchelkin --- v2: remove incorrect checks and rephrase commit info drivers/net/wireless/ath/ath9k/wmi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/wireless/ath/ath9k/wmi.c b/drivers/net/wireless/ath/ath9k/wmi.c index 19345b8f7bfd..d652c647d56b 100644 --- a/drivers/net/wireless/ath/ath9k/wmi.c +++ b/drivers/net/wireless/ath/ath9k/wmi.c @@ -221,6 +221,10 @@ static void ath9k_wmi_ctrl_rx(void *priv, struct sk_buff *skb, if (unlikely(wmi->stopped)) goto free_skb; + /* Validate the obtained SKB. */ + if (unlikely(skb->len < sizeof(struct wmi_cmd_hdr))) + goto free_skb; + hdr = (struct wmi_cmd_hdr *) skb->data; cmd_id = be16_to_cpu(hdr->command_id); -- 2.34.1