From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B45CC2417D1 for ; Wed, 29 Jul 2026 01:37:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785289077; cv=none; b=pb+zb/4ywFiKEpwYQbA7xX+8lI6S+mOlW52FaeW5opeyFINz5wMOC1//tkYAuPq5QHHGj+zCihvO0+aQY9OhecvB2nmggBRjV1iTQibVh+r7k7u/NMBsYY1Ue5YCJJ7Mevzmv+T4LuYzdjbvkf3hqOUj2KnR24jaNmgVJKbhpWw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785289077; c=relaxed/simple; bh=o+MxJEf6+pMI1pTG/g1jMJLP2DPBjQADHSuE1GZuIZA=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=WDSbNXk/Rkk5xdj/t2MPbzD6BxubC3peCI8wBo40orYI6gBUt7g/lHCK2tsKYaDhIUhe+eoXe9cTL9kB83dNDVIXrm423VgCUumOsOOppFnJYUuhsxHmMM9ggpWjxvZaN0gTOEGzHtLW1wNRpRYZm+cK4utXZGtm3kWykOlCXKs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.161.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oo1-f72.google.com with SMTP id 006d021491bc7-6aae4fb9327so218189eaf.3 for ; Tue, 28 Jul 2026 18:37:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785289074; x=1785893874; h=content-type:to:from:subject:message-id:in-reply-to:date :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=O3lS8WnTExXdE6EgME3UaWZuKVfAYNoW8UFYo/Rdm0M=; b=VHer7HdibZVJ6J8lMbjFmH1y/J9IVP7BZskbIl133utfu6yrwkdOjjhFZDK1tDEqMW oHW4/GUTEwX43IFqlmmr6PwRQnOb24cvNUWqNgbrKVFyqkJ6J3TJCreT13NRdD6U98Gh 1OmPKUQPpus6q22zRc6hG0b4jucynZw/67Te6+oVmuw4TmkJWeZ7Bz7K/1QboAHMe6MJ 8Yinoqs/pKWf7a6tU0p/gatuIncIHND8u1O90QobRsGUhwuRHWvXC3A42V9lXK0/tX30 uLVq0eTqvKo4Lg7ksVbYNF1fEcgsyKcTsH9HpAqcqrqL+NIFTjVYYtqp4I/6Sxis9Jvi G9Qw== X-Gm-Message-State: AOJu0YwGAC7mVmbp/UeY4AegKSqhGMVUqigUF1w+oO3NYDd0Pliz0XCL ifrxtqN1syvEMsMPDCvNr7Mlvol7sjOpe0X2YLv+NS5vgD9Zk2+1Fv3uYOWCswW+lW2HRnDPOXK J/0SGt7xCK9TKThSGocUUYrOyp3+y48zEyXmQEnquC9Zgngkd0Z1ESCV1xn0= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6820:4c82:b0:6a3:71a9:4476 with SMTP id 006d021491bc7-6ac96cb3869mr2670396eaf.58.1785289074727; Tue, 28 Jul 2026 18:37:54 -0700 (PDT) Date: Tue, 28 Jul 2026 18:37:54 -0700 In-Reply-To: <6a4fcd58.a1ad617e.25832.000e.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <6a695972.e3659fcc.2a40b8.002d.GAE@google.com> Subject: Forwarded: [PATCH v3] wifi: cfg80211: add cfg80211_validate_ies() helper and use it From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH v3] wifi: cfg80211: add cfg80211_validate_ies() helper and use it Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci The KASAN allocation trace shows that a malformed IE buffer is stored via SIOCSIWGENIE (cfg80211_wext_siwgenie()) without any validation. The crash trace shows that a subsequent SIOCSIWESSID triggers a connection attempt which calls cfg80211_sme_get_conn_ies() to process the stored IE buffer, causing: - An out-of-bounds read in skip_ie() which reads ies[pos+1] (the length byte) past the end of the 1-byte buffer. - An integer underflow in the memcpy size argument when offs returned by ieee80211_ie_split() exceeds ies_len, causing unsigned subtraction to wrap to SIZE_MAX and triggering a fortify panic. Fix this by adding a cfg80211_validate_ies() helper that uses for_each_element() and for_each_element_completed() to verify that all information elements in a buffer are well-formed. Refactor the existing duplicate patterns in validate_beacon_head() and validate_ie_attr() in nl80211.c to use the new helper, and use it in cfg80211_wext_siwgenie() to validate the IE buffer before storing it. Return -EINVAL if validation fails. Reported-by: syzbot+cc867e537e4bd36f69bb@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=cc867e537e4bd36f69bb Signed-off-by: Deepanshu Kartikey --- v3: Refactor validation into cfg80211_validate_ies() helper and use it in validate_beacon_head(), validate_ie_attr(), and cfg80211_wext_siwgenie(), as suggested by Jeff Johnson. Remove redundant ie_len < 2 check since for_each_element() already handles that case. Fix missing semicolon after /* nothing */ in for_each_element() body. v2: Use for_each_element() and for_each_element_completed() instead of open-coded validation loop, as suggested by Johannes Berg. --- net/wireless/nl80211.c | 15 ++------------- net/wireless/nl80211.h | 2 ++ net/wireless/util.c | 11 +++++++++++ net/wireless/wext-sme.c | 3 +++ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 5adcb6bd0fc5..27bbaf916574 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -228,7 +228,6 @@ static int validate_beacon_head(const struct nlattr *attr, { const u8 *data = nla_data(attr); unsigned int len = nla_len(attr); - const struct element *elem; const struct ieee80211_mgmt *mgmt = (void *)data; const struct ieee80211_ext *ext; unsigned int fixedlen, hdrlen; @@ -259,13 +258,8 @@ static int validate_beacon_head(const struct nlattr *attr, data += fixedlen; len -= fixedlen; - for_each_element(elem, data, len) { - /* nothing */ - } - - if (for_each_element_completed(elem, data, len)) + if (cfg80211_validate_ies(data, len)) return 0; - err: NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head"); return -EINVAL; @@ -276,13 +270,8 @@ static int validate_ie_attr(const struct nlattr *attr, { const u8 *data = nla_data(attr); unsigned int len = nla_len(attr); - const struct element *elem; - - for_each_element(elem, data, len) { - /* nothing */ - } - if (for_each_element_completed(elem, data, len)) + if (cfg80211_validate_ies(data, len)) return 0; NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); diff --git a/net/wireless/nl80211.h b/net/wireless/nl80211.h index bdb065d14054..8322ced6b551 100644 --- a/net/wireless/nl80211.h +++ b/net/wireless/nl80211.h @@ -129,4 +129,6 @@ int nl80211_pmsr_start(struct sk_buff *skb, struct genl_info *info); void nl80211_mlo_reconf_add_done(struct net_device *dev, struct cfg80211_mlo_reconf_done_data *data); +bool cfg80211_validate_ies(const u8 *data, int len); + #endif /* __NET_WIRELESS_NL80211_H */ diff --git a/net/wireless/util.c b/net/wireless/util.c index 24527bf321b2..dcaa5903bcd2 100644 --- a/net/wireless/util.c +++ b/net/wireless/util.c @@ -3083,3 +3083,14 @@ bool cfg80211_wdev_channel_allowed(struct wireless_dev *wdev, return false; } EXPORT_SYMBOL(cfg80211_wdev_channel_allowed); + +bool cfg80211_validate_ies(const u8 *data, int len) +{ + const struct element *elem; + + for_each_element(elem, data, len) { + /* nothing */ + } + + return for_each_element_completed(elem, data, len); +} diff --git a/net/wireless/wext-sme.c b/net/wireless/wext-sme.c index 573b6b15a446..1476d933c7e7 100644 --- a/net/wireless/wext-sme.c +++ b/net/wireless/wext-sme.c @@ -319,6 +319,9 @@ int cfg80211_wext_siwgenie(struct net_device *dev, return 0; if (ie_len) { + if (!cfg80211_validate_ies(extra, ie_len)) + return -EINVAL; + ie = kmemdup(extra, ie_len, GFP_KERNEL); if (!ie) return -ENOMEM; -- 2.43.0