Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2262625pxj; Sun, 9 May 2021 21:17:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNGyPESZuwfVuhrxWyPM+tKV2Qm+THCd25k2jE4QC77dDSEqblikt6MQ/gfU+3as4rwZaI X-Received: by 2002:a02:cbac:: with SMTP id v12mr20001966jap.51.1620620256964; Sun, 09 May 2021 21:17:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620620256; cv=none; d=google.com; s=arc-20160816; b=rCseMb+Yjbpx5ALh85L/Y9i+KIwstjNUFVQcj0BOii4mxCYgWOwDw7O9QyurO5DtTL 0Xm5pchyf4cSmNWrxxa4I5ODnmdWeK5yD7wezRXOPvGlynrA4DMX3PqQYt/6enrh5xLE VvxXBibbtw8SGX+a2hniKaqWK0PW1/vja3R9QjSermOPCFO2G2jVXbD+8YyJEKRAtN59 1p3yoiLw8Aq7CHcKHSeoX6kZdkppprIcrTOhmY88Qh/7jOHCT+W01noS2cz6v/QDgSr0 BoX79y9PX7LaI4TiD8FfoxGTL5WJs+OtQpICunxgHaajBo09h+HHbsQxVt/lnXA3WOLp Rikw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=sTerZRGKeQCfH6TL4AouuTqXMWKe0PPg8qnOakbVp7s=; b=JKN4RWlrAIZ/o/wfjBEDfpC06w39v1XfLsawFgjjNEjcb1GPXbnDJq+/2yEPBsCDFw sEPXMLfkwvEwQXBkWHd7TPpIkIui7CYBKlCzD87QFRbz3uT6D3QUCK+JqMV5RI//CWfq vwolnC44GTRtMQSQOf8z/uYctOrzVIxdr3P5IRZYgNZaVIgW/cey3ZHIe/9tpBdnJ5sK oCBZARdxKnvSf7FgishTcXY1XWRBSR+rVSUWM/Sxz7TQvSBSrEdM4/3PRvrCYUx8D1TM ZLntUDSUb6+pOUWS4BXZ7gWzAIRwqzD2Bpcq6pZZGIiiX9ihmVRfdJtrrmsz/y5crMfF Pqog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RDgggXQP; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m20si2314291jat.70.2021.05.09.21.17.15; Sun, 09 May 2021 21:17:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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=@gmail.com header.s=20161025 header.b=RDgggXQP; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229876AbhEJER6 (ORCPT + 99 others); Mon, 10 May 2021 00:17:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbhEJER6 (ORCPT ); Mon, 10 May 2021 00:17:58 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AEF7C061573 for ; Sun, 9 May 2021 21:16:54 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id c17so12732948pfn.6 for ; Sun, 09 May 2021 21:16:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sTerZRGKeQCfH6TL4AouuTqXMWKe0PPg8qnOakbVp7s=; b=RDgggXQPCF1gm3g6z3puQaCoINBUWbN4UUJJIRcTkfDR72eLFz3ff3FHC9OZLhxSVw fCf9hfSrTrYRak4xXonLFiFvJ9/PoR5uTJ4NBMaIXiL+MpmmIeZ/wuW5M4vupYh1lraf 3YpVMV72QQl1KZckUsBG4e7fL6ma94aMyH9rbD5lrcPUA04JHK13qpyS4w2DuwYo2JZ0 1na7OzEAgjYrNlKDOhs7jacNAnGsisvMpb/QOhorhIkS7rmjOKWinKFsq3zm3+mnYhjn oZEgW1OAo1ni9c4MCvwJ+SNT+5IvmZHqVrLSFzNY5BUqRt+iExAde+jyToqn9/MWiLKY Dwhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sTerZRGKeQCfH6TL4AouuTqXMWKe0PPg8qnOakbVp7s=; b=cI5TUtGwwZfRwdEE1YmM0NtQEZdhglShcs5ozjbEeSO3bny1sMQtuQgJkcmjLXKXCs 4+LkUG3lxu/aivoWBHScNR/SyEZKBXrqB27PEPlWBgH7Nd67zHGyVUm1z3Av7WD4JuNo IV1S2HY+HKDXBtVxHOclIvHvJJWeDOMFoKCO83C4w3sJPeVFv/Z2A6vrJDhJbJPtx4c7 Y/nnuXewefTG63Llphf1hH1WKJZSpL8HdW14cFWzt0u/2Gfx2S2S6LbvYeqMc8+MbFZS 1/tt7ztnNY5TBMrVbEuzZ4bOq+Halprp5ZpNe05GhMffgiK8OHV9e8kxf9LODRlFbKtS dG/Q== X-Gm-Message-State: AOAM530mK873NERzcKf7LJSQ+s9mFViU2JRLb5xi4D0Cvs5VCGvS7r7p ZLpenIE2US/eyYwRsmQqQ+w= X-Received: by 2002:a62:79c3:0:b029:28e:a874:4e1e with SMTP id u186-20020a6279c30000b029028ea8744e1emr23161892pfc.3.1620620213625; Sun, 09 May 2021 21:16:53 -0700 (PDT) Received: from nuc.. ([202.133.196.154]) by smtp.gmail.com with ESMTPSA id g84sm10003510pfb.198.2021.05.09.21.16.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 May 2021 21:16:53 -0700 (PDT) From: Du Cheng To: Thomas Pedersen , Johannes Berg Cc: linux-wireless@vger.kernel.org, Shuah Khan , Greg Kroah-Hartman , Du Cheng , syzbot+405843667e93b9790fc1@syzkaller.appspotmail.com Subject: [PATCH] net: mac80211: fix hard-coding of length check on skb->len in ieee80211_scan_rx() Date: Mon, 10 May 2021 12:16:49 +0800 Message-Id: <20210510041649.589754-1-ducheng2@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Replace hard-coding with compile-time constants for header length check on skb->len. This skb->len will be checked again further down the callstack in cfg80211_inform_bss_frame_data() in net/wireless/scan.c (which has a proper length check with WARN_ON()). If the kernel is configure to panic_on_warn(), the insuffient check of skb->len in ieee80211_scan_rx() causes kernel crash in cfg80211_inform_bss_frame_data(). Bug reported by syzbot: https://syzkaller.appspot.com/bug?id=183869c2f25b1c8692e381d8fcd69771a99221cc Reported-by: syzbot+405843667e93b9790fc1@syzkaller.appspotmail.com Signed-off-by: Du Cheng --- This patch has passed syzbot testing. net/mac80211/scan.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index d4cc9ac2d703..562eda13e802 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -251,13 +251,21 @@ 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