]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
kcov: detect double association with a single task
authorDmitry Vyukov <dvyukov@google.com>
Tue, 6 Feb 2018 23:40:28 +0000 (15:40 -0800)
committerSeth Forshee <seth.forshee@canonical.com>
Wed, 28 Feb 2018 14:46:36 +0000 (08:46 -0600)
BugLink: http://bugs.launchpad.net/bugs/1752119
commit a77660d231f8b3d84fd23ed482e0964f7aa546d6 upstream.

Currently KCOV_ENABLE does not check if the current task is already
associated with another kcov descriptor.  As the result it is possible
to associate a single task with more than one kcov descriptor, which
later leads to a memory leak of the old descriptor.  This relation is
really meant to be one-to-one (task has only one back link).

Extend validation to detect such misuse.

Link: http://lkml.kernel.org/r/20180122082520.15716-1-dvyukov@google.com
Fixes: 5c9a8750a640 ("kernel: add kcov code coverage")
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Reported-by: Shankara Pailoor <sp3485@columbia.edu>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
kernel/kcov.c

index 7594c033d98a39f3f51632a8f6f77b4440079ec4..2c16f1ab5e107562a8f9ade9735d97d0277931fd 100644 (file)
@@ -358,7 +358,8 @@ static int kcov_ioctl_locked(struct kcov *kcov, unsigned int cmd,
                 */
                if (kcov->mode != KCOV_MODE_INIT || !kcov->area)
                        return -EINVAL;
-               if (kcov->t != NULL)
+               t = current;
+               if (kcov->t != NULL || t->kcov != NULL)
                        return -EBUSY;
                if (arg == KCOV_TRACE_PC)
                        kcov->mode = KCOV_MODE_TRACE_PC;
@@ -370,7 +371,6 @@ static int kcov_ioctl_locked(struct kcov *kcov, unsigned int cmd,
 #endif
                else
                        return -EINVAL;
-               t = current;
                /* Cache in task struct for performance. */
                t->kcov_size = kcov->size;
                t->kcov_area = kcov->area;