return useful error when accessing /proc/<pid>/maps
Subsystems (2)
PATCH 1/1 return useful error when accessing /proc/<pid>/maps
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 <[email protected]>
---
fs/proc/base.c +3 -2
@@ -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)
fs/proc/task_mmu.c +3 -3
@@ -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);
fs/proc/task_nommu.c +2 -2
@@ -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 */