Re: Problem doing a read...

Michael J. Greger (greger@f182-085.net.wisc.edu)
Sun, 4 Aug 1996 21:46:22 -0500 (CDT)


On Sun, 4 Aug 1996, Albert Cahalan wrote:

> From: "Michael J. Greger" <greger@f182-137.net.wisc.edu>
>
> > Under 2.0.4, I have a program that gives the following under /proc/pid/maps:
> >
> > 0x8048000 0x8054000 r-xp 0x0 16:1 368915
> > 0x8054000 0x8055000 rw-p 0xb000 16:1 368915
> > 0x8055000 0x8069000 rwxp 0x0 0:0 0
> > 0x40000000 0x40005000 rwxp 0x0 16:1 16473
> > 0x40005000 0x40006000 rw-p 0x4000 16:1 16473
> > 0x40006000 0x40009000 rw-p 0x0 0:0 0 ****
> > 0x40009000 0x40082000 r-xp 0x0 16:1 16419
> > 0x40082000 0x40088000 rw-p 0x78000 16:1 16419
> > 0x40088000 0x400ba000 rw-p 0x0 0:0 0
> > 0xbfffc000 0xc0000000 rwxp 0xffffd000 0:0 0
> >
> > I'm tring to read the segment of memory marked above with the ***'s.
> > When I read to about 0x40008000, I get a segfault. According to the
> > protection bits, I should have read access. Well, why do I get a segfault??
>
> Which reminds me... Those numbers are ranges, right?
> I think I see an off-by-one error. Shouldn't that be:
>
> 0x08048000 0x08053fff r-xp 0x00000000 16:1 368915
> 0x08054000 0x08054fff rw-p 0x0000b000 16:1 368915
> 0x08055000 0x08068fff rwxp 0x00000000 0:0 0
> 0x40000000 0x40004fff rwxp 0x00000000 16:1 16473
> 0x40005000 0x40005fff rw-p 0x00004000 16:1 16473
> 0x40006000 0x40008fff rw-p 0x00000000 0:0 0
> 0x40009000 0x40081fff r-xp 0x00000000 16:1 16419
> 0x40082000 0x40087fff rw-p 0x00078000 16:1 16419
> 0x40088000 0x400b9fff rw-p 0x00000000 0:0 0
> 0xbfffc000 0xbfffffff rwxp 0xffffd000 0:0 0
>
Yeah, I agree with that, the problem is that I still can't read the
entire range... The last few pages of some of the maps are just not
readable... I just stuck a hack into the code for now. It calls
mprotect trying to modify the protection and decreases the ending address
until it works.

For now, the hack works fine, but I really would like to figure this one
out if possible. I looked at ld.so and the mmap stuff in the kernel. So
far, I don't see any problems in either place.

If anyone can figure this out or even verify that it happens on their
system, I'm certainly interested. I'd like to clean my code up a bit...

Thanks,
Mike