Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2655091pxj; Mon, 31 May 2021 07:30:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxW4O7i7fhzv8HNJ6y4Eskh9R2bOYuKCp0I2qiAqzpcBg4PwSEc+FuCEvxAihIjZlhnG2Ma X-Received: by 2002:a92:cc51:: with SMTP id t17mr3857067ilq.113.1622471451858; Mon, 31 May 2021 07:30:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622471451; cv=none; d=google.com; s=arc-20160816; b=m31yfFkJz6HxRW15tVpKflMbbAMZjbyaZeBo611XyRuhDO7b+9gy2htYBQWIILn33B elnhwPH37Br6bJCIu1rqmV0fh9qqfh+I7nBPRjwrpTZaiWqhmiCLecYE/rtcMG+gQ3wW 9v8NpifJWrAG0zbBWuQzxdRi+C+VQ+mXqCGzDrt6iIvPZ22IFINnmu1vdpBpxCQi/30A pktG01BmcJf2Ql+FcfQhmkMplJcOG3aNVr8W5g34Sd91Tn7OPKGNgi8ZGy+cGmHIzW7b iNbcPToCJ9eK1octOrVY+mjmL66jWLw2I04dbGVsm3ZWXE8yxqdCmY4EXvHpfZO2Yvr6 hKow== 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=NtdvzlKA54PNP9Px9Rv5X3r8epvR0sRf4/18Pno6xIo=; b=MMJ57LxDzXK5FbIIsGsxaHJF3CZbd7fAiUge0fyH92489O+Q9bbNLpVOlZGLp4aJMt G6dzI0d8RtfHrHou720UgYYJsmKQyyhWM41C5Ktxy2Wp6k6zLHuufRxo/CR00sLh/iYZ iRAVrJxRDXEobDH7e0OUgEWFaMaWEYE1IkBX4BEJdSYeaAowmR72fOa76lAaE8nu5EOp XJWEk2fZAyGjHuKqOsqj67cGEO1UOjsGXRQz8POp8/jY2d11MyGfSbUUPnofujt3RXe3 NJ0a44RhlTa4ZWqThx8oZfhvobTaQIW/V97zFnABPCnHL7TFrUJiAFZmd1qaaENQdv54 6Avw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HjOGV+C6; 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 j10si13845102ilc.16.2021.05.31.07.30.38; Mon, 31 May 2021 07:30:51 -0700 (PDT) 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=HjOGV+C6; 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 S232524AbhEaOb1 (ORCPT + 99 others); Mon, 31 May 2021 10:31:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:55372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232102AbhEaNxw (ORCPT ); Mon, 31 May 2021 09:53:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7F6E66191C; Mon, 31 May 2021 13:33:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468011; bh=1o2+Is/pQJipStDRXaYgWWfEyZRlUpcSGH2OSIKcdBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HjOGV+C6niZKQarOvl5KSWSACnm2p/FO1MGER8vi+3sw6aFpzdtnM9ROZYrZLKk/U z9OcaSnXdsy/U1B49k1RVGPUY0ZzctdnA3fzX69T0bMpnGA4jKGZyugQ860bj94iE+ o/67JrNaBQiZS7e5N3OWRPg7bYwauAWatyYeDt2w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sriram R , Jouni Malinen , Johannes Berg Subject: [PATCH 5.10 038/252] ath10k: Validate first subframe of A-MSDU before processing the list Date: Mon, 31 May 2021 15:11:43 +0200 Message-Id: <20210531130659.287223417@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@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: Sriram R commit 62a8ff67eba52dae9b107e1fb8827054ed00a265 upstream. In certain scenarios a normal MSDU can be received as an A-MSDU when the A-MSDU present bit of a QoS header gets flipped during reception. Since this bit is unauthenticated, the hardware crypto engine can pass the frame to the driver without any error indication. This could result in processing unintended subframes collected in the A-MSDU list. Hence, validate A-MSDU list by checking if the first frame has a valid subframe header. Comparing the non-aggregated MSDU and an A-MSDU, the fields of the first subframe DA matches the LLC/SNAP header fields of a normal MSDU. In order to avoid processing such frames, add a validation to filter such A-MSDU frames where the first subframe header DA matches with the LLC/SNAP header pattern. Tested-on: QCA9984 hw1.0 PCI 10.4-3.10-00047 Cc: stable@vger.kernel.org Signed-off-by: Sriram R Signed-off-by: Jouni Malinen Link: https://lore.kernel.org/r/20210511200110.e6f5eb7b9847.I38a77ae26096862527a5eab73caebd7346af8b66@changeid Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- drivers/net/wireless/ath/ath10k/htt_rx.c | 61 ++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) --- a/drivers/net/wireless/ath/ath10k/htt_rx.c +++ b/drivers/net/wireless/ath/ath10k/htt_rx.c @@ -2108,14 +2108,62 @@ static void ath10k_htt_rx_h_unchain(stru ath10k_unchain_msdu(amsdu, unchain_cnt); } +static bool ath10k_htt_rx_validate_amsdu(struct ath10k *ar, + struct sk_buff_head *amsdu) +{ + u8 *subframe_hdr; + struct sk_buff *first; + bool is_first, is_last; + struct htt_rx_desc *rxd; + struct ieee80211_hdr *hdr; + size_t hdr_len, crypto_len; + enum htt_rx_mpdu_encrypt_type enctype; + int bytes_aligned = ar->hw_params.decap_align_bytes; + + first = skb_peek(amsdu); + + rxd = (void *)first->data - sizeof(*rxd); + hdr = (void *)rxd->rx_hdr_status; + + is_first = !!(rxd->msdu_end.common.info0 & + __cpu_to_le32(RX_MSDU_END_INFO0_FIRST_MSDU)); + is_last = !!(rxd->msdu_end.common.info0 & + __cpu_to_le32(RX_MSDU_END_INFO0_LAST_MSDU)); + + /* Return in case of non-aggregated msdu */ + if (is_first && is_last) + return true; + + /* First msdu flag is not set for the first msdu of the list */ + if (!is_first) + return false; + + enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0), + RX_MPDU_START_INFO0_ENCRYPT_TYPE); + + hdr_len = ieee80211_hdrlen(hdr->frame_control); + crypto_len = ath10k_htt_rx_crypto_param_len(ar, enctype); + + subframe_hdr = (u8 *)hdr + round_up(hdr_len, bytes_aligned) + + crypto_len; + + /* Validate if the amsdu has a proper first subframe. + * There are chances a single msdu can be received as amsdu when + * the unauthenticated amsdu flag of a QoS header + * gets flipped in non-SPP AMSDU's, in such cases the first + * subframe has llc/snap header in place of a valid da. + * return false if the da matches rfc1042 pattern + */ + if (ether_addr_equal(subframe_hdr, rfc1042_header)) + return false; + + return true; +} + static bool ath10k_htt_rx_amsdu_allowed(struct ath10k *ar, struct sk_buff_head *amsdu, struct ieee80211_rx_status *rx_status) { - /* FIXME: It might be a good idea to do some fuzzy-testing to drop - * invalid/dangerous frames. - */ - if (!rx_status->freq) { ath10k_dbg(ar, ATH10K_DBG_HTT, "no channel configured; ignoring frame(s)!\n"); return false; @@ -2126,6 +2174,11 @@ static bool ath10k_htt_rx_amsdu_allowed( return false; } + if (!ath10k_htt_rx_validate_amsdu(ar, amsdu)) { + ath10k_dbg(ar, ATH10K_DBG_HTT, "invalid amsdu received\n"); + return false; + } + return true; }