Fix /proc/pid/pagemap return length calculation
Subsystems (2)
PATCH 1/1 Fix /proc/pid/pagemap return length calculation
/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
--- fs/proc/task_mmu.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/proc/task_mmu.c +1 -1
@@ -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;
Signature · 1 line
1.4.4.2
Quoted 8 lines · Dave Boutcher
/proc/pid/pagemaphas 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.
Quoted 22 lines
Diffed against 2.6.23-rc1-mm2
Signed-off-by Dave Boutcher <[email protected]>--- fs/proc/task_mmu.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)fs/proc/task_mmu.c +1
-1@@ -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;Signature · 1 line
1.4.4.2
Signature · 1 line
Mathematics is the supreme nostalgia of our time.
Quoted 11 lines · Matt Mackall
Quoted 8 lines · Dave Boutcher
/proc/pid/pagemaphas 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.
Quoted 4 lines
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 <[email protected]>
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