Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: Prabhakar <prabhakar.csengg@gmail.com>
Cc: conor+dt@kernel.org, linux-rtc@vger.kernel.org, robh@kernel.org,
	wsa+renesas@sang-engineering.com, devicetree@vger.kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH v4 03/15] rtc: rzn1: Fix weekday underflow when alarm crosses month boundary
Date: Wed, 19 Aug 2026 10:53:56 +0000	[thread overview]
Message-ID: <20260819105356.BD7731F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260819103926.2136712-4-prabhakar.mahadev-lad.rj@bp.renesas.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Truncation of 64-bit `time64_t` alarm timestamps to 32-bit `unsigned long` and misuse of `time_after()` allows users to bypass the 1-week hardware alarm limit on 32-bit systems for alarms requested > 68 years in the future.
- [Medium] Missing validation for an uninitialized `wday` hardware register in `rzn1_rtc_read_alarm` produces bogus alarm dates.
--

--- Patch [3]: [PATCH v4 03/15] rtc: rzn1: Fix weekday underflow when alarm crosses month boundary ---
commit d19190c56b59d2960781807a89bdaa97caa58aa4
Author: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

rtc: rzn1: Fix weekday underflow when alarm crosses month boundary

This patch fixes an underflow issue in rzn1_rtc_set_alarm() when
calculating the alarm weekday across month boundaries. It directly uses
the tm_wday field from the pre-populated rtc_time struct instead of
recalculating it from the days ahead.

> diff --git a/drivers/rtc/rtc-rzn1.c b/drivers/rtc/rtc-rzn1.c
> index aa27ad7f5941a..8c70dbf8c7ecd 100644
> --- a/drivers/rtc/rtc-rzn1.c
> +++ b/drivers/rtc/rtc-rzn1.c

[ ... ]

> @@ -273,13 +272,9 @@ static int rzn1_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
>  	if (time_after(alarm, farest))
>  		return -ERANGE;

[Severity: High]
This is a pre-existing issue, but does this time_after() comparison
allow bypassing the 1-week hardware limit on 32-bit systems?

Since rtc_tm_to_time64() returns a 64-bit value that gets truncated
into the 32-bit unsigned long alarm and farest variables on 32-bit
architectures, requesting an alarm > 68 years in the future (e.g. 2099)
could cause the difference farest - alarm to exceed INT_MAX.

This subtraction would overflow in two's complement and evaluate as a
positive integer, causing time_after(alarm, farest) to evaluate to
false, bypassing the -ERANGE check and configuring an alarm that fires at
the wrong time.


While reviewing this file, I also noticed another pre-existing issue in
rzn1_rtc_read_alarm() that might need attention:

drivers/rtc/rtc-rzn1.c:rzn1_rtc_read_alarm() {
    ...
    wday = readl(rtc->base + RZN1_RTC_ALW);
    ...
    delta_days = ((fls(wday) - 1) - tm->tm_wday + 7) % 7;
    tm->tm_wday = fls(wday) - 1;
    ...
}

[Severity: Medium]
This is a pre-existing issue, but what happens if the RZN1_RTC_ALW register
is uninitialized and wday is 0?

Calling fls(0) - 1 would evaluate to -1. If the current time is a Saturday
(tm_now.tm_wday == 6), delta_days evaluates to 0, which bypasses
the if (delta_days) block and leaves tm->tm_wday = -1.

Since the core function rtc_valid_tm() does not check tm_wday, would this
propagate a bogus alarm date to the caller?


> -	/* Convert alarm day into week day */
> -	days_ahead = tm->tm_mday - tm_now.tm_mday;
> -	wday = (tm_now.tm_wday + days_ahead) % 7;
> -
>  	writel(bin2bcd(tm->tm_min), rtc->base + RZN1_RTC_ALM);
>  	writel(bin2bcd(tm->tm_hour), rtc->base + RZN1_RTC_ALH);
> -	writel(BIT(wday), rtc->base + RZN1_RTC_ALW);
> +	writel(BIT(tm->tm_wday), rtc->base + RZN1_RTC_ALW);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260819103926.2136712-1-prabhakar.mahadev-lad.rj@bp.renesas.com?part=3

  reply	other threads:[~2026-08-19 10:53 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19 10:39 [PATCH v4 00/15] Add RTC support for Renesas RZ/T2H and RZ/N2H SoCs Prabhakar
2026-08-19 10:39 ` [PATCH v4 01/15] dt-bindings: rtc: renesas,rzn1-rtc: Add RZ/T2H and RZ/N2H support Prabhakar
2026-08-19 10:48   ` sashiko-bot
2026-08-19 10:39 ` [PATCH v4 02/15] rtc: rzn1: Handle EPROBE_DEFER for optional pps interrupt Prabhakar
2026-08-19 10:46   ` sashiko-bot
2026-08-19 10:39 ` [PATCH v4 03/15] rtc: rzn1: Fix weekday underflow when alarm crosses month boundary Prabhakar
2026-08-19 10:53   ` sashiko-bot [this message]
2026-08-19 13:01     ` Wolfram Sang
2026-08-19 12:57   ` Wolfram Sang
2026-08-19 10:39 ` [PATCH v4 04/15] rtc: rzn1: Fix malformed MODULE_AUTHOR string Prabhakar
2026-08-19 10:43   ` sashiko-bot
2026-08-19 10:39 ` [PATCH v4 05/15] rtc: Kconfig: Broaden RTC_DRV_RZN1 dependency to ARCH_RENESAS Prabhakar
2026-08-19 10:44   ` sashiko-bot
2026-08-19 10:39 ` [PATCH v4 06/15] rtc: rzn1: Fix alarm range check truncation on 32-bit systems Prabhakar
2026-08-19 10:50   ` sashiko-bot
2026-08-19 13:05     ` Wolfram Sang
2026-08-19 10:39 ` [PATCH v4 07/15] rtc: rzn1: Replace remove callback with devm_add_action_or_reset() Prabhakar
2026-08-19 10:50   ` sashiko-bot
2026-08-19 13:06     ` Wolfram Sang
2026-08-19 10:39 ` [PATCH v4 08/15] rtc: rzn1: Use pm_runtime_put_sync() in rzn1_rtc_disable_hardware() Prabhakar
2026-08-19 10:51   ` sashiko-bot
2026-08-19 13:07     ` Wolfram Sang
2026-08-19 10:39 ` [PATCH v4 09/15] rtc: rzn1: Dynamically calculate synchronization delay based on clock rate Prabhakar
2026-08-19 10:47   ` sashiko-bot
2026-08-19 13:08   ` Wolfram Sang
2026-08-19 10:39 ` [PATCH v4 10/15] rtc: rzn1: Use temporary variable for struct device Prabhakar
2026-08-19 10:46   ` sashiko-bot
2026-08-19 10:39 ` [PATCH v4 11/15] rtc: rzn1: Consistently use dev_err_probe() Prabhakar
2026-08-19 10:46   ` sashiko-bot
2026-08-19 10:39 ` [PATCH v4 12/15] rtc: rzn1: use FIELD_PREP/FIELD_GET and GENMASK for register access Prabhakar
2026-08-19 10:49   ` sashiko-bot
2026-08-19 13:09     ` Wolfram Sang
2026-08-19 10:39 ` [PATCH v4 13/15] rtc: rzn1: Add OF match data to gate SUBU " Prabhakar
2026-08-19 10:47   ` sashiko-bot
2026-08-19 13:12   ` Wolfram Sang
2026-08-19 10:39 ` [PATCH v4 14/15] rtc: rzn1: Drop trailing comma from OF match table sentinel Prabhakar
2026-08-19 10:47   ` sashiko-bot
2026-08-19 13:13   ` Wolfram Sang
2026-08-19 10:39 ` [PATCH v4 15/15] rtc: rzn1: Add support for Renesas RZ/T2H and RZ/N2H SoCs Prabhakar
2026-08-19 10:52   ` sashiko-bot
2026-08-19 13:14   ` Wolfram Sang
2026-08-19 13:15 ` [PATCH v4 00/15] Add RTC " Wolfram Sang

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=20260819105356.BD7731F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=prabhakar.csengg@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wsa+renesas@sang-engineering.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