Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3923039pxb; Mon, 4 Oct 2021 12:44:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxME8nn61g/us/egBI2UwFgbIXAzhhnSBjyfOa0g2KbD+gQj8RJ1UA4yZo83W7oq709wFNI X-Received: by 2002:a17:906:7c86:: with SMTP id w6mr12255173ejo.283.1633376665561; Mon, 04 Oct 2021 12:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633376665; cv=none; d=google.com; s=arc-20160816; b=GjhOxrU2k1aIkCpuTLMvcvz7LX29PsGZ+LsbvnaJBI6kT7/7yLRKsVS4NmS0YTFWbm Si6CzigarnTVroKreTgsPpcXao7XcZM591IKw8NexbrknmL1nfC/r2wi/jexkonis3Uk zHVjfqJ+SOgqyYFgdXi9BRTJEefiWMYXPPLHX0/xVTsSmAWq05ea3HyrGe4zkYKI1Tuj bFDwP+ONHiI5jpQEwD2bUlzWIeEaAxC6kmcnzQT/cMg30enzF5l+6v+WwF2SPS/NZ7Yi rnoHDRFrPRBw7rUiSd/sEpANHso+6GJ5BEVeKxO1WbuI6aOvck+6cKWxTCvB0jnoIxa5 vl9A== 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=KXczPjFMYJkMbHWlv9Fb7hVFEwpBUH7cAaEYJSNJFC8=; b=zWNv9HJhjUAKwdhsJSBiGDbGoyEI4iJ6lQFwwmh+z/JWQH/JhlRIHrI/F64fvO/ex9 yY7N/f5T5F2oRTtauNR1CheaxD4pZAOC+XDuI81xb8tiJN8hrQZpfrBJKvnNue/LAZ+p NnrGIPUE4GaNKBtfzfp+alDtZxU7/QezxNhmBhx0D6EzfQaIyq7h4F7lHpOvLb1qRiQa xm6sfUdB84Xt4Io7UntJiBdEJBqKUW66YrYCV3Phx9Fl6C7uAeVJcYDZW8x1XRiW6tbs fYxyb03cwwIsd/cWoorcYf7maJ/4e6lBDG6eS0SRlx1DY9lYcu1ooExrg9a0+iC3WeJ4 5p6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MZf5qWjp; 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 s11si21430541edh.626.2021.10.04.12.44.01; Mon, 04 Oct 2021 12:44:25 -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=MZf5qWjp; 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 S235904AbhJDNP0 (ORCPT + 99 others); Mon, 4 Oct 2021 09:15:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:47340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236174AbhJDNNc (ORCPT ); Mon, 4 Oct 2021 09:13:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BE9D5619E7; Mon, 4 Oct 2021 13:05:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633352712; bh=+0DQQQLmIQLKwx/0MMa8E3YVPGNF+IEyAwsXgPXejlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MZf5qWjpaoInGc6LI9fj+9Fv7L0AVHmYOuLNSALhD30QSMYdADP6plfAUgtC8xMaV zxGwfn6aywJ/RanWHSDjwQVqePSEzhrZjb6CtdOIIL52GDVkBaXYH3AAntD9At6FDY S3JtXVb8GBMDzcUU07fJXDK0VsrhVaaTkhaVQaXw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Berg Subject: [PATCH 4.19 59/95] mac80211: fix use-after-free in CCMP/GCMP RX Date: Mon, 4 Oct 2021 14:52:29 +0200 Message-Id: <20211004125035.500814442@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125033.572932188@linuxfoundation.org> References: <20211004125033.572932188@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 @@ -523,6 +523,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; @@ -752,6 +755,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;