Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3930060pxj; Mon, 21 Jun 2021 09:35:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2jvFabpy6W9R/3GoAw37BhguKmZkREgmKGqdum+gS/I1z4lu2E6hBDlmcf+zmMZm8Woob X-Received: by 2002:a05:6402:26c7:: with SMTP id x7mr1613734edd.383.1624293356680; Mon, 21 Jun 2021 09:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624293356; cv=none; d=google.com; s=arc-20160816; b=b0joZvC16VFt69ES4yTf4ZyQ283az/9f7AFGG2FRm2J0M4BoUlyV3o9RhuCzHUXrJd E6MVBKwbz0JHdSfgOghvxgyl9ZJwRCmyGrhuQW862wM4kV9KLNjlG1BmZ0+D4tA1VCWo aTrb0m5u/cx8PzsYoxBGn95bhXLo+D1wL4jqwv0nGeBjTXOTBLEQ9uJVjwEq/l6G7yvz tprt+lVoCD1eWm1fccJIlRrOBKcbPj8+cpnS2bHHs7no1Tr+oijI9p72xSOKOuQR4od0 EZuiNbYIJYTkkEo9yn/H9N92Yl6FA1F0jEztcMyW6SnvpxhifvA0hVNIoO05BVX+TunK J/Ww== 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=vAVKKXp9XRcrQMu0R3NiKr8Ky1VQYqYZbT4hzByTWiU=; b=t/tTkUyHqmh0WqzGrgM37tnocb9ATYkBCzNwAYnN8r16YrxyHnGbRJD7RRKXEvp8C5 x+9hJyR5dikYjaIoHfcQwbAabXoar7UFUi4HXeZNsUBZwcKuI6gl6X/QuYkWQ7ibBUUg OBK0DZoLnaIsN4DnETsxL/jN0cXJR7KZP4Ursa+HjAa9uRi++eDGh912m9t16x8et5ll BfvsGdyo1ZwraouvscduC5VSrAuaPYtNFWLzZKSdLp/RvAnSa7qyvipHp+zuqWxCtEeI uCm8SlFHwPWSHtTVedHUhXXOoOxv/0uqNmPLx48MQTuFRw5DAsFUf6tw5PcAcUU+NluL HZgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ja+o4SwQ; 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 f2si7628365edv.62.2021.06.21.09.35.34; Mon, 21 Jun 2021 09:35:56 -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=Ja+o4SwQ; 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 S232662AbhFUQgz (ORCPT + 99 others); Mon, 21 Jun 2021 12:36:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:56006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231143AbhFUQdM (ORCPT ); Mon, 21 Jun 2021 12:33:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 004C061369; Mon, 21 Jun 2021 16:26:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292778; bh=MDCNXLQaQeRCclZguFc8JPVwqRvHbGxIhkqjfdDrtS8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ja+o4SwQjMubNFaEBr+r3UJKd2lc/eYooKyNnlcRdPnJDVUIxQ5cwUOrSG/pGLg0z wYzYDwfEQEyBQ4is9/YjKOfU+BMojmnCWKO8pwvnaBnJ0kv1rZKJdZwNGxJHEDvBqG MtnCIdji/cccCH5hmCh8EFtVJn3/gcfui1E4nOik= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ben Greear , Mathy Vanhoef , Sven Eckelmann , Johannes Berg Subject: [PATCH 5.10 127/146] mac80211: Fix NULL ptr deref for injected rate info Date: Mon, 21 Jun 2021 18:15:57 +0200 Message-Id: <20210621154919.487162348@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154911.244649123@linuxfoundation.org> References: <20210621154911.244649123@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: Mathy Vanhoef commit bddc0c411a45d3718ac535a070f349be8eca8d48 upstream. The commit cb17ed29a7a5 ("mac80211: parse radiotap header when selecting Tx queue") moved the code to validate the radiotap header from ieee80211_monitor_start_xmit to ieee80211_parse_tx_radiotap. This made is possible to share more code with the new Tx queue selection code for injected frames. But at the same time, it now required the call of ieee80211_parse_tx_radiotap at the beginning of functions which wanted to handle the radiotap header. And this broke the rate parser for radiotap header parser. The radiotap parser for rates is operating most of the time only on the data in the actual radiotap header. But for the 802.11a/b/g rates, it must also know the selected band from the chandef information. But this information is only written to the ieee80211_tx_info at the end of the ieee80211_monitor_start_xmit - long after ieee80211_parse_tx_radiotap was already called. The info->band information was therefore always 0 (NL80211_BAND_2GHZ) when the parser code tried to access it. For a 5GHz only device, injecting a frame with 802.11a rates would cause a NULL pointer dereference because local->hw.wiphy->bands[NL80211_BAND_2GHZ] would most likely have been NULL when the radiotap parser searched for the correct rate index of the driver. Cc: stable@vger.kernel.org Reported-by: Ben Greear Fixes: cb17ed29a7a5 ("mac80211: parse radiotap header when selecting Tx queue") Signed-off-by: Mathy Vanhoef [sven@narfation.org: added commit message] Signed-off-by: Sven Eckelmann Link: https://lore.kernel.org/r/20210530133226.40587-1-sven@narfation.org Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- include/net/mac80211.h | 7 +++++- net/mac80211/tx.c | 52 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 17 deletions(-) --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -6335,7 +6335,12 @@ bool ieee80211_tx_prepare_skb(struct iee /** * ieee80211_parse_tx_radiotap - Sanity-check and parse the radiotap header - * of injected frames + * of injected frames. + * + * To accurately parse and take into account rate and retransmission fields, + * you must initialize the chandef field in the ieee80211_tx_info structure + * of the skb before calling this function. + * * @skb: packet injected by userspace * @dev: the &struct device of this 802.11 device */ --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -2030,6 +2030,26 @@ void ieee80211_xmit(struct ieee80211_sub ieee80211_tx(sdata, sta, skb, false); } +static bool ieee80211_validate_radiotap_len(struct sk_buff *skb) +{ + struct ieee80211_radiotap_header *rthdr = + (struct ieee80211_radiotap_header *)skb->data; + + /* check for not even having the fixed radiotap header part */ + if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header))) + return false; /* too short to be possibly valid */ + + /* is it a header version we can trust to find length from? */ + if (unlikely(rthdr->it_version)) + return false; /* only version 0 is supported */ + + /* does the skb contain enough to deliver on the alleged length? */ + if (unlikely(skb->len < ieee80211_get_radiotap_len(skb->data))) + return false; /* skb too short for claimed rt header extent */ + + return true; +} + bool ieee80211_parse_tx_radiotap(struct sk_buff *skb, struct net_device *dev) { @@ -2038,8 +2058,6 @@ bool ieee80211_parse_tx_radiotap(struct struct ieee80211_radiotap_header *rthdr = (struct ieee80211_radiotap_header *) skb->data; struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); - struct ieee80211_supported_band *sband = - local->hw.wiphy->bands[info->band]; int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len, NULL); u16 txflags; @@ -2052,17 +2070,8 @@ bool ieee80211_parse_tx_radiotap(struct u8 vht_mcs = 0, vht_nss = 0; int i; - /* check for not even having the fixed radiotap header part */ - if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header))) - return false; /* too short to be possibly valid */ - - /* is it a header version we can trust to find length from? */ - if (unlikely(rthdr->it_version)) - return false; /* only version 0 is supported */ - - /* does the skb contain enough to deliver on the alleged length? */ - if (unlikely(skb->len < ieee80211_get_radiotap_len(skb->data))) - return false; /* skb too short for claimed rt header extent */ + if (!ieee80211_validate_radiotap_len(skb)) + return false; info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | IEEE80211_TX_CTL_DONTFRAG; @@ -2186,6 +2195,9 @@ bool ieee80211_parse_tx_radiotap(struct return false; if (rate_found) { + struct ieee80211_supported_band *sband = + local->hw.wiphy->bands[info->band]; + info->control.flags |= IEEE80211_TX_CTRL_RATE_INJECT; for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { @@ -2199,7 +2211,7 @@ bool ieee80211_parse_tx_radiotap(struct } else if (rate_flags & IEEE80211_TX_RC_VHT_MCS) { ieee80211_rate_set_vht(info->control.rates, vht_mcs, vht_nss); - } else { + } else if (sband) { for (i = 0; i < sband->n_bitrates; i++) { if (rate * 5 != sband->bitrates[i].bitrate) continue; @@ -2236,8 +2248,8 @@ netdev_tx_t ieee80211_monitor_start_xmit info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS | IEEE80211_TX_CTL_INJECTED; - /* Sanity-check and process the injection radiotap header */ - if (!ieee80211_parse_tx_radiotap(skb, dev)) + /* Sanity-check the length of the radiotap header */ + if (!ieee80211_validate_radiotap_len(skb)) goto fail; /* we now know there is a radiotap header with a length we can use */ @@ -2353,6 +2365,14 @@ netdev_tx_t ieee80211_monitor_start_xmit info->band = chandef->chan->band; + /* + * Process the radiotap header. This will now take into account the + * selected chandef above to accurately set injection rates and + * retransmissions. + */ + if (!ieee80211_parse_tx_radiotap(skb, dev)) + goto fail_rcu; + /* remove the injection radiotap header */ skb_pull(skb, len_rthdr);