Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net: ena: PHC: Check return code before setting timestamp output
@ 2026-05-07  0:35 Arthur Kiyanovski
  2026-05-07 10:38 ` Vadim Fedorenko
  2026-05-12  0:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Arthur Kiyanovski @ 2026-05-07  0:35 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski, netdev
  Cc: Arthur Kiyanovski, Richard Cochran, Eric Dumazet, Paolo Abeni,
	David Woodhouse, Thomas Gleixner, Miroslav Lichvar, Andrew Lunn,
	Wen Gu, Xuan Zhuo, David Woodhouse, Yonatan Sarna,
	Zorik Machulsky, Alexander Matushevsky, Saeed Bshara, Matt Wilson,
	Anthony Liguori, Nafea Bshara, Evgeny Schmeilin, Netanel Belgazal,
	Ali Saidi, Benjamin Herrenschmidt, Noam Dagan, David Arinzon,
	Evgeny Ostrovsky, Ofir Tabachnik, Amit Bernstein, stable

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")
Cc: stable@vger.kernel.org
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_phc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_phc.c b/drivers/net/ethernet/amazon/ena/ena_phc.c
index 7867e893fd15..c2a3ff1ef645 100644
--- a/drivers/net/ethernet/amazon/ena/ena_phc.c
+++ b/drivers/net/ethernet/amazon/ena/ena_phc.c
@@ -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,
-- 
2.47.3


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

* Re: [PATCH net] net: ena: PHC: Check return code before setting timestamp output
  2026-05-07  0:35 [PATCH net] net: ena: PHC: Check return code before setting timestamp output Arthur Kiyanovski
@ 2026-05-07 10:38 ` Vadim Fedorenko
  2026-05-07 18:09   ` Kiyanovski, Arthur
  2026-05-12  0:40 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Vadim Fedorenko @ 2026-05-07 10:38 UTC (permalink / raw)
  To: Arthur Kiyanovski, David Miller, Jakub Kicinski, netdev
  Cc: Richard Cochran, Eric Dumazet, Paolo Abeni, David Woodhouse,
	Thomas Gleixner, Miroslav Lichvar, Andrew Lunn, Wen Gu, Xuan Zhuo,
	David Woodhouse, Yonatan Sarna, Zorik Machulsky,
	Alexander Matushevsky, Saeed Bshara, Matt Wilson, Anthony Liguori,
	Nafea Bshara, Evgeny Schmeilin, Netanel Belgazal, Ali Saidi,
	Benjamin Herrenschmidt, Noam Dagan, David Arinzon,
	Evgeny Ostrovsky, Ofir Tabachnik, Amit Bernstein, stable

On 07/05/2026 01:35, Arthur Kiyanovski 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.
> 
> 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")
> Cc: stable@vger.kernel.org
> Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
> ---
>   drivers/net/ethernet/amazon/ena/ena_phc.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/amazon/ena/ena_phc.c b/drivers/net/ethernet/amazon/ena/ena_phc.c
> index 7867e893fd15..c2a3ff1ef645 100644
> --- a/drivers/net/ethernet/amazon/ena/ena_phc.c
> +++ b/drivers/net/ethernet/amazon/ena/ena_phc.c
> @@ -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;
>   }

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>

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

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

* RE: [PATCH net] net: ena: PHC: Check return code before setting timestamp output
  2026-05-07 10:38 ` Vadim Fedorenko
@ 2026-05-07 18:09   ` Kiyanovski, Arthur
  0 siblings, 0 replies; 4+ messages in thread
From: Kiyanovski, Arthur @ 2026-05-07 18:09 UTC (permalink / raw)
  To: Vadim Fedorenko, David Miller, Jakub Kicinski,
	netdev@vger.kernel.org
  Cc: Richard Cochran, Eric Dumazet, Paolo Abeni, David Woodhouse,
	Thomas Gleixner, Miroslav Lichvar, Andrew Lunn, Wen Gu, Xuan Zhuo,
	Woodhouse, David, Sarna, Yuval, Machulsky, Zorik,
	Matushevsky, Alexander, Bshara, Saeed, Wilson, Matt,
	Liguori, Anthony, Bshara, Nafea, Schmeilin, Evgeny,
	Belgazal, Netanel, Saidi, Ali, Herrenschmidt, Benjamin,
	Dagan, Noam, Arinzon, David, Ostrovsky, Evgeny, Tabachnik, Ofir,
	Bernstein, Amit, stable@vger.kernel.org


> -----Original Message-----
> From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
> 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

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

* Re: [PATCH net] net: ena: PHC: Check return code before setting timestamp output
  2026-05-07  0:35 [PATCH net] net: ena: PHC: Check return code before setting timestamp output Arthur Kiyanovski
  2026-05-07 10:38 ` Vadim Fedorenko
@ 2026-05-12  0:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-05-12  0:40 UTC (permalink / raw)
  To: Arthur Kiyanovski
  Cc: davem, kuba, netdev, richardcochran, edumazet, pabeni, dwmw2,
	tglx, mlichvar, andrew+netdev, guwen, xuanzhuo, dwmw, ysarna,
	zorik, matua, saeedb, msw, aliguori, nafea, evgenys, netanel,
	alisaidi, benh, ndagan, darinzon, evostrov, ofirt, amitbern,
	stable

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-05-12  0:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-07  0:35 [PATCH net] net: ena: PHC: Check return code before setting timestamp output Arthur Kiyanovski
2026-05-07 10:38 ` Vadim Fedorenko
2026-05-07 18:09   ` Kiyanovski, Arthur
2026-05-12  0:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox