All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [Security] [PATCH] bug in led_proc_write()
       [not found] ` <20100710170458.96dc8a65.akpm@linux-foundation.org>
@ 2010-08-02 20:46   ` Helge Deller
  2010-08-03 13:31     ` Kyle McMartin
  0 siblings, 1 reply; 2+ messages in thread
From: Helge Deller @ 2010-08-02 20:46 UTC (permalink / raw)
  To: Andrew Morton, linux-parisc, Kyle McMartin
  Cc: Ilja, security, Helge Deller, James E.J. Bottomley

* Andrew Morton <akpm@linux-foundation.org>:
> On Sat, 10 Nov 2007 23:50:29 +0100 Ilja <ilja@netric.org> wrote:
> > When reading some of the parisc driver code I stumbled on a bug in
> > led_proc_write() in drivers/parisc/led.c
> > the code looks like:
> > 
> > 182 static int led_proc_write(struct file *file, const char *buf, 
> > 183         unsigned long count, void *data)
> > 184 {
> > 185         char *cur, lbuf[count + 1];
> > 186         int d;
> > 187
> > 188         if (!capable(CAP_SYS_ADMIN))
> > 189                 return -EACCES;
> > ....
> > 235 }
> > 
> > the problem being that the stack is limited and count is not (except for the
> > MAX_INT check done in sys_write() I guess). this could lead to stack
> > corruption (when for example calling capable()). 
> 
> yes, and the bug's still there.  It allows a writer to /proc/pdc/led(?)
> to cause the kernel to consume an unbounded amount of stack. 

Ilja, Andrew,

Thanks for the bug report.
Below is a patch to fix this issue.

Kyle, please apply to the parisc git tree.

Helge

-----------
[PARISC] led.c - fix potential stack overflow in led_proc_write()

avoid potential stack overflow by correctly checking count parameter

Signed-off-by: Helge Deller <deller@gmx.de>


diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c
index 188bc84..d02be78 100644
--- a/drivers/parisc/led.c
+++ b/drivers/parisc/led.c
@@ -176,16 +176,18 @@ static ssize_t led_proc_write(struct file *file, const char *buf,
 	size_t count, loff_t *pos)
 {
 	void *data = PDE(file->f_path.dentry->d_inode)->data;
-	char *cur, lbuf[count + 1];
+	char *cur, lbuf[32];
 	int d;
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EACCES;
 
-	memset(lbuf, 0, count + 1);
+	if (count >= sizeof(lbuf))
+		count = sizeof(lbuf)-1;
 
 	if (copy_from_user(lbuf, buf, count))
 		return -EFAULT;
+	lbuf[count] = 0;
 
 	cur = lbuf;
 



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

* Re: [Security] [PATCH] bug in led_proc_write()
  2010-08-02 20:46   ` [Security] [PATCH] bug in led_proc_write() Helge Deller
@ 2010-08-03 13:31     ` Kyle McMartin
  0 siblings, 0 replies; 2+ messages in thread
From: Kyle McMartin @ 2010-08-03 13:31 UTC (permalink / raw)
  To: Helge Deller
  Cc: Andrew Morton, linux-parisc, Kyle McMartin, Ilja, security,
	James E.J. Bottomley

On Mon, Aug 02, 2010 at 10:46:41PM +0200, Helge Deller wrote:
> Kyle, please apply to the parisc git tree.
> 

Please send this straight to Linus with my
Signed-off-by: Kyle McMartin <kyle@mcmartin.ca>

I don't want to accidentally mis-place it again this summer.

--Kyle

> Helge
> 
> -----------
> [PARISC] led.c - fix potential stack overflow in led_proc_write()
> 
> avoid potential stack overflow by correctly checking count parameter
> 
> Signed-off-by: Helge Deller <deller@gmx.de>
> 
> 
> diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c
> index 188bc84..d02be78 100644
> --- a/drivers/parisc/led.c
> +++ b/drivers/parisc/led.c
> @@ -176,16 +176,18 @@ static ssize_t led_proc_write(struct file *file, const char *buf,
>  	size_t count, loff_t *pos)
>  {
>  	void *data = PDE(file->f_path.dentry->d_inode)->data;
> -	char *cur, lbuf[count + 1];
> +	char *cur, lbuf[32];
>  	int d;
>  
>  	if (!capable(CAP_SYS_ADMIN))
>  		return -EACCES;
>  
> -	memset(lbuf, 0, count + 1);
> +	if (count >= sizeof(lbuf))
> +		count = sizeof(lbuf)-1;
>  
>  	if (copy_from_user(lbuf, buf, count))
>  		return -EFAULT;
> +	lbuf[count] = 0;
>  
>  	cur = lbuf;
>  
> 
> 
> 

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

end of thread, other threads:[~2010-08-03 13:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <52a11dc3cc92b1e13c028304d9a7beaa@81.11.193.46>
     [not found] ` <20100710170458.96dc8a65.akpm@linux-foundation.org>
2010-08-02 20:46   ` [Security] [PATCH] bug in led_proc_write() Helge Deller
2010-08-03 13:31     ` Kyle McMartin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.