linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ipw2200: prevent alloc of unspecified size on stack
@ 2007-12-19  6:01 Reinette Chatre
  2007-12-19  6:20 ` Zhu Yi
  2007-12-19  6:35 ` Al Viro
  0 siblings, 2 replies; 5+ messages in thread
From: Reinette Chatre @ 2007-12-19  6:01 UTC (permalink / raw)
  To: linville, linux-wireless; +Cc: yi.zhu, viro, Reinette Chatre

if log_len is larger than 4K then we are killing the stack.
allocate on heap instead and limit size to what practically can
be used (PAGE_SIZE)

Is it possible for this to get into 2.6.24?

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
 drivers/net/wireless/ipw2200.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/drivers/net/wireless/ipw2200.c b/drivers/net/wireless/ipw2200.c
index 54f44e5..e19e83a 100644
--- a/drivers/net/wireless/ipw2200.c
+++ b/drivers/net/wireless/ipw2200.c
@@ -1233,9 +1233,19 @@ static ssize_t show_event_log(struct device *d,
 {
 	struct ipw_priv *priv = dev_get_drvdata(d);
 	u32 log_len = ipw_get_event_log_len(priv);
-	struct ipw_event log[log_len];
+	u32 log_size;
+	struct ipw_event *log;
 	u32 len = 0, i;
 
+	/* not using min() because of its strict type checking */
+	log_size = sizeof(*log) * log_len < PAGE_SIZE ?
+			sizeof(*log) * log_len : PAGE_SIZE;
+	log = kzalloc(log_size, GFP_KERNEL);
+	if (!log) {
+		IPW_ERROR("Unable to allocate memory for log\n");
+		return 0;
+	}
+	log_len = log_size / sizeof(*log);
 	ipw_capture_event_log(priv, log_len, log);
 
 	len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
@@ -1244,6 +1254,7 @@ static ssize_t show_event_log(struct device *d,
 				"\n%08X%08X%08X",
 				log[i].time, log[i].event, log[i].data);
 	len += snprintf(buf + len, PAGE_SIZE - len, "\n");
+	kfree(log);
 	return len;
 }
 
-- 
1.5.3.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ipw2200: prevent alloc of unspecified size on stack
  2007-12-19  6:01 [PATCH] ipw2200: prevent alloc of unspecified size on stack Reinette Chatre
@ 2007-12-19  6:20 ` Zhu Yi
  2007-12-19  6:35 ` Al Viro
  1 sibling, 0 replies; 5+ messages in thread
From: Zhu Yi @ 2007-12-19  6:20 UTC (permalink / raw)
  To: Reinette Chatre; +Cc: linville, linux-wireless, viro


On Tue, 2007-12-18 at 22:01 -0800, Reinette Chatre wrote:
> if log_len is larger than 4K then we are killing the stack.
> allocate on heap instead and limit size to what practically can
> be used (PAGE_SIZE)
> 
> Is it possible for this to get into 2.6.24?
> 
> Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>

ACK.

> ---
> +       /* not using min() because of its strict type checking */
> +       log_size = sizeof(*log) * log_len < PAGE_SIZE ?
> +                       sizeof(*log) * log_len : PAGE_SIZE;

A (u32) cast should work. But I don't think it's a big issue.

Thanks,
-yi


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ipw2200: prevent alloc of unspecified size on stack
  2007-12-19  6:01 [PATCH] ipw2200: prevent alloc of unspecified size on stack Reinette Chatre
  2007-12-19  6:20 ` Zhu Yi
@ 2007-12-19  6:35 ` Al Viro
  2007-12-19  6:52   ` Chatre, Reinette
  2007-12-19  7:16   ` Zhu Yi
  1 sibling, 2 replies; 5+ messages in thread
From: Al Viro @ 2007-12-19  6:35 UTC (permalink / raw)
  To: Reinette Chatre; +Cc: linville, linux-wireless, yi.zhu, viro

On Tue, Dec 18, 2007 at 10:01:02PM -0800, Reinette Chatre wrote:
> +	/* not using min() because of its strict type checking */
> +	log_size = sizeof(*log) * log_len < PAGE_SIZE ?

		   PAGE_SIZE / sizeof(*log) > len ?

to be provably safe against wraparounds, if you really want to limit that
to PAGE_SIZE...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] ipw2200: prevent alloc of unspecified size on stack
  2007-12-19  6:35 ` Al Viro
@ 2007-12-19  6:52   ` Chatre, Reinette
  2007-12-19  7:16   ` Zhu Yi
  1 sibling, 0 replies; 5+ messages in thread
From: Chatre, Reinette @ 2007-12-19  6:52 UTC (permalink / raw)
  To: Al Viro; +Cc: linville, linux-wireless, Zhu, Yi, viro

On Tuesday, December 18, 2007 10:35 PM, Al Viro  wrote:

> On Tue, Dec 18, 2007 at 10:01:02PM -0800, Reinette Chatre wrote:
>> +	/* not using min() because of its strict type checking */
>> +	log_size = sizeof(*log) * log_len < PAGE_SIZE ?
> 
> 		   PAGE_SIZE / sizeof(*log) > len ?
> 
> to be provably safe against wraparounds, if you really want to limit
> that to PAGE_SIZE...

To cover this I reset log_len after allocating the memory:

+	}
+	log_len = log_size / sizeof(*log);
 	ipw_capture_event_log(priv, log_len, log);


If we use the original length then we are ok and log_len is just what it
was before. If we use PAGE_SIZE then log_len is reset to fit in the
amount of memory we allocated (PAGE_SIZE).

Is this what you meant?

Reinette

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ipw2200: prevent alloc of unspecified size on stack
  2007-12-19  6:35 ` Al Viro
  2007-12-19  6:52   ` Chatre, Reinette
@ 2007-12-19  7:16   ` Zhu Yi
  1 sibling, 0 replies; 5+ messages in thread
From: Zhu Yi @ 2007-12-19  7:16 UTC (permalink / raw)
  To: Al Viro; +Cc: Reinette Chatre, linville, linux-wireless, viro


On Wed, 2007-12-19 at 06:35 +0000, Al Viro wrote:
> to be provably safe against wraparounds, if you really want to limit
> that to PAGE_SIZE...

This is a sysfs read. We can only print PAGE_SIZE at most anyway.

Thanks,
-yi


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-12-19  7:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-19  6:01 [PATCH] ipw2200: prevent alloc of unspecified size on stack Reinette Chatre
2007-12-19  6:20 ` Zhu Yi
2007-12-19  6:35 ` Al Viro
2007-12-19  6:52   ` Chatre, Reinette
2007-12-19  7:16   ` Zhu Yi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).