Skip to contentSkip to conversation

kcov: detect double association with a single task

PATCH New [email protected] 1 participant 1 message Feb 6, 2018 KCOV

lore
Share & tools
lore
#0 lore raw

PATCH 76/114 kcov: detect double association with a single task

From: Dmitry Vyukov <[email protected]>
Subject: kcov: detect double association with a single task

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 5c9a8750a640 ("kernel: add kcov code coverage")
Cc Dmitry Vyukov <[email protected]>
Cc syzbot <[email protected]>

---

 kernel/kcov.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kcov.c renamed from kernel/kcov.c~kcov-detect-double-association-with-a-single-task +2 -2
diff -puN kernel/kcov.c~kcov-detect-double-association-with-a-single-task kernel/kcov.c
@@ -358,7 +358,8 @@ static int kcov_ioctl_locked(struct kcov
 		 */
 		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
 #endif
 		else
 			return -EINVAL;
-		t = current;
 		/* Cache in task struct for performance. */
 		t->kcov_size = kcov->size;
 		t->kcov_area = kcov->area;

_