From: Xuanqiang Luo <xuanqiang.luo@linux.dev>
To: Vadim Fedorenko <vadim.fedorenko@linux.dev>,
netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>
Cc: richardcochran@gmail.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
arnd@arndb.de, john.stultz@linaro.org, jacob.e.keller@intel.com,
linux-kernel@vger.kernel.org,
Xuanqiang Luo <luoxuanqiang@kylinos.cn>,
stable@vger.kernel.org
Subject: Re: [PATCH net v1] ptp: fix NULL deref when adjtime/adjfine are missing
Date: Thu, 27 Aug 2026 14:43:31 +0800 [thread overview]
Message-ID: <ba8e71ce-42e2-4c92-b7c8-dd6ce900a5d4@linux.dev> (raw)
In-Reply-To: <e9c97286-d121-40ca-b6f1-4c63641e7283@linux.dev>
Hi Vadim
在 2026/8/26 20:24, Vadim Fedorenko 写道:
> On 26/08/2026 11:10, Xuanqiang Luo wrote:
>> From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
>>
>> ptp_clock_adjtime() invokes ->adjtime and ->adjfine unconditionally,
>> but both callbacks are optional.
>
> Could you please link to the source of this statement?
>
Ah, I noticed that ops->adjphase is checked for NULL, while
ops->adjtime and ops->adjfine are not. I then found that the iavf
driver does not register either callback, making the NULL-dereference
paths reachable. This led me to believe that these callbacks were
optional.
However, the PTP hardware clock documentation explicitly states:
Clock drivers must implement all of the functions in the interface. If
a clock does not offer a particular ancillary feature, then the driver
should just return -EOPNOTSUPP from those functions.
Link: https://docs.kernel.org/driver-api/ptp.html#writing-clock-drivers
Therefore, iavf does not comply with this requirement, and fixing the
issue in the iavf driver is more appropriate.
Thank you for pointing this out, Vadim.
> clock_adjtime() with ADJ_SETOFFSET
>> or ADJ_FREQUENCY therefore oopses on a PHC that implements neither.
>>
>> iavf registers such a read-only clock: no adjtime/adjfine, and
>> max_adj left at 0. ADJ_SETOFFSET hits the NULL ->adjtime after the
>> offset is validated. ADJ_FREQUENCY with freq 0 converts to 0 ppb,
>> passes the max_adj check, and hits the NULL ->adjfine.
>>
>> Return -EOPNOTSUPP when the requested callback is missing, as the
>> adjphase path already does, rather than adding driver stubs.
>
> If PHC does not implement adjtime/adjfine/adjphase then it is a free-
> running clock. ptp_clock_adjtime() has the check for such clocks.
> To properly fix core part we have to extend ptp_clock and/or
> ptp_clock_info to properly signal that registered clock is
> free-running/read-only.
I understand your suggestion. However, I plan to fix the iavf driver
by providing the missing callbacks and returning -EOPNOTSUPP, as
required by the PTP documentation.
An explicit free-running/read-only state would only cover PHCs with no
adjustment callbacks at all. It would not cover PHCs that implement only
a subset of the adjustment callbacks. Marking those clocks as
free-running would also incorrectly reject operations that they do
support.
Therefore, I think a driver-side fix is more appropriate for this case.
I will revise the patch to fix iavf accordingly.
Thank you very much for your comments!
BRs,
Xuanqiang
next prev parent reply other threads:[~2026-08-27 6:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 10:10 [PATCH net v1] ptp: fix NULL deref when adjtime/adjfine are missing Xuanqiang Luo
2026-08-26 12:24 ` Vadim Fedorenko
2026-08-27 6:43 ` Xuanqiang Luo [this message]
2026-08-31 18:01 ` Richard Cochran
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=ba8e71ce-42e2-4c92-b7c8-dd6ce900a5d4@linux.dev \
--to=xuanqiang.luo@linux.dev \
--cc=andrew+netdev@lunn.ch \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jacob.e.keller@intel.com \
--cc=john.stultz@linaro.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luoxuanqiang@kylinos.cn \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=stable@vger.kernel.org \
--cc=vadim.fedorenko@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.