From: sashiko-bot@kernel.org
To: "Fredrik M Olsson" <fredrik.m.olsson@axis.com>
Cc: conor+dt@kernel.org, robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v2 2/3] rtc: ds1307: Fix off-by-one issue with wday for rx8130
Date: Wed, 20 May 2026 15:45:09 +0000 [thread overview]
Message-ID: <20260520154509.D5B881F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260520-ds1307-rx8901-add-v2-2-e069ea32e1db@axis.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Undefined Behavior via out-of-bounds shift in ds1307_set_time()
- [High] Hardware configuration corruption in rx8130_set_alarm()
--
commit 3f83bdbd74c118b742ad3d44c6daf3ae8e8ffcbe
Author: Fredrik M Olsson <fredrik.m.olsson@axis.com>
rtc: ds1307: Fix off-by-one issue with wday for rx8130
The RTC represent each weekday with a individual bit set in the WDAY
register, where the 0th bit represent the first day of the week and the
6th bit represents the last day of the week.
> diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
> index 7205c59ff7294..bf42c250ea7d1 100644
> --- a/drivers/rtc/rtc-ds1307.c
> +++ b/drivers/rtc/rtc-ds1307.c
> @@ -308,7 +308,7 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
> t->tm_hour = bcd2bin(tmp);
> /* rx8130 is bit position, not BCD */
> if (ds1307->type == rx_8130)
> - t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f);
> + t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f) - 1;
[Severity: High]
This isn't a bug introduced by this patch, but does this introduce a new
non-malicious trigger for a pre-existing undefined behavior?
The kernel's rtc_valid_tm() omits validation of tm_wday. A malicious userspace
program with CAP_SYS_TIME could already pass a negative value to RTC_SET_TIME,
triggering an out-of-bounds shift in ds1307_set_time():
drivers/rtc/rtc-ds1307.c:ds1307_set_time() {
...
if (ds1307->type == rx_8130)
regs[DS1307_REG_WDAY] = 1 << t->tm_wday;
...
}
With this patch, if the hardware WDAY register is zeroed, fls(0) returns 0,
making t->tm_wday equal to -1. A benign read-modify-write cycle by standard
tools (like hwclock) will now naturally trigger the undefined behavior.
> else
> t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1;
> t->tm_mday = bcd2bin(regs[DS1307_REG_MDAY] & 0x3f);
[Severity: High]
This is a pre-existing issue, but does rx8130_set_alarm() corrupt the RTC's
hardware configuration?
drivers/rtc/rtc-ds1307.c:rx8130_set_alarm() {
...
/* Read control registers. */
ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl,
sizeof(ctl));
if (ret < 0)
return ret;
ctl[0] &= RX8130_REG_EXTENSION_WADA;
ctl[1] &= ~RX8130_REG_FLAG_AF;
ctl[2] &= ~RX8130_REG_CONTROL0_AIE;
...
}
Because RX8130_REG_EXTENSION_WADA is defined as BIT(3), this operation masks
out and clears all other configuration bits in the register (such as timer
enables and frequency selection), while preserving the WADA bit if it was set
instead of clearing it.
Does this break other features every time an alarm is set?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260520-ds1307-rx8901-add-v2-0-e069ea32e1db@axis.com?part=2
next prev parent reply other threads:[~2026-05-20 15:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 14:48 [PATCH v2 0/3] rtc: ds1307: Add support for Epson RX8901CE Fredrik M Olsson
2026-05-20 14:48 ` [PATCH v2 1/3] dt-bindings: rtc: ds1307: Add epson,rx8901 Fredrik M Olsson
2026-05-20 14:48 ` [PATCH v2 2/3] rtc: ds1307: Fix off-by-one issue with wday for rx8130 Fredrik M Olsson
2026-05-20 15:45 ` sashiko-bot [this message]
2026-05-20 14:48 ` [PATCH v2 3/3] rtc: ds1307: Add driver for Epson RX8901CE Fredrik M Olsson
2026-05-20 17:03 ` 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=20260520154509.D5B881F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=fredrik.m.olsson@axis.com \
--cc=robh@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox