Re: Reading raw memory

2009-08-28 Thread Roland Smith
On Fri, Aug 28, 2009 at 08:43:26AM -0400, Steve Bertrand wrote:
 Hi all,
 
 I'm wondering if FreeBSD allows direct access to memory.

Yes, via /dev/(k)mem. Byte offsets in /dev/mem are interpreted as physical
memory adresses. See mem(4). Mind you that only root has access to this
device be default. Giving others even read access is a security problem.

Roland
-- 
R.F.Smith   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)


pgphUSojNDc1c.pgp
Description: PGP signature


Re: Reading raw memory

2009-08-28 Thread Dan Nelson
In the last episode (Aug 28), Steve Bertrand said:
 I'm wondering if FreeBSD allows direct access to memory.
 
 What I'd like to do is try to force a Perl application to leak memory by
 simulating a dangling pointer that it's garbage collection system can't
 clean up.
 
 I'd then like to look at the raw memory address to find out if the data is
 in a state where it could later be retrieved.

From within the perl process itself, it's easy.  Just read the memory
address directly.  From another process, you will need to use the ptrace()
function to attach to your target process as a debugger (PT_ATTACH).  Then
read its memory, using either PT_READ_D if you just want to read one int, or
PT_IO, which will let you copy an arbitrary block of memory.
 
 Is accessing memory like this permitted within the OS? If so, what type of
 editor would be used to do such a thing?  Perhaps a snip of C code that
 one could pass in the address as a parameter?

/usr/src/usr.bin/truss/syscalls.c has some examples of how to do this.  See
the get_struct() function.

-- 
Dan Nelson
dnel...@allantgroup.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org