Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4026494ybl; Mon, 3 Feb 2020 11:06:33 -0800 (PST) X-Google-Smtp-Source: APXvYqxhjUJXoECc2k4PxQR3xGQ7Wi6Oaj06loiJhiShuaZtGOu4LDrWbhigcs6+VSOp7nWjILTP X-Received: by 2002:aca:100e:: with SMTP id 14mr380177oiq.88.1580756793544; Mon, 03 Feb 2020 11:06:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580756793; cv=none; d=google.com; s=arc-20160816; b=AZ3yZMCsXfFr4zCUtF6/g+Fy3qJqyfL6JL00qIlEovJDxgbxgm88usPSOSaYq5515M btWnyZEzud9Ic7Nh4/xkoFT6xMgfCctDd8xOzRjzFWreQUjW0xn8Y1o7ZAgrdP0aXE4f ujMN2JHXEXLz06trkH/NNbutaD5u8uYlumse1L/AmVRJcvbcMGIXq3mWvl5Oe0LN/qEf aXobrtJclZrkjmA9349U5i1mea2BN5svEOTsg9ubEQOKYryxP45QvCKLbw9CR4RpPW5P n2/G9hfMSl+sNPsbaSsuednRs6wxCE/KvAulYCXh4QgequRsudj9sCAt91pnOJmN0pZh 4iPg== 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=jQ80tT4lyM3taae5LSSfWidprsgdJTcV4RPmGmG3jsmY6H/4MP1GBdjTE9pPwGIgo4 9IL7rL0CVqetGn+v+ZgxfEpkgMxIGpgLfd34oTQFPXnCTbaQ2wGpAjhhf/fTCidcjZwx 7qAac2ml+nKqTMGwN50dt88/oGJqxDKh8271pPtKer5t9HMymYkl7Hd+Uwdegl8Zpr+G yyNRernSk7j0HfFpYL2oKet+eQFtoW9abkX5KXItr2+ms2WvFz0ykUR/tddlKLvE0ZlN wAad2aWRiA6KUfqpBS0ehHhfV3vpRqb3NlLeUgH3rZgWw3GSZFqy17okwWLnV+LCQowI o8Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QU2BrUgF; 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 r22si9381471otn.192.2020.02.03.11.06.21; Mon, 03 Feb 2020 11:06:33 -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=QU2BrUgF; 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 S1730179AbgBCQco (ORCPT + 98 others); Mon, 3 Feb 2020 11:32:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:46460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730159AbgBCQcl (ORCPT ); Mon, 3 Feb 2020 11:32:41 -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 D33E02082E; Mon, 3 Feb 2020 16:32:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580747561; bh=rOC8U+f1daTPhWJ4bxWs0HkmJ05pAb0NOy3PkAdNkRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QU2BrUgFlnor5Qk/hGAZO+kK5MaVS1TyyxCW0rvkOMz1KFHJhQuC+9RplkP2HUg/f vY+Y4ufjkWPys59Ni9lSFbmzVuneQmCsaeZTEyU1nBhYvFEvPicjHAr+4Q2IaQC7yp XhS9NE/3B0zrVS8xX0LAiP0X29gmccjj5stKwkMo= 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.19 44/70] mac80211: Fix TKIP replay protection immediately after key setup Date: Mon, 3 Feb 2020 16:19:56 +0000 Message-Id: <20200203161918.742702787@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200203161912.158976871@linuxfoundation.org> References: <20200203161912.158976871@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