Bug in reading some files in /proc/<pid>/
PATCH RESEND 1/1 Bug in reading some files in /proc/<pid>/
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: -1This result could be expected.
but..
$ ./a.out /proc/1/stat
Success: 214 fs/proc/base.c renamed from fs/proc/base.c.orig +4 -2
@@ -357,8 +357,10 @@ static ssize_t proc_info_read(struct filif (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; }