2018-06-21 03:22:24

by Jia-Ju Bai

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

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

[FUNC] vfree --> can sleep
kernel/kcov.c, 237: vfree in kcov_put
kernel/kcov.c, 396: kcov_put in kcov_ioctl_locked
kernel/kcov.c, 410: kcov_ioctl_locked in kcov_ioctl
kernel/kcov.c, 409: spin_lock in kcov_ioctl

This bug is found by my static analysis tool (DSAC-2) and checked by my
code review.

I do not know how to correctly fix this bug, so I just report them.


Best wishes,
Jia-Ju Bai


2018-06-21 03:44:36

by Al Viro

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

On Thu, Jun 21, 2018 at 11:20:59AM +0800, Jia-Ju Bai wrote:
> The kernel may sleep with holding a spinlock.
> The function call path (from bottom to top) in Linux-4.16.7 is:
>
> [FUNC] vfree --> can sleep
> kernel/kcov.c, 237: vfree in kcov_put
> kernel/kcov.c, 396: kcov_put in kcov_ioctl_locked
> kernel/kcov.c, 410: kcov_ioctl_locked in kcov_ioctl
> kernel/kcov.c, 409: spin_lock in kcov_ioctl
>
> This bug is found by my static analysis tool (DSAC-2) and checked by my
> code review.
>
> I do not know how to correctly fix this bug, so I just report them.

Assuming it's a bug in the first place, that is. Note that
* we never modify task->kcov for task != current
* task->kcov contributes to refcount
* opened file contributes to refcount
* that kcov_put() of yours happens from ->ioctl() and removes
current->kcov reference; it *can't* be the last reference - the one
held by struct file used to call ->ioctl() is also there.

IOW, it's a false positive.

2018-06-21 03:52:16

by Jia-Ju Bai

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



On 2018/6/21 11:43, Al Viro wrote:
> On Thu, Jun 21, 2018 at 11:20:59AM +0800, Jia-Ju Bai wrote:
>> The kernel may sleep with holding a spinlock.
>> The function call path (from bottom to top) in Linux-4.16.7 is:
>>
>> [FUNC] vfree --> can sleep
>> kernel/kcov.c, 237: vfree in kcov_put
>> kernel/kcov.c, 396: kcov_put in kcov_ioctl_locked
>> kernel/kcov.c, 410: kcov_ioctl_locked in kcov_ioctl
>> kernel/kcov.c, 409: spin_lock in kcov_ioctl
>>
>> This bug is found by my static analysis tool (DSAC-2) and checked by my
>> code review.
>>
>> I do not know how to correctly fix this bug, so I just report them.
> Assuming it's a bug in the first place, that is. Note that
> * we never modify task->kcov for task != current
> * task->kcov contributes to refcount
> * opened file contributes to refcount
> * that kcov_put() of yours happens from ->ioctl() and removes
> current->kcov reference; it *can't* be the last reference - the one
> held by struct file used to call ->ioctl() is also there.
>
> IOW, it's a false positive.

Okay, thanks for your reply and explanation.
I agree that my report is false.


Best wishes,
Jia-Ju Bai