Skip to content

Commit

Permalink
[PATCH] cpuset read past eof memory leak fix
Browse files Browse the repository at this point in the history
Don't leak a page of memory if user reads a cpuset file past eof.

Signed-off-by: KUROSAWA Takahiro <kurosawa@valinux.co.jp>
Signed-off-by: Paul Jackson <pj@sgi.com>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Paul Jackson authored and Linus Torvalds committed Sep 28, 2005
1 parent 2dd3c1d commit 5134fc1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions kernel/cpuset.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ static ssize_t cpuset_common_file_read(struct file *file, char __user *buf,
ssize_t retval = 0;
char *s;
char *start;
size_t n;
ssize_t n;

if (!(page = (char *)__get_free_page(GFP_KERNEL)))
return -ENOMEM;
Expand Down Expand Up @@ -999,12 +999,13 @@ static ssize_t cpuset_common_file_read(struct file *file, char __user *buf,
*s++ = '\n';
*s = '\0';

/* Do nothing if *ppos is at the eof or beyond the eof. */
if (s - page <= *ppos)
return 0;

start = page + *ppos;
n = s - start;

/* Do nothing if *ppos is at the eof or beyond the eof. */
if (n <= 0)
goto out;

retval = n - copy_to_user(buf, start, min(n, nbytes));
*ppos += retval;
out:
Expand Down

0 comments on commit 5134fc1

Please sign in to comment.