ptp: guard ptp_clock_gettime() if neither gettimex64 nor
Subsystems (3)
PATCH 1/1 ptp: guard ptp_clock_gettime() if neither gettimex64 nor
Syzbot reports a NULL function pointer call on arm64 when ptp_clock_gettime() falls back to ->gettime64() and the driver provides neither ->gettimex64() nor ->gettime64(). This leads to a crash in the posix clock gettime path.
Return -EOPNOTSUPP when both callbacks are missing, avoiding the crash and matching the defensive style used in the posix clock layer.
--- drivers/ptp/ptp_clock.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(
drivers/ptp/ptp_clock.c +6 -4
@@ -110,12 +110,14 @@ static int ptp_clock_settime(struct posix_clock *pc, const struct timespec64 *tpstatic int ptp_clock_gettime (struct posix_clock *pc,struct timespec64 *tp) { struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); -int err; +int err = -EOPNOTSUPP ;if (ptp->info->gettimex64) - err = ptp->info->gettimex64 (ptp->info, tp,NULL ); -else - err = ptp->info->gettime64 (ptp->info, tp); +return ptp->info->gettimex64 (ptp->info, tp,NULL ); + +if (ptp->info->gettime64) +return ptp->info->gettime64 (ptp->info, tp); +return err; }
Signature · 1 line
2.43.0
Quoted 27 lines · Junjie Cao
Syzbot reports a NULL function pointer call on arm64 when
ptp_clock_gettime()falls back to ->gettime64() and the driver provides neither ->gettimex64() nor ->gettime64(). This leads to a crash in the posix clock gettime path.Return
-EOPNOTSUPPwhen both callbacks are missing, avoiding the crash and matching the defensive style used in the posix clock layer.Reported-by [email protected]Signed-off-by Junjie Cao <[email protected]>--- drivers/ptp/ptp_clock.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(drivers/ptp/ptp_clock.c +1
-1@@ -110,12 +110,14 @@ static int ptp_clock_settime(struct posix_clock *pc, const struct timespec64 *tpstatic int ptp_clock_gettime (struct posix_clock *pc,struct timespec64 *tp) { struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); -int err; +int err = -EOPNOTSUPP ;if (ptp->info->gettimex64)
drivers/ptp/ptp_clock.c static int ptp_clock_settime(struct posix_clock *pc, const struct timespec64 *tp · line 122
Quoted 10 lines
drivers/ptp/ptp_clock.c +5
-3- err = ptp->info->gettimex64 (ptp->info, tp,NULL ); - else - err = ptp->info->gettime64 (ptp->info, tp); +return ptp->info->gettimex64 (ptp->info, tp,NULL ); + +if (ptp->info->gettime64) +return ptp->info->gettime64 (ptp->info, tp); +return err; }
Patch looks valid to me. But a similar situation exists right above this function where ptp_clock_settime() is calling ptp->info->settime64() unconditionally.
Maybe that can be guarded also?
Also this looks like a patch meant for "net" with an improved title IMO.
Quoted 5 lines
drivers/ptp/ptp_clock.c +0
-1--2.43.0
Richard Cochran
maintainerQuoted 4 lines · Junjie Cao
Syzbot reports a NULL function pointer call on arm64 when
ptp_clock_gettime()falls back to ->gettime64() and the driver provides neither ->gettimex64() nor ->gettime64(). This leads to a crash in the posix clock gettime path.
Drivers must provide a gettime method.
If they do not, then that is a bug in the driver.
Thanks,
Richard
From: Richard Cochran <[email protected]>
Date: Tue, 28 Oct 2025 07:09:41 -0700
Quoted 9 lines · Junjie Cao
Quoted 4 lines
Syzbot reports a NULL function pointer call on arm64 when
ptp_clock_gettime()falls back to ->gettime64() and the driver provides neither ->gettimex64() nor ->gettime64(). This leads to a crash in the posix clock gettime path.Drivers must provide a gettime method.
If they do not, then that is a bug in the driver.
AFAICT, only GVE does not have gettime() and settime(), and Tim (CCed) was preparing a fix and mostly ready to post it.
Jakub Kicinski
maintainerQuoted 8 lines · On Tue, 28 Oct 2025 15:51:50 +0000 Kuniyuki Iwashima wrote:
From: Richard Cochran <[email protected]>
Date: Tue, 28 Oct 2025 07:09:41 -0700Quoted 6 lines · Junjie Cao
Quoted 4 lines
Syzbot reports a NULL function pointer call on arm64 when
ptp_clock_gettime()falls back to ->gettime64() and the driver provides neither ->gettimex64() nor ->gettime64(). This leads to a crash in the posix clock gettime path.
Quoted 6 lines
Quoted 3 lines
Drivers must provide a gettime method.
If they do not, then that is a bug in the driver.
AFAICT, only GVE does not have
gettime()andsettime(), and Tim (CCed) was preparing a fix and mostly ready to post it.
cc: Vadim who promised me a PTP driver test :) Let's make sure we tickle gettime/setting in that test..
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · On Tue, 28 Oct 2025 15:51:50 +0000 Kuniyuki Iwashima wrote:
From: Richard Cochran <[email protected]>
Date: Tue, 28 Oct 2025 07:09:41 -0700Quoted 8 lines · Junjie Cao
Quoted 4 lines
Syzbot reports a NULL function pointer call on arm64 when
ptp_clock_gettime()falls back to ->gettime64() and the driver provides neither ->gettimex64() nor ->gettime64(). This leads to a crash in the posix clock gettime path.Drivers must provide a gettime method.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
If they do not, then that is a bug in the driver.
AFAICT, only GVE does not have
gettime()andsettime(), and Tim (CCed) was preparing a fix and mostly ready to post it.cc: Vadim who promised me a PTP driver test :) Let's make sure we tickle gettime/setting in that test..
Heh, call gettime/settime is easy. But in case of absence of these callbacks the kernel will crash - not sure we can gather good signal in such case?
Quoted 15 lines · Vadim Fedorenko
Quoted 13 lines · Jakub Kicinski
Quoted 12 lines · On Tue, 28 Oct 2025 15:51:50 +0000 Kuniyuki Iwashima wrote:
From: Richard Cochran <[email protected]>
Date: Tue, 28 Oct 2025 07:09:41 -0700Quoted 9 lines · Junjie Cao
Quoted 4 lines
Syzbot reports a NULL function pointer call on arm64 when
ptp_clock_gettime()falls back to ->gettime64() and the driver provides neither ->gettimex64() nor ->gettime64(). This leads to a crash in the posix clock gettime path.Drivers must provide a gettime method.
If they do not, then that is a bug in the driver.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
AFAICT, only GVE does not have
gettime()andsettime(), and Tim (CCed) was preparing a fix and mostly ready to post it.cc: Vadim who promised me a PTP driver test :) Let's make sure we tickle gettime/setting in that test..
Heh, call gettime/settime is easy. But in case of absence of these callbacks the kernel will crash - not sure we can gather good signal in such case?
At least we could catch it on NIPA.
but I suggested Tim adding WARN_ON_ONCE(!info->gettime64 && !info-> getimex64) in ptp_clock_register() so that a developer can notice that even while loading a buggy module.
Quoted 24 lines · Kuniyuki Iwashima
Quoted 21 lines · Vadim Fedorenko
Quoted 18 lines · Jakub Kicinski
Quoted 8 lines · On Tue, 28 Oct 2025 15:51:50 +0000 Kuniyuki Iwashima wrote:
From: Richard Cochran <[email protected]>
Date: Tue, 28 Oct 2025 07:09:41 -0700Quoted 6 lines · Junjie Cao
Quoted 4 lines
Syzbot reports a NULL function pointer call on arm64 when
ptp_clock_gettime()falls back to ->gettime64() and the driver provides neither ->gettimex64() nor ->gettime64(). This leads to a crash in the posix clock gettime path.Quoted 6 lines
Quoted 3 lines
Drivers must provide a gettime method.
If they do not, then that is a bug in the driver.
AFAICT, only GVE does not have
gettime()andsettime(), and Tim (CCed) was preparing a fix and mostly ready to post it.cc: Vadim who promised me a PTP driver test :) Let's make sure we tickle gettime/setting in that test..
Quoted 8 lines
Quoted 2 lines
Heh, call gettime/settime is easy. But in case of absence of these callbacks the kernel will crash - not sure we can gather good signal in such case?
At least we could catch it on NIPA.
but I suggested Tim adding
WARN_ON_ONCE(!info->gettime64 && !info-> getimex64)inptp_clock_register()so that a developer can notice that even while loading a buggy module.
Of course this needs to check settime too.
Quoted 23 lines · Kuniyuki Iwashima
Quoted 21 lines · Vadim Fedorenko
Quoted 18 lines · Jakub Kicinski
Quoted 8 lines · On Tue, 28 Oct 2025 15:51:50 +0000 Kuniyuki Iwashima wrote:
From: Richard Cochran <[email protected]>
Date: Tue, 28 Oct 2025 07:09:41 -0700Quoted 6 lines · Junjie Cao
Quoted 4 lines
Syzbot reports a NULL function pointer call on arm64 when
ptp_clock_gettime()falls back to ->gettime64() and the driver provides neither ->gettimex64() nor ->gettime64(). This leads to a crash in the posix clock gettime path.Quoted 6 lines
Quoted 3 lines
Drivers must provide a gettime method.
If they do not, then that is a bug in the driver.
AFAICT, only GVE does not have
gettime()andsettime(), and Tim (CCed) was preparing a fix and mostly ready to post it.cc: Vadim who promised me a PTP driver test :) Let's make sure we tickle gettime/setting in that test..
Quoted 8 lines
Quoted 2 lines
Heh, call gettime/settime is easy. But in case of absence of these callbacks the kernel will crash - not sure we can gather good signal in such case?
At least we could catch it on NIPA.
but I suggested Tim adding
WARN_ON_ONCE(!info->gettime64 && !info-> getimex64)inptp_clock_register()so that a developer can notice that even while loading a buggy module.
Yeah, that looks like a solution
Quoted 28 lines · Vadim Fedorenko
Quoted 26 lines · Kuniyuki Iwashima
Quoted 23 lines · Vadim Fedorenko
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · On Tue, 28 Oct 2025 15:51:50 +0000 Kuniyuki Iwashima wrote:
From: Richard Cochran <[email protected]>
Date: Tue, 28 Oct 2025 07:09:41 -0700Quoted 8 lines · Junjie Cao
Quoted 4 lines
Syzbot reports a NULL function pointer call on arm64 when
ptp_clock_gettime()falls back to ->gettime64() and the driver provides neither ->gettimex64() nor ->gettime64(). This leads to a crash in the posix clock gettime path.Drivers must provide a gettime method.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
If they do not, then that is a bug in the driver.
AFAICT, only GVE does not have
gettime()andsettime(), and Tim (CCed) was preparing a fix and mostly ready to post it.cc: Vadim who promised me a PTP driver test :) Let's make sure we tickle gettime/setting in that test..
Heh, call gettime/settime is easy. But in case of absence of these callbacks the kernel will crash - not sure we can gather good signal in such case?
Quoted 7 lines
Quoted 5 lines
At least we could catch it on NIPA.
but I suggested Tim adding
WARN_ON_ONCE(!info->gettime64 && !info-> getimex64)inptp_clock_register()so that a developer can notice that even while loading a buggy module.Yeah, that looks like a solution
Yes, I was actually going to post the fix to gve today (I'll still do that as ptp_clock_gettime() is not the only function to assume a gettime64 or gettimex64 implementation) and shortly after posting Kuniyuki's suggested fix to ptp_clock_register() as such:
drivers/ptp/ptp_clock.c +0 -0
@@ -325,6 +325,9 @@ struct ptp_clock *ptp_clock_register(struct
ptp_clock_info *info,
if (info->n_alarm > PTP_MAX_ALARMS)
return ERR_PTR(-EINVAL);+ if (WARN_ON_ONCE(!info->gettimex64 && !info->gettime64))
+ return ERR_PTR(-EINVAL);
+
/* Initialize a clock structure. */
ptp = kzalloc(sizeof(struct ptp_clock), GFP_KERNEL);
if (!ptp) {--
I also have a similar patch for checking for settime64's function pointer.
But I have no objections to Junjie posting a v2 in this manner instead of waiting for me.
Quoted 58 lines · Tim Hostetler
Quoted 28 lines · Vadim Fedorenko
Quoted 26 lines · Kuniyuki Iwashima
Quoted 23 lines · Vadim Fedorenko
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · On Tue, 28 Oct 2025 15:51:50 +0000 Kuniyuki Iwashima wrote:
From: Richard Cochran <[email protected]>
Date: Tue, 28 Oct 2025 07:09:41 -0700Quoted 8 lines · Junjie Cao
Quoted 4 lines
Syzbot reports a NULL function pointer call on arm64 when
ptp_clock_gettime()falls back to ->gettime64() and the driver provides neither ->gettimex64() nor ->gettime64(). This leads to a crash in the posix clock gettime path.Drivers must provide a gettime method.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
If they do not, then that is a bug in the driver.
AFAICT, only GVE does not have
gettime()andsettime(), and Tim (CCed) was preparing a fix and mostly ready to post it.cc: Vadim who promised me a PTP driver test :) Let's make sure we tickle gettime/setting in that test..
Heh, call gettime/settime is easy. But in case of absence of these callbacks the kernel will crash - not sure we can gather good signal in such case?
Quoted 7 lines
Quoted 5 lines
At least we could catch it on NIPA.
but I suggested Tim adding
WARN_ON_ONCE(!info->gettime64 && !info-> getimex64)inptp_clock_register()so that a developer can notice that even while loading a buggy module.Yeah, that looks like a solution
Yes, I was actually going to post the fix to gve today (I'll still do that as
ptp_clock_gettime()is not the only function to assume a gettime64 or gettimex64 implementation) and shortly after posting Kuniyuki's suggested fix toptp_clock_register()as such:drivers/ptp/ptp_clock.c +3
-0@@ -325,6 +325,9 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, if (info->n_alarm > PTP_MAX_ALARMS)return ERR_PTR (-EINVAL ); +if (WARN_ON_ONCE (!info->gettimex64 && !info->gettime64)) +return ERR_PTR (-EINVAL ); +/* Initialize a clock structure. */ ptp =kzalloc (sizeof (struct ptp_clock ),GFP_KERNEL );if (!ptp) {
Quoted 6 lines
--
I also have a similar patch for checking for settime64's function pointer.
But I have no objections to Junjie posting a v2 in this manner instead of waiting for me.
WARN_ON_ONCE is better in terms of reducing the amount of review work. Driver developers will be automatically notified about improper implementation while Junjie's patch will simply hide the problem.