From: Phil Chang <phil.chang@mediatek.com>
To: <anna-maria@linutronix.de>
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: [PATCH v3] hrtimer: check hrtimer with a NULL function
Date: Mon, 10 Jun 2024 21:31:36 +0800 [thread overview]
Message-ID: <20240610133136.327-1-phil.chang@mediatek.com> (raw)
In-Reply-To: <87bk496seb.fsf@somnus>
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.
Signed-off-by: Phil Chang <phil.chang@mediatek.com>
---
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
--
2.18.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-06-10 13:42 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 ` Phil Chang [this message]
2024-06-17 16:19 ` [PATCH v3] " Anna-Maria Behnsen
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=20240610133136.327-1-phil.chang@mediatek.com \
--to=phil.chang@mediatek.com \
--cc=alix.wu@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=anna-maria@linutronix.de \
--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=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).