From: Greg Banks <gnb@melbourne.sgi.com>
To: Andrew Morton <akpm@osdl.org>
Cc: OProfile List <oprofile-list@lists.sourceforge.net>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH 1/11] oprofile: add check_user_page_readable()
Date: Tue, 09 Nov 2004 21:37:16 +1100 [thread overview]
Message-ID: <1099996636.1985.781.camel@hole.melbourne.sgi.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 95 bytes --]
--
Greg Banks, R&D Software Engineer, SGI Australian Software Group.
I don't speak for SGI.
[-- Attachment #2: check-user-page --]
[-- Type: text/plain, Size: 2343 bytes --]
Add check_user_page_readable() for kernel modules which need
to follow user space addresses but can't use get_user().
Signed-off-by: John Levon <levon@movementarian.org>
Signed-off-by: Greg Banks <gnb@melbourne.sgi.com>
---
include/linux/mm.h | 1 +
mm/memory.c | 20 ++++++++++++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)
Index: linux/include/linux/mm.h
===================================================================
--- linux.orig/include/linux/mm.h 2004-11-06 01:12:07.%N +1100
+++ linux/include/linux/mm.h 2004-11-07 17:59:40.%N +1100
@@ -789,6 +789,7 @@ extern struct page * vmalloc_to_page(voi
extern unsigned long vmalloc_to_pfn(void *addr);
extern struct page * follow_page(struct mm_struct *mm, unsigned long address,
int write);
+extern int check_user_page_readable(struct mm_struct *mm, unsigned long address);
int remap_pfn_range(struct vm_area_struct *, unsigned long,
unsigned long, unsigned long, pgprot_t);
Index: linux/mm/memory.c
===================================================================
--- linux.orig/mm/memory.c 2004-11-06 01:11:57.%N +1100
+++ linux/mm/memory.c 2004-11-07 17:59:40.%N +1100
@@ -746,8 +746,8 @@ void zap_page_range(struct vm_area_struc
* Do a quick page-table lookup for a single page.
* mm->page_table_lock must be held.
*/
-struct page *
-follow_page(struct mm_struct *mm, unsigned long address, int write)
+static struct page *
+__follow_page(struct mm_struct *mm, unsigned long address, int read, int write)
{
pml4_t *pml4;
pgd_t *pgd;
@@ -790,6 +790,8 @@ follow_page(struct mm_struct *mm, unsign
if (pte_present(pte)) {
if (write && !pte_write(pte))
goto out;
+ if (read && !pte_read(pte))
+ goto out;
pfn = pte_pfn(pte);
if (pfn_valid(pfn)) {
page = pfn_to_page(pfn);
@@ -804,6 +806,20 @@ out:
return NULL;
}
+struct page *
+follow_page(struct mm_struct *mm, unsigned long address, int write)
+{
+ return __follow_page(mm, address, /*read*/0, write);
+}
+
+int
+check_user_page_readable(struct mm_struct *mm, unsigned long address)
+{
+ return __follow_page(mm, address, /*read*/1, /*write*/0) != NULL;
+}
+
+EXPORT_SYMBOL(check_user_page_readable);
+
/*
* Given a physical address, is there a useful struct page pointing to
* it? This may become more complex in the future if we start dealing
next reply other threads:[~2004-11-09 10:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-11-09 10:37 Greg Banks [this message]
2004-11-09 11:04 ` Andrew Morton
2004-11-09 11:20 ` Greg Banks
2004-11-09 11:26 ` Andrew Morton
2004-11-09 11:52 ` Greg Banks
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1099996636.1985.781.camel@hole.melbourne.sgi.com \
--to=gnb@melbourne.sgi.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oprofile-list@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®