Skip to contentSkip to conversation

ptrace PTRACE_READDATA/WRITEDATA, kernel 2.5.62

PATCH Manfred Spraul 3 participants 4 messages Feb 24, 2003 – Feb 25, 2003

lore
Share & tools
lore
#0 lore raw

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/mem instead. It works with no kernel modifications, and is just as fast.

I assume you mean /proc/<pid>/mem. Performance is identical, same implementation.

--
Manfred

#1 lore raw

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_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

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.

#2 lore raw
Quoted 3 lines · [email protected] wrote:

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.

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_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.

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