Skip to content

Commit

Permalink
Remove broken ptrace() special-case code from file mapping
Browse files Browse the repository at this point in the history
The kernel has for random historical reasons allowed ptrace() accesses
to access (and insert) pages into the page cache above the size of the
file.

However, Nick broke that by mistake when doing the new fault handling in
commit 54cb882 ("mm: merge populate and
nopage into fault (fixes nonlinear)".  The breakage caused a hang with
gdb when trying to access the invalid page.

The ptrace "feature" really isn't worth resurrecting, since it really is
wrong both from a portability _and_ from an internal page cache validity
standpoint.  So this removes those old broken remnants, and fixes the
ptrace() hang in the process.

Noticed and bisected by Duane Griffin, who also supplied a test-case
(quoth Nick: "Well that's probably the best bug report I've ever had,
thanks Duane!").

Cc: Duane Griffin <duaneg@dghda.com>
Acked-by: Nick Piggin <npiggin@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Linus Torvalds committed Oct 31, 2007
1 parent bb374b7 commit 5307cc1
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)

size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
if (vmf->pgoff >= size)
goto outside_data_content;
return VM_FAULT_SIGBUS;

/* If we don't want any read-ahead, don't bother */
if (VM_RandomReadHint(vma))
Expand Down Expand Up @@ -1377,7 +1377,7 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
if (unlikely(vmf->pgoff >= size)) {
unlock_page(page);
page_cache_release(page);
goto outside_data_content;
return VM_FAULT_SIGBUS;
}

/*
Expand All @@ -1388,15 +1388,6 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
vmf->page = page;
return ret | VM_FAULT_LOCKED;

outside_data_content:
/*
* An external ptracer can access pages that normally aren't
* accessible..
*/
if (vma->vm_mm == current->mm)
return VM_FAULT_SIGBUS;

/* Fall through to the non-read-ahead case */
no_cached_page:
/*
* We're only likely to ever get here if MADV_RANDOM is in
Expand Down

0 comments on commit 5307cc1

Please sign in to comment.