All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Lee Jones <lee@kernel.org>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Nishanth Menon <nm@ti.com>, "George G. Davis" <gdavis@mvista.com>,
	or <source@mvista.com>, Andrew Morton <akpm@linux-foundation.org>,
	linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH 09/10] rtc: omap: prevent NULL and dangling pointer dereferences in power-off path
Date: Tue, 24 Nov 2026 08:59:17 +0100	[thread overview]
Message-ID: <awVD1YwurAJDjien@hovoldconsulting.com> (raw)
In-Reply-To: <20261123200012.502284-10-lee@kernel.org>

On Mon, Nov 23, 2026 at 07:59:20PM +0000, Lee Jones wrote:
> omap_rtc_remove() only clears the global omap_rtc_power_off_rtc pointer
> if pm_power_off still equals omap_rtc_power_off.  If another driver
> overwrote pm_power_off after probe, unbinding the RTC leaves
> omap_rtc_power_off_rtc pointing to freed memory.  Furthermore,
> omap_rtc_power_off_program() is exported and called directly from
> am33xx_rtc_only_idle() during suspend without checking whether
> omap_rtc_power_off_rtc is NULL, causing a NULL pointer dereference if
> omap_rtc_power_off_rtc was never assigned or was cleared on unbind.

This sounds like two separate issues and the am33xx_rtc_only_idle call()
was added later by commit 5a99ae0092fe ("soc: ti: pm33xx: AM437X: Add
rtc_only with ddr in self-refresh support").

> Always clear omap_rtc_power_off_rtc when removing the matching RTC
> instance, and return -ENODEV from omap_rtc_power_off_program() when
> omap_rtc_power_off_rtc is NULL.
> 
> Fixes: 222a12fca604 ("rtc: omap: add support for pmic_power_en")

So this isn't the right fixes tag for that.

> Closes: https://sashiko.dev/#/bug/linux-97b795c5-f68f-4228-948f-547a106c6775
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
>  drivers/rtc/rtc-omap.c | 21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
> index 3c978edd6c2c..156444fab916 100644
> --- a/drivers/rtc/rtc-omap.c
> +++ b/drivers/rtc/rtc-omap.c
> @@ -416,6 +416,9 @@ int omap_rtc_power_off_program(void)
>  	int seconds;
>  	u32 val;
>  
> +	if (!rtc)
> +		return -ENODEV;
> +
>  	rtc->type->unlock(rtc);
>  	/* enable pmic_power_en control */
>  	val = rtc_readl(rtc, OMAP_RTC_PMIC_REG);
> @@ -481,17 +484,19 @@ EXPORT_SYMBOL(omap_rtc_power_off_program);
>   */
>  static void omap_rtc_power_off(void)
>  {
> +	struct omap_rtc *rtc = omap_rtc_power_off_rtc;
>  	u32 val;
>  
> -	omap_rtc_power_off_program();
> +	if (omap_rtc_power_off_program())
> +		return;
  
>  	/* Set PMIC power enable and EXT_WAKEUP in case PB power on is used */
> -	omap_rtc_power_off_rtc->type->unlock(omap_rtc_power_off_rtc);
> -	val = rtc_readl(omap_rtc_power_off_rtc, OMAP_RTC_PMIC_REG);
> +	rtc->type->unlock(rtc);
> +	val = rtc_readl(rtc, OMAP_RTC_PMIC_REG);
>  	val |= OMAP_RTC_PMIC_POWER_EN_EN | OMAP_RTC_PMIC_EXT_WKUP_POL(0) |
>  			OMAP_RTC_PMIC_EXT_WKUP_EN(0);
> -	rtc_writel(omap_rtc_power_off_rtc, OMAP_RTC_PMIC_REG, val);
> -	omap_rtc_power_off_rtc->type->lock(omap_rtc_power_off_rtc);
> +	rtc_writel(rtc, OMAP_RTC_PMIC_REG, val);
> +	rtc->type->lock(rtc);

This is an unrelated change.

>  	/*
>  	 * Wait for alarm to trigger (within one second) and external PMIC to
> @@ -913,9 +918,9 @@ static void omap_rtc_remove(struct platform_device *pdev)
>  	struct omap_rtc *rtc = platform_get_drvdata(pdev);
>  	u8 reg;
>  
> -	if (pm_power_off == omap_rtc_power_off &&
> -			omap_rtc_power_off_rtc == rtc) {
> -		pm_power_off = NULL;
> +	if (omap_rtc_power_off_rtc == rtc) {
> +		if (pm_power_off == omap_rtc_power_off)
> +			pm_power_off = NULL;
>  		omap_rtc_power_off_rtc = NULL;
>  	}

You can only have one legacy power off handler, but leaving the
omap_rtc_power_off_rtc pointer set after unbind wasn't an issue before
the later added am33xx_rtc_only_idle() call.

So with the Fixes tag fixed and the unrelated changes in
omap_rtc_power_off() dropped I guess this can all go in one patch.

Johan

  reply	other threads:[~2026-11-24  7:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
2026-11-23 19:59 ` [PATCH 01/10] rtc: rx8025: pass parent I2C device in clock_adjust_ppb sysfs callbacks Lee Jones
2026-11-23 19:59 ` [PATCH 02/10] rtc: mt6397: handle non-DT platform device matching in probe Lee Jones
2026-11-23 19:59 ` [PATCH 03/10] rtc: ma35d1: allocate RTC device before requesting interrupt Lee Jones
2026-11-23 19:59 ` [PATCH 04/10] rtc: mpc5121: get interrupts via platform_get_irq() Lee Jones
2026-11-23 19:59 ` [PATCH 05/10] rtc: m41t80: use devm helpers for square-wave clock registration Lee Jones
2026-11-23 19:59 ` [PATCH 06/10] rtc: nct3018y: fix clock provider use-after-free and leak on unbind Lee Jones
2026-11-23 19:59 ` [PATCH 07/10] rtc: stmp3xxx: unregister child watchdog platform device " Lee Jones
2026-11-23 19:59 ` [PATCH 08/10] rtc: ds1685: check driver data for NULL in ds1685_rtc_poweroff() Lee Jones
2026-11-29 16:08   ` Imre Kaloz
2026-11-23 19:59 ` [PATCH 09/10] rtc: omap: prevent NULL and dangling pointer dereferences in power-off path Lee Jones
2026-11-24  7:59   ` Johan Hovold [this message]
2026-11-23 19:59 ` [PATCH 10/10] rtc: bq32k: use u8 register buffer in trickle_charge_bypass sysfs Lee Jones
2026-11-23 20:16 ` [PATCH 00/10] rtc: assorted bug fixes across RTC drivers sashiko-bot

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=awVD1YwurAJDjien@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=gdavis@mvista.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=source@mvista.com \
    --cc=stable@vger.kernel.org \
    /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.