bpf: Reject TCP_NODELAY in TCP header option
Subsystems (7)
v4 cover bpf: Reject TCP_NODELAY in TCP header option
This small patchset is about avoid infinite recursion in TCP header option callbacks and bpf-tcp-cc callbacks via TCP_NODELAY setsockopt.
v4:
- Fix the test case for TCP header option callbacks (Martin and Jiayuan)
- Reject TCP_NODELAY in bpf-tcp-cc callbacks (AI and Martin)
- Add a test case for bpf-tcp-cc
v3:
- Remove CONFIG_INET check and add comment (Martin and Jiayuan)
- Fix the test case (Martin)
https://lore.kernel.org/bpf/[email protected]/
v2:
- Reject TCP_NODELAY in bpf_sock_ops_setsockopt() (AI and Martin)
https://lore.kernel.org/bpf/[email protected]/
v1:
https://lore.kernel.org/bpf/[email protected]/
---
KaFai Wan (4):
bpf: Reject TCP_NODELAY in TCP header option callbacks
bpf: Reject TCP_NODELAY in bpf-tcp-cc selftests/bpf: Test TCP_NODELAY in TCP hdr opt callbacks selftests/bpf: Verify bpf-tcp-cc rejects TCP_NODELAY
include/linux/bpf.h | 1 + net/core/filter.c | 30 +++++++++++++++++++ net/ipv4/bpf_tcp_ca.c | 2 +- .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 4 +++ .../bpf/prog_tests/tcp_hdr_options.c | 6 ++++ tools/testing/selftests/bpf/progs/bpf_cubic.c | 12 ++++++++ .../bpf/progs/test_misc_tcp_hdr_options.c | 15 +++++++++- 7 files changed, 68 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
PATCH v4 1/4 bpf: Reject TCP_NODELAY in TCP header option callbacks
A BPF_SOCK_OPS program can enable BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG and then call bpf_setsockopt(TCP_NODELAY) from BPF_SOCK_OPS_HDR_OPT_LEN_CB or BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
In these callbacks, bpf_setsockopt(TCP_NODELAY) can reach __tcp_sock_set_nodelay(), which can call tcp_push_pending_frames().
From BPF_SOCK_OPS_HDR_OPT_LEN_CB, tcp_push_pending_frames() can call tcp_current_mss(), which calls tcp_established_options() and re-enters bpf_skops_hdr_opt_len().
BPF_SOCK_OPS_HDR_OPT_LEN_CB
-> bpf_setsockopt(TCP_NODELAY)
-> tcp_push_pending_frames()
-> tcp_current_mss()
-> tcp_established_options()
-> bpf_skops_hdr_opt_len()
-> BPF_SOCK_OPS_HDR_OPT_LEN_CBFrom BPF_SOCK_OPS_WRITE_HDR_OPT_CB, tcp_push_pending_frames() can call tcp_write_xmit(), which calls tcp_transmit_skb(). That path recomputes header option length through tcp_established_options() and bpf_skops_hdr_opt_len() before re-entering bpf_skops_write_hdr_opt().
BPF_SOCK_OPS_WRITE_HDR_OPT_CB
-> bpf_setsockopt(TCP_NODELAY)
-> tcp_push_pending_frames()
-> tcp_write_xmit()
-> tcp_transmit_skb()
-> tcp_established_options()
-> bpf_skops_hdr_opt_len()
-> bpf_skops_write_hdr_opt()
-> BPF_SOCK_OPS_WRITE_HDR_OPT_CBThis leads to unbounded recursion and can overflow the kernel stack.
Reject TCP_NODELAY with -EOPNOTSUPP in bpf_sock_ops_setsockopt() when bpf_setsockopt() is called from BPF_SOCK_OPS_HDR_OPT_LEN_CB or BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
--- net/core/filter.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/core/filter.c +6 -0
@@ -5833,6 +5833,12 @@ BPF_CALL_5(bpf_sock_ops_setsockopt, struct bpf_sock_ops_kern *, bpf_sock,if (!is_locked_tcp_sock_ops (bpf_sock))return -EOPNOTSUPP ; +/* TCP_NODELAY triggers tcp_push_pending_frames() and re-enters these callbacks. */ +if ((bpf_sock->op ==BPF_SOCK_OPS_HDR_OPT_LEN_CB || + bpf_sock->op ==BPF_SOCK_OPS_WRITE_HDR_OPT_CB ) && + level ==SOL_TCP && optname ==TCP_NODELAY ) +return -EOPNOTSUPP ; +return _bpf_setsockopt (bpf_sock->sk, level, optname, optval, optlen); }
Signature · 1 line
2.43.0
PATCH v4 2/4 bpf: Reject TCP_NODELAY in bpf-tcp-cc
In reply to KaFai WanA BPF TCP congestion control program can call bpf_setsockopt() from its callbacks. In current kernels, if it calls bpf_setsockopt(TCP_NODELAY) from cwnd_event_tx_start(), the call can re-enter the TCP transmit path before the outer tcp_transmit_skb() has completed and advanced the send head.
This can re-trigger CA_EVENT_TX_START and lead to unbounded recursion:
tcp_transmit_skb()
-> tcp_event_data_sent()
-> tcp_ca_event(sk, CA_EVENT_TX_START)
-> cwnd_event_tx_start()
-> bpf_setsockopt(TCP_NODELAY)
-> tcp_push_pending_frames()
-> tcp_write_xmit()
-> tcp_transmit_skb()This leads to unbounded recursion and can overflow the kernel stack.
Reject TCP_NODELAY with -EOPNOTSUPP for bpf-tcp-cc by introducing a dedicated setsockopt proto for BPF_PROG_TYPE_STRUCT_OPS TCP congestion control programs.
--- include/linux/bpf.h | 1 + net/core/filter.c | 24 ++++++++++++++++++++++++ net/ipv4/bpf_tcp_ca.c | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-)
include/linux/bpf.h +1 -0
@@ -3725,6 +3725,7 @@ extern const struct bpf_func_proto bpf_for_each_map_elem_proto;extern const struct bpf_func_proto bpf_btf_find_by_name_kind_proto;extern const struct bpf_func_proto bpf_sk_setsockopt_proto;extern const struct bpf_func_proto bpf_sk_getsockopt_proto; +extern const struct bpf_func_proto bpf_sk_setsockopt_nodelay_proto;extern const struct bpf_func_proto bpf_unlocked_sk_setsockopt_proto;extern const struct bpf_func_proto bpf_unlocked_sk_getsockopt_proto;extern const struct bpf_func_proto bpf_find_vma_proto;
net/core/filter.c +24 -0
@@ -5688,6 +5688,30 @@ const struct bpf_func_proto bpf_sk_getsockopt_proto = { .arg5_type = ARG_CONST_SIZE, }; +BPF_CALL_5(bpf_sk_setsockopt_nodelay, struct sock *, sk, int, level, + int, optname, char *, optval, int, optlen) +{ +/* +* TCP_NODELAY triggers tcp_push_pending_frames() and re-enters +* CA_EVENT_TX_START in bpf_tcp_cc, reject it in all bpf_tcp_cc. +*/ +if (level ==SOL_TCP && optname ==TCP_NODELAY ) +return -EOPNOTSUPP ; + +return _bpf_setsockopt (sk, level, optname, optval, optlen); +} + +const struct bpf_func_proto bpf_sk_setsockopt_nodelay_proto = { + .func = bpf_sk_setsockopt_nodelay, + .gpl_only = false, + .ret_type =RET_INTEGER , + .arg1_type =ARG_PTR_TO_BTF_ID_SOCK_COMMON , + .arg2_type =ARG_ANYTHING , + .arg3_type =ARG_ANYTHING , + .arg4_type =ARG_PTR_TO_MEM |MEM_RDONLY , + .arg5_type =ARG_CONST_SIZE , +}; + BPF_CALL_5(bpf_unlocked_sk_setsockopt, struct sock *, sk, int, level, int, optname, char *, optval, int, optlen) {
net/ipv4/bpf_tcp_ca.c +1 -1
@@ -168,7 +168,7 @@ bpf_tcp_ca_get_func_proto(enum bpf_func_id func_id,*/ if (prog_ops_moff (prog) != offsetof(struct tcp_congestion_ops , release)) -return &bpf_sk_setsockopt_proto; +return &bpf_sk_setsockopt_nodelay_proto;return NULL ;case BPF_FUNC_getsockopt:/* Since get/setsockopt is usually expected to
Signature · 1 line
2.43.0
PATCH v4 3/4 selftests/bpf: Test TCP_NODELAY in TCP hdr opt callbacks
In reply to KaFai WanAdd a sockops selftest for the TCP_NODELAY restriction in BPF_SOCK_OPS_HDR_OPT_LEN_CB and BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
With BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG enabled, bpf_setsockopt(TCP_NODELAY) returns -EOPNOTSUPP from BPF_SOCK_OPS_HDR_OPT_LEN_CB and BPF_SOCK_OPS_WRITE_HDR_OPT_CB, avoiding unbounded recursion and kernel stack overflow.
Other cases continue to work as before, includingBPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB.
--- .../selftests/bpf/prog_tests/tcp_hdr_options.c | 6 ++++++ .../bpf/progs/test_misc_tcp_hdr_options.c | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c +6 -0
@@ -507,6 +507,12 @@ static void misc(void)ASSERT_EQ (misc_skel->bss->nr_hwtstamp,0 ,"nr_hwtstamp" ); +ASSERT_TRUE (misc_skel->data->nodelay_est_ok,"nodelay_est_ok" ); + +ASSERT_TRUE (misc_skel->data->nodelay_hdr_len_reject,"nodelay_hdr_len_reject" ); + +ASSERT_TRUE (misc_skel->data->nodelay_write_hdr_reject,"nodelay_write_hdr_reject" ); + check_linum:ASSERT_FALSE (check_error_linum (&sk_fds),"check_error_linum" );sk_fds_close (&sk_fds);
tools/testing/selftests/bpf/progs/test_misc_tcp_hdr_options.c +14 -1
@@ -29,6 +29,10 @@ unsigned int nr_syn = 0;unsigned int nr_fin =0 ;unsigned int nr_hwtstamp =0 ; +bool nodelay_est_ok = true; +bool nodelay_hdr_len_reject = true; +bool nodelay_write_hdr_reject = true; +/* Check the header received from the active side */ static int __check_active_hdr_in (struct bpf_sock_ops *skops,bool check_syn) {
@@ -300,7 +304,7 @@ static int handle_passive_estab(struct bpf_sock_ops *skops) SEC("sockops")int misc_estab (struct bpf_sock_ops *skops) { -int true_val =1 ; +int true_val =1 , false_val =0 , ret;switch (skops->op) {case BPF_SOCK_OPS_TCP_LISTEN_CB :
@@ -316,10 +320,19 @@ int misc_estab(struct bpf_sock_ops *skops)case BPF_SOCK_OPS_PARSE_HDR_OPT_CB :return handle_parse_hdr (skops);case BPF_SOCK_OPS_HDR_OPT_LEN_CB : + ret =bpf_setsockopt (skops,SOL_TCP ,TCP_NODELAY , &true_val,sizeof (true_val)); + nodelay_hdr_len_reject &= ret == -EOPNOTSUPP ; +return handle_hdr_opt_len (skops);case BPF_SOCK_OPS_WRITE_HDR_OPT_CB : + ret =bpf_setsockopt (skops,SOL_TCP ,TCP_NODELAY , &true_val,sizeof (true_val)); + nodelay_write_hdr_reject &= ret == -EOPNOTSUPP ; +return handle_write_hdr_opt (skops);case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB : + ret =bpf_setsockopt (skops,SOL_TCP ,TCP_NODELAY , &false_val,sizeof (false_val)); + nodelay_est_ok &= ret ==0 ; +return handle_passive_estab (skops); }
Signature · 1 line
2.43.0
PATCH v4 4/4 selftests/bpf: Verify bpf-tcp-cc rejects TCP_NODELAY
In reply to KaFai WanAdd a bpf_tcp_ca selftest for the TCP_NODELAY restriction in bpf-tcp-cc.
Update bpf_cubic to exercise init() and cwnd_event_tx_start(), and check that both callbacks reject bpf_setsockopt(TCP_NODELAY) with -EOPNOTSUPP.
--- tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c | 4 ++++ tools/testing/selftests/bpf/progs/bpf_cubic.c | 12 ++++++++++++ 2 files changed, 16 insertions(+)
tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +4 -0
@@ -112,6 +112,10 @@ static void test_cubic(void)ASSERT_EQ (cubic_skel->bss->bpf_cubic_acked_called,1 ,"pkts_acked called" ); +ASSERT_TRUE (cubic_skel->data->nodelay_init_reject,"init reject nodelay option" ); +ASSERT_TRUE (cubic_skel->data->nodelay_cwnd_event_tx_start_reject, +"cwnd_event_tx_start reject nodelay option" ); +bpf_link__destroy (link);bpf_cubic__destroy (cubic_skel); }
tools/testing/selftests/bpf/progs/bpf_cubic.c +12 -0
@@ -16,6 +16,7 @@#include "bpf_tracing_net.h" #include <bpf/bpf_tracing.h> +#include <errno.h> char _license[] SEC("license") = "GPL";
@@ -170,10 +171,17 @@ static void bictcp_hystart_reset(struct sock *sk) ca->sample_cnt =0 ; } +bool nodelay_init_reject = true; +bool nodelay_cwnd_event_tx_start_reject = true; + SEC("struct_ops")void BPF_PROG (bpf_cubic_init ,struct sock *sk) {struct bpf_bictcp *ca =inet_csk_ca (sk); +int true_val =1 , ret; + + ret =bpf_setsockopt (sk,SOL_TCP ,TCP_NODELAY , &true_val,sizeof (true_val)); + nodelay_init_reject &= ret == -EOPNOTSUPP ;bictcp_reset (ca);
@@ -189,8 +197,12 @@ void BPF_PROG(bpf_cubic_cwnd_event_tx_start, struct sock *sk) {struct bpf_bictcp *ca =inet_csk_ca (sk);__u32 now = tcp_jiffies32; +int true_val =1 , ret;__s32 delta; + ret =bpf_setsockopt (sk,SOL_TCP ,TCP_NODELAY , &true_val,sizeof (true_val)); + nodelay_cwnd_event_tx_start_reject &= ret == -EOPNOTSUPP ; + delta = now -tcp_sk (sk)->lsndtime;/* We were application limited (idle) for a while.
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH bpf-next v4 1/4] bpf: Reject TCP_NODELAY in TCP header option callbacks
In reply to KaFai WanDoes this same recursion vulnerability exist for BPF TCP congestion control algorithms using BPF_PROG_TYPE_STRUCT_OPS?
Quoted 5 lines
net/core/filter.c +0
-0
net/core/filter.c BPF_CALL_5(bpf_sock_ops_setsockopt, struct bpf_sock_ops_kern *, bpf_sock, · line 5841
Quoted 9 lines
net/core/filter.c +6
-0@@ -5833,6 +5833,12 @@ BPF_CALL_5(bpf_sock_ops_setsockopt, struct bpf_sock_ops_kern *, bpf_sock,if (!is_locked_tcp_sock_ops (bpf_sock))return -EOPNOTSUPP ; +/* TCP_NODELAY triggers tcp_push_pending_frames() and re-enters these callbacks. */ +if ((bpf_sock->op ==BPF_SOCK_OPS_HDR_OPT_LEN_CB || + bpf_sock->op ==BPF_SOCK_OPS_WRITE_HDR_OPT_CB ) && + level ==SOL_TCP && optname ==TCP_NODELAY ) +return -EOPNOTSUPP ; +
Does this same recursion vulnerability exist for BPF TCP congestion control algorithms using BPF_PROG_TYPE_STRUCT_OPS?
If a BPF congestion control algorithm invokes bpf_setsockopt(TCP_NODELAY) from its cwnd_event callback when handling CA_EVENT_TX_START, could it trigger unbounded recursion through this path:
BPF_PROG_TYPE_STRUCT_OPS cwnd_event callback (CA_EVENT_TX_START)
-> bpf_setsockopt(TCP_NODELAY)
-> tcp_push_pending_frames()
-> tcp_write_xmit()
-> tcp_transmit_skb()
-> tcp_event_data_sent()
-> cwnd_event()
-> BPF congestion control cwnd_event callbackThe author confirmed this issue in the v3 discussion thread and Martin KaFai Lau suggested creating a new func_proto (bpf_sk_setsockopt_nodelay_proto) to reject TCP_NODELAY for all struct_ops programs, but this patch only addresses BPF_SOCK_OPS callbacks.
Reference: https://lore.kernel.org/bpf/[email protected]/
Does this fix also need to block TCP_CORK when the value is 0?
When bpf_setsockopt() is called with SOL_TCP and TCP_CORK with value 0 (disabling cork), the call path goes through __tcp_sock_set_cork() in net/ipv4/tcp.c, which unconditionally calls tcp_push_pending_frames(sk) when cork is disabled:
__tcp_sock_set_cork()
-> tcp_push_pending_frames()
-> tcp_current_mss()
-> tcp_established_options()
-> bpf_skops_hdr_opt_len()
-> BPF_SOCK_OPS_HDR_OPT_LEN_CBThis triggers the same recursion chain described in the commit message, but the patch only blocks TCP_NODELAY, not TCP_CORK with value 0.
net/core/filter.c BPF_CALL_5(bpf_sock_ops_setsockopt, struct bpf_sock_ops_kern *, bpf_sock, · line 5844
Quoted 3 lines
net/core/filter.c +0
-0return _bpf_setsockopt (bpf_sock->sk, level, optname, optval, optlen); }
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/24733356810
Re: [PATCH bpf-next v4 1/4] bpf: Reject TCP_NODELAY in TCP header option callbacks
Quoted 31 lines · On Tue, 2026-04-21 at 16:51 +0000, [email protected] wrote:
Quoted 5 lines
net/core/filter.c +0
-0net/core/filter.c BPF_CALL_5(bpf_sock_ops_setsockopt, struct bpf_sock_ops_kern *, bpf_sock, · line 5841
Quoted 9 lines
net/core/filter.c +6
-0@@ -5833,6 +5833,12 @@ BPF_CALL_5(bpf_sock_ops_setsockopt, struct bpf_sock_ops_kern *, bpf_sock, if (!is_locked_tcp_sock_ops(bpf_sock)) return -EOPNOTSUPP; +/* TCP_NODELAY triggers tcp_push_pending_frames() and re-enters these callbacks. */ +if ((bpf_sock->op ==BPF_SOCK_OPS_HDR_OPT_LEN_CB || + bpf_sock->op == BPF_SOCK_OPS_WRITE_HDR_OPT_CB) && + level == SOL_TCP && optname == TCP_NODELAY) +return -EOPNOTSUPP ; +Does this same recursion vulnerability exist for BPF TCP congestion control algorithms using
BPF_PROG_TYPE_STRUCT_OPS?If a BPF congestion control algorithm invokes
bpf_setsockopt(TCP_NODELAY)from itscwnd_eventcallback when handlingCA_EVENT_TX_START, could it trigger unbounded recursion through this path:
BPF_PROG_TYPE_STRUCT_OPScwnd_eventcallback (CA_EVENT_TX_START) ->bpf_setsockopt(TCP_NODELAY)
->tcp_push_pending_frames()
->tcp_write_xmit()
->tcp_transmit_skb()
->tcp_event_data_sent()
->cwnd_event()
-> BPF congestion controlcwnd_eventcallback
Quoted 4 lines
The author confirmed this issue in the v3 discussion thread and Martin KaFai Lau suggested creating a new
func_proto(bpf_sk_setsockopt_nodelay_proto) to rejectTCP_NODELAYfor allstruct_opsprograms, but this patch only addressesBPF_SOCK_OPScallbacks.
patch#2 ("bpf: Reject TCP_NODELAY in bpf-tcp-cc") fix this, pls check.
Quoted 5 lines
Reference: https://lore.kernel.org/bpf/[email protected]/
Does this fix also need to block
TCP_CORKwhen the value is 0?
TCP_CORK is not support, return -EINVAL by default in sol_tcp_sockopt().
Quoted 29 lines
When
bpf_setsockopt()is called withSOL_TCPandTCP_CORKwith value 0 (disabling cork), the call path goes through__tcp_sock_set_cork()innet/ipv4/tcp.c, which unconditionally callstcp_push_pending_frames(sk)when cork is disabled:
__tcp_sock_set_cork()
->tcp_push_pending_frames()
->tcp_current_mss()
->tcp_established_options()
->bpf_skops_hdr_opt_len()
->BPF_SOCK_OPS_HDR_OPT_LEN_CBThis triggers the same recursion chain described in the commit message, but the patch only blocks
TCP_NODELAY, notTCP_CORKwith value 0.net/core/filter.c BPF_CALL_5(bpf_sock_ops_setsockopt, struct bpf_sock_ops_kern *, bpf_sock, · line 5844
Quoted 3 lines
net/core/filter.c +0
-0return _bpf_setsockopt(bpf_sock->sk, level, optname, optval, optlen); }---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.mdCI run summary: https://github.com/kernel-patches/bpf/actions/runs/24733356810
Signature · 2 lines
Thanks, KaFai
Re: [PATCH bpf-next v4 2/4] bpf: Reject TCP_NODELAY in bpf-tcp-cc
In reply to KaFai WanQuoted 19 lines · KaFai Wan
A BPF TCP congestion control program can call
bpf_setsockopt()from its callbacks. In current kernels, if it callsbpf_setsockopt(TCP_NODELAY)fromcwnd_event_tx_start(), the call can re-enter the TCP transmit path before the outertcp_transmit_skb()has completed and advanced the send head.This can re-trigger
CA_EVENT_TX_STARTand lead to unbounded recursion:tcp_transmit_skb() -> tcp_event_data_sent() -> tcp_ca_event(sk, CA_EVENT_TX_START) -> cwnd_event_tx_start() -> bpf_setsockopt(TCP_NODELAY) -> tcp_push_pending_frames() -> tcp_write_xmit() -> tcp_transmit_skb()This leads to unbounded recursion and can overflow the kernel stack.
Quoted 7 lines
Reject
TCP_NODELAYwith-EOPNOTSUPPfor bpf-tcp-cc by introducing a dedicated setsockopt proto forBPF_PROG_TYPE_STRUCT_OPSTCP congestion control programs.Fixes 7e41df5dbba2 ("bpf: Add a few optnames to bpf_setsockopt")Suggested-by Martin KaFai Lau <[email protected]>Signed-off-by KaFai Wan <[email protected]>
[email protected]
AI reviewRe: [PATCH bpf-next v4 4/4] selftests/bpf: Verify bpf-tcp-cc rejects TCP_NODELAY
In reply to KaFai WanSashiko AI review found 2 potential issue(s): - [Medium] Test logic allows vacuous passes if BPF callbacks are never executed. - [Low] Type mismatch for `bpf_setsockopt` return value. --
Sashiko AI review found 2 potential issue(s):
- [Medium] Test logic allows vacuous passes if BPF callbacks are never executed.
- [Low] Type mismatch for bpf_setsockopt return value.
--
commit 8a4ced8128582d3995376457598fd25202c0468a
Author: KaFai Wan <[email protected]>
selftests/bpf: Verify bpf-tcp-cc rejects TCP_NODELAY
This commit adds a bpf_tcp_ca selftest to verify that the TCP_NODELAY restriction is properly enforced in bpf-tcp-cc. It updates bpf_cubic to exercise the init() and cwnd_event_tx_start() callbacks, ensuring both reject the option with -EOPNOTSUPP.
Quoted 4 lines
tools/testing/selftests/bpf/progs/bpf_cubic.c +0
-0
[ ... ]
tools/testing/selftests/bpf/progs/bpf_cubic.c static void bictcp_hystart_reset(struct sock *sk) · line 175
Quoted 6 lines
tools/testing/selftests/bpf/progs/bpf_cubic.c +2
-0@@ -170,10 +171,17 @@ static void bictcp_hystart_reset(struct sock *sk) ca->sample_cnt =0 ; } +bool nodelay_init_reject = true; +bool nodelay_cwnd_event_tx_start_reject = true;
Can this test pass vacuously? Since these boolean variables are statically initialized to true and the callbacks update them using a bitwise AND, the userspace assertions will pass even if the callbacks are never executed.
Would it be safer to add explicit execution counters (like the existing bpf_cubic_acked_called) to ensure the callbacks actually run during the test workload?
tools/testing/selftests/bpf/progs/bpf_cubic.c static void bictcp_hystart_reset(struct sock *sk) · line 183
Quoted 8 lines
tools/testing/selftests/bpf/progs/bpf_cubic.c +4
-0+ SEC("struct_ops")void BPF_PROG (bpf_cubic_init ,struct sock *sk) {struct bpf_bictcp *ca =inet_csk_ca (sk); +int true_val =1 , ret; + + ret =bpf_setsockopt (sk,SOL_TCP ,TCP_NODELAY , &true_val,sizeof (true_val));
This isn't a bug since we only expect a small negative constant here, but bpf_setsockopt() returns a long. Could assigning the return value to an int cause unintended truncation issues in the future?
Quoted 4 lines
tools/testing/selftests/bpf/progs/bpf_cubic.c +1
-0+ nodelay_init_reject &= ret == -EOPNOTSUPP ;bictcp_reset (ca);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
This series was applied to bpf/bpf.git (master) by Martin KaFai Lau <[email protected]>:
Hello:
This series was applied to bpf/bpf.git (master)
by Martin KaFai Lau <[email protected]>:
Quoted 9 lines · On Tue, 21 Apr 2026 23:58:00 +0800 you wrote:
This small patchset is about avoid infinite recursion in TCP header option callbacks and bpf-tcp-cc callbacks via
TCP_NODELAYsetsockopt.v4:
- Fix the test case for TCP header option callbacks (Martin and Jiayuan)
- RejectTCP_NODELAYin bpf-tcp-cc callbacks (AI and Martin)
- Add a test case for bpf-tcp-cc[...]
Here is the summary with links:
- [bpf-next,v4,1/4] bpf: Reject TCP_NODELAY in TCP header option callbacks
https://git.kernel.org/bpf/bpf/c/846c76ecc029 - [bpf-next,v4,2/4] bpf: Reject TCP_NODELAY in bpf-tcp-cc https://git.kernel.org/bpf/bpf/c/54377fcab51f - [bpf-next,v4,3/4] selftests/bpf: Test TCP_NODELAY in TCP hdr opt callbacks https://git.kernel.org/bpf/bpf/c/52b6b5334924 - [bpf-next,v4,4/4] selftests/bpf: Verify bpf-tcp-cc rejects TCP_NODELAY https://git.kernel.org/bpf/bpf/c/2c7e33f1fc2e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html