linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix /proc/pid/pagemap return length calculation
@ 2007-08-06  2:03 Dave Boutcher
  2007-08-06  3:34 ` Matt Mackall
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Boutcher @ 2007-08-06  2:03 UTC (permalink / raw)
  To: Matt Mackall; +Cc: linux-kernel


/proc/pid/pagemap has a header (usually 8 bytes) the length
of which needs to be compensated for when converting from
proc file offset to page number.  The calculation of the
starting page number (svpfn) compensates for this, but the
calculation of the ending page number (evpfn) does not, resulting
in reads returning 8 bytes more than were asked for and
nastily overwriting userspace memory.

Diffed against 2.6.23-rc1-mm2

Signed-off-by: Dave Boutcher <boutcher@cs.umn.edu>
---
 fs/proc/task_mmu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 4594f15..b2baeab 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -627,7 +627,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
 	addr = PAGE_SIZE * svpfn;
 	if ((svpfn + 1) * sizeof(unsigned long) != src)
 		goto out;
-	evpfn = min((src + count) / sizeof(unsigned long),
+	evpfn = min((src + count) / sizeof(unsigned long) - 1,
 		    ((~0UL) >> PAGE_SHIFT) + 1);
 	count = (evpfn - svpfn) * sizeof(unsigned long);
 	end = PAGE_SIZE * evpfn;
-- 
1.4.4.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix /proc/pid/pagemap return length calculation
  2007-08-06  2:03 [PATCH] Fix /proc/pid/pagemap return length calculation Dave Boutcher
@ 2007-08-06  3:34 ` Matt Mackall
  2007-08-06  4:55   ` Dave Boutcher
  0 siblings, 1 reply; 3+ messages in thread
From: Matt Mackall @ 2007-08-06  3:34 UTC (permalink / raw)
  To: Dave Boutcher; +Cc: linux-kernel, Dave Hansen, Andrew Morton

On Sun, Aug 05, 2007 at 09:03:23PM -0500, Dave Boutcher wrote:
> 
> /proc/pid/pagemap has a header (usually 8 bytes) the length
> of which needs to be compensated for when converting from
> proc file offset to page number.  The calculation of the
> starting page number (svpfn) compensates for this, but the
> calculation of the ending page number (evpfn) does not, resulting
> in reads returning 8 bytes more than were asked for and
> nastily overwriting userspace memory.

Does this mean you're running on a 64-bit arch? I'd already fixed this
locally, but it was off by 4 for me.

Acked-by: Matt Mackall <mpm@selenic.com>
 
> Diffed against 2.6.23-rc1-mm2
> 
> Signed-off-by: Dave Boutcher <boutcher@cs.umn.edu>
> ---
>  fs/proc/task_mmu.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index 4594f15..b2baeab 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -627,7 +627,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
>  	addr = PAGE_SIZE * svpfn;
>  	if ((svpfn + 1) * sizeof(unsigned long) != src)
>  		goto out;
> -	evpfn = min((src + count) / sizeof(unsigned long),
> +	evpfn = min((src + count) / sizeof(unsigned long) - 1,
>  		    ((~0UL) >> PAGE_SHIFT) + 1);
>  	count = (evpfn - svpfn) * sizeof(unsigned long);
>  	end = PAGE_SIZE * evpfn;
> -- 
> 1.4.4.2

-- 
Mathematics is the supreme nostalgia of our time.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix /proc/pid/pagemap return length calculation
  2007-08-06  3:34 ` Matt Mackall
@ 2007-08-06  4:55   ` Dave Boutcher
  0 siblings, 0 replies; 3+ messages in thread
From: Dave Boutcher @ 2007-08-06  4:55 UTC (permalink / raw)
  To: Matt Mackall; +Cc: Dave Boutcher, linux-kernel, Dave Hansen, Andrew Morton

On Sun, 5 Aug 2007 22:34:46 -0500, Matt Mackall <mpm@selenic.com> said:
> 
> On Sun, Aug 05, 2007 at 09:03:23PM -0500, Dave Boutcher wrote:
>> 
>> /proc/pid/pagemap has a header (usually 8 bytes) the length
>> of which needs to be compensated for when converting from
>> proc file offset to page number.  The calculation of the
>> starting page number (svpfn) compensates for this, but the
>> calculation of the ending page number (evpfn) does not, resulting
>> in reads returning 8 bytes more than were asked for and
>> nastily overwriting userspace memory.
> 
> Does this mean you're running on a 64-bit arch? I'd already fixed this
> locally, but it was off by 4 for me.
> 
> Acked-by: Matt Mackall <mpm@selenic.com>

Yeah, and there is going to be at least one more patch coming, since
with this fix, which is a righteous fix, things don't get copied up to
user space correctly since some other code was dependent on the borken 
length :-)

I like the /proc/xxx/pagemap function though...thanks for writing it.

Dave B

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-08-06  5:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-06  2:03 [PATCH] Fix /proc/pid/pagemap return length calculation Dave Boutcher
2007-08-06  3:34 ` Matt Mackall
2007-08-06  4:55   ` Dave Boutcher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).