mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	"George G. Davis" <gdavis@mvista.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Dave Gerlach <d-gerlach@ti.com>, Johan Hovold <johan@kernel.org>,
	Keerthy <j-keerthy@ti.com>,
	linux-rtc@vger.kernel.org, Tony Lindgren <tony@atomide.com>
Subject: [PATCH v2 09/10] rtc: omap: prevent NULL and dangling pointer dereferences in power-off path
Date: Wed,  2 Dec 2026 20:22:38 +0000	[thread overview]
Message-ID: <f042677983a6d70047dc75552356ff68b1d964ca.1796242916.git.lee@kernel.org> (raw)
In-Reply-To: <cover.1796242916.git.lee@kernel.org>

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.
Furthermore, omap_rtc_remove() only clears omap_rtc_power_off_rtc 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 for subsequent calls to
omap_rtc_power_off_program().

Return -ENODEV from omap_rtc_power_off_program() when
omap_rtc_power_off_rtc is NULL, and always clear omap_rtc_power_off_rtc
when removing the matching RTC instance.

Fixes: 5a99ae0092fe ("soc: ti: pm33xx: AM437X: Add rtc_only with ddr in self-refresh support")
Closes: https://sashiko.dev/#/bug/linux-97b795c5-f68f-4228-948f-547a106c6775
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

v1 => v2:
 - Update Fixes: tag to 5a99ae0092fe ("soc: ti: pm33xx: AM437X: Add
   rtc_only with ddr in self-refresh support") and reword the commit
   message accordingly (Johan)
 - Drop the unrelated refactoring in omap_rtc_power_off() (Johan)

Cc: "George G. Davis" <gdavis@mvista.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Dave Gerlach <d-gerlach@ti.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Keerthy <j-keerthy@ti.com>
Cc: linux-rtc@vger.kernel.org
Cc: Tony Lindgren <tony@atomide.com>

 drivers/rtc/rtc-omap.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 18492165a19f..f75a00dd8386 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);
@@ -913,9 +916,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;
 	}
 
-- 
2.56.1.911.g883d8bcb20-goog


  parent reply	other threads:[~2026-12-02 20:23 UTC|newest]

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

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=f042677983a6d70047dc75552356ff68b1d964ca.1796242916.git.lee@kernel.org \
    --to=lee@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=d-gerlach@ti.com \
    --cc=gdavis@mvista.com \
    --cc=j-keerthy@ti.com \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tony@atomide.com \
    /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

all inboxes | Powered by JetHome®