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;
}