* [PATCH v5 0/2] posix-clock: Fix missing timespec64 check for PTP clock
@ 2024-10-08 9:10 Jinjie Ruan
2024-10-08 9:11 ` [PATCH v5 1/2] posix-clock: Fix missing timespec64 check in pc_clock_settime() Jinjie Ruan
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Jinjie Ruan @ 2024-10-08 9:10 UTC (permalink / raw)
To: bryan.whitehead, davem, edumazet, kuba, pabeni, anna-maria,
frederic, tglx, richardcochran, johnstul, UNGLinuxDriver, netdev,
linux-kernel
Cc: ruanjinjie
Check timespec64 in pc_clock_settime() for PTP clock as
the man manual of clock_settime() said.
Changes in v5:
- Use timespec64_valid_strict() instead of timespec64_valid()
as Thomas suggested.
- Add fix tag.
- Update the commit message.
Changes in v4:
- Check it in pc_clock_settime() for PTP clock.
- Update the commit message.
Changes in v3:
- Check it before call clock_set().
- Update the commit message.
Jinjie Ruan (2):
posix-clock: Fix missing timespec64 check in pc_clock_settime()
net: lan743x: Remove duplicate check
drivers/net/ethernet/microchip/lan743x_ptp.c | 35 ++++++++------------
kernel/time/posix-clock.c | 3 ++
2 files changed, 17 insertions(+), 21 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v5 1/2] posix-clock: Fix missing timespec64 check in pc_clock_settime()
2024-10-08 9:10 [PATCH v5 0/2] posix-clock: Fix missing timespec64 check for PTP clock Jinjie Ruan
@ 2024-10-08 9:11 ` Jinjie Ruan
2024-10-08 9:11 ` [PATCH v5 2/2] net: lan743x: Remove duplicate check Jinjie Ruan
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Jinjie Ruan @ 2024-10-08 9:11 UTC (permalink / raw)
To: bryan.whitehead, davem, edumazet, kuba, pabeni, anna-maria,
frederic, tglx, richardcochran, johnstul, UNGLinuxDriver, netdev,
linux-kernel
Cc: ruanjinjie
As Andrew pointed out, it will make sense that the PTP core
checked timespec64 struct's tv_sec and tv_nsec range before calling
ptp->info->settime64().
As the man manual of clock_settime() said, if tp.tv_sec is negative or
tp.tv_nsec is outside the range [0..999,999,999], it should return EINVAL,
which include dynamic clocks which handles PTP clock, and the condition is
consistent with timespec64_valid(). As Thomas suggested, timespec64_valid()
only check the timespec is valid, but not ensure that the time is
in a valid range, so check it ahead using timespec64_valid_strict()
in pc_clock_settime() and return -EINVAL if not valid.
There are some drivers that use tp->tv_sec and tp->tv_nsec directly to
write registers without validity checks and assume that the higher layer
has checked it, which is dangerous and will benefit from this, such as
hclge_ptp_settime(), igb_ptp_settime_i210(), _rcar_gen4_ptp_settime(),
and some drivers can remove the checks of itself.
Cc: stable@vger.kernel.org
Fixes: 0606f422b453 ("posix clocks: Introduce dynamic clocks")
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
v5:
- Update the commit message.
- Use timespec64_valid_strict() instead of timespec64_valid()
as Thomas suggested.
- Add fix tag.
v4:
- Check it in pc_clock_settime().
- Update the commit message.
v3:
- Adjust to check in more higher layer clock_settime().
- Remove the NULL check.
- Update the commit message and subject.
v2:
- Adjust to check in ptp_clock_settime().
---
kernel/time/posix-clock.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index c2f3d0c490d5..316a4e8c97d3 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -318,6 +318,9 @@ static int pc_clock_settime(clockid_t id, const struct timespec64 *ts)
goto out;
}
+ if (!timespec64_valid_strict(ts))
+ return -EINVAL;
+
if (cd.clk->ops.clock_settime)
err = cd.clk->ops.clock_settime(cd.clk, ts);
else
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v5 2/2] net: lan743x: Remove duplicate check
2024-10-08 9:10 [PATCH v5 0/2] posix-clock: Fix missing timespec64 check for PTP clock Jinjie Ruan
2024-10-08 9:11 ` [PATCH v5 1/2] posix-clock: Fix missing timespec64 check in pc_clock_settime() Jinjie Ruan
@ 2024-10-08 9:11 ` Jinjie Ruan
2024-10-08 14:58 ` [PATCH v5 0/2] posix-clock: Fix missing timespec64 check for PTP clock Richard Cochran
2024-10-08 15:18 ` Richard Cochran
3 siblings, 0 replies; 5+ messages in thread
From: Jinjie Ruan @ 2024-10-08 9:11 UTC (permalink / raw)
To: bryan.whitehead, davem, edumazet, kuba, pabeni, anna-maria,
frederic, tglx, richardcochran, johnstul, UNGLinuxDriver, netdev,
linux-kernel
Cc: ruanjinjie
Since timespec64_valid() has been checked in higher layer
pc_clock_settime(), the duplicate check in lan743x_ptpci_settime64()
can be removed.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
v4:
- Update the commit message.
v2:
- Check it in ptp core instead of using NSEC_PER_SEC macro.
- Remove the NULL check.
---
drivers/net/ethernet/microchip/lan743x_ptp.c | 35 ++++++++------------
1 file changed, 14 insertions(+), 21 deletions(-)
diff --git a/drivers/net/ethernet/microchip/lan743x_ptp.c b/drivers/net/ethernet/microchip/lan743x_ptp.c
index dcea6652d56d..4a777b449ecd 100644
--- a/drivers/net/ethernet/microchip/lan743x_ptp.c
+++ b/drivers/net/ethernet/microchip/lan743x_ptp.c
@@ -401,28 +401,21 @@ static int lan743x_ptpci_settime64(struct ptp_clock_info *ptpci,
u32 nano_seconds = 0;
u32 seconds = 0;
- if (ts) {
- if (ts->tv_sec > 0xFFFFFFFFLL ||
- ts->tv_sec < 0) {
- netif_warn(adapter, drv, adapter->netdev,
- "ts->tv_sec out of range, %lld\n",
- ts->tv_sec);
- return -ERANGE;
- }
- if (ts->tv_nsec >= 1000000000L ||
- ts->tv_nsec < 0) {
- netif_warn(adapter, drv, adapter->netdev,
- "ts->tv_nsec out of range, %ld\n",
- ts->tv_nsec);
- return -ERANGE;
- }
- seconds = ts->tv_sec;
- nano_seconds = ts->tv_nsec;
- lan743x_ptp_clock_set(adapter, seconds, nano_seconds, 0);
- } else {
- netif_warn(adapter, drv, adapter->netdev, "ts == NULL\n");
- return -EINVAL;
+ if (ts->tv_sec > 0xFFFFFFFFLL) {
+ netif_warn(adapter, drv, adapter->netdev,
+ "ts->tv_sec out of range, %lld\n",
+ ts->tv_sec);
+ return -ERANGE;
+ }
+ if (ts->tv_nsec < 0) {
+ netif_warn(adapter, drv, adapter->netdev,
+ "ts->tv_nsec out of range, %ld\n",
+ ts->tv_nsec);
+ return -ERANGE;
}
+ seconds = ts->tv_sec;
+ nano_seconds = ts->tv_nsec;
+ lan743x_ptp_clock_set(adapter, seconds, nano_seconds, 0);
return 0;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v5 0/2] posix-clock: Fix missing timespec64 check for PTP clock
2024-10-08 9:10 [PATCH v5 0/2] posix-clock: Fix missing timespec64 check for PTP clock Jinjie Ruan
2024-10-08 9:11 ` [PATCH v5 1/2] posix-clock: Fix missing timespec64 check in pc_clock_settime() Jinjie Ruan
2024-10-08 9:11 ` [PATCH v5 2/2] net: lan743x: Remove duplicate check Jinjie Ruan
@ 2024-10-08 14:58 ` Richard Cochran
2024-10-08 15:18 ` Richard Cochran
3 siblings, 0 replies; 5+ messages in thread
From: Richard Cochran @ 2024-10-08 14:58 UTC (permalink / raw)
To: Jinjie Ruan
Cc: bryan.whitehead, davem, edumazet, kuba, pabeni, anna-maria,
frederic, tglx, johnstul, UNGLinuxDriver, netdev, linux-kernel
On Tue, Oct 08, 2024 at 05:10:59PM +0800, Jinjie Ruan wrote:
> Check timespec64 in pc_clock_settime() for PTP clock as
> the man manual of clock_settime() said.
>
> Changes in v5:
> - Use timespec64_valid_strict() instead of timespec64_valid()
> as Thomas suggested.
> - Add fix tag.
> - Update the commit message.
For the series:
Acked-by: Richard Cochran <richardcochran@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5 0/2] posix-clock: Fix missing timespec64 check for PTP clock
2024-10-08 9:10 [PATCH v5 0/2] posix-clock: Fix missing timespec64 check for PTP clock Jinjie Ruan
` (2 preceding siblings ...)
2024-10-08 14:58 ` [PATCH v5 0/2] posix-clock: Fix missing timespec64 check for PTP clock Richard Cochran
@ 2024-10-08 15:18 ` Richard Cochran
3 siblings, 0 replies; 5+ messages in thread
From: Richard Cochran @ 2024-10-08 15:18 UTC (permalink / raw)
To: Jinjie Ruan
Cc: bryan.whitehead, davem, edumazet, kuba, pabeni, anna-maria,
frederic, tglx, John Stultz, UNGLinuxDriver, netdev, linux-kernel
On Tue, Oct 08, 2024 at 05:10:59PM +0800, Jinjie Ruan wrote:
> Check timespec64 in pc_clock_settime() for PTP clock as
> the man manual of clock_settime() said.
Adding John Stultz's correct email address onto CC.
Thanks,
Richard
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-10-08 15:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-08 9:10 [PATCH v5 0/2] posix-clock: Fix missing timespec64 check for PTP clock Jinjie Ruan
2024-10-08 9:11 ` [PATCH v5 1/2] posix-clock: Fix missing timespec64 check in pc_clock_settime() Jinjie Ruan
2024-10-08 9:11 ` [PATCH v5 2/2] net: lan743x: Remove duplicate check Jinjie Ruan
2024-10-08 14:58 ` [PATCH v5 0/2] posix-clock: Fix missing timespec64 check for PTP clock Richard Cochran
2024-10-08 15:18 ` Richard Cochran
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).