Skip to contentSkip to conversation

ptp: guard ptp_clock_gettime() if neither gettimex64 nor

PATCH In review Junjie Cao 7 participants 11 messages Oct 28, 2025 – Oct 29, 2025

Subsystems (3)
lore
Share & tools
lore

Junjie Cao

author
#0 lore raw

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
index ef020599b771..764bd25220c1 100644
@@ -110,12 +110,14 @@ static int ptp_clock_settime(struct posix_clock *pc, const struct timespec64 *tp
 static 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
#1 lore raw
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 -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 +1 -1
index ef020599b771..764bd25220c1 100644
@@ -110,12 +110,14 @@ static int ptp_clock_settime(struct posix_clock *pc, const struct timespec64 *tp
 static 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

maintainer
#2 lore raw
In reply to Junjie Cao
Quoted 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

#3 lore raw

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.

maintainer
#4 lore raw
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 -0700

Quoted 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() and settime(), 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..

#5 lore raw
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 -0700

Quoted 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() and settime(), 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?

#6 lore raw
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 -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.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

AFAICT, only GVE does not have gettime() and settime(), 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.

#7 lore raw
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 -0700

Quoted 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() and settime(), 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) in ptp_clock_register() so that a developer can notice that even while loading a buggy module.

Of course this needs to check settime too.

#8 lore raw
In reply to Kuniyuki Iwashima
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 -0700

Quoted 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() and settime(), 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) in ptp_clock_register() so that a developer can notice that even while loading a buggy module.

Yeah, that looks like a solution

#9 lore raw
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 -0700

Quoted 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() and settime(), 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) in ptp_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
index ef020599b771..f2d9cf4a455e 100644
@@ -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.

#10 lore raw
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 -0700

Quoted 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() and settime(), 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) in ptp_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 +3 -0
index ef020599b771..f2d9cf4a455e 100644
@@ -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.