From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DF46DC27C79 for ; Mon, 17 Jun 2024 16:19:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=uiuI0ne78SCn0dRqC/AA7OSeq1K0b9qMP7aQO3GiU3A=; b=Dh6q7I8qmHulPpsoL7Q5zwmQNz E7IudAdS69Z8AC8OGQXulS5OkyszkFcLO1v+bKgJRzncwdafy43/ylDFWzXjwLsn/kDhM8LQvMpky hAF+GP1gF2yuM8TfxsSeC2x473WqliwBZEz4JTqzfqYkigHlnCZdiutb/QL9N3nDLfpmcIBznUr1l gC1jomDgGp62D9fyV5GTuvQT3Z6CTKRAifJ4C8FKMt3vGUnUsxKlxo05rmnc6Vt7NERwZ/F92hDcn tSC8PfKbV/n6yOAuCNK8cpypwb5APJ45Z7oao2wBroPYlfO6vuBw7yAdTUO7I0+091mkj1aoB7jxh fELpn+TA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJF5C-0000000BhIR-2FWb; Mon, 17 Jun 2024 16:19:50 +0000 Received: from galois.linutronix.de ([193.142.43.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJF57-0000000BhGm-3NFV for linux-arm-kernel@lists.infradead.org; Mon, 17 Jun 2024 16:19:48 +0000 From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1718641182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uiuI0ne78SCn0dRqC/AA7OSeq1K0b9qMP7aQO3GiU3A=; b=c9yjD5c0rmBkkXgK+g/+45a92f5RYx1M1zhQAj0cZoAsc2vCaoKRCI2GSvXLrxDcLapxi8 CeuExVn+rbtI/5a88s6XKv7v2M62uR/oKa/EzQyHcrdv5TW5iaGz7GMYCcrCfdB+XPDpJn yuDp3taCI+Wthli5R230f93MkNkMMFpLA43giMkkbUQUjxrabaNuI9bn3yoeWBY6k3SzMb C2X2ueeaxRHND0Qbgtl7ubt0jUl/IlXCYfjbRuWjLhfRTat61w3HZg/+Wbsd/ApM0D6stN DkkiWqpw/EN/LBv48PZRWd+xlcAFMeI286caZdN8isotddO8+78u/5D1/oy9ew== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1718641182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=uiuI0ne78SCn0dRqC/AA7OSeq1K0b9qMP7aQO3GiU3A=; b=OCHSGj4fl0S5vb/+GHyOFycN5xud/B011qQqB4AEftopyb79TSmKd18Ea/IyMmqF0Mr685 1wRKWs368hv5l/Bg== To: Phil Chang 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 In-Reply-To: <20240610133136.327-1-phil.chang@mediatek.com> References: <87bk496seb.fsf@somnus> <20240610133136.327-1-phil.chang@mediatek.com> Date: Mon, 17 Jun 2024 18:19:42 +0200 Message-ID: <87tthr4k4h.fsf@somnus> MIME-Version: 1.0 Content-Type: text/plain X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240617_091946_033283_1EEFE2B6 X-CRM114-Status: GOOD ( 15.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Phil Chang 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 Reviewed-by: Anna-Maria Behnsen > --- > 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