Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3923057pxj; Mon, 21 Jun 2021 09:27:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2mO4XHeQf3qWxtopzCRRSQd6rtBXAdhBs5MKyTCzBFleihR952G4dGqqpswv+Q6AIsMer X-Received: by 2002:a05:6638:5ad:: with SMTP id b13mr19031008jar.42.1624292834273; Mon, 21 Jun 2021 09:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624292834; cv=none; d=google.com; s=arc-20160816; b=wMqBGTsdR8D7MFqabV3YSP33rnibueogVjVNNzBD4dSn24Z5+OL94IgXY+GGFRdRNt thi0y89fME3st5tyo6fxAdOMJEiB3bSIVIkgC/h0Ir9267YJvS+MYFgF0WiRkODk1ULB V3HHOSKEfdFqsC4cu+C9694wPwbbxM3wtcApNUAoBmJVPRGf49o2KLgE/bO9M87MQf6H DR64NpgxJTOvAbrvYQbcLs1AEUZsC/67+YAJZdaDBqM3YuWi6no4p8AioEufsq/uWR0+ iHh52QcAzsJlF9qUUFoWFfKlmceAP1PLMMhqAi4SPBXjeJ4uXZnDE+GPqovqzPsqgIQg WKQw== 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=DQZ77D7pa8L6ZCh77bu61+pn4S5SN4ePq1vRnQgMmiA=; b=EmpxXKgu6IptKMWKFQZu7Hb0WQzZs543bnXZQJF7kfJNMyD13+ue1X1e7z3Pwlea01 6ng1CrSFuYnbszIKi1hcGyrgauUNZZSTIayMTnG5jhxwwmFrzxBmOpuey9sY/Q6kkEYf s3JqxT8xaWjAExzbVIbL+9/k2sJxvbzvycFtgcupbiObG6kuj5D66wRkLZ31zRXhjezg FqQqtgL+v3tl+OPy6NPf6ibjGSmsu1npg3M29ybgB80G+uqNGe9agN0AIRWaGNc0qHt4 qsYFbtoSlTwaOAmSLrJnze4/0NbRS8Q5pVZwJIRFT11dvNJ8S4FCJAA2EOuf0xn15rQj Z3Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SXeoGDaj; 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 t22si22986259ioh.104.2021.06.21.09.27.02; Mon, 21 Jun 2021 09:27:14 -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=SXeoGDaj; 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 S231636AbhFUQ2v (ORCPT + 99 others); Mon, 21 Jun 2021 12:28:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:49444 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231837AbhFUQ1O (ORCPT ); Mon, 21 Jun 2021 12:27:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 34F6D613CC; Mon, 21 Jun 2021 16:22:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292563; bh=ALqKo1VmroxhzO8nwgjB/9QqKYkuPOE7lUq6KOJjfo4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SXeoGDajsJP7TyKM3QAEq8c7NEwn67N9A+d2oMxUl1O7uGXCc5q4g6EOMW0H9p2E2 N5hgZUTmJqNoZHHk5nZyqDYfcg59/oNDR26ykNg2X+tn4VDXo4vmWylfZnuZtlqwcT KGcPhN11E7PPZu7tP/XSHeF6pO1OOiDj4xygqA8U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+405843667e93b9790fc1@syzkaller.appspotmail.com, Du Cheng , Johannes Berg , Sasha Levin Subject: [PATCH 5.10 013/146] mac80211: fix skb length check in ieee80211_scan_rx() Date: Mon, 21 Jun 2021 18:14:03 +0200 Message-Id: <20210621154911.715681409@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154911.244649123@linuxfoundation.org> References: <20210621154911.244649123@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: Du Cheng [ Upstream commit e298aa358f0ca658406d524b6639fe389cb6e11e ] Replace hard-coded compile-time constants for header length check with dynamic determination based on the frame type. Otherwise, we hit a validation WARN_ON in cfg80211 later. Fixes: cd418ba63f0c ("mac80211: convert S1G beacon to scan results") Reported-by: syzbot+405843667e93b9790fc1@syzkaller.appspotmail.com Signed-off-by: Du Cheng Link: https://lore.kernel.org/r/20210510041649.589754-1-ducheng2@gmail.com [style fixes, reword commit message] Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- net/mac80211/scan.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index d4cc9ac2d703..6b50cb5e0e3c 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -251,13 +251,24 @@ void ieee80211_scan_rx(struct ieee80211_local *local, struct sk_buff *skb) struct ieee80211_mgmt *mgmt = (void *)skb->data; struct ieee80211_bss *bss; struct ieee80211_channel *channel; + size_t min_hdr_len = offsetof(struct ieee80211_mgmt, + u.probe_resp.variable); + + if (!ieee80211_is_probe_resp(mgmt->frame_control) && + !ieee80211_is_beacon(mgmt->frame_control) && + !ieee80211_is_s1g_beacon(mgmt->frame_control)) + return; if (ieee80211_is_s1g_beacon(mgmt->frame_control)) { - if (skb->len < 15) - return; - } else if (skb->len < 24 || - (!ieee80211_is_probe_resp(mgmt->frame_control) && - !ieee80211_is_beacon(mgmt->frame_control))) + if (ieee80211_is_s1g_short_beacon(mgmt->frame_control)) + min_hdr_len = offsetof(struct ieee80211_ext, + u.s1g_short_beacon.variable); + else + min_hdr_len = offsetof(struct ieee80211_ext, + u.s1g_beacon); + } + + if (skb->len < min_hdr_len) return; sdata1 = rcu_dereference(local->scan_sdata); -- 2.30.2