[PATCH] Bug in reading some files in /proc/PID/

From: Akinobu Mita
Date: Thu Dec 25 2003 - 21:59:12 EST


Hi,

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

ex.

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

-----
#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, 0, 4*1024); // Bad address
printf("%s: %d\n", strerror(errno), ret);
}

--- linux-2.4.23/fs/proc/base.c.orig 2003-12-26 11:34:19.000000000 +0900
+++ linux-2.4.23/fs/proc/base.c 2003-12-26 11:34:41.000000000 +0900
@@ -357,7 +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);
+ if (copy_to_user(buf, (char *) page + *ppos, count)) {
+ free_page(page);
+ return -EFAULT;
+ }
*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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/