From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: starmiku1207184332@gmail.com
Cc: rydberg@bitmath.org, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drivers: input: input: Fix possible sleep-in-atomic bug in input_alloc_absinfo()
Date: Mon, 1 May 2023 18:03:52 -0700 [thread overview]
Message-ID: <ZFBheCRW5fbzVK1V@google.com> (raw)
In-Reply-To: <20230425074951.1042694-1-starmiku1207184332@gmail.com>
Hi Teng Qi,
On Tue, Apr 25, 2023 at 07:49:51AM +0000, starmiku1207184332@gmail.com wrote:
> From: Teng Qi <starmiku1207184332@gmail.com>
>
> input_alloc_absinfo() may cause the kernel to sleep by calling kcalloc() with
> the GFP_KERNEL flag. It may be called by input_event() holding spinlock through
> the following call path:
>
> input_event(), 433
> input_handle_event(), 399
> input_get_disposition(), 294
> input_handle_abs_event(), 232
> input_abs_set_val(), Clang suggests it calls input_alloc_absinfo()
> unconditionally
> input_alloc_absinfo(), 483
> kcalloc(..., GFP_KERNEL)
>
> This call path can potentially trigger a sleep-in-atomic bug. To prevent this
> potential bug, we modify input_alloc_absinfo() to use the GFP_ATOMIC flag
> instead of the GFP_KERNEL flag.
This can not happen in practice, and changing the allocation type to
GFP_ATOMIC hurts the other code. We can avoid the issue by not using the
helper and have input core access the slot info directly. I CCed you on
a patch doing so.
> The possible bug is detected by a static code analysis tool.
>
> Signed-off-by: Teng Qi <starmiku1207184332@gmail.com>
> ---
> drivers/input/input.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index 37e876d45eb9..eefc4c85a693 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -480,7 +480,7 @@ void input_alloc_absinfo(struct input_dev *dev)
> if (dev->absinfo)
> return;
>
> - dev->absinfo = kcalloc(ABS_CNT, sizeof(*dev->absinfo), GFP_KERNEL);
> + dev->absinfo = kcalloc(ABS_CNT, sizeof(*dev->absinfo), GFP_ATOMIC);
> if (!dev->absinfo) {
> dev_err(dev->dev.parent ?: &dev->dev,
> "%s: unable to allocate memory\n", __func__);
> --
> 2.25.1
>
Thanks.
--
Dmitry
next prev parent reply other threads:[~2023-05-02 1:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-25 7:49 [PATCH] drivers: input: input: Fix possible sleep-in-atomic bug in input_alloc_absinfo() starmiku1207184332
2023-05-02 1:03 ` Dmitry Torokhov [this message]
[not found] ` <CALyQVay-_StW8ZghzF0DUp75UFZvssh-RcPC-DvHPgFLt0np=w@mail.gmail.com>
2023-05-08 15:01 ` Dmitry Torokhov
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=ZFBheCRW5fbzVK1V@google.com \
--to=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rydberg@bitmath.org \
--cc=starmiku1207184332@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.