From: Thomas Gleixner <tglx@linutronix.de>
To: Jinjie Ruan <ruanjinjie@huawei.com>,
bryan.whitehead@microchip.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
anna-maria@linutronix.de, frederic@kernel.org,
richardcochran@gmail.com, UNGLinuxDriver@microchip.com,
mbenes@suse.cz, jstultz@google.com, andrew@lunn.ch,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: ruanjinjie@huawei.com
Subject: Re: [PATCH -next v4 1/2] posix-clock: Check timespec64 before call clock_settime()
Date: Wed, 02 Oct 2024 17:22:29 +0200 [thread overview]
Message-ID: <87ldz6wmve.ffs@tglx> (raw)
In-Reply-To: <20240914100625.414013-2-ruanjinjie@huawei.com>
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
next prev parent reply other threads:[~2024-10-02 15:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2024-09-14 10:06 ` [PATCH -next v4 2/2] net: lan743x: Remove duplicate check Jinjie Ruan
2024-09-14 13:56 ` Jakub Kicinski
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=87ldz6wmve.ffs@tglx \
--to=tglx@linutronix.de \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=anna-maria@linutronix.de \
--cc=bryan.whitehead@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=frederic@kernel.org \
--cc=jstultz@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=ruanjinjie@huawei.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;
as well as URLs for NNTP newsgroup(s).