Don't leak a page of memory if user reads a cpuset file past eof. Signed-off-by: KUROSAWA Takahiro <[email protected]> Signed-off-by: Paul Jackson <[email protected]> --- linux-2.6.14-rc2.orig/kernel/cpuset.c +++ linux-2.6.14-rc2/kernel/cpuset.c 2005-09-28 17:42:00.759401736 +0900 @@ -969,7 +969,7 @@ static ssize_t cpuset_common_file_read(s ssize_t retval = 0; char *s; char *start; - size_t n; + ssize_t n; if (!(page = (char *)__get_free_page(GFP_KERNEL))) return -ENOMEM; @@ -999,12 +999,13 @@ static ssize_t cpuset_common_file_read(s *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: -- I won't rest till it's the best ... Programmer, Linux Scalability Paul Jackson <[email protected]> 1.925.600.0401 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
- Follow-Ups:
- Re: [PATCH] cpuset read past eof memory leak fix
- From: Linus Torvalds <[email protected]>
- Re: [PATCH] cpuset read past eof memory leak fix
- References:
- Re: [PATCH 0/5] SUBCPUSETS: a resource control functionality using CPUSETS
- From: Paul Jackson <[email protected]>
- Re: [PATCH 0/5] SUBCPUSETS: a resource control functionality using CPUSETS
- From: Hirokazu Takahashi <[email protected]>
- Re: [PATCH 0/5] SUBCPUSETS: a resource control functionality using CPUSETS
- From: Paul Jackson <[email protected]>
- Re: [PATCH 0/5] SUBCPUSETS: a resource control functionality using CPUSETS
- From: Hirokazu Takahashi <[email protected]>
- Re: [PATCH 0/5] SUBCPUSETS: a resource control functionality using CPUSETS
- From: Paul Jackson <[email protected]>
- [PATCH 1/3] CPUMETER: add cpumeter framework to the CPUSETS
- From: KUROSAWA Takahiro <[email protected]>
- Re: [PATCH 1/3] CPUMETER: add cpumeter framework to the CPUSETS
- From: Paul Jackson <[email protected]>
- Re: [PATCH 1/3] CPUMETER: add cpumeter framework to the CPUSETS
- From: KUROSAWA Takahiro <[email protected]>
- [PATCH][BUG] fix memory leak on reading cpuset files after seeking beyond eof
- From: KUROSAWA Takahiro <[email protected]>
- Re: [PATCH 0/5] SUBCPUSETS: a resource control functionality using CPUSETS
- Prev by Date: Re: [PATCH][BUG] fix memory leak on reading cpuset files after seeking beyond eof
- Next by Date: Re: [git pull] InfiniBand fixes for 2.6.14
- Previous by thread: Re: [PATCH][BUG] fix memory leak on reading cpuset files after seeking beyond eof
- Next by thread: Re: [PATCH] cpuset read past eof memory leak fix
- Index(es):