Skip to content

Commit ec6fd8a

Browse files
author
Al Viro
committed
report errors in /proc/*/*map* sanely
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent ca6b0bf commit ec6fd8a

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎fs/proc/base.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,17 @@ static int check_mem_permission(struct task_struct *task)
225225
struct mm_struct *mm_for_maps(struct task_struct *task)
226226
{
227227
struct mm_struct *mm;
228+
int err;
228229

229-
if (mutex_lock_killable(&task->signal->cred_guard_mutex))
230-
return NULL;
230+
err = mutex_lock_killable(&task->signal->cred_guard_mutex);
231+
if (err)
232+
return ERR_PTR(err);
231233

232234
mm = get_task_mm(task);
233235
if (mm && mm != current->mm &&
234236
!ptrace_may_access(task, PTRACE_MODE_READ)) {
235237
mmput(mm);
236-
mm = NULL;
238+
mm = ERR_PTR(-EACCES);
237239
}
238240
mutex_unlock(&task->signal->cred_guard_mutex);
239241

‎fs/proc/task_mmu.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ static void *m_start(struct seq_file *m, loff_t *pos)
119119

120120
priv->task = get_pid_task(priv->pid, PIDTYPE_PID);
121121
if (!priv->task)
122-
return NULL;
122+
return ERR_PTR(-ESRCH);
123123

124124
mm = mm_for_maps(priv->task);
125-
if (!mm)
126-
return NULL;
125+
if (!mm || IS_ERR(mm))
126+
return mm;
127127
down_read(&mm->mmap_sem);
128128

129129
tail_vma = get_gate_vma(priv->task);
@@ -728,9 +728,9 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
728728
if (!task)
729729
goto out;
730730

731-
ret = -EACCES;
732731
mm = mm_for_maps(task);
733-
if (!mm)
732+
ret = PTR_ERR(mm);
733+
if (!mm || IS_ERR(mm))
734734
goto out_task;
735735

736736
ret = -EINVAL;

‎fs/proc/task_nommu.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ static void *m_start(struct seq_file *m, loff_t *pos)
199199
/* pin the task and mm whilst we play with them */
200200
priv->task = get_pid_task(priv->pid, PIDTYPE_PID);
201201
if (!priv->task)
202-
return NULL;
202+
return ERR_PTR(-ESRCH);
203203

204204
mm = mm_for_maps(priv->task);
205-
if (!mm) {
205+
if (!mm || IS_ERR(mm)) {
206206
put_task_struct(priv->task);
207207
priv->task = NULL;
208-
return NULL;
208+
return mm;
209209
}
210210
down_read(&mm->mmap_sem);
211211

0 commit comments

Comments
 (0)