netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ptp: guard ptp_clock_gettime() if neither gettimex64 nor
@ 2025-10-28  9:51 Junjie Cao
  2025-10-28 12:58 ` Pavan Chebbi
  2025-10-28 14:09 ` Richard Cochran
  0 siblings, 2 replies; 11+ messages in thread
From: Junjie Cao @ 2025-10-28  9:51 UTC (permalink / raw)
  To: Richard Cochran, Andrew Lunn, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, syzkaller-bugs, Junjie Cao,
	syzbot+c8c0e7ccabd456541612

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.

Reported-by: syzbot+c8c0e7ccabd456541612@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c8c0e7ccabd456541612
Signed-off-by: Junjie Cao <junjie.cao@intel.com>
---
 drivers/ptp/ptp_clock.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(
diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index ef020599b771..764bd25220c1 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -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;
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-10-29 18:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-28  9:51 [PATCH] ptp: guard ptp_clock_gettime() if neither gettimex64 nor Junjie Cao
2025-10-28 12:58 ` Pavan Chebbi
2025-10-28 14:09 ` Richard Cochran
2025-10-28 15:51   ` Kuniyuki Iwashima
2025-10-28 23:13     ` Jakub Kicinski
2025-10-28 23:45       ` Vadim Fedorenko
2025-10-28 23:54         ` Kuniyuki Iwashima
2025-10-28 23:56           ` Kuniyuki Iwashima
2025-10-28 23:56           ` Vadim Fedorenko
2025-10-29 16:37             ` Tim Hostetler
2025-10-29 18:55               ` Vadim Fedorenko

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).