Commit 4249e8af authored by Dmitry Vyukov's avatar Dmitry Vyukov Committed by Greg Kroah-Hartman

kcov: detect double association with a single task

commit a77660d2 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.

Fixes: 5c9a8750 ("kernel: add kcov code coverage")
Signed-off-by: default avatarDmitry Vyukov <>
Reported-by: default avatarShankara Pailoor <>
Cc: Dmitry Vyukov <>
Cc: syzbot <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent 7b5ec550
......@@ -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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment