ptrace PTRACE_READDATA/WRITEDATA, kernel 2.5.62
Review
Quoted 6 lines · On Mon, Feb 24, 2003 at 03:05:14PM +0100, [email protected] wrote:
(quoted diff) +4
-0+ ret = 0; + res = ptrace_readdata(child, addr, (void *)addr2, data); + if (res == data) + break;
You mention sparc - have you tested if that works on sparc?ptrace_readdata assumes that addr2 is a pointer to kernel space, not user space. It works by chance on i386, but that's not acceptable for merging. You must double buffer, check mem_read in fs/proc/base.c
Quoted 5 lines · Daniel
Thirdly, I was going to do this, but I ended up making GDB use pread64 on
/dev/meminstead. It works with no kernel modifications, and is just as fast.
I assume you mean /proc/<pid>/mem. Performance is identical, same implementation.
--
Manfred
Hi,
Quoted 11 lines
Review
Quoted 6 lines
(quoted diff) +4
-0+ ret = 0; + res = ptrace_readdata(child, addr, (void *)addr2, data); + if (res == data) + break;You mention sparc - have you tested if that works on sparc?
ptrace_readdataassumes that addr2 is a pointer to kernel space, not user space. It works by chance on i386, but that's not acceptable for merging.
You must double buffer, checkmem_readinfs/proc/base.c
I don't own a sparc so I couldn't test it. But since the ptrace_readdata lives in the kernel tree for some time now and nobody is complaining about it I assume the sparc usage of ptrace_readdata is OK. I did test it on i386 and it works just fine.
When I look at the implementation of ptrace_readdata the dst (3th arg) has to be a pointer to user space; see: copy_to_user(dst, buf, retval). Only access_process_vm wants a kernel pointer. Anyway access_process_vm has some known issues, see:
http://www.kernel.org/pub/linux/kernel/people/akpm/patches/2.5/2.5.62/2.5.62-mm3/broken-out/ptrace-flush.patch
but it's getting fixed I hope.
As for that double buffering, it's already there. See usage of:
kernel/ptrace.c:ptrace_readdata:char buf[128];
Please notice this double buffering can be eliminated as done in my exptrace patch, available at:
http://www.elis.rug.ac.be/~fcorneli/downloads/devel/exptrace-0.3.6pre7-2.4.20.patch
This speeds up everything... but the code needs some more testing, and a port to 2.5.
Regards,
Frank.
Quoted 3 lines · [email protected] wrote:
But since the
ptrace_readdatalives in the kernel tree for some time now and nobody is complaining about it I assume the sparc usage ofptrace_readdatais OK. I did test it on i386 and it works just fine.
Sorry, my fault. I remembered that someone must do double buffering. I've overlooked that ptrace_readdata does the double buffering.
Quoted 5 lines
When I look at the implementation of
ptrace_readdatathe dst (3th arg) has to be a pointer to user space; see:copy_to_user(dst, buf, retval). Onlyaccess_process_vmwants a kernel pointer. Anywayaccess_process_vmhas some known issues, see:
http://www.kernel.org/pub/linux/kernel/people/akpm/patches/2.5/2.5.62/2.5.62-mm3/broken-out/ptrace-flush.patch
but it's getting fixed I hope.
This patch seems to be wrong.flush_dcache_page is not a replacement for flush_page_to_ram(): It's an optimized cache flush function, only valid for page cache pages:
If a page is mapped only once, then no aliasing can occur and the flush is not required.
For page cache pages, "mapped once" is equivalient to an empty page->mapping->i_mmap{,_shared}. The pages are mapped once in the page cache, and _if_ they are mapped in user space, then page->mapping->i_mmap{,_shared} is not empty.
ptrace can be called on random addresses - sysv shm, anonymous pages, etc. page->mapping->i_mmap{,_shared} is meaningless.
If you think about it, if ptrace accesses a page, then it's guaranteed to be mapped twice: once in user space, once by the kmap_atomic() for the kernel space access.
--
Manfred
Quoted 6 lines · Manfred Spraul
Quoted 5 lines
http://www.kernel.org/pub/linux/kernel/people/akpm/patches/2.5/2.5.62/2.5.62-mm3/broken-out/ptrace-flush.patch
but it's getting fixed I hope.This patch seems to be wrong.
Yes, it is wrong. I discussed it with davem a while back and he was planning on fixing it up for real. I just keep the patch floating about as a reminder that the thing which it doesn't fix needs fixing.
I'll update the changelog...