Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 11b2357

Browse files
Karl Beldanjmberg-intel
authored andcommitted
mac80211: minstrels: fix buffer overflow in HT debugfs rc_stats
ATM an HT rc_stats line is 106 chars. Times 8(MCS_GROUP_RATES)*3(SS)*2(GI)*2(BW) + CCK(4), i.e. x100, this is well above the current 8192 - sizeof(*ms) currently allocated. Fix this by squeezing the output as follows (not that we're short on memory but this also improves readability and range, the new format adds one more digit to *ok/*cum and ok/cum): - Before (HT) (106 ch): type rate throughput ewma prob this prob retry this succ/attempt success attempts CCK/LP 5.5M 0.0 0.0 0.0 0 0( 0) 0 0 HT20/LGI ABCDP MCS0 0.0 0.0 0.0 1 0( 0) 0 0 - After (75 ch): type rate tpt eprob *prob ret *ok(*cum) ok( cum) CCK/LP 5.5M 0.0 0.0 0.0 0 0( 0) 0( 0) HT20/LGI ABCDP MCS0 0.0 0.0 0.0 1 0( 0) 0( 0) - Align non-HT format Before (non-HT) (83 ch): rate throughput ewma prob this prob this succ/attempt success attempts ABCDP 6 0.0 0.0 0.0 0( 0) 0 0 54 0.0 0.0 0.0 0( 0) 0 0 - After (61 ch): rate tpt eprob *prob *ok(*cum) ok( cum) ABCDP 1 0.0 0.0 0.0 0( 0) 0( 0) 54 0.0 0.0 0.0 0( 0) 0( 0) *This also adds dynamic checks for overflow, lowers the size of the non-HT request (allowing > 30 entries) and replaces the buddy-rounded allocations (s/sizeof(*ms) + 8192/8192). Signed-off-by: Karl Beldan <karl.beldan@rivierawaves.com> Acked-by: Felix Fietkau <nbd@openwrt.org> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent c7abf25 commit 11b2357

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

net/mac80211/rc80211_minstrel_debugfs.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ minstrel_stats_open(struct inode *inode, struct file *file)
6262
unsigned int i, tp, prob, eprob;
6363
char *p;
6464

65-
ms = kmalloc(sizeof(*ms) + 4096, GFP_KERNEL);
65+
ms = kmalloc(2048, GFP_KERNEL);
6666
if (!ms)
6767
return -ENOMEM;
6868

6969
file->private_data = ms;
7070
p = ms->buf;
71-
p += sprintf(p, "rate throughput ewma prob this prob "
72-
"this succ/attempt success attempts\n");
71+
p += sprintf(p, "rate tpt eprob *prob"
72+
" *ok(*cum) ok( cum)\n");
7373
for (i = 0; i < mi->n_rates; i++) {
7474
struct minstrel_rate *mr = &mi->r[i];
7575
struct minstrel_rate_stats *mrs = &mi->r[i].stats;
@@ -86,8 +86,8 @@ minstrel_stats_open(struct inode *inode, struct file *file)
8686
prob = MINSTREL_TRUNC(mrs->cur_prob * 1000);
8787
eprob = MINSTREL_TRUNC(mrs->probability * 1000);
8888

89-
p += sprintf(p, " %6u.%1u %6u.%1u %6u.%1u "
90-
" %3u(%3u) %8llu %8llu\n",
89+
p += sprintf(p, " %4u.%1u %3u.%1u %3u.%1u"
90+
" %4u(%4u) %9llu(%9llu)\n",
9191
tp / 10, tp % 10,
9292
eprob / 10, eprob % 10,
9393
prob / 10, prob % 10,
@@ -102,6 +102,8 @@ minstrel_stats_open(struct inode *inode, struct file *file)
102102
mi->sample_packets);
103103
ms->len = p - ms->buf;
104104

105+
WARN_ON(ms->len + sizeof(*ms) > 2048);
106+
105107
return 0;
106108
}
107109

net/mac80211/rc80211_minstrel_ht_debugfs.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ minstrel_ht_stats_dump(struct minstrel_ht_sta *mi, int i, char *p)
6363
prob = MINSTREL_TRUNC(mr->cur_prob * 1000);
6464
eprob = MINSTREL_TRUNC(mr->probability * 1000);
6565

66-
p += sprintf(p, " %6u.%1u %6u.%1u %6u.%1u "
67-
"%3u %3u(%3u) %8llu %8llu\n",
66+
p += sprintf(p, " %4u.%1u %3u.%1u %3u.%1u "
67+
"%3u %4u(%4u) %9llu(%9llu)\n",
6868
tp / 10, tp % 10,
6969
eprob / 10, eprob % 10,
7070
prob / 10, prob % 10,
@@ -96,14 +96,15 @@ minstrel_ht_stats_open(struct inode *inode, struct file *file)
9696
return ret;
9797
}
9898

99-
ms = kmalloc(sizeof(*ms) + 8192, GFP_KERNEL);
99+
ms = kmalloc(8192, GFP_KERNEL);
100100
if (!ms)
101101
return -ENOMEM;
102102

103103
file->private_data = ms;
104104
p = ms->buf;
105-
p += sprintf(p, "type rate throughput ewma prob "
106-
"this prob retry this succ/attempt success attempts\n");
105+
p += sprintf(p, "type rate tpt eprob *prob "
106+
"ret *ok(*cum) ok( cum)\n");
107+
107108

108109
p = minstrel_ht_stats_dump(mi, max_mcs, p);
109110
for (i = 0; i < max_mcs; i++)
@@ -118,6 +119,8 @@ minstrel_ht_stats_open(struct inode *inode, struct file *file)
118119
MINSTREL_TRUNC(mi->avg_ampdu_len * 10) % 10);
119120
ms->len = p - ms->buf;
120121

122+
WARN_ON(ms->len + sizeof(*ms) > 8192);
123+
121124
return nonseekable_open(inode, file);
122125
}
123126

0 commit comments

Comments
 (0)