public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Akinobu Mita <mita@miraclelinux.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] Bug in reading some files in /proc/PID/
Date: Fri, 26 Dec 2003 11:54:02 +0900	[thread overview]
Message-ID: <200312261154.02338.mita@miraclelinux.com> (raw)

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;


                 reply	other threads:[~2003-12-26  2:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200312261154.02338.mita@miraclelinux.com \
    --to=mita@miraclelinux.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox