lkml.org 
[lkml]   [1998]   [Feb]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: How to read-protect a vm_area?
Date
Hmmm... let me see.  Would like to generate a page fault on reading a page 
or writing a page?

Case A: You want a page fault on write

I ran into this problem implementing distributed shared memory. I needed
to know when a process wrote to memory so it could synchronize with its
remote half. To accomplish this, I used sys_mprotect and a hacked version
of change_protection() to clear the _PROT_READ bit on all pte's in a vm
area. But there's a catch: if a page is read-only, do_wp_page() gets
called on a page fault and silently makes the page writeable. I had to add
my own hook to vm->vm_ops->wppage() there to catch the write fault.

Case B: you want a page fault on read

Wouldn't you rather just swap this memory out and handle nopage()?

Let's say you wouldn't. I believe that sys_mprotect will happily clear the
read bit on your pte's. However, if you look at do_page_fault(), you will
notice that a read fault always generates SIGSEGV if the page is present.
You will have to change that, if that's really what you want.

Prerequisites: pte? fault? what?

You need to get a good understanding of how vm_area_structs, pgd_t, pmd_t,
and pte_t's work. I used the following sources:

"Linux Kernel Internals" by Bohm et. al. A great overview of the linux
kernel and memory

http://www.intel.com/design/pentiumii/manuals/. Details of ix86 virtual
memory management

running emacs and etags on my kernel. (2.0.32)

Let me know how it goes. If you have more info on your project, send it
along.

Good luck.

--Noel


-----Original Message-----
From: mshar@vax.ipm.ac.ir [SMTP:mshar@vax.ipm.ac.ir]
Sent: Wednesday, February 11, 1998 5:54 AM
To: linux-kernel@vger.rutgers.edu
Subject: How to read-protect a vm_area?

Hi,

Could someone please tell me how to read-protect a vm_area? I copied the
mprotect_fixup() routine and the functions it calls, and changed them so
they accept an additional mm_struct pointer (to be used instead of
"current->mm"), and then tried to read-protect a shared memory segment
with it. As the protection flag, I &'d shm_vm_area->vm_flags with
~(PROT_READ | PROT_WRITE), and in another try with
~(PROT_READ | PROT_WRITE | PROT_EXEC).

It didn't work: The shared memory segment remained readable.

-Kamran Karimi
PS- The mprotect_fixup() was taken from a 2.1.49 kernel's mm/mprotect.c
file.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu

\
 
 \ /
  Last update: 2005-03-22 13:41    [W:0.196 / U:0.196 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site