From: Kyuwon Cho <kyuwoncho18@gmail.com>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: John Crispin <john@phrozen.org>,
Aloka Dixit <quic_alokad@quicinc.com>,
Rameshkumar Sundaram <rameshkumar.sundaram@oss.qualcomm.com>,
linux-wireless@vger.kernel.org
Subject: [PATCH wireless] wifi: mac80211: clear the MBSSID options when starting an AP fails
Date: Tue, 24 Nov 2026 22:32:21 +0900 [thread overview]
Message-ID: <179552107132.1345245.6487482796651760102@gmail.com> (raw)
ieee80211_start_ap() applies the MBSSID configuration with
ieee80211_set_ap_mbssid_options() before it takes the channel. If
ieee80211_link_use_channel() or a later step fails, the error paths
restore the beacon interval and the SSID length but leave
link_conf->tx_bss_conf and the other MBSSID fields set. cfg80211 does
not consider the AP started, so STOP_AP does not clear them either.
A retry with the same MBSSID configuration then fails with -EALREADY
until the interface goes down, and a start without MBSSID succeeds but
keeps the stale transmitting BSS.
Clear the MBSSID options on both error paths.
Fixes: 171964252189 ("mac80211: MBSSID support in interface handling")
Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype. A reproducer, which runs as any
user with mac80211_hwsim loaded: it creates a one-channel radio with
two AP interfaces, starts wlan0 as the transmitting BSS of an MBSSID
set, and then starts ap1 as a nontransmitted BSS, first on another
channel and then on wlan0's.
#define _GNU_SOURCE
#include <linux/genetlink.h>
#include <linux/nl80211.h>
#include <net/if.h>
#include <sched.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <unistd.h>
#define HWSIM_CMD_NEW_RADIO 4
#define HWSIM_ATTR_CHANNELS 9
#define HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE 16
static int fd;
static unsigned char req[1024], *p;
static void msg(int family, int cmd)
{
memset(req, 0, sizeof(req));
((struct nlmsghdr *)req)->nlmsg_type = family;
((struct nlmsghdr *)req)->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
((struct genlmsghdr *)NLMSG_DATA(req))->cmd = cmd;
((struct genlmsghdr *)NLMSG_DATA(req))->version = 1;
p = req + NLMSG_LENGTH(GENL_HDRLEN);
}
static struct nlattr *attr(int type, const void *data, int len)
{
struct nlattr *a = (void *)p;
a->nla_type = type;
a->nla_len = NLA_HDRLEN + len;
if (len)
memcpy(a + 1, data, len);
p += NLA_ALIGN(a->nla_len);
return a;
}
static void u32(int type, uint32_t v)
{
attr(type, &v, 4);
}
/* returns the ack's error; copies attribute "want" of a reply to "out" */
static int talk(int want, void *out)
{
static char buf[8192];
struct nlmsghdr *nh = (void *)req;
int n;
nh->nlmsg_len = p - req;
send(fd, req, nh->nlmsg_len, 0);
for (;;) {
n = recv(fd, buf, sizeof(buf), 0);
for (nh = (void *)buf; NLMSG_OK(nh, n); nh = NLMSG_NEXT(nh, n)) {
struct nlattr *a = (void *)((char *)NLMSG_DATA(nh) + GENL_HDRLEN);
int rem = nh->nlmsg_len - NLMSG_LENGTH(GENL_HDRLEN);
if (nh->nlmsg_type == NLMSG_ERROR)
return ((struct nlmsgerr *)NLMSG_DATA(nh))->error;
for (; rem >= NLA_HDRLEN && a->nla_len >= NLA_HDRLEN;
rem -= NLA_ALIGN(a->nla_len), a = (void *)((char *)a + NLA_ALIGN(a->nla_len)))
if (a->nla_type == want)
memcpy(out, a + 1, a->nla_len - NLA_HDRLEN);
}
}
}
static int family(const char *name)
{
uint16_t id = 0;
msg(GENL_ID_CTRL, CTRL_CMD_GETFAMILY);
attr(CTRL_ATTR_FAMILY_NAME, name, strlen(name) + 1);
talk(CTRL_ATTR_FAMILY_ID, &id);
return id;
}
static void up(const char *name)
{
struct ifreq ifr = { .ifr_flags = IFF_UP };
int s = socket(AF_INET, SOCK_DGRAM, 0);
strcpy(ifr.ifr_name, name);
ioctl(s, SIOCSIFFLAGS, &ifr);
close(s);
}
/* START_AP as part of an MBSSID set whose transmitting BSS is wlan0 */
static int start_ap(int nl80211, const char *name, int freq, uint8_t index)
{
static const unsigned char ie[] = { 0, 4, 'm', 'b', 's', 's',
1, 8, 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24 }, mbssid[] = { 71, 1, 1 };
unsigned char head[36 + sizeof(ie)] = { 0x80 };
struct ifreq ifr = {};
struct nlattr *nest;
int s = socket(AF_INET, SOCK_DGRAM, 0);
strcpy(ifr.ifr_name, name);
ioctl(s, SIOCGIFHWADDR, &ifr);
close(s);
memset(head + 4, 0xff, 6);
memcpy(head + 10, ifr.ifr_hwaddr.sa_data, 6);
memcpy(head + 16, ifr.ifr_hwaddr.sa_data, 6);
head[32] = 100; /* beacon interval */
head[34] = 1; /* ESS */
memcpy(head + 36, ie, sizeof(ie));
msg(nl80211, NL80211_CMD_START_AP);
u32(NL80211_ATTR_IFINDEX, if_nametoindex(name));
u32(NL80211_ATTR_WIPHY_FREQ, freq);
u32(NL80211_ATTR_BEACON_INTERVAL, 100);
u32(NL80211_ATTR_DTIM_PERIOD, 2);
attr(NL80211_ATTR_BEACON_HEAD, head, sizeof(head));
attr(NL80211_ATTR_SSID, "mbss", 4);
nest = attr(NL80211_ATTR_MBSSID_CONFIG | NLA_F_NESTED, NULL, 0);
attr(NL80211_MBSSID_CONFIG_ATTR_INDEX, &index, 1);
u32(NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX, if_nametoindex("wlan0"));
nest->nla_len = p - (unsigned char *)nest;
if (!index) {
nest = attr(NL80211_ATTR_MBSSID_ELEMS | NLA_F_NESTED, NULL, 0);
attr(1, mbssid, sizeof(mbssid));
nest->nla_len = p - (unsigned char *)nest;
}
return talk(-1, NULL);
}
int main(void)
{
struct sockaddr_nl sa = { .nl_family = AF_NETLINK };
uint32_t wiphy = 0;
int hwsim, nl80211;
/* CAP_NET_ADMIN over a radio of our own */
if (unshare(CLONE_NEWUSER | CLONE_NEWNET))
return perror("unshare"), 1;
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
bind(fd, (void *)&sa, sizeof(sa));
hwsim = family("MAC80211_HWSIM");
nl80211 = family("nl80211");
/* a radio with one channel: a second AP cannot use another one */
msg(hwsim, HWSIM_CMD_NEW_RADIO);
u32(HWSIM_ATTR_CHANNELS, 1);
attr(HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE, NULL, 0);
talk(-1, NULL);
while (!if_nametoindex("wlan0"))
usleep(10000);
msg(nl80211, NL80211_CMD_GET_INTERFACE);
u32(NL80211_ATTR_IFINDEX, if_nametoindex("wlan0"));
talk(NL80211_ATTR_WIPHY, &wiphy);
msg(nl80211, NL80211_CMD_SET_INTERFACE);
u32(NL80211_ATTR_IFINDEX, if_nametoindex("wlan0"));
u32(NL80211_ATTR_IFTYPE, NL80211_IFTYPE_AP);
talk(-1, NULL);
msg(nl80211, NL80211_CMD_NEW_INTERFACE);
u32(NL80211_ATTR_WIPHY, wiphy);
attr(NL80211_ATTR_IFNAME, "ap1", 4);
u32(NL80211_ATTR_IFTYPE, NL80211_IFTYPE_AP);
talk(-1, NULL);
up("wlan0");
up("ap1");
printf("wlan0, transmitting BSS, 2412 MHz: %s\n", strerror(-start_ap(nl80211, "wlan0", 2412, 0)));
printf("ap1, nontransmitted BSS, 2437 MHz: %s\n", strerror(-start_ap(nl80211, "ap1", 2437, 1)));
printf("ap1, nontransmitted BSS, 2412 MHz: %s\n", strerror(-start_ap(nl80211, "ap1", 2412, 1)));
return 0;
}
Without the patch, the last start fails with EALREADY ("Operation
already in progress"); with it, it succeeds.
The patch was written with LLM assistance; we reviewed and tested it.
net/mac80211/cfg.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 9608c07bcea7..4ca5246527cf 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -162,6 +162,15 @@ static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
return 0;
}
+static void ieee80211_clear_ap_mbssid_options(struct ieee80211_bss_conf *link_conf)
+{
+ RCU_INIT_POINTER(link_conf->tx_bss_conf, NULL);
+ link_conf->bssid_index = 0;
+ link_conf->nontransmitted = false;
+ link_conf->ema_ap = false;
+ link_conf->bssid_indicator = 0;
+}
+
static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata,
struct cfg80211_mbssid_config *params,
struct ieee80211_bss_conf *link_conf)
@@ -1937,6 +1946,7 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
ieee80211_link_copy_chanctx_to_vlans(link, false);
if (err) {
link_conf->beacon_int = prev_beacon_int;
+ ieee80211_clear_ap_mbssid_options(link_conf);
return err;
}
@@ -2055,6 +2065,7 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
link_conf->beacon_int = prev_beacon_int;
sdata->vif.cfg.ssid_len = 0;
ieee80211_link_release_channel(link);
+ ieee80211_clear_ap_mbssid_options(link_conf);
return err;
}
--
2.43.0
reply other threads:[~2026-11-24 13:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179552107132.1345245.6487482796651760102@gmail.com \
--to=kyuwoncho18@gmail.com \
--cc=johannes@sipsolutions.net \
--cc=john@phrozen.org \
--cc=linux-wireless@vger.kernel.org \
--cc=quic_alokad@quicinc.com \
--cc=rameshkumar.sundaram@oss.qualcomm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox