summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-02-06 15:40:28 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-02-25 11:07:50 +0100
commit4249e8af8108afadc6316d9e4815f3333c9770d0 (patch)
tree41cb9bbada830d7d4dd19c007386a72797b68ad3
parent7b5ec5505945ee2ba6f6dbab51483a1102720623 (diff)
downloadlinux-stable-4249e8af8108afadc6316d9e4815f3333c9770d0.tar.gz
linux-stable-4249e8af8108afadc6316d9e4815f3333c9770d0.tar.bz2
linux-stable-4249e8af8108afadc6316d9e4815f3333c9770d0.zip
kcov: detect double association with a single task
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>
-rw-r--r--kernel/kcov.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/kernel/kcov.c b/kernel/kcov.c
index fc6af9e1308b..b11ef6e51f7e 100644
--- a/kernel/kcov.c
+++ b/kernel/kcov.c
@@ -225,9 +225,9 @@ static int kcov_ioctl_locked(struct kcov *kcov, unsigned int cmd,
if (unused != 0 || kcov->mode == KCOV_MODE_DISABLED ||
kcov->area == NULL)
return -EINVAL;
- if (kcov->t != NULL)
- return -EBUSY;
t = current;
+ if (kcov->t != NULL || t->kcov != NULL)
+ return -EBUSY;
/* Cache in task struct for performance. */
t->kcov_size = kcov->size;
t->kcov_area = kcov->area;