Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3933888pxj; Mon, 21 Jun 2021 09:41:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeigqWBkWROGuyUln5fCkJxN8UG7seKBhVZPDk/Ta1baqm6yssWf/rl9g+Z5Zo4YAFFlIL X-Received: by 2002:a17:906:40d5:: with SMTP id a21mr10771952ejk.455.1624293659792; Mon, 21 Jun 2021 09:40:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624293659; cv=none; d=google.com; s=arc-20160816; b=w77kcHyYT0jgV3jgW765xkWR8qIEQs2fasmQQ3hs2fcOtxyWQLEYPBk7WJ3J5xCyVz EtFzAppZg65FwDo3d5TcgXzqqJuYwvJnsoZ1Y5OWXmSdu0G1t2lnfHekKjvhiDwxmcwb ce4O5QsoUdbSnTLI3rT+I95G3tz6+Z09xePaNZTYKVW+eMTp3Vfa3dQkYO3Z6mnUkQ44 JD6ThvHjiNb4ZfSoHIXZSv5KSyc5z8ozNOrqizlwBSWR8Q9OKn8P02B7ComhGkTjsbNk FUKEDOyBBQHjCnaUcxOQYmtGxwY32SSb7Nq2x7wv2maYLyiLwNR4LZZYi/xS/PeXBGe9 NW9w== 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=wYxlaa5aOxydIHba99XzXIatyTZP5P3iGhfaKQDLaDYs7nizJezMiCvc/d3EtbLrwZ dii9lXlyv/1J3PqjVI4Cr9+3wEmyTiC1r2xtUYo3WnsYnatxhR2UHcbf0Rs9c7UqiQk3 /XBtRFDXz8wyp7oUCIxFA6/tpqgKQOOhSSfq8CIgVIxdz/1yrpBtCKyTQN0RsfEjQqlC u5IKujqEpjxxqFrMThFykVgRwJGWM3+KrJJu5WHJIDLR2/WRURfXd+HjsN/MZ0grjxed 2BNncYkNljpDBftvm29x5n/QI9TiCkSzWdRYw9oQRXjBJjGR1YfAiAuVeAma66leHULj Xobg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DJAQvtaV; 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 eb14si1256079edb.48.2021.06.21.09.40.37; Mon, 21 Jun 2021 09:40:59 -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=DJAQvtaV; 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 S233288AbhFUQjl (ORCPT + 99 others); Mon, 21 Jun 2021 12:39:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:55398 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233158AbhFUQfM (ORCPT ); Mon, 21 Jun 2021 12:35:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 78EFB61378; Mon, 21 Jun 2021 16:27:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292870; bh=ALqKo1VmroxhzO8nwgjB/9QqKYkuPOE7lUq6KOJjfo4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DJAQvtaVlykBdbWj7VWkK77cvkadvOSzSTpwHoxKHt//mT/hFGkmHNAzUxnbXgKMB LjsFer/Y7NKXcu1S2ehMW9KDSc/+kmrJkaZPOTrX/gN39NCHHyazGHQH1Pguam1A7n ngBTmV+uTv3c2i0pzAeSYJlTRvjEkvFDhX228mzM= 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.12 015/178] mac80211: fix skb length check in ieee80211_scan_rx() Date: Mon, 21 Jun 2021 18:13:49 +0200 Message-Id: <20210621154922.142419394@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154921.212599475@linuxfoundation.org> References: <20210621154921.212599475@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