Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3983002pxb; Mon, 4 Oct 2021 14:23:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvZ/VHR3B/BDpHIJvWQl66R6vl4mwGhqAUQsMXFqReobCZN6B5JKINrkY1LE4ZHARnmE4i X-Received: by 2002:a17:902:fe82:b0:13e:7271:92dc with SMTP id x2-20020a170902fe8200b0013e727192dcmr1772692plm.0.1633382614914; Mon, 04 Oct 2021 14:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633382614; cv=none; d=google.com; s=arc-20160816; b=ZaYvPsJZc4aLnvePxUeR4tWQSKNqL4Sm8swpHbYWaI1jjRafiB16dyQ43tXBXJh/tG yZ3xfG4WuSe7MgEsMBpNQ/HeR74jWXtdQrBdhw13vZfU3L6BlN9n56Ap+e9hI9yLBDQK 3UtEvEoExUK2GiBsCpnT490nNQWSGxzsPOzLozrrAtIHx1l/MObOoyg8Q7mhwlbjH32s x3bFZp0KfaQbqzIZwRvbjC50+E6vw80KbTGLAWXof668/z1bZkdYuNjoeLt1k3TqsH/r HZ4Fkt4SxkaMW+1hO28nTxGI/iXU0LDIl9XofipQu5nJ7mDZIIMN7L8LsNivd0JEftdt Tg5g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pCVFazXx/Qq62KJW1KTXSR3tBVZI6CkfD22u+eER66M=; b=aXO9YZWTWKs7kuU/M4RTkXCMUy24eEUvZ1ANHKI0dgEkYTc/PTiiv7Dpzm9nedolHc qai+89kCsz/iKIhogidjvH9PqEfNZ1T+EGs8Po9dJgPxaXCsAHh9ZLWgILb0Pv3R+ifj VrcnUPGwrMpctzCmJ/LWIybzuFGNb9Dr6bh/rd5nzD6nbW4g2opX4E1HByYe/lk8poDu WEY1qfZSsTKWNp0WpzvDYZfBQYoAo59WRzZZb9iYpNQakoApON07yX/RZ7asRvYgGIw6 Luq5LCDDTi1Mt5p5nFOedVNNjnGXJHQrpLkgaaDl1Gav5awZOBDbBo3SMPDWvtMiBDTV LSLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ythVLsRq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a6si7708351pjo.100.2021.10.04.14.23.21; Mon, 04 Oct 2021 14:23:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=ythVLsRq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237523AbhJDNcf (ORCPT + 99 others); Mon, 4 Oct 2021 09:32:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:43760 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237562AbhJDNae (ORCPT ); Mon, 4 Oct 2021 09:30:34 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7E89061B96; Mon, 4 Oct 2021 13:13:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353231; bh=9DB9ESAOJ1QB5v+g5UT2LVVrpoNPdfYcg2nLYbholQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ythVLsRqwDIs8FPiTAH2QGdGMManVBLA+5SoXCvaI2PHkifTtqz/4K52Q7jueNMpd 6FYAB/nCEA9RCgw+/SBkPPpNjFxsWhvnKnJBZgw/f/IgB9UcjF8/S5zz5H/cC7lneo DkJKrGmOzyYokdYcmMeXfkJJ646cH7hbRsFdwU88= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Berg Subject: [PATCH 5.14 046/172] mac80211: fix use-after-free in CCMP/GCMP RX Date: Mon, 4 Oct 2021 14:51:36 +0200 Message-Id: <20211004125046.478858397@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johannes Berg commit 94513069eb549737bcfc3d988d6ed4da948a2de8 upstream. When PN checking is done in mac80211, for fragmentation we need to copy the PN to the RX struct so we can later use it to do a comparison, since commit bf30ca922a0c ("mac80211: check defrag PN against current frame"). Unfortunately, in that commit I used the 'hdr' variable without it being necessarily valid, so use-after-free could occur if it was necessary to reallocate (parts of) the frame. Fix this by reloading the variable after the code that results in the reallocations, if any. This fixes https://bugzilla.kernel.org/show_bug.cgi?id=214401. Cc: stable@vger.kernel.org Fixes: bf30ca922a0c ("mac80211: check defrag PN against current frame") Link: https://lore.kernel.org/r/20210927115838.12b9ac6bb233.I1d066acd5408a662c3b6e828122cd314fcb28cdb@changeid Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- net/mac80211/wpa.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/net/mac80211/wpa.c +++ b/net/mac80211/wpa.c @@ -520,6 +520,9 @@ ieee80211_crypto_ccmp_decrypt(struct iee return RX_DROP_UNUSABLE; } + /* reload hdr - skb might have been reallocated */ + hdr = (void *)rx->skb->data; + data_len = skb->len - hdrlen - IEEE80211_CCMP_HDR_LEN - mic_len; if (!rx->sta || data_len < 0) return RX_DROP_UNUSABLE; @@ -749,6 +752,9 @@ ieee80211_crypto_gcmp_decrypt(struct iee return RX_DROP_UNUSABLE; } + /* reload hdr - skb might have been reallocated */ + hdr = (void *)rx->skb->data; + data_len = skb->len - hdrlen - IEEE80211_GCMP_HDR_LEN - mic_len; if (!rx->sta || data_len < 0) return RX_DROP_UNUSABLE;