Skip to content

[Bug]: ptp_clock_info in ena 2.13 is missing .adjfine  #322

Open
@gemorin

Description

Preliminary Actions

Driver Type

Linux kernel driver for Elastic Network Adapter (ENA)

Driver Tag/Commit

ena 2.13.0

Custom Code

No

OS Platform and Distribution

Linux 6.2+ with ena.phc_enable=1

Bug description

Starting from Linux 6.2 (commit 75ab70ec5cef), .adjfine (introduced in 4.10) is required in struct ptp_clock_info and will trigger a NULL pointer dereference in (at least) ptp_clock_adjtime()

testing this change:

--- a/kernel/linux/ena/ena_phc.c
+++ b/kernel/linux/ena/ena_phc.c
@@ -15,6 +15,15 @@ static int ena_phc_adjfreq(struct ptp_cl
 }
 
 #endif /* ENA_PHC_SUPPORT_ADJFREQ */
+
+#ifdef ENA_PHC_SUPPORT_ADJFINE
+static int ena_phc_adjfine(struct ptp_clock_info *clock_info, long delta)
+{
+       return -EOPNOTSUPP;
+}
+
+#endif /* ENA_PHC_SUPPORT_ADJFINE */
+
 static int ena_phc_adjtime(struct ptp_clock_info *clock_info, s64 delta)
 {
        return -EOPNOTSUPP;
@@ -113,6 +122,9 @@ static struct ptp_clock_info ena_ptp_clo
 #ifdef ENA_PHC_SUPPORT_ADJFREQ
        .adjfreq        = ena_phc_adjfreq,
 #endif /* ENA_PHC_SUPPORT_ADJFREQ */
+#ifdef ENA_PHC_SUPPORT_ADJFINE
+       .adjfine        = ena_phc_adjfine,
+#endif /* ENA_PHC_SUPPORT_ADJFINE */
        .adjtime        = ena_phc_adjtime,
 #ifdef ENA_PHC_SUPPORT_GETTIME64
 #ifdef ENA_PHC_SUPPORT_GETTIME64_EXTENDED
--- a/kernel/linux/ena/kcompat.h
+++ b/kernel/linux/ena/kcompat.h
@@ -995,6 +995,10 @@ static inline bool ktime_after(const kti
 #define ptp_clock_register(info, parent) ptp_clock_register(info)
 #endif
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
+#define ENA_PHC_SUPPORT_ADJFINE
+#endif /* ENA_PHC_SUPPORT_ADJFINE */
+
 #endif /* CONFIG_PTP_1588_CLOCK */
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)) && \

Reproduction steps

1. boot a Linux 6.2+ kernel

Expected Behavior

not crash

Actual Behavior

crash :-)

Additional Data

No response

Relevant log output

abbreviated kernel log:

BUG: kernel NULL pointer dereference, address: 0000000000000000
#PF: supervisor instruction fetch in kernel mode
#PF: error_code(0x0010) - not-present page
PGD 149927067 P4D 149927067 PUD 143ccf067 PMD 0 
Oops: 0010 [#1] SMP NOPTI
CPU: 0 PID: 9217 Comm: t Tainted: G           O        #1
Hardware name: Amazon EC2/Not Specified, BIOS 1.0 10/16/2017
RIP: 0010:0x0
Code: Unable to access opcode bytes at 0xffffffffffffffd6.
Call Trace:
 <TASK>
 ptp_clock_adjtime+0xd1/0x1d0
 pc_clock_adjtime+0x5b/0xa0
 __do_sys_clock_adjtime+0x8a/0x110
 __x64_sys_clock_adjtime+0x16/0x20
 x64_sys_call+0x1321/0x2020
 do_syscall_64+0x33/0x80
 entry_SYSCALL_64_after_hwframe+0x78/0xe2

Contact Details

[email protected]

Metadata

Assignees

No one assigned

    Labels

    Linux ENA driverbugReport errors or unexpected behaviortriageDetermine the priority and severity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions