Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3851587pxb; Tue, 17 Nov 2020 05:23:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyckGoT4up0vXgPknBJSktHjMi9jK72cijLjckGqXtYpKAcsr1s7b1ZhQeTD0+63KurdjqF X-Received: by 2002:aa7:d404:: with SMTP id z4mr21080945edq.334.1605619436725; Tue, 17 Nov 2020 05:23:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605619436; cv=none; d=google.com; s=arc-20160816; b=C0n1uzCj58kW3TBYjhx9OMOFelwTpj5d36uxLsvHH/INgFLv62S3FobsVa0CGxS5e/ SMpJOV+P9sxk+DLuK+QKxtjEXRgJJ6PCP8zX1dgvrWUpcsq0QXJ+6Fc+f/pPauMMk42g FpWCpsMlac2VuAfFRnrPn84xnmdstUg7KdU7a1G8edpy0e4Iv15imUGjiIN/YpL+lPXw ROWK+TEwvny8JkjyorN4E7JD08u4TEdGFK5f0KGzaVzc1EZpjcyIBx5lxysrgzrW2/ay sqJv2eYcPmh6XkN1oaBimdoWxdFP1dmC3D5pcGbtU5YrfaFcQfLlTAJLu+QwNDzm8Zwe SVmg== 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=dGIZDVLuNPjDD1PBc7B9ZWVOdZxa6Ywa+DeZseUCmHQ=; b=Dw7f6XQzQ6NpehU0gV6YpS1KMuRMqSMzhw6ZD6ey8cd+oMZVe1s66T8wvKdKpcriHe l3Hum59d7zNTjC5TxrbWDn28RQ+V4mEFgJ6zSaNaA0JbtYhlJz4Tmoya+/iS3GQ6Yz0r VSST/+c2IB7hUTMcq2DbNw1d3i4ShXhx3PhiIW+vmcROPLYW0J2euQ2evzHpYWyf6sGz G4FbQk9+URf2OIPvazE0agra+T+DclNtbSX9DxCsQnSKPaA4w3Mw9XMOSB3k/Qb7mQfS VEFRuYw+fFlYBJPEkxUmftcKCXrmLsyNKuTXLUXNUrsR3IcSSdapLj/K2hDbdWr5K5lg EiqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NEgRCLoQ; 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=fail (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 c25si14105505edy.364.2020.11.17.05.23.33; Tue, 17 Nov 2020 05:23:56 -0800 (PST) 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=@kernel.org header.s=default header.b=NEgRCLoQ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729417AbgKQNTR (ORCPT + 99 others); Tue, 17 Nov 2020 08:19:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:51624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730166AbgKQNS6 (ORCPT ); Tue, 17 Nov 2020 08:18:58 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3C54021734; Tue, 17 Nov 2020 13:18:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619137; bh=QDl6ZGTPmYEEeILA0AcjUgmPYYSeYYTVzSyeHeQ9+lY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NEgRCLoQdPWTMVEKH+/wH/X26J234IbxirofN+4uj0unisuqvvWqIu2wF0abXciyn x7+oTxv81C1uqICqXbFowxTqkyTohE1q80hjrO4UfvhhkFwuFLm1gXhA+yZ7yBTEoO havlCQ7548eUEQymQGXuOvpIX7/P5QRccTN16KBc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+32fd1a1bfe355e93f1e2@syzkaller.appspotmail.com, Johannes Berg , Sasha Levin Subject: [PATCH 4.19 039/101] mac80211: fix use of skb payload instead of header Date: Tue, 17 Nov 2020 14:05:06 +0100 Message-Id: <20201117122115.002353385@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122113.128215851@linuxfoundation.org> References: <20201117122113.128215851@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: Johannes Berg [ Upstream commit 14f46c1e5108696ec1e5a129e838ecedf108c7bf ] When ieee80211_skb_resize() is called from ieee80211_build_hdr() the skb has no 802.11 header yet, in fact it consist only of the payload as the ethernet frame is removed. As such, we're using the payload data for ieee80211_is_mgmt(), which is of course completely wrong. This didn't really hurt us because these are always data frames, so we could only have added more tailroom than we needed if we determined it was a management frame and sdata->crypto_tx_tailroom_needed_cnt was false. However, syzbot found that of course there need not be any payload, so we're using at best uninitialized memory for the check. Fix this to pass explicitly the kind of frame that we have instead of checking there, by replacing the "bool may_encrypt" argument with an argument that can carry the three possible states - it's not going to be encrypted, it's a management frame, or it's a data frame (and then we check sdata->crypto_tx_tailroom_needed_cnt). Reported-by: syzbot+32fd1a1bfe355e93f1e2@syzkaller.appspotmail.com Signed-off-by: Johannes Berg Link: https://lore.kernel.org/r/20201009132538.e1fd7f802947.I799b288466ea2815f9d4c84349fae697dca2f189@changeid Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- net/mac80211/tx.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 3160ffd93a153..98d048630ad2f 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -1908,19 +1908,24 @@ static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata, /* device xmit handlers */ +enum ieee80211_encrypt { + ENCRYPT_NO, + ENCRYPT_MGMT, + ENCRYPT_DATA, +}; + static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, - int head_need, bool may_encrypt) + int head_need, + enum ieee80211_encrypt encrypt) { struct ieee80211_local *local = sdata->local; - struct ieee80211_hdr *hdr; bool enc_tailroom; int tail_need = 0; - hdr = (struct ieee80211_hdr *) skb->data; - enc_tailroom = may_encrypt && - (sdata->crypto_tx_tailroom_needed_cnt || - ieee80211_is_mgmt(hdr->frame_control)); + enc_tailroom = encrypt == ENCRYPT_MGMT || + (encrypt == ENCRYPT_DATA && + sdata->crypto_tx_tailroom_needed_cnt); if (enc_tailroom) { tail_need = IEEE80211_ENCRYPT_TAILROOM; @@ -1952,23 +1957,29 @@ void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, { struct ieee80211_local *local = sdata->local; struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); - struct ieee80211_hdr *hdr; + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; int headroom; - bool may_encrypt; + enum ieee80211_encrypt encrypt; - may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT); + if (info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT) + encrypt = ENCRYPT_NO; + else if (ieee80211_is_mgmt(hdr->frame_control)) + encrypt = ENCRYPT_MGMT; + else + encrypt = ENCRYPT_DATA; headroom = local->tx_headroom; - if (may_encrypt) + if (encrypt != ENCRYPT_NO) headroom += sdata->encrypt_headroom; headroom -= skb_headroom(skb); headroom = max_t(int, 0, headroom); - if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) { + if (ieee80211_skb_resize(sdata, skb, headroom, encrypt)) { ieee80211_free_txskb(&local->hw, skb); return; } + /* reload after potential resize */ hdr = (struct ieee80211_hdr *) skb->data; info->control.vif = &sdata->vif; @@ -2751,7 +2762,7 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, head_need += sdata->encrypt_headroom; head_need += local->tx_headroom; head_need = max_t(int, 0, head_need); - if (ieee80211_skb_resize(sdata, skb, head_need, true)) { + if (ieee80211_skb_resize(sdata, skb, head_need, ENCRYPT_DATA)) { ieee80211_free_txskb(&local->hw, skb); skb = NULL; return ERR_PTR(-ENOMEM); @@ -3414,7 +3425,7 @@ static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata, if (unlikely(ieee80211_skb_resize(sdata, skb, max_t(int, extra_head + hw_headroom - skb_headroom(skb), 0), - false))) { + ENCRYPT_NO))) { kfree_skb(skb); return true; } -- 2.27.0