From: sashiko-bot@kernel.org
To: "Myeonghun Pak" <mhun512@gmail.com>
Cc: linux-rtc@vger.kernel.org,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH] rtc: m41t80: clean up watchdog on registration failure
Date: Wed, 29 Jul 2026 02:28:49 +0000 [thread overview]
Message-ID: <20260729022850.3C0961F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260729021812.49868-1-mhun512@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] The clock provider registered by `m41t80_sqw_register_clk()` is never unregistered on probe failure or device removal, leaving a dangling pointer in the Common Clock Framework.
- [High] Probing multiple M41T80 devices overwrites the global `save_client` pointer before verifying watchdog registration success, leading to a NULL pointer dereference.
- [High] Registering the watchdog misc device before probe completes allows user-space to open the device, and the lack of VFS file descriptor revocation coupled with a dangling `save_client` leads to a NULL pointer dereference.
--
--- Patch [1]: [PATCH] rtc: m41t80: clean up watchdog on registration failure ---
commit 7f474c7e546e109c3aad769a8ec54e1bdf1316d0
Author: Myeonghun Pak <mhun512@gmail.com>
rtc: m41t80: clean up watchdog on registration failure
This commit unregisters the watchdog miscdevice and reboot notifier if the
RTC device registration fails during probe. This prevents leaving callbacks
tied to a device whose driver failed to bind.
> diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
> index 3c8c379392c14..3cb3f5e94f861 100644
> --- a/drivers/rtc/rtc-m41t80.c
> +++ b/drivers/rtc/rtc-m41t80.c
> @@ -1008,8 +1008,15 @@ static int m41t80_probe(struct i2c_client *client)
> #endif
>
> rc = devm_rtc_register_device(m41t80_data->rtc);
> - if (rc)
> + if (rc) {
[Severity: High]
This isn't a bug introduced by this patch, but does the probe error path also
need to unregister the clock provider?
If devm_rtc_register_device() fails, the driver frees the devres-managed
m41t80_data. However, m41t80_sqw_register_clk() registers the clock using
non-devm functions (clk_register and of_clk_add_provider):
drivers/rtc/rtc-m41t80.c:m41t80_sqw_register_clk() {
...
clk = clk_register(&client->dev, &m41t80->sqw);
if (!IS_ERR(clk))
of_clk_add_provider(node, of_clk_src_simple_get, clk);
...
}
Since neither this error path nor m41t80_remove() unregisters the clock,
could subsequent accesses to the clock tree (like reading
/sys/kernel/debug/clk/clk_summary) dereference the freed clk_hw and
cause a use-after-free?
[Severity: High]
This is another pre-existing issue, but is it safe to unconditionally
overwrite the global save_client pointer earlier in the probe function?
Earlier in m41t80_probe(), save_client is set before misc_register() is
confirmed to succeed:
drivers/rtc/rtc-m41t80.c:m41t80_probe() {
...
save_client = client;
rc = misc_register(&wdt_dev);
if (rc)
return rc;
...
}
If multiple M41T80 devices exist, the second probe will overwrite save_client
but fail at misc_register() because the watchdog minor is already taken.
The driver core then clears drvdata for the failed device.
If a user-space process sends a keepalive to the working watchdog, wdt_ping()
will use the corrupted save_client pointing to the unbound device, fetching
a NULL clientdata. Could this cause a NULL pointer dereference in wdt_ping()?
> +#ifdef CONFIG_RTC_DRV_M41T80_WDT
> + if (m41t80_data->features & M41T80_FEATURE_HT) {
> + unregister_reboot_notifier(&wdt_notifier);
> + misc_deregister(&wdt_dev);
[Severity: High]
This is a pre-existing issue, but should save_client be cleared to NULL
when deregistering the watchdog?
When misc_deregister() is called here (and in m41t80_remove()), it removes
the device node but does not revoke existing open file descriptors. If
user-space has already opened /dev/watchdog before the probe fails, the
global save_client pointer is left dangling.
If user-space later writes to the open file descriptor, wdt_ping() will use
save_client to fetch clientdata:
drivers/rtc/rtc-m41t80.c:wdt_ping() {
...
struct m41t80_data *clientdata = i2c_get_clientdata(save_client);
...
if (clientdata->features & M41T80_FEATURE_WD)
...
}
Since the driver core clears drvdata on probe failure, clientdata will be
NULL. Does this lead to a NULL pointer dereference?
> + }
> +#endif
> return rc;
> + }
>
> return 0;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260729021812.49868-1-mhun512@gmail.com?part=1
prev parent reply other threads:[~2026-07-29 2:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-29 2:18 [PATCH] rtc: m41t80: clean up watchdog on registration failure Myeonghun Pak
2026-07-29 2:28 ` sashiko-bot [this message]
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=20260729022850.3C0961F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-rtc@vger.kernel.org \
--cc=mhun512@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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.