Skip to contentSkip to conversation

net: ena: PHC: Check return code before setting timestamp output

PATCH Applied Arthur Kiyanovski 3 participants 4 messages May 7 – May 12

Subsystems (4)
lore
Share & tools
lore

Arthur Kiyanovski

author maintainer
#0 lore raw

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

Fixes e0ea34158ee8 ("net: ena: Add PHC support in the ENA driver")
---
 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
index 7867e893fd15..c2a3ff1ef645 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Arthur Kiyanovski

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.

Fixes e0ea34158ee8 ("net: ena: Add PHC support in the ENA driver")
---
  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
index 7867e893fd15..c2a3ff1ef645 100644
@@ -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 -1
  	spin_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...

author maintainer
#2 lore raw
Quoted 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

#3 lore raw
In reply to Arthur Kiyanovski
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 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.

[...]

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