From nobody Mon Feb 24 20:27:10 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Z1sjD3zJWz5pq3w; Mon, 24 Feb 2025 20:27:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Z1sjC1X4Vz3p1w; Mon, 24 Feb 2025 20:27:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740428831; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=503gNOOULJ4Fj/0mM3Cf5Ru17Mu34NC5Mxi+/S5MWCU=; b=ER3bkE8TvRWb5vxWPTP/WZCgBEVBG1CLlAe1sXLGv6Z9yTw+O7WSx16IYTlEAobMC05OTu ZORPpFqi64nBhcuVupdDH0HnDdH3P5fDdwDKnp5U72sTOgq2fVmZRJyzKPC/5fSJDbobDR aPuDMeOa6sXdays2p5mfM9qSyPryR+RqDhCRMZBR3rzDqOMkdFlLEV1EzBQUw8rxFnobY/ RSVUfONtaUYeBSBGEiqJeqfvbyvRFqml2FxGyJm2+uJNscbIbGFSQPxzLfWhZUttMSpn2L R52ij9ijSZa1cXCzk5vyxgWVyZMZFsHz881gYbEGgqy1OksODskllV+CM9FSvQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1740428831; a=rsa-sha256; cv=none; b=koBrjWzaizpoQ/1kpICEA/CTcmbSHubSZ+7gGzv744O2TyDGp9UjjwlGNbNlGJSlgJdcJ7 kd/2WYw+VQ76lLdAq/Q1bWbgIOLXDBkIF48PoMnIEHsab4647aBFqlj897lKwQ0Lk9hHQa uMNdWiiJlakNNUFRwm3N3iYOEBU1aLEQ8j+DAqLJmX2JrikI8MX2jgf0M9gYkoRUsp9UCA ZJg6hgreKGsSxwCupEogLnyj2bzLeZCh2jSgj4nMalaHanQ20s20q87ql35GZt4MJ+T8/7 8xNvc7lbBkQfTqXBdKs2mBXlhzahCL+W4inNTdLaC0XmNdIDOwrTL5UhFhn7kw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740428831; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=503gNOOULJ4Fj/0mM3Cf5Ru17Mu34NC5Mxi+/S5MWCU=; b=yqsVnDVPqUgoNk9UfZlPGNxRMZAI+Os/vkp4zPKqXLKvhn6Gnl9hdNdC3q9Y29dG5f4p5Q DiamvN30T3VaG5d/XzvjK3+gsXJsoCvSw629XiYeFALmqox53SWlX4UAGMZT44dM17AmC4 1uChkumGgNRRa8954RGUkYr++t6lw7GskgKsYF5Z4TqqNhExpmDbUqG5HDdLqIpYuW4xNY tVoOURnKBUs8sungh44ZqL3HD9LmChUAE2I5Hp4qKe6+gMAwuTbzI8pJm2uKAWWJVLT+I8 F6E4ajrXSXsb3sZc90f1xTAsGCpbdsTh+9i93jYxh8zdfQd0IJ+Z3kNYe975yA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Z1sjB6l8rzwYP; Mon, 24 Feb 2025 20:27:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 51OKRApC027273; Mon, 24 Feb 2025 20:27:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51OKRAdr027270; Mon, 24 Feb 2025 20:27:10 GMT (envelope-from git) Date: Mon, 24 Feb 2025 20:27:10 GMT Message-Id: <202502242027.51OKRAdr027270@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: bdc94f09bd96 - stable/14 - net80211/crypto: LinuxKPI/802.11: introduce IEEE80211_RX_F_PN_VALIDATED List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: bdc94f09bd96b28dcb841afa31f44b0879130134 Auto-Submitted: auto-generated The branch stable/14 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=bdc94f09bd96b28dcb841afa31f44b0879130134 commit bdc94f09bd96b28dcb841afa31f44b0879130134 Author: Bjoern A. Zeeb AuthorDate: 2025-01-07 12:02:54 +0000 Commit: Bjoern A. Zeeb CommitDate: 2025-02-24 20:26:48 +0000 net80211/crypto: LinuxKPI/802.11: introduce IEEE80211_RX_F_PN_VALIDATED There are cases when we see "rx seq# violation (CCMP)". Historically these were AHDEMO/IBBS cases (IEEE80211_KEY_NOREPLAY, see 5d766a09daab2). With iwlwifi(4) doing RSS for newer chipsets and us not having any idea about multiple rx-queues (passed all the way through) leads to the same problem. An easy way to trigger this is doing an IPv6 all-nodes echo request. With a sufficient amount of nodes answering the answers will be hashed to different queues and re-ordering will likely take place as queues get released individually. However crypto validation is already done in fw/driver for these cases and we need to carry the state forward. Add IEEE80211_RX_F_PN_VALIDATED to indicate that the checks were done passing the information from driver through LinuxKPI to net80211. LinuxKPI enforces that a frame was indeed decrypted; otherwise the flag would be invalid. This also avoids returning an error and no key from ieee80211_crypto_decap() and thus avoids dropping the frame. Sponsored by: The FreeBSD Foundation Reviewed by: adrian Differential Revision: https://reviews.freebsd.org/D49029 (cherry picked from commit ec6185c52661d3af0dac6dcc8701fc49fae3e1d9) --- sys/compat/linuxkpi/common/src/linux_80211.c | 16 +++++++++++++++- sys/net80211/_ieee80211.h | 1 + sys/net80211/ieee80211_crypto_ccmp.c | 16 +++++++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c index 02cacc62a4c2..7b0ddc3cbf9a 100644 --- a/sys/compat/linuxkpi/common/src/linux_80211.c +++ b/sys/compat/linuxkpi/common/src/linux_80211.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2020-2024 The FreeBSD Foundation + * Copyright (c) 2020-2025 The FreeBSD Foundation * Copyright (c) 2020-2025 Bjoern A. Zeeb * * This software was developed by Björn Zeeb under sponsorship from @@ -5425,6 +5425,20 @@ no_trace_beacons: rx_stats.c_freq = rx_status->freq; rx_stats.c_ieee = ieee80211_mhz2ieee(rx_stats.c_freq, rx_stats.c_band); + /* + * We only need these for LKPI_80211_HW_CRYPTO in theory but in + * case the hardware does something we do not expect always leave + * these enabled. Leaving this commant as documentation for the || 1. + */ +#if defined(LKPI_80211_HW_CRYPTO) || 1 + if (rx_status->flag & RX_FLAG_DECRYPTED) { + rx_stats.c_pktflags |= IEEE80211_RX_F_DECRYPTED; + /* Only valid if decrypted is set. */ + if (rx_status->flag & RX_FLAG_PN_VALIDATED) + rx_stats.c_pktflags |= IEEE80211_RX_F_PN_VALIDATED; + } +#endif + /* XXX (*sta_statistics)() to get to some of that? */ /* XXX-BZ dump the FreeBSD version of rx_stats as well! */ diff --git a/sys/net80211/_ieee80211.h b/sys/net80211/_ieee80211.h index 929de475f4bf..8b86cd612168 100644 --- a/sys/net80211/_ieee80211.h +++ b/sys/net80211/_ieee80211.h @@ -573,6 +573,7 @@ struct ieee80211_mimo_info { #define IEEE80211_RX_F_OFDM 0x00002000 #define IEEE80211_RX_F_HT 0x00004000 #define IEEE80211_RX_F_VHT 0x00008000 +#define IEEE80211_RX_F_PN_VALIDATED 0x00010000 /* Decrypted; PN validated */ /* Channel width */ #define IEEE80211_RX_FW_20MHZ 1 diff --git a/sys/net80211/ieee80211_crypto_ccmp.c b/sys/net80211/ieee80211_crypto_ccmp.c index 45e795a8799b..8f7d5eed593c 100644 --- a/sys/net80211/ieee80211_crypto_ccmp.c +++ b/sys/net80211/ieee80211_crypto_ccmp.c @@ -238,6 +238,7 @@ ccmp_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen) struct ieee80211_frame *wh; uint8_t *ivp, tid; uint64_t pn; + bool noreplaycheck; rxs = ieee80211_get_rx_params_ptr(m); @@ -261,8 +262,10 @@ ccmp_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen) } tid = ieee80211_gettid(wh); pn = READ_6(ivp[0], ivp[1], ivp[4], ivp[5], ivp[6], ivp[7]); - if (pn <= k->wk_keyrsc[tid] && - (k->wk_flags & IEEE80211_KEY_NOREPLAY) == 0) { + + noreplaycheck = (k->wk_flags & IEEE80211_KEY_NOREPLAY) != 0; + noreplaycheck |= (rxs != NULL) && (rxs->c_pktflags & IEEE80211_RX_F_PN_VALIDATED) != 0; + if (pn <= k->wk_keyrsc[tid] && !noreplaycheck) { /* * Replay violation. */ @@ -302,7 +305,14 @@ finish: * Ok to update rsc now. */ if (! ((rxs != NULL) && (rxs->c_pktflags & IEEE80211_RX_F_IV_STRIP))) { - k->wk_keyrsc[tid] = pn; + /* + * Do not go backwards in the IEEE80211_KEY_NOREPLAY cases + * or in case hardware has checked but frames are arriving + * reordered (e.g., LinuxKPI drivers doing RSS which we are + * not prepared for at all). + */ + if (pn > k->wk_keyrsc[tid]) + k->wk_keyrsc[tid] = pn; } return 1;