[Devel] fs/proc/base.c: fix GPF in /proc/$PID/map_files

Submitted by Stanislav Kinsburskiy on July 14, 2017, 4:25 p.m.

Details

Message ID 20170714162526.7713.38329.stgit@localhost.localdomain
State New
Series "fs/proc/base.c: fix GPF in /proc/$PID/map_files"
Headers show

Commit Message

Stanislav Kinsburskiy July 14, 2017, 4:25 p.m.
From: Artem Fetishev <artem_fetishev@epam.com>

The expected logic of proc_map_files_get_link() is either to return 0
and initialize 'path' or return an error and leave 'path' uninitialized.

By the time dname_to_vma_addr() returns 0 the corresponding vma may have
already be gone.  In this case the path is not initialized but the
return value is still 0.  This results in 'general protection fault'
inside d_path().

Steps to reproduce:

  CONFIG_CHECKPOINT_RESTORE=y

    fd = open(...);
    while (1) {
        mmap(fd, ...);
        munmap(fd, ...);
    }

  ls -la /proc/$PID/map_files

Addresses https://bugzilla.kernel.org/show_bug.cgi?id=68991

https://jira.sw.ru/browse/PSBM-68472

Signed-off-by: Artem Fetishev <artem_fetishev@epam.com>
Signed-off-by: Aleksandr Terekhov <aleksandr_terekhov@epam.com>
Reported-by: <wiebittewas@gmail.com>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Reviewed-by: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
---
 fs/proc/base.c |    1 +
 1 file changed, 1 insertion(+)

Patch hide | download patch | download mbox

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 0af670c..291e503 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2028,6 +2028,7 @@  static int proc_map_files_get_link(struct dentry *dentry, struct path *path)
 	if (rc)
 		goto out_mmput;
 
+	rc = -ENOENT;
 	down_read(&mm->mmap_sem);
 	vma = find_exact_vma(mm, vm_start, vm_end);
 	if (vma && vma->vm_file) {

Comments

Cyrill Gorcunov July 14, 2017, 4:29 p.m.
On Fri, Jul 14, 2017 at 08:25:35PM +0400, Stanislav Kinsburskiy wrote:
> From: Artem Fetishev <artem_fetishev@epam.com>
> 
> The expected logic of proc_map_files_get_link() is either to return 0
> and initialize 'path' or return an error and leave 'path' uninitialized.
> 
> By the time dname_to_vma_addr() returns 0 the corresponding vma may have
> already be gone.  In this case the path is not initialized but the
> return value is still 0.  This results in 'general protection fault'
> inside d_path().
> 
> Steps to reproduce:
> 
>   CONFIG_CHECKPOINT_RESTORE=y
> 
>     fd = open(...);
>     while (1) {
>         mmap(fd, ...);
>         munmap(fd, ...);
>     }
> 
>   ls -la /proc/$PID/map_files
> 
> Addresses https://bugzilla.kernel.org/show_bug.cgi?id=68991
> 
> https://jira.sw.ru/browse/PSBM-68472
> 
> Signed-off-by: Artem Fetishev <artem_fetishev@epam.com>
> Signed-off-by: Aleksandr Terekhov <aleksandr_terekhov@epam.com>
> Reported-by: <wiebittewas@gmail.com>
> Acked-by: Pavel Emelyanov <xemul@parallels.com>
> Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
> Reviewed-by: "Eric W. Biederman" <ebiederm@xmission.com>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>