Skip to contentSkip to conversation

Bug in reading some files in /proc/PID/

PATCH Superseded Akinobu Mita 1 participant 1 message Dec 26, 2003 Proc filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bug in reading some files in /proc/PID/

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);
}
fs/proc/base.c 2003-12-26 11:34:41.000000000 +0900 renamed from fs/proc/base.c.orig 2003-12-26 11:34:19.000000000 +0900 +4 -1
@@ -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;