lkml.org 
[lkml]   [2004]   [Jan]   [7]   [last100]   RSS Feed
Views: [more markup]   [less markup]   [headers]   [forward]  
 
Messages in this thread
Patch in this message
/
FromAkinobu Mita <>
Subject[PATCH 2.4][RESEND] Bug in reading some files in /proc/<pid>/
DateWed, 7 Jan 2004 14:10:22 +0900
Hi Marcelo,

I found the bug in 2.4. this problem has already been fixed in 2.6.

The following program could not detect Bad address
with /proc/<pid>/cmdline, stat, statm, ...

-----
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char **argv)
{
    int fd, ret;
    fd = open(argv[1], O_RDONLY);
    ret = read(fd, NULL, 4*1024); // Bad address
    printf("%s: %d\n", strerror(errno), ret);
}
-----
For example.

    $ ./a.out a.out
    Bad Address: -1

This result could be expected.
but..

    $ ./a.out /proc/1/stat
    Success: 214 


--- linux-2.4.x/fs/proc/base.c.orig	2003-12-26 11:34:19.000000000 +0900
+++ linux-2.4.x/fs/proc/base.c	2004-01-07 13:32:12.000000000 +0900
@@ -357,8 +357,10 @@ static ssize_t proc_info_read(struct fil
 	if (count + *ppos > length)
 		count = length - *ppos;
 	end = count + *ppos;
-	copy_to_user(buf, (char *) page + *ppos, count);
-	*ppos = end;
+	if (copy_to_user(buf, (char *) page + *ppos, count))
+		count = -EFAULT;
+	else
+		*ppos = end;
 	free_page(page);
 	return count;
 }

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:59    [W:0.640 / U:0.280 seconds]
©2003-2008 Jasper Spaans