The patch titled Subject: fs/proc/task_mmu.c: shift mm_access() from m_start() to proc_maps_open() has been added to the -mm tree. Its filename is fs-proc-task_mmuc-shift-mm_access-from-m_start-to-proc_maps_open.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/fs-proc-task_mmuc-shift-mm_access-from-m_start-to-proc_maps_open.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/fs-proc-task_mmuc-shift-mm_access-from-m_start-to-proc_maps_open.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Oleg Nesterov <oleg@xxxxxxxxxx> Subject: fs/proc/task_mmu.c: shift mm_access() from m_start() to proc_maps_open() A simple test-case from Kirill Shutemov cat /proc/self/maps >/dev/null chmod +x /proc/self/net/packet exec /proc/self/net/packet makes lockdep unhappy, cat/exec take seq_file->lock + cred_guard_mutex in the opposite order. It's a false positive and probably we should not allow "chmod +x" on proc files. Still I think that we should avoid mm_access() and cred_guard_mutex in sys_read() paths, security checking should happen at open time. Besides, this doesn't even look right if the task changes its ->mm between m_stop() and m_start(). Add the new "mm_struct *mm" member into struct proc_maps_private and change proc_maps_open() to initialize it using proc_mem_open(). Change m_start() to use priv->mm if atomic_inc_not_zero(mm_users) succeeds or return NULL (eof) otherwise. The only complication is that proc_maps_open() users should additionally do mmdrop() in fop->release(), add the new proc_map_release() helper for that. Note: this is the user-visible change, if the task execs after open("maps") the new ->mm won't be visible via this file. I hope this is fine, and this matches /proc/pid/mem bahaviour. Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx> Reported-by: "Kirill A. Shutemov" <kirill@xxxxxxxxxxxxx> Acked-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> Acked-by: Cyrill Gorcunov <gorcunov@xxxxxxxxxx> Cc: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- fs/proc/internal.h | 1 + fs/proc/task_mmu.c | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) diff -puN fs/proc/internal.h~fs-proc-task_mmuc-shift-mm_access-from-m_start-to-proc_maps_open fs/proc/internal.h --- a/fs/proc/internal.h~fs-proc-task_mmuc-shift-mm_access-from-m_start-to-proc_maps_open +++ a/fs/proc/internal.h @@ -270,6 +270,7 @@ extern int proc_remount(struct super_blo struct proc_maps_private { struct pid *pid; struct task_struct *task; + struct mm_struct *mm; #ifdef CONFIG_MMU struct vm_area_struct *tail_vma; #endif diff -puN fs/proc/task_mmu.c~fs-proc-task_mmuc-shift-mm_access-from-m_start-to-proc_maps_open fs/proc/task_mmu.c --- a/fs/proc/task_mmu.c~fs-proc-task_mmuc-shift-mm_access-from-m_start-to-proc_maps_open +++ a/fs/proc/task_mmu.c @@ -165,9 +165,9 @@ static void *m_start(struct seq_file *m, if (!priv->task) return ERR_PTR(-ESRCH); - mm = mm_access(priv->task, PTRACE_MODE_READ); - if (!mm || IS_ERR(mm)) - return mm; + mm = priv->mm; + if (!mm || !atomic_inc_not_zero(&mm->mm_users)) + return NULL; down_read(&mm->mmap_sem); tail_vma = get_gate_vma(mm); @@ -240,9 +240,28 @@ static int proc_maps_open(struct inode * return -ENOMEM; priv->pid = proc_pid(inode); + priv->mm = proc_mem_open(inode, PTRACE_MODE_READ); + if (IS_ERR(priv->mm)) { + int err = PTR_ERR(priv->mm); + seq_release_private(inode, file); + return err; + } + return 0; } +static int proc_map_release(struct inode *inode, struct file *file) +{ + struct seq_file *seq = file->private_data; + struct proc_maps_private *priv = seq->private; + + if (priv->mm) + mmdrop(priv->mm); + + return seq_release_private(inode, file); +} + + static int do_maps_open(struct inode *inode, struct file *file, const struct seq_operations *ops) { @@ -398,14 +417,14 @@ const struct file_operations proc_pid_ma .open = pid_maps_open, .read = seq_read, .llseek = seq_lseek, - .release = seq_release_private, + .release = proc_map_release, }; const struct file_operations proc_tid_maps_operations = { .open = tid_maps_open, .read = seq_read, .llseek = seq_lseek, - .release = seq_release_private, + .release = proc_map_release, }; /* @@ -680,14 +699,14 @@ const struct file_operations proc_pid_sm .open = pid_smaps_open, .read = seq_read, .llseek = seq_lseek, - .release = seq_release_private, + .release = proc_map_release, }; const struct file_operations proc_tid_smaps_operations = { .open = tid_smaps_open, .read = seq_read, .llseek = seq_lseek, - .release = seq_release_private, + .release = proc_map_release, }; /* @@ -1535,13 +1554,13 @@ const struct file_operations proc_pid_nu .open = pid_numa_maps_open, .read = seq_read, .llseek = seq_lseek, - .release = seq_release_private, + .release = proc_map_release, }; const struct file_operations proc_tid_numa_maps_operations = { .open = tid_numa_maps_open, .read = seq_read, .llseek = seq_lseek, - .release = seq_release_private, + .release = proc_map_release, }; #endif /* CONFIG_NUMA */ _ Patches currently in -mm which might be from oleg@xxxxxxxxxx are origin.patch earlyprintk-re-enable-earlyprintk-calling-early_param.patch fs-proc-task_mmuc-dont-use-task-mm-in-m_start-and-show_map.patch fs-proc-task_mmuc-unify-simplify-do_maps_open-and-numa_maps_open.patch proc-introduce-proc_mem_open.patch fs-proc-task_mmuc-shift-mm_access-from-m_start-to-proc_maps_open.patch fs-proc-task_mmuc-simplify-the-vma_stop-logic.patch fs-proc-task_mmuc-cleanup-the-tail_vma-horror-in-m_next.patch fs-proc-task_mmuc-shift-priv-task-=-null-from-m_start-to-m_stop.patch fs-proc-task_mmuc-kill-the-suboptimal-and-confusing-m-version-logic.patch fs-proc-task_mmuc-simplify-m_start-to-make-it-readable.patch fs-proc-task_mmuc-introduce-m_next_vma-helper.patch fs-proc-task_mmuc-reintroduce-m-version-logic.patch fs-proc-task_mmuc-update-m-version-in-the-main-loop-in-m_start.patch fs-proc-task_nommuc-change-maps_open-to-use-__seq_open_private.patch fs-proc-task_nommuc-shift-mm_access-from-m_start-to-proc_maps_open.patch fs-proc-task_nommuc-dont-use-priv-task-mm.patch linux-next.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html