Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mac80211: Fix TKIP replay protection immediately after key setup

TKIP replay protection was skipped for the very first frame received
after a new key is configured. While this is potentially needed to avoid
dropping a frame in some cases, this does leave a window for replay
attacks with group-addressed frames at the station side. Any earlier
frame sent by the AP using the same key would be accepted as a valid
frame and the internal RSC would then be updated to the TSC from that
frame. This would allow multiple previously transmitted group-addressed
frames to be replayed until the next valid new group-addressed frame
from the AP is received by the station.

Fix this by limiting the no-replay-protection exception to apply only
for the case where TSC=0, i.e., when this is for the very first frame
protected using the new key, and the local RSC had not been set to a
higher value when configuring the key (which may happen with GTK).

Signed-off-by: Jouni Malinen <j@w1.fi>
Link: https://lore.kernel.org/r/20200107153545.10934-1-j@w1.fi
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

authored by

Jouni Malinen and committed by
Johannes Berg
6f601265 26ec17a1

+15 -3
+15 -3
net/mac80211/tkip.c
··· 263 263 if ((keyid >> 6) != key->conf.keyidx) 264 264 return TKIP_DECRYPT_INVALID_KEYIDX; 265 265 266 - if (rx_ctx->ctx.state != TKIP_STATE_NOT_INIT && 267 - (iv32 < rx_ctx->iv32 || 268 - (iv32 == rx_ctx->iv32 && iv16 <= rx_ctx->iv16))) 266 + /* Reject replays if the received TSC is smaller than or equal to the 267 + * last received value in a valid message, but with an exception for 268 + * the case where a new key has been set and no valid frame using that 269 + * key has yet received and the local RSC was initialized to 0. This 270 + * exception allows the very first frame sent by the transmitter to be 271 + * accepted even if that transmitter were to use TSC 0 (IEEE 802.11 272 + * described TSC to be initialized to 1 whenever a new key is taken into 273 + * use). 274 + */ 275 + if (iv32 < rx_ctx->iv32 || 276 + (iv32 == rx_ctx->iv32 && 277 + (iv16 < rx_ctx->iv16 || 278 + (iv16 == rx_ctx->iv16 && 279 + (rx_ctx->iv32 || rx_ctx->iv16 || 280 + rx_ctx->ctx.state != TKIP_STATE_NOT_INIT))))) 269 281 return TKIP_DECRYPT_REPLAY; 270 282 271 283 if (only_iv) {