| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/11/25 09:51 | flow | patch-triage |
22mArgs:null Results: {
"EnableConfigs": [
"HSR"
],
"FocusSymbols": [
"hsr_ptp_parse_header",
"hsr_dev_xmit",
"hsr_forward_skb",
"hsr_create_tagged_frame",
"hsr_fill_frame_info",
"hsr_handle_frame"
],
"KMSANReasoning": "The patch series implements PTP (Precision Time Protocol / IEEE 1588) support for HSR (High-availability Seamless Redundancy) networks by introducing an inline header (`struct hsr_inline_header`) parsed during packet transmission, handling port steering, and avoiding improper PTP forwarding in slave ingress.\n\nKMSAN vs KASAN Applicability Analysis:\n1. No uninitialized memory leaks to userspace: The patch does not add or modify any data structures sent to userspace (`copy_to_user`, `put_user`, Netlink attributes, ioctl returns, socket options, or BPF buffers). The newly added UAPI header defines `struct hsr_inline_header`, which is received from userspace (via raw/packet sockets) and parsed/stripped by the kernel before network transmission; it is never copied back to user space.\n2. Fully initialized stack and heap structures: In `hsr_dev_xmit`, local variables `req_tx_port` and `has_hsr_header` are explicitly initialized. In `fill_frame_info`, the `struct hsr_frame_info` buffer is completely zero-initialized via `memset(frame, 0, sizeof(*frame))` prior to assigning fields.\n3. Packet manipulation and bounds checking: Packet header manipulations (pulling inline headers with `skb_pull`, adjusting headroom with `skb_cow_head`, moving data with `skb_postpush_data_move`, and reading Ethernet/HSR headers) are guarded by `pskb_may_pull` checks. Any potential bounds violations, buffer overreads/overwrites, or use-after-free bugs on cloned skbs are classical memory safety issues that are fully covered by standard KASAN and debug builds.\n\nBecause there are no uninitialized memory usage risks or kernel-to-user info-leak vectors introduced by this patch series, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch introduces support for an inline header for PTP (ETH_P_1588) frames over High-availability Seamless Redundancy (HSR) virtual network devices, refactors tagged frame creation (switching to skb_clone and skb_cow_head), alters ingress frame filtering in hsr_slave, and adds new runtime assertions (WARN_ON_ONCE) in hsr_fill_frame_info. HSR interfaces are purely software-defined virtual devices that can be created and tested over dummy/veth devices in standard QEMU/KVM fuzzing environments without dedicated physical hardware.",
"WorthFuzzing": true
} |
| 1/1 | 2026/11/25 09:51 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 2b333a99dc8f7bbab557b05888b4f7fd3fc682f1\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Wed Nov 25 09:51:13 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/MAINTAINERS b/MAINTAINERS\nindex ccbcdc0799b9fb..1c23e7b2dafacb 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -12310,6 +12310,7 @@ F:\tdrivers/net/usb/hso.c\n HSR NETWORK PROTOCOL\n L:\tnetdev@vger.kernel.org\n S:\tOrphan\n+F:\tinclude/uapi/linux/hsr_ptp.h\n F:\tnet/hsr/\n F:\ttools/testing/selftests/net/hsr/\n \ndiff --git a/include/linux/if_hsr.h b/include/linux/if_hsr.h\nindex f4cf2dd36d193d..d0773a60c4fd05 100644\n--- a/include/linux/if_hsr.h\n+++ b/include/linux/if_hsr.h\n@@ -3,6 +3,7 @@\n #define _LINUX_IF_HSR_H_\n \n #include \u003clinux/types.h\u003e\n+#include \u003clinux/if_ether.h\u003e\n \n struct net_device;\n \n@@ -38,6 +39,11 @@ struct hsr_tag {\n \n #define HSR_HLEN\t6\n \n+struct hsr_ethhdr {\n+\tstruct ethhdr\tethhdr;\n+\tstruct hsr_tag\thsr_tag;\n+} __packed;\n+\n #if IS_ENABLED(CONFIG_HSR)\n extern bool is_hsr_master(struct net_device *dev);\n extern int hsr_get_version(struct net_device *dev, enum hsr_version *ver);\ndiff --git a/include/uapi/linux/hsr_ptp.h b/include/uapi/linux/hsr_ptp.h\nnew file mode 100644\nindex 00000000000000..95e905441ebdcf\n--- /dev/null\n+++ b/include/uapi/linux/hsr_ptp.h\n@@ -0,0 +1,20 @@\n+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */\n+#ifndef __UAPI_HSR_PTP_H\n+#define __UAPI_HSR_PTP_H\n+\n+#include \u003clinux/types.h\u003e\n+\n+#define HSR_INLINE_HDR 0xaf485352\n+#define HSR_INLINE_HDR_PORT_A\t1\n+#define HSR_INLINE_HDR_PORT_B\t2\n+\n+struct hsr_inline_header {\n+\t__u8 req_tx_port;\n+\t__u8 has_hsr_header;\n+\t__be32 __pad0;\n+\t__be32 magic;\n+\t__be16 __pad1;\n+\t__be16 eth_type;\n+} __attribute__ ((packed));\n+\n+#endif\ndiff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c\nindex fc512204600cd8..be29d73bef76a3 100644\n--- a/net/hsr/hsr_device.c\n+++ b/net/hsr/hsr_device.c\n@@ -12,6 +12,8 @@\n #include \u003clinux/etherdevice.h\u003e\n #include \u003clinux/rtnetlink.h\u003e\n #include \u003clinux/pkt_sched.h\u003e\n+#include \u003cuapi/linux/hsr_ptp.h\u003e\n+\n #include \"hsr_device.h\"\n #include \"hsr_slave.h\"\n #include \"hsr_framereg.h\"\n@@ -221,32 +223,85 @@ static netdev_features_t hsr_fix_features(struct net_device *dev,\n \treturn hsr_features_recompute(hsr, features);\n }\n \n+static int hsr_ptp_parse_header(struct sk_buff *skb, bool *has_hsr_header,\n+\t\t\t\tenum hsr_port_type *req_tx_port)\n+{\n+\tstruct hsr_inline_header *hsr_inline_hdr;\n+\tstruct ethhdr *eth_hdr;\n+\tunsigned int hdr_len;\n+\n+\tBUILD_BUG_ON(sizeof(struct hsr_inline_header) != sizeof(struct ethhdr));\n+\n+\tskb_reset_mac_header(skb);\n+\t/* need to access the magic header */\n+\tif (!pskb_may_pull(skb, sizeof(struct hsr_inline_header)))\n+\t\treturn -EINVAL;\n+\n+\thsr_inline_hdr = (struct hsr_inline_header *)skb_mac_header(skb);\n+\tif (hsr_inline_hdr-\u003emagic != htonl(HSR_INLINE_HDR))\n+\t\treturn -EINVAL;\n+\n+\t*has_hsr_header = hsr_inline_hdr-\u003ehas_hsr_header;\n+\t*req_tx_port = hsr_inline_hdr-\u003ereq_tx_port;\n+\tif (*req_tx_port != HSR_PT_SLAVE_A \u0026\u0026 *req_tx_port != HSR_PT_SLAVE_B)\n+\t\treturn -EINVAL;\n+\n+\tif (hsr_inline_hdr-\u003e__pad0 != 0 || hsr_inline_hdr-\u003e__pad1 != 0)\n+\t\treturn -EINVAL;\n+\n+\thdr_len = ETH_HLEN;\n+\tif (*has_hsr_header)\n+\t\thdr_len += HSR_HLEN;\n+\n+\t/* Ensure the real header after the stripped one can be\n+\t * accessed\n+\t */\n+\tif (!pskb_may_pull(skb, sizeof(struct hsr_inline_header) +\n+\t\t\t hdr_len))\n+\t\treturn -EINVAL;\n+\n+\teth_hdr = skb_pull(skb, sizeof(struct hsr_inline_header));\n+\tskb_set_network_header(skb, hdr_len);\n+\tskb-\u003eprotocol = eth_hdr-\u003eh_proto;\n+\treturn 0;\n+}\n+\n static netdev_tx_t hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)\n {\n+\tenum hsr_port_type req_tx_port = HSR_PT_NONE;\n \tstruct hsr_priv *hsr = netdev_priv(dev);\n+\tbool has_hsr_header = false;\n \tstruct hsr_port *master;\n \n \trcu_read_lock();\n \tmaster = hsr_port_get_hsr(hsr, HSR_PT_MASTER);\n-\tif (master) {\n-\t\tskb-\u003edev = master-\u003edev;\n-\t\tskb_reset_mac_header(skb);\n-\t\tskb_reset_mac_len(skb);\n-\t\tspin_lock_bh(\u0026hsr-\u003eseqnr_lock);\n-\t\thsr_forward_skb(skb, master);\n-\t\tspin_unlock_bh(\u0026hsr-\u003eseqnr_lock);\n-\t} else {\n-\t\tdev_core_stats_tx_dropped_inc(dev);\n-\t\tdev_kfree_skb_any(skb);\n-\t}\n+\tif (!master)\n+\t\tgoto drop;\n+\n+\tskb-\u003edev = master-\u003edev;\n+\tif (skb-\u003eprotocol == htons(ETH_P_1588) \u0026\u0026\n+\t hsr_ptp_parse_header(skb, \u0026has_hsr_header, \u0026req_tx_port))\n+\t\tgoto drop;\n+\n+\tskb_reset_mac_header(skb);\n+\tskb_reset_mac_len(skb);\n+\tspin_lock_bh(\u0026hsr-\u003eseqnr_lock);\n+\thsr_forward_skb(skb, master, req_tx_port, has_hsr_header);\n+\tspin_unlock_bh(\u0026hsr-\u003eseqnr_lock);\n \trcu_read_unlock();\n \n+\treturn NETDEV_TX_OK;\n+drop:\n+\trcu_read_unlock();\n+\tdev_core_stats_tx_dropped_inc(dev);\n+\tdev_kfree_skb_any(skb);\n \treturn NETDEV_TX_OK;\n }\n \n static const struct header_ops hsr_header_ops = {\n \t.create\t = eth_header,\n \t.parse\t = eth_header_parse,\n+\t.parse_protocol = eth_header_parse_protocol,\n };\n \n static struct sk_buff *hsr_init_skb(struct hsr_port *master, int extra)\n@@ -361,7 +416,7 @@ static void send_hsr_supervision_frame(struct hsr_port *port,\n \t\treturn;\n \t}\n \n-\thsr_forward_skb(skb, port);\n+\thsr_forward_skb(skb, port, HSR_PT_NONE, false);\n \tspin_unlock_bh(\u0026hsr-\u003eseqnr_lock);\n \treturn;\n }\n@@ -429,7 +484,7 @@ static void send_prp_supervision_frame(struct hsr_port *master,\n \t\treturn;\n \t}\n \n-\thsr_forward_skb(skb, master);\n+\thsr_forward_skb(skb, master, HSR_PT_NONE, false);\n \tspin_unlock_bh(\u0026hsr-\u003eseqnr_lock);\n }\n \ndiff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c\nindex 44f6d9c83180a6..9cb3297a8640a3 100644\n--- a/net/hsr/hsr_forward.c\n+++ b/net/hsr/hsr_forward.c\n@@ -12,6 +12,7 @@\n #include \u003clinux/skbuff.h\u003e\n #include \u003clinux/etherdevice.h\u003e\n #include \u003clinux/if_vlan.h\u003e\n+#include \u003cnet/sock.h\u003e\n #include \"hsr_main.h\"\n #include \"hsr_framereg.h\"\n \n@@ -331,7 +332,6 @@ static struct sk_buff *hsr_fill_tag(struct sk_buff *skb,\n struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,\n \t\t\t\t\tstruct hsr_port *port)\n {\n-\tunsigned char *dst, *src;\n \tstruct sk_buff *skb;\n \tint movelen;\n \n@@ -342,33 +342,43 @@ struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,\n \t\t/* set the lane id properly */\n \t\thsr_set_path_id(frame, hsr_ethhdr, port);\n \t\treturn skb_clone(frame-\u003eskb_hsr, GFP_ATOMIC);\n-\t} else if (port-\u003edev-\u003efeatures \u0026 NETIF_F_HW_HSR_TAG_INS) {\n-\t\treturn skb_clone(frame-\u003eskb_std, GFP_ATOMIC);\n \t}\n \n-\t/* Create the new skb with enough headroom to fit the HSR tag */\n-\tskb = __pskb_copy(frame-\u003eskb_std,\n-\t\t\t skb_headroom(frame-\u003eskb_std) + HSR_HLEN, GFP_ATOMIC);\n+\tskb = skb_clone(frame-\u003eskb_std, GFP_ATOMIC);\n \tif (!skb)\n \t\treturn NULL;\n-\tskb_reset_mac_header(skb);\n \n-\tif (skb-\u003eip_summed == CHECKSUM_PARTIAL)\n-\t\tskb-\u003ecsum_start += HSR_HLEN;\n+\tif (frame-\u003ereq_tx_port != HSR_PT_NONE \u0026\u0026 frame-\u003eskb_std-\u003esk)\n+\t\tskb_set_owner_w(skb, frame-\u003eskb_std-\u003esk);\n+\n+\tif (port-\u003edev-\u003efeatures \u0026 NETIF_F_HW_HSR_TAG_INS)\n+\t\treturn skb;\n+\n+\t/* Ensure the cloned skb has enough headroom to fit the HSR tag */\n+\tif (skb_cow_head(skb, skb_metadata_len(skb) + HSR_HLEN))\n+\t\tgoto err;\n \n \tmovelen = ETH_HLEN;\n \tif (frame-\u003eis_vlan)\n \t\tmovelen += VLAN_HLEN;\n \n-\tsrc = skb_mac_header(skb);\n-\tdst = skb_push(skb, HSR_HLEN);\n-\tmemmove(dst, src, movelen);\n+\t/* The entire header area needs to be linear */\n+\tif (!pskb_may_pull(skb, movelen))\n+\t\tgoto err;\n+\n+\tskb_push(skb, HSR_HLEN);\n+\tskb_postpush_data_move(skb, HSR_HLEN, movelen);\n+\tskb_set_network_header(skb, HSR_HLEN + movelen);\n \tskb_reset_mac_header(skb);\n+\tskb_reset_mac_len(skb);\n \n \t/* skb_put_padto free skb on error and hsr_fill_tag returns NULL in\n \t * that case\n \t */\n \treturn hsr_fill_tag(skb, frame, port, port-\u003ehsr-\u003eprot_version);\n+err:\n+\tkfree_skb(skb);\n+\treturn NULL;\n }\n \n struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,\n@@ -420,7 +430,7 @@ static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev,\n static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port,\n \t\t struct hsr_frame_info *frame)\n {\n-\tif (frame-\u003eport_rcv-\u003etype == HSR_PT_MASTER) {\n+\tif (frame-\u003eport_rcv-\u003etype == HSR_PT_MASTER \u0026\u0026 !frame-\u003ehas_hsr_header) {\n \t\thsr_addr_subst_dest(frame-\u003enode_src, skb, port);\n \n \t\t/* Address substitution (IEC62439-3 pp 26, 50): replace mac\n@@ -546,6 +556,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)\n \n \thsr_for_each_port(frame-\u003eport_rcv-\u003ehsr, port) {\n \t\tstruct hsr_priv *hsr = port-\u003ehsr;\n+\n \t\t/* Don't send frame back the way it came */\n \t\tif (port == frame-\u003eport_rcv)\n \t\t\tcontinue;\n@@ -564,6 +575,22 @@ static void hsr_forward_do(struct hsr_frame_info *frame)\n \t\tif ((port-\u003edev-\u003efeatures \u0026 NETIF_F_HW_HSR_DUP) \u0026\u0026 sent)\n \t\t\tcontinue;\n \n+\t\t/* If this frame has a specific outgoing port specified (by the\n+\t\t * sender) then send it on this port only.\n+\t\t */\n+\t\tif (frame-\u003ereq_tx_port != HSR_PT_NONE \u0026\u0026\n+\t\t frame-\u003ereq_tx_port != port-\u003etype)\n+\t\t\tcontinue;\n+\t\t/* If this TX frame already has a HSR header then forward the\n+\t\t * frame with it and don't add one.\n+\t\t */\n+\t\tif (frame-\u003ehas_hsr_header \u0026\u0026 frame-\u003eskb_std) {\n+\t\t\tskb = skb_clone(frame-\u003eskb_std, GFP_ATOMIC);\n+\t\t\tif (skb \u0026\u0026 frame-\u003eskb_std-\u003esk)\n+\t\t\t\tskb_set_owner_w(skb, frame-\u003eskb_std-\u003esk);\n+\t\t\tgoto inject_into_stack;\n+\t\t}\n+\n \t\t/* Don't send frame over port where it has been sent before.\n \t\t * Also for SAN, this shouldn't be done.\n \t\t */\n@@ -591,6 +618,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)\n \t\telse\n \t\t\tskb = hsr-\u003eproto_ops-\u003eget_untagged_frame(frame, port);\n \n+inject_into_stack:\n \t\tif (!skb) {\n \t\t\tframe-\u003eport_rcv-\u003edev-\u003estats.rx_dropped++;\n \t\t\tcontinue;\n@@ -655,6 +683,13 @@ int hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,\n \tstruct hsr_port *port = frame-\u003eport_rcv;\n \tstruct hsr_priv *hsr = port-\u003ehsr;\n \n+\tif (frame-\u003ehas_hsr_header) {\n+\t\tframe-\u003eskb_std = skb;\n+\n+\t\tWARN_ON_ONCE(port-\u003etype != HSR_PT_MASTER);\n+\t\tWARN_ON_ONCE(skb-\u003emac_len \u003c sizeof(struct hsr_ethhdr));\n+\t\treturn 0;\n+\t}\n \t/* HSRv0 supervisory frames double as a tag so treat them as tagged. */\n \tif ((!hsr-\u003eprot_version \u0026\u0026 proto == htons(ETH_P_PRP)) ||\n \t proto == htons(ETH_P_HSR)) {\n@@ -696,7 +731,8 @@ int prp_fill_frame_info(__be16 proto, struct sk_buff *skb,\n }\n \n static int fill_frame_info(struct hsr_frame_info *frame,\n-\t\t\t struct sk_buff *skb, struct hsr_port *port)\n+\t\t\t struct sk_buff *skb, struct hsr_port *port,\n+\t\t\t enum hsr_port_type req_tx_port, bool has_hsr_header)\n {\n \tstruct hsr_priv *hsr = port-\u003ehsr;\n \tstruct hsr_vlan_ethhdr *vlan_hdr;\n@@ -719,10 +755,16 @@ static int fill_frame_info(struct hsr_frame_info *frame,\n \tif (port-\u003etype == HSR_PT_INTERLINK)\n \t\tn_db = \u0026hsr-\u003eproxy_node_db;\n \n-\tframe-\u003enode_src = hsr_get_node(port, n_db, skb,\n-\t\t\t\t frame-\u003eis_supervision, port-\u003etype);\n-\tif (!frame-\u003enode_src)\n-\t\treturn -1; /* Unknown node and !is_supervision, or no mem */\n+\tframe-\u003ereq_tx_port = req_tx_port;\n+\tframe-\u003ehas_hsr_header = has_hsr_header;\n+\n+\tif (!frame-\u003ehas_hsr_header) {\n+\t\tframe-\u003enode_src = hsr_get_node(port, n_db, skb,\n+\t\t\t\t\t frame-\u003eis_supervision,\n+\t\t\t\t\t port-\u003etype);\n+\t\tif (!frame-\u003enode_src)\n+\t\t\treturn -1; /* Unknown node and !is_supervision, or no mem */\n+\t}\n \n \tethhdr = (struct ethhdr *)skb_mac_header(skb);\n \tframe-\u003eis_vlan = false;\n@@ -765,15 +807,17 @@ static int fill_frame_info(struct hsr_frame_info *frame,\n }\n \n /* Must be called holding rcu read lock (because of the port parameter) */\n-void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port)\n+void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port,\n+\t\t enum hsr_port_type req_tx_port, bool has_hsr_header)\n {\n \tstruct hsr_frame_info frame;\n \n \trcu_read_lock();\n-\tif (fill_frame_info(\u0026frame, skb, port) \u003c 0)\n+\tif (fill_frame_info(\u0026frame, skb, port, req_tx_port, has_hsr_header) \u003c 0)\n \t\tgoto out_drop;\n \n-\thsr_register_frame_in(frame.node_src, port, frame.sequence_nr);\n+\tif (!frame.has_hsr_header)\n+\t\thsr_register_frame_in(frame.node_src, port, frame.sequence_nr);\n \thsr_forward_do(\u0026frame);\n \trcu_read_unlock();\n \t/* Gets called for ingress frames as well as egress from master port.\ndiff --git a/net/hsr/hsr_forward.h b/net/hsr/hsr_forward.h\nindex 206636750b3001..662dd369c7df21 100644\n--- a/net/hsr/hsr_forward.h\n+++ b/net/hsr/hsr_forward.h\n@@ -13,7 +13,8 @@\n #include \u003clinux/netdevice.h\u003e\n #include \"hsr_main.h\"\n \n-void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port);\n+void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port,\n+\t\t enum hsr_port_type req_tx_port, bool has_hsr_header);\n struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,\n \t\t\t\t\tstruct hsr_port *port);\n struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,\ndiff --git a/net/hsr/hsr_framereg.h b/net/hsr/hsr_framereg.h\nindex 127a3fb64d5f03..dc13819d04098b 100644\n--- a/net/hsr/hsr_framereg.h\n+++ b/net/hsr/hsr_framereg.h\n@@ -29,6 +29,8 @@ struct hsr_frame_info {\n \tbool is_from_san;\n \tbool dst_in_node_db;\n \tbool dst_in_proxy_node_db;\n+\tbool has_hsr_header;\n+\tenum hsr_port_type req_tx_port;\n };\n \n void hsr_del_self_node(struct hsr_priv *hsr);\ndiff --git a/net/hsr/hsr_main.h b/net/hsr/hsr_main.h\nindex 53e95bae0ee276..36eb82774000c2 100644\n--- a/net/hsr/hsr_main.h\n+++ b/net/hsr/hsr_main.h\n@@ -72,11 +72,6 @@ static inline void set_hsr_tag_LSDU_size(struct hsr_tag *ht, u16 LSDU_size)\n \t\t\t\t 0xF000) | (LSDU_size \u0026 0x0FFF));\n }\n \n-struct hsr_ethhdr {\n-\tstruct ethhdr\tethhdr;\n-\tstruct hsr_tag\thsr_tag;\n-} __packed;\n-\n struct hsr_vlan_ethhdr {\n \tstruct vlan_ethhdr vlanhdr;\n \tstruct hsr_tag\thsr_tag;\ndiff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c\nindex a546f70f9cc8b4..a5b47f016abd78 100644\n--- a/net/hsr/hsr_slave.c\n+++ b/net/hsr/hsr_slave.c\n@@ -23,6 +23,7 @@ bool hsr_invalid_dan_ingress_frame(__be16 protocol)\n \n static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)\n {\n+\tstruct hsr_ethhdr *hsr_ethhdr;\n \tstruct sk_buff *skb = *pskb;\n \tstruct hsr_port *port;\n \tstruct hsr_priv *hsr;\n@@ -44,8 +45,7 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)\n \n \tif (hsr_addr_is_self(port-\u003ehsr, eth_hdr(skb)-\u003eh_source)) {\n \t\t/* Directly kill frames sent by ourselves */\n-\t\tkfree_skb(skb);\n-\t\tgoto finish_consume;\n+\t\tgoto finish_free_consume;\n \t}\n \n \t/* For HSR, only tagged frames are expected (unless the device offloads\n@@ -64,27 +64,43 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)\n \tskb_reset_mac_header(skb);\n \tif ((!hsr-\u003eprot_version \u0026\u0026 protocol == htons(ETH_P_PRP)) ||\n \t protocol == htons(ETH_P_HSR)) {\n-\t\tif (!pskb_may_pull(skb, ETH_HLEN + HSR_HLEN)) {\n-\t\t\tkfree_skb(skb);\n-\t\t\tgoto finish_consume;\n-\t\t}\n+\t\tif (!pskb_may_pull(skb, ETH_HLEN + HSR_HLEN))\n+\t\t\tgoto finish_free_consume;\n \n \t\tskb_set_network_header(skb, ETH_HLEN + HSR_HLEN);\n \t}\n \tskb_reset_mac_len(skb);\n \n+\t/* PTP packets are not supposed to be forwarded via HSR as-is. The\n+\t * latency introduced by forwarding renders the time information\n+\t * useless. Userland needs to capture the packet on the original\n+\t * interface instead of hsr.\n+\t */\n+\tif ((!hsr-\u003eprot_version \u0026\u0026 protocol == htons(ETH_P_PRP)) ||\n+\t protocol == htons(ETH_P_HSR)) {\n+\t\thsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb);\n+\t\tif (hsr_ethhdr-\u003ehsr_tag.encap_proto == htons(ETH_P_1588))\n+\t\t\tgoto finish_free_consume;\n+\t} else {\n+\t\tif (protocol == htons(ETH_P_1588))\n+\t\t\tgoto finish_free_consume;\n+\t}\n+\n \t/* Only the frames received over the interlink port will assign a\n \t * sequence number and require synchronisation vs other sender.\n \t */\n \tif (port-\u003etype == HSR_PT_INTERLINK) {\n \t\tspin_lock_bh(\u0026hsr-\u003eseqnr_lock);\n-\t\thsr_forward_skb(skb, port);\n+\t\thsr_forward_skb(skb, port, HSR_PT_NONE, false);\n \t\tspin_unlock_bh(\u0026hsr-\u003eseqnr_lock);\n \t} else {\n-\t\thsr_forward_skb(skb, port);\n+\t\thsr_forward_skb(skb, port, HSR_PT_NONE, false);\n \t}\n \n-finish_consume:\n+\treturn RX_HANDLER_CONSUMED;\n+\n+finish_free_consume:\n+\tkfree_skb(skb);\n \treturn RX_HANDLER_CONSUMED;\n \n finish_pass:\ndiff --git a/tools/include/uapi/linux/hsr_ptp.h b/tools/include/uapi/linux/hsr_ptp.h\nnew file mode 100644\nindex 00000000000000..95e905441ebdcf\n--- /dev/null\n+++ b/tools/include/uapi/linux/hsr_ptp.h\n@@ -0,0 +1,20 @@\n+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */\n+#ifndef __UAPI_HSR_PTP_H\n+#define __UAPI_HSR_PTP_H\n+\n+#include \u003clinux/types.h\u003e\n+\n+#define HSR_INLINE_HDR 0xaf485352\n+#define HSR_INLINE_HDR_PORT_A\t1\n+#define HSR_INLINE_HDR_PORT_B\t2\n+\n+struct hsr_inline_header {\n+\t__u8 req_tx_port;\n+\t__u8 has_hsr_header;\n+\t__be32 __pad0;\n+\t__be32 magic;\n+\t__be16 __pad1;\n+\t__be16 eth_type;\n+} __attribute__ ((packed));\n+\n+#endif\ndiff --git a/tools/testing/selftests/net/hsr/.gitignore b/tools/testing/selftests/net/hsr/.gitignore\nnew file mode 100644\nindex 00000000000000..849eecb84c9748\n--- /dev/null\n+++ b/tools/testing/selftests/net/hsr/.gitignore\n@@ -0,0 +1 @@\n+hsr_ptp_test\ndiff --git a/tools/testing/selftests/net/hsr/Makefile b/tools/testing/selftests/net/hsr/Makefile\nindex 2150e487ac7d7f..512ccf61b66525 100644\n--- a/tools/testing/selftests/net/hsr/Makefile\n+++ b/tools/testing/selftests/net/hsr/Makefile\n@@ -2,9 +2,12 @@\n \n top_srcdir = ../../../../..\n \n+CFLAGS += -Wall -Wl,--no-as-needed -O2 -g $(TOOLS_INCLUDES)\n+\n TEST_PROGS := \\\n \thsr_ping.sh \\\n \thsr_prp_redbox.sh \\\n+\thsr_ptp.sh \\\n \thsr_redbox.sh \\\n \tlink_faults.sh \\\n \tprp_ping.sh \\\n@@ -12,4 +15,6 @@ TEST_PROGS := \\\n \n TEST_FILES += hsr_common.sh\n \n+TEST_GEN_FILES := hsr_ptp_test\n+\n include ../../lib.mk\ndiff --git a/tools/testing/selftests/net/hsr/hsr_ptp.sh b/tools/testing/selftests/net/hsr/hsr_ptp.sh\nnew file mode 100755\nindex 00000000000000..23379b1ce7a56a\n--- /dev/null\n+++ b/tools/testing/selftests/net/hsr/hsr_ptp.sh\n@@ -0,0 +1,109 @@\n+#!/bin/bash\n+# SPDX-License-Identifier: GPL-2.0\n+\n+ipv6=false\n+\n+source ./hsr_common.sh\n+\n+optstring=\"h\"\n+usage() {\n+\techo \"Usage: $0\"\n+}\n+\n+while getopts \"$optstring\" option;do\n+\tcase \"$option\" in\n+\t\"h\")\n+\t\tusage \"$0\"\n+\t\texit 0\n+\t\t;;\n+\t\"?\")\n+\t\tusage \"$0\"\n+\t\texit 1\n+\t\t;;\n+esac\n+done\n+\n+setup_hsr_interfaces()\n+{\n+\tlocal HSRv=\"$1\"\n+\n+\techo \"INFO: Preparing interfaces for HSRv${HSRv}.\"\n+# Three HSR nodes. Each node has one link to each of its neighbour, two links in total.\n+\n+# ns1eth1 ----- ns2eth1\n+# hsr1 hsr2\n+# ns1eth2 ns2eth2\n+# | |\n+# ns3eth1 ns3eth2\n+# \\ /\n+# hsr3\n+#\n+\t# Interfaces\n+\tip link add ns1eth1 netns \"$ns1\" type veth peer name ns2eth1 netns \"$ns2\"\n+\tip link add ns1eth2 netns \"$ns1\" type veth peer name ns3eth1 netns \"$ns3\"\n+\tip link add ns3eth2 netns \"$ns3\" type veth peer name ns2eth2 netns \"$ns2\"\n+\n+\t# HSRv0/1\n+\tip -net \"$ns1\" link add name hsr1 type hsr slave1 ns1eth1 \\\n+\t\tslave2 ns1eth2 supervision 45 version \"$HSRv\" proto 0\n+\tip -net \"$ns2\" link add name hsr2 type hsr slave1 ns2eth1 \\\n+\t\tslave2 ns2eth2 supervision 45 version \"$HSRv\" proto 0\n+\tip -net \"$ns3\" link add name hsr3 type hsr slave1 ns3eth1 \\\n+\t\tslave2 ns3eth2 supervision 45 version \"$HSRv\" proto 0\n+\n+\t# IP for HSR\n+\tip -net \"$ns1\" addr add 100.64.0.1/24 dev hsr1\n+\tip -net \"$ns1\" addr add dead:beef:0::1/64 dev hsr1 nodad\n+\tip -net \"$ns2\" addr add 100.64.0.2/24 dev hsr2\n+\tip -net \"$ns2\" addr add dead:beef:0::2/64 dev hsr2 nodad\n+\tip -net \"$ns3\" addr add 100.64.0.3/24 dev hsr3\n+\tip -net \"$ns3\" addr add dead:beef:0::3/64 dev hsr3 nodad\n+\n+\tip -net \"$ns1\" link set address 00:11:22:00:01:01 dev ns1eth1\n+\tip -net \"$ns1\" link set address 00:11:22:00:01:02 dev ns1eth2\n+\n+\tip -net \"$ns2\" link set address 00:11:22:00:02:01 dev ns2eth1\n+\tip -net \"$ns2\" link set address 00:11:22:00:02:02 dev ns2eth2\n+\n+\tip -net \"$ns3\" link set address 00:11:22:00:03:01 dev ns3eth1\n+\tip -net \"$ns3\" link set address 00:11:22:00:03:02 dev ns3eth2\n+\n+\t# All Links up\n+\tip -net \"$ns1\" link set ns1eth1 up\n+\tip -net \"$ns1\" link set ns1eth2 up\n+\tip -net \"$ns1\" link set hsr1 up\n+\n+\tip -net \"$ns2\" link set ns2eth1 up\n+\tip -net \"$ns2\" link set ns2eth2 up\n+\tip -net \"$ns2\" link set hsr2 up\n+\n+\tip -net \"$ns3\" link set ns3eth1 up\n+\tip -net \"$ns3\" link set ns3eth2 up\n+\tip -net \"$ns3\" link set hsr3 up\n+}\n+\n+run_ptp_hdr_tests()\n+{\n+\techo \"INFO: Running PTP-header tests.\"\n+\n+\tip netns exec \"$ns1\" ./hsr_ptp_test -H hsr1 -A ns1eth1 -B ns1eth2\n+\tret=$?\n+\tstop_if_error \"PTP header test failed (ns1).\"\n+\n+\tip netns exec \"$ns2\" ./hsr_ptp_test -H hsr2 -A ns2eth1 -B ns2eth2\n+\tret=$?\n+\tstop_if_error \"PTP header test failed (ns2).\"\n+\n+\tip netns exec \"$ns3\" ./hsr_ptp_test -H hsr3 -A ns3eth1 -B ns3eth2\n+\tret=$?\n+\tstop_if_error \"PTP header test failed (ns3).\"\n+}\n+\n+check_prerequisites\n+trap cleanup_all_ns EXIT\n+\n+setup_ns ns1 ns2 ns3\n+setup_hsr_interfaces 1\n+run_ptp_hdr_tests\n+\n+exit $ret\ndiff --git a/tools/testing/selftests/net/hsr/hsr_ptp_test.c b/tools/testing/selftests/net/hsr/hsr_ptp_test.c\nnew file mode 100644\nindex 00000000000000..e2c2da56138ae3\n--- /dev/null\n+++ b/tools/testing/selftests/net/hsr/hsr_ptp_test.c\n@@ -0,0 +1,496 @@\n+// SPDX-License-Identifier: GPL-2.0-or-later\n+/*\n+ * Simple test to verify the usage of the inline header used for HSR with\n+ * ether type ETH_P_1588.\n+ * The inline header has to be stripped, the sent packet must only appear on the\n+ * specified port and the interface needs to accept a foreign HSR header and\n+ * prepend its own header.\n+ *\n+ * Socket handling inspired by raw.c from linuxptp.\n+ *\n+ */\n+#include \u003cpoll.h\u003e\n+#include \u003cstdbool.h\u003e\n+#include \u003cstdint.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003cstring.h\u003e\n+#include \u003ctime.h\u003e\n+#include \u003cunistd.h\u003e\n+\n+#include \u003clinux/types.h\u003e\n+#include \u003clinux/hsr_ptp.h\u003e\n+#include \u003clinux/if_ether.h\u003e\n+#include \u003cnet/if.h\u003e\n+#include \u003cnetinet/in.h\u003e\n+#include \u003cnetpacket/packet.h\u003e\n+#include \u003csys/ioctl.h\u003e\n+\n+#define MSEC_TO_NSEC(_x)\t(_x * 1000000)\n+#define USEC_PER_SEC\t\t1000000\n+#define NSEC_PER_SEC\t\t1000000000\n+\n+#ifndef __packed\n+#define __packed __attribute__((packed))\n+#endif\n+\n+#define MAC_LEN 6\n+typedef uint8_t eth_addr[MAC_LEN];\n+\n+struct eth_hdr {\n+\teth_addr dst;\n+\teth_addr src;\n+\tuint16_t type;\n+} __packed;\n+\n+struct hsr_hdr {\n+\teth_addr dst;\n+\teth_addr src;\n+\tuint16_t type;\n+\tuint16_t pathid_and_LSDU_size;\n+\tuint16_t sequence_nr;\n+\tuint16_t encap_type;\n+} __packed;\n+\n+struct hsr_meta_header {\n+\tstruct hsr_inline_header hsr_opt;\n+\tunion {\n+\t\tstruct hsr_hdr hsr_hdr;\n+\t\tstruct eth_hdr eth_hdr;\n+\t};\n+} __packed;\n+\n+static uint8_t ptp_packet[] = {\n+\t0x00, 0x12, 0x00, 0x2c, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n+\t0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x00, 0x01, 0x00, 0x01,\n+\t0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n+};\n+\n+static uint8_t p2p_dst_mac[MAC_LEN] = {\n+\t0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e\n+};\n+\n+static uint8_t slave_mac_addr[MAC_LEN];\n+static int32_t fd_slaveA = -1;\n+static int32_t fd_slaveB = -1;\n+static int32_t fd_hsr = -1;\n+static uint16_t hsr_seq = 37;\n+\n+static void tsnorm(struct timespec *ts)\n+{\n+\twhile (ts-\u003etv_nsec \u003e= NSEC_PER_SEC) {\n+\t\tts-\u003etv_nsec -= NSEC_PER_SEC;\n+\t\tts-\u003etv_sec++;\n+\t}\n+}\n+\n+static int64_t calcdiff(struct timespec t1, struct timespec t2)\n+{\n+\tint64_t diff = USEC_PER_SEC * (long long)((int) t1.tv_sec - (int) t2.tv_sec);\n+\n+\tdiff += ((int) t1.tv_nsec - (int) t2.tv_nsec) / 1000;\n+\treturn diff;\n+}\n+\n+static int tsgreater(struct timespec *a, struct timespec *b)\n+{\n+\treturn ((a-\u003etv_sec \u003e b-\u003etv_sec) ||\n+\t\t(a-\u003etv_sec == b-\u003etv_sec \u0026\u0026 a-\u003etv_nsec \u003e b-\u003etv_nsec));\n+}\n+\n+static int sk_interface_index(int fd, const char *name)\n+{\n+\tstruct ifreq ifreq;\n+\tint32_t err;\n+\n+\tmemset(\u0026ifreq, 0, sizeof(ifreq));\n+\tstrncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name) - 1);\n+\terr = ioctl(fd, SIOCGIFINDEX, \u0026ifreq);\n+\tif (err \u003c 0) {\n+\t\tprintf(\"ioctl SIOCGIFINDEX failed: %m\\n\");\n+\t\treturn err;\n+\t}\n+\treturn ifreq.ifr_ifindex;\n+}\n+\n+static int open_socket(const char *name)\n+{\n+\tstruct sockaddr_ll addr;\n+\tint32_t fd, index;\n+\n+\tfd = socket(AF_PACKET, SOCK_RAW, 0);\n+\tif (fd \u003c 0) {\n+\t\tprintf(\"socket failed: %m\\n\");\n+\t\tgoto err;\n+\t}\n+\tindex = sk_interface_index(fd, name);\n+\tif (index \u003c 0)\n+\t\tgoto err;\n+\n+\tmemset(\u0026addr, 0, sizeof(addr));\n+\taddr.sll_ifindex = index;\n+\taddr.sll_family = AF_PACKET;\n+\taddr.sll_protocol = htons(ETH_P_ALL);\n+\tif (bind(fd, (struct sockaddr *) \u0026addr, sizeof(addr))) {\n+\t\tprintf(\"bind failed: %m\\n\");\n+\t\tgoto err;\n+\t}\n+\tif (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, name, strlen(name))) {\n+\t\tprintf(\"setsockopt SO_BINDTODEVICE failed: %m\\n\");\n+\t\tgoto err;\n+\t}\n+\n+\treturn fd;\n+err:\n+\tif (fd \u003e= 0)\n+\t\tclose(fd);\n+\treturn -1;\n+}\n+\n+static int sk_interface_macaddr(const char *name)\n+{\n+\tstruct ifreq ifreq;\n+\tint32_t err, fd;\n+\n+\tmemset(\u0026ifreq, 0, sizeof(ifreq));\n+\tstrncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name) - 1);\n+\n+\tfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);\n+\tif (fd \u003c 0) {\n+\t\tprintf(\"socket failed: %m\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\terr = ioctl(fd, SIOCGIFHWADDR, \u0026ifreq);\n+\tif (err \u003c 0) {\n+\t\tprintf(\"ioctl SIOCGIFHWADDR failed: %m\\n\");\n+\t\tclose(fd);\n+\t\treturn -1;\n+\t}\n+\n+\tclose(fd);\n+\n+\tmemcpy(slave_mac_addr, \u0026ifreq.ifr_hwaddr.sa_data, MAC_LEN);\n+\treturn 0;\n+}\n+\n+static int raw_open(const char *hsr_dev, const char *slaveA_dev, const char *slaveB_dev)\n+{\n+\n+\tif (sk_interface_macaddr(slaveA_dev))\n+\t\tgoto err;\n+\n+\tfd_slaveA = open_socket(slaveA_dev);\n+\tif (fd_slaveA \u003c 0)\n+\t\tgoto err;\n+\n+\tfd_slaveB = open_socket(slaveB_dev);\n+\tif (fd_slaveB \u003c 0)\n+\t\tgoto err;\n+\n+\tfd_hsr = open_socket(hsr_dev);\n+\tif (fd_hsr \u003c 0)\n+\t\tgoto err;\n+\n+\treturn 0;\n+\n+err:\n+\tif (fd_slaveA \u003e= 0)\n+\t\tclose(fd_slaveA);\n+\tif (fd_slaveB \u003e= 0)\n+\t\tclose(fd_slaveB);\n+\tif (fd_hsr \u003e= 0)\n+\t\tclose(fd_hsr);\n+\n+\treturn -1;\n+}\n+\n+static int sk_receive(int fd, void *buf, int buflen)\n+{\n+\tstruct iovec iov = { buf, buflen };\n+\tuint8_t control[256];\n+\tint32_t cnt = 0;\n+\tstruct msghdr msg;\n+\n+\tmemset(control, 0, sizeof(control));\n+\tmemset(\u0026msg, 0, sizeof(msg));\n+\n+\tmsg.msg_iov = \u0026iov;\n+\tmsg.msg_iovlen = 1;\n+\tmsg.msg_control = control;\n+\tmsg.msg_controllen = sizeof(control);\n+\n+\tcnt = recvmsg(fd, \u0026msg, MSG_DONTWAIT);\n+\tif (cnt \u003c 0)\n+\t\treturn 0;\n+\treturn cnt;\n+}\n+\n+static int raw_recv(int fd, bool fwd_hsr, void *sample, int sample_len)\n+{\n+\tstruct timespec now, end;\n+\tstruct hsr_hdr *hsr_hdr;\n+\tuint8_t buf[1500];\n+\tint32_t cnt;\n+\n+\t/* The packet is expected to arrive within 100ms. HSR will send hello\n+\t * packets so there an end time and poll() will wait until this point.\n+\t */\n+\tclock_gettime(CLOCK_MONOTONIC, \u0026now);\n+\tend = now;\n+\tend.tv_nsec += MSEC_TO_NSEC(100);\n+\ttsnorm(\u0026end);\n+again:\n+\n+\tcnt = sk_receive(fd, buf, sizeof(buf));\n+\tif (cnt == 0) {\n+\t\tint64_t sleep_time;\n+\t\tstruct pollfd pfd;\n+\t\tint ret;\n+\n+\t\tclock_gettime(CLOCK_MONOTONIC, \u0026now);\n+\t\tif (tsgreater(\u0026now, \u0026end))\n+\t\t\treturn 0;\n+\n+\t\tsleep_time = calcdiff(end, now) / 1000;\n+\t\tif (sleep_time \u003c= 0)\n+\t\t\treturn 0;\n+\n+\t\tpfd.fd = fd;\n+\t\tpfd.events = POLLIN;\n+\t\tret = poll(\u0026pfd, 1, sleep_time);\n+\t\tif (ret \u003c= 0)\n+\t\t\treturn ret;\n+\t\tgoto again;\n+\t}\n+\n+\tif (cnt \u003c sizeof(struct hsr_hdr))\n+\t\tgoto again;\n+\n+\thsr_hdr = (void *)buf;\n+\t/* Embedded magic packet passed? */\n+\tif (hsr_hdr-\u003etype == htons(ETH_P_1588)) {\n+\t\tstruct hsr_inline_header *hsr_opt = (void *)buf;\n+\n+\t\tif (hsr_opt-\u003emagic == htonl(HSR_INLINE_HDR)) {\n+\t\t\tprintf(\"Error: Found HSR_INLINE_HDR\\n\");\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\t/* Assuming it is *our* network and nobody but the test here sends\n+\t * packets to p2p_dst_mac. Therefore any received packet needs to be\n+\t * ours and every mismatch is considered as error.\n+\t */\n+\tif (memcmp(hsr_hdr-\u003edst, p2p_dst_mac, MAC_LEN))\n+\t\tgoto again;\n+\n+\tif (hsr_hdr-\u003etype != htons(ETH_P_HSR)) {\n+\t\tprintf(\"Error: Unexpected ether type: 0x%x\\n\", ntohs(hsr_hdr-\u003etype));\n+\t\treturn -1;\n+\t}\n+\n+\tif (hsr_hdr-\u003eencap_type != htons(ETH_P_1588)) {\n+\t\tprintf(\"Error: Unexpected encapsulated type: 0x%x\\n\",\n+\t\t htons(hsr_hdr-\u003eencap_type));\n+\t\treturn -1;\n+\t}\n+\n+\tif (fwd_hsr) {\n+\t\tif (hsr_hdr-\u003esequence_nr != htons(hsr_seq - 1)) {\n+\t\t\tprintf(\"Error: Packet has wrong seq nr, %d vs %d.\\n\",\n+\t\t\t ntohs(hsr_hdr-\u003esequence_nr), hsr_seq - 1);\n+\t\t\treturn -1;\n+\t\t}\n+\t\t/* Undo the SRC MAC change in pkt_send() */\n+\t\thsr_hdr-\u003esrc[3] ^= 0x21;\n+\t\tif (memcmp(hsr_hdr-\u003esrc, slave_mac_addr, MAC_LEN)) {\n+\t\t\tprintf(\"Error: Packet has wrong SRC-MAC\\n\");\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\tif (cnt \u003c sizeof(struct hsr_hdr) + sample_len) {\n+\t\tprintf(\"Error: Packet %d is too small for data check\\n\", cnt);\n+\t\treturn -1;\n+\t}\n+\n+\tif (!memcmp(\u0026buf[sizeof(struct hsr_hdr)], sample, sample_len))\n+\t\treturn 1;\n+\n+\tprintf(\"Error: Packet did not match the sample\\n\");\n+\treturn -1;\n+}\n+\n+static int recv_verify(int port, bool fwd_hsr, void *sample, int sample_len)\n+{\n+\tint32_t error = 0;\n+\tint32_t ret;\n+\n+\tret = raw_recv(fd_slaveA, fwd_hsr, sample, sample_len);\n+\tif (ret \u003c 0)\n+\t\treturn ret;\n+\tif (port == HSR_INLINE_HDR_PORT_A \u0026\u0026 ret == 0) {\n+\t\tprintf(\"Error: Missing packet on portA\\n\");\n+\t\terror = 1;\n+\t}\n+\tif (port == HSR_INLINE_HDR_PORT_B \u0026\u0026 ret == 1) {\n+\t\tprintf(\"Error: Not expecting packet on portA\\n\");\n+\t\terror = 1;\n+\t}\n+\n+\tret = raw_recv(fd_slaveB, fwd_hsr, sample, sample_len);\n+\tif (ret \u003c 0)\n+\t\treturn ret;\n+\tif (port == HSR_INLINE_HDR_PORT_B \u0026\u0026 ret == 0) {\n+\t\tprintf(\"Error: Missing packet on portB\\n\");\n+\t\terror = 1;\n+\t}\n+\tif (port == HSR_INLINE_HDR_PORT_A \u0026\u0026 ret == 1) {\n+\t\tprintf(\"Error: Not expecting packet on portB\\n\");\n+\t\terror = 1;\n+\t}\n+\treturn error;\n+}\n+\n+static int32_t pkt_send(int port, bool hsr_hdr, void *data, int data_len)\n+{\n+\tstruct hsr_meta_header *hdr;\n+\tuint8_t packet[200];\n+\tssize_t cnt;\n+\tsize_t len;\n+\n+\tmemset(packet, 0, sizeof(packet));\n+\n+\tlen = sizeof(struct hsr_inline_header);\n+\thdr = (struct hsr_meta_header *)packet;\n+\tmemset(\u0026hdr-\u003ehsr_opt, 0, sizeof(hdr-\u003ehsr_opt));\n+\thdr-\u003ehsr_opt.magic = htonl(HSR_INLINE_HDR);\n+\thdr-\u003ehsr_opt.eth_type = htons(ETH_P_1588);\n+\tif (port != HSR_INLINE_HDR_PORT_A \u0026\u0026 port != HSR_INLINE_HDR_PORT_B) {\n+\t\tprintf(\"Wrong port requested\\n\");\n+\t\treturn -1;\n+\t}\n+\thdr-\u003ehsr_opt.req_tx_port = port;\n+\n+\tif (hsr_hdr) {\n+\t\tuint16_t pathid_size;\n+\n+\t\tlen += sizeof(struct hsr_hdr);\n+\t\tmemcpy(\u0026packet[len], data, data_len);\n+\n+\t\thdr-\u003ehsr_opt.has_hsr_header = 1;\n+\n+\t\tmemcpy(\u0026hdr-\u003ehsr_hdr.dst, p2p_dst_mac, MAC_LEN);\n+\t\tmemcpy(\u0026hdr-\u003ehsr_hdr.src, slave_mac_addr, MAC_LEN);\n+\t\t/* Flip a bit in SRC MAC addr so it does not look like hosts */\n+\t\thdr-\u003ehsr_hdr.src[3] ^= 0x21;\n+\n+\t\thdr-\u003ehsr_hdr.type = htons(ETH_P_HSR);\n+\t\thdr-\u003ehsr_hdr.sequence_nr = htons(hsr_seq++);\n+\t\thdr-\u003ehsr_hdr.encap_type = htons(ETH_P_1588);\n+\n+\t\t/* The resulting packet must be alteast 66 bytes */\n+\t\tif (data_len + sizeof(struct hsr_hdr) \u003c 66)\n+\t\t\tdata_len = 66 - sizeof(struct hsr_hdr);\n+\n+\t\tpathid_size = data_len + sizeof(struct hsr_hdr) - sizeof(struct eth_hdr);\n+\t\tpathid_size |= (port - 1) \u003c\u003c 12;\n+\n+\t\thdr-\u003ehsr_hdr.pathid_and_LSDU_size = htons(pathid_size);\n+\t} else {\n+\t\tlen += sizeof(struct eth_hdr);\n+\t\thdr-\u003ehsr_opt.has_hsr_header = 0;\n+\n+\t\tmemcpy(\u0026hdr-\u003eeth_hdr.dst, p2p_dst_mac, MAC_LEN);\n+\t\tmemcpy(\u0026hdr-\u003eeth_hdr.src, slave_mac_addr, MAC_LEN);\n+\t\thdr-\u003eeth_hdr.type = htons(ETH_P_1588);\n+\n+\t\tmemcpy(\u0026packet[len], data, data_len);\n+\t}\n+\n+\tcnt = send(fd_hsr, packet, len + data_len, 0);\n+\tif (cnt \u003c 1)\n+\t\treturn -1;\n+\n+\treturn cnt;\n+}\n+\n+int main(int argc, char *argv[])\n+{\n+\tchar *slaveA = NULL, *slaveB = NULL, *hsr_dev = NULL;\n+\tchar *msg_mode;\n+\tint opt;\n+\n+\twhile ((opt = getopt(argc, argv, \"A:B:H:\")) != -1) {\n+\t\tswitch (opt) {\n+\t\tcase 'A':\n+\t\t\tslaveA = strdup(optarg);\n+\t\t\tbreak;\n+\n+\t\tcase 'B':\n+\t\t\tslaveB = strdup(optarg);\n+\t\t\tbreak;\n+\n+\t\tcase 'H':\n+\t\t\thsr_dev = strdup(optarg);\n+\t\t\tbreak;\n+\t\tdefault: /* '?' */\n+\t\t\tfprintf(stderr, \"Usage: %s -A slaveA -B slaveB -H hsr_device\\n\",\n+\t\t\t\targv[0]);\n+\t\t\texit(EXIT_FAILURE);\n+\t\t}\n+\t}\n+\n+\tif (!slaveA || !slaveB || !hsr_dev) {\n+\t\tfprintf(stderr, \"Missing network devices\\n\");\n+\t\texit(EXIT_FAILURE);\n+\t}\n+\n+\tif (raw_open(hsr_dev, slaveA, slaveB) \u003c 0)\n+\t\treturn EXIT_FAILURE;\n+\n+\tmsg_mode = \"PortA, no-hsr-header\";\n+\tif (pkt_send(HSR_INLINE_HDR_PORT_A, false, ptp_packet, sizeof(ptp_packet)) \u003c 0) {\n+\t\tprintf(\"Sending failed: %s\\n\", msg_mode);\n+\t\treturn EXIT_FAILURE;\n+\t}\n+\tif (recv_verify(HSR_INLINE_HDR_PORT_A, false, ptp_packet, sizeof(ptp_packet))) {\n+\t\tprintf(\"Verify failed: %s\\n\", msg_mode);\n+\t\treturn EXIT_FAILURE;\n+\t}\n+\n+\tptp_packet[16 + 4]++;\n+\tmsg_mode = \"PortB, no-hsr-header\";\n+\tif (pkt_send(HSR_INLINE_HDR_PORT_B, false, ptp_packet, sizeof(ptp_packet)) \u003c 0) {\n+\t\tprintf(\"Sending failed: %s\\n\", msg_mode);\n+\t\treturn EXIT_FAILURE;\n+\t}\n+\tif (recv_verify(HSR_INLINE_HDR_PORT_B, false, ptp_packet, sizeof(ptp_packet))) {\n+\t\tprintf(\"Verify failed: %s\\n\", msg_mode);\n+\t\treturn EXIT_FAILURE;\n+\t}\n+\n+\tptp_packet[16 + 4]++;\n+\tmsg_mode = \"PortA, hsr-header\";\n+\tif (pkt_send(HSR_INLINE_HDR_PORT_A, true, ptp_packet, sizeof(ptp_packet)) \u003c 0) {\n+\t\tprintf(\"Sending failed: %s\\n\", msg_mode);\n+\t\treturn EXIT_FAILURE;\n+\t}\n+\tif (recv_verify(HSR_INLINE_HDR_PORT_A, true, ptp_packet, sizeof(ptp_packet))) {\n+\t\tprintf(\"Verify failed: %s\\n\", msg_mode);\n+\t\treturn EXIT_FAILURE;\n+\t}\n+\n+\tptp_packet[16 + 4]++;\n+\tmsg_mode = \"PortB, hsr-header\";\n+\tif (pkt_send(HSR_INLINE_HDR_PORT_B, true, ptp_packet, sizeof(ptp_packet)) \u003c 0) {\n+\t\tprintf(\"Sending failed: %s\\n\", msg_mode);\n+\t\treturn EXIT_FAILURE;\n+\t}\n+\tif (recv_verify(HSR_INLINE_HDR_PORT_B, true, ptp_packet, sizeof(ptp_packet))) {\n+\t\tprintf(\"Verify failed: %s\\n\", msg_mode);\n+\t\treturn EXIT_FAILURE;\n+\t}\n+\n+\treturn EXIT_SUCCESS;\n+}\n"
} |
| 2/1 | 2026/11/25 09:51 | agent | patch-evaluator |
9mModel:core Args: null Results: {
"EnableConfigs": [
"HSR"
],
"FocusSymbols": [
"hsr_ptp_parse_header",
"hsr_dev_xmit",
"hsr_forward_skb",
"hsr_create_tagged_frame",
"hsr_fill_frame_info",
"hsr_handle_frame"
],
"Reasoning": "The patch introduces support for an inline header for PTP (ETH_P_1588) frames over High-availability Seamless Redundancy (HSR) virtual network devices, refactors tagged frame creation (switching to skb_clone and skb_cow_head), alters ingress frame filtering in hsr_slave, and adds new runtime assertions (WARN_ON_ONCE) in hsr_fill_frame_info. HSR interfaces are purely software-defined virtual devices that can be created and tested over dummy/veth devices in standard QEMU/KVM fuzzing environments without dedicated physical hardware.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 2b333a99dc8f7bbab557b05888b4f7fd3fc682f1
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Nov 25 09:51:13 2026 +0000
syz-cluster: applied patch under review
diff --git a/MAINTAINERS b/MAINTAINERS
index ccbcdc0799b9fb..1c23e7b2dafacb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12310,6 +12310,7 @@ F: drivers/net/usb/hso.c
HSR NETWORK PROTOCOL
L: netdev@vger.kernel.org
S: Orphan
+F: include/uapi/linux/hsr_ptp.h
F: net/hsr/
F: tools/testing/selftests/net/hsr/
diff --git a/include/linux/if_hsr.h b/include/linux/if_hsr.h
index f4cf2dd36d193d..d0773a60c4fd05 100644
--- a/include/linux/if_hsr.h
+++ b/include/linux/if_hsr.h
@@ -3,6 +3,7 @@
#define _LINUX_IF_HSR_H_
#include <linux/types.h>
+#include <linux/if_ether.h>
struct net_device;
@@ -38,6 +39,11 @@ struct hsr_tag {
#define HSR_HLEN 6
+struct hsr_ethhdr {
+ struct ethhdr ethhdr;
+ struct hsr_tag hsr_tag;
+} __packed;
+
#if IS_ENABLED(CONFIG_HSR)
extern bool is_hsr_master(struct net_device *dev);
extern int hsr_get_version(struct net_device *dev, enum hsr_version *ver);
diff --git a/include/uapi/linux/hsr_ptp.h b/include/uapi/linux/hsr_ptp.h
new file mode 100644
index 00000000000000..95e905441ebdcf
--- /dev/null
+++ b/include/uapi/linux/hsr_ptp.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+#ifndef __UAPI_HSR_PTP_H
+#define __UAPI_HSR_PTP_H
+
+#include <linux/types.h>
+
+#define HSR_INLINE_HDR 0xaf485352
+#define HSR_INLINE_HDR_PORT_A 1
+#define HSR_INLINE_HDR_PORT_B 2
+
+struct hsr_inline_header {
+ __u8 req_tx_port;
+ __u8 has_hsr_header;
+ __be32 __pad0;
+ __be32 magic;
+ __be16 __pad1;
+ __be16 eth_type;
+} __attribute__ ((packed));
+
+#endif
diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
index fc512204600cd8..be29d73bef76a3 100644
--- a/net/hsr/hsr_device.c
+++ b/net/hsr/hsr_device.c
@@ -12,6 +12,8 @@
#include <linux/etherdevice.h>
#include <linux/rtnetlink.h>
#include <linux/pkt_sched.h>
+#include <uapi/linux/hsr_ptp.h>
+
#include "hsr_device.h"
#include "hsr_slave.h"
#include "hsr_framereg.h"
@@ -221,32 +223,85 @@ static netdev_features_t hsr_fix_features(struct net_device *dev,
return hsr_features_recompute(hsr, features);
}
+static int hsr_ptp_parse_header(struct sk_buff *skb, bool *has_hsr_header,
+ enum hsr_port_type *req_tx_port)
+{
+ struct hsr_inline_header *hsr_inline_hdr;
+ struct ethhdr *eth_hdr;
+ unsigned int hdr_len;
+
+ BUILD_BUG_ON(sizeof(struct hsr_inline_header) != sizeof(struct ethhdr));
+
+ skb_reset_mac_header(skb);
+ /* need to access the magic header */
+ if (!pskb_may_pull(skb, sizeof(struct hsr_inline_header)))
+ return -EINVAL;
+
+ hsr_inline_hdr = (struct hsr_inline_header *)skb_mac_header(skb);
+ if (hsr_inline_hdr->magic != htonl(HSR_INLINE_HDR))
+ return -EINVAL;
+
+ *has_hsr_header = hsr_inline_hdr->has_hsr_header;
+ *req_tx_port = hsr_inline_hdr->req_tx_port;
+ if (*req_tx_port != HSR_PT_SLAVE_A && *req_tx_port != HSR_PT_SLAVE_B)
+ return -EINVAL;
+
+ if (hsr_inline_hdr->__pad0 != 0 || hsr_inline_hdr->__pad1 != 0)
+ return -EINVAL;
+
+ hdr_len = ETH_HLEN;
+ if (*has_hsr_header)
+ hdr_len += HSR_HLEN;
+
+ /* Ensure the real header after the stripped one can be
+ * accessed
+ */
+ if (!pskb_may_pull(skb, sizeof(struct hsr_inline_header) +
+ hdr_len))
+ return -EINVAL;
+
+ eth_hdr = skb_pull(skb, sizeof(struct hsr_inline_header));
+ skb_set_network_header(skb, hdr_len);
+ skb->protocol = eth_hdr->h_proto;
+ return 0;
+}
+
static netdev_tx_t hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)
{
+ enum hsr_port_type req_tx_port = HSR_PT_NONE;
struct hsr_priv *hsr = netdev_priv(dev);
+ bool has_hsr_header = false;
struct hsr_port *master;
rcu_read_lock();
master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
- if (master) {
- skb->dev = master->dev;
- skb_reset_mac_header(skb);
- skb_reset_mac_len(skb);
- spin_lock_bh(&hsr->seqnr_lock);
- hsr_forward_skb(skb, master);
- spin_unlock_bh(&hsr->seqnr_lock);
- } else {
- dev_core_stats_tx_dropped_inc(dev);
- dev_kfree_skb_any(skb);
- }
+ if (!master)
+ goto drop;
+
+ skb->dev = master->dev;
+ if (skb->protocol == htons(ETH_P_1588) &&
+ hsr_ptp_parse_header(skb, &has_hsr_header, &req_tx_port))
+ goto drop;
+
+ skb_reset_mac_header(skb);
+ skb_reset_mac_len(skb);
+ spin_lock_bh(&hsr->seqnr_lock);
+ hsr_forward_skb(skb, master, req_tx_port, has_hsr_header);
+ spin_unlock_bh(&hsr->seqnr_lock);
rcu_read_unlock();
+ return NETDEV_TX_OK;
+drop:
+ rcu_read_unlock();
+ dev_core_stats_tx_dropped_inc(dev);
+ dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}
static const struct header_ops hsr_header_ops = {
.create = eth_header,
.parse = eth_header_parse,
+ .parse_protocol = eth_header_parse_protocol,
};
static struct sk_buff *hsr_init_skb(struct hsr_port *master, int extra)
@@ -361,7 +416,7 @@ static void send_hsr_supervision_frame(struct hsr_port *port,
return;
}
- hsr_forward_skb(skb, port);
+ hsr_forward_skb(skb, port, HSR_PT_NONE, false);
spin_unlock_bh(&hsr->seqnr_lock);
return;
}
@@ -429,7 +484,7 @@ static void send_prp_supervision_frame(struct hsr_port *master,
return;
}
- hsr_forward_skb(skb, master);
+ hsr_forward_skb(skb, master, HSR_PT_NONE, false);
spin_unlock_bh(&hsr->seqnr_lock);
}
diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
index 44f6d9c83180a6..9cb3297a8640a3 100644
--- a/net/hsr/hsr_forward.c
+++ b/net/hsr/hsr_forward.c
@@ -12,6 +12,7 @@
#include <linux/skbuff.h>
#include <linux/etherdevice.h>
#include <linux/if_vlan.h>
+#include <net/sock.h>
#include "hsr_main.h"
#include "hsr_framereg.h"
@@ -331,7 +332,6 @@ static struct sk_buff *hsr_fill_tag(struct sk_buff *skb,
struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
struct hsr_port *port)
{
- unsigned char *dst, *src;
struct sk_buff *skb;
int movelen;
@@ -342,33 +342,43 @@ struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
/* set the lane id properly */
hsr_set_path_id(frame, hsr_ethhdr, port);
return skb_clone(frame->skb_hsr, GFP_ATOMIC);
- } else if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) {
- return skb_clone(frame->skb_std, GFP_ATOMIC);
}
- /* Create the new skb with enough headroom to fit the HSR tag */
- skb = __pskb_copy(frame->skb_std,
- skb_headroom(frame->skb_std) + HSR_HLEN, GFP_ATOMIC);
+ skb = skb_clone(frame->skb_std, GFP_ATOMIC);
if (!skb)
return NULL;
- skb_reset_mac_header(skb);
- if (skb->ip_summed == CHECKSUM_PARTIAL)
- skb->csum_start += HSR_HLEN;
+ if (frame->req_tx_port != HSR_PT_NONE && frame->skb_std->sk)
+ skb_set_owner_w(skb, frame->skb_std->sk);
+
+ if (port->dev->features & NETIF_F_HW_HSR_TAG_INS)
+ return skb;
+
+ /* Ensure the cloned skb has enough headroom to fit the HSR tag */
+ if (skb_cow_head(skb, skb_metadata_len(skb) + HSR_HLEN))
+ goto err;
movelen = ETH_HLEN;
if (frame->is_vlan)
movelen += VLAN_HLEN;
- src = skb_mac_header(skb);
- dst = skb_push(skb, HSR_HLEN);
- memmove(dst, src, movelen);
+ /* The entire header area needs to be linear */
+ if (!pskb_may_pull(skb, movelen))
+ goto err;
+
+ skb_push(skb, HSR_HLEN);
+ skb_postpush_data_move(skb, HSR_HLEN, movelen);
+ skb_set_network_header(skb, HSR_HLEN + movelen);
skb_reset_mac_header(skb);
+ skb_reset_mac_len(skb);
/* skb_put_padto free skb on error and hsr_fill_tag returns NULL in
* that case
*/
return hsr_fill_tag(skb, frame, port, port->hsr->prot_version);
+err:
+ kfree_skb(skb);
+ return NULL;
}
struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,
@@ -420,7 +430,7 @@ static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev,
static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port,
struct hsr_frame_info *frame)
{
- if (frame->port_rcv->type == HSR_PT_MASTER) {
+ if (frame->port_rcv->type == HSR_PT_MASTER && !frame->has_hsr_header) {
hsr_addr_subst_dest(frame->node_src, skb, port);
/* Address substitution (IEC62439-3 pp 26, 50): replace mac
@@ -546,6 +556,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
hsr_for_each_port(frame->port_rcv->hsr, port) {
struct hsr_priv *hsr = port->hsr;
+
/* Don't send frame back the way it came */
if (port == frame->port_rcv)
continue;
@@ -564,6 +575,22 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
if ((port->dev->features & NETIF_F_HW_HSR_DUP) && sent)
continue;
+ /* If this frame has a specific outgoing port specified (by the
+ * sender) then send it on this port only.
+ */
+ if (frame->req_tx_port != HSR_PT_NONE &&
+ frame->req_tx_port != port->type)
+ continue;
+ /* If this TX frame already has a HSR header then forward the
+ * frame with it and don't add one.
+ */
+ if (frame->has_hsr_header && frame->skb_std) {
+ skb = skb_clone(frame->skb_std, GFP_ATOMIC);
+ if (skb && frame->skb_std->sk)
+ skb_set_owner_w(skb, frame->skb_std->sk);
+ goto inject_into_stack;
+ }
+
/* Don't send frame over port where it has been sent before.
* Also for SAN, this shouldn't be done.
*/
@@ -591,6 +618,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
else
skb = hsr->proto_ops->get_untagged_frame(frame, port);
+inject_into_stack:
if (!skb) {
frame->port_rcv->dev->stats.rx_dropped++;
continue;
@@ -655,6 +683,13 @@ int hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,
struct hsr_port *port = frame->port_rcv;
struct hsr_priv *hsr = port->hsr;
+ if (frame->has_hsr_header) {
+ frame->skb_std = skb;
+
+ WARN_ON_ONCE(port->type != HSR_PT_MASTER);
+ WARN_ON_ONCE(skb->mac_len < sizeof(struct hsr_ethhdr));
+ return 0;
+ }
/* HSRv0 supervisory frames double as a tag so treat them as tagged. */
if ((!hsr->prot_version && proto == htons(ETH_P_PRP)) ||
proto == htons(ETH_P_HSR)) {
@@ -696,7 +731,8 @@ int prp_fill_frame_info(__be16 proto, struct sk_buff *skb,
}
static int fill_frame_info(struct hsr_frame_info *frame,
- struct sk_buff *skb, struct hsr_port *port)
+ struct sk_buff *skb, struct hsr_port *port,
+ enum hsr_port_type req_tx_port, bool has_hsr_header)
{
struct hsr_priv *hsr = port->hsr;
struct hsr_vlan_ethhdr *vlan_hdr;
@@ -719,10 +755,16 @@ static int fill_frame_info(struct hsr_frame_info *frame,
if (port->type == HSR_PT_INTERLINK)
n_db = &hsr->proxy_node_db;
- frame->node_src = hsr_get_node(port, n_db, skb,
- frame->is_supervision, port->type);
- if (!frame->node_src)
- return -1; /* Unknown node and !is_supervision, or no mem */
+ frame->req_tx_port = req_tx_port;
+ frame->has_hsr_header = has_hsr_header;
+
+ if (!frame->has_hsr_header) {
+ frame->node_src = hsr_get_node(port, n_db, skb,
+ frame->is_supervision,
+ port->type);
+ if (!frame->node_src)
+ return -1; /* Unknown node and !is_supervision, or no mem */
+ }
ethhdr = (struct ethhdr *)skb_mac_header(skb);
frame->is_vlan = false;
@@ -765,15 +807,17 @@ static int fill_frame_info(struct hsr_frame_info *frame,
}
/* Must be called holding rcu read lock (because of the port parameter) */
-void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port)
+void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port,
+ enum hsr_port_type req_tx_port, bool has_hsr_header)
{
struct hsr_frame_info frame;
rcu_read_lock();
- if (fill_frame_info(&frame, skb, port) < 0)
+ if (fill_frame_info(&frame, skb, port, req_tx_port, has_hsr_header) < 0)
goto out_drop;
- hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
+ if (!frame.has_hsr_header)
+ hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
hsr_forward_do(&frame);
rcu_read_unlock();
/* Gets called for ingress frames as well as egress from master port.
diff --git a/net/hsr/hsr_forward.h b/net/hsr/hsr_forward.h
index 206636750b3001..662dd369c7df21 100644
--- a/net/hsr/hsr_forward.h
+++ b/net/hsr/hsr_forward.h
@@ -13,7 +13,8 @@
#include <linux/netdevice.h>
#include "hsr_main.h"
-void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port);
+void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port,
+ enum hsr_port_type req_tx_port, bool has_hsr_header);
struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,
struct hsr_port *port);
struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
diff --git a/net/hsr/hsr_framereg.h b/net/hsr/hsr_framereg.h
index 127a3fb64d5f03..dc13819d04098b 100644
--- a/net/hsr/hsr_framereg.h
+++ b/net/hsr/hsr_framereg.h
@@ -29,6 +29,8 @@ struct hsr_frame_info {
bool is_from_san;
bool dst_in_node_db;
bool dst_in_proxy_node_db;
+ bool has_hsr_header;
+ enum hsr_port_type req_tx_port;
};
void hsr_del_self_node(struct hsr_priv *hsr);
diff --git a/net/hsr/hsr_main.h b/net/hsr/hsr_main.h
index 53e95bae0ee276..36eb82774000c2 100644
--- a/net/hsr/hsr_main.h
+++ b/net/hsr/hsr_main.h
@@ -72,11 +72,6 @@ static inline void set_hsr_tag_LSDU_size(struct hsr_tag *ht, u16 LSDU_size)
0xF000) | (LSDU_size & 0x0FFF));
}
-struct hsr_ethhdr {
- struct ethhdr ethhdr;
- struct hsr_tag hsr_tag;
-} __packed;
-
struct hsr_vlan_ethhdr {
struct vlan_ethhdr vlanhdr;
struct hsr_tag hsr_tag;
diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c
index a546f70f9cc8b4..a5b47f016abd78 100644
--- a/net/hsr/hsr_slave.c
+++ b/net/hsr/hsr_slave.c
@@ -23,6 +23,7 @@ bool hsr_invalid_dan_ingress_frame(__be16 protocol)
static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
{
+ struct hsr_ethhdr *hsr_ethhdr;
struct sk_buff *skb = *pskb;
struct hsr_port *port;
struct hsr_priv *hsr;
@@ -44,8 +45,7 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
if (hsr_addr_is_self(port->hsr, eth_hdr(skb)->h_source)) {
/* Directly kill frames sent by ourselves */
- kfree_skb(skb);
- goto finish_consume;
+ goto finish_free_consume;
}
/* For HSR, only tagged frames are expected (unless the device offloads
@@ -64,27 +64,43 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
skb_reset_mac_header(skb);
if ((!hsr->prot_version && protocol == htons(ETH_P_PRP)) ||
protocol == htons(ETH_P_HSR)) {
- if (!pskb_may_pull(skb, ETH_HLEN + HSR_HLEN)) {
- kfree_skb(skb);
- goto finish_consume;
- }
+ if (!pskb_may_pull(skb, ETH_HLEN + HSR_HLEN))
+ goto finish_free_consume;
skb_set_network_header(skb, ETH_HLEN + HSR_HLEN);
}
skb_reset_mac_len(skb);
+ /* PTP packets are not supposed to be forwarded via HSR as-is. The
+ * latency introduced by forwarding renders the time information
+ * useless. Userland needs to capture the packet on the original
+ * interface instead of hsr.
+ */
+ if ((!hsr->prot_version && protocol == htons(ETH_P_PRP)) ||
+ protocol == htons(ETH_P_HSR)) {
+ hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb);
+ if (hsr_ethhdr->hsr_tag.encap_proto == htons(ETH_P_1588))
+ goto finish_free_consume;
+ } else {
+ if (protocol == htons(ETH_P_1588))
+ goto finish_free_consume;
+ }
+
/* Only the frames received over the interlink port will assign a
* sequence number and require synchronisation vs other sender.
*/
if (port->type == HSR_PT_INTERLINK) {
spin_lock_bh(&hsr->seqnr_lock);
- hsr_forward_skb(skb, port);
+ hsr_forward_skb(skb, port, HSR_PT_NONE, false);
spin_unlock_bh(&hsr->seqnr_lock);
} else {
- hsr_forward_skb(skb, port);
+ hsr_forward_skb(skb, port, HSR_PT_NONE, false);
}
-finish_consume:
+ return RX_HANDLER_CONSUMED;
+
+finish_free_consume:
+ kfree_skb(skb);
return RX_HANDLER_CONSUMED;
finish_pass:
diff --git a/tools/include/uapi/linux/hsr_ptp.h b/tools/include/uapi/linux/hsr_ptp.h
new file mode 100644
index 00000000000000..95e905441ebdcf
--- /dev/null
+++ b/tools/include/uapi/linux/hsr_ptp.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+#ifndef __UAPI_HSR_PTP_H
+#define __UAPI_HSR_PTP_H
+
+#include <linux/types.h>
+
+#define HSR_INLINE_HDR 0xaf485352
+#define HSR_INLINE_HDR_PORT_A 1
+#define HSR_INLINE_HDR_PORT_B 2
+
+struct hsr_inline_header {
+ __u8 req_tx_port;
+ __u8 has_hsr_header;
+ __be32 __pad0;
+ __be32 magic;
+ __be16 __pad1;
+ __be16 eth_type;
+} __attribute__ ((packed));
+
+#endif
diff --git a/tools/testing/selftests/net/hsr/.gitignore b/tools/testing/selftests/net/hsr/.gitignore
new file mode 100644
index 00000000000000..849eecb84c9748
--- /dev/null
+++ b/tools/testing/selftests/net/hsr/.gitignore
@@ -0,0 +1 @@
+hsr_ptp_test
diff --git a/tools/testing/selftests/net/hsr/Makefile b/tools/testing/selftests/net/hsr/Makefile
index 2150e487ac7d7f..512ccf61b66525 100644
--- a/tools/testing/selftests/net/hsr/Makefile
+++ b/tools/testing/selftests/net/hsr/Makefile
@@ -2,9 +2,12 @@
top_srcdir = ../../../../..
+CFLAGS += -Wall -Wl,--no-as-needed -O2 -g $(TOOLS_INCLUDES)
+
TEST_PROGS := \
hsr_ping.sh \
hsr_prp_redbox.sh \
+ hsr_ptp.sh \
hsr_redbox.sh \
link_faults.sh \
prp_ping.sh \
@@ -12,4 +15,6 @@ TEST_PROGS := \
TEST_FILES += hsr_common.sh
+TEST_GEN_FILES := hsr_ptp_test
+
include ../../lib.mk
diff --git a/tools/testing/selftests/net/hsr/hsr_ptp.sh b/tools/testing/selftests/net/hsr/hsr_ptp.sh
new file mode 100755
index 00000000000000..23379b1ce7a56a
--- /dev/null
+++ b/tools/testing/selftests/net/hsr/hsr_ptp.sh
@@ -0,0 +1,109 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+ipv6=false
+
+source ./hsr_common.sh
+
+optstring="h"
+usage() {
+ echo "Usage: $0"
+}
+
+while getopts "$optstring" option;do
+ case "$option" in
+ "h")
+ usage "$0"
+ exit 0
+ ;;
+ "?")
+ usage "$0"
+ exit 1
+ ;;
+esac
+done
+
+setup_hsr_interfaces()
+{
+ local HSRv="$1"
+
+ echo "INFO: Preparing interfaces for HSRv${HSRv}."
+# Three HSR nodes. Each node has one link to each of its neighbour, two links in total.
+
+# ns1eth1 ----- ns2eth1
+# hsr1 hsr2
+# ns1eth2 ns2eth2
+# | |
+# ns3eth1 ns3eth2
+# \ /
+# hsr3
+#
+ # Interfaces
+ ip link add ns1eth1 netns "$ns1" type veth peer name ns2eth1 netns "$ns2"
+ ip link add ns1eth2 netns "$ns1" type veth peer name ns3eth1 netns "$ns3"
+ ip link add ns3eth2 netns "$ns3" type veth peer name ns2eth2 netns "$ns2"
+
+ # HSRv0/1
+ ip -net "$ns1" link add name hsr1 type hsr slave1 ns1eth1 \
+ slave2 ns1eth2 supervision 45 version "$HSRv" proto 0
+ ip -net "$ns2" link add name hsr2 type hsr slave1 ns2eth1 \
+ slave2 ns2eth2 supervision 45 version "$HSRv" proto 0
+ ip -net "$ns3" link add name hsr3 type hsr slave1 ns3eth1 \
+ slave2 ns3eth2 supervision 45 version "$HSRv" proto 0
+
+ # IP for HSR
+ ip -net "$ns1" addr add 100.64.0.1/24 dev hsr1
+ ip -net "$ns1" addr add dead:beef:0::1/64 dev hsr1 nodad
+ ip -net "$ns2" addr add 100.64.0.2/24 dev hsr2
+ ip -net "$ns2" addr add dead:beef:0::2/64 dev hsr2 nodad
+ ip -net "$ns3" addr add 100.64.0.3/24 dev hsr3
+ ip -net "$ns3" addr add dead:beef:0::3/64 dev hsr3 nodad
+
+ ip -net "$ns1" link set address 00:11:22:00:01:01 dev ns1eth1
+ ip -net "$ns1" link set address 00:11:22:00:01:02 dev ns1eth2
+
+ ip -net "$ns2" link set address 00:11:22:00:02:01 dev ns2eth1
+ ip -net "$ns2" link set address 00:11:22:00:02:02 dev ns2eth2
+
+ ip -net "$ns3" link set address 00:11:22:00:03:01 dev ns3eth1
+ ip -net "$ns3" link set address 00:11:22:00:03:02 dev ns3eth2
+
+ # All Links up
+ ip -net "$ns1" link set ns1eth1 up
+ ip -net "$ns1" link set ns1eth2 up
+ ip -net "$ns1" link set hsr1 up
+
+ ip -net "$ns2" link set ns2eth1 up
+ ip -net "$ns2" link set ns2eth2 up
+ ip -net "$ns2" link set hsr2 up
+
+ ip -net "$ns3" link set ns3eth1 up
+ ip -net "$ns3" link set ns3eth2 up
+ ip -net "$ns3" link set hsr3 up
+}
+
+run_ptp_hdr_tests()
+{
+ echo "INFO: Running PTP-header tests."
+
+ ip netns exec "$ns1" ./hsr_ptp_test -H hsr1 -A ns1eth1 -B ns1eth2
+ ret=$?
+ stop_if_error "PTP header test failed (ns1)."
+
+ ip netns exec "$ns2" ./hsr_ptp_test -H hsr2 -A ns2eth1 -B ns2eth2
+ ret=$?
+ stop_if_error "PTP header test failed (ns2)."
+
+ ip netns exec "$ns3" ./hsr_ptp_test -H hsr3 -A ns3eth1 -B ns3eth2
+ ret=$?
+ stop_if_error "PTP header test failed (ns3)."
+}
+
+check_prerequisites
+trap cleanup_all_ns EXIT
+
+setup_ns ns1 ns2 ns3
+setup_hsr_interfaces 1
+run_ptp_hdr_tests
+
+exit $ret
diff --git a/tools/testing/selftests/net/hsr/hsr_ptp_test.c b/tools/testing/selftests/net/hsr/hsr_ptp_test.c
new file mode 100644
index 00000000000000..e2c2da56138ae3
--- /dev/null
+++ b/tools/testing/selftests/net/hsr/hsr_ptp_test.c
@@ -0,0 +1,496 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Simple test to verify the usage of the inline header used for HSR with
+ * ether type ETH_P_1588.
+ * The inline header has to be stripped, the sent packet must only appear on the
+ * specified port and the interface needs to accept a foreign HSR header and
+ * prepend its own header.
+ *
+ * Socket handling inspired by raw.c from linuxptp.
+ *
+ */
+#include <poll.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <linux/types.h>
+#include <linux/hsr_ptp.h>
+#include <linux/if_ether.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netpacket/packet.h>
+#include <sys/ioctl.h>
+
+#define MSEC_TO_NSEC(_x) (_x * 1000000)
+#define USEC_PER_SEC 1000000
+#define NSEC_PER_SEC 1000000000
+
+#ifndef __packed
+#define __packed __attribute__((packed))
+#endif
+
+#define MAC_LEN 6
+typedef uint8_t eth_addr[MAC_LEN];
+
+struct eth_hdr {
+ eth_addr dst;
+ eth_addr src;
+ uint16_t type;
+} __packed;
+
+struct hsr_hdr {
+ eth_addr dst;
+ eth_addr src;
+ uint16_t type;
+ uint16_t pathid_and_LSDU_size;
+ uint16_t sequence_nr;
+ uint16_t encap_type;
+} __packed;
+
+struct hsr_meta_header {
+ struct hsr_inline_header hsr_opt;
+ union {
+ struct hsr_hdr hsr_hdr;
+ struct eth_hdr eth_hdr;
+ };
+} __packed;
+
+static uint8_t ptp_packet[] = {
+ 0x00, 0x12, 0x00, 0x2c, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x00, 0x01, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+static uint8_t p2p_dst_mac[MAC_LEN] = {
+ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e
+};
+
+static uint8_t slave_mac_addr[MAC_LEN];
+static int32_t fd_slaveA = -1;
+static int32_t fd_slaveB = -1;
+static int32_t fd_hsr = -1;
+static uint16_t hsr_seq = 37;
+
+static void tsnorm(struct timespec *ts)
+{
+ while (ts->tv_nsec >= NSEC_PER_SEC) {
+ ts->tv_nsec -= NSEC_PER_SEC;
+ ts->tv_sec++;
+ }
+}
+
+static int64_t calcdiff(struct timespec t1, struct timespec t2)
+{
+ int64_t diff = USEC_PER_SEC * (long long)((int) t1.tv_sec - (int) t2.tv_sec);
+
+ diff += ((int) t1.tv_nsec - (int) t2.tv_nsec) / 1000;
+ return diff;
+}
+
+static int tsgreater(struct timespec *a, struct timespec *b)
+{
+ return ((a->tv_sec > b->tv_sec) ||
+ (a->tv_sec == b->tv_sec && a->tv_nsec > b->tv_nsec));
+}
+
+static int sk_interface_index(int fd, const char *name)
+{
+ struct ifreq ifreq;
+ int32_t err;
+
+ memset(&ifreq, 0, sizeof(ifreq));
+ strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name) - 1);
+ err = ioctl(fd, SIOCGIFINDEX, &ifreq);
+ if (err < 0) {
+ printf("ioctl SIOCGIFINDEX failed: %m\n");
+ return err;
+ }
+ return ifreq.ifr_ifindex;
+}
+
+static int open_socket(const char *name)
+{
+ struct sockaddr_ll addr;
+ int32_t fd, index;
+
+ fd = socket(AF_PACKET, SOCK_RAW, 0);
+ if (fd < 0) {
+ printf("socket failed: %m\n");
+ goto err;
+ }
+ index = sk_interface_index(fd, name);
+ if (index < 0)
+ goto err;
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sll_ifindex = index;
+ addr.sll_family = AF_PACKET;
+ addr.sll_protocol = htons(ETH_P_ALL);
+ if (bind(fd, (struct sockaddr *) &addr, sizeof(addr))) {
+ printf("bind failed: %m\n");
+ goto err;
+ }
+ if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, name, strlen(name))) {
+ printf("setsockopt SO_BINDTODEVICE failed: %m\n");
+ goto err;
+ }
+
+ return fd;
+err:
+ if (fd >= 0)
+ close(fd);
+ return -1;
+}
+
+static int sk_interface_macaddr(const char *name)
+{
+ struct ifreq ifreq;
+ int32_t err, fd;
+
+ memset(&ifreq, 0, sizeof(ifreq));
+ strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name) - 1);
+
+ fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (fd < 0) {
+ printf("socket failed: %m\n");
+ return -1;
+ }
+
+ err = ioctl(fd, SIOCGIFHWADDR, &ifreq);
+ if (err < 0) {
+ printf("ioctl SIOCGIFHWADDR failed: %m\n");
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+
+ memcpy(slave_mac_addr, &ifreq.ifr_hwaddr.sa_data, MAC_LEN);
+ return 0;
+}
+
+static int raw_open(const char *hsr_dev, const char *slaveA_dev, const char *slaveB_dev)
+{
+
+ if (sk_interface_macaddr(slaveA_dev))
+ goto err;
+
+ fd_slaveA = open_socket(slaveA_dev);
+ if (fd_slaveA < 0)
+ goto err;
+
+ fd_slaveB = open_socket(slaveB_dev);
+ if (fd_slaveB < 0)
+ goto err;
+
+ fd_hsr = open_socket(hsr_dev);
+ if (fd_hsr < 0)
+ goto err;
+
+ return 0;
+
+err:
+ if (fd_slaveA >= 0)
+ close(fd_slaveA);
+ if (fd_slaveB >= 0)
+ close(fd_slaveB);
+ if (fd_hsr >= 0)
+ close(fd_hsr);
+
+ return -1;
+}
+
+static int sk_receive(int fd, void *buf, int buflen)
+{
+ struct iovec iov = { buf, buflen };
+ uint8_t control[256];
+ int32_t cnt = 0;
+ struct msghdr msg;
+
+ memset(control, 0, sizeof(control));
+ memset(&msg, 0, sizeof(msg));
+
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = control;
+ msg.msg_controllen = sizeof(control);
+
+ cnt = recvmsg(fd, &msg, MSG_DONTWAIT);
+ if (cnt < 0)
+ return 0;
+ return cnt;
+}
+
+static int raw_recv(int fd, bool fwd_hsr, void *sample, int sample_len)
+{
+ struct timespec now, end;
+ struct hsr_hdr *hsr_hdr;
+ uint8_t buf[1500];
+ int32_t cnt;
+
+ /* The packet is expected to arrive within 100ms. HSR will send hello
+ * packets so there an end time and poll() will wait until this point.
+ */
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ end = now;
+ end.tv_nsec += MSEC_TO_NSEC(100);
+ tsnorm(&end);
+again:
+
+ cnt = sk_receive(fd, buf, sizeof(buf));
+ if (cnt == 0) {
+ int64_t sleep_time;
+ struct pollfd pfd;
+ int ret;
+
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (tsgreater(&now, &end))
+ return 0;
+
+ sleep_time = calcdiff(end, now) / 1000;
+ if (sleep_time <= 0)
+ return 0;
+
+ pfd.fd = fd;
+ pfd.events = POLLIN;
+ ret = poll(&pfd, 1, sleep_time);
+ if (ret <= 0)
+ return ret;
+ goto again;
+ }
+
+ if (cnt < sizeof(struct hsr_hdr))
+ goto again;
+
+ hsr_hdr = (void *)buf;
+ /* Embedded magic packet passed? */
+ if (hsr_hdr->type == htons(ETH_P_1588)) {
+ struct hsr_inline_header *hsr_opt = (void *)buf;
+
+ if (hsr_opt->magic == htonl(HSR_INLINE_HDR)) {
+ printf("Error: Found HSR_INLINE_HDR\n");
+ return -1;
+ }
+ }
+ /* Assuming it is *our* network and nobody but the test here sends
+ * packets to p2p_dst_mac. Therefore any received packet needs to be
+ * ours and every mismatch is considered as error.
+ */
+ if (memcmp(hsr_hdr->dst, p2p_dst_mac, MAC_LEN))
+ goto again;
+
+ if (hsr_hdr->type != htons(ETH_P_HSR)) {
+ printf("Error: Unexpected ether type: 0x%x\n", ntohs(hsr_hdr->type));
+ return -1;
+ }
+
+ if (hsr_hdr->encap_type != htons(ETH_P_1588)) {
+ printf("Error: Unexpected encapsulated type: 0x%x\n",
+ htons(hsr_hdr->encap_type));
+ return -1;
+ }
+
+ if (fwd_hsr) {
+ if (hsr_hdr->sequence_nr != htons(hsr_seq - 1)) {
+ printf("Error: Packet has wrong seq nr, %d vs %d.\n",
+ ntohs(hsr_hdr->sequence_nr), hsr_seq - 1);
+ return -1;
+ }
+ /* Undo the SRC MAC change in pkt_send() */
+ hsr_hdr->src[3] ^= 0x21;
+ if (memcmp(hsr_hdr->src, slave_mac_addr, MAC_LEN)) {
+ printf("Error: Packet has wrong SRC-MAC\n");
+ return -1;
+ }
+ }
+
+ if (cnt < sizeof(struct hsr_hdr) + sample_len) {
+ printf("Error: Packet %d is too small for data check\n", cnt);
+ return -1;
+ }
+
+ if (!memcmp(&buf[sizeof(struct hsr_hdr)], sample, sample_len))
+ return 1;
+
+ printf("Error: Packet did not match the sample\n");
+ return -1;
+}
+
+static int recv_verify(int port, bool fwd_hsr, void *sample, int sample_len)
+{
+ int32_t error = 0;
+ int32_t ret;
+
+ ret = raw_recv(fd_slaveA, fwd_hsr, sample, sample_len);
+ if (ret < 0)
+ return ret;
+ if (port == HSR_INLINE_HDR_PORT_A && ret == 0) {
+ printf("Error: Missing packet on portA\n");
+ error = 1;
+ }
+ if (port == HSR_INLINE_HDR_PORT_B && ret == 1) {
+ printf("Error: Not expecting packet on portA\n");
+ error = 1;
+ }
+
+ ret = raw_recv(fd_slaveB, fwd_hsr, sample, sample_len);
+ if (ret < 0)
+ return ret;
+ if (port == HSR_INLINE_HDR_PORT_B && ret == 0) {
+ printf("Error: Missing packet on portB\n");
+ error = 1;
+ }
+ if (port == HSR_INLINE_HDR_PORT_A && ret == 1) {
+ printf("Error: Not expecting packet on portB\n");
+ error = 1;
+ }
+ return error;
+}
+
+static int32_t pkt_send(int port, bool hsr_hdr, void *data, int data_len)
+{
+ struct hsr_meta_header *hdr;
+ uint8_t packet[200];
+ ssize_t cnt;
+ size_t len;
+
+ memset(packet, 0, sizeof(packet));
+
+ len = sizeof(struct hsr_inline_header);
+ hdr = (struct hsr_meta_header *)packet;
+ memset(&hdr->hsr_opt, 0, sizeof(hdr->hsr_opt));
+ hdr->hsr_opt.magic = htonl(HSR_INLINE_HDR);
+ hdr->hsr_opt.eth_type = htons(ETH_P_1588);
+ if (port != HSR_INLINE_HDR_PORT_A && port != HSR_INLINE_HDR_PORT_B) {
+ printf("Wrong port requested\n");
+ return -1;
+ }
+ hdr->hsr_opt.req_tx_port = port;
+
+ if (hsr_hdr) {
+ uint16_t pathid_size;
+
+ len += sizeof(struct hsr_hdr);
+ memcpy(&packet[len], data, data_len);
+
+ hdr->hsr_opt.has_hsr_header = 1;
+
+ memcpy(&hdr->hsr_hdr.dst, p2p_dst_mac, MAC_LEN);
+ memcpy(&hdr->hsr_hdr.src, slave_mac_addr, MAC_LEN);
+ /* Flip a bit in SRC MAC addr so it does not look like hosts */
+ hdr->hsr_hdr.src[3] ^= 0x21;
+
+ hdr->hsr_hdr.type = htons(ETH_P_HSR);
+ hdr->hsr_hdr.sequence_nr = htons(hsr_seq++);
+ hdr->hsr_hdr.encap_type = htons(ETH_P_1588);
+
+ /* The resulting packet must be alteast 66 bytes */
+ if (data_len + sizeof(struct hsr_hdr) < 66)
+ data_len = 66 - sizeof(struct hsr_hdr);
+
+ pathid_size = data_len + sizeof(struct hsr_hdr) - sizeof(struct eth_hdr);
+ pathid_size |= (port - 1) << 12;
+
+ hdr->hsr_hdr.pathid_and_LSDU_size = htons(pathid_size);
+ } else {
+ len += sizeof(struct eth_hdr);
+ hdr->hsr_opt.has_hsr_header = 0;
+
+ memcpy(&hdr->eth_hdr.dst, p2p_dst_mac, MAC_LEN);
+ memcpy(&hdr->eth_hdr.src, slave_mac_addr, MAC_LEN);
+ hdr->eth_hdr.type = htons(ETH_P_1588);
+
+ memcpy(&packet[len], data, data_len);
+ }
+
+ cnt = send(fd_hsr, packet, len + data_len, 0);
+ if (cnt < 1)
+ return -1;
+
+ return cnt;
+}
+
+int main(int argc, char *argv[])
+{
+ char *slaveA = NULL, *slaveB = NULL, *hsr_dev = NULL;
+ char *msg_mode;
+ int opt;
+
+ while ((opt = getopt(argc, argv, "A:B:H:")) != -1) {
+ switch (opt) {
+ case 'A':
+ slaveA = strdup(optarg);
+ break;
+
+ case 'B':
+ slaveB = strdup(optarg);
+ break;
+
+ case 'H':
+ hsr_dev = strdup(optarg);
+ break;
+ default: /* '?' */
+ fprintf(stderr, "Usage: %s -A slaveA -B slaveB -H hsr_device\n",
+ argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!slaveA || !slaveB || !hsr_dev) {
+ fprintf(stderr, "Missing network devices\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (raw_open(hsr_dev, slaveA, slaveB) < 0)
+ return EXIT_FAILURE;
+
+ msg_mode = "PortA, no-hsr-header";
+ if (pkt_send(HSR_INLINE_HDR_PORT_A, false, ptp_packet, sizeof(ptp_packet)) < 0) {
+ printf("Sending failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+ if (recv_verify(HSR_INLINE_HDR_PORT_A, false, ptp_packet, sizeof(ptp_packet))) {
+ printf("Verify failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+
+ ptp_packet[16 + 4]++;
+ msg_mode = "PortB, no-hsr-header";
+ if (pkt_send(HSR_INLINE_HDR_PORT_B, false, ptp_packet, sizeof(ptp_packet)) < 0) {
+ printf("Sending failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+ if (recv_verify(HSR_INLINE_HDR_PORT_B, false, ptp_packet, sizeof(ptp_packet))) {
+ printf("Verify failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+
+ ptp_packet[16 + 4]++;
+ msg_mode = "PortA, hsr-header";
+ if (pkt_send(HSR_INLINE_HDR_PORT_A, true, ptp_packet, sizeof(ptp_packet)) < 0) {
+ printf("Sending failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+ if (recv_verify(HSR_INLINE_HDR_PORT_A, true, ptp_packet, sizeof(ptp_packet))) {
+ printf("Verify failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+
+ ptp_packet[16 + 4]++;
+ msg_mode = "PortB, hsr-header";
+ if (pkt_send(HSR_INLINE_HDR_PORT_B, true, ptp_packet, sizeof(ptp_packet)) < 0) {
+ printf("Sending failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+ if (recv_verify(HSR_INLINE_HDR_PORT_B, true, ptp_packet, sizeof(ptp_packet))) {
+ printf("Verify failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
|
| 3/2 | 2026/11/25 09:51 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17917 output: 28 thoughts: 340 Thoughts: **Analyzing This Linux Kernel Patch: An HSR Deep Dive** Okay, so the user wants me to dissect this patch applied to the Linux kernel. First things first: let's get a handle on what this patch *actually* does. From the file list, I see it's touching quite a few files: the `MAINTAINERS` file (good, ensuring the right people are in the loop!), the include files related to `if_hsr` and `hsr_ptp`, several source files within `net/hsr/`, and even a tool within the `tools` directory. That points directly to the High-availability Seamless Redundancy (HSR) protocol, defined in IEC 62439-3, which operates within the Linux kernel as a virtual network interface driver under `net/hsr/`. Now, let's refresh on HSR and how it is typically configured. My understanding is that you can absolutely create these HSR devices within standard virtualized environments, like QEMU or even Google Compute Engine. I believe the core of it all is the `ip link add ... type hsr slave1 ... slave2 ...` command. It makes use of standard virtual interfaces like veth, dummy, and tap devices, which I have used myself in virtualized test environments. As a matter of fact, I recall, the selftest in `tools/testing/selftests/net/hsr/hsr_ptp.sh` does precisely that: creating virtual devices by adding `veth` interfaces using `ip link add ns1eth1 type veth peer name ns2eth1` and then creating the HSR interface on top of them, with the command `ip link add name hsr1 type hsr slave1 ns1eth1 slave2 ns1eth2`. That seems to be a reliable configuration for understanding the underlying principles. Therefore, next I should probably check the Kconfig files to see how the `CONFIG_HSR` option is configured and any related dependencies. This will help with the understanding of what features are added or modified by this patch, what new functionality is being introduced, or, at a minimum, what configuration options might be affected. |
| 4/2 | 2026/11/25 09:52 | tool | grepper |
0mArgs:{
"Expression": "config HSR",
"PathPrefixes": [
"net/hsr"
]
}Results: {
"Output": "net/hsr/Kconfig-5-\nnet/hsr/Kconfig:6:config HSR\nnet/hsr/Kconfig-7-\ttristate \"High-availability Seamless Redundancy (HSR \u0026 PRP)\"\n"
} |
| 5/2 | 2026/11/25 09:52 | llm | patch-evaluator |
2mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 18816 output: 33 thoughts: 13 Thoughts: Okay, let's dive into this. Here's my take on examining `net/hsr/Kconfig`: **Analyzing `net/hsr/Kconfig`** Alright, I'm going to take a look at the `net/hsr/Kconfig` file. I immediately recognize this as the configuration file for the HSR (High-availability Seamless Redundancy) protocol in the Linux kernel networking stack. Given my expertise, I'm expecting this file to define the various configuration options related to enabling, disabling, and customizing HSR functionality. I'll be specifically looking for: * **Dependencies and Relationships:** I'll quickly want to see what other kernel subsystems or features `net/hsr/Kconfig` depends on. Are there any prerequisites, like specific network drivers or other protocol support? I'm anticipating interactions with the Ethernet driver infrastructure, potentially the `net/` directory's core. * **Feature Flags:** I'm expecting to find a series of `config` options that users can set. These will likely control aspects like enabling HSR support as a whole (`CONFIG_HSR`), controlling specific features such as the maximum frame size or the various HSR implementations that might be supported. I'll need to know whether any of these are selectable based on a choice, or if they're standalone booleans or tristates. * **Help Text and Descriptions:** I will pay close attention to the help text associated with each option. This is where the file provides clarity to the user and will be useful to understand the purpose of each flag. Well-written help text here is critical for maintainability and usability. * **Defaults:** Checking the defaults associated with options. Understanding the default settings is paramount to establishing the base behavior of the HSR module and understanding how it functions out of the box. * **Conditional Logic:** The Kconfig format can employ various conditional logic constructs like `if`, `select`, `depends on`, and `default`. I'll analyze those statements to see how configurations are interlinked and how certain options are activated/deactivated based on other settings. This is key to understanding the module's flexibility and potential limitations. * **Architectural Considerations:** I'll also be on the lookout for architecture-specific configurations. Are there options that only apply to certain CPU architectures or hardware platforms? I would anticipate some of the internal functionality might be architecture-specific. * **Potential Areas for Improvement:** Throughout my review, I'll be forming opinions about the design and implementation, checking for areas for potential improvements in terms of clarity, organization, or completeness. I'll be thinking about how well the configuration options align with best practices and whether there are any potential ambiguities or conflicts. I'll keep all of this in mind, and as an expert, I'll quickly pick up on the subtleties and implications of each configuration setting as I go. Let's start examining! |
| 6/2 | 2026/11/25 09:55 | tool | read-file |
0mArgs:{
"File": "net/hsr/Kconfig",
"FirstLine": 1,
"LineCount": 40
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\t#\n 3:\t# IEC 62439-3 High-availability Seamless Redundancy\n 4:\t#\n 5:\t\n 6:\tconfig HSR\n 7:\t\ttristate \"High-availability Seamless Redundancy (HSR \u0026 PRP)\"\n 8:\t\thelp\n 9:\t\t This enables IEC 62439 defined High-availability Seamless\n 10:\t\t Redundancy (HSR) and Parallel Redundancy Protocol (PRP).\n 11:\t\n 12:\t\t If you say Y here, then your Linux box will be able to act as a\n 13:\t\t DANH (\"Doubly attached node implementing HSR\") or DANP (\"Doubly\n 14:\t\t attached node implementing PRP\"). For this to work, your Linux box\n 15:\t\t needs (at least) two physical Ethernet interfaces.\n 16:\t\n 17:\t\t For DANH, it must be connected as a node in a ring network together\n 18:\t\t with other HSR capable nodes. All Ethernet frames sent over the HSR\n 19:\t\t device will be sent in both directions on the ring (over both slave\n 20:\t\t ports), giving a redundant, instant fail-over network. Each HSR node\n 21:\t\t in the ring acts like a bridge for HSR frames, but filters frames\n 22:\t\t that have been forwarded earlier.\n 23:\t\n 24:\t\t For DANP, it must be connected as a node connecting to two\n 25:\t\t separate networks over the two slave interfaces. Like HSR, Ethernet\n 26:\t\t frames sent over the PRP device will be sent to both networks giving\n 27:\t\t a redundant, instant fail-over network. Unlike HSR, PRP networks\n 28:\t\t can have Singly Attached Nodes (SAN) such as PC, printer, bridges\n 29:\t\t etc and will be able to communicate with DANP nodes.\n 30:\t\n 31:\t\t This code is a \"best effort\" to comply with the HSR standard as\n 32:\t\t described in IEC 62439-3:2010 (HSRv0) and IEC 62439-3:2012 (HSRv1),\n 33:\t\t and PRP standard described in IEC 62439-4:2012 (PRP), but no\n 34:\t\t compliancy tests have been made. Use iproute2 to select the protocol\n 35:\t\t you would like to use.\n 36:\t\n 37:\t\t You need to perform any and all necessary tests yourself before\n 38:\t\t relying on this code in a safety critical system!\n 39:\t\n 40:\t\t If unsure, say N.\n"
} |
| 7/2 | 2026/11/25 09:55 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20192 output: 27 thoughts: 56 Thoughts: Okay, let's dive into this. Here's how I'm thinking about it: **Investigating the Dependencies of CONFIG_HSR** Alright, I need to figure out what dependencies are driving `CONFIG_HSR`. It looks like in the main `Kconfig` file, there aren't any explicit "depends on" lines directly associated with `config HSR`. That's a little unusual, but not a problem. Since `net/hsr/Kconfig` is likely sourced or included by another `Kconfig` file, I'll need to trace back from `net/hsr/Kconfig` to see where it's being incorporated to find the dependencies. I'll head over to `net/Kconfig` and take a look. That should give me the larger context and reveal the necessary conditions for `CONFIG_HSR` to be enabled. This should give me a complete picture. |
| 8/2 | 2026/11/25 09:56 | tool | grepper |
0mArgs:{
"Expression": "hsr/Kconfig",
"PathPrefixes": [
"net"
]
}Results: {
"Output": "net/Kconfig=277=source \"net/nsh/Kconfig\"\nnet/Kconfig:278:source \"net/hsr/Kconfig\"\nnet/Kconfig-279-source \"net/switchdev/Kconfig\"\n"
} |
| 9/2 | 2026/11/25 09:56 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20542 output: 32 thoughts: 17 Thoughts: Okay, let's dive into this. Here's my thought process summarized, assuming I'm already pretty familiar with kernel configuration: **Investigating a Kernel Configuration Detail** Right, let's get down to brass tacks. I need to zero in on something specific in the `net/Kconfig` file. Given the task at hand, my instincts are telling me that the relevant section is probably around line 278. Time to open that file and see what's what. Let's see if this hunch is correct, or if I need to adjust my search. |
| 10/2 | 2026/11/25 09:57 | tool | read-file |
0mArgs:{
"File": "net/Kconfig",
"FirstLine": 270,
"LineCount": 20
}Results: {
"Contents": " 270:\tsource \"net/dcb/Kconfig\"\n 271:\tsource \"net/dns_resolver/Kconfig\"\n 272:\tsource \"net/batman-adv/Kconfig\"\n 273:\tsource \"net/openvswitch/Kconfig\"\n 274:\tsource \"net/vmw_vsock/Kconfig\"\n 275:\tsource \"net/netlink/Kconfig\"\n 276:\tsource \"net/mpls/Kconfig\"\n 277:\tsource \"net/nsh/Kconfig\"\n 278:\tsource \"net/hsr/Kconfig\"\n 279:\tsource \"net/switchdev/Kconfig\"\n 280:\tsource \"net/l3mdev/Kconfig\"\n 281:\tsource \"net/qrtr/Kconfig\"\n 282:\tsource \"net/ncsi/Kconfig\"\n 283:\t\n 284:\tconfig PCPU_DEV_REFCNT\n 285:\t\tbool \"Use percpu variables to maintain network device refcount\"\n 286:\t\tdepends on SMP\n 287:\t\tdefault y\n 288:\t\thelp\n 289:\t\t network device refcount are using per cpu variables if this option is set.\n"
} |
| 11/2 | 2026/11/25 09:57 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 21051 output: 38 thoughts: 3545 Thoughts: **HSR with PTP Frame Support: A Deep Dive** Okay, so I'm looking at this patch for HSR (High-availability Seamless Redundancy) and PTP (Precision Time Protocol) support, and it's quite interesting. First, HSR is now directly configurable under Networking options, which is a good move for accessibility. The core of this patch introduces inline header support for PTP frames transmitted over HSR. I see that the code defines a new `hsr_inline_header` structure in `include/uapi/linux/hsr_ptp.h`, along with some helpful macros. This structure is packed, which is standard for network headers to ensure efficient memory usage. Now, let's trace this through the code. I immediately spotted changes in `net/hsr/hsr_device.c`. The `hsr_dev_xmit` function is key here. It checks if the `skb->protocol` is `ETH_P_1588` (PTP) and calls `hsr_ptp_parse_header` to handle inline headers. Inside `hsr_ptp_parse_header`, it parses the `hsr_inline_header` to determine the required transmit port and validate the inline header magic. It then adjusts the SKB's headers accordingly. The core logic now correctly handles stripping the inline header and setting the `skb->protocol`. I got a little sidetracked by how the SKB is handled when the HSR header is actually *not* present, but `skb_reset_mac_len` looks like it sets the correct length, after `skb_set_network_header`. I'm also noticing a significant rewrite of how SKB tag insertion is handled in `net/hsr/hsr_forward.c`, using `skb_clone`, `skb_cow_head`, and `skb_postpush_data_move` instead of the older `__pskb_copy`. This affects all tagged frame creation within HSR. It is a good thing that `skb_set_owner_w` is being set. More interesting, the patch adds conditional forwarding logic for frames with a specific outgoing port and those already carrying an HSR header. I see they also added two new assertions, and I want to investigate the `WARN_ON_ONCE` checks in `hsr_fill_frame_info`. These checks confirm that a frame isn't malformed. Specifically, I'm concerned that `skb->mac_len < sizeof(struct hsr_ethhdr)` could trigger and cause an unwanted code path. This could happen if a frame somehow gets crafted incorrectly. I'm especially curious about packets arriving via AF_PACKET, raw sockets, or injected packets, as those might bypass some of the normal header validation. I think I'll create a few test cases around that. Finally, I reviewed `hsr_slave.c` and found that the code explicitly *drops* incoming PTP frames on HSR slave ports, which makes sense from a timing perspective. The new code uses a `finish_free_consume` label that cleans the SKB. That makes sense. I will need to ensure there are no side effects from this change. |
| 12/2 | 2026/11/25 09:57 | tool | read-file |
0mArgs:{
"File": "net/hsr/hsr_slave.c",
"FirstLine": 40,
"LineCount": 60
}Results: {
"Contents": " 40:\t\n 41:\t\tport = hsr_port_get_rcu(skb-\u003edev);\n 42:\t\tif (!port)\n 43:\t\t\tgoto finish_pass;\n 44:\t\thsr = port-\u003ehsr;\n 45:\t\n 46:\t\tif (hsr_addr_is_self(port-\u003ehsr, eth_hdr(skb)-\u003eh_source)) {\n 47:\t\t\t/* Directly kill frames sent by ourselves */\n 48:\t\t\tgoto finish_free_consume;\n 49:\t\t}\n 50:\t\n 51:\t\t/* For HSR, only tagged frames are expected (unless the device offloads\n 52:\t\t * HSR tag removal), but for PRP there could be non tagged frames as\n 53:\t\t * well from Single attached nodes (SANs).\n 54:\t\t */\n 55:\t\tprotocol = eth_hdr(skb)-\u003eh_proto;\n 56:\t\n 57:\t\tif (!(port-\u003edev-\u003efeatures \u0026 NETIF_F_HW_HSR_TAG_RM) \u0026\u0026\n 58:\t\t port-\u003etype != HSR_PT_INTERLINK \u0026\u0026\n 59:\t\t hsr-\u003eproto_ops-\u003einvalid_dan_ingress_frame \u0026\u0026\n 60:\t\t hsr-\u003eproto_ops-\u003einvalid_dan_ingress_frame(protocol))\n 61:\t\t\tgoto finish_pass;\n 62:\t\n 63:\t\tskb_push(skb, ETH_HLEN);\n 64:\t\tskb_reset_mac_header(skb);\n 65:\t\tif ((!hsr-\u003eprot_version \u0026\u0026 protocol == htons(ETH_P_PRP)) ||\n 66:\t\t protocol == htons(ETH_P_HSR)) {\n 67:\t\t\tif (!pskb_may_pull(skb, ETH_HLEN + HSR_HLEN))\n 68:\t\t\t\tgoto finish_free_consume;\n 69:\t\n 70:\t\t\tskb_set_network_header(skb, ETH_HLEN + HSR_HLEN);\n 71:\t\t}\n 72:\t\tskb_reset_mac_len(skb);\n 73:\t\n 74:\t\t/* PTP packets are not supposed to be forwarded via HSR as-is. The\n 75:\t\t * latency introduced by forwarding renders the time information\n 76:\t\t * useless. Userland needs to capture the packet on the original\n 77:\t\t * interface instead of hsr.\n 78:\t\t */\n 79:\t\tif ((!hsr-\u003eprot_version \u0026\u0026 protocol == htons(ETH_P_PRP)) ||\n 80:\t\t protocol == htons(ETH_P_HSR)) {\n 81:\t\t\thsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb);\n 82:\t\t\tif (hsr_ethhdr-\u003ehsr_tag.encap_proto == htons(ETH_P_1588))\n 83:\t\t\t\tgoto finish_free_consume;\n 84:\t\t} else {\n 85:\t\t\tif (protocol == htons(ETH_P_1588))\n 86:\t\t\t\tgoto finish_free_consume;\n 87:\t\t}\n 88:\t\n 89:\t\t/* Only the frames received over the interlink port will assign a\n 90:\t\t * sequence number and require synchronisation vs other sender.\n 91:\t\t */\n 92:\t\tif (port-\u003etype == HSR_PT_INTERLINK) {\n 93:\t\t\tspin_lock_bh(\u0026hsr-\u003eseqnr_lock);\n 94:\t\t\thsr_forward_skb(skb, port, HSR_PT_NONE, false);\n 95:\t\t\tspin_unlock_bh(\u0026hsr-\u003eseqnr_lock);\n 96:\t\t} else {\n 97:\t\t\thsr_forward_skb(skb, port, HSR_PT_NONE, false);\n 98:\t\t}\n 99:\t\n"
} |
| 13/2 | 2026/11/25 09:57 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26327 output: 47 thoughts: 966 Thoughts: **Analyzing the `hsr_create_tagged_frame` Function** Okay, let's dive into this `hsr_create_tagged_frame` function within `net/hsr/hsr_forward.c`. I'm starting by looking at lines 342-385. The function's purpose is clear; create a tagged HSR frame. Immediately, I see a few key paths: one where `frame->skb_hsr` is already populated, and another where it isn't, and we clone `frame->skb_std`. The first path's `hsr_set_path_id` is fine, returning a cloned skb. The other path clones, sets an owner if needed, and checks for hardware HSR tag insertion. If the NIC supports it, we return the skb; otherwise, we need to manually tag the frame. That's where things get interesting. I'm noticing something significant. A previous iteration of this function used `__pskb_copy` with an added `HSR_HLEN` to the headroom. And, previously we had: `if (skb->ip_summed == CHECKSUM_PARTIAL) skb->csum_start += HSR_HLEN;` Now that's REMOVED! Hold on... why was that removed? Is this intentional, or did someone overlook something that could cause a checksum issue? I have to dig deeper on that one. Focusing on the new code flow, it uses `skb_clone`, `skb_cow_head`, `skb_push`, and `skb_postpush_data_move`. The use of `skb_cow_head` is to ensure we have enough headroom before modifying the skb. Wait, what is the contract of `skb_cow_head`? I need to look closely at its behavior. Does it simply check headroom, or does it also handle the actual allocation? Particularly: `skb_cow_head(skb, skb_metadata_len(skb) + HSR_HLEN)`. I need to verify how `skb_cow_head` handles the required headroom when adding the HSR header. I'll need to check the function signature and contract of `skb_cow_head`. |
| 14/2 | 2026/11/25 09:58 | tool | grepper |
0mArgs:{
"Expression": "int skb_cow_head",
"PathPrefixes": [
"include/linux/skbuff.h",
"net/core/skbuff.c"
]
}Results: {
"Output": "include/linux/skbuff.h=3921=static inline int skb_cow(struct sk_buff *skb, unsigned int headroom)\n--\ninclude/linux/skbuff.h-3935- */\ninclude/linux/skbuff.h:3936:static inline int skb_cow_head(struct sk_buff *skb, unsigned int headroom)\ninclude/linux/skbuff.h-3937-{\n"
} |
| 15/2 | 2026/11/25 09:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27958 output: 37 thoughts: 22 Thoughts: Okay, let's dive into this. Here's my take on those instructions: **Analyzing `include/linux/skbuff.h` around line 3936** Alright, the directive is clear. I need to take a look at the `include/linux/skbuff.h` header file. Specifically, I'm directed towards the vicinity of line 3936. Given the context, this is almost certainly related to the Socket Buffer, or `skb`, structure, a core data structure in the Linux networking stack. That line number is likely the location of a particular function definition, macro, or perhaps a data structure declaration that's particularly relevant to whatever networking problem is currently on the table. My initial thought is to quickly identify what the relevant item is, given the common patterns in `skbuff.h`. Is it related to fragmentation, checksum offloading, buffer management, or maybe a specific network protocol? I expect to rapidly parse the surrounding code, paying close attention to any function signatures, data structures, and comments. My goal is not to memorize the entire file, but to understand the logic flow and how a particular piece of functionality operates. This will help me gain the information needed to solve the issue I am considering. |
| 16/2 | 2026/11/25 09:58 | tool | read-file |
0mArgs:{
"File": "include/linux/skbuff.h",
"FirstLine": 3930,
"LineCount": 25
}Results: {
"Contents": "3930:\t *\n3931:\t *\tThis function is identical to skb_cow except that we replace the\n3932:\t *\tskb_cloned check by skb_header_cloned. It should be used when\n3933:\t *\tyou only need to push on some header and do not need to modify\n3934:\t *\tthe data.\n3935:\t */\n3936:\tstatic inline int skb_cow_head(struct sk_buff *skb, unsigned int headroom)\n3937:\t{\n3938:\t\treturn __skb_cow(skb, headroom, skb_header_cloned(skb));\n3939:\t}\n3940:\t\n3941:\t/**\n3942:\t *\tskb_padto\t- pad an skbuff up to a minimal size\n3943:\t *\t@skb: buffer to pad\n3944:\t *\t@len: minimal length\n3945:\t *\n3946:\t *\tPads up a buffer to ensure the trailing bytes exist and are\n3947:\t *\tblanked. If the buffer already contains sufficient data it\n3948:\t *\tis untouched. Otherwise it is extended. Returns zero on\n3949:\t *\tsuccess. The skb is freed on error.\n3950:\t */\n3951:\tstatic inline int skb_padto(struct sk_buff *skb, unsigned int len)\n3952:\t{\n3953:\t\tunsigned int size = skb-\u003elen;\n3954:\t\tif (likely(size \u003e= len))\n"
} |
| 17/2 | 2026/11/25 09:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28705 output: 30 thoughts: 563 Thoughts: **Analyzing `skb_cow_head` and Headroom Management** Okay, let's break this down. I'm looking at the `skb_cow_head` function. The `headroom` parameter, naturally, represents the amount of headroom required, seems straightforward. But wait, in this call `skb_cow_head(skb, skb_metadata_len(skb) + HSR_HLEN)`, what's the deal with the `skb_headroom(skb)` when the SKB is cloned? It's crucial. If the existing `skb_headroom(skb)` is, for example, just 2 bytes, but we're passing `skb_metadata_len(skb) + HSR_HLEN` (which equals 6 bytes) as the requested headroom to `skb_cow_head`, the internal check within `__skb_cow` becomes critical: `static inline int __skb_cow(struct sk_buff *skb, unsigned int headroom, int cloned)`... Essentially, if the *requested* headroom exceeds the current headroom, `delta` calculates the difference. Now, if `delta` is non-zero *or* the SKB is cloned, we have a call to `pskb_expand_head`. That function manages the actual reallocation/expansion. So, if `headroom` is *less* than `skb_headroom(skb)` but the SKB is cloned, then `pskb_expand_head(skb, 0, 0, GFP_ATOMIC)` would get called which results in a reallocation of the head without increasing headroom. Now, if we then call `skb_push(skb, HSR_HLEN)`, and we only have 2 bytes, that doesn't work! So let's look at the positive case. If `skb_headroom` was originally 2, and the passed `headroom` value is 6, then `delta = 6 - 2 = 4`. The call would look like `pskb_expand_head(skb, ALIGN(4, NET_SKB_PAD), 0)`, which means the headroom is expanded by at least `NET_SKB_PAD`. However, the real question is why is `skb_metadata_len + HSR_HLEN` passed as `headroom`? And how does the `skb_cow_head(skb, delta)` thing work? In essence, when a kernel driver needs to push `HSR_HLEN` bytes onto the `skb`, how is `skb_cow_head` actually invoked? Time to do a quick grep across the kernel to see the standard usage patterns. We'll find real usage to truly understand the intent here. |
| 18/2 | 2026/11/25 09:58 | tool | grepper |
0mArgs:{
"Expression": "skb_cow_head\\(",
"PathPrefixes": [
"net/"
]
}Results: {
"Output": "\nFull output is too long, showing 200 out of 337 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (32 files in total):\nnet/8021q/vlan_dev.c:1\nnet/atm/pppoatm.c:1\nnet/batman-adv/fragmentation.c:1\nnet/batman-adv/mesh-interface.c:2\nnet/bridge/br_netfilter_hooks.c:1\nnet/bridge/netfilter/nf_conntrack_bridge.c:1\nnet/core/filter.c:2\nnet/core/gso.c:1\nnet/core/lwt_bpf.c:3\nnet/core/skbuff.c:3\nnet/hsr/hsr_forward.c:1\nnet/ife/ife.c:1\nnet/ipv4/ip_gre.c:6\nnet/ipv4/ip_tunnel.c:2\nnet/ipv6/ioam6_iptunnel.c:3\nnet/ipv6/ip6_gre.c:3\nnet/ipv6/ip6_tunnel.c:1\nnet/ipv6/rpl_iptunnel.c:3\nnet/ipv6/seg6_iptunnel.c:6\nnet/l2tp/l2tp_core.c:1\nnet/l2tp/l2tp_ppp.c:1\nnet/mac80211/rx.c:1\nnet/mpls/mpls_iptunnel.c:1\nnet/netfilter/nf_dup_netdev.c:1\nnet/netfilter/nf_flow_table_ip.c:4\nnet/nfc/nci/data.c:1\nnet/nsh/nsh.c:1\nnet/openvswitch/actions.c:1\nnet/phonet/af_phonet.c:1\nnet/psp/psp_main.c:1\nnet/sched/sch_frag.c:1\nnet/xfrm/xfrm_input.c:1\n\nnet/8021q/vlan_dev.c=46=static int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,\n--\nnet/8021q/vlan_dev.c-60-\nnet/8021q/vlan_dev.c:61:\t\tif (skb_cow_head(skb, hlen) \u003c 0)\nnet/8021q/vlan_dev.c-62-\t\t\treturn -ENOMEM;\n--\nnet/atm/pppoatm.c=289=static int pppoatm_send(struct ppp_channel *chan, struct sk_buff *skb)\n--\nnet/atm/pppoatm.c-322-\tcase e_llc:\nnet/atm/pppoatm.c:323:\t\tif (skb_cow_head(skb, LLC_LEN)) {\nnet/atm/pppoatm.c-324-\t\t\tbh_unlock_sock(sk_atm(vcc));\n--\nnet/batman-adv/fragmentation.c=505=int batadv_frag_send_packet(struct sk_buff *skb,\n--\nnet/batman-adv/fragmentation.c-611-\t */\nnet/batman-adv/fragmentation.c:612:\tret = skb_cow_head(skb, ETH_HLEN + header_size);\nnet/batman-adv/fragmentation.c-613-\tif (ret \u003c 0)\n--\nnet/batman-adv/mesh-interface.c-60- * Warning: This function may reallocate the skb data buffer via\nnet/batman-adv/mesh-interface.c:61: * skb_cow_head()/... Any pointer into the skb data (e.g. obtained\nnet/batman-adv/mesh-interface.c-62- * from skb-\u003edata or eth_hdr()) before this call must be considered\n--\nnet/batman-adv/mesh-interface.c=67=int batadv_skb_head_push(struct sk_buff *skb, unsigned int len)\n--\nnet/batman-adv/mesh-interface.c-77-\t */\nnet/batman-adv/mesh-interface.c:78:\tresult = skb_cow_head(skb, len);\nnet/batman-adv/mesh-interface.c-79-\tif (result \u003c 0)\n--\nnet/bridge/br_netfilter_hooks.c=786=static int br_nf_push_frag_xmit(struct net *net, struct sock *sk, struct sk_buff *skb)\n--\nnet/bridge/br_netfilter_hooks.c-791-\tdata = this_cpu_ptr(\u0026brnf_frag_data_storage);\nnet/bridge/br_netfilter_hooks.c:792:\terr = skb_cow_head(skb, data-\u003esize);\nnet/bridge/br_netfilter_hooks.c-793-\n--\nnet/bridge/netfilter/nf_conntrack_bridge.c=369=static int nf_ct_bridge_frag_restore(struct sk_buff *skb,\n--\nnet/bridge/netfilter/nf_conntrack_bridge.c-373-\nnet/bridge/netfilter/nf_conntrack_bridge.c:374:\terr = skb_cow_head(skb, ETH_HLEN);\nnet/bridge/netfilter/nf_conntrack_bridge.c-375-\tif (err) {\n--\nnet/core/filter.c=3654=static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,\n--\nnet/core/filter.c-3678-\nnet/core/filter.c:3679:\tret = skb_cow_head(skb, meta_len + len_diff);\nnet/core/filter.c-3680-\tif (unlikely(ret \u003c 0))\n--\nnet/core/filter.c=7209=BPF_CALL_3(bpf_lwt_seg6_adjust_srh, struct sk_buff *, skb, u32, offset,\n--\nnet/core/filter.c-7245-\tif (len \u003e 0) {\nnet/core/filter.c:7246:\t\tret = skb_cow_head(skb, len + skb-\u003emac_len);\nnet/core/filter.c-7247-\t\tif (unlikely(ret \u003c 0))\n--\nnet/core/gso.c=90=struct sk_buff *__skb_gso_segment(struct sk_buff *skb,\n--\nnet/core/gso.c-99-\t\t/* We're going to init -\u003echeck field in TCP or UDP header */\nnet/core/gso.c:100:\t\terr = skb_cow_head(skb, 0);\nnet/core/gso.c-101-\t\tif (err \u003c 0)\n--\nnet/core/lwt_bpf.c=223=static int bpf_lwt_xmit_reroute(struct sk_buff *skb)\n--\nnet/core/lwt_bpf.c-297-\t */\nnet/core/lwt_bpf.c:298:\terr = skb_cow_head(skb, LL_RESERVED_SPACE(dst-\u003edev));\nnet/core/lwt_bpf.c-299-\tif (unlikely(err)) {\n--\nnet/core/lwt_bpf.c=650=int bpf_lwt_push_ip_encap(struct sk_buff *skb, void *hdr, u32 len, bool ingress)\n--\nnet/core/lwt_bpf.c-680-\tif (ingress)\nnet/core/lwt_bpf.c:681:\t\terr = skb_cow_head(skb, len + skb-\u003emac_len);\nnet/core/lwt_bpf.c-682-\telse\nnet/core/lwt_bpf.c:683:\t\terr = skb_cow_head(skb,\nnet/core/lwt_bpf.c-684-\t\t\t\t len + LL_RESERVED_SPACE(skb_dst(skb)-\u003edev));\n--\nnet/core/skbuff.c=4857=struct sk_buff *skb_segment(struct sk_buff *head_skb,\n--\nnet/core/skbuff.c-5024-\t\t\thsize = skb_end_offset(nskb);\nnet/core/skbuff.c:5025:\t\t\tif (skb_cow_head(nskb, doffset + headroom)) {\nnet/core/skbuff.c-5026-\t\t\t\tkfree_skb(nskb);\n--\nnet/core/skbuff.c=6695=int skb_eth_push(struct sk_buff *skb, const unsigned char *dst,\n--\nnet/core/skbuff.c-6703-\nnet/core/skbuff.c:6704:\terr = skb_cow_head(skb, sizeof(*eth));\nnet/core/skbuff.c-6705-\tif (err \u003c 0)\n--\nnet/core/skbuff.c=6751=int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto,\n--\nnet/core/skbuff.c-6763-\nnet/core/skbuff.c:6764:\terr = skb_cow_head(skb, MPLS_HLEN);\nnet/core/skbuff.c-6765-\tif (unlikely(err))\n--\nnet/hsr/hsr_forward.c=332=struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,\n--\nnet/hsr/hsr_forward.c-357-\t/* Ensure the cloned skb has enough headroom to fit the HSR tag */\nnet/hsr/hsr_forward.c:358:\tif (skb_cow_head(skb, skb_metadata_len(skb) + HSR_HLEN))\nnet/hsr/hsr_forward.c-359-\t\tgoto err;\n--\nnet/ife/ife.c=34=void *ife_encode(struct sk_buff *skb, u16 metalen)\n--\nnet/ife/ife.c-45-\nnet/ife/ife.c:46:\terr = skb_cow_head(skb, total_push);\nnet/ife/ife.c-47-\tif (unlikely(err))\n--\nnet/ipv4/ip_gre.c=496=static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev,\n--\nnet/ipv4/ip_gre.c-512-\nnet/ipv4/ip_gre.c:513:\tif (skb_cow_head(skb, dev-\u003eneeded_headroom))\nnet/ipv4/ip_gre.c-514-\t\tgoto err_free_skb;\n--\nnet/ipv4/ip_gre.c=540=static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)\n--\nnet/ipv4/ip_gre.c-568-\nnet/ipv4/ip_gre.c:569:\tif (skb_cow_head(skb, dev-\u003eneeded_headroom))\nnet/ipv4/ip_gre.c-570-\t\tgoto err_free_skb;\n--\nnet/ipv4/ip_gre.c=649=static netdev_tx_t ipgre_xmit(struct sk_buff *skb,\n--\nnet/ipv4/ip_gre.c-666-\nnet/ipv4/ip_gre.c:667:\t\tif (skb_cow_head(skb, 0))\nnet/ipv4/ip_gre.c-668-\t\t\tgoto free_skb;\n--\nnet/ipv4/ip_gre.c-682-\t} else {\nnet/ipv4/ip_gre.c:683:\t\tif (skb_cow_head(skb, dev-\u003eneeded_headroom))\nnet/ipv4/ip_gre.c-684-\t\t\tgoto free_skb;\n--\nnet/ipv4/ip_gre.c=703=static netdev_tx_t erspan_xmit(struct sk_buff *skb,\n--\nnet/ipv4/ip_gre.c-721-\nnet/ipv4/ip_gre.c:722:\tif (skb_cow_head(skb, dev-\u003eneeded_headroom))\nnet/ipv4/ip_gre.c-723-\t\tgoto free_skb;\n--\nnet/ipv4/ip_gre.c=761=static netdev_tx_t gre_tap_xmit(struct sk_buff *skb,\n--\nnet/ipv4/ip_gre.c-779-\nnet/ipv4/ip_gre.c:780:\tif (skb_cow_head(skb, dev-\u003eneeded_headroom))\nnet/ipv4/ip_gre.c-781-\t\tgoto free_skb;\n--\nnet/ipv4/ip_tunnel.c=575=void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n--\nnet/ipv4/ip_tunnel.c-652-\theadroom += LL_RESERVED_SPACE(rt-\u003edst.dev) + rt-\u003edst.header_len;\nnet/ipv4/ip_tunnel.c:653:\tif (skb_cow_head(skb, headroom)) {\nnet/ipv4/ip_tunnel.c-654-\t\tip_rt_put(rt);\n--\nnet/ipv4/ip_tunnel.c=673=void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n--\nnet/ipv4/ip_tunnel.c-842-\nnet/ipv4/ip_tunnel.c:843:\tif (skb_cow_head(skb, max_headroom)) {\nnet/ipv4/ip_tunnel.c-844-\t\tip_rt_put(rt);\n--\nnet/ipv6/ioam6_iptunnel.c=256=static int ioam6_do_inline(struct net *net, struct sk_buff *skb,\n--\nnet/ipv6/ioam6_iptunnel.c-264-\nnet/ipv6/ioam6_iptunnel.c:265:\terr = skb_cow_head(skb, hdrlen + dst_dev_overhead(cache_dst, skb));\nnet/ipv6/ioam6_iptunnel.c-266-\tif (unlikely(err))\n--\nnet/ipv6/ioam6_iptunnel.c=292=static int ioam6_do_encap(struct net *net, struct sk_buff *skb,\n--\nnet/ipv6/ioam6_iptunnel.c-305-\nnet/ipv6/ioam6_iptunnel.c:306:\terr = skb_cow_head(skb, len + dst_dev_overhead(cache_dst, skb));\nnet/ipv6/ioam6_iptunnel.c-307-\tif (unlikely(err))\n--\nnet/ipv6/ioam6_iptunnel.c=338=static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv6/ioam6_iptunnel.c-436-\nnet/ipv6/ioam6_iptunnel.c:437:\t\terr = skb_cow_head(skb, LL_RESERVED_SPACE(dst_dev(dst)));\nnet/ipv6/ioam6_iptunnel.c-438-\t\tif (unlikely(err))\n--\nnet/ipv6/ip6_gre.c=715=static netdev_tx_t __gre6_xmit(struct sk_buff *skb,\n--\nnet/ipv6/ip6_gre.c-760-\nnet/ipv6/ip6_gre.c:761:\t\tif (skb_cow_head(skb, dev-\u003eneeded_headroom ?: tun_hlen + tunnel-\u003eencap_hlen))\nnet/ipv6/ip6_gre.c-762-\t\t\treturn -ENOMEM;\n--\nnet/ipv6/ip6_gre.c-771-\t} else {\nnet/ipv6/ip6_gre.c:772:\t\tif (skb_cow_head(skb, dev-\u003eneeded_headroom ?: tunnel-\u003ehlen))\nnet/ipv6/ip6_gre.c-773-\t\t\treturn -ENOMEM;\n--\nnet/ipv6/ip6_gre.c=923=static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,\n--\nnet/ipv6/ip6_gre.c-968-\nnet/ipv6/ip6_gre.c:969:\tif (skb_cow_head(skb, dev-\u003eneeded_headroom ?: t-\u003ehlen))\nnet/ipv6/ip6_gre.c-970-\t\tgoto tx_err;\n--\nnet/ipv6/ip6_tunnel.c=1100=int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,\n--\nnet/ipv6/ip6_tunnel.c-1238-\nnet/ipv6/ip6_tunnel.c:1239:\tif (skb_cow_head(skb, max_headroom))\nnet/ipv6/ip6_tunnel.c-1240-\t\tgoto tx_err_dst_release;\n--\nnet/ipv6/rpl_iptunnel.c=127=static int rpl_do_srh_inline(struct sk_buff *skb, const struct rpl_lwt *rlwt,\n--\nnet/ipv6/rpl_iptunnel.c-156-\nnet/ipv6/rpl_iptunnel.c:157:\terr = skb_cow_head(skb, hdrlen + dst_dev_overhead(cache_dst, skb));\nnet/ipv6/rpl_iptunnel.c-158-\tif (unlikely(err)) {\n--\nnet/ipv6/rpl_iptunnel.c=204=static int rpl_output(struct net *net, struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv6/rpl_iptunnel.c-244-\nnet/ipv6/rpl_iptunnel.c:245:\t\terr = skb_cow_head(skb, LL_RESERVED_SPACE(dst_dev(dst)));\nnet/ipv6/rpl_iptunnel.c-246-\t\tif (unlikely(err))\n--\n\n"
} |
| 19/2 | 2026/11/25 09:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34748 output: 32 thoughts: 423 Thoughts: **HSR Subsystem Triage: A Fuzzing Opportunity** Okay, this is a pretty substantial change we're looking at here, diving deep into the core networking HSR subsystem (`net/hsr/`). Time to run through the triage criteria meticulously. First things first: REACHABILITY is the ultimate gatekeeper. Can we *reach* this code in a standard, virtualized environment? Absolutely. HSR is entirely software-virtualized. We can spin up HSR interfaces using standard tools like `ip link add` with dummy or veth interfaces. Transmission? No problem. AF_PACKET, raw sockets, the IP stack – all readily available pathways. The core subsystems criterion is met; we're dealing with logic modifications within core networking. We also have refactorings and cleanups in reachable data structures, helper abstractions, and algorithm flows. And look, there are runtime assertions and defensive checks being introduced or altered, right in reachable paths. Specifically, I see `WARN_ON_ONCE` checks on port types and MAC lengths within `hsr_fill_frame_info`. We also have `BUILD_BUG_ON` checks. Plus, HSR is a software protocol and virtual netdevice. No physical hardware is needed to get to it. So, considering all of this, the answer is definitively YES, this warrants fuzzing. Now, let's drill down. I need to understand the enabling configuration. What configs are necessary to build and enable HSR, along with everything it depends on? I'll head over to `net/hsr/Makefile` and `net/hsr/Kconfig` to get a complete picture of the dependencies. |
| 20/2 | 2026/11/25 09:58 | tool | read-file |
0mArgs:{
"File": "net/hsr/Makefile",
"FirstLine": 1,
"LineCount": 20
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\t#\n 3:\t# Makefile for HSR\n 4:\t#\n 5:\t\n 6:\tobj-$(CONFIG_HSR)\t+= hsr.o\n 7:\t\n 8:\thsr-y\t\t\t:= hsr_main.o hsr_framereg.o hsr_device.o \\\n 9:\t\t\t\t hsr_netlink.o hsr_slave.o hsr_forward.o\n 10:\thsr-$(CONFIG_DEBUG_FS) += hsr_debugfs.o\n 11:\t\n 12:\tobj-$(CONFIG_PRP_DUP_DISCARD_KUNIT_TEST) += prp_dup_discard_test.o\n"
} |
| 21/2 | 2026/11/25 09:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35758 output: 34 thoughts: 129 Thoughts: **Investigating the `obj-$(CONFIG_HSR)` Line** Okay, I see this line: `obj-$(CONFIG_HSR) += hsr.o`. My initial thought is, "Right, let's figure out the dependencies of `CONFIG_HSR`." This is standard procedure when I'm dealing with these build configurations. I'll need to check the Kconfig files, specifically `net/hsr/Kconfig`, to understand any preconditions or dependencies that might influence this inclusion. So, I dove into `net/hsr/Kconfig`. Immediately, I see the basic definition: `config HSR`, followed by the tristate option for "High-availability Seamless Redundancy (HSR & PRP)." Good, but is there anything *this* depends on? Scanning the file quickly reveals no "depends on" statements. That's a little unusual, but not unheard of. It means `CONFIG_HSR` itself doesn't explicitly rely on any other configurations within this specific Kconfig file. Just to be thorough and because these things can get complex, I'll need to double check the entire `net/hsr/Kconfig` file and the include context of that Kconfig. In particular, I need to look for any `if HSR` constructs within that file to see how those are treated. Just because the top-level config doesn't have dependencies doesn't mean other things it configures don't. |
| 22/2 | 2026/11/25 09:58 | tool | read-file |
0mArgs:{
"File": "net/hsr/Kconfig",
"FirstLine": 40,
"LineCount": 40
}Results: {
"Contents": " 40:\t\t If unsure, say N.\n 41:\t\n 42:\tif HSR\n 43:\t\n 44:\tconfig PRP_DUP_DISCARD_KUNIT_TEST\n 45:\t\ttristate \"PRP duplicate discard KUnit tests\" if !KUNIT_ALL_TESTS\n 46:\t\tdepends on KUNIT\n 47:\t\tdefault KUNIT_ALL_TESTS\n 48:\t\thelp\n 49:\t\t Covers the PRP duplicate discard algorithm.\n 50:\t\t Only useful for kernel devs running KUnit test harness and are not\n 51:\t\t for inclusion into a production build.\n 52:\t\n 53:\t\t For more information on KUnit and unit tests in general please refer\n 54:\t\t to the KUnit documentation in Documentation/dev-tools/kunit/.\n 55:\t\n 56:\t\t If unsure, say N.\n 57:\t\n 58:\tendif\n"
} |
| 23/2 | 2026/11/25 09:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36483 output: 65 thoughts: 424 Thoughts: **Analyzing HSR Configuration and Functionality** Okay, so it seems like `CONFIG_HSR` is the single configuration item that's required. That simplifies things, at least on the surface. Now, I need to dig into the symbols to identify the key functions, the FocusSymbols, so I can understand how HSR actually works. Let's see what we've got in `net/hsr/hsr_device.c`: `hsr_ptp_parse_header` seems interesting, though static, so likely internal. Then there's `hsr_dev_xmit`, which is a non-static, and a `netdev ndo_start_xmit` operation, a crucial entrypoint for transmitting frames, so worth examining. We also have `send_hsr_supervision_frame` and `send_prp_supervision_frame` ,both static. Moving on to `net/hsr/hsr_forward.c`, here's some meat. `hsr_create_tagged_frame`, `hsr_fill_frame_info` and `hsr_forward_skb` are non-static; they look promising candidates for our analysis, and potential entrypoints. There is also `hsr_xmit`, `hsr_forward_do` and `fill_frame_info` which look like internal implementations. Finally, in `net/hsr/hsr_slave.c`, we see `hsr_handle_frame`, which is a static function registered as an rx_handler. Ah, okay, so this is where incoming frames get processed, specifically as a callback. `netdev_rx_handler_register(dev, hsr_handle_frame, port)` tells us that it's registered as the handler for the slave devices, a crucial component. This is important to note. I want to be certain that the frame is correctly received and handled. What about `hsr_add_port`? I need to check where it's used; I will scan `hsr_slave.c` and `hsr_device.c` for all entrypoints and non-static functions within `net/hsr/` to be sure I get the whole picture. |
| 24/2 | 2026/11/25 09:59 | tool | grepper |
0mArgs:{
"Expression": "hsr_handle_frame|hsr_dev_xmit|hsr_create_tagged_frame|hsr_fill_frame_info|hsr_forward_skb",
"PathPrefixes": [
"net/hsr"
]
}Results: {
"Output": "net/hsr/hsr_device.c=226=static int hsr_ptp_parse_header(struct sk_buff *skb, bool *has_hsr_header,\n--\nnet/hsr/hsr_device.c-268-\nnet/hsr/hsr_device.c:269:static netdev_tx_t hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)\nnet/hsr/hsr_device.c-270-{\n--\nnet/hsr/hsr_device.c-288-\tspin_lock_bh(\u0026hsr-\u003eseqnr_lock);\nnet/hsr/hsr_device.c:289:\thsr_forward_skb(skb, master, req_tx_port, has_hsr_header);\nnet/hsr/hsr_device.c-290-\tspin_unlock_bh(\u0026hsr-\u003eseqnr_lock);\n--\nnet/hsr/hsr_device.c=348=static void send_hsr_supervision_frame(struct hsr_port *port,\n--\nnet/hsr/hsr_device.c-418-\nnet/hsr/hsr_device.c:419:\thsr_forward_skb(skb, port, HSR_PT_NONE, false);\nnet/hsr/hsr_device.c-420-\tspin_unlock_bh(\u0026hsr-\u003eseqnr_lock);\n--\nnet/hsr/hsr_device.c=424=static void send_prp_supervision_frame(struct hsr_port *master,\n--\nnet/hsr/hsr_device.c-486-\nnet/hsr/hsr_device.c:487:\thsr_forward_skb(skb, master, HSR_PT_NONE, false);\nnet/hsr/hsr_device.c-488-\tspin_unlock_bh(\u0026hsr-\u003eseqnr_lock);\n--\nnet/hsr/hsr_device.c=687=static const struct net_device_ops hsr_device_ops = {\n--\nnet/hsr/hsr_device.c-690-\t.ndo_stop = hsr_dev_close,\nnet/hsr/hsr_device.c:691:\t.ndo_start_xmit = hsr_dev_xmit,\nnet/hsr/hsr_device.c-692-\t.ndo_change_rx_flags = hsr_change_rx_flags,\n--\nnet/hsr/hsr_device.c=703=static const struct hsr_proto_ops hsr_ops = {\nnet/hsr/hsr_device.c-704-\t.send_sv_frame = send_hsr_supervision_frame,\nnet/hsr/hsr_device.c:705:\t.create_tagged_frame = hsr_create_tagged_frame,\nnet/hsr/hsr_device.c-706-\t.get_untagged_frame = hsr_get_untagged_frame,\nnet/hsr/hsr_device.c-707-\t.drop_frame = hsr_drop_frame,\nnet/hsr/hsr_device.c:708:\t.fill_frame_info = hsr_fill_frame_info,\nnet/hsr/hsr_device.c-709-\t.invalid_dan_ingress_frame = hsr_invalid_dan_ingress_frame,\n--\nnet/hsr/hsr_device.c=753=bool is_hsr_master(struct net_device *dev)\nnet/hsr/hsr_device.c-754-{\nnet/hsr/hsr_device.c:755:\treturn (dev-\u003enetdev_ops-\u003endo_start_xmit == hsr_dev_xmit);\nnet/hsr/hsr_device.c-756-}\n--\nnet/hsr/hsr_device.c=802=int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],\n--\nnet/hsr/hsr_device.c-828-\nnet/hsr/hsr_device.c:829:\t/* Make sure we recognize frames from ourselves in hsr_handle_frame() */\nnet/hsr/hsr_device.c-830-\tres = hsr_create_self_node(hsr, hsr_dev-\u003edev_addr,\n--\nnet/hsr/hsr_forward.c=289=static struct sk_buff *hsr_fill_tag(struct sk_buff *skb,\n--\nnet/hsr/hsr_forward.c-331- */\nnet/hsr/hsr_forward.c:332:struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.c-333-\t\t\t\t\tstruct hsr_port *port)\n--\nnet/hsr/hsr_forward.c=658=static void handle_std_frame(struct sk_buff *skb,\n--\nnet/hsr/hsr_forward.c-679-\nnet/hsr/hsr_forward.c:680:int hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,\nnet/hsr/hsr_forward.c-681-\t\t\tstruct hsr_frame_info *frame)\n--\nnet/hsr/hsr_forward.c=733=static int fill_frame_info(struct hsr_frame_info *frame,\n--\nnet/hsr/hsr_forward.c-809-/* Must be called holding rcu read lock (because of the port parameter) */\nnet/hsr/hsr_forward.c:810:void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port,\nnet/hsr/hsr_forward.c-811-\t\t enum hsr_port_type req_tx_port, bool has_hsr_header)\n--\nnet/hsr/hsr_forward.h-15-\nnet/hsr/hsr_forward.h:16:void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port,\nnet/hsr/hsr_forward.h-17-\t\t enum hsr_port_type req_tx_port, bool has_hsr_header);\nnet/hsr/hsr_forward.h=18=struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.h-19-\t\t\t\t\tstruct hsr_port *port);\nnet/hsr/hsr_forward.h:20:struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.h-21-\t\t\t\t\tstruct hsr_port *port);\n--\nnet/hsr/hsr_forward.h=28=int prp_fill_frame_info(__be16 proto, struct sk_buff *skb,\nnet/hsr/hsr_forward.h-29-\t\t\tstruct hsr_frame_info *frame);\nnet/hsr/hsr_forward.h:30:int hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,\nnet/hsr/hsr_forward.h-31-\t\t\tstruct hsr_frame_info *frame);\n--\nnet/hsr/hsr_framereg.c=66=bool hsr_is_node_in_db(struct list_head *node_db,\n--\nnet/hsr/hsr_framereg.c-71-\nnet/hsr/hsr_framereg.c:72:/* Helper for device init; the self_node is used in hsr_handle_frame() to\nnet/hsr/hsr_framereg.c-73- * recognize frames from self that's been looped over the HSR ring.\n--\nnet/hsr/hsr_main.c=31=static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,\n--\nnet/hsr/hsr_main.c-91-\nnet/hsr/hsr_main.c:92:\t\t/* Make sure we recognize frames from ourselves in hsr_handle_frame() */\nnet/hsr/hsr_main.c-93-\t\tport = hsr_port_get_hsr(hsr, HSR_PT_SLAVE_B);\n--\nnet/hsr/hsr_slave.c=19=bool hsr_invalid_dan_ingress_frame(__be16 protocol)\n--\nnet/hsr/hsr_slave.c-23-\nnet/hsr/hsr_slave.c:24:static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)\nnet/hsr/hsr_slave.c-25-{\n--\nnet/hsr/hsr_slave.c-93-\t\tspin_lock_bh(\u0026hsr-\u003eseqnr_lock);\nnet/hsr/hsr_slave.c:94:\t\thsr_forward_skb(skb, port, HSR_PT_NONE, false);\nnet/hsr/hsr_slave.c-95-\t\tspin_unlock_bh(\u0026hsr-\u003eseqnr_lock);\nnet/hsr/hsr_slave.c-96-\t} else {\nnet/hsr/hsr_slave.c:97:\t\thsr_forward_skb(skb, port, HSR_PT_NONE, false);\nnet/hsr/hsr_slave.c-98-\t}\n--\nnet/hsr/hsr_slave.c=110=bool hsr_port_exists(const struct net_device *dev)\nnet/hsr/hsr_slave.c-111-{\nnet/hsr/hsr_slave.c:112:\treturn rcu_access_pointer(dev-\u003erx_handler) == hsr_handle_frame;\nnet/hsr/hsr_slave.c-113-}\n--\nnet/hsr/hsr_slave.c=157=static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev,\n--\nnet/hsr/hsr_slave.c-187-\nnet/hsr/hsr_slave.c:188:\tres = netdev_rx_handler_register(dev, hsr_handle_frame, port);\nnet/hsr/hsr_slave.c-189-\tif (res)\n"
} |
| 25/2 | 2026/11/25 09:59 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 40147 output: 40 thoughts: 1496 Thoughts: **Focusing on HSR Subsystem Symbol Coverage** Okay, let's break down these changes and identify the optimal functions for fuzzing within the HSR (High-availability Seamless Redundancy) subsystem. My initial thought is to zero in on `hsr_device.c` to see which functions have been modified. I see `hsr_ptp_parse_header` (static, but called from `hsr_dev_xmit`), `hsr_dev_xmit`, `hsr_forward_skb`, `hsr_create_tagged_frame`, `hsr_fill_frame_info`, and `hsr_handle_frame`. Now, the question is, which ones are good candidates for `FocusSymbols`? Let's clarify: `hsr_dev_xmit` is static, but it's the `ndo_start_xmit` net_device_ops function, and called through `dev_queue_xmit` or `__dev_queue_xmit`. Can static functions be targeted, given that we are fuzzing? Let me check instruction 4 regarding `FocusSymbols`. Okay, it says we want functions that implement *specific feature logic* or are direct API entrypoints, but we should *avoid* ubiquitous lifecycle hot-paths. In that case, the static status is not relevant *per se* if they do *not* get inlined. But non-inlined static functions *do* have addresses in `kallsyms` / `vmlinux`. So, `hsr_dev_xmit`, `hsr_create_tagged_frame`, `hsr_forward_skb`, `hsr_fill_frame_info`, and `hsr_handle_frame` seem promising. Let's see if those are non-static and exported. Good, `hsr_create_tagged_frame`, `hsr_fill_frame_info`, and `hsr_forward_skb` are declared in `hsr_forward.h`, and therefore non-static. `hsr_dev_xmit` *is* static, but as a `net_device_ops` function pointer, it's a good target and not a lifecycle wrapper. `hsr_handle_frame` is a static rx_handler callback. `hsr_ptp_parse_header` is static too. Given the revisions to these, let's focus on: `hsr_dev_xmit`, `hsr_forward_skb` (where the new parameters and logic are located), `hsr_create_tagged_frame` (rewritten with cloning, COW, and postpush operations), `hsr_fill_frame_info` (which includes new assertions and `has_hsr_header` logic), and `hsr_handle_frame` (with PTP checks and new goto target). `hsr_ptp_parse_header` is static, but called only in `hsr_dev_xmit`. The compiler *might* inline it; if not, it is another good target. Let's check if there are other symbols or files involved. A quick review reveals changes in `MAINTAINERS`, `include/linux/if_hsr.h`, `include/uapi/linux/hsr_ptp.h`, `net/hsr/hsr_device.c`, `net/hsr/hsr_forward.h`, `net/hsr/hsr_framereg.h`, `net/hsr/hsr_main.h`, `net/hsr/hsr_slave.c`, and potentially in `tools/...`. So the scope seems contained to the HSR subsystem. Let's summarize the key symbols: 1. `hsr_dev_xmit`, 2. `hsr_forward_skb`, 3. `hsr_create_tagged_frame`, 4. `hsr_fill_frame_info`, 5. `hsr_handle_frame`, and 6. `hsr_ptp_parse_header` (optional). None of these are ubiquitous; they are all specific to HSR. Just to be thorough, let's make sure there aren't any config dependencies beyond `CONFIG_HSR`. I'll scan `hsr_device.c` and other files for any `#ifdef` or Kconfig guards. |
| 26/2 | 2026/11/25 09:59 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_",
"PathPrefixes": [
"net/hsr",
"include/linux/if_hsr.h"
]
}Results: {
"Output": "include/linux/if_hsr.h=42=struct hsr_ethhdr {\n--\ninclude/linux/if_hsr.h-46-\ninclude/linux/if_hsr.h:47:#if IS_ENABLED(CONFIG_HSR)\ninclude/linux/if_hsr.h-48-extern bool is_hsr_master(struct net_device *dev);\n--\ninclude/linux/if_hsr.h=71=static inline int hsr_get_port_type(struct net_device *hsr_dev,\n--\ninclude/linux/if_hsr.h-76-}\ninclude/linux/if_hsr.h:77:#endif /* CONFIG_HSR */\ninclude/linux/if_hsr.h-78-\n--\nnet/hsr/Makefile-5-\nnet/hsr/Makefile:6:obj-$(CONFIG_HSR)\t+= hsr.o\nnet/hsr/Makefile-7-\nnet/hsr/Makefile=8=hsr-y\t\t\t:= hsr_main.o hsr_framereg.o hsr_device.o \\\nnet/hsr/Makefile-9-\t\t\t hsr_netlink.o hsr_slave.o hsr_forward.o\nnet/hsr/Makefile:10:hsr-$(CONFIG_DEBUG_FS) += hsr_debugfs.o\nnet/hsr/Makefile-11-\nnet/hsr/Makefile:12:obj-$(CONFIG_PRP_DUP_DISCARD_KUNIT_TEST) += prp_dup_discard_test.o\n--\nnet/hsr/hsr_framereg.h=79=int prp_register_frame_out(struct hsr_port *port, struct hsr_frame_info *frame);\nnet/hsr/hsr_framereg.h-80-\nnet/hsr/hsr_framereg.h:81:#if IS_ENABLED(CONFIG_KUNIT)\nnet/hsr/hsr_framereg.h-82-struct hsr_seq_block *hsr_get_seq_block(struct hsr_node *node, u16 block_idx);\n--\nnet/hsr/hsr_main.h=184=struct hsr_priv {\n--\nnet/hsr/hsr_main.h-213-\t\t\t\t */\nnet/hsr/hsr_main.h:214:#ifdef\tCONFIG_DEBUG_FS\nnet/hsr/hsr_main.h-215-\tstruct dentry *node_tbl_root;\n--\nnet/hsr/hsr_main.h=255=static inline bool prp_check_lsdu_size(struct sk_buff *skb,\n--\nnet/hsr/hsr_main.h-273-\nnet/hsr/hsr_main.h:274:#if IS_ENABLED(CONFIG_DEBUG_FS)\nnet/hsr/hsr_main.h-275-void hsr_debugfs_rename(struct net_device *dev);\n"
} |
| 27/2 | 2026/11/25 09:59 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 43390 output: 226 thoughts: 647 Thoughts: **Analysis of the HSR Patch for Fuzzing Suitability** Okay, let's break this down. Everything hinges on `CONFIG_HSR`, which is good; makes the setup clean. No other config dependencies, which simplifies things. Can syzkaller hit this? Absolutely. Netlink rtnetlink (`RTM_NEWLINK`) with "hsr" `IFLA_LINKINFO` means easy virtual device creation. We can toss packets with `ETH_P_1588` (PTP) over these HSR interfaces or inject them onto slave interfaces. That's a huge accessibility win. Looking at the patch itself, we're seeing some key areas of modification: * A brand new inline header mechanism in `hsr_dev_xmit` and `hsr_ptp_parse_header` for that PTP protocol, which is critical. * Changes to `hsr_create_tagged_frame` – frame tagging rewritten with `skb_clone` and `skb_cow_head`. Anytime we're messing with `skb` manipulation, frame manipulation, memory management, or reference counting, it's a good place to poke around. * New runtime assertions, `WARN_ON_ONCE` specifically, in `hsr_fill_frame_info`. Assertions are always worth checking. Easy to trigger if there is a mistake in any conditions. * Modifications to how ingress frames are handled, particularly PTP packets, in `hsr_handle_frame`. This could be critical for exploits. This is all clearly reachable. It's touching core network protocol code in `net/hsr/`, adding runtime assertions, changing frame manipulation, and messing with the transmit/receive paths. This makes it a prime candidate for fuzzing. `WorthFuzzing` is a clear `true`. Now, let's narrow the focus with the `FocusSymbols`: * `hsr_ptp_parse_header` - Inline header. * `hsr_dev_xmit` - Transmission. * `hsr_forward_skb` - Forwarding is crucial for network devices. * `hsr_create_tagged_frame` - Frame tagging manipulation. * `hsr_fill_frame_info` - Info setting. * `hsr_handle_frame` - Ingress handling. Double-checking `EnableConfigs`: `HSR` (no `CONFIG_` prefix). The reasoning is pretty solid: * Inline header parsing for PTP packets, which opens up interesting attack surfaces. * Runtime assertions, meaning there are preconditions we should try to violate. * Rewriting tagged frame creation with `skb_clone` and `skb_cow_head`. This directly involves `skb` headroom/tailroom and ownership. * Altering `hsr_handle_frame` for PTP, and potentially dropping packets. * HSR devices are easily created in virtualized environments like QEMU or GCE and tested with packet sockets. We can create these interfaces programmatically using veth, dummy, and packet sockets. Yep, we've got everything we need. Time to `set-results`. |
| 28/2 | 2026/11/25 10:00 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"HSR"
],
"FocusSymbols": [
"hsr_ptp_parse_header",
"hsr_dev_xmit",
"hsr_forward_skb",
"hsr_create_tagged_frame",
"hsr_fill_frame_info",
"hsr_handle_frame"
],
"Reasoning": "The patch introduces support for an inline header for PTP (ETH_P_1588) frames over High-availability Seamless Redundancy (HSR) virtual network devices, refactors tagged frame creation (switching to skb_clone and skb_cow_head), alters ingress frame filtering in hsr_slave, and adds new runtime assertions (WARN_ON_ONCE) in hsr_fill_frame_info. HSR interfaces are purely software-defined virtual devices that can be created and tested over dummy/veth devices in standard QEMU/KVM fuzzing environments without dedicated physical hardware.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"HSR"
],
"FocusSymbols": [
"hsr_ptp_parse_header",
"hsr_dev_xmit",
"hsr_forward_skb",
"hsr_create_tagged_frame",
"hsr_fill_frame_info",
"hsr_handle_frame"
],
"Reasoning": "The patch introduces support for an inline header for PTP (ETH_P_1588) frames over High-availability Seamless Redundancy (HSR) virtual network devices, refactors tagged frame creation (switching to skb_clone and skb_cow_head), alters ingress frame filtering in hsr_slave, and adds new runtime assertions (WARN_ON_ONCE) in hsr_fill_frame_info. HSR interfaces are purely software-defined virtual devices that can be created and tested over dummy/veth devices in standard QEMU/KVM fuzzing environments without dedicated physical hardware.",
"WorthFuzzing": true
} |
| 29/1 | 2026/11/25 10:00 | action | If |
12mArgs:{
"WorthFuzzing": true
}Results: null |
| 30/2 | 2026/11/25 10:00 | agent | kmsan-evaluator |
12mModel:core Args: null Results: {
"KMSANReasoning": "The patch series implements PTP (Precision Time Protocol / IEEE 1588) support for HSR (High-availability Seamless Redundancy) networks by introducing an inline header (`struct hsr_inline_header`) parsed during packet transmission, handling port steering, and avoiding improper PTP forwarding in slave ingress.\n\nKMSAN vs KASAN Applicability Analysis:\n1. No uninitialized memory leaks to userspace: The patch does not add or modify any data structures sent to userspace (`copy_to_user`, `put_user`, Netlink attributes, ioctl returns, socket options, or BPF buffers). The newly added UAPI header defines `struct hsr_inline_header`, which is received from userspace (via raw/packet sockets) and parsed/stripped by the kernel before network transmission; it is never copied back to user space.\n2. Fully initialized stack and heap structures: In `hsr_dev_xmit`, local variables `req_tx_port` and `has_hsr_header` are explicitly initialized. In `fill_frame_info`, the `struct hsr_frame_info` buffer is completely zero-initialized via `memset(frame, 0, sizeof(*frame))` prior to assigning fields.\n3. Packet manipulation and bounds checking: Packet header manipulations (pulling inline headers with `skb_pull`, adjusting headroom with `skb_cow_head`, moving data with `skb_postpush_data_move`, and reading Ethernet/HSR headers) are guarded by `pskb_may_pull` checks. Any potential bounds violations, buffer overreads/overwrites, or use-after-free bugs on cloned skbs are classical memory safety issues that are fully covered by standard KASAN and debug builds.\n\nBecause there are no uninitialized memory usage risks or kernel-to-user info-leak vectors introduced by this patch series, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 2b333a99dc8f7bbab557b05888b4f7fd3fc682f1
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Nov 25 09:51:13 2026 +0000
syz-cluster: applied patch under review
diff --git a/MAINTAINERS b/MAINTAINERS
index ccbcdc0799b9fb..1c23e7b2dafacb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12310,6 +12310,7 @@ F: drivers/net/usb/hso.c
HSR NETWORK PROTOCOL
L: netdev@vger.kernel.org
S: Orphan
+F: include/uapi/linux/hsr_ptp.h
F: net/hsr/
F: tools/testing/selftests/net/hsr/
diff --git a/include/linux/if_hsr.h b/include/linux/if_hsr.h
index f4cf2dd36d193d..d0773a60c4fd05 100644
--- a/include/linux/if_hsr.h
+++ b/include/linux/if_hsr.h
@@ -3,6 +3,7 @@
#define _LINUX_IF_HSR_H_
#include <linux/types.h>
+#include <linux/if_ether.h>
struct net_device;
@@ -38,6 +39,11 @@ struct hsr_tag {
#define HSR_HLEN 6
+struct hsr_ethhdr {
+ struct ethhdr ethhdr;
+ struct hsr_tag hsr_tag;
+} __packed;
+
#if IS_ENABLED(CONFIG_HSR)
extern bool is_hsr_master(struct net_device *dev);
extern int hsr_get_version(struct net_device *dev, enum hsr_version *ver);
diff --git a/include/uapi/linux/hsr_ptp.h b/include/uapi/linux/hsr_ptp.h
new file mode 100644
index 00000000000000..95e905441ebdcf
--- /dev/null
+++ b/include/uapi/linux/hsr_ptp.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+#ifndef __UAPI_HSR_PTP_H
+#define __UAPI_HSR_PTP_H
+
+#include <linux/types.h>
+
+#define HSR_INLINE_HDR 0xaf485352
+#define HSR_INLINE_HDR_PORT_A 1
+#define HSR_INLINE_HDR_PORT_B 2
+
+struct hsr_inline_header {
+ __u8 req_tx_port;
+ __u8 has_hsr_header;
+ __be32 __pad0;
+ __be32 magic;
+ __be16 __pad1;
+ __be16 eth_type;
+} __attribute__ ((packed));
+
+#endif
diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
index fc512204600cd8..be29d73bef76a3 100644
--- a/net/hsr/hsr_device.c
+++ b/net/hsr/hsr_device.c
@@ -12,6 +12,8 @@
#include <linux/etherdevice.h>
#include <linux/rtnetlink.h>
#include <linux/pkt_sched.h>
+#include <uapi/linux/hsr_ptp.h>
+
#include "hsr_device.h"
#include "hsr_slave.h"
#include "hsr_framereg.h"
@@ -221,32 +223,85 @@ static netdev_features_t hsr_fix_features(struct net_device *dev,
return hsr_features_recompute(hsr, features);
}
+static int hsr_ptp_parse_header(struct sk_buff *skb, bool *has_hsr_header,
+ enum hsr_port_type *req_tx_port)
+{
+ struct hsr_inline_header *hsr_inline_hdr;
+ struct ethhdr *eth_hdr;
+ unsigned int hdr_len;
+
+ BUILD_BUG_ON(sizeof(struct hsr_inline_header) != sizeof(struct ethhdr));
+
+ skb_reset_mac_header(skb);
+ /* need to access the magic header */
+ if (!pskb_may_pull(skb, sizeof(struct hsr_inline_header)))
+ return -EINVAL;
+
+ hsr_inline_hdr = (struct hsr_inline_header *)skb_mac_header(skb);
+ if (hsr_inline_hdr->magic != htonl(HSR_INLINE_HDR))
+ return -EINVAL;
+
+ *has_hsr_header = hsr_inline_hdr->has_hsr_header;
+ *req_tx_port = hsr_inline_hdr->req_tx_port;
+ if (*req_tx_port != HSR_PT_SLAVE_A && *req_tx_port != HSR_PT_SLAVE_B)
+ return -EINVAL;
+
+ if (hsr_inline_hdr->__pad0 != 0 || hsr_inline_hdr->__pad1 != 0)
+ return -EINVAL;
+
+ hdr_len = ETH_HLEN;
+ if (*has_hsr_header)
+ hdr_len += HSR_HLEN;
+
+ /* Ensure the real header after the stripped one can be
+ * accessed
+ */
+ if (!pskb_may_pull(skb, sizeof(struct hsr_inline_header) +
+ hdr_len))
+ return -EINVAL;
+
+ eth_hdr = skb_pull(skb, sizeof(struct hsr_inline_header));
+ skb_set_network_header(skb, hdr_len);
+ skb->protocol = eth_hdr->h_proto;
+ return 0;
+}
+
static netdev_tx_t hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)
{
+ enum hsr_port_type req_tx_port = HSR_PT_NONE;
struct hsr_priv *hsr = netdev_priv(dev);
+ bool has_hsr_header = false;
struct hsr_port *master;
rcu_read_lock();
master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);
- if (master) {
- skb->dev = master->dev;
- skb_reset_mac_header(skb);
- skb_reset_mac_len(skb);
- spin_lock_bh(&hsr->seqnr_lock);
- hsr_forward_skb(skb, master);
- spin_unlock_bh(&hsr->seqnr_lock);
- } else {
- dev_core_stats_tx_dropped_inc(dev);
- dev_kfree_skb_any(skb);
- }
+ if (!master)
+ goto drop;
+
+ skb->dev = master->dev;
+ if (skb->protocol == htons(ETH_P_1588) &&
+ hsr_ptp_parse_header(skb, &has_hsr_header, &req_tx_port))
+ goto drop;
+
+ skb_reset_mac_header(skb);
+ skb_reset_mac_len(skb);
+ spin_lock_bh(&hsr->seqnr_lock);
+ hsr_forward_skb(skb, master, req_tx_port, has_hsr_header);
+ spin_unlock_bh(&hsr->seqnr_lock);
rcu_read_unlock();
+ return NETDEV_TX_OK;
+drop:
+ rcu_read_unlock();
+ dev_core_stats_tx_dropped_inc(dev);
+ dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
}
static const struct header_ops hsr_header_ops = {
.create = eth_header,
.parse = eth_header_parse,
+ .parse_protocol = eth_header_parse_protocol,
};
static struct sk_buff *hsr_init_skb(struct hsr_port *master, int extra)
@@ -361,7 +416,7 @@ static void send_hsr_supervision_frame(struct hsr_port *port,
return;
}
- hsr_forward_skb(skb, port);
+ hsr_forward_skb(skb, port, HSR_PT_NONE, false);
spin_unlock_bh(&hsr->seqnr_lock);
return;
}
@@ -429,7 +484,7 @@ static void send_prp_supervision_frame(struct hsr_port *master,
return;
}
- hsr_forward_skb(skb, master);
+ hsr_forward_skb(skb, master, HSR_PT_NONE, false);
spin_unlock_bh(&hsr->seqnr_lock);
}
diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
index 44f6d9c83180a6..9cb3297a8640a3 100644
--- a/net/hsr/hsr_forward.c
+++ b/net/hsr/hsr_forward.c
@@ -12,6 +12,7 @@
#include <linux/skbuff.h>
#include <linux/etherdevice.h>
#include <linux/if_vlan.h>
+#include <net/sock.h>
#include "hsr_main.h"
#include "hsr_framereg.h"
@@ -331,7 +332,6 @@ static struct sk_buff *hsr_fill_tag(struct sk_buff *skb,
struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
struct hsr_port *port)
{
- unsigned char *dst, *src;
struct sk_buff *skb;
int movelen;
@@ -342,33 +342,43 @@ struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
/* set the lane id properly */
hsr_set_path_id(frame, hsr_ethhdr, port);
return skb_clone(frame->skb_hsr, GFP_ATOMIC);
- } else if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) {
- return skb_clone(frame->skb_std, GFP_ATOMIC);
}
- /* Create the new skb with enough headroom to fit the HSR tag */
- skb = __pskb_copy(frame->skb_std,
- skb_headroom(frame->skb_std) + HSR_HLEN, GFP_ATOMIC);
+ skb = skb_clone(frame->skb_std, GFP_ATOMIC);
if (!skb)
return NULL;
- skb_reset_mac_header(skb);
- if (skb->ip_summed == CHECKSUM_PARTIAL)
- skb->csum_start += HSR_HLEN;
+ if (frame->req_tx_port != HSR_PT_NONE && frame->skb_std->sk)
+ skb_set_owner_w(skb, frame->skb_std->sk);
+
+ if (port->dev->features & NETIF_F_HW_HSR_TAG_INS)
+ return skb;
+
+ /* Ensure the cloned skb has enough headroom to fit the HSR tag */
+ if (skb_cow_head(skb, skb_metadata_len(skb) + HSR_HLEN))
+ goto err;
movelen = ETH_HLEN;
if (frame->is_vlan)
movelen += VLAN_HLEN;
- src = skb_mac_header(skb);
- dst = skb_push(skb, HSR_HLEN);
- memmove(dst, src, movelen);
+ /* The entire header area needs to be linear */
+ if (!pskb_may_pull(skb, movelen))
+ goto err;
+
+ skb_push(skb, HSR_HLEN);
+ skb_postpush_data_move(skb, HSR_HLEN, movelen);
+ skb_set_network_header(skb, HSR_HLEN + movelen);
skb_reset_mac_header(skb);
+ skb_reset_mac_len(skb);
/* skb_put_padto free skb on error and hsr_fill_tag returns NULL in
* that case
*/
return hsr_fill_tag(skb, frame, port, port->hsr->prot_version);
+err:
+ kfree_skb(skb);
+ return NULL;
}
struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,
@@ -420,7 +430,7 @@ static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev,
static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port,
struct hsr_frame_info *frame)
{
- if (frame->port_rcv->type == HSR_PT_MASTER) {
+ if (frame->port_rcv->type == HSR_PT_MASTER && !frame->has_hsr_header) {
hsr_addr_subst_dest(frame->node_src, skb, port);
/* Address substitution (IEC62439-3 pp 26, 50): replace mac
@@ -546,6 +556,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
hsr_for_each_port(frame->port_rcv->hsr, port) {
struct hsr_priv *hsr = port->hsr;
+
/* Don't send frame back the way it came */
if (port == frame->port_rcv)
continue;
@@ -564,6 +575,22 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
if ((port->dev->features & NETIF_F_HW_HSR_DUP) && sent)
continue;
+ /* If this frame has a specific outgoing port specified (by the
+ * sender) then send it on this port only.
+ */
+ if (frame->req_tx_port != HSR_PT_NONE &&
+ frame->req_tx_port != port->type)
+ continue;
+ /* If this TX frame already has a HSR header then forward the
+ * frame with it and don't add one.
+ */
+ if (frame->has_hsr_header && frame->skb_std) {
+ skb = skb_clone(frame->skb_std, GFP_ATOMIC);
+ if (skb && frame->skb_std->sk)
+ skb_set_owner_w(skb, frame->skb_std->sk);
+ goto inject_into_stack;
+ }
+
/* Don't send frame over port where it has been sent before.
* Also for SAN, this shouldn't be done.
*/
@@ -591,6 +618,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
else
skb = hsr->proto_ops->get_untagged_frame(frame, port);
+inject_into_stack:
if (!skb) {
frame->port_rcv->dev->stats.rx_dropped++;
continue;
@@ -655,6 +683,13 @@ int hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,
struct hsr_port *port = frame->port_rcv;
struct hsr_priv *hsr = port->hsr;
+ if (frame->has_hsr_header) {
+ frame->skb_std = skb;
+
+ WARN_ON_ONCE(port->type != HSR_PT_MASTER);
+ WARN_ON_ONCE(skb->mac_len < sizeof(struct hsr_ethhdr));
+ return 0;
+ }
/* HSRv0 supervisory frames double as a tag so treat them as tagged. */
if ((!hsr->prot_version && proto == htons(ETH_P_PRP)) ||
proto == htons(ETH_P_HSR)) {
@@ -696,7 +731,8 @@ int prp_fill_frame_info(__be16 proto, struct sk_buff *skb,
}
static int fill_frame_info(struct hsr_frame_info *frame,
- struct sk_buff *skb, struct hsr_port *port)
+ struct sk_buff *skb, struct hsr_port *port,
+ enum hsr_port_type req_tx_port, bool has_hsr_header)
{
struct hsr_priv *hsr = port->hsr;
struct hsr_vlan_ethhdr *vlan_hdr;
@@ -719,10 +755,16 @@ static int fill_frame_info(struct hsr_frame_info *frame,
if (port->type == HSR_PT_INTERLINK)
n_db = &hsr->proxy_node_db;
- frame->node_src = hsr_get_node(port, n_db, skb,
- frame->is_supervision, port->type);
- if (!frame->node_src)
- return -1; /* Unknown node and !is_supervision, or no mem */
+ frame->req_tx_port = req_tx_port;
+ frame->has_hsr_header = has_hsr_header;
+
+ if (!frame->has_hsr_header) {
+ frame->node_src = hsr_get_node(port, n_db, skb,
+ frame->is_supervision,
+ port->type);
+ if (!frame->node_src)
+ return -1; /* Unknown node and !is_supervision, or no mem */
+ }
ethhdr = (struct ethhdr *)skb_mac_header(skb);
frame->is_vlan = false;
@@ -765,15 +807,17 @@ static int fill_frame_info(struct hsr_frame_info *frame,
}
/* Must be called holding rcu read lock (because of the port parameter) */
-void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port)
+void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port,
+ enum hsr_port_type req_tx_port, bool has_hsr_header)
{
struct hsr_frame_info frame;
rcu_read_lock();
- if (fill_frame_info(&frame, skb, port) < 0)
+ if (fill_frame_info(&frame, skb, port, req_tx_port, has_hsr_header) < 0)
goto out_drop;
- hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
+ if (!frame.has_hsr_header)
+ hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
hsr_forward_do(&frame);
rcu_read_unlock();
/* Gets called for ingress frames as well as egress from master port.
diff --git a/net/hsr/hsr_forward.h b/net/hsr/hsr_forward.h
index 206636750b3001..662dd369c7df21 100644
--- a/net/hsr/hsr_forward.h
+++ b/net/hsr/hsr_forward.h
@@ -13,7 +13,8 @@
#include <linux/netdevice.h>
#include "hsr_main.h"
-void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port);
+void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port,
+ enum hsr_port_type req_tx_port, bool has_hsr_header);
struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,
struct hsr_port *port);
struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
diff --git a/net/hsr/hsr_framereg.h b/net/hsr/hsr_framereg.h
index 127a3fb64d5f03..dc13819d04098b 100644
--- a/net/hsr/hsr_framereg.h
+++ b/net/hsr/hsr_framereg.h
@@ -29,6 +29,8 @@ struct hsr_frame_info {
bool is_from_san;
bool dst_in_node_db;
bool dst_in_proxy_node_db;
+ bool has_hsr_header;
+ enum hsr_port_type req_tx_port;
};
void hsr_del_self_node(struct hsr_priv *hsr);
diff --git a/net/hsr/hsr_main.h b/net/hsr/hsr_main.h
index 53e95bae0ee276..36eb82774000c2 100644
--- a/net/hsr/hsr_main.h
+++ b/net/hsr/hsr_main.h
@@ -72,11 +72,6 @@ static inline void set_hsr_tag_LSDU_size(struct hsr_tag *ht, u16 LSDU_size)
0xF000) | (LSDU_size & 0x0FFF));
}
-struct hsr_ethhdr {
- struct ethhdr ethhdr;
- struct hsr_tag hsr_tag;
-} __packed;
-
struct hsr_vlan_ethhdr {
struct vlan_ethhdr vlanhdr;
struct hsr_tag hsr_tag;
diff --git a/net/hsr/hsr_slave.c b/net/hsr/hsr_slave.c
index a546f70f9cc8b4..a5b47f016abd78 100644
--- a/net/hsr/hsr_slave.c
+++ b/net/hsr/hsr_slave.c
@@ -23,6 +23,7 @@ bool hsr_invalid_dan_ingress_frame(__be16 protocol)
static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
{
+ struct hsr_ethhdr *hsr_ethhdr;
struct sk_buff *skb = *pskb;
struct hsr_port *port;
struct hsr_priv *hsr;
@@ -44,8 +45,7 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
if (hsr_addr_is_self(port->hsr, eth_hdr(skb)->h_source)) {
/* Directly kill frames sent by ourselves */
- kfree_skb(skb);
- goto finish_consume;
+ goto finish_free_consume;
}
/* For HSR, only tagged frames are expected (unless the device offloads
@@ -64,27 +64,43 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
skb_reset_mac_header(skb);
if ((!hsr->prot_version && protocol == htons(ETH_P_PRP)) ||
protocol == htons(ETH_P_HSR)) {
- if (!pskb_may_pull(skb, ETH_HLEN + HSR_HLEN)) {
- kfree_skb(skb);
- goto finish_consume;
- }
+ if (!pskb_may_pull(skb, ETH_HLEN + HSR_HLEN))
+ goto finish_free_consume;
skb_set_network_header(skb, ETH_HLEN + HSR_HLEN);
}
skb_reset_mac_len(skb);
+ /* PTP packets are not supposed to be forwarded via HSR as-is. The
+ * latency introduced by forwarding renders the time information
+ * useless. Userland needs to capture the packet on the original
+ * interface instead of hsr.
+ */
+ if ((!hsr->prot_version && protocol == htons(ETH_P_PRP)) ||
+ protocol == htons(ETH_P_HSR)) {
+ hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb);
+ if (hsr_ethhdr->hsr_tag.encap_proto == htons(ETH_P_1588))
+ goto finish_free_consume;
+ } else {
+ if (protocol == htons(ETH_P_1588))
+ goto finish_free_consume;
+ }
+
/* Only the frames received over the interlink port will assign a
* sequence number and require synchronisation vs other sender.
*/
if (port->type == HSR_PT_INTERLINK) {
spin_lock_bh(&hsr->seqnr_lock);
- hsr_forward_skb(skb, port);
+ hsr_forward_skb(skb, port, HSR_PT_NONE, false);
spin_unlock_bh(&hsr->seqnr_lock);
} else {
- hsr_forward_skb(skb, port);
+ hsr_forward_skb(skb, port, HSR_PT_NONE, false);
}
-finish_consume:
+ return RX_HANDLER_CONSUMED;
+
+finish_free_consume:
+ kfree_skb(skb);
return RX_HANDLER_CONSUMED;
finish_pass:
diff --git a/tools/include/uapi/linux/hsr_ptp.h b/tools/include/uapi/linux/hsr_ptp.h
new file mode 100644
index 00000000000000..95e905441ebdcf
--- /dev/null
+++ b/tools/include/uapi/linux/hsr_ptp.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+#ifndef __UAPI_HSR_PTP_H
+#define __UAPI_HSR_PTP_H
+
+#include <linux/types.h>
+
+#define HSR_INLINE_HDR 0xaf485352
+#define HSR_INLINE_HDR_PORT_A 1
+#define HSR_INLINE_HDR_PORT_B 2
+
+struct hsr_inline_header {
+ __u8 req_tx_port;
+ __u8 has_hsr_header;
+ __be32 __pad0;
+ __be32 magic;
+ __be16 __pad1;
+ __be16 eth_type;
+} __attribute__ ((packed));
+
+#endif
diff --git a/tools/testing/selftests/net/hsr/.gitignore b/tools/testing/selftests/net/hsr/.gitignore
new file mode 100644
index 00000000000000..849eecb84c9748
--- /dev/null
+++ b/tools/testing/selftests/net/hsr/.gitignore
@@ -0,0 +1 @@
+hsr_ptp_test
diff --git a/tools/testing/selftests/net/hsr/Makefile b/tools/testing/selftests/net/hsr/Makefile
index 2150e487ac7d7f..512ccf61b66525 100644
--- a/tools/testing/selftests/net/hsr/Makefile
+++ b/tools/testing/selftests/net/hsr/Makefile
@@ -2,9 +2,12 @@
top_srcdir = ../../../../..
+CFLAGS += -Wall -Wl,--no-as-needed -O2 -g $(TOOLS_INCLUDES)
+
TEST_PROGS := \
hsr_ping.sh \
hsr_prp_redbox.sh \
+ hsr_ptp.sh \
hsr_redbox.sh \
link_faults.sh \
prp_ping.sh \
@@ -12,4 +15,6 @@ TEST_PROGS := \
TEST_FILES += hsr_common.sh
+TEST_GEN_FILES := hsr_ptp_test
+
include ../../lib.mk
diff --git a/tools/testing/selftests/net/hsr/hsr_ptp.sh b/tools/testing/selftests/net/hsr/hsr_ptp.sh
new file mode 100755
index 00000000000000..23379b1ce7a56a
--- /dev/null
+++ b/tools/testing/selftests/net/hsr/hsr_ptp.sh
@@ -0,0 +1,109 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+ipv6=false
+
+source ./hsr_common.sh
+
+optstring="h"
+usage() {
+ echo "Usage: $0"
+}
+
+while getopts "$optstring" option;do
+ case "$option" in
+ "h")
+ usage "$0"
+ exit 0
+ ;;
+ "?")
+ usage "$0"
+ exit 1
+ ;;
+esac
+done
+
+setup_hsr_interfaces()
+{
+ local HSRv="$1"
+
+ echo "INFO: Preparing interfaces for HSRv${HSRv}."
+# Three HSR nodes. Each node has one link to each of its neighbour, two links in total.
+
+# ns1eth1 ----- ns2eth1
+# hsr1 hsr2
+# ns1eth2 ns2eth2
+# | |
+# ns3eth1 ns3eth2
+# \ /
+# hsr3
+#
+ # Interfaces
+ ip link add ns1eth1 netns "$ns1" type veth peer name ns2eth1 netns "$ns2"
+ ip link add ns1eth2 netns "$ns1" type veth peer name ns3eth1 netns "$ns3"
+ ip link add ns3eth2 netns "$ns3" type veth peer name ns2eth2 netns "$ns2"
+
+ # HSRv0/1
+ ip -net "$ns1" link add name hsr1 type hsr slave1 ns1eth1 \
+ slave2 ns1eth2 supervision 45 version "$HSRv" proto 0
+ ip -net "$ns2" link add name hsr2 type hsr slave1 ns2eth1 \
+ slave2 ns2eth2 supervision 45 version "$HSRv" proto 0
+ ip -net "$ns3" link add name hsr3 type hsr slave1 ns3eth1 \
+ slave2 ns3eth2 supervision 45 version "$HSRv" proto 0
+
+ # IP for HSR
+ ip -net "$ns1" addr add 100.64.0.1/24 dev hsr1
+ ip -net "$ns1" addr add dead:beef:0::1/64 dev hsr1 nodad
+ ip -net "$ns2" addr add 100.64.0.2/24 dev hsr2
+ ip -net "$ns2" addr add dead:beef:0::2/64 dev hsr2 nodad
+ ip -net "$ns3" addr add 100.64.0.3/24 dev hsr3
+ ip -net "$ns3" addr add dead:beef:0::3/64 dev hsr3 nodad
+
+ ip -net "$ns1" link set address 00:11:22:00:01:01 dev ns1eth1
+ ip -net "$ns1" link set address 00:11:22:00:01:02 dev ns1eth2
+
+ ip -net "$ns2" link set address 00:11:22:00:02:01 dev ns2eth1
+ ip -net "$ns2" link set address 00:11:22:00:02:02 dev ns2eth2
+
+ ip -net "$ns3" link set address 00:11:22:00:03:01 dev ns3eth1
+ ip -net "$ns3" link set address 00:11:22:00:03:02 dev ns3eth2
+
+ # All Links up
+ ip -net "$ns1" link set ns1eth1 up
+ ip -net "$ns1" link set ns1eth2 up
+ ip -net "$ns1" link set hsr1 up
+
+ ip -net "$ns2" link set ns2eth1 up
+ ip -net "$ns2" link set ns2eth2 up
+ ip -net "$ns2" link set hsr2 up
+
+ ip -net "$ns3" link set ns3eth1 up
+ ip -net "$ns3" link set ns3eth2 up
+ ip -net "$ns3" link set hsr3 up
+}
+
+run_ptp_hdr_tests()
+{
+ echo "INFO: Running PTP-header tests."
+
+ ip netns exec "$ns1" ./hsr_ptp_test -H hsr1 -A ns1eth1 -B ns1eth2
+ ret=$?
+ stop_if_error "PTP header test failed (ns1)."
+
+ ip netns exec "$ns2" ./hsr_ptp_test -H hsr2 -A ns2eth1 -B ns2eth2
+ ret=$?
+ stop_if_error "PTP header test failed (ns2)."
+
+ ip netns exec "$ns3" ./hsr_ptp_test -H hsr3 -A ns3eth1 -B ns3eth2
+ ret=$?
+ stop_if_error "PTP header test failed (ns3)."
+}
+
+check_prerequisites
+trap cleanup_all_ns EXIT
+
+setup_ns ns1 ns2 ns3
+setup_hsr_interfaces 1
+run_ptp_hdr_tests
+
+exit $ret
diff --git a/tools/testing/selftests/net/hsr/hsr_ptp_test.c b/tools/testing/selftests/net/hsr/hsr_ptp_test.c
new file mode 100644
index 00000000000000..e2c2da56138ae3
--- /dev/null
+++ b/tools/testing/selftests/net/hsr/hsr_ptp_test.c
@@ -0,0 +1,496 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Simple test to verify the usage of the inline header used for HSR with
+ * ether type ETH_P_1588.
+ * The inline header has to be stripped, the sent packet must only appear on the
+ * specified port and the interface needs to accept a foreign HSR header and
+ * prepend its own header.
+ *
+ * Socket handling inspired by raw.c from linuxptp.
+ *
+ */
+#include <poll.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <linux/types.h>
+#include <linux/hsr_ptp.h>
+#include <linux/if_ether.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netpacket/packet.h>
+#include <sys/ioctl.h>
+
+#define MSEC_TO_NSEC(_x) (_x * 1000000)
+#define USEC_PER_SEC 1000000
+#define NSEC_PER_SEC 1000000000
+
+#ifndef __packed
+#define __packed __attribute__((packed))
+#endif
+
+#define MAC_LEN 6
+typedef uint8_t eth_addr[MAC_LEN];
+
+struct eth_hdr {
+ eth_addr dst;
+ eth_addr src;
+ uint16_t type;
+} __packed;
+
+struct hsr_hdr {
+ eth_addr dst;
+ eth_addr src;
+ uint16_t type;
+ uint16_t pathid_and_LSDU_size;
+ uint16_t sequence_nr;
+ uint16_t encap_type;
+} __packed;
+
+struct hsr_meta_header {
+ struct hsr_inline_header hsr_opt;
+ union {
+ struct hsr_hdr hsr_hdr;
+ struct eth_hdr eth_hdr;
+ };
+} __packed;
+
+static uint8_t ptp_packet[] = {
+ 0x00, 0x12, 0x00, 0x2c, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x00, 0x01, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+static uint8_t p2p_dst_mac[MAC_LEN] = {
+ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e
+};
+
+static uint8_t slave_mac_addr[MAC_LEN];
+static int32_t fd_slaveA = -1;
+static int32_t fd_slaveB = -1;
+static int32_t fd_hsr = -1;
+static uint16_t hsr_seq = 37;
+
+static void tsnorm(struct timespec *ts)
+{
+ while (ts->tv_nsec >= NSEC_PER_SEC) {
+ ts->tv_nsec -= NSEC_PER_SEC;
+ ts->tv_sec++;
+ }
+}
+
+static int64_t calcdiff(struct timespec t1, struct timespec t2)
+{
+ int64_t diff = USEC_PER_SEC * (long long)((int) t1.tv_sec - (int) t2.tv_sec);
+
+ diff += ((int) t1.tv_nsec - (int) t2.tv_nsec) / 1000;
+ return diff;
+}
+
+static int tsgreater(struct timespec *a, struct timespec *b)
+{
+ return ((a->tv_sec > b->tv_sec) ||
+ (a->tv_sec == b->tv_sec && a->tv_nsec > b->tv_nsec));
+}
+
+static int sk_interface_index(int fd, const char *name)
+{
+ struct ifreq ifreq;
+ int32_t err;
+
+ memset(&ifreq, 0, sizeof(ifreq));
+ strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name) - 1);
+ err = ioctl(fd, SIOCGIFINDEX, &ifreq);
+ if (err < 0) {
+ printf("ioctl SIOCGIFINDEX failed: %m\n");
+ return err;
+ }
+ return ifreq.ifr_ifindex;
+}
+
+static int open_socket(const char *name)
+{
+ struct sockaddr_ll addr;
+ int32_t fd, index;
+
+ fd = socket(AF_PACKET, SOCK_RAW, 0);
+ if (fd < 0) {
+ printf("socket failed: %m\n");
+ goto err;
+ }
+ index = sk_interface_index(fd, name);
+ if (index < 0)
+ goto err;
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sll_ifindex = index;
+ addr.sll_family = AF_PACKET;
+ addr.sll_protocol = htons(ETH_P_ALL);
+ if (bind(fd, (struct sockaddr *) &addr, sizeof(addr))) {
+ printf("bind failed: %m\n");
+ goto err;
+ }
+ if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, name, strlen(name))) {
+ printf("setsockopt SO_BINDTODEVICE failed: %m\n");
+ goto err;
+ }
+
+ return fd;
+err:
+ if (fd >= 0)
+ close(fd);
+ return -1;
+}
+
+static int sk_interface_macaddr(const char *name)
+{
+ struct ifreq ifreq;
+ int32_t err, fd;
+
+ memset(&ifreq, 0, sizeof(ifreq));
+ strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name) - 1);
+
+ fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (fd < 0) {
+ printf("socket failed: %m\n");
+ return -1;
+ }
+
+ err = ioctl(fd, SIOCGIFHWADDR, &ifreq);
+ if (err < 0) {
+ printf("ioctl SIOCGIFHWADDR failed: %m\n");
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+
+ memcpy(slave_mac_addr, &ifreq.ifr_hwaddr.sa_data, MAC_LEN);
+ return 0;
+}
+
+static int raw_open(const char *hsr_dev, const char *slaveA_dev, const char *slaveB_dev)
+{
+
+ if (sk_interface_macaddr(slaveA_dev))
+ goto err;
+
+ fd_slaveA = open_socket(slaveA_dev);
+ if (fd_slaveA < 0)
+ goto err;
+
+ fd_slaveB = open_socket(slaveB_dev);
+ if (fd_slaveB < 0)
+ goto err;
+
+ fd_hsr = open_socket(hsr_dev);
+ if (fd_hsr < 0)
+ goto err;
+
+ return 0;
+
+err:
+ if (fd_slaveA >= 0)
+ close(fd_slaveA);
+ if (fd_slaveB >= 0)
+ close(fd_slaveB);
+ if (fd_hsr >= 0)
+ close(fd_hsr);
+
+ return -1;
+}
+
+static int sk_receive(int fd, void *buf, int buflen)
+{
+ struct iovec iov = { buf, buflen };
+ uint8_t control[256];
+ int32_t cnt = 0;
+ struct msghdr msg;
+
+ memset(control, 0, sizeof(control));
+ memset(&msg, 0, sizeof(msg));
+
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = control;
+ msg.msg_controllen = sizeof(control);
+
+ cnt = recvmsg(fd, &msg, MSG_DONTWAIT);
+ if (cnt < 0)
+ return 0;
+ return cnt;
+}
+
+static int raw_recv(int fd, bool fwd_hsr, void *sample, int sample_len)
+{
+ struct timespec now, end;
+ struct hsr_hdr *hsr_hdr;
+ uint8_t buf[1500];
+ int32_t cnt;
+
+ /* The packet is expected to arrive within 100ms. HSR will send hello
+ * packets so there an end time and poll() will wait until this point.
+ */
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ end = now;
+ end.tv_nsec += MSEC_TO_NSEC(100);
+ tsnorm(&end);
+again:
+
+ cnt = sk_receive(fd, buf, sizeof(buf));
+ if (cnt == 0) {
+ int64_t sleep_time;
+ struct pollfd pfd;
+ int ret;
+
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (tsgreater(&now, &end))
+ return 0;
+
+ sleep_time = calcdiff(end, now) / 1000;
+ if (sleep_time <= 0)
+ return 0;
+
+ pfd.fd = fd;
+ pfd.events = POLLIN;
+ ret = poll(&pfd, 1, sleep_time);
+ if (ret <= 0)
+ return ret;
+ goto again;
+ }
+
+ if (cnt < sizeof(struct hsr_hdr))
+ goto again;
+
+ hsr_hdr = (void *)buf;
+ /* Embedded magic packet passed? */
+ if (hsr_hdr->type == htons(ETH_P_1588)) {
+ struct hsr_inline_header *hsr_opt = (void *)buf;
+
+ if (hsr_opt->magic == htonl(HSR_INLINE_HDR)) {
+ printf("Error: Found HSR_INLINE_HDR\n");
+ return -1;
+ }
+ }
+ /* Assuming it is *our* network and nobody but the test here sends
+ * packets to p2p_dst_mac. Therefore any received packet needs to be
+ * ours and every mismatch is considered as error.
+ */
+ if (memcmp(hsr_hdr->dst, p2p_dst_mac, MAC_LEN))
+ goto again;
+
+ if (hsr_hdr->type != htons(ETH_P_HSR)) {
+ printf("Error: Unexpected ether type: 0x%x\n", ntohs(hsr_hdr->type));
+ return -1;
+ }
+
+ if (hsr_hdr->encap_type != htons(ETH_P_1588)) {
+ printf("Error: Unexpected encapsulated type: 0x%x\n",
+ htons(hsr_hdr->encap_type));
+ return -1;
+ }
+
+ if (fwd_hsr) {
+ if (hsr_hdr->sequence_nr != htons(hsr_seq - 1)) {
+ printf("Error: Packet has wrong seq nr, %d vs %d.\n",
+ ntohs(hsr_hdr->sequence_nr), hsr_seq - 1);
+ return -1;
+ }
+ /* Undo the SRC MAC change in pkt_send() */
+ hsr_hdr->src[3] ^= 0x21;
+ if (memcmp(hsr_hdr->src, slave_mac_addr, MAC_LEN)) {
+ printf("Error: Packet has wrong SRC-MAC\n");
+ return -1;
+ }
+ }
+
+ if (cnt < sizeof(struct hsr_hdr) + sample_len) {
+ printf("Error: Packet %d is too small for data check\n", cnt);
+ return -1;
+ }
+
+ if (!memcmp(&buf[sizeof(struct hsr_hdr)], sample, sample_len))
+ return 1;
+
+ printf("Error: Packet did not match the sample\n");
+ return -1;
+}
+
+static int recv_verify(int port, bool fwd_hsr, void *sample, int sample_len)
+{
+ int32_t error = 0;
+ int32_t ret;
+
+ ret = raw_recv(fd_slaveA, fwd_hsr, sample, sample_len);
+ if (ret < 0)
+ return ret;
+ if (port == HSR_INLINE_HDR_PORT_A && ret == 0) {
+ printf("Error: Missing packet on portA\n");
+ error = 1;
+ }
+ if (port == HSR_INLINE_HDR_PORT_B && ret == 1) {
+ printf("Error: Not expecting packet on portA\n");
+ error = 1;
+ }
+
+ ret = raw_recv(fd_slaveB, fwd_hsr, sample, sample_len);
+ if (ret < 0)
+ return ret;
+ if (port == HSR_INLINE_HDR_PORT_B && ret == 0) {
+ printf("Error: Missing packet on portB\n");
+ error = 1;
+ }
+ if (port == HSR_INLINE_HDR_PORT_A && ret == 1) {
+ printf("Error: Not expecting packet on portB\n");
+ error = 1;
+ }
+ return error;
+}
+
+static int32_t pkt_send(int port, bool hsr_hdr, void *data, int data_len)
+{
+ struct hsr_meta_header *hdr;
+ uint8_t packet[200];
+ ssize_t cnt;
+ size_t len;
+
+ memset(packet, 0, sizeof(packet));
+
+ len = sizeof(struct hsr_inline_header);
+ hdr = (struct hsr_meta_header *)packet;
+ memset(&hdr->hsr_opt, 0, sizeof(hdr->hsr_opt));
+ hdr->hsr_opt.magic = htonl(HSR_INLINE_HDR);
+ hdr->hsr_opt.eth_type = htons(ETH_P_1588);
+ if (port != HSR_INLINE_HDR_PORT_A && port != HSR_INLINE_HDR_PORT_B) {
+ printf("Wrong port requested\n");
+ return -1;
+ }
+ hdr->hsr_opt.req_tx_port = port;
+
+ if (hsr_hdr) {
+ uint16_t pathid_size;
+
+ len += sizeof(struct hsr_hdr);
+ memcpy(&packet[len], data, data_len);
+
+ hdr->hsr_opt.has_hsr_header = 1;
+
+ memcpy(&hdr->hsr_hdr.dst, p2p_dst_mac, MAC_LEN);
+ memcpy(&hdr->hsr_hdr.src, slave_mac_addr, MAC_LEN);
+ /* Flip a bit in SRC MAC addr so it does not look like hosts */
+ hdr->hsr_hdr.src[3] ^= 0x21;
+
+ hdr->hsr_hdr.type = htons(ETH_P_HSR);
+ hdr->hsr_hdr.sequence_nr = htons(hsr_seq++);
+ hdr->hsr_hdr.encap_type = htons(ETH_P_1588);
+
+ /* The resulting packet must be alteast 66 bytes */
+ if (data_len + sizeof(struct hsr_hdr) < 66)
+ data_len = 66 - sizeof(struct hsr_hdr);
+
+ pathid_size = data_len + sizeof(struct hsr_hdr) - sizeof(struct eth_hdr);
+ pathid_size |= (port - 1) << 12;
+
+ hdr->hsr_hdr.pathid_and_LSDU_size = htons(pathid_size);
+ } else {
+ len += sizeof(struct eth_hdr);
+ hdr->hsr_opt.has_hsr_header = 0;
+
+ memcpy(&hdr->eth_hdr.dst, p2p_dst_mac, MAC_LEN);
+ memcpy(&hdr->eth_hdr.src, slave_mac_addr, MAC_LEN);
+ hdr->eth_hdr.type = htons(ETH_P_1588);
+
+ memcpy(&packet[len], data, data_len);
+ }
+
+ cnt = send(fd_hsr, packet, len + data_len, 0);
+ if (cnt < 1)
+ return -1;
+
+ return cnt;
+}
+
+int main(int argc, char *argv[])
+{
+ char *slaveA = NULL, *slaveB = NULL, *hsr_dev = NULL;
+ char *msg_mode;
+ int opt;
+
+ while ((opt = getopt(argc, argv, "A:B:H:")) != -1) {
+ switch (opt) {
+ case 'A':
+ slaveA = strdup(optarg);
+ break;
+
+ case 'B':
+ slaveB = strdup(optarg);
+ break;
+
+ case 'H':
+ hsr_dev = strdup(optarg);
+ break;
+ default: /* '?' */
+ fprintf(stderr, "Usage: %s -A slaveA -B slaveB -H hsr_device\n",
+ argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!slaveA || !slaveB || !hsr_dev) {
+ fprintf(stderr, "Missing network devices\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (raw_open(hsr_dev, slaveA, slaveB) < 0)
+ return EXIT_FAILURE;
+
+ msg_mode = "PortA, no-hsr-header";
+ if (pkt_send(HSR_INLINE_HDR_PORT_A, false, ptp_packet, sizeof(ptp_packet)) < 0) {
+ printf("Sending failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+ if (recv_verify(HSR_INLINE_HDR_PORT_A, false, ptp_packet, sizeof(ptp_packet))) {
+ printf("Verify failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+
+ ptp_packet[16 + 4]++;
+ msg_mode = "PortB, no-hsr-header";
+ if (pkt_send(HSR_INLINE_HDR_PORT_B, false, ptp_packet, sizeof(ptp_packet)) < 0) {
+ printf("Sending failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+ if (recv_verify(HSR_INLINE_HDR_PORT_B, false, ptp_packet, sizeof(ptp_packet))) {
+ printf("Verify failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+
+ ptp_packet[16 + 4]++;
+ msg_mode = "PortA, hsr-header";
+ if (pkt_send(HSR_INLINE_HDR_PORT_A, true, ptp_packet, sizeof(ptp_packet)) < 0) {
+ printf("Sending failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+ if (recv_verify(HSR_INLINE_HDR_PORT_A, true, ptp_packet, sizeof(ptp_packet))) {
+ printf("Verify failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+
+ ptp_packet[16 + 4]++;
+ msg_mode = "PortB, hsr-header";
+ if (pkt_send(HSR_INLINE_HDR_PORT_B, true, ptp_packet, sizeof(ptp_packet)) < 0) {
+ printf("Sending failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+ if (recv_verify(HSR_INLINE_HDR_PORT_B, true, ptp_packet, sizeof(ptp_packet))) {
+ printf("Verify failed: %s\n", msg_mode);
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
|
| 31/3 | 2026/11/25 10:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17129 output: 32 thoughts: 879 Thoughts: **KMSAN Evaluation: HSR PTP Patch Series** Okay, let's break this down. The user wants me to decide if this HSR PTP patch series warrants a dedicated KMSAN fuzzing session. My immediate instinct is to avoid this unless absolutely necessary, given the resource overhead. KMSAN is great, but we should only deploy it if standard bug detectors (KASAN, lockdep, UB-sanitizers) are unlikely to catch a potential issue. The key is uninitialized memory reads or kernel-to-user info leaks that *only* KMSAN would reveal. First, I see the patch adds PTP support for HSR in `net/hsr/`. Standard KASAN should be picking up a lot of things. It defines some new structs: `hsr_inline_header`, `hsr_ethhdr`. The functions `hsr_ptp_parse_header`, `hsr_dev_xmit`, `hsr_forward_skb`, and several others in `hsr_forward.c` and `hsr_device.c` are introduced or modified. Looks like it handles a PTP header, parses it, and then deals with forwarding and cloning/copying SKBs. Now, my focus narrows to potential KMSAN triggers. `hsr_ptp_parse_header` pulls the header if the protocol matches and there is a valid magic header. It then checks padding. All seems fine here, no obvious uninitialized reads right off the bat. The major change seems to be in the SKB handling with new functions like `skb_clone`, `skb_cow_head`, and `skb_postpush_data_move`. Ah, here's where my alarm bells start to ring: in `hsr_forward.c` within `hsr_forward_skb`, the local variable `struct hsr_frame_info frame;` is declared. Hold on a second, is this structure fully initialized before use? I need to check how the `hsr_frame_info` struct is actually used and initialized within the code. Let me check the definition of that struct and where it's populated. This is the critical piece – uninitialized memory in `frame` could definitely trigger a KMSAN report, but only if it's actually read later without being assigned. So, I need to understand exactly which fields of the `frame` struct are used, and when and where they're assigned their initial values. I am going to dive into `hsr_forward.c` and `hsr_framereg.h` to see how the `frame` struct is initialized and used. This will determine if KMSAN is *actually* needed. I need to know if we are at risk here! |
| 32/3 | 2026/11/25 10:01 | tool | grepper |
0mArgs:{
"Expression": "hsr_frame_info",
"PathPrefixes": [
"net/hsr/"
]
}Results: {
"Output": "net/hsr/hsr_forward.c=150=static struct sk_buff *create_stripped_skb_hsr(struct sk_buff *skb_in,\nnet/hsr/hsr_forward.c:151:\t\t\t\t\t struct hsr_frame_info *frame)\nnet/hsr/hsr_forward.c-152-{\n--\nnet/hsr/hsr_forward.c-178-\nnet/hsr/hsr_forward.c:179:struct sk_buff *hsr_get_untagged_frame(struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.c-180-\t\t\t\t struct hsr_port *port)\n--\nnet/hsr/hsr_forward.c-196-\nnet/hsr/hsr_forward.c:197:struct sk_buff *prp_get_untagged_frame(struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.c-198-\t\t\t\t struct hsr_port *port)\n--\nnet/hsr/hsr_forward.c=238=static struct sk_buff *prp_fill_rct(struct sk_buff *skb,\nnet/hsr/hsr_forward.c:239:\t\t\t\t struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.c-240-\t\t\t\t struct hsr_port *port)\n--\nnet/hsr/hsr_forward.c-267-\nnet/hsr/hsr_forward.c:268:static void hsr_set_path_id(struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.c-269-\t\t\t struct hsr_ethhdr *hsr_ethhdr,\n--\nnet/hsr/hsr_forward.c=289=static struct sk_buff *hsr_fill_tag(struct sk_buff *skb,\nnet/hsr/hsr_forward.c:290:\t\t\t\t struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.c-291-\t\t\t\t struct hsr_port *port, u8 proto_version)\n--\nnet/hsr/hsr_forward.c-331- */\nnet/hsr/hsr_forward.c:332:struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.c-333-\t\t\t\t\tstruct hsr_port *port)\n--\nnet/hsr/hsr_forward.c-383-\nnet/hsr/hsr_forward.c:384:struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.c-385-\t\t\t\t\tstruct hsr_port *port)\n--\nnet/hsr/hsr_forward.c=430=static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port,\nnet/hsr/hsr_forward.c:431:\t\t struct hsr_frame_info *frame)\nnet/hsr/hsr_forward.c-432-{\n--\nnet/hsr/hsr_forward.c=453=static bool prp_is_lan_dup(enum hsr_port_type rx, struct hsr_port *port)\n--\nnet/hsr/hsr_forward.c-458-\nnet/hsr/hsr_forward.c:459:bool prp_drop_frame(struct hsr_frame_info *frame, struct hsr_port *port)\nnet/hsr/hsr_forward.c-460-{\n--\nnet/hsr/hsr_forward.c-482-\nnet/hsr/hsr_forward.c:483:bool hsr_drop_frame(struct hsr_frame_info *frame, struct hsr_port *port)\nnet/hsr/hsr_forward.c-484-{\n--\nnet/hsr/hsr_forward.c-550- */\nnet/hsr/hsr_forward.c:551:static void hsr_forward_do(struct hsr_frame_info *frame)\nnet/hsr/hsr_forward.c-552-{\n--\nnet/hsr/hsr_forward.c=639=static void check_local_dest(struct hsr_priv *hsr, struct sk_buff *skb,\nnet/hsr/hsr_forward.c:640:\t\t\t struct hsr_frame_info *frame)\nnet/hsr/hsr_forward.c-641-{\n--\nnet/hsr/hsr_forward.c=658=static void handle_std_frame(struct sk_buff *skb,\nnet/hsr/hsr_forward.c:659:\t\t\t struct hsr_frame_info *frame)\nnet/hsr/hsr_forward.c-660-{\n--\nnet/hsr/hsr_forward.c=680=int hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,\nnet/hsr/hsr_forward.c:681:\t\t\tstruct hsr_frame_info *frame)\nnet/hsr/hsr_forward.c-682-{\n--\nnet/hsr/hsr_forward.c=714=int prp_fill_frame_info(__be16 proto, struct sk_buff *skb,\nnet/hsr/hsr_forward.c:715:\t\t\tstruct hsr_frame_info *frame)\nnet/hsr/hsr_forward.c-716-{\n--\nnet/hsr/hsr_forward.c-732-\nnet/hsr/hsr_forward.c:733:static int fill_frame_info(struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.c-734-\t\t\t struct sk_buff *skb, struct hsr_port *port,\n--\nnet/hsr/hsr_forward.c=810=void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port,\n--\nnet/hsr/hsr_forward.c-812-{\nnet/hsr/hsr_forward.c:813:\tstruct hsr_frame_info frame;\nnet/hsr/hsr_forward.c-814-\n--\nnet/hsr/hsr_forward.h=16=void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port,\nnet/hsr/hsr_forward.h-17-\t\t enum hsr_port_type req_tx_port, bool has_hsr_header);\nnet/hsr/hsr_forward.h:18:struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.h-19-\t\t\t\t\tstruct hsr_port *port);\nnet/hsr/hsr_forward.h:20:struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.h-21-\t\t\t\t\tstruct hsr_port *port);\nnet/hsr/hsr_forward.h:22:struct sk_buff *hsr_get_untagged_frame(struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.h-23-\t\t\t\t struct hsr_port *port);\nnet/hsr/hsr_forward.h:24:struct sk_buff *prp_get_untagged_frame(struct hsr_frame_info *frame,\nnet/hsr/hsr_forward.h-25-\t\t\t\t struct hsr_port *port);\nnet/hsr/hsr_forward.h:26:bool prp_drop_frame(struct hsr_frame_info *frame, struct hsr_port *port);\nnet/hsr/hsr_forward.h:27:bool hsr_drop_frame(struct hsr_frame_info *frame, struct hsr_port *port);\nnet/hsr/hsr_forward.h-28-int prp_fill_frame_info(__be16 proto, struct sk_buff *skb,\nnet/hsr/hsr_forward.h:29:\t\t\tstruct hsr_frame_info *frame);\nnet/hsr/hsr_forward.h-30-int hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,\nnet/hsr/hsr_forward.h:31:\t\t\tstruct hsr_frame_info *frame);\nnet/hsr/hsr_forward.h-32-#endif /* __HSR_FORWARD_H */\n--\nnet/hsr/hsr_framereg.c=373=EXPORT_SYMBOL_IF_KUNIT(hsr_get_seq_block);\n--\nnet/hsr/hsr_framereg.c-378- */\nnet/hsr/hsr_framereg.c:379:void hsr_handle_sup_frame(struct hsr_frame_info *frame)\nnet/hsr/hsr_framereg.c-380-{\n--\nnet/hsr/hsr_framereg.c=573=void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port,\n--\nnet/hsr/hsr_framereg.c-595- */\nnet/hsr/hsr_framereg.c:596:static int hsr_check_duplicate(struct hsr_frame_info *frame,\nnet/hsr/hsr_framereg.c-597-\t\t\t unsigned int port_type)\n--\nnet/hsr/hsr_framereg.c-639- */\nnet/hsr/hsr_framereg.c:640:int hsr_register_frame_out(struct hsr_port *port, struct hsr_frame_info *frame)\nnet/hsr/hsr_framereg.c-641-{\n--\nnet/hsr/hsr_framereg.c-656- */\nnet/hsr/hsr_framereg.c:657:int prp_register_frame_out(struct hsr_port *port, struct hsr_frame_info *frame)\nnet/hsr/hsr_framereg.c-658-{\n--\nnet/hsr/hsr_framereg.h=15=struct hsr_node;\nnet/hsr/hsr_framereg.h-16-\nnet/hsr/hsr_framereg.h:17:struct hsr_frame_info {\nnet/hsr/hsr_framereg.h-18-\tstruct sk_buff *skb_std;\n--\nnet/hsr/hsr_framereg.h=38=struct hsr_node *hsr_get_node(struct hsr_port *port, struct list_head *node_db,\n--\nnet/hsr/hsr_framereg.h-40-\t\t\t enum hsr_port_type rx_port);\nnet/hsr/hsr_framereg.h:41:void hsr_handle_sup_frame(struct hsr_frame_info *frame);\nnet/hsr/hsr_framereg.h-42-bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr);\n--\nnet/hsr/hsr_framereg.h=49=void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port,\nnet/hsr/hsr_framereg.h-50-\t\t\t u16 sequence_nr);\nnet/hsr/hsr_framereg.h:51:int hsr_register_frame_out(struct hsr_port *port, struct hsr_frame_info *frame);\nnet/hsr/hsr_framereg.h-52-\n--\nnet/hsr/hsr_framereg.h=76=bool hsr_is_node_in_db(struct list_head *node_db,\n--\nnet/hsr/hsr_framereg.h-78-\nnet/hsr/hsr_framereg.h:79:int prp_register_frame_out(struct hsr_port *port, struct hsr_frame_info *frame);\nnet/hsr/hsr_framereg.h-80-\n--\nnet/hsr/hsr_main.h=147=struct hsr_port {\n--\nnet/hsr/hsr_main.h-155-\nnet/hsr/hsr_main.h:156:struct hsr_frame_info;\nnet/hsr/hsr_main.h-157-struct hsr_node;\n--\nnet/hsr/hsr_main.h=159=struct hsr_proto_ops {\n--\nnet/hsr/hsr_main.h-164-\t\t\t\t struct hsr_node *node);\nnet/hsr/hsr_main.h:165:\tbool (*drop_frame)(struct hsr_frame_info *frame, struct hsr_port *port);\nnet/hsr/hsr_main.h:166:\tstruct sk_buff * (*get_untagged_frame)(struct hsr_frame_info *frame,\nnet/hsr/hsr_main.h-167-\t\t\t\t\t struct hsr_port *port);\nnet/hsr/hsr_main.h:168:\tstruct sk_buff * (*create_tagged_frame)(struct hsr_frame_info *frame,\nnet/hsr/hsr_main.h-169-\t\t\t\t\t\tstruct hsr_port *port);\nnet/hsr/hsr_main.h-170-\tint (*fill_frame_info)(__be16 proto, struct sk_buff *skb,\nnet/hsr/hsr_main.h:171:\t\t\t struct hsr_frame_info *frame);\nnet/hsr/hsr_main.h-172-\tbool (*invalid_dan_ingress_frame)(__be16 protocol);\n--\nnet/hsr/hsr_main.h-174-\tint (*register_frame_out)(struct hsr_port *port,\nnet/hsr/hsr_main.h:175:\t\t\t\t struct hsr_frame_info *frame);\nnet/hsr/hsr_main.h-176-};\n--\nnet/hsr/prp_dup_discard_test.c=9=struct prp_test_data {\n--\nnet/hsr/prp_dup_discard_test.c-11-\tstruct hsr_port port_rcv;\nnet/hsr/prp_dup_discard_test.c:12:\tstruct hsr_frame_info frame;\nnet/hsr/prp_dup_discard_test.c-13-\tstruct hsr_node node;\n"
} |
| 33/3 | 2026/11/25 10:01 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22418 output: 40 thoughts: 36 Thoughts: Okay, let's dive into this. I need to get a handle on how this `hsr_forward.c` file is handling frame information, specifically within the `fill_frame_info` function. My target is the code between lines 710 and 820, as that's likely where the core logic resides. I'm assuming that this function is crucial for populating the data structures that the HSR (High-availability Seamless Redundancy) protocol uses to make its forwarding decisions. I'll be looking for how it extracts and processes the relevant header fields, any error checking it might perform, and how it determines if the frame needs special handling. I'll want to see how it's interfacing with the underlying network interface and any associated buffers. The goal is to fully understand its function and contribution to the overall HSR forwarding process. |
| 34/3 | 2026/11/25 10:01 | tool | read-file |
0mArgs:{
"File": "net/hsr/hsr_forward.c",
"FirstLine": 710,
"LineCount": 100
}Results: {
"Contents": " 710:\t\n 711:\t\treturn 0;\n 712:\t}\n 713:\t\n 714:\tint prp_fill_frame_info(__be16 proto, struct sk_buff *skb,\n 715:\t\t\t\tstruct hsr_frame_info *frame)\n 716:\t{\n 717:\t\t/* Supervision frame */\n 718:\t\tstruct prp_rct *rct = skb_get_PRP_rct(skb);\n 719:\t\n 720:\t\tif (rct \u0026\u0026\n 721:\t\t prp_check_lsdu_size(skb, rct, frame-\u003eis_supervision)) {\n 722:\t\t\tframe-\u003eskb_hsr = NULL;\n 723:\t\t\tframe-\u003eskb_std = NULL;\n 724:\t\t\tframe-\u003eskb_prp = skb;\n 725:\t\t\tframe-\u003esequence_nr = prp_get_skb_sequence_nr(rct);\n 726:\t\t\treturn 0;\n 727:\t\t}\n 728:\t\thandle_std_frame(skb, frame);\n 729:\t\n 730:\t\treturn 0;\n 731:\t}\n 732:\t\n 733:\tstatic int fill_frame_info(struct hsr_frame_info *frame,\n 734:\t\t\t\t struct sk_buff *skb, struct hsr_port *port,\n 735:\t\t\t\t enum hsr_port_type req_tx_port, bool has_hsr_header)\n 736:\t{\n 737:\t\tstruct hsr_priv *hsr = port-\u003ehsr;\n 738:\t\tstruct hsr_vlan_ethhdr *vlan_hdr;\n 739:\t\tstruct list_head *n_db;\n 740:\t\tstruct ethhdr *ethhdr;\n 741:\t\t__be16 proto;\n 742:\t\tint ret;\n 743:\t\n 744:\t\t/* Check if skb contains ethhdr */\n 745:\t\tif (skb-\u003emac_len \u003c sizeof(struct ethhdr))\n 746:\t\t\treturn -EINVAL;\n 747:\t\n 748:\t\tmemset(frame, 0, sizeof(*frame));\n 749:\t\tframe-\u003eis_supervision = is_supervision_frame(port-\u003ehsr, skb);\n 750:\t\tif (frame-\u003eis_supervision \u0026\u0026 hsr-\u003eredbox)\n 751:\t\t\tframe-\u003eis_proxy_supervision =\n 752:\t\t\t\tis_proxy_supervision_frame(port-\u003ehsr, skb);\n 753:\t\n 754:\t\tn_db = \u0026hsr-\u003enode_db;\n 755:\t\tif (port-\u003etype == HSR_PT_INTERLINK)\n 756:\t\t\tn_db = \u0026hsr-\u003eproxy_node_db;\n 757:\t\n 758:\t\tframe-\u003ereq_tx_port = req_tx_port;\n 759:\t\tframe-\u003ehas_hsr_header = has_hsr_header;\n 760:\t\n 761:\t\tif (!frame-\u003ehas_hsr_header) {\n 762:\t\t\tframe-\u003enode_src = hsr_get_node(port, n_db, skb,\n 763:\t\t\t\t\t\t frame-\u003eis_supervision,\n 764:\t\t\t\t\t\t port-\u003etype);\n 765:\t\t\tif (!frame-\u003enode_src)\n 766:\t\t\t\treturn -1; /* Unknown node and !is_supervision, or no mem */\n 767:\t\t}\n 768:\t\n 769:\t\tethhdr = (struct ethhdr *)skb_mac_header(skb);\n 770:\t\tframe-\u003eis_vlan = false;\n 771:\t\tproto = ethhdr-\u003eh_proto;\n 772:\t\n 773:\t\t/* PRP RedBox only: classify the unicast destination once so the\n 774:\t\t * per-egress-port decision in prp_drop_frame() stays O(1). HSR RedBox\n 775:\t\t * does its own classification and must not pay these node-table walks.\n 776:\t\t */\n 777:\t\tif (hsr-\u003eprot_version == PRP_V1 \u0026\u0026 hsr-\u003eredbox \u0026\u0026\n 778:\t\t is_unicast_ether_addr(ethhdr-\u003eh_dest)) {\n 779:\t\t\tframe-\u003edst_in_node_db =\n 780:\t\t\t\thsr_is_node_in_db(\u0026hsr-\u003enode_db, ethhdr-\u003eh_dest);\n 781:\t\t\tframe-\u003edst_in_proxy_node_db =\n 782:\t\t\t\thsr_is_node_in_db(\u0026hsr-\u003eproxy_node_db, ethhdr-\u003eh_dest);\n 783:\t\t}\n 784:\t\n 785:\t\tif (proto == htons(ETH_P_8021Q))\n 786:\t\t\tframe-\u003eis_vlan = true;\n 787:\t\n 788:\t\tif (frame-\u003eis_vlan) {\n 789:\t\t\t/* Note: skb-\u003emac_len might be wrong here. */\n 790:\t\t\tif (!pskb_may_pull(skb,\n 791:\t\t\t\t\t skb_mac_offset(skb) +\n 792:\t\t\t\t\t offsetofend(struct hsr_vlan_ethhdr, vlanhdr)))\n 793:\t\t\t\treturn -EINVAL;\n 794:\t\t\tvlan_hdr = (struct hsr_vlan_ethhdr *)skb_mac_header(skb);\n 795:\t\t\tproto = vlan_hdr-\u003evlanhdr.h_vlan_encapsulated_proto;\n 796:\t\t}\n 797:\t\n 798:\t\tframe-\u003eis_from_san = false;\n 799:\t\tframe-\u003eport_rcv = port;\n 800:\t\tret = hsr-\u003eproto_ops-\u003efill_frame_info(proto, skb, frame);\n 801:\t\tif (ret)\n 802:\t\t\treturn ret;\n 803:\t\n 804:\t\tcheck_local_dest(port-\u003ehsr, skb, frame);\n 805:\t\n 806:\t\treturn 0;\n 807:\t}\n 808:\t\n 809:\t/* Must be called holding rcu read lock (because of the port parameter) */\n"
} |
| 35/3 | 2026/11/25 10:01 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24353 output: 39 thoughts: 114 Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue: **Investigating Potential Data Corruption** Right, so `fill_frame_info` in this HSR module—specifically at line 748—it's pretty clear that it's doing a `memset` on the `frame` structure, setting everything to zero right at the beginning. That's a critical point to keep in mind; the entire `frame` is guaranteed to be initialized to all zeros *before* anything else happens within that function. This is significant because it is a common starting point to know for certain. Now, let's trace this. I need to understand what this `frame` actually *is* and how its fields are being populated and used. A zeroed-out starting point could point to data integrity, or it may have dependencies. Let's dig deeper into where this is called and how its fields are later utilized to get a complete picture. Okay, I'm heading over to `hsr_fill_frame_info` in `net/hsr/hsr_forward.c`, that's where I need to be. Let me scroll through lines 675 to 715; that looks like the relevant section to inspect. This should show me what's happening to the frame's content after the zeroing. |
| 36/3 | 2026/11/25 10:02 | tool | read-file |
0mArgs:{
"File": "net/hsr/hsr_forward.c",
"FirstLine": 675,
"LineCount": 40
}Results: {
"Contents": " 675:\t\t\tframe-\u003esequence_nr = hsr-\u003esequence_nr;\n 676:\t\t\tWRITE_ONCE(hsr-\u003esequence_nr, hsr-\u003esequence_nr + 1);\n 677:\t\t}\n 678:\t}\n 679:\t\n 680:\tint hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,\n 681:\t\t\t\tstruct hsr_frame_info *frame)\n 682:\t{\n 683:\t\tstruct hsr_port *port = frame-\u003eport_rcv;\n 684:\t\tstruct hsr_priv *hsr = port-\u003ehsr;\n 685:\t\n 686:\t\tif (frame-\u003ehas_hsr_header) {\n 687:\t\t\tframe-\u003eskb_std = skb;\n 688:\t\n 689:\t\t\tWARN_ON_ONCE(port-\u003etype != HSR_PT_MASTER);\n 690:\t\t\tWARN_ON_ONCE(skb-\u003emac_len \u003c sizeof(struct hsr_ethhdr));\n 691:\t\t\treturn 0;\n 692:\t\t}\n 693:\t\t/* HSRv0 supervisory frames double as a tag so treat them as tagged. */\n 694:\t\tif ((!hsr-\u003eprot_version \u0026\u0026 proto == htons(ETH_P_PRP)) ||\n 695:\t\t proto == htons(ETH_P_HSR)) {\n 696:\t\t\t/* Check if skb contains hsr_ethhdr */\n 697:\t\t\tif (skb-\u003emac_len \u003c sizeof(struct hsr_ethhdr))\n 698:\t\t\t\treturn -EINVAL;\n 699:\t\n 700:\t\t\t/* HSR tagged frame :- Data or Supervision */\n 701:\t\t\tframe-\u003eskb_std = NULL;\n 702:\t\t\tframe-\u003eskb_prp = NULL;\n 703:\t\t\tframe-\u003eskb_hsr = skb;\n 704:\t\t\tframe-\u003esequence_nr = hsr_get_skb_sequence_nr(skb);\n 705:\t\t\treturn 0;\n 706:\t\t}\n 707:\t\n 708:\t\t/* Standard frame or PRP from master port */\n 709:\t\thandle_std_frame(skb, frame);\n 710:\t\n 711:\t\treturn 0;\n 712:\t}\n 713:\t\n 714:\tint prp_fill_frame_info(__be16 proto, struct sk_buff *skb,\n"
} |
| 37/3 | 2026/11/25 10:02 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25460 output: 39 thoughts: 998 Thoughts: **Analyzing HSR Header Processing in `hsr_dev_xmit` and Related Functions** Okay, let's break this down. My initial focus was on lines 686-692, specifically those within `fill_frame_info`. It looks like there's a check `if (frame->has_hsr_header)` and if that is true, a return. However, there is a WARN statement on skb->mac_len, so I needed to understand that. Now, let's step back and follow the flow of events from `hsr_dev_xmit`. I see that the `skb->mac_len` and `skb->network_header` are being manipulated there. The key here seems to be `hsr_ptp_parse_header`, which is called before the header reset. I needed to understand what was being changed. The call to `hsr_ptp_parse_header` is interesting. That’s where the actual header parsing happens. I see `pskb_may_pull` and then `skb_pull`. Crucially, `skb_set_network_header(skb, hdr_len)` is called, which sets up the network header based on `hdr_len`. If `has_hsr_header` is true, which is the conditional that flagged the initial issue, then `hdr_len` includes `HSR_HLEN`. Following through with the flow, `skb_reset_mac_header(skb)` is called and then `skb_reset_mac_len(skb)`, which resets `mac_len` based on the difference between the current `network_header` and `mac_header`. Since the `network_header` was set by `hsr_ptp_parse_header`, this is the crucial point to evaluate the check on mac_len in fill_frame_info. So, if `has_hsr_header` is true, then `hdr_len = ETH_HLEN + HSR_HLEN`, which is `sizeof(struct hsr_ethhdr)`. Therefore, `mac_len` is being set to that value, too. The subsequent `if (skb->mac_len < sizeof(struct ethhdr))` check within `fill_frame_info` is *after* this manipulation. This explains the potential warning, if `has_hsr_header` is true and `skb->mac_len` could have an unexpected value. Finally, I need to check what happens within `hsr_forward_do` when `frame->has_hsr_header` is true, as this is where the `skb` is ultimately processed. It is important to know what is done with the `skb` since the value of `skb->mac_len` will depend on the path taken. |
| 38/3 | 2026/11/25 10:04 | tool | read-file |
0mArgs:{
"File": "net/hsr/hsr_forward.c",
"FirstLine": 545,
"LineCount": 90
}Results: {
"Contents": " 545:\t *\n 546:\t * HSR slave devices should insert a HSR tag into the frame, or forward the\n 547:\t * frame unchanged if it's already tagged. Interlink devices should strip HSR\n 548:\t * tags if they're of the non-HSR type (but only after duplicate discard). The\n 549:\t * master device always strips HSR tags.\n 550:\t */\n 551:\tstatic void hsr_forward_do(struct hsr_frame_info *frame)\n 552:\t{\n 553:\t\tstruct hsr_port *port;\n 554:\t\tstruct sk_buff *skb;\n 555:\t\tbool sent = false;\n 556:\t\n 557:\t\thsr_for_each_port(frame-\u003eport_rcv-\u003ehsr, port) {\n 558:\t\t\tstruct hsr_priv *hsr = port-\u003ehsr;\n 559:\t\n 560:\t\t\t/* Don't send frame back the way it came */\n 561:\t\t\tif (port == frame-\u003eport_rcv)\n 562:\t\t\t\tcontinue;\n 563:\t\n 564:\t\t\t/* Don't deliver locally unless we should */\n 565:\t\t\tif (port-\u003etype == HSR_PT_MASTER \u0026\u0026 !frame-\u003eis_local_dest)\n 566:\t\t\t\tcontinue;\n 567:\t\n 568:\t\t\t/* Deliver frames directly addressed to us to master only */\n 569:\t\t\tif (port-\u003etype != HSR_PT_MASTER \u0026\u0026 frame-\u003eis_local_exclusive)\n 570:\t\t\t\tcontinue;\n 571:\t\n 572:\t\t\t/* If hardware duplicate generation is enabled, only send out\n 573:\t\t\t * one port.\n 574:\t\t\t */\n 575:\t\t\tif ((port-\u003edev-\u003efeatures \u0026 NETIF_F_HW_HSR_DUP) \u0026\u0026 sent)\n 576:\t\t\t\tcontinue;\n 577:\t\n 578:\t\t\t/* If this frame has a specific outgoing port specified (by the\n 579:\t\t\t * sender) then send it on this port only.\n 580:\t\t\t */\n 581:\t\t\tif (frame-\u003ereq_tx_port != HSR_PT_NONE \u0026\u0026\n 582:\t\t\t frame-\u003ereq_tx_port != port-\u003etype)\n 583:\t\t\t\tcontinue;\n 584:\t\t\t/* If this TX frame already has a HSR header then forward the\n 585:\t\t\t * frame with it and don't add one.\n 586:\t\t\t */\n 587:\t\t\tif (frame-\u003ehas_hsr_header \u0026\u0026 frame-\u003eskb_std) {\n 588:\t\t\t\tskb = skb_clone(frame-\u003eskb_std, GFP_ATOMIC);\n 589:\t\t\t\tif (skb \u0026\u0026 frame-\u003eskb_std-\u003esk)\n 590:\t\t\t\t\tskb_set_owner_w(skb, frame-\u003eskb_std-\u003esk);\n 591:\t\t\t\tgoto inject_into_stack;\n 592:\t\t\t}\n 593:\t\n 594:\t\t\t/* Don't send frame over port where it has been sent before.\n 595:\t\t\t * Also for SAN, this shouldn't be done.\n 596:\t\t\t */\n 597:\t\t\tif (!frame-\u003eis_from_san \u0026\u0026\n 598:\t\t\t hsr-\u003eproto_ops-\u003eregister_frame_out \u0026\u0026\n 599:\t\t\t hsr-\u003eproto_ops-\u003eregister_frame_out(port, frame))\n 600:\t\t\t\tcontinue;\n 601:\t\n 602:\t\t\tif (frame-\u003eis_supervision \u0026\u0026 port-\u003etype == HSR_PT_MASTER \u0026\u0026\n 603:\t\t\t !frame-\u003eis_proxy_supervision) {\n 604:\t\t\t\thsr_handle_sup_frame(frame);\n 605:\t\t\t\tcontinue;\n 606:\t\t\t}\n 607:\t\n 608:\t\t\t/* Check if frame is to be dropped. Eg. for PRP no forward\n 609:\t\t\t * between ports, or sending HSR supervision to RedBox.\n 610:\t\t\t */\n 611:\t\t\tif (hsr-\u003eproto_ops-\u003edrop_frame \u0026\u0026\n 612:\t\t\t hsr-\u003eproto_ops-\u003edrop_frame(frame, port))\n 613:\t\t\t\tcontinue;\n 614:\t\n 615:\t\t\tif (port-\u003etype == HSR_PT_SLAVE_A ||\n 616:\t\t\t port-\u003etype == HSR_PT_SLAVE_B)\n 617:\t\t\t\tskb = hsr-\u003eproto_ops-\u003ecreate_tagged_frame(frame, port);\n 618:\t\t\telse\n 619:\t\t\t\tskb = hsr-\u003eproto_ops-\u003eget_untagged_frame(frame, port);\n 620:\t\n 621:\tinject_into_stack:\n 622:\t\t\tif (!skb) {\n 623:\t\t\t\tframe-\u003eport_rcv-\u003edev-\u003estats.rx_dropped++;\n 624:\t\t\t\tcontinue;\n 625:\t\t\t}\n 626:\t\n 627:\t\t\tskb-\u003edev = port-\u003edev;\n 628:\t\t\tif (port-\u003etype == HSR_PT_MASTER) {\n 629:\t\t\t\thsr_deliver_master(skb, port-\u003edev, frame-\u003enode_src);\n 630:\t\t\t} else {\n 631:\t\t\t\tif (!hsr_xmit(skb, port, frame))\n 632:\t\t\t\t\tif (port-\u003etype == HSR_PT_SLAVE_A ||\n 633:\t\t\t\t\t port-\u003etype == HSR_PT_SLAVE_B)\n 634:\t\t\t\t\t\tsent = true;\n"
} |
| 39/3 | 2026/11/25 10:04 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28579 output: 39 thoughts: 50 Thoughts: Okay, let's dive into this `hsr_xmit` function. I'm going to take a look at the code execution path. **Analyzing the Next Steps in `hsr_xmit`** Alright, I'm heading into the `hsr_forward.c` file and zeroing in on lines 425 through 450 of `hsr_xmit`. I need to get a clear picture of what's happening at this specific point. My expertise allows me to quickly identify relevant variables and control flow. I'm going to look for the key decision points and data manipulations within this section of code. I'll mentally map out the logic, considering possible branching and error handling. I want to build a complete picture of the next steps. I'm going to assess whether the code is optimal and what improvements can be made. |
| 40/3 | 2026/11/25 10:06 | tool | read-file |
0mArgs:{
"File": "net/hsr/hsr_forward.c",
"FirstLine": 425,
"LineCount": 30
}Results: {
"Contents": " 425:\t\t\tif (was_multicast_frame)\n 426:\t\t\t\tdev-\u003estats.multicast++;\n 427:\t\t}\n 428:\t}\n 429:\t\n 430:\tstatic int hsr_xmit(struct sk_buff *skb, struct hsr_port *port,\n 431:\t\t\t struct hsr_frame_info *frame)\n 432:\t{\n 433:\t\tif (frame-\u003eport_rcv-\u003etype == HSR_PT_MASTER \u0026\u0026 !frame-\u003ehas_hsr_header) {\n 434:\t\t\thsr_addr_subst_dest(frame-\u003enode_src, skb, port);\n 435:\t\n 436:\t\t\t/* Address substitution (IEC62439-3 pp 26, 50): replace mac\n 437:\t\t\t * address of outgoing frame with that of the outgoing slave's.\n 438:\t\t\t */\n 439:\t\t\tether_addr_copy(eth_hdr(skb)-\u003eh_source, port-\u003edev-\u003edev_addr);\n 440:\t\t}\n 441:\t\n 442:\t\t/* When HSR node is used as RedBox - the frame received from HSR ring\n 443:\t\t * requires source MAC address (SA) replacement to one which can be\n 444:\t\t * recognized by SAN devices (otherwise, frames are dropped by switch)\n 445:\t\t */\n 446:\t\tif (port-\u003etype == HSR_PT_INTERLINK)\n 447:\t\t\tether_addr_copy(eth_hdr(skb)-\u003eh_source,\n 448:\t\t\t\t\tport-\u003ehsr-\u003emacaddress_redbox);\n 449:\t\n 450:\t\treturn dev_queue_xmit(skb);\n 451:\t}\n 452:\t\n 453:\tstatic bool prp_is_lan_dup(enum hsr_port_type rx, struct hsr_port *port)\n 454:\t{\n"
} |
| 41/3 | 2026/11/25 10:06 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29373 output: 23 thoughts: 736 Thoughts: **Analyzing HSR Frame Handling** Okay, let's break down this HSR frame transmission logic. I'm focusing on how frames are tagged and transmitted within this HSR implementation. First, I'm examining `hsr_xmit`. The key here seems to be conditional access to `frame->node_src` depending on the `has_hsr_header` flag. If a frame *doesn't* have an HSR header, and it's a master port, then `frame->node_src` is used. However, if the header *is* present, `frame->node_src` is *not* accessed. Considering `hsr_get_node` might have been skipped, this could mean `frame->node_src` might be uninitialized (likely NULL). This access seems potentially problematic in the absence of the header. Then the frame is passed on to `dev_queue_xmit`. Now, moving on to `hsr_create_tagged_frame`. The function takes a `hsr_frame_info` structure and a `hsr_port`. If there's an existing `skb_hsr`, it clones this SKB, and then appropriately sets the path ID. If there isn't, it clones the `skb_std`. After cloning, it sets the owner if the `req_tx_port` is not none. If the hardware can insert tags, it just returns the SKB as is. Otherwise, the code ensures there's enough headroom for the HSR tag. I see the function is trying to move header data using `skb_postpush_data_move`. This is where I want to look into further. The code makes moves to push and move the required data. The function also calls `hsr_fill_tag`. If any error occurs, then the SKB is freed, and NULL is returned. I'm now interested in understanding what `skb_postpush_data_move` does exactly, as it seems crucial to correctly prepending the HSR tag. I'm going to look for implementations of this function! |
| 42/3 | 2026/11/25 10:07 | tool | grepper |
0mArgs:{
"Expression": "skb_postpush_data_move"
}Results: {
"Output": "include/linux/if_vlan.h=361=static inline int __vlan_insert_inner_tag(struct sk_buff *skb,\n--\ninclude/linux/if_vlan.h-377-\tif (likely(mac_len \u003e ETH_TLEN))\ninclude/linux/if_vlan.h:378:\t\tskb_postpush_data_move(skb, VLAN_HLEN, mac_len - ETH_TLEN);\ninclude/linux/if_vlan.h-379-\tif (skb_mac_header_was_set(skb))\n--\ninclude/linux/skbuff.h=4629=static inline void skb_metadata_clear(struct sk_buff *skb)\n--\ninclude/linux/skbuff.h-4645- *\ninclude/linux/skbuff.h:4646: * Prefer skb_postpull_data_move() or skb_postpush_data_move() to calling this\ninclude/linux/skbuff.h-4647- * helper directly.\n--\ninclude/linux/skbuff.h=4685=static inline void skb_postpull_data_move(struct sk_buff *skb,\n--\ninclude/linux/skbuff.h-4693-/**\ninclude/linux/skbuff.h:4694: * skb_postpush_data_move - Move packet data and metadata after skb_push().\ninclude/linux/skbuff.h-4695- * @skb: packet to operate on\n--\ninclude/linux/skbuff.h-4700- */\ninclude/linux/skbuff.h:4701:static inline void skb_postpush_data_move(struct sk_buff *skb,\ninclude/linux/skbuff.h-4702-\t\t\t\t\t const unsigned int len,\n--\nnet/core/filter.c=3370=static int bpf_skb_generic_push(struct sk_buff *skb, u32 off, u32 len)\n--\nnet/core/filter.c-3379-\tskb_push(skb, len);\nnet/core/filter.c:3380:\tskb_postpush_data_move(skb, len, off);\nnet/core/filter.c-3381-\tmemset(skb-\u003edata + off, 0, len);\n--\nnet/core/filter.c=4150=static inline int __bpf_skb_change_head(struct sk_buff *skb, u32 head_room,\n--\nnet/core/filter.c-4174-\t\t__skb_push(skb, head_room);\nnet/core/filter.c:4175:\t\tskb_postpush_data_move(skb, head_room, 0);\nnet/core/filter.c-4176-\t\tmemset(skb-\u003edata, 0, head_room);\n--\nnet/core/skbuff.c=2284=EXPORT_SYMBOL(__pskb_copy_fclone);\n--\nnet/core/skbuff.c-2301- *\tNote: If you skb_push() the start of the buffer after reallocating the\nnet/core/skbuff.c:2302: *\theader, call skb_postpush_data_move() first to move the metadata out of\nnet/core/skbuff.c-2303- *\tthe way before writing to \u0026sk_buff-\u003edata.\n--\nnet/hsr/hsr_forward.c=332=struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,\n--\nnet/hsr/hsr_forward.c-369-\tskb_push(skb, HSR_HLEN);\nnet/hsr/hsr_forward.c:370:\tskb_postpush_data_move(skb, HSR_HLEN, movelen);\nnet/hsr/hsr_forward.c-371-\tskb_set_network_header(skb, HSR_HLEN + movelen);\n"
} |
| 43/3 | 2026/11/25 10:07 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31608 output: 37 thoughts: 45 Thoughts: Here's my summary, as if I were thinking it: **Diving into `skb_postpush_data_move`** Alright, let's get down to brass tacks and dissect this `skb_postpush_data_move` function. I'm heading straight to `include/linux/skbuff.h` – that's where the magic should be. I'm focusing on lines 4690 through 4725. This should give me a solid understanding of how it moves data within the sk_buff structure after pushing data onto it. I'm especially interested in how it handles memory allocation, potential alignment issues, and if it interacts with any of the packet's metadata. I need to understand this to make sure my networking code is optimal. |
| 44/3 | 2026/11/25 10:07 | tool | read-file |
0mArgs:{
"File": "include/linux/skbuff.h",
"FirstLine": 4690,
"LineCount": 35
}Results: {
"Contents": "4690:\t\tskb_data_move(skb, len, n);\n4691:\t}\n4692:\t\n4693:\t/**\n4694:\t * skb_postpush_data_move - Move packet data and metadata after skb_push().\n4695:\t * @skb: packet to operate on\n4696:\t * @len: number of bytes pushed onto \u0026sk_buff-\u003edata\n4697:\t * @n: number of bytes to memmove() from pre-push \u0026sk_buff-\u003edata\n4698:\t *\n4699:\t * See skb_data_move() for details.\n4700:\t */\n4701:\tstatic inline void skb_postpush_data_move(struct sk_buff *skb,\n4702:\t\t\t\t\t\t const unsigned int len,\n4703:\t\t\t\t\t\t const unsigned int n)\n4704:\t{\n4705:\t\tDEBUG_NET_WARN_ON_ONCE(len \u003e INT_MAX);\n4706:\t\tskb_data_move(skb, -len, n);\n4707:\t}\n4708:\t\n4709:\tstruct sk_buff *skb_clone_sk(struct sk_buff *skb);\n4710:\t\n4711:\t#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING\n4712:\t\n4713:\tvoid skb_clone_tx_timestamp(struct sk_buff *skb);\n4714:\tbool skb_defer_rx_timestamp(struct sk_buff *skb);\n4715:\t\n4716:\t#else /* CONFIG_NETWORK_PHY_TIMESTAMPING */\n4717:\t\n4718:\tstatic inline void skb_clone_tx_timestamp(struct sk_buff *skb)\n4719:\t{\n4720:\t}\n4721:\t\n4722:\tstatic inline bool skb_defer_rx_timestamp(struct sk_buff *skb)\n4723:\t{\n4724:\t\treturn false;\n"
} |
| 45/3 | 2026/11/25 10:07 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32406 output: 39 thoughts: 50 Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue: **Investigating `hsr_fill_tag` in the HSR Forwarding Path** Right, let's take a look at `hsr_fill_tag`. I know that name...it's connected to the High-availability Seamless Redundancy (HSR) forwarding logic, probably in the tagging stage. Specifically, I'm thinking I need to refresh my memory on how this tag gets populated. I'll need to dig into the code itself, likely in `net/hsr/hsr_forward.c`. I'm going to start by examining the code around lines 285 to 330. That should give me a good initial view of how the tagging mechanism works and what inputs are needed. I'm hoping I can refresh my understanding of the HSR process and how the tags get filled in. |
| 46/3 | 2026/11/25 10:09 | tool | read-file |
0mArgs:{
"File": "net/hsr/hsr_forward.c",
"FirstLine": 285,
"LineCount": 45
}Results: {
"Contents": " 285:\t\n 286:\t\tset_hsr_tag_path(\u0026hsr_ethhdr-\u003ehsr_tag, path_id);\n 287:\t}\n 288:\t\n 289:\tstatic struct sk_buff *hsr_fill_tag(struct sk_buff *skb,\n 290:\t\t\t\t\t struct hsr_frame_info *frame,\n 291:\t\t\t\t\t struct hsr_port *port, u8 proto_version)\n 292:\t{\n 293:\t\tstruct hsr_ethhdr *hsr_ethhdr;\n 294:\t\tunsigned char *pc;\n 295:\t\tint lsdu_size;\n 296:\t\n 297:\t\t/* pad to minimum packet size which is 60 + 6 (HSR tag) */\n 298:\t\tif (skb_put_padto(skb, ETH_ZLEN + HSR_HLEN))\n 299:\t\t\treturn NULL;\n 300:\t\n 301:\t\tlsdu_size = skb-\u003elen - 14;\n 302:\t\tif (frame-\u003eis_vlan)\n 303:\t\t\tlsdu_size -= 4;\n 304:\t\n 305:\t\tpc = skb_mac_header(skb);\n 306:\t\tif (frame-\u003eis_vlan)\n 307:\t\t\t/* This 4-byte shift (size of a vlan tag) does not\n 308:\t\t\t * mean that the ethhdr starts there. But rather it\n 309:\t\t\t * provides the proper environment for accessing\n 310:\t\t\t * the fields, such as hsr_tag etc., just like\n 311:\t\t\t * when the vlan tag is not there. This is because\n 312:\t\t\t * the hsr tag is after the vlan tag.\n 313:\t\t\t */\n 314:\t\t\thsr_ethhdr = (struct hsr_ethhdr *)(pc + VLAN_HLEN);\n 315:\t\telse\n 316:\t\t\thsr_ethhdr = (struct hsr_ethhdr *)pc;\n 317:\t\n 318:\t\thsr_set_path_id(frame, hsr_ethhdr, port);\n 319:\t\tset_hsr_tag_LSDU_size(\u0026hsr_ethhdr-\u003ehsr_tag, lsdu_size);\n 320:\t\thsr_ethhdr-\u003ehsr_tag.sequence_nr = htons(frame-\u003esequence_nr);\n 321:\t\thsr_ethhdr-\u003ehsr_tag.encap_proto = hsr_ethhdr-\u003eethhdr.h_proto;\n 322:\t\thsr_ethhdr-\u003eethhdr.h_proto = htons(proto_version ?\n 323:\t\t\t\tETH_P_HSR : ETH_P_PRP);\n 324:\t\tskb-\u003eprotocol = hsr_ethhdr-\u003eethhdr.h_proto;\n 325:\t\n 326:\t\treturn skb;\n 327:\t}\n 328:\t\n 329:\t/* If the original frame was an HSR tagged frame, just clone it to be sent\n"
} |
| 47/3 | 2026/11/25 10:09 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 33506 output: 35 thoughts: 3255 Thoughts: **Analyzing the KMSAN Needs:** Okay, so I'm diving deep into this patch to figure out if we need to set `NeedsKMSAN=true`. It seems we are dealing with HSR (High-availability Seamless Redundancy) and PTP (Precision Time Protocol) packet handling. The core question is whether this patch introduces any risks of reading uninitialized memory. First, I need to understand where this `hsr_inline_header` is coming from. It's userland, right? Userland is sending it into a socket, so it's providing this `hsr_inline_header` struct. Right, it's this struct: But wait! Is this structure ever *copied* from the kernel *to* userspace? If it's *not* copied to userspace, then there's no way for uninitialized data to leak back to userspace. I need to make *absolutely* sure. I'm searching the kernel code for `hsr_inline_header` and it looks like it is ONLY used internally. `BUILD_BUG_ON` checks the size of the structure. I see that it is read from incoming packets. It parses the magic number and the control bits. This happens in `hsr_ptp_parse_header` and the code checks that the inline header is read and stripped, pulling it from the SKB before the packet is sent. The PTP packets are dropped so they are not forwarded to the slaves, which would mess up time sync. Let's carefully verify. Now, I'm checking for ANY `copy_to_user`, `put_user`, netlink, ioctl operations, etc. to double check. Nope, nothing. This patch doesn't send *any* kernel structures to user space. It seems like the inline header is purely an internal control structure. Let's double check, I am looking at all of the modified files, just to be sure... I see that it includes changes to `include/linux/if_hsr.h`, but that's just a definition. Now, I'm going through the KMSAN criteria. 1. No kernel structures are being sent to user space. That's a huge relief. 2. I have to check for conditional logic that uses uninitialized variables. Let's look at `hsr_dev_xmit` and `hsr_ptp_parse_header`. The variables `req_tx_port` and `has_hsr_header` *are* initialized, so there's no issue there. The logic in `hsr_ptp_parse_header` seems safe. The `hsr_forward_skb` uses a `struct hsr_frame_info frame`, which is zeroed with `memset` before use, so even if `frame->has_hsr_header` is true, the `frame->node_src` remains NULL. Then later on the checks make sure we do not dereference `frame->node_src`. And even if `frame->node_src` *were* accidentally NULL, that would cause a standard null pointer dereference, which is already covered by KASAN. I don't see any "allocation of complex data structures" being touched, so condition 3 is also not relevant. Now, let's look at condition 4. This is important. It covers bounds checks, buffer lengths, or situations where code could read beyond the intended buffer. Let's look at `hsr_create_tagged_frame`. The old code was using `__pskb_copy`, which is a copy-on-write operation. The new code is using a combination of `skb_cow_head`, `pskb_may_pull`, `skb_push`, and `skb_postpush_data_move`. The code ensures there's enough headroom, pulls data, shifts it around. I need to check `skb_data_move` to make sure there are no out-of-bounds reads. I'm carefully reading the implementation of `skb_data_move` right now... It looks like `skb_data_move` is moving data within the SKB itself, so there are no uninitialized bytes being read. Okay, after this careful analysis, I'm confident that this patch doesn't introduce any KMSAN risks. The code only handles internal structures, all |
| 48/3 | 2026/11/25 10:10 | tool | grepper |
0mArgs:{
"Expression": "skb_data_move",
"PathPrefixes": [
"include/linux/skbuff.h"
]
}Results: {
"Output": "include/linux/skbuff.h=4629=static inline void skb_metadata_clear(struct sk_buff *skb)\n--\ninclude/linux/skbuff.h-4634-/**\ninclude/linux/skbuff.h:4635: * skb_data_move - Move packet data and metadata after skb_push() or skb_pull().\ninclude/linux/skbuff.h-4636- * @skb: packet to operate on\n--\ninclude/linux/skbuff.h-4648- */\ninclude/linux/skbuff.h:4649:static inline void skb_data_move(struct sk_buff *skb, const int len,\ninclude/linux/skbuff.h-4650-\t\t\t\t const unsigned int n)\n--\ninclude/linux/skbuff.h-4682- *\ninclude/linux/skbuff.h:4683: * See skb_data_move() for details.\ninclude/linux/skbuff.h-4684- */\ninclude/linux/skbuff.h=4685=static inline void skb_postpull_data_move(struct sk_buff *skb,\n--\ninclude/linux/skbuff.h-4689-\tDEBUG_NET_WARN_ON_ONCE(len \u003e INT_MAX);\ninclude/linux/skbuff.h:4690:\tskb_data_move(skb, len, n);\ninclude/linux/skbuff.h-4691-}\n--\ninclude/linux/skbuff.h-4698- *\ninclude/linux/skbuff.h:4699: * See skb_data_move() for details.\ninclude/linux/skbuff.h-4700- */\ninclude/linux/skbuff.h=4701=static inline void skb_postpush_data_move(struct sk_buff *skb,\n--\ninclude/linux/skbuff.h-4705-\tDEBUG_NET_WARN_ON_ONCE(len \u003e INT_MAX);\ninclude/linux/skbuff.h:4706:\tskb_data_move(skb, -len, n);\ninclude/linux/skbuff.h-4707-}\n"
} |
| 49/3 | 2026/11/25 10:10 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38296 output: 37 thoughts: 36 Thoughts: Okay, let's dive into this. Here's my take on those lines of code: **Analyzing `skb_data_move` in `skbuff.h`** Alright, I'm going to pull up `include/linux/skbuff.h` and specifically focus on lines 4648 through 4680, which, if memory serves, should contain the `skb_data_move` function. This is a critical utility. My initial thought is to refresh my understanding of how this handles data movement within the `skb` structure, specifically related to buffer management. I know this is a core piece for efficient networking. It's essentially about manipulating the data buffer within the socket buffer (`skb`) structure. I want to see how this function handles the physical memory relocation, and if there are considerations for DMA (Direct Memory Access). I'll also be looking for things like reference count handling and any locking mechanisms used to ensure data integrity during the move operation. Is this synchronous or asynchronous? Are there any potential performance bottlenecks I should be aware of? I anticipate this function being heavily optimized, given its performance-critical nature. I also want to observe if the function performs any memory alignment checks or adjustments; this is a common optimization to increase throughput. My understanding is that data movement is one of the most common reasons for latency. I need to refresh my knowledge of the mechanics here. I want to understand the boundary conditions and error handling embedded within this. |
| 50/3 | 2026/11/25 10:11 | tool | read-file |
0mArgs:{
"File": "include/linux/skbuff.h",
"FirstLine": 4648,
"LineCount": 35
}Results: {
"Contents": "4648:\t */\n4649:\tstatic inline void skb_data_move(struct sk_buff *skb, const int len,\n4650:\t\t\t\t\t const unsigned int n)\n4651:\t{\n4652:\t\tconst u8 meta_len = skb_metadata_len(skb);\n4653:\t\tu8 *meta, *meta_end;\n4654:\t\n4655:\t\tif (!len || (!n \u0026\u0026 !meta_len))\n4656:\t\t\treturn;\n4657:\t\n4658:\t\tif (!meta_len)\n4659:\t\t\tgoto no_metadata;\n4660:\t\n4661:\t\tmeta_end = skb_metadata_end(skb);\n4662:\t\tmeta = meta_end - meta_len;\n4663:\t\n4664:\t\tif (WARN_ON_ONCE(meta_end + len != skb-\u003edata ||\n4665:\t\t\t\t meta_len \u003e skb_headroom(skb))) {\n4666:\t\t\tskb_metadata_clear(skb);\n4667:\t\t\tgoto no_metadata;\n4668:\t\t}\n4669:\t\n4670:\t\tmemmove(meta + len, meta, meta_len + n);\n4671:\t\treturn;\n4672:\t\n4673:\tno_metadata:\n4674:\t\tmemmove(skb-\u003edata, skb-\u003edata - len, n);\n4675:\t}\n4676:\t\n4677:\t/**\n4678:\t * skb_postpull_data_move - Move packet data and metadata after skb_pull().\n4679:\t * @skb: packet to operate on\n4680:\t * @len: number of bytes pulled from \u0026sk_buff-\u003edata\n4681:\t * @n: number of bytes to memmove() from pre-pull \u0026sk_buff-\u003edata\n4682:\t *\n"
} |
| 51/3 | 2026/11/25 10:11 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39200 output: 39 thoughts: 3736 Thoughts: **Deep Dive into HSR Frame Handling** Okay, let's break this down. My initial observation focuses on the intricacies of how HSR frames are constructed and handled within the kernel, particularly when dealing with the insertion and handling of the HSR header itself. I started by looking at how `memmove` is used to manipulate packet data. I've tracked how the `skb->data` pointer and other buffer management functions like `skb_push` are used to manage the header, and I've traced the logic through several functions and code paths. The manipulation of the data buffers with `skb_push`, and the data copy with `memmove`, and related functions are used to prep the data and copy the data around. There seems to be an important relationship between the source and destination addresses as well. I need to make sure I understand the shifting of data within the skb. It's crucial to understand that `skb_push` changes `skb->data`, but `skb_mac_header(skb)` points to the start of the MAC header. In the original code, `src` pointed to old data and `dst` pointed to new data, and `memmove(dst, src, movelen)` copied the Ethernet header. The `hsr_fill_tag` function is important for constructing the HSR header. It writes the HSR-specific fields into the `hsr_tag` struct, which is embedded within an `hsr_ethhdr`. I must make sure that it populates the correct fields, and fills the tag correctly. I need to keep in mind the offsets within the HSR header structure. Next, I looked at how the cloning of packets and the reallocation of headroom are handled. I see that the new `skb_cow_head` is introduced to reallocate headroom. This seems better than the old `__pskb_copy` method. The `hsr_forward_do` function has critical logic about whether to forward the frame or not. If a frame *already* has an HSR header (`frame->has_hsr_header` is true), the code clones the `skb` and skips adding a new one. This part is clear. The focus then shifts to the `hsr_ptp_parse_header` function. This function analyzes an incoming frame. It determines whether an HSR inline header is present. If so, it extracts information about the requested transmit port and whether an HSR header is included. If the packet *does* have the HSR header, then the `hdr_len` is `ETH_HLEN + HSR_HLEN`. If not, `hdr_len` is `ETH_HLEN`. I've discovered the `skb->protocol` is set to `ETH_P_HSR` when an HSR inline header is present. The test program sets the destination and source MAC, and the type field to `ETH_P_HSR`. Then in `hsr_dev_xmit`, the function skips some address substitution and calls `dev_queue_xmit(skb)`. This code path makes sense if `has_hsr_header` is true. Finally, I checked what happens when `has_hsr_header` is false. In this scenario, the regular Ethernet header is handled, and standard Ethernet protocols are used. |
| 52/3 | 2026/11/25 10:11 | tool | read-file |
0mArgs:{
"File": "net/hsr/hsr_forward.c",
"FirstLine": 655,
"LineCount": 26
}Results: {
"Contents": " 655:\t\t}\n 656:\t}\n 657:\t\n 658:\tstatic void handle_std_frame(struct sk_buff *skb,\n 659:\t\t\t\t struct hsr_frame_info *frame)\n 660:\t{\n 661:\t\tstruct hsr_port *port = frame-\u003eport_rcv;\n 662:\t\tstruct hsr_priv *hsr = port-\u003ehsr;\n 663:\t\n 664:\t\tframe-\u003eskb_hsr = NULL;\n 665:\t\tframe-\u003eskb_prp = NULL;\n 666:\t\tframe-\u003eskb_std = skb;\n 667:\t\n 668:\t\tif (port-\u003etype != HSR_PT_MASTER)\n 669:\t\t\tframe-\u003eis_from_san = true;\n 670:\t\n 671:\t\tif (port-\u003etype == HSR_PT_MASTER ||\n 672:\t\t port-\u003etype == HSR_PT_INTERLINK) {\n 673:\t\t\t/* Sequence nr for the master/interlink node */\n 674:\t\t\tlockdep_assert_held(\u0026hsr-\u003eseqnr_lock);\n 675:\t\t\tframe-\u003esequence_nr = hsr-\u003esequence_nr;\n 676:\t\t\tWRITE_ONCE(hsr-\u003esequence_nr, hsr-\u003esequence_nr + 1);\n 677:\t\t}\n 678:\t}\n 679:\t\n 680:\tint hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,\n"
} |
| 53/3 | 2026/11/25 10:11 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 44113 output: 38 thoughts: 1362 Thoughts: **Analyzing HSR and PRP Frame Handling** Okay, let's break this down. First, `handle_std_frame` sets the `sequence_nr` of the frame to the HSR's current sequence number and increments the HSR's sequence counter. Then, `hsr_forward_do` filters frames based on their requested transmit port. If the port doesn't match, we `continue`. For matching ports, the `frame->has_hsr_header` flag is false. It then calls `create_tagged_frame`. Within `hsr_create_tagged_frame`, the standard procedure is to clone the SKB, set its owner, and then push the HSR header, filling it with the tag. Finally, `hsr_xmit` sends it via `dev_queue_xmit`. But here's a wrinkle: what if the port's device has `NETIF_F_HW_HSR_TAG_INS` set? In that scenario, `hsr_create_tagged_frame` *just* clones the SKB and returns it. No header manipulation, just a copy. This is because hardware is inserting the tag, so the driver doesn't need to do it. Now, let's consider PRP. If PRP is in play instead of HSR, the `hsr_dev_xmit` function's check for protocol type becomes relevant. If the SKB's protocol is Ethernet PTP (ETH_P_1588), `hsr_ptp_parse_header` is called. Critically, if it's PRP, then `prp_fill_frame_info` becomes the function handling the frame info filling. This makes me consider if there is a problem with the `frame->has_hsr_header` flag in this case. After looking at `prp_fill_frame_info`, it doesn't appear to use `frame->has_hsr_header`. I needed to check what it does with the `frame` structure. Looking at the code for that function, if there's an RCT (Redundancy Control Trailer), it handles it separately. Otherwise, it calls `handle_std_frame`. Importantly, `handle_std_frame` correctly sets `skb_std` and initializes the sequence number. So there is no possibility of uninitialized memory being read. Finally, checking `hsr_slave.c`: the code explicitly prevents PTP packets from being forwarded over HSR. If the protocol is PRP or HSR, it checks for a PTP encapsulated packet and, if found, it skips the frame. I need to make sure `pskb_may_pull` succeeds before checking `hsr_ethhdr->hsr_tag.encap_proto`. It does. The protocol value is passed to the called functions, so there are no strange sources of that variable. Alright, that covers the essentials. |
| 54/3 | 2026/11/25 10:12 | tool | read-file |
0mArgs:{
"File": "net/hsr/hsr_slave.c",
"FirstLine": 20,
"LineCount": 55
}Results: {
"Contents": " 20:\t{\n 21:\t\treturn (protocol != htons(ETH_P_PRP) \u0026\u0026 protocol != htons(ETH_P_HSR));\n 22:\t}\n 23:\t\n 24:\tstatic rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)\n 25:\t{\n 26:\t\tstruct hsr_ethhdr *hsr_ethhdr;\n 27:\t\tstruct sk_buff *skb = *pskb;\n 28:\t\tstruct hsr_port *port;\n 29:\t\tstruct hsr_priv *hsr;\n 30:\t\t__be16 protocol;\n 31:\t\n 32:\t\t/* Packets from dev_loopback_xmit() do not have L2 header, bail out */\n 33:\t\tif (unlikely(skb-\u003epkt_type == PACKET_LOOPBACK))\n 34:\t\t\treturn RX_HANDLER_PASS;\n 35:\t\n 36:\t\tif (!skb_mac_header_was_set(skb)) {\n 37:\t\t\tWARN_ONCE(1, \"%s: skb invalid\", __func__);\n 38:\t\t\treturn RX_HANDLER_PASS;\n 39:\t\t}\n 40:\t\n 41:\t\tport = hsr_port_get_rcu(skb-\u003edev);\n 42:\t\tif (!port)\n 43:\t\t\tgoto finish_pass;\n 44:\t\thsr = port-\u003ehsr;\n 45:\t\n 46:\t\tif (hsr_addr_is_self(port-\u003ehsr, eth_hdr(skb)-\u003eh_source)) {\n 47:\t\t\t/* Directly kill frames sent by ourselves */\n 48:\t\t\tgoto finish_free_consume;\n 49:\t\t}\n 50:\t\n 51:\t\t/* For HSR, only tagged frames are expected (unless the device offloads\n 52:\t\t * HSR tag removal), but for PRP there could be non tagged frames as\n 53:\t\t * well from Single attached nodes (SANs).\n 54:\t\t */\n 55:\t\tprotocol = eth_hdr(skb)-\u003eh_proto;\n 56:\t\n 57:\t\tif (!(port-\u003edev-\u003efeatures \u0026 NETIF_F_HW_HSR_TAG_RM) \u0026\u0026\n 58:\t\t port-\u003etype != HSR_PT_INTERLINK \u0026\u0026\n 59:\t\t hsr-\u003eproto_ops-\u003einvalid_dan_ingress_frame \u0026\u0026\n 60:\t\t hsr-\u003eproto_ops-\u003einvalid_dan_ingress_frame(protocol))\n 61:\t\t\tgoto finish_pass;\n 62:\t\n 63:\t\tskb_push(skb, ETH_HLEN);\n 64:\t\tskb_reset_mac_header(skb);\n 65:\t\tif ((!hsr-\u003eprot_version \u0026\u0026 protocol == htons(ETH_P_PRP)) ||\n 66:\t\t protocol == htons(ETH_P_HSR)) {\n 67:\t\t\tif (!pskb_may_pull(skb, ETH_HLEN + HSR_HLEN))\n 68:\t\t\t\tgoto finish_free_consume;\n 69:\t\n 70:\t\t\tskb_set_network_header(skb, ETH_HLEN + HSR_HLEN);\n 71:\t\t}\n 72:\t\tskb_reset_mac_len(skb);\n 73:\t\n 74:\t\t/* PTP packets are not supposed to be forwarded via HSR as-is. The\n"
} |
| 55/3 | 2026/11/25 10:12 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 47027 output: 21 thoughts: 474 Thoughts: **Analyzing Potential Vulnerabilities in the HSR Slave Driver** Okay, let's break this down systematically. I'm looking at the `hsr_slave.c` code and trying to assess potential issues. My initial focus is on how the driver handles Ethernet frames, particularly those with HSR or PRP tagging, and how it deals with PTP (Precision Time Protocol) packets. First, I see the code retrieves the Ethernet protocol type using `eth_hdr(skb)->h_proto`. It then checks if enough data is present in the SKB (Socket Buffer) with `pskb_may_pull(skb, ETH_HLEN + HSR_HLEN)`. The logic branches based on whether the frame is an HSR/PRP frame or a plain PTP frame. If it's *not* an HSR/PRP frame, and the protocol is `ETH_P_1588`, it jumps to `finish_free_consume`, effectively dropping the packet. My immediate thought is: is there an unhandled case, or could we see an out-of-bounds read here? Ah, but it seems there's a safety check: `pskb_may_pull(skb, ETH_HLEN)` has been done before that point in the code. Because `skb_push(skb, ETH_HLEN);` was done, `skb->data` is pointing correctly. So, all data accesses should be within the bounds of the pulled data. The only risk would be an out-of-bounds access, which would trigger KASAN, not uninitialized memory. That's a reasonable safeguard. Next, I'm thinking about the *inline header* (`struct hsr_inline_header`). The crucial question is: is this structure or parts of it ever copied to userspace? That's where a lot of these vulnerabilities tend to lie. The answer here is that it's important to look at the `hsr_header_ops` structure. In this, the `parse_protocol` field is defined. I need to understand what this `eth_header_parse_protocol` function does. Let me grep for this function to understand where it is used. I'll need to analyze that code carefully to see if any of the header data is being leaked. |
| 56/3 | 2026/11/25 10:13 | tool | grepper |
0mArgs:{
"Expression": "eth_header_parse_protocol"
}Results: {
"Output": "drivers/net/ethernet/stmicro/stmmac/stmmac_main.c=4822=static bool stmmac_has_ip_ethertype(struct sk_buff *skb)\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-4826-\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:4827:\tproto = __vlan_get_protocol(skb, eth_header_parse_protocol(skb),\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-4828-\t\t\t\t \u0026depth);\n--\ndrivers/net/ipvlan/ipvlan_main.c=443=static const struct header_ops ipvlan_header_ops = {\n--\ndrivers/net/ipvlan/ipvlan_main.c-447-\t.cache_update\t= eth_header_cache_update,\ndrivers/net/ipvlan/ipvlan_main.c:448:\t.parse_protocol\t= eth_header_parse_protocol,\ndrivers/net/ipvlan/ipvlan_main.c-449-};\n--\ndrivers/net/macvlan.c=626=static const struct header_ops macvlan_hard_header_ops = {\n--\ndrivers/net/macvlan.c-630-\t.cache_update\t= eth_header_cache_update,\ndrivers/net/macvlan.c:631:\t.parse_protocol\t= eth_header_parse_protocol,\ndrivers/net/macvlan.c-632-};\n--\ninclude/linux/etherdevice.h=77=void eth_header_cache_update(struct hh_cache *hh, const struct net_device *dev,\ninclude/linux/etherdevice.h-78-\t\t\t const unsigned char *haddr);\ninclude/linux/etherdevice.h:79:__be16 eth_header_parse_protocol(const struct sk_buff *skb);\ninclude/linux/etherdevice.h-80-int eth_prepare_mac_addr_change(struct net_device *dev, void *p);\n--\nnet/ethernet/eth.c=239=EXPORT_SYMBOL(eth_header_cache_update);\n--\nnet/ethernet/eth.c-241-/**\nnet/ethernet/eth.c:242: * eth_header_parse_protocol - extract protocol from L2 header\nnet/ethernet/eth.c-243- * @skb: packet to extract protocol from\nnet/ethernet/eth.c-244- */\nnet/ethernet/eth.c:245:__be16 eth_header_parse_protocol(const struct sk_buff *skb)\nnet/ethernet/eth.c-246-{\n--\nnet/ethernet/eth.c-250-}\nnet/ethernet/eth.c:251:EXPORT_SYMBOL(eth_header_parse_protocol);\nnet/ethernet/eth.c-252-\n--\nnet/ethernet/eth.c=314=const struct header_ops eth_header_ops ____cacheline_aligned = {\n--\nnet/ethernet/eth.c-318-\t.cache_update\t= eth_header_cache_update,\nnet/ethernet/eth.c:319:\t.parse_protocol\t= eth_header_parse_protocol,\nnet/ethernet/eth.c-320-};\n--\nnet/hsr/hsr_device.c=301=static const struct header_ops hsr_header_ops = {\n--\nnet/hsr/hsr_device.c-303-\t.parse\t = eth_header_parse,\nnet/hsr/hsr_device.c:304:\t.parse_protocol = eth_header_parse_protocol,\nnet/hsr/hsr_device.c-305-};\n"
} |
| 57/3 | 2026/11/25 10:13 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 48998 output: 438 thoughts: 2827 Thoughts: **Analysis of HSR Patch for Potential Uninitialized Memory Issues** Okay, let's break this down. My initial thought was about how `eth_header_parse_protocol` works, which is just a standard extraction of the protocol from the MAC header. Then I started tracing the path of a user packet into `hsr_dev_xmit`. The main concern here is how the user-provided protocol, specifically `ETH_P_1588` enters the system. It appears that `ETH_P_1588` is set during transmission with `socket(AF_PACKET, SOCK_RAW, ...)` or `sendto(...)`, or potentially via `parse_protocol`. This then triggers the inline header parsing within `hsr_dev_xmit` if `skb->protocol` matches `ETH_P_1588`. Now, the `hsr_ptp_parse_header` function looks interesting. It essentially checks for a "magic" value in the `hsr_inline_header`, extracts control flags (`has_hsr_header`, `req_tx_port`), validates those flags, and discards the inline header by pulling it from the packet. The most important thing here is that the inline header *is* discarded, it does not leak to the user space. This is done through `skb_pull`. Let's look more closely at the inline header itself: its size is checked, and then `pskb_may_pull` ensures that the data is within the linear buffer. The structure's definition and size check confirm that we're dealing with a fixed, well-defined amount of data to be removed from the packet. The important thing is that `skb_pull` is happening and is discarding this data from the packet. No data is being copied, just removed. Next, I need to check the rest of the packet processing path. `hsr_fill_tag` writes to the HSR tag, and it seems like all its bytes are overwritten. The HSR tag itself is 6 bytes, comprising `path_and_LSDU_size`, `sequence_nr`, and `encap_proto`, which are all explicitly populated. Further, there is also the call to `skb_put_padto`, which if the packet is shorter than `ETH_ZLEN + HSR_HLEN`, pads it with zeroes. So there is no possibility of uninitialized memory. Then let's make sure `frame.node_src` is safe. I see that `fill_frame_info`, used by `hsr_forward_skb`, calls `memset(frame, 0, sizeof(*frame));` at the beginning. This initialization ensures that `frame` is fully initialized before use. I also checked the `MAINTAINERS` change and selftests, etc. – not relevant to this analysis. Looking at the other changed files, all local variables are assigned before use and no uninitialized structs are being leaked. No memory allocations from the kernel's perspective are going on that are relevant. There aren't any kernel to user copies in either direction. Most importantly, I've confirmed that `pskb_may_pull` is being correctly used, which protects the integrity of the data within the `skb` and prevents reading out of bounds. Now, let's review the KMSAN guidelines. There are no new or modified data paths copying kernel memory to user space. All variables are initialized, structures are zeroed, and bounds checks are present. No risks of uninitialized memory usage or info leaks. The changes touch upon out-of-bounds access, which will be detected by KASAN. So, in conclusion, this patch is safe. No KMSAN is needed, and KASAN should handle any boundary issues. |
| 58/3 | 2026/11/25 10:13 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series implements PTP (Precision Time Protocol / IEEE 1588) support for HSR (High-availability Seamless Redundancy) networks by introducing an inline header (`struct hsr_inline_header`) parsed during packet transmission, handling port steering, and avoiding improper PTP forwarding in slave ingress.\n\nKMSAN vs KASAN Applicability Analysis:\n1. No uninitialized memory leaks to userspace: The patch does not add or modify any data structures sent to userspace (`copy_to_user`, `put_user`, Netlink attributes, ioctl returns, socket options, or BPF buffers). The newly added UAPI header defines `struct hsr_inline_header`, which is received from userspace (via raw/packet sockets) and parsed/stripped by the kernel before network transmission; it is never copied back to user space.\n2. Fully initialized stack and heap structures: In `hsr_dev_xmit`, local variables `req_tx_port` and `has_hsr_header` are explicitly initialized. In `fill_frame_info`, the `struct hsr_frame_info` buffer is completely zero-initialized via `memset(frame, 0, sizeof(*frame))` prior to assigning fields.\n3. Packet manipulation and bounds checking: Packet header manipulations (pulling inline headers with `skb_pull`, adjusting headroom with `skb_cow_head`, moving data with `skb_postpush_data_move`, and reading Ethernet/HSR headers) are guarded by `pskb_may_pull` checks. Any potential bounds violations, buffer overreads/overwrites, or use-after-free bugs on cloned skbs are classical memory safety issues that are fully covered by standard KASAN and debug builds.\n\nBecause there are no uninitialized memory usage risks or kernel-to-user info-leak vectors introduced by this patch series, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series implements PTP (Precision Time Protocol / IEEE 1588) support for HSR (High-availability Seamless Redundancy) networks by introducing an inline header (`struct hsr_inline_header`) parsed during packet transmission, handling port steering, and avoiding improper PTP forwarding in slave ingress.\n\nKMSAN vs KASAN Applicability Analysis:\n1. No uninitialized memory leaks to userspace: The patch does not add or modify any data structures sent to userspace (`copy_to_user`, `put_user`, Netlink attributes, ioctl returns, socket options, or BPF buffers). The newly added UAPI header defines `struct hsr_inline_header`, which is received from userspace (via raw/packet sockets) and parsed/stripped by the kernel before network transmission; it is never copied back to user space.\n2. Fully initialized stack and heap structures: In `hsr_dev_xmit`, local variables `req_tx_port` and `has_hsr_header` are explicitly initialized. In `fill_frame_info`, the `struct hsr_frame_info` buffer is completely zero-initialized via `memset(frame, 0, sizeof(*frame))` prior to assigning fields.\n3. Packet manipulation and bounds checking: Packet header manipulations (pulling inline headers with `skb_pull`, adjusting headroom with `skb_cow_head`, moving data with `skb_postpush_data_move`, and reading Ethernet/HSR headers) are guarded by `pskb_may_pull` checks. Any potential bounds violations, buffer overreads/overwrites, or use-after-free bugs on cloned skbs are classical memory safety issues that are fully covered by standard KASAN and debug builds.\n\nBecause there are no uninitialized memory usage risks or kernel-to-user info-leak vectors introduced by this patch series, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|