From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Hans Liljestrand <ishkamiel@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
Andrea Parri <andrea.parri@amarulasolutions.com>,
Anders Roxell <anders.roxell@linaro.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Reshetova, Elena" <elena.reshetova@intel.com>,
Andrey Konovalov <andreyknvl@google.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [BUG] kernel: kcov: a possible sleep-in-atomic-context bug in kcov_ioctl()
Date: Tue, 17 Dec 2019 21:17:19 +0800 [thread overview]
Message-ID: <bc4569a3-19f8-ca5f-7e59-29bacdbc7955@gmail.com> (raw)
In-Reply-To: <CACT4Y+YLxmFTkDT88z9y5yH75bAi42-Hqatv9z2-EyufTtKHRw@mail.gmail.com>
On 2019/12/17 21:13, Dmitry Vyukov wrote:
> On Tue, Dec 17, 2019 at 2:11 PM Jia-Ju Bai <baijiaju1990@gmail.com> wrote:
>> On 2019/12/17 21:02, Dmitry Vyukov wrote:
>>> On Tue, Dec 17, 2019 at 1:56 PM Jia-Ju Bai <baijiaju1990@gmail.com> wrote:
>>>> 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.
>>> Hi Jia-Ju,
>>>
>>> Are you sure kcov_ioctl_locked can really release the descriptor? It
>>> happens in the context of ioctl, which means there is an open
>>> reference for the file descriptor. So ioctl should not do vfree I
>>> would assume.
>> Thanks for the reply :)
>> I am not sure, because I am not familiar with kcov.
>> But looking at the code, if the reference count of kcov is 1, vfree()
>> could be called.
> That kcov_put should never call vfree. We still hold reference
> associated with the file, which will be released in kcov_close.
Okay, thanks for the explanation :)
My static analysis tool does not know this fact, so it reports the false
bug, sorry...
Best wishes,
Jia-Ju Bai
next prev parent reply other threads:[~2019-12-17 13:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-17 12:56 Jia-Ju Bai
2019-12-17 13:02 ` Dmitry Vyukov
2019-12-17 13:11 ` Jia-Ju Bai
2019-12-17 13:13 ` Dmitry Vyukov
2019-12-17 13:17 ` Jia-Ju Bai [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-06-21 3:20 Jia-Ju Bai
2018-06-21 3:43 ` Al Viro
2018-06-21 3:50 ` Jia-Ju Bai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bc4569a3-19f8-ca5f-7e59-29bacdbc7955@gmail.com \
--to=baijiaju1990@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=anders.roxell@linaro.org \
--cc=andrea.parri@amarulasolutions.com \
--cc=andreyknvl@google.com \
--cc=dvyukov@google.com \
--cc=elena.reshetova@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=ishkamiel@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome