[34-longterm 077/260] wireless extensions: fix kernel heap content leak

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Paul Gortmaker
Date: Sunday, January 2, 2011 - 12:16 am

From: Johannes Berg <johannes.berg@intel.com>

commit 42da2f948d949efd0111309f5827bf0298bcc9a4 upstream.

Wireless extensions have an unfortunate, undocumented
requirement which requires drivers to always fill
iwp->length when returning a successful status. When
a driver doesn't do this, it leads to a kernel heap
content leak when userspace offers a larger buffer
than would have been necessary.

Arguably, this is a driver bug, as it should, if it
returns 0, fill iwp->length, even if it separately
indicated that the buffer contents was not valid.

However, we can also at least avoid the memory content
leak if the driver doesn't do this by setting the iwp
length to max_tokens, which then reflects how big the
buffer is that the driver may fill, regardless of how
big the userspace buffer is.

To illustrate the point, this patch also fixes a
corresponding cfg80211 bug (since this requirement
isn't documented nor was ever pointed out by anyone
during code review, I don't trust all drivers nor
all cfg80211 handlers to implement it correctly).

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
 net/wireless/wext-compat.c |    3 +++
 net/wireless/wext-core.c   |   16 ++++++++++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
index a60a277..68202f9 100644
--- a/net/wireless/wext-compat.c
+++ b/net/wireless/wext-compat.c
@@ -1415,6 +1415,9 @@ int cfg80211_wext_giwessid(struct net_device *dev,
 {
 	struct wireless_dev *wdev = dev->ieee80211_ptr;
 
+	data->flags = 0;
+	data->length = 0;
+
 	switch (wdev->iftype) {
 	case NL80211_IFTYPE_ADHOC:
 		return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
index 4f5a470..f916f5a 100644
--- a/net/wireless/wext-core.c
+++ b/net/wireless/wext-core.c
@@ -782,6 +782,22 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
 		}
 	}
 
+	if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
+		/*
+		 * If this is a GET, but not NOMAX, it means that the extra
+		 * data is not bounded by userspace, but by max_tokens. Thus
+		 * set the length to max_tokens. This matches the extra data
+		 * allocation.
+		 * The driver should fill it with the number of tokens it
+		 * provided, and it may check iwp->length rather than having
+		 * knowledge of max_tokens. If the driver doesn't change the
+		 * iwp->length, this ioctl just copies back max_token tokens
+		 * filled with zeroes. Hopefully the driver isn't claiming
+		 * them to be valid data.
+		 */
+		iwp->length = descr->max_tokens;
+	}
+
 	err = handler(dev, info, (union iwreq_data *) iwp, extra);
 
 	iwp->length += essid_compat;
-- 
1.7.3.3

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[34-longterm 000/260] v2.6.34.8 longterm review, Paul Gortmaker, (Sun Jan 2, 12:14 am)
[34-longterm 003/260] ath5k: drop warning on jumbo frames, Paul Gortmaker, (Sun Jan 2, 12:14 am)
[34-longterm 019/260] ext4: Show journal_checksum option, Paul Gortmaker, (Sun Jan 2, 12:15 am)
[34-longterm 025/260] ext4: Fix compat EXT4_IOC_ADD_GROUP, Paul Gortmaker, (Sun Jan 2, 12:15 am)
[34-longterm 028/260] ext4: fix freeze deadlock under IO, Paul Gortmaker, (Sun Jan 2, 12:15 am)
[34-longterm 030/260] xen: handle events as edge-triggered, Paul Gortmaker, (Sun Jan 2, 12:15 am)
[34-longterm 045/260] USB: ehci-ppc-of: problems in unwind, Paul Gortmaker, (Sun Jan 2, 12:15 am)
[34-longterm 047/260] USB: CP210x Add new device ID, Paul Gortmaker, (Sun Jan 2, 12:15 am)
[34-longterm 065/260] irda: off by one, Paul Gortmaker, (Sun Jan 2, 12:16 am)
[34-longterm 077/260] wireless extensions: fix kernel heap ..., Paul Gortmaker, (Sun Jan 2, 12:16 am)
[34-longterm 089/260] sched: Optimize task_rq_lock(), Paul Gortmaker, (Sun Jan 2, 12:16 am)
[34-longterm 090/260] sched: Fix nr_uninterruptible count, Paul Gortmaker, (Sun Jan 2, 12:16 am)
[34-longterm 093/260] sched: Fix select_idle_sibling(), Paul Gortmaker, (Sun Jan 2, 12:16 am)
[34-longterm 098/260] arm: fix really nasty sigreturn bug, Paul Gortmaker, (Sun Jan 2, 12:16 am)
[34-longterm 106/260] drm/i915: Prevent double dpms on, Paul Gortmaker, (Sun Jan 2, 12:16 am)
[34-longterm 110/260] gro: fix different skb headrooms, Paul Gortmaker, (Sun Jan 2, 12:16 am)
[34-longterm 111/260] gro: Re-fix different skb headrooms, Paul Gortmaker, (Sun Jan 2, 12:16 am)
[34-longterm 115/260] tcp: fix three tcp sysctls tuning, Paul Gortmaker, (Sun Jan 2, 12:16 am)
[34-longterm 118/260] rds: fix a leak of kernel memory, Paul Gortmaker, (Sun Jan 2, 12:16 am)
[34-longterm 126/260] Staging: vt6655: fix buffer overflow, Paul Gortmaker, (Sun Jan 2, 12:17 am)
[34-longterm 134/260] percpu: fix pcpu_last_unit_cpu, Paul Gortmaker, (Sun Jan 2, 12:17 am)
[34-longterm 136/260] inotify: send IN_UNMOUNT events, Paul Gortmaker, (Sun Jan 2, 12:17 am)
[34-longterm 139/260] fix siglock, Paul Gortmaker, (Sun Jan 2, 12:17 am)
[34-longterm 145/260] AT91: change dma resource index, Paul Gortmaker, (Sun Jan 2, 12:17 am)
[34-longterm 154/260] inotify: fix inotify oneshot support, Paul Gortmaker, (Sun Jan 2, 12:17 am)
[34-longterm 158/260] alpha: Fix printk format errors, Paul Gortmaker, (Sun Jan 2, 12:17 am)
[34-longterm 188/260] atl1: fix resume, Paul Gortmaker, (Sun Jan 2, 12:18 am)
[34-longterm 190/260] De-pessimize rds_page_copy_user, Paul Gortmaker, (Sun Jan 2, 12:18 am)
[34-longterm 192/260] xfrm4: strip ECN bits from tos field, Paul Gortmaker, (Sun Jan 2, 12:18 am)
[34-longterm 193/260] tcp: Fix &gt;4GB writes on 64-bit., Paul Gortmaker, (Sun Jan 2, 12:18 am)
[34-longterm 199/260] tcp: Fix race in tcp_poll, Paul Gortmaker, (Sun Jan 2, 12:18 am)
[34-longterm 200/260] netxen: dont set skb-&gt;truesize, Paul Gortmaker, (Sun Jan 2, 12:18 am)
[34-longterm 203/260] skge: add quirk to limit DMA, Paul Gortmaker, (Sun Jan 2, 12:18 am)
[34-longterm 208/260] b44: fix carrier detection on bind, Paul Gortmaker, (Sun Jan 2, 12:18 am)
[34-longterm 224/260] bluetooth: Fix missing NULL check, Paul Gortmaker, (Sun Jan 2, 12:18 am)
[34-longterm 236/260] KVM: x86: Fix SVM VMCB reset, Paul Gortmaker, (Sun Jan 2, 12:18 am)
[34-longterm 240/260] p54usb: fix off-by-one on !CONFIG_PM, Paul Gortmaker, (Sun Jan 2, 12:18 am)
[34-longterm 241/260] p54usb: add five more USBIDs, Paul Gortmaker, (Sun Jan 2, 12:18 am)
[34-longterm 256/260] libsas: fix NCQ mixing with non-NCQ, Paul Gortmaker, (Sun Jan 2, 12:19 am)
[34-longterm 257/260] gdth: integer overflow in ioctl, Paul Gortmaker, (Sun Jan 2, 12:19 am)
[34-longterm 258/260] Fix race when removing SCSI devices, Paul Gortmaker, (Sun Jan 2, 12:19 am)
Re: [34-longterm 000/260] v2.6.34.8 longterm review, Paul Gortmaker, (Sun Jan 2, 3:46 am)
Re: [34-longterm 000/260] v2.6.34.8 longterm review, Jiri Slaby, (Mon Jan 3, 3:41 am)
Re: [34-longterm 000/260] v2.6.34.8 longterm review, Paul Gortmaker, (Tue Jan 4, 12:11 pm)