bpf: Support RX/TX HW timestamp proxy.
Subsystems (10)
cover bpf: Support RX/TX HW timestamp proxy.
We have some hosts where packets come from special hardware and are provided directly to userspace, bypassing the kernel networking stack.
When standard socket applications are run on these hosts, a userspace proxy is required to mediate traffic between the hardware and the applications.
+---------+ +----------------------+
| proxy | | socket application |
+---------+ +----------------------+
^ ^ ^
userspace | | |
-----------| |-----------------------------------------------
| | | +---------------------+ | skb
| | `--->| virtual interface |<---'
kernel | | skb +---------------------+
-----------| |-----------------------------------------------
|
v
+------------+
| hardware |
+------------+However, even though the hardware fully supports timestamping, the HW timestamps are not directly accessible to the socket applications because the skb is consumed/injected by the proxy.
This series extends ethtool and adds BPF kfuncs to transparently support HW timestamp on such a setup.
Patch 1 is pure net-next patch to advertise fake timestamping capability on virtual interfaces (e.g. ipvlan, geneve, etc).
Patch 2 is misc cleanup.
Patch 3 & 4 add kfunc to proxy RX/TX hwtstamp.
Patch 5 is selftest to demonstrate how it works.
Note the test requires this iproute2 commit:
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=c9a9f12aa619288fd3d4e16bc4b3c73b655a4efe
Kuniyuki Iwashima (5):
ethtool: Introduce ETHTOOL_MSG_TSINFO_SET for virtual interfaces.
bpf: Rename bpf_kfunc_set_tcp_reqsk to bpf_kfunc_set_sched_cls.
bpf: Add bpf_skb_set_hwtstamp().
bpf: Add kfunc to proxy TX HW Timestamp.
selftest: bpf: Add test for hwtstamp proxy.
Documentation/netlink/specs/ethtool.yaml | 13 + include/linux/filter.h | 2 + include/linux/netdevice.h | 11 + include/linux/skbuff.h | 13 + include/net/tcx.h | 1 + include/uapi/linux/bpf.h | 1 + .../uapi/linux/ethtool_netlink_generated.h | 1 + include/uapi/linux/pkt_cls.h | 3 +- kernel/bpf/verifier.c | 13 +- net/core/dev.c | 39 ++ net/core/dev_ioctl.c | 31 +- net/core/filter.c | 91 ++- net/ethtool/common.c | 4 + net/ethtool/netlink.c | 8 + net/ethtool/netlink.h | 1 + net/ethtool/tsconfig.c | 7 +- net/ethtool/tsinfo.c | 123 +++- tools/testing/selftests/bpf/bpf_kfuncs.h | 10 + .../selftests/bpf/prog_tests/proxy_hwtstamp.c | 580 ++++++++++++++++++ .../selftests/bpf/progs/bpf_tracing_net.h | 1 + .../selftests/bpf/progs/proxy_hwtstamp.c | 234 +++++++ 21 files changed, 1169 insertions(+), 18 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c create mode 100644 tools/testing/selftests/bpf/progs/proxy_hwtstamp.c
Signature · 1 line
2.54.0.1136.gdb2ca164c4-goog
PATCH 1/5 ethtool: Introduce ETHTOOL_MSG_TSINFO_SET for virtual interfaces.
Before enabling SO_TIMESTAMPING, applications typically try to enable hardware timestamping on network interfaces via SIOCSHWTSTAMP (or ETHTOOL_MSG_TSCONFIG_SET).
The timestamping capability on an interface can be checked via ETHTOOL_MSG_TSINFO_GET:
# ethtool -T eth0 Time stamping parameters for eth0: Capabilities: hardware-transmit software-transmit hardware-receive software-receive software-system-clock hardware-raw-clock PTP Hardware Clock: none Hardware Transmit Timestamp Modes: off on Hardware Receive Filter Modes: none all
These operations rely on the driver implementing two callbacks, dev->netdev_ops->ndo_hwtstamp_{get,set}().
However, among all virtual network interfaces, only bond and macvlan currently implement them.
As a result, most virtual interfaces cannot advertise the capabilities of their underlying devices:
# ip link add ipvl0 link eth0 type ipvlan mode l2 bridge # ethtool -T ipvl0 Time stamping parameters for ipvl0: Capabilities: software-receive software-system-clock PTP Hardware Clock: none Hardware Transmit Timestamp Modes: none Hardware Receive Filter Modes: none
While these callbacks could be implemented in each virtual interface, this approach is limited to those directly linked to a physical device.
Not all virtual interfaces are tied to real hardware; for instance, packets from UDP tunnel devices eventually pass through physical devices and can be hardware-timestamped there.
Let's allow configuring the hardware timestamping capability on virtual interfaces via ETHTOOL_MSG_TSINFO_SET.
Note that SOF_TIMESTAMPING_RX_SOFTWARE and SOF_TIMESTAMPING_SOFTWARE are automatically added since __ethtool_get_ts_info() and ethnl_tsinfo_end_dump() report them for all devices.
By configuring this capability, ioctl(SIOCSHWTSTAMP) (hwstamp_ctl below) can enable TX/RX hardware timestamping successfully:
# ./tools/net/ynl/pyynl/cli.py \
--spec Documentation/netlink/specs/ethtool.yaml \
--do tsinfo-set \
--json '{"header": {"dev-index": 6},
"timestamping": {"nomask": true, "bits": {
"bit": [{"name": "hardware-transmit"},
{"name": "software-transmit"},
{"name": "hardware-receive"}]
}},
"tx-types": {"nomask": true, "bits": {
"bit": [{"name": "off"}, {"name": "on"}]
}},
"rx-filters": {"nomask": true, "bits": {
"bit" : [{"name": "none"}, {"name": "all"}]
}}}'# ethtool -T ipvl0 Time stamping parameters for ipvl0: Capabilities: hardware-transmit software-transmit hardware-receive software-receive software-system-clock PTP Hardware Clock: none Hardware Transmit Timestamp Modes: off on Hardware Receive Filter Modes: none all
# hwstamp_ctl -i ipvl0 -t 1 -r 1 current settings: tx_type 0 rx_filter 0 new settings: tx_type 1 rx_filter 1
--- Documentation/netlink/specs/ethtool.yaml | 13 ++ include/linux/netdevice.h | 11 ++ .../uapi/linux/ethtool_netlink_generated.h | 1 + net/core/dev_ioctl.c | 31 ++++- net/ethtool/common.c | 4 + net/ethtool/netlink.c | 8 ++ net/ethtool/netlink.h | 1 + net/ethtool/tsconfig.c | 7 +- net/ethtool/tsinfo.c | 123 +++++++++++++++++- 9 files changed, 188 insertions(+), 11 deletions(-)
Documentation/netlink/specs/ethtool.yaml +13 -0
@@ -2859,6 +2859,19 @@ operations: - worst-channel - link dump: *mse-get-op + - + name: tsinfo-set + doc: Set tsinfo params. + + attribute-set: tsinfo + + do: &tsinfo-set-op + request: + attributes: + - header + - timestamping + - tx-types + - rx-filters mcast-groups: list:
include/linux/netdevice.h +11 -0
@@ -2087,6 +2087,7 @@ enum netdev_reg_state {* offload capabilities of the device * @udp_tunnel_nic: UDP tunnel offload state * @ethtool: ethtool related state +* @tsinfo: HW timestamping capability for virtual devices * @xdp_state: stores info on attached XDP BPF programs * * @nested_level: Used as a parameter of spin_lock_nested() of
@@ -2509,6 +2510,16 @@ struct net_device {*/ struct netdev_config *cfg_pending;struct ethtool_netdev_state *ethtool; +struct { +struct { +u32 tx_type; +u32 rx_filter; + } cfg; +u32 so_timestamping; +u32 tx_types; +u32 rx_filters; +bool enabled; + } tsinfo;/* protected by rtnl_lock */ struct bpf_xdp_entity xdp_state[__MAX_XDP_MODE];
include/uapi/linux/ethtool_netlink_generated.h +1 -0
@@ -893,6 +893,7 @@ enum {ETHTOOL_MSG_RSS_CREATE_ACT ,ETHTOOL_MSG_RSS_DELETE_ACT ,ETHTOOL_MSG_MSE_GET , +ETHTOOL_MSG_TSINFO_SET , __ETHTOOL_MSG_USER_CNT,ETHTOOL_MSG_USER_MAX = (__ETHTOOL_MSG_USER_CNT -1 )
net/core/dev_ioctl.c +27 -4
@@ -260,6 +260,15 @@ int dev_get_hwtstamp_phylib(struct net_device *dev, {struct hwtstamp_provider *hwprov; +if (!dev->netdev_ops->ndo_hwtstamp_get) { +if (!dev->tsinfo.enabled) +return -EOPNOTSUPP ; + + cfg->rx_filter = dev->tsinfo.cfg.rx_filter; + cfg->tx_type = dev->tsinfo.cfg.tx_type; +return 0 ; + } + hwprov =rtnl_dereference (dev->hwprov);if (hwprov) { cfg->qualifier = hwprov->desc.qualifier;
@@ -286,7 +295,7 @@ static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr)struct hwtstamp_config cfg;int err; -if (!ops->ndo_hwtstamp_get) +if (!ops->ndo_hwtstamp_get && !dev->tsinfo.enabled)return -EOPNOTSUPP ;if (!netif_device_present (dev))
@@ -337,6 +346,20 @@ int dev_set_hwtstamp_phylib(struct net_device *dev,bool phy_ts;int err; +if (!ops->ndo_hwtstamp_set) { +if (!dev->tsinfo.enabled || + !(dev->tsinfo.tx_types &BIT (cfg->tx_type)) || + !(dev->tsinfo.rx_filters &BIT (cfg->rx_filter))) +return -EOPNOTSUPP ; + +if (cfg->flags) +return -EINVAL ; + + dev->tsinfo.cfg.tx_type = cfg->tx_type; + dev->tsinfo.cfg.rx_filter = cfg->rx_filter; +return 0 ; + } + hwprov =rtnl_dereference (dev->hwprov);if (hwprov) { if (hwprov->source == HWTSTAMP_SOURCE_PHYLIB &&
@@ -413,7 +436,7 @@ static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr)return err; } -if (!ops->ndo_hwtstamp_set) +if (!ops->ndo_hwtstamp_set && !dev->tsinfo.enabled)return -EOPNOTSUPP ;if (!netif_device_present (dev))
@@ -447,7 +470,7 @@ int generic_hwtstamp_get_lower(struct net_device *dev,if (!netif_device_present (dev))return -ENODEV ; -if (!ops->ndo_hwtstamp_get) +if (!ops->ndo_hwtstamp_get && !dev->tsinfo.enabled)return -EOPNOTSUPP ;netdev_lock_ops (dev);
@@ -468,7 +491,7 @@ int generic_hwtstamp_set_lower(struct net_device *dev,if (!netif_device_present (dev))return -ENODEV ; -if (!ops->ndo_hwtstamp_set) +if (!ops->ndo_hwtstamp_set && !dev->tsinfo.enabled)return -EOPNOTSUPP ;netdev_lock_ops (dev);
net/ethtool/common.c +4 -0
@@ -1090,6 +1090,10 @@ int __ethtool_get_ts_info(struct net_device *dev, err = ops->get_ts_info (dev, info);if (!err && info->phc_index >=0 ) info->phc_source =HWTSTAMP_SOURCE_NETDEV ; + }else if (dev->tsinfo.enabled) { + info->so_timestamping = dev->tsinfo.so_timestamping; + info->tx_types = dev->tsinfo.tx_types; + info->rx_filters = dev->tsinfo.rx_filters; } info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |
net/ethtool/netlink.c +8 -0
@@ -422,6 +422,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_TSCONFIG_SET] = ðnl_tsconfig_request_ops, [ETHTOOL_MSG_PHY_GET] = ðnl_phy_request_ops, [ETHTOOL_MSG_MSE_GET] = ðnl_mse_request_ops, + [ETHTOOL_MSG_TSINFO_SET] = ðnl_tsinfo_request_ops, };static struct ethnl_dump_ctx *ethnl_dump_context (struct netlink_callback *cb)
@@ -1548,6 +1549,13 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_mse_get_policy, .maxattr = ARRAY_SIZE(ethnl_mse_get_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_TSINFO_SET, + .flags = GENL_UNS_ADMIN_PERM, + .doit = ethnl_default_set_doit, + .policy = ethnl_tsinfo_set_policy, + .maxattr = ARRAY_SIZE(ethnl_tsinfo_set_policy) - 1, + }, };static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/netlink.h +1 -0
@@ -502,6 +502,7 @@ extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER + 1];extern const struct nla_policy ethnl_tsconfig_get_policy[ETHTOOL_A_TSCONFIG_HEADER +1 ];extern const struct nla_policy ethnl_tsconfig_set_policy[ETHTOOL_A_TSCONFIG_MAX +1 ];extern const struct nla_policy ethnl_mse_get_policy[ETHTOOL_A_MSE_HEADER +1 ]; +extern const struct nla_policy ethnl_tsinfo_set_policy[ETHTOOL_A_TSINFO_MAX +1 ];int ethnl_set_features (struct sk_buff *skb,struct genl_info *info);int ethnl_act_cable_test (struct sk_buff *skb,struct genl_info *info);
net/ethtool/tsconfig.c +4 -3
@@ -41,7 +41,7 @@ static int tsconfig_prepare_data(const struct ethnl_req_info *req_base,struct kernel_hwtstamp_config cfg = {};int ret; -if (!dev->netdev_ops->ndo_hwtstamp_get) +if (!dev->netdev_ops->ndo_hwtstamp_get && !dev->tsinfo.enabled)return -EOPNOTSUPP ; ret =ethnl_ops_begin (dev);
@@ -61,7 +61,7 @@ static int tsconfig_prepare_data(const struct ethnl_req_info *req_base,if (hwprov) { data->hwprov_desc.index = hwprov->desc.index; data->hwprov_desc.qualifier = hwprov->desc.qualifier; - }else { + }else if (!dev->tsinfo.enabled) {struct kernel_ethtool_ts_info ts_info = {}; ts_info.phc_index =-1 ;
@@ -252,7 +252,8 @@ static int ethnl_set_tsconfig_validate(struct ethnl_req_info *req_base, {const struct net_device_ops *ops = req_base->dev->netdev_ops; -if (!ops->ndo_hwtstamp_set || !ops->ndo_hwtstamp_get) +if ((!ops->ndo_hwtstamp_set || !ops->ndo_hwtstamp_get) && + !READ_ONCE (req_base->dev->tsinfo.enabled))return -EOPNOTSUPP ;return 1 ;
net/ethtool/tsinfo.c +119 -4
159 lines not on this page · raw message
Signature · 1 line
2.54.0.1136.gdb2ca164c4-goog
PATCH 2/5 bpf: Rename bpf_kfunc_set_tcp_reqsk to bpf_kfunc_set_sched_cls.
In reply to Kuniyuki IwashimaCurrently bpf_kfunc_set_tcp_reqsk is registered for BPF_PROG_TYPE_SCHED_CLS.
We will add more kfuncs there, but the name is too specific.
Let's rename it to bpf_kfunc_set_sched_cls.
--- net/core/filter.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/core/filter.c +5 -5
@@ -12498,9 +12498,9 @@ BTF_KFUNCS_START(bpf_kfunc_check_set_sock_addr) BTF_ID_FLAGS(func, bpf_sock_addr_set_sun_path) BTF_KFUNCS_END(bpf_kfunc_check_set_sock_addr) -BTF_KFUNCS_START(bpf_kfunc_check_set_tcp_reqsk) +BTF_KFUNCS_START(bpf_kfunc_check_set_sched_cls) BTF_ID_FLAGS(func, bpf_sk_assign_tcp_reqsk) -BTF_KFUNCS_END(bpf_kfunc_check_set_tcp_reqsk) +BTF_KFUNCS_END(bpf_kfunc_check_set_sched_cls) BTF_KFUNCS_START(bpf_kfunc_check_set_sock_ops) BTF_ID_FLAGS(func, bpf_sock_ops_enable_tx_tstamp)
@@ -12526,9 +12526,9 @@ static const struct btf_kfunc_id_set bpf_kfunc_set_sock_addr = { .set = &bpf_kfunc_check_set_sock_addr, }; -static const struct btf_kfunc_id_set bpf_kfunc_set_tcp_reqsk = { +static const struct btf_kfunc_id_set bpf_kfunc_set_sched_cls = { .owner =THIS_MODULE , - .set = &bpf_kfunc_check_set_tcp_reqsk, + .set = &bpf_kfunc_check_set_sched_cls, };static const struct btf_kfunc_id_set bpf_kfunc_set_sock_ops = {
@@ -12556,7 +12556,7 @@ static int __init bpf_kfunc_init(void) ret = ret ?:register_btf_kfunc_id_set (BPF_PROG_TYPE_XDP , &bpf_kfunc_set_xdp); ret = ret ?:register_btf_kfunc_id_set (BPF_PROG_TYPE_CGROUP_SOCK_ADDR , &bpf_kfunc_set_sock_addr); - ret = ret ?:register_btf_kfunc_id_set (BPF_PROG_TYPE_SCHED_CLS , &bpf_kfunc_set_tcp_reqsk); + ret = ret ?:register_btf_kfunc_id_set (BPF_PROG_TYPE_SCHED_CLS , &bpf_kfunc_set_sched_cls);return ret ?:register_btf_kfunc_id_set (BPF_PROG_TYPE_SOCK_OPS , &bpf_kfunc_set_sock_ops); }late_initcall (bpf_kfunc_init);
Signature · 1 line
2.54.0.1136.gdb2ca164c4-goog
PATCH 3/5 bpf: Add bpf_skb_set_hwtstamp().
In reply to Kuniyuki IwashimaWe have some hosts where packets come from special hardware and are provided directly to userspace, bypassing the kernel networking stack.
When standard socket applications are run on these hosts, a userspace proxy is required to mediate traffic between the hardware and the applications.
+---------+ +----------------------+
| proxy | | socket application |
+---------+ +----------------------+
^ ^ ^
userspace | | |
-----------| |-----------------------------------------------
| | | +---------------------+ | skb
| | `--->| virtual interface |<---'
kernel | | skb +---------------------+
-----------| |-----------------------------------------------
|
v
+------------+
| hardware |
+------------+However, even though the hardware fully supports timestamping, the HW timestamps are not directly accessible to the socket applications because the skb is consumed/injected by the proxy.
For RX flow, let's add a kfunc to update skb_hwtstamps(skb)->hwtstamp at tc/ingress.
With this kfunc, the proxy can carry the RX hardware timestamp via encapsulated packets (e.g. in GENEVE option) and BPF prog can extract it into skb_hwtstamps(skb)->hwtstamp at tc/ingress of the virtual interface above.
+---------+ +----------------------+
| proxy | | socket application |
+---------+ +----------------------+
^ | encap packets ^ recv payload
userspace | | w/ RX hwtstamp | w/ RX hwtstamp
-----------| |-----------------------------------------------
| | | +---------------------+ | skb
| | `--->| geneve0 |----'
kernel | | skb +---------------------+
| | | ^
| | v |
| | +------------------+ extract RX hwtstamp
| | | BPF@tc/ingress | and set it to skb
| | +------------------+
-----------| |-----------------------------------------------
|
|
+------------+
| hardware |
+------------+This allows transparently proxying RX hardware timestamps to the socket applications via SCM_TIMESTAMPING.
Note that bpf_skb_set_hwtstamp() calls skb_header_unclone() and bpf_compute_data_pointers(), so it is marked as a packet-changing kfunc.
--- include/linux/skbuff.h | 5 +++++ kernel/bpf/verifier.c | 9 ++++++++- net/core/filter.c | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-)
include/linux/skbuff.h +5 -0
@@ -4701,6 +4701,11 @@ static inline bool skb_defer_rx_timestamp(struct sk_buff *skb)#endif /* !CONFIG_NETWORK_PHY_TIMESTAMPING */ +struct bpf_hwtstamp { +ktime_t hwtstamp; +u64 reserved; +} __packed; +/** * skb_complete_tx_timestamp() - deliver cloned skb with tx timestamps *
kernel/bpf/verifier.c +8 -1
@@ -11191,6 +11191,7 @@ enum special_kfunc_type { KF_bpf_session_is_return, KF_bpf_stream_vprintk, KF_bpf_stream_print_stack, + KF_bpf_skb_set_hwtstamp, };BTF_ID_LIST (special_kfunc_list)
@@ -11283,6 +11284,11 @@ BTF_ID_UNUSED#endif BTF_ID(func, bpf_stream_vprintk) BTF_ID(func, bpf_stream_print_stack) +#ifdef CONFIG_NET +BTF_ID(func, bpf_skb_set_hwtstamp) +#else +BTF_ID_UNUSED +#endif static bool is_bpf_obj_new_kfunc (u32 func_id) {
@@ -11364,7 +11370,8 @@ static bool is_kfunc_bpf_preempt_enable(struct bpf_kfunc_call_arg_meta *meta)bool bpf_is_kfunc_pkt_changing (struct bpf_kfunc_call_arg_meta *meta) { -return meta->func_id == special_kfunc_list[KF_bpf_xdp_pull_data]; +return meta->func_id == special_kfunc_list[KF_bpf_xdp_pull_data] || + meta->func_id == special_kfunc_list[KF_bpf_skb_set_hwtstamp]; } static enum kfunc_ptr_arg_type
net/core/filter.c +23 -0
@@ -12372,6 +12372,28 @@ __bpf_kfunc int bpf_sock_ops_enable_tx_tstamp(struct bpf_sock_ops_kern *skops,return 0 ; } +__bpf_kfunc int bpf_skb_set_hwtstamp(struct __sk_buff *s, +struct bpf_hwtstamp *attrs,int attrs__sz) +{ +struct sk_buff *skb = (struct sk_buff *)s; + +if (attrs__sz !=sizeof (*attrs) || attrs->reserved) +return -EINVAL ; + +if (!skb_at_tc_ingress (skb)) +return -EINVAL ; + +if (skb_header_unclone (skb,GFP_ATOMIC )) +return -ENOMEM ; + +skb_clear_tstamp (skb); +skb_hwtstamps (skb)->hwtstamp = attrs->hwtstamp; + +bpf_compute_data_pointers (skb); + +return 0 ; +} +/** * bpf_xdp_pull_data() - Pull in non-linear xdp data. * @x: &xdp_md associated with the XDP buffer
@@ -12500,6 +12522,7 @@ BTF_KFUNCS_END(bpf_kfunc_check_set_sock_addr) BTF_KFUNCS_START(bpf_kfunc_check_set_sched_cls) BTF_ID_FLAGS(func, bpf_sk_assign_tcp_reqsk) +BTF_ID_FLAGS(func, bpf_skb_set_hwtstamp) BTF_KFUNCS_END(bpf_kfunc_check_set_sched_cls) BTF_KFUNCS_START(bpf_kfunc_check_set_sock_ops)
Signature · 1 line
2.54.0.1136.gdb2ca164c4-goog
[email protected]
AI reviewRe: [PATCH v1 bpf-next/net 3/5] bpf: Add bpf_skb_set_hwtstamp().
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Unsafe modification of shared SKB data (skb_shinfo) via insufficient uncloning --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unsafe modification of shared SKB data (skb_shinfo) via insufficient uncloning --
commit 96bf1885d42f4593da3e164388ab66653eb4e518
Author: Kuniyuki Iwashima <[email protected]>
bpf: Add bpf_skb_set_hwtstamp().
Adds a kfunc to update skb_hwtstamps(skb)->hwtstamp at tc/ingress. This allows transparent proxying of RX hardware timestamps via SCM_TIMESTAMPING to socket applications.
Quoted 4 lines
net/core/filter.c +0
-0
[ ... ]
Quoted 10 lines
net/core/filter.c +6
-0@@ -12372,6 +12372,28 @@ __bpf_kfunc int bpf_sock_ops_enable_tx_tstamp(struct bpf_sock_ops_kern *skops,return 0 ; } +__bpf_kfunc int bpf_skb_set_hwtstamp(struct __sk_buff *s, +struct bpf_hwtstamp *attrs,int attrs__sz) +{ +struct sk_buff *skb = (struct sk_buff *)s; + +if (attrs__sz !=sizeof (*attrs) || attrs->reserved)
net/core/filter.c __bpf_kfunc int bpf_sock_ops_enable_tx_tstamp(struct bpf_sock_ops_kern *skops, · line 12390
Quoted 10 lines
net/core/filter.c +10
-0+return -EINVAL ; + +if (!skb_at_tc_ingress (skb)) +return -EINVAL ; + +if (skb_header_unclone (skb,GFP_ATOMIC )) +return -ENOMEM ; + +skb_clear_tstamp (skb); +skb_hwtstamps (skb)->hwtstamp = attrs->hwtstamp;
[Severity: High]
Does using skb_header_unclone() safely protect against modifying a shared skb_shinfo(skb) here?
For TCP transmit clones, the header is released and skb->nohdr is set to 1. This makes skb_header_cloned() return false, even though the data buffer and skb_shinfo are still shared with the original packet in the TCP write queue.
When these packets loop back to TC ingress, such as via veth or loopback, and are modified by the BPF program, skb_header_unclone() will skip reallocation.
Could this lead to silent data corruption of the original socket buffer's skb_shinfo? Would using skb_unclone() instead be necessary to prevent this?
Quoted 5 lines
net/core/filter.c +5
-0+ +bpf_compute_data_pointers (skb); + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v1 bpf-next/net 3/5] bpf: Add bpf_skb_set_hwtstamp().
Quoted 46 lines · On Thu, Jun 11, 2026 at 5:33 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unsafe modification of shared SKB data (skb_shinfo) via insufficient uncloning --commit
96bf1885d42f4593da3e164388ab66653eb4e518
Author: Kuniyuki Iwashima <[email protected]>bpf: Add
bpf_skb_set_hwtstamp().Adds a kfunc to update skb_hwtstamps(skb)->hwtstamp at tc/ingress. This allows transparent proxying of RX hardware timestamps via
SCM_TIMESTAMPINGto socket applications.Quoted 4 lines
net/core/filter.c +0
-0[ ... ]
Quoted 10 lines
net/core/filter.c +6
-0@@ -12372,6 +12372,28 @@ __bpf_kfunc int bpf_sock_ops_enable_tx_tstamp(struct bpf_sock_ops_kern *skops,return 0 ; } +__bpf_kfunc int bpf_skb_set_hwtstamp(struct __sk_buff *s, +struct bpf_hwtstamp *attrs,int attrs__sz) +{ +struct sk_buff *skb = (struct sk_buff *)s; + +if (attrs__sz !=sizeof (*attrs) || attrs->reserved)net/core/filter.c __bpf_kfunc int bpf_sock_ops_enable_tx_tstamp(struct bpf_sock_ops_kern *skops, · line 12390
Quoted 10 lines
net/core/filter.c +10
-0+return -EINVAL ; + +if (!skb_at_tc_ingress (skb)) +return -EINVAL ; + +if (skb_header_unclone (skb,GFP_ATOMIC )) +return -ENOMEM ; + +skb_clear_tstamp (skb); +skb_hwtstamps (skb)->hwtstamp = attrs->hwtstamp;[Severity: High]
Does usingskb_header_unclone()safely protect against modifying a sharedskb_shinfo(skb)here?
Quoted 7 lines
For TCP transmit clones, the header is released and
skb->nohdris set to 1. This makesskb_header_cloned()return false, even though the data buffer andskb_shinfoare still shared with the original packet in the TCP write queue.When these packets loop back to TC ingress, such as via veth or loopback, and are modified by the BPF program,
skb_header_unclone()will skip reallocation.
I missed this loopback scenario.
Actually I have another patch to avoid skb_header_unclone() in bpf_skb_scrub_tx_tstamp() for TCP skb (skb->destructor == tcp_wfree()).
Quoted 3 lines
Could this lead to silent data corruption of the original socket buffer's
skb_shinfo? Would usingskb_unclone()instead be necessary to prevent this?
Will use skb_unclone().
PATCH 4/5 bpf: Add kfunc to proxy TX HW Timestamp.
In reply to Kuniyuki IwashimaIn the setup mentioned in the previous patch, it is impossible for socket applications to get TX hardware timestamps via SCM_TIMESTAMPING.
To proxy TX hardware timestamp, let's add two kfuncs:
* bpf_skb_scrub_tx_tstamp() : scrub skb_shinfo(skb)->tx_flags
* bpf_skb_complete_tx_tstamp() : enqueue skb to sk->sk_error_queue
The key idea is to regenerate an skb that contains all the information required for the TX timestamp, identical to the original skb.
Here is how it works:
When the socket application sends a packet, BPF prog at tc/egress checks skb_shinfo()->tx_flags. If it has SKBTX_HW_TSTAMP_NOBPF, BPF prog scrub the value by bpf_skb_scrub_tx_tstamp() and inserts a GENEVE option to signal that the packet wants TX HW timestamp.
The proxy decapsulates and forwards the packet to the hardware, and if it has GENEVE option, the proxy keeps the original packet until TX completion.
+---------+ +----------------------+
| proxy | | socket application |
+---------+ +----------------------+
| ^ decap packet and |
userspace | | keep it till TX cmpl |
-----------| |-----------------------------------------------
| | | +---------------------+ | skb
| | `----| geneve0 |<---'
kernel | | skb +---------------------+
| | ^ |
| | | v
| | +------------------+ check skb_shinfo()->tx_flags
| | | BPF@tc/egress | and insert a GENEVE option
| | +------------------+
-----------| |-----------------------------------------------
|
v
+------------+
| hardware |
+------------+Once the proxy gets TX hwtstamp, encapsulate the original packet with TX hwtstamp embedded in GENEVE option, and sends it to the GENEVE device.
At tc@ingress, BPF extracts the TX hwtstamp and sets it to skb. Then, it looks up the sender socket, assigns it to skb->sk, calls bpf_skb_complete_tx_tstamp(), and returns TCX_ERRQUEUE to put the skb to skb->sk->sk_error_queue.
+---------+ +----------------------+
| proxy | | socket application |
+---------+ +----------------------+
^ | encap packet ^ get TX hwtstamp by
userspace | | w/ TX hwtstamp | recvmsg(MSG_ERRQUEUE)
-----------| |-----------------------------------------------
| | | +---------------------+ | skb
| | `--->| geneve0 | |
kernel | | skb +---------------------+ |
| | | ________'
| | v | extract TX hwtstamp to skb
| | +------------------+ and look up the sender sk
| | | BPF@tc/ingress | and enqueue skb to its
| | +------------------+ sk->sk_error_queue
-----------| |-----------------------------------------------
|
| TX completion w/ TX hwtstamp
+------------+
| hardware |
+------------+This provides transparent TX HW timestamp support, and the socket application can finally receive it via recvmsg(MSG_ERRQUEUE).
Note that struct bpf_tx_tstamp_cmpl needs network_offset and payload_offset so that
1. ip_cmsg_recv() and ipv6_recv_error() can correctly parse the IPv4/IPv6 header for some control messages
2. applications can receive the original payload
--- include/linux/filter.h | 2 ++ include/linux/skbuff.h | 8 +++++ include/net/tcx.h | 1 + include/uapi/linux/bpf.h | 1 + include/uapi/linux/pkt_cls.h | 3 +- kernel/bpf/verifier.c | 6 +++- net/core/dev.c | 39 ++++++++++++++++++++++++ net/core/filter.c | 58 ++++++++++++++++++++++++++++++++++++ 8 files changed, 116 insertions(+), 2 deletions(-)
include/linux/filter.h +2 -0
@@ -770,6 +770,7 @@ struct bpf_nh_params {#define BPF_RI_F_CPU_MAP_INIT BIT(2)#define BPF_RI_F_DEV_MAP_INIT BIT(3)#define BPF_RI_F_XSK_MAP_INIT BIT(4) +#define BPF_RI_F_TX_TS_CMPL BIT(5)struct bpf_redirect_info {u64 tgt_index;
@@ -780,6 +781,7 @@ struct bpf_redirect_info {enum bpf_map_type map_type;struct bpf_nh_params nh;u32 kern_flags; +struct bpf_tx_tstamp_cmpl txtscmpl; };struct bpf_net_context {
include/linux/skbuff.h +8 -0
@@ -4706,6 +4706,14 @@ struct bpf_hwtstamp {u64 reserved; } __packed; +struct bpf_tx_tstamp_cmpl { +u32 tskey; +__be16 protocol; +u16 network_offset; +u16 payload_offset; +u16 reserved; +} __packed; +/** * skb_complete_tx_timestamp() - deliver cloned skb with tx timestamps *
include/net/tcx.h +1 -0
@@ -151,6 +151,7 @@ static inline enum tcx_action_base tcx_action_code(struct sk_buff *skb, fallthrough;case TCX_DROP :case TCX_REDIRECT : +case TCX_ERRQUEUE :return code;case TCX_NEXT :default :
include/uapi/linux/bpf.h +1 -0
@@ -6532,6 +6532,7 @@ enum tcx_action_base {TCX_PASS =0 ,TCX_DROP =2 ,TCX_REDIRECT =7 , + TCX_ERRQUEUE = 9, }; struct bpf_xdp_sock {
include/uapi/linux/pkt_cls.h +2 -1
@@ -76,7 +76,8 @@ enum {* the skb and act like everything * is alright. */ -#define TC_ACT_VALUE_MAX TC_ACT_TRAP +#define TC_ACT_ERRQUEUE 9 +#define TC_ACT_VALUE_MAX TC_ACT_ERRQUEUE/* There is a special kind of actions called "extended actions", * which need a value parameter. These have a local opcode located in
kernel/bpf/verifier.c +5 -1
@@ -11192,6 +11192,7 @@ enum special_kfunc_type { KF_bpf_stream_vprintk, KF_bpf_stream_print_stack, KF_bpf_skb_set_hwtstamp, + KF_bpf_skb_scrub_tx_tstamp, };BTF_ID_LIST (special_kfunc_list)
@@ -11286,8 +11287,10 @@ BTF_ID(func, bpf_stream_vprintk) BTF_ID(func, bpf_stream_print_stack)#ifdef CONFIG_NET BTF_ID(func, bpf_skb_set_hwtstamp) +BTF_ID(func, bpf_skb_scrub_tx_tstamp)#else BTF_ID_UNUSED +BTF_ID_UNUSED#endif static bool is_bpf_obj_new_kfunc (u32 func_id)
@@ -11371,7 +11374,8 @@ static bool is_kfunc_bpf_preempt_enable(struct bpf_kfunc_call_arg_meta *meta)bool bpf_is_kfunc_pkt_changing (struct bpf_kfunc_call_arg_meta *meta) {return meta->func_id == special_kfunc_list[KF_bpf_xdp_pull_data] || - meta->func_id == special_kfunc_list[KF_bpf_skb_set_hwtstamp]; + meta->func_id == special_kfunc_list[KF_bpf_skb_set_hwtstamp] || + meta->func_id == special_kfunc_list[KF_bpf_skb_scrub_tx_tstamp]; } static enum kfunc_ptr_arg_type
net/core/dev.c +39 -0
@@ -4457,6 +4457,41 @@ tcx_run(const struct bpf_mprog_entry *entry, struct sk_buff *skb,return tcx_action_code (skb, ret); } +static int skb_do_completion (struct sk_buff *skb) +{ +enum skb_drop_reason drop_reason =SKB_DROP_REASON_TC_INGRESS ; +struct bpf_redirect_info *ri =bpf_net_ctx_get_ri (); +struct bpf_tx_tstamp_cmpl *txtscmpl; + +if (!(ri->kern_flags &BPF_RI_F_TX_TS_CMPL )) + goto drop; + +if (skb_header_unclone (skb,GFP_ATOMIC )) + goto drop; + +__skb_push (skb, skb->mac_len); + + txtscmpl = &ri->txtscmpl; + + drop_reason =pskb_may_pull_reason (skb, txtscmpl->payload_offset); +if (drop_reason) + goto drop; + + skb->protocol = txtscmpl->protocol; +skb_set_network_header (skb, txtscmpl->network_offset); +__skb_pull (skb, txtscmpl->payload_offset); + +skb_shinfo (skb)->tskey = txtscmpl->tskey; +skb_shinfo (skb)->tx_flags =SKBTX_HW_TSTAMP_NOBPF ; +__skb_tstamp_tx (skb,NULL ,skb_hwtstamps (skb), skb->sk,SCM_TSTAMP_SND ); + +consume_skb (skb); +return NET_RX_SUCCESS ; +drop: +kfree_skb_reason (skb, drop_reason); +return NET_RX_DROP ; +} + static __always_inline struct sk_buff *sch_handle_ingress (struct sk_buff *skb,struct packet_type **pt_prev,int *ret,struct net_device *orig_dev,bool *another)
@@ -4505,6 +4540,10 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret, *ret =NET_RX_DROP ;bpf_net_ctx_clear (bpf_net_ctx);return NULL ; +case TC_ACT_ERRQUEUE : + *ret =skb_do_completion (skb); +bpf_net_ctx_clear (bpf_net_ctx); +return NULL ;/* used by tc_run */ case TC_ACT_STOLEN :case TC_ACT_QUEUED :
net/core/filter.c +58 -0
70 lines not on this page · raw message
Signature · 1 line
2.54.0.1136.gdb2ca164c4-goog
[email protected]
AI reviewRe: [PATCH v1 bpf-next/net 4/5] bpf: Add kfunc to proxy TX HW Timestamp.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] The TC_ACT_ERRQUEUE action is unhandled in sch_handle_egress(), causing packets to be silently transmitted instead of queued or dropped.
Pre-existing issues:
- [High] bpf_net_ctx_get_ri() will dereference a NULL pointer if bpf_skb_complete_tx_tstamp is called from a qdisc where bpf_net_ctx is not set. --
commit 532ea1ea43e08b0ed268837eba11a8d463c7b97b
Author: Kuniyuki Iwashima <[email protected]>
bpf: Add kfunc to proxy TX HW Timestamp.
This patch introduces two new kfuncs, bpf_skb_scrub_tx_tstamp() and bpf_skb_complete_tx_tstamp(), to proxy TX hardware timestamps for socket applications using SCM_TIMESTAMPING. It also introduces the TCX_ERRQUEUE action to enqueue the modified packet to the socket's error queue.
Quoted 4 lines
net/core/dev.c +0
-0
[ ... ]
net/core/dev.c sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret, · line 4545
Quoted 8 lines
net/core/dev.c +4
-0@@ -4504,6 +4539,10 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret, *ret =NET_RX_DROP ;bpf_net_ctx_clear (bpf_net_ctx);return NULL ; +case TC_ACT_ERRQUEUE : + *ret =skb_do_completion (skb); +bpf_net_ctx_clear (bpf_net_ctx); +return NULL ;
[Severity: High]
Does TC_ACT_ERRQUEUE also need to be handled in sch_handle_egress()?
If a BPF program returns TCX_ERRQUEUE on egress, the switch statement in sch_handle_egress() will fall through. This clears the BPF network context and returns the skb for transmission instead of queueing or dropping it, which seems to bypass the intended error queue behavior.
[ ... ]
Quoted 4 lines
net/core/filter.c +0
-0
[ ... ]
Quoted 4 lines
net/core/filter.c +4
-0+__bpf_kfunc int bpf_skb_complete_tx_tstamp(struct __sk_buff *s, +struct bpf_tx_tstamp_cmpl *attrs, +int attrs__sz) +{
net/core/filter.c __bpf_kfunc int bpf_skb_set_hwtstamp(struct __sk_buff *s, · line 12427
Quoted 10 lines
net/core/filter.c +10
-0+struct sk_buff *skb = (struct sk_buff *)s; +struct bpf_redirect_info *ri; +struct sock *sk = skb->sk; +s32 delta; + +if (attrs__sz !=sizeof (*attrs) || attrs->reserved) +return -EINVAL ; + +if (!sk || !sk_fullsock (sk)) +return -EINVAL ;
[Severity: High]
Should this function verify it is only called on ingress?
Without checking skb_at_tc_ingress(skb), bpf_skb_complete_tx_tstamp() could be called on egress. If that happens and the program returns TCX_ERRQUEUE, the completion state would be silently discarded and the packet transmitted because sch_handle_egress() does not currently handle TC_ACT_ERRQUEUE.
Quoted 9 lines
net/core/filter.c +9
-0+ +if (attrs->payload_offset > skb->len) +return -EINVAL ; + + delta = attrs->payload_offset - attrs->network_offset; +switch (attrs->protocol) { +case htons (ETH_P_IP ): +if (delta < (s32 )sizeof (struct iphdr ) || !sk_is_inet (sk)) +return -EINVAL ;
net/core/filter.c __bpf_kfunc int bpf_skb_set_hwtstamp(struct __sk_buff *s, · line 12446
Quoted 10 lines
net/core/filter.c +10
-0+break ; +case htons (ETH_P_IPV6 ): +if (delta < (s32 )sizeof (struct ipv6hdr ) || sk->sk_family !=AF_INET6 ) +return -EINVAL ; +break ; +default : +return -EAFNOSUPPORT ; + } + + ri =bpf_net_ctx_get_ri ();
[Severity: High]
This is a pre-existing issue, but can bpf_net_ctx_get_ri() trigger a NULL pointer dereference here under certain conditions?
When a BPF program runs via tcf_classify() from a traditional classful qdisc enqueue callback (like HTB), sch_handle_egress() has already cleared the bpf_net_ctx. Calling this kfunc in that scenario would cause bpf_net_ctx_get_ri() to dereference a NULL pointer.
Quoted 5 lines
net/core/filter.c +5
-0+ ri->kern_flags |=BPF_RI_F_TX_TS_CMPL ; + ri->txtscmpl = *attrs; + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v1 bpf-next/net 4/5] bpf: Add kfunc to proxy TX HW Timestamp.
Quoted 25 lines · On Thu, Jun 11, 2026 at 5:33 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] TheTC_ACT_ERRQUEUEaction is unhandled insch_handle_egress(), causing packets to be silently transmitted instead of queued or dropped.Pre-existing issues:
- [High]bpf_net_ctx_get_ri()will dereference a NULL pointer ifbpf_skb_complete_tx_tstampis called from a qdisc wherebpf_net_ctxis not set. --commit
532ea1ea43e08b0ed268837eba11a8d463c7b97b
Author: Kuniyuki Iwashima <[email protected]>bpf: Add kfunc to proxy TX HW Timestamp.
This patch introduces two new kfuncs,
bpf_skb_scrub_tx_tstamp()andbpf_skb_complete_tx_tstamp(), to proxy TX hardware timestamps for socket applications usingSCM_TIMESTAMPING. It also introduces theTCX_ERRQUEUEaction to enqueue the modified packet to the socket's error queue.Quoted 4 lines
net/core/dev.c +0
-0[ ... ]
Quoted 11 lines
net/core/dev.c sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret, · line 4545
Quoted 8 lines
net/core/dev.c +4
-0@@ -4504,6 +4539,10 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret, *ret =NET_RX_DROP ;bpf_net_ctx_clear (bpf_net_ctx);return NULL ; +case TC_ACT_ERRQUEUE : + *ret =skb_do_completion (skb); +bpf_net_ctx_clear (bpf_net_ctx); +return NULL ;[Severity: High]
DoesTC_ACT_ERRQUEUEalso need to be handled insch_handle_egress()?
This is intentional. I'll add !skb_at_tc_ingress() check in bpf_skb_complete_tx_tstamp () instead.
Quoted 21 lines
If a BPF program returns
TCX_ERRQUEUEon egress, the switch statement insch_handle_egress()will fall through. This clears the BPF network context and returns the skb for transmission instead of queueing or dropping it, which seems to bypass the intended error queue behavior.[ ... ]
Quoted 4 lines
net/core/filter.c +0
-0[ ... ]
Quoted 9 lines
net/core/filter.c +9
-0+__bpf_kfunc int bpf_skb_complete_tx_tstamp(struct __sk_buff *s, +struct bpf_tx_tstamp_cmpl *attrs, +int attrs__sz) +{ +struct sk_buff *skb = (struct sk_buff *)s; +struct bpf_redirect_info *ri; +struct sock *sk = skb->sk; +s32 delta; +
Quoted 8 lines
net/core/filter.c __bpf_kfunc int bpf_skb_set_hwtstamp(struct __sk_buff *s, · line 12427
Quoted 5 lines
net/core/filter.c +5
-0+if (attrs__sz !=sizeof (*attrs) || attrs->reserved) +return -EINVAL ; + +if (!sk || !sk_fullsock (sk)) +return -EINVAL ;[Severity: High]
Should this function verify it is only called on ingress?
Right, I'll add it.
Quoted 21 lines
Without checking
skb_at_tc_ingress(skb),bpf_skb_complete_tx_tstamp()could be called on egress. If that happens and the program returnsTCX_ERRQUEUE, the completion state would be silently discarded and the packet transmitted becausesch_handle_egress()does not currently handleTC_ACT_ERRQUEUE.Quoted 15 lines
net/core/filter.c +15
-0+ +if (attrs->payload_offset > skb->len) +return -EINVAL ; + + delta = attrs->payload_offset - attrs->network_offset; +switch (attrs->protocol) { +case htons (ETH_P_IP ): +if (delta < (s32 )sizeof (struct iphdr ) || !sk_is_inet (sk)) +return -EINVAL ; +break ; +case htons (ETH_P_IPV6 ): +if (delta < (s32 )sizeof (struct ipv6hdr ) || sk->sk_family !=AF_INET6 ) +return -EINVAL ; +break ; +default :
Quoted 8 lines
net/core/filter.c __bpf_kfunc int bpf_skb_set_hwtstamp(struct __sk_buff *s, · line 12446
Quoted 4 lines
net/core/filter.c +4
-0+return -EAFNOSUPPORT ; + } + + ri =bpf_net_ctx_get_ri ();[Severity: High]
This is a pre-existing issue, but canbpf_net_ctx_get_ri()trigger a NULL pointer dereference here under certain conditions?
This is orthogonal to this series.
Also, bpf_redirect() etc do not have NULL check too.
Quoted 14 lines
When a BPF program runs via
tcf_classify()from a traditional classful qdisc enqueue callback (like HTB),sch_handle_egress()has already cleared thebpf_net_ctx. Calling this kfunc in that scenario would causebpf_net_ctx_get_ri()to dereference a NULL pointer.net/core/filter.c __bpf_kfunc int bpf_skb_set_hwtstamp(struct __sk_buff *s, · line 12451
Quoted 5 lines
net/core/filter.c +5
-0+ ri->kern_flags |=BPF_RI_F_TX_TS_CMPL ; + ri->txtscmpl = *attrs; + +return 0 ; +}--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v1 bpf-next/net 4/5] bpf: Add kfunc to proxy TX HW Timestamp.
In reply to Kuniyuki IwashimaQuoted 5 lines · Kuniyuki Iwashima
include/linux/skbuff.h +0
-0
include/linux/skbuff.h struct bpf_hwtstamp { · line 4715
Quoted 10 lines
include/linux/skbuff.h +7
-0@@ -4706,6 +4706,14 @@ struct bpf_hwtstamp {u64 reserved; } __packed; +struct bpf_tx_tstamp_cmpl { +u32 tskey; +__be16 protocol; +u16 network_offset; +u16 payload_offset; +u16 reserved; +} __packed;
Here and in the prior patch..
let's not penalize modern architectures like x86 and arm64 just because somebody has sparc on the shelf that collects dust.
Also don't use 'u16 reserved'. 'u16 :16' is better from backward compat pov.
And consider addressing sashiko findings.
Everything with [high] or [critical] most likely needs to be fixed. [medium] and below is a grey zone.
pw-bot: cr
Re: [PATCH v1 bpf-next/net 4/5] bpf: Add kfunc to proxy TX HW Timestamp.
Quoted 10 lines · Alexei Starovoitov
Quoted 8 lines · Kuniyuki Iwashima
include/linux/skbuff.h +0
-0@@ -4706,6 +4706,14 @@ struct bpf_hwtstamp {u64 reserved; } __packed;
Quoted 11 lines
include/linux/skbuff.h struct bpf_hwtstamp { · line 4715
Quoted 7 lines
include/linux/skbuff.h +7
-0+struct bpf_tx_tstamp_cmpl { +u32 tskey; +__be16 protocol; +u16 network_offset; +u16 payload_offset; +u16 reserved; +} __packed;Here and in the prior patch..
let's not penalize modern architectures like x86 and arm64 just because somebody has sparc on the shelf that collects dust.
Oh, I didn't know __packed has such a side effect even with 4/8 byte-aligned struct. Will remove __packed.
Quoted 2 lines
Also don't use 'u16 reserved'. 'u16 :16' is better from backward compat pov.
Will use it and ensure 0-padding with memchr_inv().
Quoted 4 lines
And consider addressing sashiko findings.
Everything with [high] or [critical] most likely needs to be fixed. [medium] and below is a grey zone.
Sure, I'll reply to them.
Thanks !
PATCH 5/5 selftest: bpf: Add test for hwtstamp proxy.
In reply to Kuniyuki IwashimaThis selftest simulates the hardware timestamp proxy scenario mentioned in the previous commits using two UDP sockets.
Here, app_fd represents a standard socket application, and proxy_fd simulates a userspace proxy that receives and injects encapsulated packets from/to app_fd via a GENEVE device (geneve0).
TX:
1. app_fd sends data w/ SCM_TS_OPT_ID
2. BPF prog hooks at tc/egress of geneve0
3. BPF inserts the GENEVE option with Type 0x1 to save SCM_TS_OPT_ID
4. proxy_fd receives the encapsulated packet
5. proxy changes the option Type to 0x2 and sets TX hwtstamp
6. proxy sends it back to geneve0
7. BPF prog hooks at tc/ingress of geneve0
8. BPF extracts TX hwtstamp into skb
9. BPF looks up the app_fd socket
10. BPF enqueues skb to app_fd's sk->sk_error_queue
11. app_fd receives TX hwtstamp and verifies the value
RX:
12. proxy_fd generates RX packet from TX packet
by swapping src/dst in each header
13. proxy changes the option Type to 0x3 and sets RX hwtstamp
14. proxy sends the encapsulated packet to geneve0
15. BPF prog hooks at tc/ingress of geneve0
16. BPF extracts RX hwtstamp into skb
17. app_fd receives RX hwtstamp and verifies the value
The GENEVE TLV option is structured as follows:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Option Class | Type |0|0|0| Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | + HW Timestamp (8 bytes) + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Timestamp key (4 bytes) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Type:
- 0x1: TX packet
- 0x2: TX completion packet w/ TX hwtstamp
- 0x3: RX packet w/ RX hwtstamp
--- tools/testing/selftests/bpf/bpf_kfuncs.h | 10 + .../selftests/bpf/prog_tests/proxy_hwtstamp.c | 580 ++++++++++++++++++ .../selftests/bpf/progs/bpf_tracing_net.h | 1 + .../selftests/bpf/progs/proxy_hwtstamp.c | 234 +++++++ 4 files changed, 825 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c create mode 100644 tools/testing/selftests/bpf/progs/proxy_hwtstamp.c
tools/testing/selftests/bpf/bpf_kfuncs.h +10 -0
@@ -92,4 +92,14 @@ extern int bpf_set_dentry_xattr(struct dentry *dentry, const char *name__str, const struct bpf_dynptr *value_p, int flags) __ksym __weak; extern int bpf_remove_dentry_xattr(struct dentry *dentry, const char *name__str) __ksym __weak; +extern int bpf_skb_scrub_tx_tstamp(struct __sk_buff *s) __ksym __weak; + +struct bpf_hwtstamp ; +extern int bpf_skb_set_hwtstamp(struct __sk_buff *s, + struct bpf_hwtstamp *attrs, int attrs__sz) __ksym __weak; + +struct bpf_tx_tstamp_cmpl ; +extern int bpf_skb_complete_tx_tstamp(struct __sk_buff *s, + struct bpf_tx_tstamp_cmpl *attrs, + int attrs__sz) __ksym __weak;#endif
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +580 -0
580 lines not on this page · raw message
tools/testing/selftests/bpf/progs/bpf_tracing_net.h +1 -0
@@ -73,6 +73,7 @@#define ETH_P_IPV6 0x86DD#define NEXTHDR_TCP 6 +#define NEXTHDR_UDP 17#define TCPOPT_NOP 1#define TCPOPT_EOL 0
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +234 -0
234 lines not on this page · raw message
Signature · 1 line
2.54.0.1136.gdb2ca164c4-goog
[email protected]
AI reviewRe: [PATCH v1 bpf-next/net 5/5] selftest: bpf: Add test for hwtstamp proxy.
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] Comparing a potentially negative return value to `sizeof()` causes failure handling to be skipped…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Comparing a potentially negative return value to sizeof() causes failure handling to be skipped, erroneously dropping packets.
- [Medium] Incorrect struct cast for SO_TIMESTAMPING_NEW cmsg data causes test failures on 32-bit systems.
- [Medium] Typo in the test assertion prevents verification of TX timestamp keys.
- [Low] Multi-line comments violate the BPF subsystem comment style.
- [Low] The buf_cmsg array is not fully initialized before being passed to sendmsg(), passing uninitialized stack data to the kernel. --
commit e747f30190af013f6f5cc858f0dacb86e902e2d2
Author: Kuniyuki Iwashima <[email protected]>
selftest: bpf: Add test for hwtstamp proxy.
This selftest simulates the hardware timestamp proxy scenario using two UDP sockets, simulating a userspace proxy via a GENEVE device.
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +0
-0
[ ... ]
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c line 151
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +10
-0+char *ipv4_commands[] = { +"ip link set dev lo up" , +"ip link add geneve0 type geneve local " APP_SRC_IPV4 " external" , +"ip addr add " APP_SRC_IPV4 "/24 dev geneve0" , +"ip link set dev geneve0 address aa:bb:cc:dd:ee:ff" , +"ip link set dev geneve0 up" , +"ip route add " APP_DST_IPV4 "/32 dev geneve0" , +/* We do not forward ARP to the wire in this test, +* so a static neighbour entry is needed for APP_DST_IPV4. +*/
[Severity: Low]
Does this multi-line comment format violate the BPF subsystem comment style? It seems the subsystem guidelines prefer the opening /* on its own line for multi-line comments.
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +2
-0+ "ip neigh add " APP_DST_IPV4 " lladdr ab:bc:cd:de:ef:fa dev geneve0", +};
[ ... ]
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +2
-0+static int check_tstamp (struct proxy_hwtstamp_test_case *test_case,bool tx) +{
[ ... ]
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c line 414
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +7
-0+for (cmsg =CMSG_FIRSTHDR (&msg); cmsg; cmsg =CMSG_NXTHDR (&msg, cmsg)) { +if (cmsg->cmsg_level ==SOL_SOCKET && cmsg->cmsg_type ==SO_TIMESTAMPING_NEW ) { +struct scm_timestamping *ts; + + ts = (struct scm_timestamping *)CMSG_DATA (cmsg); +ASSERT_EQ (ts->ts[2 ].tv_sec,0 ,"tv_sec" ); +ASSERT_EQ (ts->ts[2 ].tv_nsec,HWTSTAMP ,"tv_nsec" );
[Severity: Medium]
Since the test requests SO_TIMESTAMPING_NEW, the kernel will return timestamps using the 64-bit time architecture (via struct scm_timestamping64). Could casting CMSG_DATA(cmsg) to struct scm_timestamping * cause issues on 32-bit architectures where time_t is 32-bit?
It looks like this might misalign the array access, reading the zeroed software timestamp ts[1] instead of the hardware timestamp, potentially causing the test to fail.
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +6
-0+ + saw_tstamp = true; + }else if ((cmsg->cmsg_level ==SOL_IP && cmsg->cmsg_type ==IP_RECVERR ) || + (cmsg->cmsg_level ==SOL_IPV6 && cmsg->cmsg_type ==IPV6_RECVERR )) { +struct sock_extended_err *ee; +
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c line 430
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +10
-0+ ee = (struct sock_extended_err *)CMSG_DATA (cmsg); + +if (ee->ee_origin ==SO_EE_ORIGIN_TIMESTAMPING ) { +ASSERT_EQ (ee->ee_data,TSKEY ,"tskey" ); + saw_tskey = true; + } + } + } + +ASSERT_TRUE (saw_tstamp && (!tx || saw_tstamp),"no timestamp" );
[Severity: Medium]
Should this check validate saw_tskey instead of checking saw_tstamp twice? It looks like if the kernel fails to deliver the timestamp key, this check will silently pass, potentially hiding regressions.
Quoted 20 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +20
-0+ +return ret; +} + +static int test_proxy_hwtstamp_tx (struct proxy_hwtstamp_test_case *test_case) +{ +char h_source_dummy[ETH_HLEN ] = {0xFF ,0xEE ,0xDD ,0xCC ,0xBB ,0xAA }; +char buf_cmsg[CMSG_SPACE (sizeof (u32))]; +struct proxy_header *phdr; +struct msghdr msg = {}; +struct iovec iov = {}; +struct cmsghdr *cmsg; +int ret; + +memset (test_case->app_payload,0xAB ,sizeof (test_case->app_payload)); + iov.iov_base = test_case->app_payload; + iov.iov_len =sizeof (test_case->app_payload); + + msg.msg_iov = &iov; + msg.msg_iovlen =1 ;
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c line 460
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +10
-0+ msg.msg_control = buf_cmsg; + msg.msg_controllen =sizeof (buf_cmsg); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_TS_OPT_ID ; + cmsg->cmsg_len =CMSG_LEN (sizeof (u32)); + *(u32 *)CMSG_DATA (cmsg) =TSKEY ; + + ret =sendmsg (test_case->app_fd, &msg,0 );
[Severity: Low]
Is it possible that uninitialized stack memory from buf_cmsg is being passed to the kernel here?
Only the first CMSG_LEN bytes are initialized, but msg_controllen is set to the full CMSG_SPACE size which includes uninitialized alignment padding. Could this trigger MemorySanitizer warnings?
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +2
-0+if (!ASSERT_EQ (ret,sizeof (test_case->app_payload),"send" )) +return -1 ;
[ ... ]
Quoted 5 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +0
-0
[ ... ]
Quoted 3 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +3
-0+SEC("tcx/egress") +int proxy_hwtstamp_egress (struct __sk_buff *skb) +{
[ ... ]
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c line 49
Quoted 6 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +6
-0+ kskb =bpf_cast_to_kern_ctx (skb); + shared_info = bpf_core_cast(kskb->head + kskb->end, struct skb_shared_info); +if (!shared_info->tx_flags) { +/* If TX tstamp is not needed, don't insert the GENEVE option. +* The proxy socket will see genevehdr.opt_len == 0. +*/
[Severity: Low]
Does this multi-line comment format violate the BPF subsystem comment style? It seems the subsystem guidelines prefer the opening /* on its own line for multi-line comments.
Quoted 2 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +2
-0+ goto pass; + }
[ ... ]
Quoted 8 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +8
-0+SEC("tcx/ingress") +int proxy_hwtstamp_ingress (struct __sk_buff *skb) +{ +struct proxy_hwtstamp_opt opt; +struct bpf_tunnel_key key; +int ret; + +/* Get the GENEVE header. */
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c line 206
Quoted 10 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +10
-0+ ret =bpf_skb_get_tunnel_key (skb, &key,sizeof (key), tunnel_rx_flags); +if (ret <0 ) + goto drop; + +if (key.tunnel_id !=GENEVE_VNI ) + goto drop; + +/* Get the GENEVE option. */ + ret =bpf_skb_get_tunnel_opt (skb, &opt,sizeof (opt)); +if (ret <sizeof (opt)) {
[Severity: High]
Can this check drop packets without a GENEVE option?
bpf_skb_get_tunnel_opt() returns a signed integer, but sizeof(opt) is unsigned. If the return value is negative (e.g., -ENOENT), it will be promoted to a large unsigned integer during the comparison.
Would this cause ret < sizeof(opt) to evaluate to false and skip the failure handling, inadvertently dropping legitimate traffic?
Quoted 5 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +5
-0+/* If TX/RX tstamp is not needed, the proxy socket +* does not insert the GENEVE option. +*/ + goto pass; + }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v1 bpf-next/net 5/5] selftest: bpf: Add test for hwtstamp proxy.
Quoted 34 lines · On Thu, Jun 11, 2026 at 5:31 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Comparing a potentially negative return value tosizeof()causes failure handling to be skipped, erroneously dropping packets.
- [Medium] Incorrect struct cast forSO_TIMESTAMPING_NEWcmsg data causes test failures on 32-bit systems.
- [Medium] Typo in the test assertion prevents verification of TX timestamp keys.
- [Low] Multi-line comments violate the BPF subsystem comment style.
- [Low] Thebuf_cmsgarray is not fully initialized before being passed tosendmsg(), passing uninitialized stack data to the kernel. --commit
e747f30190af013f6f5cc858f0dacb86e902e2d2
Author: Kuniyuki Iwashima <[email protected]>selftest: bpf: Add test for hwtstamp proxy.
This selftest simulates the hardware timestamp proxy scenario using two UDP sockets, simulating a userspace proxy via a GENEVE device.
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +0
-0[ ... ]
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c line 151
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +10
-0+char *ipv4_commands[] = { +"ip link set dev lo up" , +"ip link add geneve0 type geneve local " APP_SRC_IPV4 " external" , +"ip addr add " APP_SRC_IPV4 "/24 dev geneve0" , +"ip link set dev geneve0 address aa:bb:cc:dd:ee:ff" , +"ip link set dev geneve0 up" , +"ip route add " APP_DST_IPV4 "/32 dev geneve0" , +/* We do not forward ARP to the wire in this test, +* so a static neighbour entry is needed for APP_DST_IPV4. +*/
Quoted 4 lines
[Severity: Low]
Does this multi-line comment format violate the BPF subsystem comment style? It seems the subsystem guidelines prefer the opening /* on its own line for multi-line comments.
Gray zone, this is rather net one :)
Quoted 15 lines
Quoted 3 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +2
-0+ "ip neigh add " APP_DST_IPV4 " lladdr ab:bc:cd:de:ef:fa dev geneve0", +};[ ... ]
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +2
-0+static int check_tstamp (struct proxy_hwtstamp_test_case *test_case,bool tx) +{[ ... ]
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c line 414
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +7
-0+for (cmsg =CMSG_FIRSTHDR (&msg); cmsg; cmsg =CMSG_NXTHDR (&msg, cmsg)) { +if (cmsg->cmsg_level ==SOL_SOCKET && cmsg->cmsg_type ==SO_TIMESTAMPING_NEW ) { +struct scm_timestamping *ts; + + ts = (struct scm_timestamping *)CMSG_DATA (cmsg); +ASSERT_EQ (ts->ts[2 ].tv_sec,0 ,"tv_sec" ); +ASSERT_EQ (ts->ts[2 ].tv_nsec,HWTSTAMP ,"tv_nsec" );
Quoted 5 lines
[Severity: Medium]
Since the test requestsSO_TIMESTAMPING_NEW, the kernel will return timestamps using the 64-bit time architecture (via structscm_timestamping64). Could castingCMSG_DATA(cmsg)to structscm_timestamping* cause issues on 32-bit architectures wheretime_tis 32-bit?
Indeed, I'll use scm_timestamping64 here.
Quoted 16 lines
It looks like this might misalign the array access, reading the zeroed software timestamp ts[1] instead of the hardware timestamp, potentially causing the test to fail.
Quoted 11 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +11
-0+ + saw_tstamp = true; + }else if ((cmsg->cmsg_level ==SOL_IP && cmsg->cmsg_type ==IP_RECVERR ) || + (cmsg->cmsg_level ==SOL_IPV6 && cmsg->cmsg_type ==IPV6_RECVERR )) { +struct sock_extended_err *ee; + + ee = (struct sock_extended_err *)CMSG_DATA (cmsg); + +if (ee->ee_origin ==SO_EE_ORIGIN_TIMESTAMPING ) { +ASSERT_EQ (ee->ee_data,TSKEY ,"tskey" ); + saw_tskey = true;
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c line 430
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +5
-0+ } + } + } + +ASSERT_TRUE (saw_tstamp && (!tx || saw_tstamp),"no timestamp" );[Severity: Medium]
Should this check validatesaw_tskeyinstead of checkingsaw_tstamptwice?
Yes, will update the latter check.
Quoted 29 lines
It looks like if the kernel fails to deliver the timestamp key, this check will silently pass, potentially hiding regressions.
Quoted 26 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +26
-0+ +return ret; +} + +static int test_proxy_hwtstamp_tx (struct proxy_hwtstamp_test_case *test_case) +{ +char h_source_dummy[ETH_HLEN ] = {0xFF ,0xEE ,0xDD ,0xCC ,0xBB ,0xAA }; +char buf_cmsg[CMSG_SPACE (sizeof (u32))]; +struct proxy_header *phdr; +struct msghdr msg = {}; +struct iovec iov = {}; +struct cmsghdr *cmsg; +int ret; + +memset (test_case->app_payload,0xAB ,sizeof (test_case->app_payload)); + iov.iov_base = test_case->app_payload; + iov.iov_len =sizeof (test_case->app_payload); + + msg.msg_iov = &iov; + msg.msg_iovlen =1 ; + msg.msg_control = buf_cmsg; + msg.msg_controllen =sizeof (buf_cmsg); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_TS_OPT_ID ;
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c line 460
Quoted 4 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +4
-0+ cmsg->cmsg_len =CMSG_LEN (sizeof (u32)); + *(u32 *)CMSG_DATA (cmsg) =TSKEY ; + + ret =sendmsg (test_case->app_fd, &msg,0 );[Severity: Low]
Is it possible that uninitialized stack memory frombuf_cmsgis being passed to the kernel here?
No. All fields are initialised here.
Quoted 25 lines
Only the first
CMSG_LENbytes are initialized, butmsg_controllenis set to the fullCMSG_SPACEsize which includes uninitialized alignment padding. Could this trigger MemorySanitizer warnings?Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +2
-0+if (!ASSERT_EQ (ret,sizeof (test_case->app_payload),"send" )) +return -1 ;[ ... ]
Quoted 5 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +0
-0[ ... ]
Quoted 3 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +3
-0+SEC("tcx/egress") +int proxy_hwtstamp_egress (struct __sk_buff *skb) +{[ ... ]
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c line 49
Quoted 6 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +6
-0+ kskb =bpf_cast_to_kern_ctx (skb); + shared_info = bpf_core_cast(kskb->head + kskb->end, struct skb_shared_info); +if (!shared_info->tx_flags) { +/* If TX tstamp is not needed, don't insert the GENEVE option. +* The proxy socket will see genevehdr.opt_len == 0. +*/
Quoted 4 lines
[Severity: Low]
Does this multi-line comment format violate the BPF subsystem comment style? It seems the subsystem guidelines prefer the opening /* on its own line for multi-line comments.
Same.
Quoted 26 lines
Quoted 3 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +2
-0+ goto pass; + }[ ... ]
Quoted 8 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +8
-0+SEC("tcx/ingress") +int proxy_hwtstamp_ingress (struct __sk_buff *skb) +{ +struct proxy_hwtstamp_opt opt; +struct bpf_tunnel_key key; +int ret; + +/* Get the GENEVE header. */ tools/testing/selftests/bpf/progs/proxy_hwtstamp.c line 206
Quoted 10 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +10
-0+ ret =bpf_skb_get_tunnel_key (skb, &key,sizeof (key), tunnel_rx_flags); +if (ret <0 ) + goto drop; + +if (key.tunnel_id !=GENEVE_VNI ) + goto drop; + +/* Get the GENEVE option. */ + ret =bpf_skb_get_tunnel_opt (skb, &opt,sizeof (opt)); +if (ret <sizeof (opt)) {[Severity: High]
Can this check drop packets without a GENEVE option?
Quoted 6 lines
bpf_skb_get_tunnel_opt()returns a signed integer, but sizeof(opt) is unsigned. If the return value is negative (e.g.,-ENOENT), it will be promoted to a large unsigned integer during the comparison.Would this cause ret < sizeof(opt) to evaluate to false and skip the failure handling, inadvertently dropping legitimate traffic?
Ugh, I'll cast sizeof() to int.
Quoted 9 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c line 211
Quoted 6 lines
tools/testing/selftests/bpf/progs/proxy_hwtstamp.c new file +5
-0+/* If TX/RX tstamp is not needed, the proxy socket +* does not insert the GENEVE option. +*/ + goto pass; + }--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v1 bpf-next/net 5/5] selftest: bpf: Add test for hwtstamp proxy.
Quoted 35 lines · Kuniyuki Iwashima
Quoted 34 lines · On Thu, Jun 11, 2026 at 5:31 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Comparing a potentially negative return value tosizeof()causes failure handling to be skipped, erroneously dropping packets.
- [Medium] Incorrect struct cast forSO_TIMESTAMPING_NEWcmsg data causes test failures on 32-bit systems.
- [Medium] Typo in the test assertion prevents verification of TX timestamp keys.
- [Low] Multi-line comments violate the BPF subsystem comment style.
- [Low] Thebuf_cmsgarray is not fully initialized before being passed tosendmsg(), passing uninitialized stack data to the kernel. --commit
e747f30190af013f6f5cc858f0dacb86e902e2d2
Author: Kuniyuki Iwashima <[email protected]>selftest: bpf: Add test for hwtstamp proxy.
This selftest simulates the hardware timestamp proxy scenario using two UDP sockets, simulating a userspace proxy via a GENEVE device.
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +0
-0[ ... ]
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +10
-0+char *ipv4_commands[] = { +"ip link set dev lo up" , +"ip link add geneve0 type geneve local " APP_SRC_IPV4 " external" , +"ip addr add " APP_SRC_IPV4 "/24 dev geneve0" , +"ip link set dev geneve0 address aa:bb:cc:dd:ee:ff" , +"ip link set dev geneve0 up" , +"ip route add " APP_DST_IPV4 "/32 dev geneve0" , +/* We do not forward ARP to the wire in this test, +* so a static neighbour entry is needed for APP_DST_IPV4. +*/
Quoted 6 lines
Quoted 4 lines
[Severity: Low]
Does this multi-line comment format violate the BPF subsystem comment style? It seems the subsystem guidelines prefer the opening /* on its own line for multi-line comments.Gray zone, this is rather net one :)
bot is correct on this one :) BPF prefers normal kernel coding style.
Re: [PATCH v1 bpf-next/net 5/5] selftest: bpf: Add test for hwtstamp proxy.
Quoted 37 lines · Alexei Starovoitov
Quoted 35 lines · Kuniyuki Iwashima
Quoted 34 lines · On Thu, Jun 11, 2026 at 5:31 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Comparing a potentially negative return value tosizeof()causes failure handling to be skipped, erroneously dropping packets.
- [Medium] Incorrect struct cast forSO_TIMESTAMPING_NEWcmsg data causes test failures on 32-bit systems.
- [Medium] Typo in the test assertion prevents verification of TX timestamp keys.
- [Low] Multi-line comments violate the BPF subsystem comment style.
- [Low] Thebuf_cmsgarray is not fully initialized before being passed tosendmsg(), passing uninitialized stack data to the kernel. --commit
e747f30190af013f6f5cc858f0dacb86e902e2d2
Author: Kuniyuki Iwashima <[email protected]>selftest: bpf: Add test for hwtstamp proxy.
This selftest simulates the hardware timestamp proxy scenario using two UDP sockets, simulating a userspace proxy via a GENEVE device.
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +0
-0[ ... ]
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/proxy_hwtstamp.c new file +10
-0+char *ipv4_commands[] = { +"ip link set dev lo up" , +"ip link add geneve0 type geneve local " APP_SRC_IPV4 " external" , +"ip addr add " APP_SRC_IPV4 "/24 dev geneve0" , +"ip link set dev geneve0 address aa:bb:cc:dd:ee:ff" , +"ip link set dev geneve0 up" , +"ip route add " APP_DST_IPV4 "/32 dev geneve0" , +/* We do not forward ARP to the wire in this test, +* so a static neighbour entry is needed for APP_DST_IPV4. +*/
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
[Severity: Low]
Does this multi-line comment format violate the BPF subsystem comment style? It seems the subsystem guidelines prefer the opening /* on its own line for multi-line comments.Gray zone, this is rather net one :)
bot is correct on this one :) BPF prefers normal kernel coding style.
Fair, will follow that ;)
Thanks !