* [PATCH -next v4 0/2] posix-clock: Check timespec64 for PTP clock @ 2024-09-14 10:06 Jinjie Ruan 2024-09-14 10:06 ` [PATCH -next v4 1/2] posix-clock: Check timespec64 before call clock_settime() Jinjie Ruan 2024-09-14 10:06 ` [PATCH -next v4 2/2] net: lan743x: Remove duplicate check Jinjie Ruan 0 siblings, 2 replies; 7+ messages in thread From: Jinjie Ruan @ 2024-09-14 10:06 UTC (permalink / raw) To: bryan.whitehead, davem, edumazet, kuba, pabeni, anna-maria, frederic, tglx, richardcochran, UNGLinuxDriver, mbenes, jstultz, andrew, netdev, linux-kernel Cc: ruanjinjie Check timespec64 in pc_clock_settime() for PTP clock. 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: Check timespec64 before call 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] 7+ messages in thread
* [PATCH -next v4 1/2] posix-clock: Check timespec64 before call clock_settime() 2024-09-14 10:06 [PATCH -next v4 0/2] posix-clock: Check timespec64 for PTP clock Jinjie Ruan @ 2024-09-14 10:06 ` Jinjie Ruan 2024-09-14 15:23 ` Simon Horman 2024-10-02 15:22 ` Thomas Gleixner 2024-09-14 10:06 ` [PATCH -next v4 2/2] net: lan743x: Remove duplicate check Jinjie Ruan 1 sibling, 2 replies; 7+ messages in thread From: Jinjie Ruan @ 2024-09-14 10:06 UTC (permalink / raw) To: bryan.whitehead, davem, edumazet, kuba, pabeni, anna-maria, frederic, tglx, richardcochran, UNGLinuxDriver, mbenes, jstultz, andrew, 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 mannul of clock_settime() said, if tp.tv_sec is negative or tp.tv_nsec is outside the range [0..999,999,999], it shuld return EINVAL, which include Dynamic clocks which handles PTP clock, and the condition is consistent with timespec64_valid(). So check it ahead using timespec64_valid() 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. Suggested-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> --- 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 4782edcbe7b9..89e39f9bd7ae 100644 --- a/kernel/time/posix-clock.c +++ b/kernel/time/posix-clock.c @@ -319,6 +319,9 @@ static int pc_clock_settime(clockid_t id, const struct timespec64 *ts) goto out; } + if (!timespec64_valid(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] 7+ messages in thread
* Re: [PATCH -next v4 1/2] posix-clock: Check timespec64 before call clock_settime() 2024-09-14 10:06 ` [PATCH -next v4 1/2] posix-clock: Check timespec64 before call clock_settime() Jinjie Ruan @ 2024-09-14 15:23 ` Simon Horman 2024-10-02 15:18 ` Thomas Gleixner 2024-10-02 15:22 ` Thomas Gleixner 1 sibling, 1 reply; 7+ messages in thread From: Simon Horman @ 2024-09-14 15:23 UTC (permalink / raw) To: Jinjie Ruan Cc: bryan.whitehead, davem, edumazet, kuba, pabeni, anna-maria, frederic, tglx, richardcochran, UNGLinuxDriver, mbenes, jstultz, andrew, netdev, linux-kernel On Sat, Sep 14, 2024 at 06:06:24PM +0800, Jinjie Ruan wrote: > 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 mannul of clock_settime() said, if tp.tv_sec is negative or > tp.tv_nsec is outside the range [0..999,999,999], it shuld return EINVAL, nit: should Flagged by checkpatch.pl --codespell ... ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH -next v4 1/2] posix-clock: Check timespec64 before call clock_settime() 2024-09-14 15:23 ` Simon Horman @ 2024-10-02 15:18 ` Thomas Gleixner 0 siblings, 0 replies; 7+ messages in thread From: Thomas Gleixner @ 2024-10-02 15:18 UTC (permalink / raw) To: Simon Horman, Jinjie Ruan Cc: bryan.whitehead, davem, edumazet, kuba, pabeni, anna-maria, frederic, richardcochran, UNGLinuxDriver, mbenes, jstultz, andrew, netdev, linux-kernel On Sat, Sep 14 2024 at 16:23, Simon Horman wrote: > On Sat, Sep 14, 2024 at 06:06:24PM +0800, Jinjie Ruan wrote: >> 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 mannul of clock_settime() said, if tp.tv_sec is negative or >> tp.tv_nsec is outside the range [0..999,999,999], it shuld return EINVAL, > > nit: should > > Flagged by checkpatch.pl --codespell ... man mannul Flagged by my taste sensors. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH -next v4 1/2] posix-clock: Check timespec64 before call clock_settime() 2024-09-14 10:06 ` [PATCH -next v4 1/2] posix-clock: Check timespec64 before call clock_settime() Jinjie Ruan 2024-09-14 15:23 ` Simon Horman @ 2024-10-02 15:22 ` Thomas Gleixner 1 sibling, 0 replies; 7+ messages in thread From: Thomas Gleixner @ 2024-10-02 15:22 UTC (permalink / raw) To: Jinjie Ruan, bryan.whitehead, davem, edumazet, kuba, pabeni, anna-maria, frederic, richardcochran, UNGLinuxDriver, mbenes, jstultz, andrew, netdev, linux-kernel Cc: ruanjinjie On Sat, Sep 14 2024 at 18:06, Jinjie Ruan wrote: > 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 mannul of clock_settime() said, if tp.tv_sec is negative or > tp.tv_nsec is outside the range [0..999,999,999], it shuld return EINVAL, > which include Dynamic clocks which handles PTP clock, and the condition is > consistent with timespec64_valid(). So check it ahead using > timespec64_valid() 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. > + if (!timespec64_valid(ts)) > + return -EINVAL; This just makes sure, that the timespec is valid. But it does not ensure that the time is in a valid range. This should at least use timespec64_valid_strict() if not timespec64_valid_gettod(). Thanks, tglx ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH -next v4 2/2] net: lan743x: Remove duplicate check 2024-09-14 10:06 [PATCH -next v4 0/2] posix-clock: Check timespec64 for PTP clock Jinjie Ruan 2024-09-14 10:06 ` [PATCH -next v4 1/2] posix-clock: Check timespec64 before call clock_settime() Jinjie Ruan @ 2024-09-14 10:06 ` Jinjie Ruan 2024-09-14 13:56 ` Jakub Kicinski 1 sibling, 1 reply; 7+ messages in thread From: Jinjie Ruan @ 2024-09-14 10:06 UTC (permalink / raw) To: bryan.whitehead, davem, edumazet, kuba, pabeni, anna-maria, frederic, tglx, richardcochran, UNGLinuxDriver, mbenes, jstultz, andrew, 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] 7+ messages in thread
* Re: [PATCH -next v4 2/2] net: lan743x: Remove duplicate check 2024-09-14 10:06 ` [PATCH -next v4 2/2] net: lan743x: Remove duplicate check Jinjie Ruan @ 2024-09-14 13:56 ` Jakub Kicinski 0 siblings, 0 replies; 7+ messages in thread From: Jakub Kicinski @ 2024-09-14 13:56 UTC (permalink / raw) To: Jinjie Ruan Cc: bryan.whitehead, davem, edumazet, pabeni, anna-maria, frederic, tglx, richardcochran, UNGLinuxDriver, mbenes, jstultz, andrew, netdev, linux-kernel On Sat, 14 Sep 2024 18:06:25 +0800 Jinjie Ruan wrote: > Since timespec64_valid() has been checked in higher layer > pc_clock_settime(), the duplicate check in lan743x_ptpci_settime64() > can be removed. net-next is closed until the end of the 6.12 merge window: https://lore.kernel.org/all/20240912181222.2dd75818@kernel.org/ please repost when it reopens -- pw-bot: defer ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-10-02 15:22 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-09-14 10:06 [PATCH -next v4 0/2] posix-clock: Check timespec64 for PTP clock Jinjie Ruan 2024-09-14 10:06 ` [PATCH -next v4 1/2] posix-clock: Check timespec64 before call clock_settime() Jinjie Ruan 2024-09-14 15:23 ` Simon Horman 2024-10-02 15:18 ` Thomas Gleixner 2024-10-02 15:22 ` Thomas Gleixner 2024-09-14 10:06 ` [PATCH -next v4 2/2] net: lan743x: Remove duplicate check Jinjie Ruan 2024-09-14 13:56 ` Jakub Kicinski
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).