[PATCH net v1 2/3] af_packet: use skb_get_hwtstamp() for hardware timestamps

Kohei Enju
2026-04-29T09:16:45Z

Since commit 97dc7cd92ac6 ("ptp: Support late timestamp determination"),
skb_shared_hwtstamps may contain netdev_data instead of hwtstamp.
tpacket_get_timestamp() unconditionally interprets skb_shared_hwtstamps
as a resolved hardware timestamp, and can report bogus hardware
timestamps to userspace.

Use skb_get_hwtstamp() instead of reading hwtstamp directly, so packet
sockets follow the same hardware timestamp resolution path as the socket
layer.

Note that skb_get_hwtstamp() is called with cycles == false, since
AF_PACKET hasn't honored SOF_TIMESTAMPING_BIND_PHC so far, and this
patch doesn't change that behavior.

Fixes: 97dc7cd92ac6 ("ptp: Support late timestamp determination")
Signed-off-by: Kohei Enju <kohei@enjuk.jp>
---
net/packet/af_packet.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 8e6f3a734ba0..e88bc3f1156f 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -458,7 +458,7 @@ static __u32 tpacket_get_timestamp(struct sk_buff *skb, struct timespec64 *ts,

if (shhwtstamps &&
(flags & SOF_TIMESTAMPING_RAW_HARDWARE) &&
- ktime_to_timespec64_cond(shhwtstamps->hwtstamp, ts))
+ ktime_to_timespec64_cond(skb_get_hwtstamp(skb, false, NULL), ts))
return TP_STATUS_TS_RAW_HARDWARE;

if ((flags & SOF_TIMESTAMPING_SOFTWARE) &&
--
2.53.0