Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4023752ybl; Mon, 3 Feb 2020 11:03:49 -0800 (PST) X-Google-Smtp-Source: APXvYqw2D7tPyeKR7GtQ5+piPDaxS57ZL3vrEJMHG0M21mNrGNI8cK0cmyRBZc7cHm9vLsOsKWUB X-Received: by 2002:a05:6830:1094:: with SMTP id y20mr18679579oto.12.1580756629564; Mon, 03 Feb 2020 11:03:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580756629; cv=none; d=google.com; s=arc-20160816; b=xzh7qnWeIEYwIExDZd6zmJrEd6UqP0sfVrLwnt411H3BUPyHprLFT/72/w5qB4LuH0 iZ/E/yKmk5Kruf2vJ1G11Rxk1Xdd9+I0/o01M2VFW9/n6dNgFY1aHiBFxgWmlnR0WkJ6 yWB+POVquvbciizHR+sDTDtV0FlOZd1kJdKwjzR6HN7punbZTqdIgyXN0olAkZcABbc0 w9OIXp7E3l99hmqZ8R27h8L14EHs93eFWKiktYtQLAGtXJKBcvI0PDugQUXKsV0JlFsY 3JT8tAWOzox9yyDt8FzjWKJGpjnKjTsETah3yhgq3sGCka/q6z4o5nJpbPqmB/5xHCzr dqsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=A7/PWf67QkAOgHBRmMQZhTOA5zNGmXJlc+WEdiuvrIo=; b=mxnWCM5K23qeakd5Ceb+uPOtkWUAIURfhIkpAcOOBwnie2EFKcWT0MAlaRMPbN6yv3 U+pi9tapInIYEvVfZ6XLCK9piAwxEcka0jD+mKYBwd3V15A4NHFqsyDEms8V97W6KE8g eKpxJgUkywJLSEMfMyDfDIerrDCCrrRoUCilislS71snUgazqHklPqbpcoUVQK17TXYo sttrJ8gOETsmXZoBZzTvvNXaHz6tBtwTFjQe5z6lilJFhLeEARP2uyV1qhgDv4cyJBbZ 3kUZ+3pxiSDIffdUd99J5BUqEq8b+BODqLXmT7Ap/g9tJoThu/LTxH6Wqm9OhwszWegT k/yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qNbi711B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v23si3507558oto.81.2020.02.03.11.03.36; Mon, 03 Feb 2020 11:03:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qNbi711B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729391AbgBCQ1Y (ORCPT + 99 others); Mon, 3 Feb 2020 11:27:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:38560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729379AbgBCQ1U (ORCPT ); Mon, 3 Feb 2020 11:27:20 -0500 Received: from localhost (unknown [104.132.45.99]) (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 C7EB521741; Mon, 3 Feb 2020 16:27:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580747239; bh=rOC8U+f1daTPhWJ4bxWs0HkmJ05pAb0NOy3PkAdNkRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qNbi711BonNg2rF9xgQtNrMDaJslJRztE81FEhFZhvOFqCQK89PrfxFbBgXz0/MGN O6Jsc+e2LimHRKFSxuMnSizC0q+9uK8mFS7pbz0tazk8o3VSqUQvgRV0mAd/gRr+1t sixprfxm3jeYgv+tjYev/MmGfNVG88FH4qhZ5pFw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jouni Malinen , Johannes Berg , Sasha Levin Subject: [PATCH 4.9 49/68] mac80211: Fix TKIP replay protection immediately after key setup Date: Mon, 3 Feb 2020 16:19:45 +0000 Message-Id: <20200203161913.035130758@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200203161904.705434837@linuxfoundation.org> References: <20200203161904.705434837@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jouni Malinen [ Upstream commit 6f601265215a421f425ba3a4850a35861d024643 ] 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 Link: https://lore.kernel.org/r/20200107153545.10934-1-j@w1.fi Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- net/mac80211/tkip.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c index b3622823bad23..ebd66e8f46b3f 100644 --- a/net/mac80211/tkip.c +++ b/net/mac80211/tkip.c @@ -266,9 +266,21 @@ int ieee80211_tkip_decrypt_data(struct crypto_cipher *tfm, if ((keyid >> 6) != key->conf.keyidx) return TKIP_DECRYPT_INVALID_KEYIDX; - if (rx_ctx->ctx.state != TKIP_STATE_NOT_INIT && - (iv32 < rx_ctx->iv32 || - (iv32 == rx_ctx->iv32 && iv16 <= rx_ctx->iv16))) + /* Reject replays if the received TSC is smaller than or equal to the + * last received value in a valid message, but with an exception for + * the case where a new key has been set and no valid frame using that + * key has yet received and the local RSC was initialized to 0. This + * exception allows the very first frame sent by the transmitter to be + * accepted even if that transmitter were to use TSC 0 (IEEE 802.11 + * described TSC to be initialized to 1 whenever a new key is taken into + * use). + */ + if (iv32 < rx_ctx->iv32 || + (iv32 == rx_ctx->iv32 && + (iv16 < rx_ctx->iv16 || + (iv16 == rx_ctx->iv16 && + (rx_ctx->iv32 || rx_ctx->iv16 || + rx_ctx->ctx.state != TKIP_STATE_NOT_INIT))))) return TKIP_DECRYPT_REPLAY; if (only_iv) { -- 2.20.1