[BUG] kernel: kcov: a possible sleep-in-atomic-context bug in kcov_ioctl()

From: Jia-Ju Bai
Date: Tue Dec 17 2019 - 07:56:58 EST


The kernel may sleep while holding a spinlock.
The function call path (from bottom to top) in Linux 4.19 is:

kernel/kcov.c, 237:
ÂÂÂ vfree in kcov_put
kernel/kcov.c, 413:
ÂÂÂ kcov_put in kcov_ioctl_locked
kernel/kcov.c, 427:
ÂÂÂ kcov_ioctl_locked in kcov_ioctl
kernel/kcov.c, 426:
ÂÂÂ spin_lock in kcov_ioctl

vfree() can sleep at runtime.

I am not sure how to properly fix this possible bug, so I only report it.
A possible way is to replace vfree() with kfree(), and replace related calls to vmalloc() with kmalloc().

This bug is found by a static analysis tool STCheck written by myself.


Best wishes,
Jia-Ju Bai