From 4cc4291f0b48ae49c35ac703f679e2bf756c6add Mon Sep 17 00:00:00 2001 From: avos Date: Tue, 15 Jan 2019 02:26:03 +0000 Subject: [PATCH] MFC r342966: net80211: fix possible panic for some drivers after r342465 Check if rate control structures were allocated before trying to access them in various places; this was possible before on allocation failure (unlikely), but was revealed after r342211 where allocation was deferred. The patch was adjusted a bit since file contents are different enough since r306591. Also, 'rate_stats' sysctl is not available here, so the panic is unlikely to happen here even without this patch. git-svn-id: svn://svn.freebsd.org/base/stable/10@343036 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/net80211/ieee80211_amrr.c | 33 ++++++++++++++++++++++++++++--- sys/net80211/ieee80211_rssadapt.c | 29 ++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/sys/net80211/ieee80211_amrr.c b/sys/net80211/ieee80211_amrr.c index e7597ef66..0fcd5f0d9 100644 --- a/sys/net80211/ieee80211_amrr.c +++ b/sys/net80211/ieee80211_amrr.c @@ -98,6 +98,9 @@ amrr_setinterval(const struct ieee80211vap *vap, int msecs) struct ieee80211_amrr *amrr = vap->iv_rs; int t; + if (!amrr) + return; + if (msecs < 100) msecs = 100; t = msecs_to_ticks(msecs); @@ -152,6 +155,12 @@ amrr_node_init(struct ieee80211_node *ni) struct ieee80211_amrr_node *amn; uint8_t rate; + if (!amrr) { + if_printf(vap->iv_ifp, "ratectl structure was not allocated, " + "per-node structure allocation skipped\n"); + return; + } + if (ni->ni_rctls == NULL) { ni->ni_rctls = amn = malloc(sizeof(struct ieee80211_amrr_node), M_80211_RATECTL, M_NOWAIT|M_ZERO); @@ -303,10 +312,19 @@ static int amrr_rate(struct ieee80211_node *ni, void *arg __unused, uint32_t iarg __unused) { struct ieee80211_amrr_node *amn = ni->ni_rctls; - struct ieee80211_amrr *amrr = amn->amn_amrr; + struct ieee80211_amrr *amrr; const struct ieee80211_rateset *rs = NULL; int rix; + /* XXX should return -1 here, but drivers may not expect this... */ + if (!amn) + { + ni->ni_txrate = ni->ni_rates.rs_rates[0]; + return 0; + } + + amrr = amn->amn_amrr; + /* 11n or not? Pick the right rateset */ if (amrr_node_is_11n(ni)) { /* XXX ew */ @@ -346,6 +364,9 @@ amrr_tx_complete(const struct ieee80211vap *vap, struct ieee80211_amrr_node *amn = ni->ni_rctls; int retries = *(int *)arg1; + if (!amn) + return; + amn->amn_txcnt++; if (ok) amn->amn_success++; @@ -374,9 +395,12 @@ amrr_sysctl_interval(SYSCTL_HANDLER_ARGS) { struct ieee80211vap *vap = arg1; struct ieee80211_amrr *amrr = vap->iv_rs; - int msecs = ticks_to_msecs(amrr->amrr_interval); - int error; + int msecs, error; + if (!amrr) + return ENOMEM; + + msecs = ticks_to_msecs(amrr->amrr_interval); error = sysctl_handle_int(oidp, &msecs, 0, req); if (error || !req->newptr) return error; @@ -390,6 +414,9 @@ amrr_sysctlattach(struct ieee80211vap *vap, { struct ieee80211_amrr *amrr = vap->iv_rs; + if (!amrr) + return; + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "amrr_rate_interval", CTLTYPE_INT | CTLFLAG_RW, vap, 0, amrr_sysctl_interval, "I", "amrr operation interval (ms)"); diff --git a/sys/net80211/ieee80211_rssadapt.c b/sys/net80211/ieee80211_rssadapt.c index 1d412b3fd..d9d269d61 100644 --- a/sys/net80211/ieee80211_rssadapt.c +++ b/sys/net80211/ieee80211_rssadapt.c @@ -114,6 +114,9 @@ rssadapt_setinterval(const struct ieee80211vap *vap, int msecs) struct ieee80211_rssadapt *rs = vap->iv_rs; int t; + if (!rs) + return; + if (msecs < 100) msecs = 100; t = msecs_to_ticks(msecs); @@ -172,6 +175,12 @@ rssadapt_node_init(struct ieee80211_node *ni) struct ieee80211_rssadapt *rsa = vap->iv_rs; const struct ieee80211_rateset *rs = &ni->ni_rates; + if (!rsa) { + if_printf(vap->iv_ifp, "ratectl structure was not allocated, " + "per-node structure allocation skipped\n"); + return; + } + if (ni->ni_rctls == NULL) { ni->ni_rctls = ra = malloc(sizeof(struct ieee80211_rssadapt_node), @@ -226,10 +235,18 @@ rssadapt_rate(struct ieee80211_node *ni, void *arg __unused, uint32_t iarg) { struct ieee80211_rssadapt_node *ra = ni->ni_rctls; u_int pktlen = iarg; - const struct ieee80211_rateset *rs = &ra->ra_rates; + const struct ieee80211_rateset *rs; uint16_t (*thrs)[IEEE80211_RATE_SIZE]; int rix, rssi; + /* XXX should return -1 here, but drivers may not expect this... */ + if (!ra) + { + ni->ni_txrate = ni->ni_rates.rs_rates[0]; + return 0; + } + + rs = &ra->ra_rates; if ((ticks - ra->ra_ticks) > ra->ra_rs->interval) { rssadapt_updatestats(ra); ra->ra_ticks = ticks; @@ -315,6 +332,9 @@ rssadapt_tx_complete(const struct ieee80211vap *vap, struct ieee80211_rssadapt_node *ra = ni->ni_rctls; int pktlen = *(int *)arg1, rssi = *(int *)arg2; + if (!ra) + return; + if (success) { ra->ra_nok++; if ((ra->ra_rix + 1) < ra->ra_rates.rs_nrates && @@ -331,9 +351,12 @@ rssadapt_sysctl_interval(SYSCTL_HANDLER_ARGS) { struct ieee80211vap *vap = arg1; struct ieee80211_rssadapt *rs = vap->iv_rs; - int msecs = ticks_to_msecs(rs->interval); - int error; + int msecs, error; + + if (!rs) + return ENOMEM; + msecs = ticks_to_msecs(rs->interval); error = sysctl_handle_int(oidp, &msecs, 0, req); if (error || !req->newptr) return error; -- 2.45.0