Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp345532pxb; Mon, 16 Aug 2021 06:48:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzg2C+KF3JvON3sTPu7S59O6gO/UOySdmVwFf5P/74YakJd4WJ6Xp8/FaO4hLG8QoHOJsiQ X-Received: by 2002:a05:6638:419a:: with SMTP id az26mr15405826jab.70.1629121700813; Mon, 16 Aug 2021 06:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629121700; cv=none; d=google.com; s=arc-20160816; b=LkEXrnIO+qiNUjbLt47+z5yo5N2CkEj3C4Q4n+avw11OUvEqPFxrvF01DA+76VG4IV L/e4WUDDKlWa6b+iVrFhupiKAJqXs3x0/SKj0u7hu+00JSIKZcEAi7oFNDb7PMHb9y72 HVFhKxEM7/+gKJXM76LXJWD+rzdmwzEtv1y4UhwxfMkrqPRHom379fNF+Xg0w6Mr7aa9 mJrsr1q3uDQiCmCOkzmN4mUgoaOSCZUWnkCSR2Eyhn8ixVu1qZSiHtl5/cDBjBLbW5UW hcTD4ErnUvloyZQGiaHaMVdPo98k/FaYDrkwXPy0bx/J8lWZE1xvMEHq1oDjf1wpVAii UoWA== 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; bh=zgbEmYiLaXda/+f/goUmlyaOJi1oX4Wtq9AwOZUz3Fg=; b=k7lBhb0OQi3/miruoGq5+yv7+0h/S7ozdVz6P3wns/OlkfzLHJtonG542l7ULRDFKM +NOnRcpY5KSqjzuFiXLCB1aFmo1NG+VcXywkcoRkBAu7IrsacAUdPqaauW5kaPO/NI0h 6xzkD6fZntqYHVBuAH7ykWcR/WbPYZTvkpMuFDys5cPgMyidsbPEhTMp4oE9Rqo5tEBD GHgHD9v5IN/7OdgrlKj27V67PbjivgF/QCfkaGoY+YU7E2qtdqVjD+Ggk1CQ+AOuEdZe JLs6bLf/dInFr2M7u0EC0tQyt72UwXydyfQl25PlegLxjpAty23FWuW4aQ6W0xEu0jQz ohYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aqz+j91W; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g15si7893660ilc.45.2021.08.16.06.48.03; Mon, 16 Aug 2021 06:48:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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=k20201202 header.b=aqz+j91W; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231756AbhHPNpK (ORCPT + 99 others); Mon, 16 Aug 2021 09:45:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:60152 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbhHPNpI (ORCPT ); Mon, 16 Aug 2021 09:45:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CCBE863282; Mon, 16 Aug 2021 13:44:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629121476; bh=DBLx5Qi1xn3W3lUbGH5/MbJacCST668Js48ekUZyKkU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aqz+j91WbqNXs+0TWqTn3VZHdph25VwNBZoh+3SAHxIOzR7iLrYyVQ2Lbx7BBZ4hC Gm/UIsvsK7vpnYgIpVH8vBAZofRdta8a5EXVLM1Eqg9Pl3y9dviRqSWYuIrI3oVwCh paj9AsP06bG+YT0eGbmx/CaMiDi6l3npoR86c8p1l3b+gaSDZ3S+B3+o5v3XVCAnl4 /SOvbtnn+SWz6HbsT0Ex1qyiNmvu41eK0UtuVWtYKZEtJ5Y98CJqOdldomgxrU7dt+ vVWbKSWqKfpOHlZ6qWdyr0ePsbRZc+8Bzby9TG24/OPWbNJPW8fVHvU7/BSSR1WMch IgQnzkFB2NXKA== Received: by pali.im (Postfix) id CA4992B76; Mon, 16 Aug 2021 15:44:33 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: stable@vger.kernel.org Cc: Johannes Berg , Sasha Levin , Luca Coelho , linux-wireless@vger.kernel.org Subject: [PATCH] mac80211: drop data frames without key on encrypted links Date: Mon, 16 Aug 2021 15:44:24 +0200 Message-Id: <20210816134424.28191-1-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200327150342.252AF20748@mail.kernel.org> References: <20200327150342.252AF20748@mail.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Johannes Berg commit a0761a301746ec2d92d7fcb82af69c0a6a4339aa upstream. If we know that we have an encrypted link (based on having had a key configured for TX in the past) then drop all data frames in the key selection handler if there's no key anymore. This fixes an issue with mac80211 internal TXQs - there we can buffer frames for an encrypted link, but then if the key is no longer there when they're dequeued, the frames are sent without encryption. This happens if a station is disconnected while the frames are still on the TXQ. Detecting that a link should be encrypted based on a first key having been configured for TX is fine as there are no use cases for a connection going from with encryption to no encryption. With extended key IDs, however, there is a case of having a key configured for only decryption, so we can't just trigger this behaviour on a key being configured. Cc: stable@vger.kernel.org Reported-by: Jouni Malinen Signed-off-by: Johannes Berg Signed-off-by: Luca Coelho Link: https://lore.kernel.org/r/iwlwifi.20200326150855.6865c7f28a14.I9fb1d911b064262d33e33dfba730cdeef83926ca@changeid Signed-off-by: Johannes Berg [pali: Backported to 4.19 and older versions] Signed-off-by: Pali Rohár --- net/mac80211/debugfs_sta.c | 1 + net/mac80211/key.c | 1 + net/mac80211/sta_info.h | 1 + net/mac80211/tx.c | 12 +++++++++--- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c index 4105081dc1df..6f390c2e4c8e 100644 --- a/net/mac80211/debugfs_sta.c +++ b/net/mac80211/debugfs_sta.c @@ -80,6 +80,7 @@ static const char * const sta_flag_names[] = { FLAG(MPSP_OWNER), FLAG(MPSP_RECIPIENT), FLAG(PS_DELIVER), + FLAG(USES_ENCRYPTION), #undef FLAG }; diff --git a/net/mac80211/key.c b/net/mac80211/key.c index 6775d6cb7d3d..7fc55177db84 100644 --- a/net/mac80211/key.c +++ b/net/mac80211/key.c @@ -341,6 +341,7 @@ static void ieee80211_key_replace(struct ieee80211_sub_if_data *sdata, if (sta) { if (pairwise) { rcu_assign_pointer(sta->ptk[idx], new); + set_sta_flag(sta, WLAN_STA_USES_ENCRYPTION); sta->ptk_idx = idx; ieee80211_check_fast_xmit(sta); } else { diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h index c33bc5fc0f2d..75d982ff7f3d 100644 --- a/net/mac80211/sta_info.h +++ b/net/mac80211/sta_info.h @@ -102,6 +102,7 @@ enum ieee80211_sta_info_flags { WLAN_STA_MPSP_OWNER, WLAN_STA_MPSP_RECIPIENT, WLAN_STA_PS_DELIVER, + WLAN_STA_USES_ENCRYPTION, NUM_WLAN_STA_FLAGS, }; diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 98d048630ad2..3530d1a5fc98 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -593,10 +593,13 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; - if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) + if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) { tx->key = NULL; - else if (tx->sta && - (key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx]))) + return TX_CONTINUE; + } + + if (tx->sta && + (key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx]))) tx->key = key; else if (ieee80211_is_group_privacy_action(tx->skb) && (key = rcu_dereference(tx->sdata->default_multicast_key))) @@ -657,6 +660,9 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) if (!skip_hw && tx->key && tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) info->control.hw_key = &tx->key->conf; + } else if (!ieee80211_is_mgmt(hdr->frame_control) && tx->sta && + test_sta_flag(tx->sta, WLAN_STA_USES_ENCRYPTION)) { + return TX_DROP; } return TX_CONTINUE; -- 2.20.1