2005-01-07 01:41:48

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH][4/4] let's kill verify_area - convert kernel/printk.c to access_ok()


Here's a patch to convert verify_area to access_ok in kernel/printk.c


Signed-off-by: Jesper Juhl <[email protected]>

diff -up linux-2.6.10-bk9-orig/kernel/printk.c linux-2.6.10-bk9/kernel/printk.c
--- linux-2.6.10-bk9-orig/kernel/printk.c 2004-12-24 22:35:40.000000000 +0100
+++ linux-2.6.10-bk9/kernel/printk.c 2005-01-07 02:11:16.000000000 +0100
@@ -269,8 +269,8 @@ int do_syslog(int type, char __user * bu
error = 0;
if (!len)
goto out;
- error = verify_area(VERIFY_WRITE,buf,len);
- if (error)
+ error = access_ok(VERIFY_WRITE,buf,len);
+ if (!error)
goto out;
error = wait_event_interruptible(log_wait, (log_start - log_end));
if (error)
@@ -300,8 +300,8 @@ int do_syslog(int type, char __user * bu
error = 0;
if (!len)
goto out;
- error = verify_area(VERIFY_WRITE,buf,len);
- if (error)
+ error = access_ok(VERIFY_WRITE,buf,len);
+ if (!error)
goto out;
count = len;
if (count > log_buf_len)




2005-01-07 12:51:45

by Vincent Hanquez

[permalink] [raw]
Subject: Re: [PATCH][4/4] let's kill verify_area - convert kernel/printk.c to access_ok()

On Fri, Jan 07, 2005 at 02:18:55AM +0100, Jesper Juhl wrote:
> @@ -300,8 +300,8 @@ int do_syslog(int type, char __user * bu
> error = 0;
> if (!len)
> goto out;
> - error = verify_area(VERIFY_WRITE,buf,len);
> - if (error)
> + error = access_ok(VERIFY_WRITE,buf,len);
> + if (!error)

I would rather put the ! on access_ok
"if (!error)" is read as "if no error"

--
Vincent Hanquez

2005-01-07 15:41:05

by Peter Kjellerstedt

[permalink] [raw]
Subject: RE: [PATCH][4/4] let's kill verify_area - convert kernel/printk.c to access_ok()

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of
> Vincent Hanquez
> Sent: Friday, January 07, 2005 13:52
> To: Jesper Juhl
> Cc: linux-kernel; Andrew Morton
> Subject: Re: [PATCH][4/4] let's kill verify_area - convert
> kernel/printk.c to access_ok()
>
> On Fri, Jan 07, 2005 at 02:18:55AM +0100, Jesper Juhl wrote:
> > @@ -300,8 +300,8 @@ int do_syslog(int type, char __user * bu
> > error = 0;
> > if (!len)
> > goto out;
> > - error = verify_area(VERIFY_WRITE,buf,len);
> > - if (error)
> > + error = access_ok(VERIFY_WRITE,buf,len);
> > + if (!error)
>
> I would rather put the ! on access_ok
> "if (!error)" is read as "if no error"

Actually, this should be:

error = access_ok(VERIFY_WRITE, buf, len) ? 0 : -EFAULT;
if (error)
goto out;

Alternatively:

if (!access_ok(VERIFY_WRITE, buf, len)) {
error = -EFAULT;
goto out;
}

Otherwise the returned value from do_syslog() is incorrect
in case access_ok() fails (i.e., 0 instead of -EFAULT)...

//Peter