[PATCH] return useful error when accessing /proc/<pid>/maps

From: Jean-Marc Saffroy
Date: Sun Feb 17 2008 - 12:15:31 EST


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@xxxxxxxxx>

---

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 */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/