Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Only intercept mprotect(2) syscall
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Henrik Faber  
View profile  
 More options Nov 5, 6:50 pm
Newsgroups: comp.os.linux.development.system
From: Henrik Faber <hfa...@invalid.net>
Date: Thu, 05 Nov 2009 08:50:01 +0100
Local: Thurs, Nov 5 2009 6:50 pm
Subject: Only intercept mprotect(2) syscall
Dear group,

I'd like to do the following: Trap all read/write access to a page in
memory (e.g., for logging purposes), but do not deny them. When I use
mprotect() on a certain location, I can intercept the read/write, but
(as the page is obviously protected) the read/write is not actually
performed. I'd like my handler to be called right prior to any read and
any write, but without changing the results.

I find it hard to explain (English is not my native language), so maybe
the solution I have though of (but find incredibly ugly) helps:

1. Install sighandler for SIGSEGV
2. mprotect() the region in question
3. Upon SIGSEGV, log, reverse mprotect, set flag that memory is unprotected
4. Change return value on stack so that the instuction which led to the
SIGSEGV is executed again (and will work this time). Also patch code so
that instructed executed after the trapped instruction is replaced by int3
5. Upon SIGSEGV (because of int3), install mprotect again, set flag that
memory is protected, patch code back to original instruction, again
change return value so that the last instruction is executed

This should work - but it's horrible. And really lots of work. What I
would like much more is something like a flag that I could pass to
mprotect (all pseudocode following)

mprotect(my_region, 4096, PROT_INTERCEPT);

void intercepthandler(int signal, void *magic) {
        struct magicmprotstruct *m = (struct magicmprotstruct *)magic;
        printf("There was a %d byte %s on addr %x with value %x\n",
                magic->opsize,
                magic->read ? "read" : write,
                magic->addr,
                magic->value);

}

Is there any way I can achieve this (or something like this) without
going through the whole trouble I described above?

Regards,
Henrik


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris McDonald  
View profile  
 More options Nov 5, 6:57 pm
Newsgroups: comp.os.linux.development.system
From: Chris McDonald <ch...@csse.uwa.edu.au>
Date: Thu, 5 Nov 2009 07:57:36 +0000 (UTC)
Local: Thurs, Nov 5 2009 6:57 pm
Subject: Re: Only intercept mprotect(2) syscall

Henrik Faber <hfa...@invalid.net> writes:
>I'd like to do the following: Trap all read/write access to a page in
>memory (e.g., for logging purposes), but do not deny them. When I use
>mprotect() on a certain location, I can intercept the read/write, but
>(as the page is obviously protected) the read/write is not actually
>performed. I'd like my handler to be called right prior to any read and
>any write, but without changing the results.

Not my field of expertise, at all, but could you mirror the page being
watched with another page,  trap all reads and writes to the watched page,
and then perform the requested operations on your own page?

--
Chris.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vitus Jensen  
View profile  
 More options Nov 19, 1:34 am
Newsgroups: comp.os.linux.development.system
From: Vitus Jensen <vi...@alter-schwede.de>
Date: Wed, 18 Nov 2009 15:34:26 +0100
Local: Thurs, Nov 19 2009 1:34 am
Subject: Re: Only intercept mprotect(2) syscall
Hi Henrik,

On Thu, 5 Nov 2009, Henrik Faber wrote:
> I'd like to do the following: Trap all read/write access to a page in memory
> (e.g., for logging purposes), but do not deny them. When I use mprotect() on
> a certain location, I can intercept the read/write, but (as the page is
> obviously protected) the read/write is not actually performed. I'd like my
> handler to be called right prior to any read and any write, but without
> changing the results.

> I find it hard to explain (English is not my native language), so maybe the
> solution I have though of (but find incredibly ugly) helps:

> 1. Install sighandler for SIGSEGV
> 2. mprotect() the region in question
> 3. Upon SIGSEGV, log, reverse mprotect, set flag that memory is unprotected

What about

4. analyse the interrupted instruction and do the memory access yourself
from inside the SIGSEGV handler
5. install mprotect again
6. continue

The hard part is the disassembling.  But your design has the same problem.

Vitus

--
Vitus Jensen, Hannover, Germany, Earth, Universe (current)


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google