net: ena: PHC: Check return code before setting timestamp output
Subsystems (4)
Arthur Kiyanovski
maintainerPATCH 1/1 net: ena: PHC: Check return code before setting timestamp output
ena_phc_gettimex64() is setting the output parameter regardless of whether ena_com_phc_get_timestamp() succeeded or failed.
When ena_com_phc_get_timestamp() returns an error, the timestamp parameter may contain uninitialized stack memory (e.g., when PHC is disabled or in blocked state) or invalid hardware values. Passing these to userspace via the PTP ioctl is both a security issue (information leak) and a correctness bug.
Fix by checking the return code after releasing the lock and only setting the output timestamp on success.
--- drivers/net/ethernet/amazon/ena/ena_phc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/amazon/ena/ena_phc.c +4 -1
@@ -46,9 +46,12 @@ static int ena_phc_gettimex64(struct ptp_clock_info *clock_info,spin_unlock_irqrestore (&phc_info->lock, flags); +if (rc) +return rc; + *ts =ns_to_timespec64 (timestamp_nsec); -return rc; +return 0 ; } static int ena_phc_settime64(struct ptp_clock_info *clock_info,
Signature · 1 line
2.47.3
Quoted 25 lines · Arthur Kiyanovski
ena_phc_gettimex64()is setting the output parameter regardless of whetherena_com_phc_get_timestamp()succeeded or failed.When
ena_com_phc_get_timestamp()returns an error, the timestamp parameter may contain uninitialized stack memory (e.g., when PHC is disabled or in blocked state) or invalid hardware values. Passing these to userspace via the PTP ioctl is both a security issue (information leak) and a correctness bug.Fix by checking the return code after releasing the lock and only setting the output timestamp on success.
Fixes e0ea34158ee8 ("net: ena: Add PHC support in the ENA driver")Signed-off-by Arthur Kiyanovski <[email protected]>--- drivers/net/ethernet/amazon/ena/ena_phc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/net/ethernet/amazon/ena/ena_phc.c +0
-0@@ -46,9 +46,12 @@ static int ena_phc_gettimex64(struct ptp_clock_info *clock_info,
drivers/net/ethernet/amazon/ena/ena_phc.c static int ena_phc_gettimex64(struct ptp_clock_info *clock_info, · line 55
Quoted 10 lines
drivers/net/ethernet/amazon/ena/ena_phc.c +4
-1spin_unlock_irqrestore (&phc_info->lock, flags); +if (rc) +return rc; + *ts =ns_to_timespec64 (timestamp_nsec); -return rc; +return 0 ; }
Just an observation while reviewing - the idea of taking 2 spinlocks while reading timestamp doesn't look great and can potentially be CPU-expensive. Please, consider refactoring into RCU-style...
Kiyanovski, Arthur
maintainerQuoted 10 lines
-----Original Message-----
From: Vadim Fedorenko <[email protected]>
Sent: Thursday, May 7, 2026 3:38 AM
Subject: RE: [EXTERNAL] [PATCH net] net: ena: PHC: Check return code before setting timestamp output
...
Just an observation while reviewing - the idea of taking 2 spinlocks while reading timestamp doesn't look great and can potentially be CPU-expensive. Please, consider refactoring into RCU-style...
Noted, thanks for the review. We'll evaluate whether an RCU-based approach is appropriate here.
Arthur
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Thu, 7 May 2026 00:35:15 +0000 you wrote:
ena_phc_gettimex64()is setting the output parameter regardless of whetherena_com_phc_get_timestamp()succeeded or failed.When
ena_com_phc_get_timestamp()returns an error, the timestamp parameter may contain uninitialized stack memory (e.g., when PHC is disabled or in blocked state) or invalid hardware values. Passing these to userspace via the PTP ioctl is both a security issue (information leak) and a correctness bug.[...]
Here is the summary with links:
- [net] net: ena: PHC: Check return code before setting timestamp output
https://git.kernel.org/netdev/net/c/24a08d7d6218
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html