public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Bug in reading some files in /proc/PID/
@ 2003-12-26  2:54 Akinobu Mita
  0 siblings, 0 replies; only message in thread
From: Akinobu Mita @ 2003-12-26  2:54 UTC (permalink / raw)
  To: linux-kernel

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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-12-26  2:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-26  2:54 [PATCH] Bug in reading some files in /proc/PID/ Akinobu Mita

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox