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 1BE98C25B75 for ; Thu, 6 Jun 2024 13:15:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:References :In-Reply-To:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xZFqdsgmXeHExMWwiCCjVtzoDZvg9IZKERa3p5yzsY8=; b=IsWjEeAT9yEzDM PoLfZyywgft/FDDusGkIw7mxu7bu5KrchoRE7B4eyCgxN/I2aBEKkJKPE0JEKpHDGOU63T130ApY8 3Uy4FQy74qHl2BskmVRWP6HMWtW5htPDXPEPfGzpmw4vAreEi3b39xXg6tckrCn+C0Q9CC5iXT/Z/ 9wTZ3ivgM1BQahJpVIdC+5eZaZzYyFfgPlfmuL2sm5lxNakYaBsDaPSyh5QpSLA7QnczolrDLjyhr EnuVnqbbRADOGjt2spDdmcY70a5j0pCWc4FbpkmsqPQZTJYvoSLXSztxIbkpq+FUL9uAUKs7OzM6U hGbnlpgydnh7sTFYAm2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sFCxF-00000009owd-1za6; Thu, 06 Jun 2024 13:14:57 +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 1sFCx1-00000009ooH-1l6U for linux-arm-kernel@lists.infradead.org; Thu, 06 Jun 2024 13:14:56 +0000 From: Anna-Maria Behnsen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1717679677; 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=yAsZ/41lOcaQ90q2I6nOsLXJ1jn8OTLuONqlVOl/Qwg=; b=F3hXU3vclt3wgaEdMhe8f2JPD/jGLGgpsWebOgeBHHa+8kjuavv10RP98lWXdLB9khxweb bx0iAHU9PkIMvFi5XyqKXa8cwEBFbvzPm+AMrc6hAP/5XGlvfaE8Pj6zulkl9mW6N1h9gj 4aQhu3iBzJjpDr7TUcAvfMzCwfDHej3zV2rBsKISWob/PgQL2BsMdL7vx4wCFeSkEa/r32 c2Z/ptEBHyb3oOafTpZhmW+wCKarLgVkYP9wLNM8QHSldv1iK0+xiVwmh//mM5IYJA15uw RVe/NREYcdiCrtORtLX9OOfXbaCkiubx2lFztT5rBTJObbNd//3VHg4uX6lKqg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717679677; 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=yAsZ/41lOcaQ90q2I6nOsLXJ1jn8OTLuONqlVOl/Qwg=; b=PCjwzUTvkzTIUnlN4ZroszFujEBS7bTxk+AsI0SO3II+nx1H9Iud162t4hji4zxpl2163r /L2LAj8lnnwsHdAg== 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] hrtimer: check hrtimer with a NULL function In-Reply-To: <20240605135106.16065-1-phil.chang@mediatek.com> References: <87plsvvgpn.fsf@somnus> <20240605135106.16065-1-phil.chang@mediatek.com> Date: Thu, 06 Jun 2024 15:14:37 +0200 Message-ID: <877cf2i56q.fsf@somnus> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240606_061443_641370_19FC2793 X-CRM114-Status: GOOD ( 15.01 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Phil Chang writes: >>> simillar with timers, check for timer->function == NULL. >>> If the pointer is NULL, discard the request silently. > >> Can you please explain, why this change is required? > >> The statement "similar to timers" is not a valid explaination as timer >> list timers and hrtimers are two different things. The function pointer >> for timer list timers is explicitly set to NULL in shutdown path to >> prevent unwanted rearming of the timer. For hrtimers there is no >> shutdown function implemented and function is never set to NULL by >> hrtimer code. >> > The timer->function is provided by caller, which is invaild if fuction is NULL, > and currently, the hrtime code does not perform any checks to validate this. > Passing a NULL function can lead to a system panic, with a backtrace likes: > ``` > __hrtimer_run_queues+0x1d8/0x3b8 > hrtimer_interrupt+0xdc/0x3a0 > arch_timer_handler_phys+0x54/0x94 > handle_percpu_devid_irq+0xb8/0x308 > handle_domain_irq+0x78/0xec > gic_handle_irq+0x50/0x10c > call_on_irq_stack+0x38/0x54 > do_interrupt_handler+0x40/0x98 > ``` > This backtrace does not clearly indicate the source of the invalid usage of hrtimer. To make it more clear to the inexperienced hrtimer user that it is mandatory to initialize timer->function to be able to use hrtimers, but to prevent the kernel to crash, please add a warning in hrtimer_start_range_ns(). The check can be done without locking the hrtimer base. When the function pointer is not set, return directly without doing anything. So this above mentioned backtrace will no longer appear, as the timer is not added to a queue. Thanks, Anna-Maria _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel