Bug 65357

Summary: (VM)If ptrace() modifes a page, the child program can as well.
Product: [Retired] Red Hat Linux Reporter: Tom Horsley <horsley1953>
Component: kernelAssignee: Arjan van de Ven <arjanv>
Status: CLOSED CURRENTRELEASE QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1   
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-09-30 15:39:37 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Tom Horsley 2002-05-22 17:56:19 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0; T312461)

Description of problem:
If you are debugging a program and modify read only pages (by setting
a breakpoint, for example), then the modified pages are now writable
by the user process being debugged as well.

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1. Compile attached bug.c program (with -g)
2. Run it and watch it segfault
3. Now run gdb on the program.
4. Set a breakpoint at *&main
5. Let the program run to the breakpoint, then continue it.
6. Watch the program run with no errors and overwrite &main.	

Actual Results:  Program does not segfault.

Expected Results:  Program should segfault. Just because it is running under
the debugger, read/execute pages should not become writable.

By the way: The /proc address map info still shows the page
as read/execute even though it really is writable after you
set the breakpoint.


Additional info:

Here is the bug.c source code (its small):

  #include <stdio.h>

  int
  main(int argc, char ** argv) {
     int * mainprog = ((int *)(void *)&main);
     printf("Main program starts at %#x\n", mainprog);
     printf("First word looks like 0x%08x\n", *mainprog);
     printf("About to try writing on it...\n");
     fflush(stdout);
     *mainprog = 0xdeadbeef;
     printf("First word now looks like 0x%08x\n", *mainprog);
     fflush(stdout);
     return 0;
  }

Comment 1 Arjan van de Ven 2002-05-22 18:30:59 UTC
Since ptrace changes quite a bit per kernel version, could you specify which
kernel version(s) you have tested ?

Comment 2 Tom Horsley 2002-05-22 18:49:46 UTC
I tried several different linux systems, and it failed on all of
them (including a 2.4.18 kernel we have some custom mods in).
The redhat 7.1 system it failed on first is running 2.4.9-21.


Comment 3 Bugzilla owner 2004-09-30 15:39:37 UTC
Thanks for the bug report. However, Red Hat no longer maintains this version of
the product. Please upgrade to the latest version and open a new bug if the problem
persists.

The Fedora Legacy project (http://fedoralegacy.org/) maintains some older releases, 
and if you believe this bug is interesting to them, please report the problem in
the bug tracker at: http://bugzilla.fedora.us/