From: Jean-Marc Saffroy <saffroy@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH] return useful error when accessing /proc/<pid>/maps
Date: Sun, 17 Feb 2008 18:02:07 +0100 (CET) [thread overview]
Message-ID: <Pine.LNX.4.64.0802171735470.5339@erda.mds> (raw)
Hello folks,
Access to /proc/<pid>/maps is now restricted to legitimate users, but
read(2) simply returns 0 instead of a more explicit error. The patch below
fixes this.
Signed-off-by: Jean-Marc Saffroy <saffroy@gmail.com>
---
Index: linux-2.6.24.2/fs/proc/base.c
===================================================================
--- linux-2.6.24.2.orig/fs/proc/base.c 2008-02-17 16:43:49.000000000 +0100
+++ linux-2.6.24.2/fs/proc/base.c 2008-02-17 17:18:13.000000000 +0100
@@ -204,6 +204,7 @@
struct mm_struct *mm_for_maps(struct task_struct *task)
{
+ int rc = 0;
struct mm_struct *mm = get_task_mm(task);
if (!mm)
return NULL;
@@ -211,7 +212,7 @@
task_lock(task);
if (task->mm != mm)
goto out;
- if (task->mm != current->mm && __ptrace_may_attach(task) < 0)
+ if (task->mm != current->mm && (rc = __ptrace_may_attach(task)) < 0)
goto out;
task_unlock(task);
return mm;
@@ -219,7 +220,7 @@
task_unlock(task);
up_read(&mm->mmap_sem);
mmput(mm);
- return NULL;
+ return rc ? ERR_PTR(rc) : NULL;
}
static int proc_pid_cmdline(struct task_struct *task, char * buffer)
Index: linux-2.6.24.2/fs/proc/task_mmu.c
===================================================================
--- linux-2.6.24.2.orig/fs/proc/task_mmu.c 2008-02-17 16:43:49.000000000 +0100
+++ linux-2.6.24.2/fs/proc/task_mmu.c 2008-02-17 17:27:55.000000000 +0100
@@ -398,8 +398,8 @@
return NULL;
mm = mm_for_maps(priv->task);
- if (!mm)
- return NULL;
+ if (!mm || IS_ERR(mm))
+ return mm;
priv->tail_vma = tail_vma = get_gate_vma(priv->task);
@@ -437,7 +437,7 @@
static void vma_stop(struct proc_maps_private *priv, struct vm_area_struct *vma)
{
- if (vma && vma != priv->tail_vma) {
+ if (vma && !IS_ERR(vma) && vma != priv->tail_vma) {
struct mm_struct *mm = vma->vm_mm;
up_read(&mm->mmap_sem);
mmput(mm);
Index: linux-2.6.24.2/fs/proc/task_nommu.c
===================================================================
--- linux-2.6.24.2.orig/fs/proc/task_nommu.c 2008-02-17 16:43:49.000000000 +0100
+++ linux-2.6.24.2/fs/proc/task_nommu.c 2008-02-17 17:18:13.000000000 +0100
@@ -166,10 +166,10 @@
return NULL;
mm = mm_for_maps(priv->task);
- if (!mm) {
+ if (!mm || IS_ERR(mm)) {
put_task_struct(priv->task);
priv->task = NULL;
- return NULL;
+ return mm;
}
/* start from the Nth VMA */
reply other threads:[~2008-02-17 17:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=Pine.LNX.4.64.0802171735470.5339@erda.mds \
--to=saffroy@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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®