From: Anna-Maria Behnsen <anna-maria@linutronix.de>
To: Phil Chang <phil.chang@mediatek.com>
Cc: alix.wu@mediatek.com, angelogioacchino.delregno@collabora.com,
frederic@kernel.org, jy.ho@mediatek.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, matthias.bgg@gmail.com,
phil.chang@mediatek.com, tglx@linutronix.de
Subject: Re: [PATCH v3] hrtimer: check hrtimer with a NULL function
Date: Mon, 17 Jun 2024 18:19:42 +0200 [thread overview]
Message-ID: <87tthr4k4h.fsf@somnus> (raw)
In-Reply-To: <20240610133136.327-1-phil.chang@mediatek.com>
Phil Chang <phil.chang@mediatek.com> writes:
> To prevent improper usage of hrtimers and avoid potential kernel crashes,
> this commit introduces a validation check for hrtimers with a valid function callback,
> discard the hrtimers that have a NULL callback.
>
> The `run_hrtimer` executes callbacks for every hrtimer,
> and these callbacks must not be NULL. A NULL callback can lead to a kernel crash.
> This update ensures that all hrtimers have properly initialized callbacks
> before execution.
Definitely better! You could sort it, first problem description and then
solution:
The hrtimer function callback must not be NULL. It has to be specified
by the callsite but it is not validated by hrtimer code. When a hrtimer
is queued with a NULL pointer instead of a valid function, the kernel
crashes with a null pointer dereference when trying to execute the
callback in __run_hrtimer().
Introduce a validation before queueing the hrtimer in
hrtimer_start_range_ns().
>
> Signed-off-by: Phil Chang <phil.chang@mediatek.com>
Reviewed-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
> ---
> kernel/time/hrtimer.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
> index 492c14aac642..b8ee320208d4 100644
> --- a/kernel/time/hrtimer.c
> +++ b/kernel/time/hrtimer.c
> @@ -1285,6 +1285,8 @@ void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
> struct hrtimer_clock_base *base;
> unsigned long flags;
>
> + if (WARN_ON_ONCE(!timer->function))
> + return;
> /*
> * Check whether the HRTIMER_MODE_SOFT bit and hrtimer.is_soft
> * match on CONFIG_PREEMPT_RT = n. With PREEMPT_RT check the hard
prev parent reply other threads:[~2024-06-17 16:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-05 8:41 [PATCH] hrtimer: check hrtimer with a NULL function Phil Chang
2024-06-05 10:15 ` Anna-Maria Behnsen
2024-06-05 13:51 ` Phil Chang
2024-06-06 13:14 ` Anna-Maria Behnsen
2024-06-07 2:26 ` [PATCH v2] " Phil Chang
2024-06-10 9:47 ` Anna-Maria Behnsen
2024-06-10 13:31 ` [PATCH v3] " Phil Chang
2024-06-17 16:19 ` Anna-Maria Behnsen [this message]
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=87tthr4k4h.fsf@somnus \
--to=anna-maria@linutronix.de \
--cc=alix.wu@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=frederic@kernel.org \
--cc=jy.ho@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=phil.chang@mediatek.com \
--cc=tglx@linutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).