| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/06 20:07 | flow | patch-triage |
8mArgs:null Results: {
"EnableConfigs": [
"INET",
"CGROUPS",
"CGROUP_BPF",
"BPF_SYSCALL",
"BPF_JIT",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"bpf_tcp_ops_set_flags",
"bpf_tcp_ops_set_rcvlowat",
"__tcp_set_rcvlowat",
"tcp_set_rcvlowat",
"tcp_fastopen_add_skb"
],
"KMSANReasoning": "The patch adds BPF struct_ops callback support and flag-based invocation for TCP receive queue operations (enqueue_rcvq, dequeue_rcvq) and refactors existing TCP BPF hook calling paths.\n\nEvaluation against KMSAN criteria:\n1. No structures are copied to user space; no copy_to_user, put_user, netlink attributes, or ioctl/sockopt data disclosures to user space are introduced or altered.\n2. The newly added struct member (bpf_tcp_ops_flags in struct tcp_sock) resides in a zero-allocated structure (via sk_alloc with __GFP_ZERO) and is explicitly reset in tcp_clear_sock_ops_cb_flags().\n3. All local variables and arrays (such as __args[] in tcp_call_bpf_flag and sock_ops in __tcp_call_bpf) are fully initialized before read access.\n4. Any potential issues stemming from BPF callback invocation, such as socket reference safety, concurrent access to tcp_sock fields, or skb management, fall into concurrency, NULL dereference, or lifetime categories covered by LOCKDEP and KASAN, rather than uninitialized memory reads.\n\nTherefore, the patch introduces no uninitialized memory risks or info-leaks that would require a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false,
"Reasoning": "The patch series introduces new bpf_tcp_ops flags and callbacks (enqueue_rcvq, dequeue_rcvq) in core TCP hot paths, along with new BPF kfuncs (bpf_tcp_ops_set_flags and bpf_tcp_ops_set_rcvlowat) and logic for dynamic SO_RCVLOWAT tuning. These changes affect reachable TCP input/output paths and BPF struct_ops handling, making them relevant for fuzzing.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/06 20:07 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 03049c52daff18ae374ab888a324b6713ecef26a\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Tue Oct 6 20:07:14 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst\nindex 0f6088c4ab8bb..e4776905e8821 100644\n--- a/Documentation/networking/net_cachelines/tcp_sock.rst\n+++ b/Documentation/networking/net_cachelines/tcp_sock.rst\n@@ -151,6 +151,7 @@ u32 urg_seq\n unsigned_int keepalive_time\n unsigned_int keepalive_intvl\n int linger2\n+u32 bpf_tcp_ops_flags read_mostly read_mostly bpf_tcp_ops_hdr_opt_len,bpf_skops_write_hdr_opt(tx);bpf_tcp_ops_parse_hdr,tcp_bpf_rtt,tcp_cleanup_rbuf,tcp_queue_rcv,tcp_ofo_queue,tcp_fastopen_add_skb(rx);\n u8 bpf_sock_ops_cb_flags\n u8:1 bpf_chg_cc_inprogress\n u16 timeout_rehash\ndiff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h\nindex 8a75a6cd73096..02ef7f899b3de 100644\n--- a/include/linux/bpf-cgroup.h\n+++ b/include/linux/bpf-cgroup.h\n@@ -345,27 +345,19 @@ static inline bool cgroup_bpf_sock_enabled(struct sock *sk,\n * calling bpf_setsockopt on listener-sk will not make sense anyway,\n * so passing 'sock_ops-\u003esk == req_sk' to the bpf prog is appropriate here.\n */\n-#define BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(sock_ops, sk)\t\t\t\\\n-({\t\t\t\t\t\t\t\t\t\\\n-\tint __ret = 0;\t\t\t\t\t\t\t\\\n-\tif (cgroup_bpf_enabled(CGROUP_SOCK_OPS))\t\t\t\\\n-\t\t__ret = __cgroup_bpf_run_filter_sock_ops(sk,\t\t\\\n-\t\t\t\t\t\t\t sock_ops,\t\\\n-\t\t\t\t\t\t\t CGROUP_SOCK_OPS); \\\n-\t__ret;\t\t\t\t\t\t\t\t\\\n-})\n-\n-#define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops)\t\t\t\t \\\n-({\t\t\t\t\t\t\t\t\t \\\n-\tint __ret = 0;\t\t\t\t\t\t\t \\\n-\tif (cgroup_bpf_enabled(CGROUP_SOCK_OPS) \u0026\u0026 (sock_ops)-\u003esk) { \\\n-\t\ttypeof(sk) __sk = sk_to_full_sk((sock_ops)-\u003esk);\t \\\n-\t\tif (__sk \u0026\u0026 sk_fullsock(__sk))\t\t\t\t \\\n-\t\t\t__ret = __cgroup_bpf_run_filter_sock_ops(__sk,\t \\\n-\t\t\t\t\t\t\t\t sock_ops, \\\n-\t\t\t\t\t\t\t CGROUP_SOCK_OPS); \\\n-\t}\t\t\t\t\t\t\t\t \\\n-\t__ret;\t\t\t\t\t\t\t\t \\\n+#define __BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(sock_ops, sk)\t\t\t\t\\\n+\t__cgroup_bpf_run_filter_sock_ops(sk, sock_ops,\t\t\t\t\\\n+\t\t\t\t\t CGROUP_SOCK_OPS)\n+\n+#define __BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops)\t\t\t\t\\\n+({\t\t\t\t\t\t\t\t\t\t\\\n+\tint __ret = 0;\t\t\t\t\t\t\t\t\\\n+\ttypeof(sk) __sk = sk_to_full_sk((sock_ops)-\u003esk);\t\t\t\\\n+\tif (__sk \u0026\u0026 sk_fullsock(__sk))\t\t\t\t\t\t\\\n+\t\t__ret = __cgroup_bpf_run_filter_sock_ops(__sk,\t\t\t\\\n+\t\t\t\t\t\t\t sock_ops,\t\t\\\n+\t\t\t\t\t\t\t CGROUP_SOCK_OPS);\t\\\n+\t__ret;\t\t\t\t\t\t\t\t\t\\\n })\n \n #define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(atype, major, minor, access)\t \\\n@@ -529,7 +521,7 @@ static inline int cgroup_bpf_struct_ops_attach(struct bpf_map *map,\n #define BPF_CGROUP_RUN_PROG_UDP4_RECVMSG_LOCK(sk, uaddr, uaddrlen) ({ 0; })\n #define BPF_CGROUP_RUN_PROG_UDP6_RECVMSG_LOCK(sk, uaddr, uaddrlen) ({ 0; })\n #define BPF_CGROUP_RUN_PROG_UNIX_RECVMSG_LOCK(sk, uaddr, uaddrlen) ({ 0; })\n-#define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; })\n+#define __BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; })\n #define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(atype, major, minor, access) ({ 0; })\n #define BPF_CGROUP_RUN_PROG_SYSCTL(head,table,write,buf,count,pos) ({ 0; })\n #define BPF_CGROUP_RUN_PROG_GETSOCKOPT(sock, level, optname, optval, \\\ndiff --git a/include/linux/tcp.h b/include/linux/tcp.h\nindex 6a8c77719322f..24bb751cc65a6 100644\n--- a/include/linux/tcp.h\n+++ b/include/linux/tcp.h\n@@ -233,6 +233,13 @@ struct tcp_sock {\n \t\tis_sack_reneg:1, /* in recovery from loss with SACK reneg? */\n \t\tis_cwnd_limited:1,/* forward progress limited by snd_cwnd? */\n \t\trecvmsg_inq : 1;/* Indicate # of bytes in queue upon recvmsg */\n+#ifdef CONFIG_BPF\n+\tu32\tbpf_tcp_ops_flags;\n+#define BPF_TCP_OPS_TEST_FLAG(TP, ARG) \\\n+\t(READ_ONCE((TP)-\u003ebpf_tcp_ops_flags) \u0026 BPF_TCP_OPS_FLAG_ ## ARG)\n+#else\n+#define BPF_TCP_OPS_TEST_FLAG(TP, ARG) (0)\n+#endif\n \t__cacheline_group_end(tcp_sock_read_txrx);\n \n \t/* RX read-mostly hotpath cache lines */\ndiff --git a/include/net/tcp.h b/include/net/tcp.h\nindex 4ecabf4989de9..f7624ab9b4208 100644\n--- a/include/net/tcp.h\n+++ b/include/net/tcp.h\n@@ -512,6 +512,7 @@ void tcp_set_keepalive(struct sock *sk, int val);\n void tcp_syn_ack_timeout(const struct request_sock *req);\n int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,\n \t\tint flags);\n+int __tcp_set_rcvlowat(struct sock *sk, int val, bool wakeup);\n int tcp_set_rcvlowat(struct sock *sk, int val);\n void tcp_set_rcvbuf(struct sock *sk, int val);\n int tcp_set_window_clamp(struct sock *sk, int val);\n@@ -2891,7 +2892,7 @@ static inline void bpf_skops_init_skb(struct bpf_sock_ops_kern *skops,\n * program loaded).\n */\n #ifdef CONFIG_BPF\n-static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)\n+static inline int __tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)\n {\n \tstruct bpf_sock_ops_kern sock_ops;\n \tint ret;\n@@ -2908,7 +2909,7 @@ static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)\n \tif (nargs \u003e 0)\n \t\tmemcpy(sock_ops.args, args, nargs * sizeof(*args));\n \n-\tret = BPF_CGROUP_RUN_PROG_SOCK_OPS(\u0026sock_ops);\n+\tret = __BPF_CGROUP_RUN_PROG_SOCK_OPS(\u0026sock_ops);\n \tif (ret == 0)\n \t\tret = sock_ops.reply;\n \telse\n@@ -2916,42 +2917,37 @@ static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)\n \treturn ret;\n }\n \n-static inline int tcp_call_bpf_2arg(struct sock *sk, int op, u32 arg1, u32 arg2)\n-{\n-\tu32 args[2] = {arg1, arg2};\n-\n-\treturn tcp_call_bpf(sk, op, 2, args);\n-}\n-\n-static inline int tcp_call_bpf_3arg(struct sock *sk, int op, u32 arg1, u32 arg2,\n-\t\t\t\t u32 arg3)\n-{\n-\tu32 args[3] = {arg1, arg2, arg3};\n+#define tcp_call_bpf(sk, op)\t\t\t\t\t\t\\\n+({\t\t\t\t\t\t\t\t\t\\\n+\tint __ret = 0;\t\t\t\t\t\t\t\\\n+\tif (cgroup_bpf_enabled(CGROUP_SOCK_OPS)) {\t\t\t\\\n+\t\t__ret = __tcp_call_bpf(sk, op, 0, NULL);\t\t\\\n+\t}\t\t\t\t\t\t\t\t\\\n+\t__ret;\t\t\t\t\t\t\t\t\\\n+})\n \n-\treturn tcp_call_bpf(sk, op, 3, args);\n-}\n+#define tcp_call_bpf_flag(sk, op, ...)\t\t\t\t\t\\\n+do {\t\t\t\t\t\t\t\t\t\\\n+\tif (cgroup_bpf_enabled(CGROUP_SOCK_OPS) \u0026\u0026\t\t\t\\\n+\t BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk), op ## _FLAG)) {\t\t\\\n+\t\tu32 __args[] = { __VA_ARGS__ };\t\t\t\t\\\n+\t\t__tcp_call_bpf(sk, op, ARRAY_SIZE(__args), __args);\t\\\n+\t}\t\t\t\t\t\t\t\t\\\n+} while (0)\n \n static inline void tcp_clear_sock_ops_cb_flags(struct sock *sk)\n {\n \ttcp_sk(sk)-\u003ebpf_sock_ops_cb_flags = 0;\n+\tWRITE_ONCE(tcp_sk(sk)-\u003ebpf_tcp_ops_flags, 0);\n }\n \n #else\n-static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)\n-{\n-\treturn -EPERM;\n-}\n-\n-static inline int tcp_call_bpf_2arg(struct sock *sk, int op, u32 arg1, u32 arg2)\n+static inline int tcp_call_bpf(struct sock *sk, int op)\n {\n \treturn -EPERM;\n }\n \n-static inline int tcp_call_bpf_3arg(struct sock *sk, int op, u32 arg1, u32 arg2,\n-\t\t\t\t u32 arg3)\n-{\n-\treturn -EPERM;\n-}\n+#define tcp_call_bpf_flag(sk, op, ...) do { } while (0)\n \n static inline void tcp_clear_sock_ops_cb_flags(struct sock *sk)\n {\n@@ -2989,7 +2985,7 @@ struct bpf_tcp_ops {\n \t/* Called when the retransmission timer fires. */\n \tvoid (*rto)(struct sock *sk);\n \n-\t/* Called on every RTT sample.\n+\t/* Called on every RTT sample if BPF_TCP_OPS_FLAG_RTT is enabled.\n \t * @mrtt: the measured RTT, in microseconds.\n \t * @srtt: the updated smoothed RTT.\n \t */\n@@ -3016,6 +3012,10 @@ struct bpf_tcp_ops {\n \t * Parse the TCP header options of an incoming skb received on an\n \t * established connection. Use bpf_dynptr_from_skb()/bpf_skb_load_bytes()\n \t * to access the options.\n+\t *\n+\t * Called if BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_ALL is enabled, or if\n+\t * BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_UNKNOWN is enabled and an unknown\n+\t * option is received.\n \t */\n \tvoid (*parse_hdr)(struct sock *sk, struct sk_buff *skb);\n \n@@ -3023,6 +3023,8 @@ struct bpf_tcp_ops {\n \t * Reserve space in the outgoing TCP header for options to be written\n \t * later by write_hdr_opt(). Call bpf_reserve_hdr_opt() to reserve bytes.\n \t *\n+\t * Called if BPF_TCP_OPS_FLAG_WRITE_HDR_OPT is enabled.\n+\t *\n \t * @skb: outgoing packet. NULL when called from tcp_current_mss()\n \t * (MSS sizing).\n \t * @req: request_sock on the synack path; NULL otherwise.\n@@ -3041,6 +3043,8 @@ struct bpf_tcp_ops {\n \t * Use bpf_store_hdr_opt() to write; it appends within the reserved window\n \t * shared with legacy SOCKOPS.\n \t *\n+\t * Called if BPF_TCP_OPS_FLAG_WRITE_HDR_OPT is enabled.\n+\t *\n \t * @skb: outgoing packet.\n \t * @req: request_sock on the synack path; NULL otherwise.\n \t * @syn_skb: incoming SYN on the synack path; NULL otherwise.\n@@ -3053,24 +3057,47 @@ struct bpf_tcp_ops {\n \t\t\t struct request_sock *req, struct sk_buff *syn_skb,\n \t\t\t enum tcp_synack_type synack_type,\n \t\t\t u32 opt_off);\n+\n+\t/*\n+\t * Called when an incoming skb is enqueued to sk-\u003esk_receive_queue\n+\t * if BPF_TCP_OPS_FLAG_RCVQ is enabled.\n+\t */\n+\tvoid (*enqueue_rcvq)(struct sock *sk, struct sk_buff *skb);\n+\n+\t/*\n+\t * Called after data is dequeued from sk-\u003esk_receive_queue\n+\t * if BPF_TCP_OPS_FLAG_RCVQ is enabled.\n+\t */\n+\tvoid (*dequeue_rcvq)(struct sock *sk);\n };\n \n-#define bpf_tcp_ops_call(op, sk, ...)\t\t\t\t\t\\\n+#define __bpf_tcp_ops_call(op, sk, ...)\t\t\t\t\t\\\n do {\t\t\t\t\t\t\t\t\t\\\n-\tif (cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS)) {\t\t\t\\\n-\t\tconst struct bpf_prog_array_item *item;\t\t\t\\\n-\t\tconst struct bpf_tcp_ops *tcp_ops;\t\t\t\\\n-\t\tstruct cgroup *cgrp;\t\t\t\t\t\\\n+\tconst struct bpf_prog_array_item *item;\t\t\t\t\\\n+\tconst struct bpf_tcp_ops *tcp_ops;\t\t\t\t\\\n+\tstruct cgroup *cgrp;\t\t\t\t\t\t\\\n \t\t\t\t\t\t\t\t\t\\\n-\t\tcgrp = sock_cgroup_ptr(\u0026sk-\u003esk_cgrp_data);\t\t\\\n-\t\trcu_read_lock_dont_migrate();\t\t\t\t\\\n-\t\tbpf_cgroup_struct_ops_foreach(tcp_ops, item, cgrp,\t\\\n-\t\t\t\t\t CGROUP_TCP_SOCK_OPS) {\t\\\n-\t\t\tif (tcp_ops-\u003eop)\t\t\t\t\\\n-\t\t\t\ttcp_ops-\u003eop(sk, ##__VA_ARGS__);\t\t\\\n-\t\t}\t\t\t\t\t\t\t\\\n-\t\trcu_read_unlock_migrate();\t\t\t\t\\\n+\tcgrp = sock_cgroup_ptr(\u0026sk-\u003esk_cgrp_data);\t\t\t\\\n+\trcu_read_lock_dont_migrate();\t\t\t\t\t\\\n+\tbpf_cgroup_struct_ops_foreach(tcp_ops, item, cgrp,\t\t\\\n+\t\t\t\t CGROUP_TCP_SOCK_OPS) {\t\t\\\n+\t\tif (tcp_ops-\u003eop)\t\t\t\t\t\\\n+\t\t\ttcp_ops-\u003eop(sk, ##__VA_ARGS__);\t\t\t\\\n \t}\t\t\t\t\t\t\t\t\\\n+\trcu_read_unlock_migrate();\t\t\t\t\t\\\n+} while (0)\n+\n+#define bpf_tcp_ops_call(op, sk, ...)\t\t\t\t\t\\\n+do {\t\t\t\t\t\t\t\t\t\\\n+\tif (cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS))\t\t\t\\\n+\t\t__bpf_tcp_ops_call(op, sk, ##__VA_ARGS__);\t\t\\\n+} while (0)\n+\n+#define bpf_tcp_ops_call_flag(op, flag, sk, ...)\t\t\t\\\n+do {\t\t\t\t\t\t\t\t\t\\\n+\tif (cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS) \u0026\u0026\t\t\t\\\n+\t BPF_TCP_OPS_TEST_FLAG(tcp_sk(sk), flag))\t\t\t\\\n+\t\t__bpf_tcp_ops_call(op, sk, ##__VA_ARGS__);\t\t\\\n } while (0)\n \n #define bpf_tcp_ops_call_int(op, init_retval, sk, ...)\t\t\t\\\n@@ -3106,7 +3133,9 @@ do {\t\t\t\t\t\t\t\t\t\\\n })\n \n #else\n-#define bpf_tcp_ops_call(op, sk, ...)\t\tdo { } while (0)\n+#define __bpf_tcp_ops_call(op, sk, ...)\t\t\tdo { } while (0)\n+#define bpf_tcp_ops_call(op, sk, ...)\t\t\tdo { } while (0)\n+#define bpf_tcp_ops_call_flag(op, flag, sk, ...)\tdo { } while (0)\n #define bpf_tcp_ops_call_int(op, init_retval, sk, ...)\t(init_retval)\n #endif\n \n@@ -3114,7 +3143,7 @@ static inline u32 tcp_timeout_init(struct sock *sk)\n {\n \tint timeout;\n \n-\ttimeout = tcp_call_bpf(sk, BPF_SOCK_OPS_TIMEOUT_INIT, 0, NULL);\n+\ttimeout = tcp_call_bpf(sk, BPF_SOCK_OPS_TIMEOUT_INIT);\n \ttimeout = bpf_tcp_ops_call_int(timeout_init, timeout, sk);\n \tif (timeout \u003c= 0)\n \t\ttimeout = TCP_TIMEOUT_INIT;\n@@ -3125,7 +3154,7 @@ static inline u32 tcp_rwnd_init_bpf(struct sock *sk)\n {\n \tint rwnd;\n \n-\trwnd = tcp_call_bpf(sk, BPF_SOCK_OPS_RWND_INIT, 0, NULL);\n+\trwnd = tcp_call_bpf(sk, BPF_SOCK_OPS_RWND_INIT);\n \trwnd = bpf_tcp_ops_call_int(rwnd_init, rwnd, sk);\n \tif (rwnd \u003c 0)\n \t\trwnd = 0;\n@@ -3134,14 +3163,13 @@ static inline u32 tcp_rwnd_init_bpf(struct sock *sk)\n \n static inline bool tcp_bpf_ca_needs_ecn(struct sock *sk)\n {\n-\treturn (tcp_call_bpf(sk, BPF_SOCK_OPS_NEEDS_ECN, 0, NULL) == 1);\n+\treturn (tcp_call_bpf(sk, BPF_SOCK_OPS_NEEDS_ECN) == 1);\n }\n \n static inline void tcp_bpf_rtt(struct sock *sk, long mrtt, u32 srtt)\n {\n-\tif (BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk), BPF_SOCK_OPS_RTT_CB_FLAG))\n-\t\ttcp_call_bpf_2arg(sk, BPF_SOCK_OPS_RTT_CB, mrtt, srtt);\n-\tbpf_tcp_ops_call(rtt, sk, mrtt, srtt);\n+\ttcp_call_bpf_flag(sk, BPF_SOCK_OPS_RTT_CB, mrtt, srtt);\n+\tbpf_tcp_ops_call_flag(rtt, RTT, sk, mrtt, srtt);\n }\n \n #if IS_ENABLED(CONFIG_SMC)\ndiff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h\nindex e0ed44b1bbcb7..6f70db7515dd4 100644\n--- a/include/uapi/linux/bpf.h\n+++ b/include/uapi/linux/bpf.h\n@@ -7340,6 +7340,31 @@ enum {\n \t\t\t\t\t */\n };\n \n+/*\n+ * Most callbacks of struct bpf_tcp_ops are placed in the slow\n+ * path (e.g., one-shot connection setup or unlikely events like\n+ * timers) and are invoked simply by defining non-NULL callbacks.\n+ *\n+ * Callbacks in the fast path, however, would incur noticeable\n+ * overhead even when set to NULL, so they are disabled by default\n+ * and must be explicitly enabled per socket via bpf_tcp_ops_set_flags().\n+ *\n+ * The flags are per-socket and shared by all effective bpf_tcp_ops\n+ * programs.\n+ */\n+enum {\n+\t/* .rtt() */\n+\tBPF_TCP_OPS_FLAG_RTT\t\t\t= (1 \u003c\u003c 0),\n+\t/* .parse_hdr() */\n+\tBPF_TCP_OPS_FLAG_PARSE_HDR_OPT_ALL\t= (1 \u003c\u003c 1),\n+\tBPF_TCP_OPS_FLAG_PARSE_HDR_OPT_UNKNOWN\t= (1 \u003c\u003c 2),\n+\t/* .hdr_opt_len() and .write_hdr_opt() */\n+\tBPF_TCP_OPS_FLAG_WRITE_HDR_OPT\t\t= (1 \u003c\u003c 3),\n+\t/* .enqueue_rcvq() and .dequeue_rcvq() */\n+\tBPF_TCP_OPS_FLAG_RCVQ\t\t\t= (1 \u003c\u003c 4),\n+\tBPF_TCP_OPS_FLAG_ALL\t\t\t= (1 \u003c\u003c 5) - 1,\n+};\n+\n /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect\n * changes between the TCP and BPF versions. Ideally this should never happen.\n * If it does, we need to add code to convert them before calling\ndiff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c\nindex cdcfc7d3c6d2e..035c83338e0f1 100644\n--- a/net/ipv4/af_inet.c\n+++ b/net/ipv4/af_inet.c\n@@ -226,7 +226,7 @@ int __inet_listen_sk(struct sock *sk, int backlog)\n \t\tif (err)\n \t\t\treturn err;\n \n-\t\ttcp_call_bpf(sk, BPF_SOCK_OPS_TCP_LISTEN_CB, 0, NULL);\n+\t\ttcp_call_bpf(sk, BPF_SOCK_OPS_TCP_LISTEN_CB);\n \t\tbpf_tcp_ops_call(listen, sk);\n \t}\n \treturn 0;\ndiff --git a/net/ipv4/bpf_tcp_ops.c b/net/ipv4/bpf_tcp_ops.c\nindex 681fed6429999..2ba73dd6c52cc 100644\n--- a/net/ipv4/bpf_tcp_ops.c\n+++ b/net/ipv4/bpf_tcp_ops.c\n@@ -76,6 +76,14 @@ static void write_hdr_opt_stub(struct sock *sk, struct sk_buff *skb,\n {\n }\n \n+static void enqueue_rcvq_stub(struct sock *sk, struct sk_buff *skb)\n+{\n+}\n+\n+static void dequeue_rcvq_stub(struct sock *sk)\n+{\n+}\n+\n static struct bpf_tcp_ops __bpf_tcp_ops = {\n \t.timeout_init = timeout_init_stub,\n \t.rwnd_init = rwnd_init_stub,\n@@ -90,6 +98,8 @@ static struct bpf_tcp_ops __bpf_tcp_ops = {\n \t.parse_hdr = parse_hdr_stub,\n \t.hdr_opt_len = hdr_opt_len_stub,\n \t.write_hdr_opt = write_hdr_opt_stub,\n+\t.enqueue_rcvq = enqueue_rcvq_stub,\n+\t.dequeue_rcvq = dequeue_rcvq_stub,\n };\n \n BPF_CALL_4(bpf_tcp_ops_store_hdr_opt, void *, ctx, const void *, from,\n@@ -210,6 +220,24 @@ const struct bpf_func_proto bpf_tcp_ops_get_retval_proto = {\n \t.ret_type\t= RET_INTEGER,\n };\n \n+static bool is_sockopt_supported(u32 moff)\n+{\n+\tswitch (moff) {\n+\tcase offsetof(struct bpf_tcp_ops, active_established):\n+\tcase offsetof(struct bpf_tcp_ops, passive_established):\n+\tcase offsetof(struct bpf_tcp_ops, rto):\n+\tcase offsetof(struct bpf_tcp_ops, rtt):\n+\tcase offsetof(struct bpf_tcp_ops, set_state):\n+\tcase offsetof(struct bpf_tcp_ops, retrans):\n+\tcase offsetof(struct bpf_tcp_ops, connect):\n+\tcase offsetof(struct bpf_tcp_ops, listen):\n+\tcase offsetof(struct bpf_tcp_ops, parse_hdr):\n+\t\treturn true;\n+\t}\n+\n+\treturn false;\n+}\n+\n static const struct bpf_func_proto *\n get_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)\n {\n@@ -221,22 +249,13 @@ get_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)\n \tcase BPF_FUNC_sk_storage_delete:\n \t\treturn \u0026bpf_sk_storage_delete_proto;\n \tcase BPF_FUNC_setsockopt:\n-\t\t/* The sk may be an unlocked listener (synack path) or NULL\n-\t\t * fullsock; disable for members that can run unlocked.\n-\t\t */\n-\t\tif (moff == offsetof(struct bpf_tcp_ops, rwnd_init) ||\n-\t\t moff == offsetof(struct bpf_tcp_ops, timeout_init) ||\n-\t\t moff == offsetof(struct bpf_tcp_ops, hdr_opt_len) ||\n-\t\t moff == offsetof(struct bpf_tcp_ops, write_hdr_opt))\n-\t\t\treturn NULL;\n-\t\treturn \u0026bpf_sk_setsockopt_proto;\n+\t\tif (is_sockopt_supported(moff))\n+\t\t\treturn \u0026bpf_sk_setsockopt_proto;\n+\t\treturn NULL;\n \tcase BPF_FUNC_getsockopt:\n-\t\tif (moff == offsetof(struct bpf_tcp_ops, rwnd_init) ||\n-\t\t moff == offsetof(struct bpf_tcp_ops, timeout_init) ||\n-\t\t moff == offsetof(struct bpf_tcp_ops, hdr_opt_len) ||\n-\t\t moff == offsetof(struct bpf_tcp_ops, write_hdr_opt))\n-\t\t\treturn NULL;\n-\t\treturn \u0026bpf_sk_getsockopt_proto;\n+\t\tif (is_sockopt_supported(moff))\n+\t\t\treturn \u0026bpf_sk_getsockopt_proto;\n+\t\treturn NULL;\n \tcase BPF_FUNC_get_retval:\n \t\tif (moff == offsetof(struct bpf_tcp_ops, timeout_init) ||\n \t\t moff == offsetof(struct bpf_tcp_ops, rwnd_init))\n@@ -319,8 +338,116 @@ static struct bpf_struct_ops bpf_tcp_ops = {\n \t.owner = THIS_MODULE,\n };\n \n+__bpf_kfunc_start_defs();\n+\n+__bpf_kfunc int bpf_tcp_ops_set_flags(struct tcp_sock *tp, u32 enable, u32 disable)\n+{\n+\tu32 old, new;\n+\n+\tif ((enable \u0026 disable) || (enable | disable) \u0026 ~BPF_TCP_OPS_FLAG_ALL)\n+\t\treturn -EINVAL;\n+\n+\tif (sk_is_mptcp((struct sock *)tp) \u0026\u0026 (enable \u0026 BPF_TCP_OPS_FLAG_RCVQ))\n+\t\treturn -EOPNOTSUPP;\n+\n+\told = READ_ONCE(tp-\u003ebpf_tcp_ops_flags);\n+\n+\tdo {\n+\t\tnew = (old | enable) \u0026 ~disable;\n+\t\tif (new == old)\n+\t\t\tbreak;\n+\t} while (!try_cmpxchg(\u0026tp-\u003ebpf_tcp_ops_flags, \u0026old, new));\n+\n+\treturn 0;\n+}\n+\n+__bpf_kfunc int bpf_tcp_ops_set_rcvlowat(struct sock *sk, int rcvlowat,\n+\t\t\t\t\t const struct bpf_prog_aux *aux)\n+{\n+\tu32 moff = aux-\u003eattach_st_ops_member_off;\n+\tbool wakeup = false;\n+\n+\tif (moff == offsetof(struct bpf_tcp_ops, dequeue_rcvq))\n+\t\twakeup = true;\n+\n+\tif (rcvlowat \u003c 0)\n+\t\trcvlowat = INT_MAX;\n+\n+\treturn __tcp_set_rcvlowat(sk, rcvlowat, wakeup);\n+}\n+\n+__bpf_kfunc_end_defs();\n+\n+BTF_KFUNCS_START(bpf_tcp_ops_set_flags_kfunc_set)\n+BTF_ID_FLAGS(func, bpf_tcp_ops_set_flags)\n+BTF_KFUNCS_END(bpf_tcp_ops_set_flags_kfunc_set)\n+\n+BTF_KFUNCS_START(bpf_tcp_ops_set_rcvlowat_kfunc_set)\n+BTF_ID_FLAGS(func, bpf_tcp_ops_set_rcvlowat, KF_IMPLICIT_ARGS)\n+BTF_KFUNCS_END(bpf_tcp_ops_set_rcvlowat_kfunc_set)\n+\n+static int bpf_tcp_ops_set_flags_kfunc_filter(const struct bpf_prog *prog,\n+\t\t\t\t\t u32 kfunc_id)\n+{\n+\tif (!btf_id_set8_contains(\u0026bpf_tcp_ops_set_flags_kfunc_set, kfunc_id))\n+\t\treturn 0;\n+\n+\tif (prog-\u003etype == BPF_PROG_TYPE_STRUCT_OPS \u0026\u0026\n+\t prog-\u003eaux-\u003est_ops == \u0026bpf_tcp_ops)\n+\t\treturn 0;\n+\n+\tif (prog-\u003etype == BPF_PROG_TYPE_CGROUP_SOCKOPT ||\n+\t prog-\u003etype == BPF_PROG_TYPE_CGROUP_SKB)\n+\t\treturn 0;\n+\n+\treturn -EACCES;\n+}\n+\n+static const struct btf_kfunc_id_set bpf_tcp_ops_set_flags_kfunc_id_set = {\n+\t.owner = THIS_MODULE,\n+\t.set = \u0026bpf_tcp_ops_set_flags_kfunc_set,\n+\t.filter = bpf_tcp_ops_set_flags_kfunc_filter,\n+};\n+\n+static int bpf_tcp_ops_set_rcvlowat_kfunc_filter(const struct bpf_prog *prog,\n+\t\t\t\t\t\t u32 kfunc_id)\n+{\n+\tu32 moff;\n+\n+\tif (!btf_id_set8_contains(\u0026bpf_tcp_ops_set_rcvlowat_kfunc_set, kfunc_id))\n+\t\treturn 0;\n+\n+\tif (prog-\u003eaux-\u003est_ops != \u0026bpf_tcp_ops)\n+\t\treturn -EACCES;\n+\n+\tmoff = prog-\u003eaux-\u003eattach_st_ops_member_off;\n+\tif (moff != offsetof(struct bpf_tcp_ops, enqueue_rcvq) \u0026\u0026\n+\t moff != offsetof(struct bpf_tcp_ops, dequeue_rcvq))\n+\t\treturn -EACCES;\n+\n+\treturn 0;\n+}\n+\n+static const struct btf_kfunc_id_set bpf_tcp_ops_set_rcvlowat_kfunc_id_set = {\n+\t.owner = THIS_MODULE,\n+\t.set = \u0026bpf_tcp_ops_set_rcvlowat_kfunc_set,\n+\t.filter = bpf_tcp_ops_set_rcvlowat_kfunc_filter,\n+};\n+\n static int __init __bpf_tcp_ops_init(void)\n {\n-\treturn register_bpf_struct_ops(\u0026bpf_tcp_ops, bpf_tcp_ops);\n+\tint ret;\n+\n+\tret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,\n+\t\t\t\t\t\u0026bpf_tcp_ops_set_flags_kfunc_id_set);\n+\t/* BPF_PROG_TYPE_CGROUP_{SOCKOPT,SKB} share BTF_KFUNC_HOOK_CGROUP. */\n+\tret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCKOPT,\n+\t\t\t\t\t \u0026bpf_tcp_ops_set_flags_kfunc_id_set);\n+\tret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,\n+\t\t\t\t\t \u0026bpf_tcp_ops_set_rcvlowat_kfunc_id_set);\n+\tret = ret ?: register_bpf_struct_ops(\u0026bpf_tcp_ops, bpf_tcp_ops);\n+\n+\treturn ret;\n }\n+\n late_initcall(__bpf_tcp_ops_init);\ndiff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c\nindex 650a2e89950af..c3c756a1ba8cf 100644\n--- a/net/ipv4/tcp.c\n+++ b/net/ipv4/tcp.c\n@@ -1609,6 +1609,8 @@ void tcp_cleanup_rbuf(struct sock *sk, int copied)\n \t \"cleanup rbuf bug: copied %X seq %X rcvnxt %X\\n\",\n \t tp-\u003ecopied_seq, TCP_SKB_CB(skb)-\u003eend_seq, tp-\u003ercv_nxt);\n \t__tcp_cleanup_rbuf(sk, copied);\n+\n+\tbpf_tcp_ops_call_flag(dequeue_rcvq, RCVQ, sk);\n }\n \n static void tcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)\n@@ -1825,8 +1827,7 @@ int tcp_peek_len(struct socket *sock)\n \treturn tcp_inq(sock-\u003esk);\n }\n \n-/* Make sure sk_rcvbuf is big enough to satisfy SO_RCVLOWAT hint */\n-int tcp_set_rcvlowat(struct sock *sk, int val)\n+int __tcp_set_rcvlowat(struct sock *sk, int val, bool wakeup)\n {\n \tstruct tcp_sock *tp = tcp_sk(sk);\n \tint space, cap;\n@@ -1839,7 +1840,8 @@ int tcp_set_rcvlowat(struct sock *sk, int val)\n \tWRITE_ONCE(sk-\u003esk_rcvlowat, val ? : 1);\n \n \t/* Check if we need to signal EPOLLIN right now */\n-\ttcp_data_ready(sk);\n+\tif (wakeup)\n+\t\ttcp_data_ready(sk);\n \n \tif (sk-\u003esk_userlocks \u0026 SOCK_RCVBUF_LOCK)\n \t\treturn 0;\n@@ -1854,6 +1856,12 @@ int tcp_set_rcvlowat(struct sock *sk, int val)\n \treturn 0;\n }\n \n+/* Make sure sk_rcvbuf is big enough to satisfy SO_RCVLOWAT hint */\n+int tcp_set_rcvlowat(struct sock *sk, int val)\n+{\n+\treturn __tcp_set_rcvlowat(sk, val, true);\n+}\n+\n void tcp_set_rcvbuf(struct sock *sk, int val)\n {\n \ttcp_set_window_clamp(sk, tcp_win_from_space(sk, val));\n@@ -2994,8 +3002,7 @@ void tcp_set_state(struct sock *sk, int state)\n \t */\n \tBTF_TYPE_EMIT_ENUM(BPF_TCP_ESTABLISHED);\n \n-\tif (BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk), BPF_SOCK_OPS_STATE_CB_FLAG))\n-\t\ttcp_call_bpf_2arg(sk, BPF_SOCK_OPS_STATE_CB, oldstate, state);\n+\ttcp_call_bpf_flag(sk, BPF_SOCK_OPS_STATE_CB, oldstate, state);\n \tbpf_tcp_ops_call(set_state, sk, state);\n \n \tswitch (state) {\n@@ -5217,6 +5224,9 @@ static void __init tcp_struct_check(void)\n \tCACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_txrx, lost_out);\n \tCACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_txrx, sacked_out);\n \tCACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_txrx, scaling_ratio);\n+#ifdef CONFIG_BPF\n+\tCACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_txrx, bpf_tcp_ops_flags);\n+#endif\n \n \t/* RX read-mostly hotpath cache lines */\n \tCACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_rx, copied_seq);\ndiff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c\nindex 471c78be55137..6dfe40322fb59 100644\n--- a/net/ipv4/tcp_fastopen.c\n+++ b/net/ipv4/tcp_fastopen.c\n@@ -281,6 +281,8 @@ void tcp_fastopen_add_skb(struct sock *sk, struct sk_buff *skb)\n \tTCP_SKB_CB(skb)-\u003eseq++;\n \tTCP_SKB_CB(skb)-\u003etcp_flags \u0026= ~TCPHDR_SYN;\n \n+\tbpf_tcp_ops_call_flag(enqueue_rcvq, RCVQ, sk, skb);\n+\n \ttp-\u003ercv_nxt = TCP_SKB_CB(skb)-\u003eend_seq;\n \ttcp_add_receive_queue(sk, skb);\n \ttp-\u003esyn_data_acked = 1;\ndiff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c\nindex 209db8effcc41..46f5c4fafa8db 100644\n--- a/net/ipv4/tcp_input.c\n+++ b/net/ipv4/tcp_input.c\n@@ -146,14 +146,16 @@ EXPORT_SYMBOL_GPL(clean_acked_data_flush);\n #ifdef CONFIG_CGROUP_BPF\n static void bpf_skops_parse_hdr(struct sock *sk, struct sk_buff *skb)\n {\n-\tbool unknown_opt = tcp_sk(sk)-\u003erx_opt.saw_unknown \u0026\u0026\n-\t\tBPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),\n-\t\t\t\t BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG);\n-\tbool parse_all_opt = BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),\n-\t\t\t\t\t\t BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG);\n \tstruct bpf_sock_ops_kern sock_ops;\n+\tconst struct tcp_sock *tp;\n \n-\tif (likely(!unknown_opt \u0026\u0026 !parse_all_opt))\n+\tif (!cgroup_bpf_enabled(CGROUP_SOCK_OPS))\n+\t\treturn;\n+\n+\ttp = tcp_sk(sk);\n+\tif (!(tp-\u003erx_opt.saw_unknown \u0026\u0026\n+\t BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG)) \u0026\u0026\n+\t !BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG))\n \t\treturn;\n \n \t/* The skb will be handled in the\n@@ -176,7 +178,7 @@ static void bpf_skops_parse_hdr(struct sock *sk, struct sk_buff *skb)\n \tsock_ops.sk = sk;\n \tbpf_skops_init_skb(\u0026sock_ops, skb, tcp_hdrlen(skb));\n \n-\tBPF_CGROUP_RUN_PROG_SOCK_OPS(\u0026sock_ops);\n+\t__BPF_CGROUP_RUN_PROG_SOCK_OPS(\u0026sock_ops);\n }\n \n static void bpf_skops_established(struct sock *sk, int bpf_op,\n@@ -184,6 +186,9 @@ static void bpf_skops_established(struct sock *sk, int bpf_op,\n {\n \tstruct bpf_sock_ops_kern sock_ops;\n \n+\tif (!cgroup_bpf_enabled(CGROUP_SOCK_OPS))\n+\t\treturn;\n+\n \tsock_owned_by_me(sk);\n \n \tmemset(\u0026sock_ops, 0, offsetof(struct bpf_sock_ops_kern, temp));\n@@ -195,7 +200,7 @@ static void bpf_skops_established(struct sock *sk, int bpf_op,\n \tif (skb)\n \t\tbpf_skops_init_skb(\u0026sock_ops, skb, tcp_hdrlen(skb));\n \n-\tBPF_CGROUP_RUN_PROG_SOCK_OPS(\u0026sock_ops);\n+\t__BPF_CGROUP_RUN_PROG_SOCK_OPS(\u0026sock_ops);\n }\n #else\n static void bpf_skops_parse_hdr(struct sock *sk, struct sk_buff *skb)\n@@ -210,6 +215,11 @@ static void bpf_skops_established(struct sock *sk, int bpf_op,\n \n static void bpf_tcp_ops_parse_hdr(struct sock *sk, struct sk_buff *skb)\n {\n+\tconst struct tcp_sock *tp;\n+\n+\tif (!cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS))\n+\t\treturn;\n+\n \tswitch (sk-\u003esk_state) {\n \tcase TCP_SYN_RECV:\n \tcase TCP_SYN_SENT:\n@@ -217,7 +227,12 @@ static void bpf_tcp_ops_parse_hdr(struct sock *sk, struct sk_buff *skb)\n \t\treturn;\n \t}\n \n-\tbpf_tcp_ops_call(parse_hdr, sk, skb);\n+\ttp = tcp_sk(sk);\n+\n+\tif ((tp-\u003erx_opt.saw_unknown \u0026\u0026\n+\t BPF_TCP_OPS_TEST_FLAG(tp, PARSE_HDR_OPT_UNKNOWN)) ||\n+\t BPF_TCP_OPS_TEST_FLAG(tp, PARSE_HDR_OPT_ALL))\n+\t\t__bpf_tcp_ops_call(parse_hdr, sk, skb);\n }\n \n static __cold void tcp_gro_dev_warn(const struct sock *sk, const struct sk_buff *skb,\n@@ -5350,6 +5365,8 @@ static void tcp_ofo_queue(struct sock *sk)\n \t\t\tcontinue;\n \t\t}\n \n+\t\tbpf_tcp_ops_call_flag(enqueue_rcvq, RCVQ, sk, skb);\n+\n \t\ttail = skb_peek_tail(\u0026sk-\u003esk_receive_queue);\n \t\teaten = tail \u0026\u0026 tcp_try_coalesce(sk, tail, skb, \u0026fragstolen);\n \t\ttcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)-\u003eend_seq);\n@@ -5553,6 +5570,8 @@ static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb,\n \tint eaten;\n \tstruct sk_buff *tail = skb_peek_tail(\u0026sk-\u003esk_receive_queue);\n \n+\tbpf_tcp_ops_call_flag(enqueue_rcvq, RCVQ, sk, skb);\n+\n \teaten = (tail \u0026\u0026\n \t\t tcp_try_coalesce(sk, tail,\n \t\t\t\t skb, fragstolen)) ? 1 : 0;\ndiff --git a/net/ipv4/tcp_nv.c b/net/ipv4/tcp_nv.c\nindex f345897a68dfc..7b0dae23d9aa2 100644\n--- a/net/ipv4/tcp_nv.c\n+++ b/net/ipv4/tcp_nv.c\n@@ -146,7 +146,7 @@ static void tcpnv_init(struct sock *sk)\n \t * within a datacenter, where we have reasonable estimates of\n \t * RTTs\n \t */\n-\tbase_rtt = tcp_call_bpf(sk, BPF_SOCK_OPS_BASE_RTT, 0, NULL);\n+\tbase_rtt = tcp_call_bpf(sk, BPF_SOCK_OPS_BASE_RTT);\n \tif (base_rtt \u003e 0) {\n \t\tca-\u003env_base_rtt = base_rtt;\n \t\tca-\u003env_lower_bound_rtt = (base_rtt * 205) \u003e\u003e 8; /* 80% */\ndiff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c\nindex 3ac465513bf51..db4fd1825d999 100644\n--- a/net/ipv4/tcp_output.c\n+++ b/net/ipv4/tcp_output.c\n@@ -476,8 +476,9 @@ static u32 bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,\n \tstruct bpf_sock_ops_kern sock_ops;\n \tint err;\n \n-\tif (likely(!BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),\n-\t\t\t\t\t BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG)) ||\n+\tif (!cgroup_bpf_enabled(CGROUP_SOCK_OPS) ||\n+\t !BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),\n+\t\t\t\t BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG)||\n \t !remaining)\n \t\treturn remaining;\n \n@@ -518,7 +519,7 @@ static u32 bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,\n \tif (skb)\n \t\tbpf_skops_init_skb(\u0026sock_ops, skb, 0);\n \n-\terr = BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(\u0026sock_ops, sk);\n+\terr = __BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(\u0026sock_ops, sk);\n \n \tif (err || sock_ops.remaining_opt_len == remaining)\n \t\treturn remaining;\n@@ -543,7 +544,8 @@ static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,\n \n \tfirst_opt_off = tcp_hdrlen(skb) - max_opt_len;\n \n-\tif (BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),\n+\tif (cgroup_bpf_enabled(CGROUP_SOCK_OPS) \u0026\u0026\n+\t BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),\n \t\t\t\t BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG)) {\n \t\tstruct bpf_sock_ops_kern sock_ops;\n \t\tint err;\n@@ -567,7 +569,7 @@ static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,\n \t\tsock_ops.remaining_opt_len = max_opt_len;\n \t\tbpf_skops_init_skb(\u0026sock_ops, skb, first_opt_off);\n \n-\t\terr = BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(\u0026sock_ops, sk);\n+\t\terr = __BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(\u0026sock_ops, sk);\n \t\tif (!err)\n \t\t\tnr_written = max_opt_len - sock_ops.remaining_opt_len;\n \t}\n@@ -581,8 +583,8 @@ static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,\n \t * writer's bytes). The writer finds the append point by scanning from\n \t * first_opt_off + nr_written to the first NOP.\n \t */\n-\tbpf_tcp_ops_call(write_hdr_opt, sk, skb, req, syn_skb, synack_type,\n-\t\t\t first_opt_off + nr_written);\n+\tbpf_tcp_ops_call_flag(write_hdr_opt, WRITE_HDR_OPT, sk, skb, req,\n+\t\t\t syn_skb, synack_type, first_opt_off + nr_written);\n }\n #else\n static u32 bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,\n@@ -613,11 +615,13 @@ static u32 bpf_tcp_ops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,\n {\n \tunsigned int remaining_out = remaining, reserved;\n \n-\tif (!remaining)\n-\t\treturn 0;\n+\tif (!cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS) ||\n+\t !BPF_TCP_OPS_TEST_FLAG(tcp_sk(sk), WRITE_HDR_OPT)||\n+\t !remaining)\n+\t\treturn remaining;\n \n \t/* bpf_tcp_ops_reserve_hdr_opt() reserves space via remaining_out */\n-\tbpf_tcp_ops_call(hdr_opt_len, sk, skb, req, syn_skb, synack_type, \u0026remaining_out);\n+\t__bpf_tcp_ops_call(hdr_opt_len, sk, skb, req, syn_skb, synack_type, \u0026remaining_out);\n \n \treserved = remaining - remaining_out;\n \tif (!reserved)\n@@ -1193,8 +1197,9 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb\n \t\t\t\t\tstruct tcp_key *key)\n {\n \tstruct tcp_sock *tp = tcp_sk(sk);\n-\tunsigned int size = 0;\n \tunsigned int eff_sacks;\n+\tunsigned int remaining;\n+\tunsigned int size = 0;\n \n \topts-\u003eoptions = 0;\n \topts-\u003ebpf_opt_len = 0;\n@@ -1224,10 +1229,10 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb\n \t * left.\n \t */\n \tif (sk_is_mptcp(sk)) {\n-\t\tunsigned int remaining = MAX_TCP_OPTION_SPACE - size;\n \t\tbool has_ts = opts-\u003eoptions \u0026 OPTION_TS;\n \t\tint opt_size;\n \n+\t\tremaining = MAX_TCP_OPTION_SPACE - size;\n \t\topts-\u003emptcp.drop_ts = 0;\n \n \t\topt_size = mptcp_established_options(sk, skb, remaining, has_ts,\n@@ -1244,7 +1249,8 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb\n \n \teff_sacks = tp-\u003erx_opt.num_sacks + tp-\u003erx_opt.dsack;\n \tif (unlikely(eff_sacks)) {\n-\t\tconst unsigned int remaining = MAX_TCP_OPTION_SPACE - size;\n+\t\tremaining = MAX_TCP_OPTION_SPACE - size;\n+\n \t\tif (likely(remaining \u003e= TCPOLEN_SACK_BASE_ALIGNED +\n \t\t\t\t\tTCPOLEN_SACK_PERBLOCK)) {\n \t\t\topts-\u003enum_sack_blocks =\n@@ -1275,24 +1281,14 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb\n \t\t}\n \t}\n \n-\tif (unlikely(BPF_SOCK_OPS_TEST_FLAG(tp,\n-\t\t\t\t\t BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG))) {\n-\t\tunsigned int remaining = MAX_TCP_OPTION_SPACE - size;\n+\tremaining = MAX_TCP_OPTION_SPACE - size;\n \n-\t\tremaining = bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,\n-\t\t\t\t\t\t remaining);\n-\n-\t\tsize = MAX_TCP_OPTION_SPACE - remaining;\n-\t}\n-\n-\tif (cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS)) {\n-\t\tunsigned int remaining = MAX_TCP_OPTION_SPACE - size;\n-\n-\t\tremaining = bpf_tcp_ops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,\n-\t\t\t\t\t\t remaining);\n+\tremaining = bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,\n+\t\t\t\t\t remaining);\n+\tremaining = bpf_tcp_ops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,\n+\t\t\t\t\t remaining);\n \n-\t\tsize = MAX_TCP_OPTION_SPACE - remaining;\n-\t}\n+\tsize = MAX_TCP_OPTION_SPACE - remaining;\n \n \treturn size;\n }\n@@ -3725,9 +3721,8 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)\n \t\terr = tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC);\n \t}\n \n-\tif (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RETRANS_CB_FLAG))\n-\t\ttcp_call_bpf_3arg(sk, BPF_SOCK_OPS_RETRANS_CB,\n-\t\t\t\t TCP_SKB_CB(skb)-\u003eseq, segs, err);\n+\ttcp_call_bpf_flag(sk, BPF_SOCK_OPS_RETRANS_CB,\n+\t\t\t TCP_SKB_CB(skb)-\u003eseq, segs, err);\n \tbpf_tcp_ops_call(retrans, sk, skb, err);\n \n \tif (unlikely(err) \u0026\u0026 err != -EBUSY)\n@@ -4355,7 +4350,7 @@ int tcp_connect(struct sock *sk)\n \tstruct sk_buff *buff;\n \tint err;\n \n-\ttcp_call_bpf(sk, BPF_SOCK_OPS_TCP_CONNECT_CB, 0, NULL);\n+\ttcp_call_bpf(sk, BPF_SOCK_OPS_TCP_CONNECT_CB);\n \tbpf_tcp_ops_call(connect, sk);\n \n #if defined(CONFIG_TCP_MD5SIG) \u0026\u0026 defined(CONFIG_TCP_AO)\ndiff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c\nindex 3d49adc517663..00debcba122b1 100644\n--- a/net/ipv4/tcp_timer.c\n+++ b/net/ipv4/tcp_timer.c\n@@ -286,10 +286,8 @@ static int tcp_write_timeout(struct sock *sk)\n \ttcp_fastopen_active_detect_blackhole(sk, expired);\n \tmptcp_active_detect_blackhole(sk, expired);\n \n-\tif (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RTO_CB_FLAG))\n-\t\ttcp_call_bpf_3arg(sk, BPF_SOCK_OPS_RTO_CB,\n-\t\t\t\t icsk-\u003eicsk_retransmits,\n-\t\t\t\t icsk-\u003eicsk_rto, (int)expired);\n+\ttcp_call_bpf_flag(sk, BPF_SOCK_OPS_RTO_CB,\n+\t\t\t icsk-\u003eicsk_retransmits, icsk-\u003eicsk_rto, (int)expired);\n \tbpf_tcp_ops_call(rto, sk);\n \n \tif (expired) {\ndiff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h\nindex e0ed44b1bbcb7..6f70db7515dd4 100644\n--- a/tools/include/uapi/linux/bpf.h\n+++ b/tools/include/uapi/linux/bpf.h\n@@ -7340,6 +7340,31 @@ enum {\n \t\t\t\t\t */\n };\n \n+/*\n+ * Most callbacks of struct bpf_tcp_ops are placed in the slow\n+ * path (e.g., one-shot connection setup or unlikely events like\n+ * timers) and are invoked simply by defining non-NULL callbacks.\n+ *\n+ * Callbacks in the fast path, however, would incur noticeable\n+ * overhead even when set to NULL, so they are disabled by default\n+ * and must be explicitly enabled per socket via bpf_tcp_ops_set_flags().\n+ *\n+ * The flags are per-socket and shared by all effective bpf_tcp_ops\n+ * programs.\n+ */\n+enum {\n+\t/* .rtt() */\n+\tBPF_TCP_OPS_FLAG_RTT\t\t\t= (1 \u003c\u003c 0),\n+\t/* .parse_hdr() */\n+\tBPF_TCP_OPS_FLAG_PARSE_HDR_OPT_ALL\t= (1 \u003c\u003c 1),\n+\tBPF_TCP_OPS_FLAG_PARSE_HDR_OPT_UNKNOWN\t= (1 \u003c\u003c 2),\n+\t/* .hdr_opt_len() and .write_hdr_opt() */\n+\tBPF_TCP_OPS_FLAG_WRITE_HDR_OPT\t\t= (1 \u003c\u003c 3),\n+\t/* .enqueue_rcvq() and .dequeue_rcvq() */\n+\tBPF_TCP_OPS_FLAG_RCVQ\t\t\t= (1 \u003c\u003c 4),\n+\tBPF_TCP_OPS_FLAG_ALL\t\t\t= (1 \u003c\u003c 5) - 1,\n+};\n+\n /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect\n * changes between the TCP and BPF versions. Ideally this should never happen.\n * If it does, we need to add code to convert them before calling\ndiff --git a/tools/testing/selftests/bpf/prog_tests/tcp_autolowat.c b/tools/testing/selftests/bpf/prog_tests/tcp_autolowat.c\nnew file mode 100644\nindex 0000000000000..337f9d34a39c5\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/prog_tests/tcp_autolowat.c\n@@ -0,0 +1,350 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Copyright 2026 Google LLC */\n+#include \u003csys/epoll.h\u003e\n+\n+#include \"test_progs.h\"\n+#include \"cgroup_helpers.h\"\n+#include \"network_helpers.h\"\n+\n+#include \"tcp_autolowat.skel.h\"\n+\n+#define SOL_BPF\t\t\t0xdeadbeef\n+#define BPF_TCP_AUTOLOWAT\t0x8badf00d\n+\n+struct rpc_descriptor {\n+\tu32 header_len;\n+\tu32 payload_len;\n+};\n+\n+enum rpc_event_type {\n+\tRPC_EVENT_END,\n+\tRPC_EVENT_AUTOLOWAT,\n+\tRPC_EVENT_SEND,\n+\tRPC_EVENT_RECV,\n+\tRPC_EVENT_EPOLL,\n+\tRPC_EVENT_RCVLOWAT,\n+};\n+\n+struct rpc_event {\n+\tenum rpc_event_type type;\n+\tunion {\n+\t\tint len;\n+\t\tint nfds;\n+\t\tint val;\n+\t\tint rcvlowat;\n+\t};\n+};\n+\n+#define RPC_DESC_SIZE (sizeof(struct rpc_descriptor))\n+\n+static struct rpc_test_case {\n+\tchar data[4096];\n+\tstruct rpc_descriptor desc[32];\n+\tstruct rpc_event event[32];\n+} rpc_test_cases[] = {\n+\t{\n+\t\t.desc = {\n+\t\t\t{ .header_len = 100, .payload_len = 150 },\n+\t\t},\n+\t\t.event = {\n+\t\t\t{ .type = RPC_EVENT_AUTOLOWAT,\t.val = 1},\n+\t\t\t/* Single full RPC message in skb. */\n+\t\t\t{ .type = RPC_EVENT_SEND,\t.len = RPC_DESC_SIZE + 100 + 150},\n+\t\t\t{ .type = RPC_EVENT_EPOLL,\t.nfds = 1},\n+\t\t\t{ .type = RPC_EVENT_RCVLOWAT,\t.rcvlowat = RPC_DESC_SIZE + 100 + 150},\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = {\n+\t\t\t{.header_len = 100, .payload_len = 150},\n+\t\t\t{.header_len = 100, .payload_len = 150},\n+\t\t\t{.header_len = 100, .payload_len = 150},\n+\t\t},\n+\t\t.event = {\n+\t\t\t{ .type = RPC_EVENT_AUTOLOWAT,\t.val = 1},\n+\t\t\t/* Two full RPC messages in skb. */\n+\t\t\t{.type = RPC_EVENT_SEND,\t.len = (RPC_DESC_SIZE + 100 + 150) * 2},\n+\t\t\t{.type = RPC_EVENT_EPOLL,\t.nfds = 1},\n+\t\t\t{.type = RPC_EVENT_RCVLOWAT,\t.rcvlowat = (RPC_DESC_SIZE + 100 + 150) * 2},\n+\t\t\t/* Single full RPC message in skb. */\n+\t\t\t{ .type = RPC_EVENT_SEND,\t.len = RPC_DESC_SIZE + 100 + 150},\n+\t\t\t{ .type = RPC_EVENT_EPOLL,\t.nfds = 1},\n+\t\t\t{ .type = RPC_EVENT_RCVLOWAT,\t.rcvlowat = (RPC_DESC_SIZE + 100 + 150) * 3},\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = {\n+\t\t\t{.header_len = 100, .payload_len = 150},\n+\t\t\t{.header_len = 100, .payload_len = 150},\n+\t\t\t{.header_len = 100, .payload_len = 150},\n+\t\t},\n+\t\t.event = {\n+\t\t\t{ .type = RPC_EVENT_AUTOLOWAT,\t.val = 1},\n+\t\t\t/* Two full RPC messages in skb. */\n+\t\t\t{.type = RPC_EVENT_SEND,\t.len = (RPC_DESC_SIZE + 100 + 150) * 2},\n+\t\t\t{.type = RPC_EVENT_EPOLL,\t.nfds = 1},\n+\t\t\t{.type = RPC_EVENT_RCVLOWAT,\t.rcvlowat = (RPC_DESC_SIZE + 100 + 150) * 2},\n+\t\t\t/* Only the next descriptor in skb. */\n+\t\t\t{ .type = RPC_EVENT_SEND,\t.len = RPC_DESC_SIZE},\n+\t\t\t{ .type = RPC_EVENT_EPOLL,\t.nfds = 1},\n+\t\t\t{ .type = RPC_EVENT_RCVLOWAT,\t.rcvlowat = (RPC_DESC_SIZE + 100 + 150) * 2},\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = {\n+\t\t\t{.header_len = 100, .payload_len = 150},\n+\t\t\t{.header_len = 200, .payload_len = 500},\n+\t\t},\n+\t\t.event = {\n+\t\t\t{ .type = RPC_EVENT_AUTOLOWAT,\t.val = 1},\n+\t\t\t/* The first descriptor is partial. */\n+\t\t\t{.type = RPC_EVENT_SEND,\t.len = 1},\n+\t\t\t{.type = RPC_EVENT_EPOLL,\t.nfds = 0},\n+\t\t\t{.type = RPC_EVENT_RCVLOWAT,\t.rcvlowat = RPC_DESC_SIZE},\n+\t\t\t/* The first descriptor is available. */\n+\t\t\t{.type = RPC_EVENT_SEND,\t.len = RPC_DESC_SIZE - 1},\n+\t\t\t{.type = RPC_EVENT_EPOLL,\t.nfds = 0},\n+\t\t\t{.type = RPC_EVENT_RCVLOWAT,\t.rcvlowat = RPC_DESC_SIZE + 150 + 100},\n+\t\t\t/* The first header is ready. */\n+\t\t\t{.type = RPC_EVENT_SEND,\t.len = 100},\n+\t\t\t{.type = RPC_EVENT_EPOLL,\t.nfds = 0},\n+\t\t\t{.type = RPC_EVENT_RCVLOWAT,\t.rcvlowat = RPC_DESC_SIZE + 150 + 100},\n+\t\t\t/* skb has the first payload and 1 byte of the next descriptor. */\n+\t\t\t{.type = RPC_EVENT_SEND,\t.len = 150 + 1},\n+\t\t\t{.type = RPC_EVENT_EPOLL,\t.nfds = 1},\n+\t\t\t{.type = RPC_EVENT_RCVLOWAT,\t.rcvlowat = RPC_DESC_SIZE + 150 + 100},\n+\t\t\t/* After reading the first RPC message, SO_RCVLOWAT should be RPC_DESC_SIZE. */\n+\t\t\t{.type = RPC_EVENT_RECV,\t.len = RPC_DESC_SIZE + 150 + 100},\n+\t\t\t{.type = RPC_EVENT_EPOLL,\t.nfds = 0},\n+\t\t\t{.type = RPC_EVENT_RCVLOWAT,\t.rcvlowat = RPC_DESC_SIZE},\n+\t\t\t/* The second descriptor is available. */\n+\t\t\t{.type = RPC_EVENT_SEND,\t.len = RPC_DESC_SIZE - 1},\n+\t\t\t{.type = RPC_EVENT_EPOLL,\t.nfds = 0},\n+\t\t\t{.type = RPC_EVENT_RCVLOWAT,\t.rcvlowat = RPC_DESC_SIZE + 200 + 500},\n+\t\t},\n+\t},\n+};\n+\n+struct tcp_autolowat_test_cb {\n+\tint saved_netns;\n+\tunion {\n+\t\tint fd[4];\n+\t\tstruct {\n+\t\t\tint server, client, child;\n+\t\t\tint epoll;\n+\t\t};\n+\t};\n+};\n+\n+static void tcp_autolowat_teardown_cb(struct tcp_autolowat_test_cb *cb)\n+{\n+\tint i, err;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(cb-\u003efd); i++) {\n+\t\tif (cb-\u003efd[i] != -1)\n+\t\t\tclose(cb-\u003efd[i]);\n+\t}\n+\n+\tif (cb-\u003esaved_netns != -1) {\n+\t\terr = setns(cb-\u003esaved_netns, CLONE_NEWNET);\n+\t\tASSERT_OK(err, \"restore netns\");\n+\n+\t\tclose(cb-\u003esaved_netns);\n+\t}\n+}\n+\n+static int tcp_autolowat_setup_cb(struct tcp_autolowat_test_cb *cb, int family)\n+{\n+\tstruct epoll_event ev = {};\n+\tint err;\n+\tint i;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(cb-\u003efd); i++)\n+\t\tcb-\u003efd[i] = -1;\n+\n+\tcb-\u003esaved_netns = open(\"/proc/self/ns/net\", O_RDONLY);\n+\tif (!ASSERT_OK_FD(cb-\u003esaved_netns, \"save netns\"))\n+\t\tgoto err;\n+\n+\terr = unshare(CLONE_NEWNET);\n+\tif (!ASSERT_OK(err, \"unshare\"))\n+\t\tgoto err;\n+\n+\terr = system(\"ip link set dev lo up\");\n+\tif (!ASSERT_OK(err, \"set up lo\"))\n+\t\tgoto err;\n+\n+\tcb-\u003eserver = start_server(family, SOCK_STREAM, NULL, 0, 0);\n+\tif (!ASSERT_OK_FD(cb-\u003eserver, \"start_server\"))\n+\t\tgoto err;\n+\n+\tcb-\u003eclient = connect_to_fd(cb-\u003eserver, 0);\n+\tif (!ASSERT_OK_FD(cb-\u003eclient, \"connect_to_fd\"))\n+\t\tgoto err;\n+\n+\tcb-\u003echild = accept(cb-\u003eserver, NULL, NULL);\n+\tif (!ASSERT_OK_FD(cb-\u003echild, \"accept\"))\n+\t\tgoto err;\n+\n+\tcb-\u003eepoll = epoll_create1(0);\n+\tif (!ASSERT_OK_FD(cb-\u003eepoll, \"epoll_create\"))\n+\t\tgoto err;\n+\n+\tev.events = EPOLLIN;\n+\tev.data.fd = cb-\u003echild;\n+\n+\terr = epoll_ctl(cb-\u003eepoll, EPOLL_CTL_ADD, cb-\u003echild, \u0026ev);\n+\tif (!ASSERT_OK(err, \"epoll_ctl\"))\n+\t\tgoto err;\n+\n+\treturn 0;\n+\n+err:\n+\ttcp_autolowat_teardown_cb(cb);\n+\treturn -1;\n+}\n+\n+static int tcp_autolowat_build_data(struct rpc_test_case *test_case)\n+{\n+\tstruct rpc_descriptor *desc = test_case-\u003edesc;\n+\tchar *ptr = test_case-\u003edata;\n+\tint rpc_size;\n+\n+\tmemset(ptr, 0, sizeof(test_case-\u003edata));\n+\n+\twhile (desc-\u003eheader_len + desc-\u003epayload_len) {\n+\t\trpc_size = sizeof(*desc) + desc-\u003eheader_len + desc-\u003epayload_len;\n+\n+\t\tif (!ASSERT_LE(ptr + rpc_size - test_case-\u003edata,\n+\t\t\t sizeof(test_case-\u003edata), \"data overflow\"))\n+\t\t\treturn 1;\n+\n+\t\tmemcpy(ptr, desc, sizeof(*desc));\n+\t\tptr += rpc_size;\n+\t\tdesc++;\n+\t}\n+\n+\tif (!ASSERT_GT(ptr - test_case-\u003edata, 0, \"no data\"))\n+\t\treturn 1;\n+\n+\treturn 0;\n+}\n+\n+static void tcp_autolowat_run_rpc_test(struct tcp_autolowat_test_cb *cb,\n+\t\t\t\t struct rpc_test_case *test_case)\n+{\n+\tstruct rpc_event *event = test_case-\u003eevent;\n+\tchar *ptr = test_case-\u003edata;\n+\tstruct epoll_event ev;\n+\tsocklen_t optlen;\n+\tint err, optval;\n+\tchar buf[4096];\n+\n+\tif (tcp_autolowat_build_data(test_case))\n+\t\treturn;\n+\n+\twhile (1) {\n+\t\tswitch (event-\u003etype) {\n+\t\tcase RPC_EVENT_END:\n+\t\t\treturn;\n+\t\tcase RPC_EVENT_AUTOLOWAT:\n+\t\t\terr = setsockopt(cb-\u003echild, SOL_BPF, BPF_TCP_AUTOLOWAT,\n+\t\t\t\t\t \u0026event-\u003eval, sizeof(event-\u003eval));\n+\t\t\tif (!ASSERT_OK(err, \"setsockopt\"))\n+\t\t\t\treturn;\n+\t\t\tbreak;\n+\t\tcase RPC_EVENT_SEND:\n+\t\t\terr = send(cb-\u003eclient, ptr, event-\u003elen, 0);\n+\t\t\tif (!ASSERT_EQ(err, event-\u003elen, \"send\"))\n+\t\t\t\treturn;\n+\n+\t\t\tptr += event-\u003elen;\n+\t\t\tbreak;\n+\t\tcase RPC_EVENT_RECV:\n+\t\t\terr = recv(cb-\u003echild, buf, event-\u003elen, 0);\n+\t\t\tif (!ASSERT_EQ(err, event-\u003elen, \"recv\"))\n+\t\t\t\treturn;\n+\t\t\tbreak;\n+\t\tcase RPC_EVENT_EPOLL:\n+\t\t\terr = epoll_wait(cb-\u003eepoll, \u0026ev, 1, 100);\n+\t\t\tif (!ASSERT_EQ(err, event-\u003enfds, \"epoll_wait\"))\n+\t\t\t\treturn;\n+\t\t\tbreak;\n+\t\tcase RPC_EVENT_RCVLOWAT:\n+\t\t\toptval = 0;\n+\t\t\toptlen = sizeof(optval);\n+\n+\t\t\terr = getsockopt(cb-\u003echild, SOL_SOCKET, SO_RCVLOWAT, \u0026optval, \u0026optlen);\n+\t\t\tif (!ASSERT_OK(err, \"getsockopt\") ||\n+\t\t\t !ASSERT_EQ(optval, event-\u003ercvlowat, \"rcvlowat\"))\n+\t\t\t\treturn;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tevent++;\n+\t}\n+}\n+\n+static void tcp_autolowat_run_rpc_tests(struct tcp_autolowat *skel, int family)\n+{\n+\tstruct tcp_autolowat_test_cb cb;\n+\tint err;\n+\tint i;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(rpc_test_cases); i++) {\n+\t\tmemset(skel-\u003ebss-\u003etest_name, 0, sizeof(skel-\u003ebss-\u003etest_name));\n+\n+\t\tsnprintf(skel-\u003ebss-\u003etest_name, sizeof(skel-\u003ebss-\u003etest_name),\n+\t\t\t \"AF_INET%c rpc_test_cases[%d]\",\n+\t\t\t family == AF_INET ? ' ' : '6', i);\n+\n+\t\tif (!test__start_subtest(skel-\u003ebss-\u003etest_name))\n+\t\t\tcontinue;\n+\n+\t\terr = tcp_autolowat_setup_cb(\u0026cb, family);\n+\t\tif (err)\n+\t\t\tcontinue;\n+\n+\t\ttcp_autolowat_run_rpc_test(\u0026cb, \u0026rpc_test_cases[i]);\n+\t\ttcp_autolowat_teardown_cb(\u0026cb);\n+\t}\n+}\n+\n+static void tcp_autolowat_run_tests(struct tcp_autolowat *skel)\n+{\n+\ttcp_autolowat_run_rpc_tests(skel, AF_INET);\n+\ttcp_autolowat_run_rpc_tests(skel, AF_INET6);\n+}\n+\n+void test_tcp_autolowat(void)\n+{\n+\tstruct tcp_autolowat *skel;\n+\tstruct bpf_link *link[2];\n+\tint cgroup;\n+\n+\tskel = tcp_autolowat__open_and_load();\n+\tif (!ASSERT_OK_PTR(skel, \"open_and_load\"))\n+\t\treturn;\n+\n+\tcgroup = test__join_cgroup(\"/tcp_autolowat\");\n+\tif (!ASSERT_GE(cgroup, 0, \"join_cgroup\"))\n+\t\tgoto destroy_skel;\n+\n+\tlink[0] = bpf_map__attach_cgroup_opts(skel-\u003emaps.tcp_autolowat_ops, cgroup, NULL);\n+\tif (!ASSERT_OK_PTR(link[0], \"attach_cgroup(tcp_autolowat_ops)\"))\n+\t\tgoto close_cgroup;\n+\n+\tlink[1] = bpf_program__attach_cgroup(skel-\u003eprogs.tcp_autolowat_setsockopt, cgroup);\n+\tif (!ASSERT_OK_PTR(link[1], \"attach_cgroup(SETSOCKOPT)\"))\n+\t\tgoto destroy_sockops;\n+\n+\ttcp_autolowat_run_tests(skel);\n+\n+\tbpf_link__destroy(link[1]);\n+destroy_sockops:\n+\tbpf_link__destroy(link[0]);\n+close_cgroup:\n+\tclose(cgroup);\n+destroy_skel:\n+\ttcp_autolowat__destroy(skel);\n+}\ndiff --git a/tools/testing/selftests/bpf/progs/bpf_tcp_ops_hdr.c b/tools/testing/selftests/bpf/progs/bpf_tcp_ops_hdr.c\nindex f3e3dff13784c..706e94d794e46 100644\n--- a/tools/testing/selftests/bpf/progs/bpf_tcp_ops_hdr.c\n+++ b/tools/testing/selftests/bpf/progs/bpf_tcp_ops_hdr.c\n@@ -18,6 +18,24 @@ int found_cnt;\n __u8 found_d0;\n __u8 found_d1;\n \n+SEC(\"struct_ops\")\n+void BPF_PROG(test_listen, struct sock *sk)\n+{\n+\tbpf_tcp_ops_set_flags((struct tcp_sock *)sk,\n+\t\t\t BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_ALL |\n+\t\t\t BPF_TCP_OPS_FLAG_WRITE_HDR_OPT,\n+\t\t\t 0);\n+}\n+\n+SEC(\"struct_ops\")\n+void BPF_PROG(test_connect, struct sock *sk)\n+{\n+\tbpf_tcp_ops_set_flags((struct tcp_sock *)sk,\n+\t\t\t BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_UNKNOWN |\n+\t\t\t BPF_TCP_OPS_FLAG_WRITE_HDR_OPT,\n+\t\t\t 0);\n+}\n+\n SEC(\"struct_ops\")\n void BPF_PROG(test_hdr_opt_len, struct sock *sk, struct sk_buff *skb,\n \t struct request_sock *req, struct sk_buff *syn_skb,\n@@ -78,6 +96,8 @@ void BPF_PROG(test_parse_hdr, struct sock *sk, struct sk_buff *skb)\n \n SEC(\".struct_ops.link\")\n struct bpf_tcp_ops test_hdr_ops = {\n+\t.listen\t\t= (void *)test_listen,\n+\t.connect\t= (void *)test_connect,\n \t.hdr_opt_len\t= (void *)test_hdr_opt_len,\n \t.write_hdr_opt\t= (void *)test_write_hdr_opt,\n \t.parse_hdr\t= (void *)test_parse_hdr,\ndiff --git a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h\nindex 593b38f904174..4c999d59cbbce 100644\n--- a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h\n+++ b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h\n@@ -79,6 +79,8 @@\n \n #define NEXTHDR_TCP\t\t6\n \n+#define TCPHDR_FIN\t\t0x01\n+\n #define TCPOPT_NOP\t\t1\n #define TCPOPT_EOL\t\t0\n #define TCPOPT_MSS\t\t2\ndiff --git a/tools/testing/selftests/bpf/progs/tcp_autolowat.c b/tools/testing/selftests/bpf/progs/tcp_autolowat.c\nnew file mode 100644\nindex 0000000000000..8a55f3cee2609\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/tcp_autolowat.c\n@@ -0,0 +1,294 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Copyright 2026 Google LLC */\n+#include \"vmlinux.h\"\n+\n+#include \u003cstring.h\u003e\n+#include \u003climits.h\u003e\n+#include \u003cbpf/bpf_helpers.h\u003e\n+#include \u003cbpf/bpf_tracing.h\u003e\n+#include \u003cbpf/bpf_core_read.h\u003e\n+\n+#include \"bpf_tracing_net.h\"\n+\n+#define SOL_BPF\t\t\t0xdeadbeef\n+#define BPF_TCP_AUTOLOWAT\t0x8badf00d\n+\n+//#define DEBUG /* For verbose output. */\n+\n+struct rpc_descriptor {\n+\tu32 header_len;\n+\tu32 payload_len;\n+};\n+\n+#define RPC_DESC_SIZE\t\t(sizeof(struct rpc_descriptor))\n+#define MAX_RPC_DESC_PER_SKB\t100\n+\n+struct tcp_autolowat_cb {\n+\t/* Don't put this field at the end; BPF verifier complains. */\n+\tchar rpc_desc_buf[RPC_DESC_SIZE];\n+\tu32 rpc_desc_seq;\n+\tu32 rpc_end_seq;\n+#ifdef DEBUG\n+\tu32 isn;\n+#endif\n+\tu8 rpc_desc_buff_len;\n+};\n+\n+struct {\n+\t__uint(type, BPF_MAP_TYPE_SK_STORAGE);\n+\t__uint(map_flags, BPF_F_NO_PREALLOC);\n+\t__type(key, int);\n+\t__type(value, struct tcp_autolowat_cb);\n+} tcp_autolowat_map SEC(\".maps\");\n+\n+char test_name[64];\n+\n+#ifdef DEBUG\n+#define LOG(str, ...)\t\t\t\t\t\t\t\\\n+\tbpf_printk(\"%s: \" str, test_name, ##__VA_ARGS__)\n+#else\n+#define LOG(...)\n+#endif\n+\n+#define SEQ(val)\t\t\t\t\\\n+\t(val - cb-\u003eisn)\n+#define TP_SEQ(field)\t\t\t\t\\\n+\t(tp-\u003efield - cb-\u003eisn)\n+#define CB_SEQ(field)\t\t\t\t\\\n+\t(cb-\u003efield - cb-\u003eisn)\n+\n+static int tcp_parse_descriptor(struct tcp_autolowat_cb *cb,\n+\t\t\t\tstruct bpf_dynptr *dptr,\n+\t\t\t\tu32 seq, u32 end_seq)\n+{\n+\tstruct rpc_descriptor *rpc_desc;\n+\tu32 rpc_copied_seq;\n+\tu64 copy_len; /* u32 should work, but not for no_alu32 :/ */\n+\tu64 rpc_len;\n+\tint err;\n+\n+\trpc_copied_seq = cb-\u003erpc_desc_seq + cb-\u003erpc_desc_buff_len;\n+\n+\tif (before(cb-\u003erpc_desc_seq + RPC_DESC_SIZE, end_seq))\n+\t\tcopy_len = RPC_DESC_SIZE - cb-\u003erpc_desc_buff_len;\n+\telse\n+\t\tcopy_len = end_seq - rpc_copied_seq;\n+\n+\tif (copy_len == 0)\n+\t\tgoto disable; /* FIN. */\n+\tif (copy_len \u003e RPC_DESC_SIZE)\n+\t\tgoto disable; /* always false, only for verifier. */\n+\tif (cb-\u003erpc_desc_buff_len \u003e= RPC_DESC_SIZE)\n+\t\tgoto disable; /* always false, only for verifier. */\n+\n+\terr = bpf_dynptr_read(cb-\u003erpc_desc_buf + cb-\u003erpc_desc_buff_len,\n+\t\t\t copy_len, dptr, rpc_copied_seq - seq, 0);\n+\tif (err)\n+\t\tgoto disable;\n+\n+\tcb-\u003erpc_desc_buff_len += copy_len;\n+\n+\tif (cb-\u003erpc_desc_buff_len != RPC_DESC_SIZE) {\n+\t\tLOG(\"Copied %d bytes: rpc_desc_buff_len: %u\", copy_len, cb-\u003erpc_desc_buff_len);\n+\t\tgoto partial;\n+\t}\n+\n+\trpc_desc = (struct rpc_descriptor *)cb-\u003erpc_desc_buf;\n+\trpc_len = RPC_DESC_SIZE + rpc_desc-\u003eheader_len + rpc_desc-\u003epayload_len;\n+\n+\tif (rpc_len \u003e INT_MAX)\n+\t\tgoto disable;\n+\n+\tcb-\u003erpc_end_seq = cb-\u003erpc_desc_seq + rpc_len;\n+\n+\tLOG(\"Copied full descriptor: rpc_desc_seq: %u, rpc_end_seq: %u, header_len: %u, payload_len: %u\",\n+\t CB_SEQ(rpc_desc_seq), CB_SEQ(rpc_end_seq),\n+\t rpc_desc-\u003eheader_len, rpc_desc-\u003epayload_len);\n+\n+\treturn 0;\n+disable:\n+\treturn -1;\n+partial:\n+\treturn 1;\n+}\n+\n+static void tcp_set_autolowat(struct tcp_autolowat_cb *cb,\n+\t\t\t struct sock *sk)\n+{\n+\tstruct tcp_sock *tp = (struct tcp_sock *)sk;\n+\tu32 val; /* To handle wraparound. */\n+\n+\tLOG(\"Setting rcvlowat: tp-\u003ecopied_seq: %u, rpc_desc_seq: %u, rpc_end_seq: %u, rpc_desc_buff_len: %u\",\n+\t TP_SEQ(copied_seq), CB_SEQ(rpc_desc_seq),\n+\t CB_SEQ(rpc_end_seq), cb-\u003erpc_desc_buff_len);\n+\n+\tif (before(tp-\u003ecopied_seq, cb-\u003erpc_desc_seq))\n+\t\tval = cb-\u003erpc_desc_seq - tp-\u003ecopied_seq;\n+\telse if (cb-\u003erpc_desc_buff_len != RPC_DESC_SIZE)\n+\t\tval = RPC_DESC_SIZE;\n+\telse\n+\t\tval = cb-\u003erpc_end_seq - tp-\u003ecopied_seq;\n+\n+\tif (val != tp-\u003einet_conn.icsk_inet.sk.sk_rcvlowat) {\n+\t\tbpf_tcp_ops_set_rcvlowat(sk, val);\n+\n+\t\tLOG(\"Set rcvlowat: expected: %u, actual: %d\\n\",\n+\t\t val, tp-\u003einet_conn.icsk_inet.sk.sk_rcvlowat);\n+\t} else {\n+\t\tLOG(\"No need to set rcvlowat: %u\\n\", val);\n+\t}\n+}\n+\n+static void tcp_disable_autolowat(struct sock *sk)\n+{\n+\tbpf_tcp_ops_set_flags((struct tcp_sock *)sk, 0, BPF_TCP_OPS_FLAG_RCVQ);\n+\n+\tbpf_tcp_ops_set_rcvlowat(sk, 1);\n+\n+\tLOG(\"Disabled autolowat\");\n+}\n+\n+static void tcp_do_autolowat(struct tcp_autolowat_cb *cb,\n+\t\t\t struct sock *sk, struct sk_buff *skb)\n+{\n+\tstruct bpf_dynptr dptr;\n+\tstruct tcp_skb_cb *tcb;\n+\tu32 seq, end_seq;\n+\tint ret = 0, i;\n+\n+\tif (bpf_dynptr_from_skb((struct __sk_buff *)skb, 0, \u0026dptr)) {\n+\t\tret = -1;\n+\t\tgoto update;\n+\t}\n+\n+\ttcb = bpf_core_cast(skb-\u003ecb, struct tcp_skb_cb);\n+\tseq = tcb-\u003eseq;\n+\tend_seq = tcb-\u003eend_seq - !!(tcb-\u003etcp_flags \u0026 TCPHDR_FIN);\n+\n+\tLOG(\"Start parsing skb: seq: %u, end_seq: %u, len: %u, rpc_desc_seq: %u, rpc_end_seq: %u, rpc_buff_len: %u\",\n+\t SEQ(seq), SEQ(end_seq), end_seq - seq,\n+\t CB_SEQ(rpc_desc_seq), CB_SEQ(rpc_end_seq), cb-\u003erpc_desc_buff_len);\n+\n+\tif (cb-\u003erpc_desc_buff_len != RPC_DESC_SIZE) {\n+\t\tret = tcp_parse_descriptor(cb, \u0026dptr, seq, end_seq);\n+\t\tif (ret)\n+\t\t\tgoto update;\n+\t}\n+\n+\ti = 0;\n+\n+\twhile (1) {\n+\t\tif (i++ \u003e MAX_RPC_DESC_PER_SKB) {\n+\t\t\tret = -1;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (after(cb-\u003erpc_end_seq, end_seq)) {\n+\t\t\tLOG(\"No more descriptor: rpc_end_seq: %u, end_seq: %u\",\n+\t\t\t CB_SEQ(rpc_end_seq), SEQ(end_seq));\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tcb-\u003erpc_desc_seq = cb-\u003erpc_end_seq;\n+\t\tcb-\u003erpc_desc_buff_len = 0;\n+\n+\t\tif (cb-\u003erpc_end_seq == end_seq)\n+\t\t\tbreak;\n+\n+\t\tLOG(\"Found next descriptor: rpc_end_seq: %u, end_seq: %u, len: %u\",\n+\t\t CB_SEQ(rpc_end_seq), SEQ(end_seq), end_seq - cb-\u003erpc_end_seq);\n+\n+\t\tret = tcp_parse_descriptor(cb, \u0026dptr, seq, end_seq);\n+\t\tif (ret)\n+\t\t\tbreak;\n+\t}\n+\n+update:\n+\tif (ret \u003e= 0)\n+\t\ttcp_set_autolowat(cb, sk);\n+\telse\n+\t\ttcp_disable_autolowat(sk);\n+}\n+\n+SEC(\"struct_ops\")\n+void BPF_PROG(tcp_autolowat_enqueue_rcvq, struct sock *sk, struct sk_buff *skb)\n+{\n+\tstruct tcp_autolowat_cb *cb;\n+\n+\tcb = bpf_sk_storage_get(\u0026tcp_autolowat_map, sk, 0, 0);\n+\tif (!cb)\n+\t\treturn;\n+\n+\ttcp_do_autolowat(cb, sk, skb);\n+}\n+\n+SEC(\"struct_ops\")\n+void BPF_PROG(tcp_autolowat_dequeue_rcvq, struct sock *sk)\n+{\n+\tstruct tcp_autolowat_cb *cb;\n+\n+\tcb = bpf_sk_storage_get(\u0026tcp_autolowat_map, sk, 0, 0);\n+\tif (!cb)\n+\t\treturn;\n+\n+\ttcp_set_autolowat(cb, sk);\n+}\n+\n+SEC(\".struct_ops.link\")\n+struct bpf_tcp_ops tcp_autolowat_ops = {\n+\t.enqueue_rcvq = (void *)tcp_autolowat_enqueue_rcvq,\n+\t.dequeue_rcvq = (void *)tcp_autolowat_dequeue_rcvq,\n+};\n+\n+static int tcp_init_autolowat_cb(struct bpf_tcp_sock *btp)\n+{\n+\tstruct tcp_autolowat_cb *cb;\n+\tstruct tcp_sock *tp;\n+\n+\tcb = bpf_sk_storage_get(\u0026tcp_autolowat_map, btp, 0,\n+\t\t\t\tBPF_SK_STORAGE_GET_F_CREATE);\n+\tif (!cb)\n+\t\treturn -1;\n+\n+\ttp = bpf_core_cast(btp, struct tcp_sock);\n+\n+\tcb-\u003erpc_desc_seq = tp-\u003ecopied_seq;\n+\tcb-\u003erpc_end_seq = tp-\u003ecopied_seq;\n+#ifdef DEBUG\n+\tcb-\u003eisn = tp-\u003ecopied_seq;\n+#endif\n+\n+\treturn bpf_tcp_ops_set_flags((struct tcp_sock *)btp,\n+\t\t\t\t BPF_TCP_OPS_FLAG_RCVQ, 0);\n+}\n+\n+SEC(\"cgroup/setsockopt\")\n+int tcp_autolowat_setsockopt(struct bpf_sockopt *ctx)\n+{\n+\tvoid *optval_end = ctx-\u003eoptval_end;\n+\tint *optval = ctx-\u003eoptval;\n+\tstruct bpf_tcp_sock *btp;\n+\n+\tif (ctx-\u003elevel != SOL_BPF || ctx-\u003eoptname != BPF_TCP_AUTOLOWAT)\n+\t\tgoto out;\n+\n+\tif (optval + 1 \u003e optval_end)\n+\t\treturn 0; /* -EPERM */\n+\n+\tbtp = bpf_tcp_sock(ctx-\u003esk);\n+\tif (!btp)\n+\t\tgoto out;\n+\n+\tif (*optval \u0026\u0026 tcp_init_autolowat_cb(btp))\n+\t\treturn 0; /* -EPERM */\n+\n+\t/*\n+\t * BPF has consumed this option, don't call kernel\n+\t * setsockopt handler.\n+\t */\n+\tctx-\u003eoptlen = -1;\n+out:\n+\treturn 1;\n+}\n+\n+char _license[] SEC(\"license\") = \"GPL\";\n"
} |
| 2/1 | 2026/10/06 20:07 | agent | patch-evaluator |
6mModel:core Args: null Results: {
"EnableConfigs": [
"INET",
"CGROUPS",
"CGROUP_BPF",
"BPF_SYSCALL",
"BPF_JIT",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"bpf_tcp_ops_set_flags",
"bpf_tcp_ops_set_rcvlowat",
"__tcp_set_rcvlowat",
"tcp_set_rcvlowat",
"tcp_fastopen_add_skb"
],
"Reasoning": "The patch series introduces new bpf_tcp_ops flags and callbacks (enqueue_rcvq, dequeue_rcvq) in core TCP hot paths, along with new BPF kfuncs (bpf_tcp_ops_set_flags and bpf_tcp_ops_set_rcvlowat) and logic for dynamic SO_RCVLOWAT tuning. These changes affect reachable TCP input/output paths and BPF struct_ops handling, making them relevant for fuzzing.",
"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 03049c52daff18ae374ab888a324b6713ecef26a
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Oct 6 20:07:14 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst
index 0f6088c4ab8bb..e4776905e8821 100644
--- a/Documentation/networking/net_cachelines/tcp_sock.rst
+++ b/Documentation/networking/net_cachelines/tcp_sock.rst
@@ -151,6 +151,7 @@ u32 urg_seq
unsigned_int keepalive_time
unsigned_int keepalive_intvl
int linger2
+u32 bpf_tcp_ops_flags read_mostly read_mostly bpf_tcp_ops_hdr_opt_len,bpf_skops_write_hdr_opt(tx);bpf_tcp_ops_parse_hdr,tcp_bpf_rtt,tcp_cleanup_rbuf,tcp_queue_rcv,tcp_ofo_queue,tcp_fastopen_add_skb(rx);
u8 bpf_sock_ops_cb_flags
u8:1 bpf_chg_cc_inprogress
u16 timeout_rehash
diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
index 8a75a6cd73096..02ef7f899b3de 100644
--- a/include/linux/bpf-cgroup.h
+++ b/include/linux/bpf-cgroup.h
@@ -345,27 +345,19 @@ static inline bool cgroup_bpf_sock_enabled(struct sock *sk,
* calling bpf_setsockopt on listener-sk will not make sense anyway,
* so passing 'sock_ops->sk == req_sk' to the bpf prog is appropriate here.
*/
-#define BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(sock_ops, sk) \
-({ \
- int __ret = 0; \
- if (cgroup_bpf_enabled(CGROUP_SOCK_OPS)) \
- __ret = __cgroup_bpf_run_filter_sock_ops(sk, \
- sock_ops, \
- CGROUP_SOCK_OPS); \
- __ret; \
-})
-
-#define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) \
-({ \
- int __ret = 0; \
- if (cgroup_bpf_enabled(CGROUP_SOCK_OPS) && (sock_ops)->sk) { \
- typeof(sk) __sk = sk_to_full_sk((sock_ops)->sk); \
- if (__sk && sk_fullsock(__sk)) \
- __ret = __cgroup_bpf_run_filter_sock_ops(__sk, \
- sock_ops, \
- CGROUP_SOCK_OPS); \
- } \
- __ret; \
+#define __BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(sock_ops, sk) \
+ __cgroup_bpf_run_filter_sock_ops(sk, sock_ops, \
+ CGROUP_SOCK_OPS)
+
+#define __BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) \
+({ \
+ int __ret = 0; \
+ typeof(sk) __sk = sk_to_full_sk((sock_ops)->sk); \
+ if (__sk && sk_fullsock(__sk)) \
+ __ret = __cgroup_bpf_run_filter_sock_ops(__sk, \
+ sock_ops, \
+ CGROUP_SOCK_OPS); \
+ __ret; \
})
#define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(atype, major, minor, access) \
@@ -529,7 +521,7 @@ static inline int cgroup_bpf_struct_ops_attach(struct bpf_map *map,
#define BPF_CGROUP_RUN_PROG_UDP4_RECVMSG_LOCK(sk, uaddr, uaddrlen) ({ 0; })
#define BPF_CGROUP_RUN_PROG_UDP6_RECVMSG_LOCK(sk, uaddr, uaddrlen) ({ 0; })
#define BPF_CGROUP_RUN_PROG_UNIX_RECVMSG_LOCK(sk, uaddr, uaddrlen) ({ 0; })
-#define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; })
+#define __BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; })
#define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(atype, major, minor, access) ({ 0; })
#define BPF_CGROUP_RUN_PROG_SYSCTL(head,table,write,buf,count,pos) ({ 0; })
#define BPF_CGROUP_RUN_PROG_GETSOCKOPT(sock, level, optname, optval, \
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 6a8c77719322f..24bb751cc65a6 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -233,6 +233,13 @@ struct tcp_sock {
is_sack_reneg:1, /* in recovery from loss with SACK reneg? */
is_cwnd_limited:1,/* forward progress limited by snd_cwnd? */
recvmsg_inq : 1;/* Indicate # of bytes in queue upon recvmsg */
+#ifdef CONFIG_BPF
+ u32 bpf_tcp_ops_flags;
+#define BPF_TCP_OPS_TEST_FLAG(TP, ARG) \
+ (READ_ONCE((TP)->bpf_tcp_ops_flags) & BPF_TCP_OPS_FLAG_ ## ARG)
+#else
+#define BPF_TCP_OPS_TEST_FLAG(TP, ARG) (0)
+#endif
__cacheline_group_end(tcp_sock_read_txrx);
/* RX read-mostly hotpath cache lines */
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 4ecabf4989de9..f7624ab9b4208 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -512,6 +512,7 @@ void tcp_set_keepalive(struct sock *sk, int val);
void tcp_syn_ack_timeout(const struct request_sock *req);
int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
int flags);
+int __tcp_set_rcvlowat(struct sock *sk, int val, bool wakeup);
int tcp_set_rcvlowat(struct sock *sk, int val);
void tcp_set_rcvbuf(struct sock *sk, int val);
int tcp_set_window_clamp(struct sock *sk, int val);
@@ -2891,7 +2892,7 @@ static inline void bpf_skops_init_skb(struct bpf_sock_ops_kern *skops,
* program loaded).
*/
#ifdef CONFIG_BPF
-static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)
+static inline int __tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)
{
struct bpf_sock_ops_kern sock_ops;
int ret;
@@ -2908,7 +2909,7 @@ static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)
if (nargs > 0)
memcpy(sock_ops.args, args, nargs * sizeof(*args));
- ret = BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops);
+ ret = __BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops);
if (ret == 0)
ret = sock_ops.reply;
else
@@ -2916,42 +2917,37 @@ static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)
return ret;
}
-static inline int tcp_call_bpf_2arg(struct sock *sk, int op, u32 arg1, u32 arg2)
-{
- u32 args[2] = {arg1, arg2};
-
- return tcp_call_bpf(sk, op, 2, args);
-}
-
-static inline int tcp_call_bpf_3arg(struct sock *sk, int op, u32 arg1, u32 arg2,
- u32 arg3)
-{
- u32 args[3] = {arg1, arg2, arg3};
+#define tcp_call_bpf(sk, op) \
+({ \
+ int __ret = 0; \
+ if (cgroup_bpf_enabled(CGROUP_SOCK_OPS)) { \
+ __ret = __tcp_call_bpf(sk, op, 0, NULL); \
+ } \
+ __ret; \
+})
- return tcp_call_bpf(sk, op, 3, args);
-}
+#define tcp_call_bpf_flag(sk, op, ...) \
+do { \
+ if (cgroup_bpf_enabled(CGROUP_SOCK_OPS) && \
+ BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk), op ## _FLAG)) { \
+ u32 __args[] = { __VA_ARGS__ }; \
+ __tcp_call_bpf(sk, op, ARRAY_SIZE(__args), __args); \
+ } \
+} while (0)
static inline void tcp_clear_sock_ops_cb_flags(struct sock *sk)
{
tcp_sk(sk)->bpf_sock_ops_cb_flags = 0;
+ WRITE_ONCE(tcp_sk(sk)->bpf_tcp_ops_flags, 0);
}
#else
-static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)
-{
- return -EPERM;
-}
-
-static inline int tcp_call_bpf_2arg(struct sock *sk, int op, u32 arg1, u32 arg2)
+static inline int tcp_call_bpf(struct sock *sk, int op)
{
return -EPERM;
}
-static inline int tcp_call_bpf_3arg(struct sock *sk, int op, u32 arg1, u32 arg2,
- u32 arg3)
-{
- return -EPERM;
-}
+#define tcp_call_bpf_flag(sk, op, ...) do { } while (0)
static inline void tcp_clear_sock_ops_cb_flags(struct sock *sk)
{
@@ -2989,7 +2985,7 @@ struct bpf_tcp_ops {
/* Called when the retransmission timer fires. */
void (*rto)(struct sock *sk);
- /* Called on every RTT sample.
+ /* Called on every RTT sample if BPF_TCP_OPS_FLAG_RTT is enabled.
* @mrtt: the measured RTT, in microseconds.
* @srtt: the updated smoothed RTT.
*/
@@ -3016,6 +3012,10 @@ struct bpf_tcp_ops {
* Parse the TCP header options of an incoming skb received on an
* established connection. Use bpf_dynptr_from_skb()/bpf_skb_load_bytes()
* to access the options.
+ *
+ * Called if BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_ALL is enabled, or if
+ * BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_UNKNOWN is enabled and an unknown
+ * option is received.
*/
void (*parse_hdr)(struct sock *sk, struct sk_buff *skb);
@@ -3023,6 +3023,8 @@ struct bpf_tcp_ops {
* Reserve space in the outgoing TCP header for options to be written
* later by write_hdr_opt(). Call bpf_reserve_hdr_opt() to reserve bytes.
*
+ * Called if BPF_TCP_OPS_FLAG_WRITE_HDR_OPT is enabled.
+ *
* @skb: outgoing packet. NULL when called from tcp_current_mss()
* (MSS sizing).
* @req: request_sock on the synack path; NULL otherwise.
@@ -3041,6 +3043,8 @@ struct bpf_tcp_ops {
* Use bpf_store_hdr_opt() to write; it appends within the reserved window
* shared with legacy SOCKOPS.
*
+ * Called if BPF_TCP_OPS_FLAG_WRITE_HDR_OPT is enabled.
+ *
* @skb: outgoing packet.
* @req: request_sock on the synack path; NULL otherwise.
* @syn_skb: incoming SYN on the synack path; NULL otherwise.
@@ -3053,24 +3057,47 @@ struct bpf_tcp_ops {
struct request_sock *req, struct sk_buff *syn_skb,
enum tcp_synack_type synack_type,
u32 opt_off);
+
+ /*
+ * Called when an incoming skb is enqueued to sk->sk_receive_queue
+ * if BPF_TCP_OPS_FLAG_RCVQ is enabled.
+ */
+ void (*enqueue_rcvq)(struct sock *sk, struct sk_buff *skb);
+
+ /*
+ * Called after data is dequeued from sk->sk_receive_queue
+ * if BPF_TCP_OPS_FLAG_RCVQ is enabled.
+ */
+ void (*dequeue_rcvq)(struct sock *sk);
};
-#define bpf_tcp_ops_call(op, sk, ...) \
+#define __bpf_tcp_ops_call(op, sk, ...) \
do { \
- if (cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS)) { \
- const struct bpf_prog_array_item *item; \
- const struct bpf_tcp_ops *tcp_ops; \
- struct cgroup *cgrp; \
+ const struct bpf_prog_array_item *item; \
+ const struct bpf_tcp_ops *tcp_ops; \
+ struct cgroup *cgrp; \
\
- cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); \
- rcu_read_lock_dont_migrate(); \
- bpf_cgroup_struct_ops_foreach(tcp_ops, item, cgrp, \
- CGROUP_TCP_SOCK_OPS) { \
- if (tcp_ops->op) \
- tcp_ops->op(sk, ##__VA_ARGS__); \
- } \
- rcu_read_unlock_migrate(); \
+ cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); \
+ rcu_read_lock_dont_migrate(); \
+ bpf_cgroup_struct_ops_foreach(tcp_ops, item, cgrp, \
+ CGROUP_TCP_SOCK_OPS) { \
+ if (tcp_ops->op) \
+ tcp_ops->op(sk, ##__VA_ARGS__); \
} \
+ rcu_read_unlock_migrate(); \
+} while (0)
+
+#define bpf_tcp_ops_call(op, sk, ...) \
+do { \
+ if (cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS)) \
+ __bpf_tcp_ops_call(op, sk, ##__VA_ARGS__); \
+} while (0)
+
+#define bpf_tcp_ops_call_flag(op, flag, sk, ...) \
+do { \
+ if (cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS) && \
+ BPF_TCP_OPS_TEST_FLAG(tcp_sk(sk), flag)) \
+ __bpf_tcp_ops_call(op, sk, ##__VA_ARGS__); \
} while (0)
#define bpf_tcp_ops_call_int(op, init_retval, sk, ...) \
@@ -3106,7 +3133,9 @@ do { \
})
#else
-#define bpf_tcp_ops_call(op, sk, ...) do { } while (0)
+#define __bpf_tcp_ops_call(op, sk, ...) do { } while (0)
+#define bpf_tcp_ops_call(op, sk, ...) do { } while (0)
+#define bpf_tcp_ops_call_flag(op, flag, sk, ...) do { } while (0)
#define bpf_tcp_ops_call_int(op, init_retval, sk, ...) (init_retval)
#endif
@@ -3114,7 +3143,7 @@ static inline u32 tcp_timeout_init(struct sock *sk)
{
int timeout;
- timeout = tcp_call_bpf(sk, BPF_SOCK_OPS_TIMEOUT_INIT, 0, NULL);
+ timeout = tcp_call_bpf(sk, BPF_SOCK_OPS_TIMEOUT_INIT);
timeout = bpf_tcp_ops_call_int(timeout_init, timeout, sk);
if (timeout <= 0)
timeout = TCP_TIMEOUT_INIT;
@@ -3125,7 +3154,7 @@ static inline u32 tcp_rwnd_init_bpf(struct sock *sk)
{
int rwnd;
- rwnd = tcp_call_bpf(sk, BPF_SOCK_OPS_RWND_INIT, 0, NULL);
+ rwnd = tcp_call_bpf(sk, BPF_SOCK_OPS_RWND_INIT);
rwnd = bpf_tcp_ops_call_int(rwnd_init, rwnd, sk);
if (rwnd < 0)
rwnd = 0;
@@ -3134,14 +3163,13 @@ static inline u32 tcp_rwnd_init_bpf(struct sock *sk)
static inline bool tcp_bpf_ca_needs_ecn(struct sock *sk)
{
- return (tcp_call_bpf(sk, BPF_SOCK_OPS_NEEDS_ECN, 0, NULL) == 1);
+ return (tcp_call_bpf(sk, BPF_SOCK_OPS_NEEDS_ECN) == 1);
}
static inline void tcp_bpf_rtt(struct sock *sk, long mrtt, u32 srtt)
{
- if (BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk), BPF_SOCK_OPS_RTT_CB_FLAG))
- tcp_call_bpf_2arg(sk, BPF_SOCK_OPS_RTT_CB, mrtt, srtt);
- bpf_tcp_ops_call(rtt, sk, mrtt, srtt);
+ tcp_call_bpf_flag(sk, BPF_SOCK_OPS_RTT_CB, mrtt, srtt);
+ bpf_tcp_ops_call_flag(rtt, RTT, sk, mrtt, srtt);
}
#if IS_ENABLED(CONFIG_SMC)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index e0ed44b1bbcb7..6f70db7515dd4 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -7340,6 +7340,31 @@ enum {
*/
};
+/*
+ * Most callbacks of struct bpf_tcp_ops are placed in the slow
+ * path (e.g., one-shot connection setup or unlikely events like
+ * timers) and are invoked simply by defining non-NULL callbacks.
+ *
+ * Callbacks in the fast path, however, would incur noticeable
+ * overhead even when set to NULL, so they are disabled by default
+ * and must be explicitly enabled per socket via bpf_tcp_ops_set_flags().
+ *
+ * The flags are per-socket and shared by all effective bpf_tcp_ops
+ * programs.
+ */
+enum {
+ /* .rtt() */
+ BPF_TCP_OPS_FLAG_RTT = (1 << 0),
+ /* .parse_hdr() */
+ BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_ALL = (1 << 1),
+ BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_UNKNOWN = (1 << 2),
+ /* .hdr_opt_len() and .write_hdr_opt() */
+ BPF_TCP_OPS_FLAG_WRITE_HDR_OPT = (1 << 3),
+ /* .enqueue_rcvq() and .dequeue_rcvq() */
+ BPF_TCP_OPS_FLAG_RCVQ = (1 << 4),
+ BPF_TCP_OPS_FLAG_ALL = (1 << 5) - 1,
+};
+
/* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
* changes between the TCP and BPF versions. Ideally this should never happen.
* If it does, we need to add code to convert them before calling
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index cdcfc7d3c6d2e..035c83338e0f1 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -226,7 +226,7 @@ int __inet_listen_sk(struct sock *sk, int backlog)
if (err)
return err;
- tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_LISTEN_CB, 0, NULL);
+ tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_LISTEN_CB);
bpf_tcp_ops_call(listen, sk);
}
return 0;
diff --git a/net/ipv4/bpf_tcp_ops.c b/net/ipv4/bpf_tcp_ops.c
index 681fed6429999..2ba73dd6c52cc 100644
--- a/net/ipv4/bpf_tcp_ops.c
+++ b/net/ipv4/bpf_tcp_ops.c
@@ -76,6 +76,14 @@ static void write_hdr_opt_stub(struct sock *sk, struct sk_buff *skb,
{
}
+static void enqueue_rcvq_stub(struct sock *sk, struct sk_buff *skb)
+{
+}
+
+static void dequeue_rcvq_stub(struct sock *sk)
+{
+}
+
static struct bpf_tcp_ops __bpf_tcp_ops = {
.timeout_init = timeout_init_stub,
.rwnd_init = rwnd_init_stub,
@@ -90,6 +98,8 @@ static struct bpf_tcp_ops __bpf_tcp_ops = {
.parse_hdr = parse_hdr_stub,
.hdr_opt_len = hdr_opt_len_stub,
.write_hdr_opt = write_hdr_opt_stub,
+ .enqueue_rcvq = enqueue_rcvq_stub,
+ .dequeue_rcvq = dequeue_rcvq_stub,
};
BPF_CALL_4(bpf_tcp_ops_store_hdr_opt, void *, ctx, const void *, from,
@@ -210,6 +220,24 @@ const struct bpf_func_proto bpf_tcp_ops_get_retval_proto = {
.ret_type = RET_INTEGER,
};
+static bool is_sockopt_supported(u32 moff)
+{
+ switch (moff) {
+ case offsetof(struct bpf_tcp_ops, active_established):
+ case offsetof(struct bpf_tcp_ops, passive_established):
+ case offsetof(struct bpf_tcp_ops, rto):
+ case offsetof(struct bpf_tcp_ops, rtt):
+ case offsetof(struct bpf_tcp_ops, set_state):
+ case offsetof(struct bpf_tcp_ops, retrans):
+ case offsetof(struct bpf_tcp_ops, connect):
+ case offsetof(struct bpf_tcp_ops, listen):
+ case offsetof(struct bpf_tcp_ops, parse_hdr):
+ return true;
+ }
+
+ return false;
+}
+
static const struct bpf_func_proto *
get_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
{
@@ -221,22 +249,13 @@ get_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
case BPF_FUNC_sk_storage_delete:
return &bpf_sk_storage_delete_proto;
case BPF_FUNC_setsockopt:
- /* The sk may be an unlocked listener (synack path) or NULL
- * fullsock; disable for members that can run unlocked.
- */
- if (moff == offsetof(struct bpf_tcp_ops, rwnd_init) ||
- moff == offsetof(struct bpf_tcp_ops, timeout_init) ||
- moff == offsetof(struct bpf_tcp_ops, hdr_opt_len) ||
- moff == offsetof(struct bpf_tcp_ops, write_hdr_opt))
- return NULL;
- return &bpf_sk_setsockopt_proto;
+ if (is_sockopt_supported(moff))
+ return &bpf_sk_setsockopt_proto;
+ return NULL;
case BPF_FUNC_getsockopt:
- if (moff == offsetof(struct bpf_tcp_ops, rwnd_init) ||
- moff == offsetof(struct bpf_tcp_ops, timeout_init) ||
- moff == offsetof(struct bpf_tcp_ops, hdr_opt_len) ||
- moff == offsetof(struct bpf_tcp_ops, write_hdr_opt))
- return NULL;
- return &bpf_sk_getsockopt_proto;
+ if (is_sockopt_supported(moff))
+ return &bpf_sk_getsockopt_proto;
+ return NULL;
case BPF_FUNC_get_retval:
if (moff == offsetof(struct bpf_tcp_ops, timeout_init) ||
moff == offsetof(struct bpf_tcp_ops, rwnd_init))
@@ -319,8 +338,116 @@ static struct bpf_struct_ops bpf_tcp_ops = {
.owner = THIS_MODULE,
};
+__bpf_kfunc_start_defs();
+
+__bpf_kfunc int bpf_tcp_ops_set_flags(struct tcp_sock *tp, u32 enable, u32 disable)
+{
+ u32 old, new;
+
+ if ((enable & disable) || (enable | disable) & ~BPF_TCP_OPS_FLAG_ALL)
+ return -EINVAL;
+
+ if (sk_is_mptcp((struct sock *)tp) && (enable & BPF_TCP_OPS_FLAG_RCVQ))
+ return -EOPNOTSUPP;
+
+ old = READ_ONCE(tp->bpf_tcp_ops_flags);
+
+ do {
+ new = (old | enable) & ~disable;
+ if (new == old)
+ break;
+ } while (!try_cmpxchg(&tp->bpf_tcp_ops_flags, &old, new));
+
+ return 0;
+}
+
+__bpf_kfunc int bpf_tcp_ops_set_rcvlowat(struct sock *sk, int rcvlowat,
+ const struct bpf_prog_aux *aux)
+{
+ u32 moff = aux->attach_st_ops_member_off;
+ bool wakeup = false;
+
+ if (moff == offsetof(struct bpf_tcp_ops, dequeue_rcvq))
+ wakeup = true;
+
+ if (rcvlowat < 0)
+ rcvlowat = INT_MAX;
+
+ return __tcp_set_rcvlowat(sk, rcvlowat, wakeup);
+}
+
+__bpf_kfunc_end_defs();
+
+BTF_KFUNCS_START(bpf_tcp_ops_set_flags_kfunc_set)
+BTF_ID_FLAGS(func, bpf_tcp_ops_set_flags)
+BTF_KFUNCS_END(bpf_tcp_ops_set_flags_kfunc_set)
+
+BTF_KFUNCS_START(bpf_tcp_ops_set_rcvlowat_kfunc_set)
+BTF_ID_FLAGS(func, bpf_tcp_ops_set_rcvlowat, KF_IMPLICIT_ARGS)
+BTF_KFUNCS_END(bpf_tcp_ops_set_rcvlowat_kfunc_set)
+
+static int bpf_tcp_ops_set_flags_kfunc_filter(const struct bpf_prog *prog,
+ u32 kfunc_id)
+{
+ if (!btf_id_set8_contains(&bpf_tcp_ops_set_flags_kfunc_set, kfunc_id))
+ return 0;
+
+ if (prog->type == BPF_PROG_TYPE_STRUCT_OPS &&
+ prog->aux->st_ops == &bpf_tcp_ops)
+ return 0;
+
+ if (prog->type == BPF_PROG_TYPE_CGROUP_SOCKOPT ||
+ prog->type == BPF_PROG_TYPE_CGROUP_SKB)
+ return 0;
+
+ return -EACCES;
+}
+
+static const struct btf_kfunc_id_set bpf_tcp_ops_set_flags_kfunc_id_set = {
+ .owner = THIS_MODULE,
+ .set = &bpf_tcp_ops_set_flags_kfunc_set,
+ .filter = bpf_tcp_ops_set_flags_kfunc_filter,
+};
+
+static int bpf_tcp_ops_set_rcvlowat_kfunc_filter(const struct bpf_prog *prog,
+ u32 kfunc_id)
+{
+ u32 moff;
+
+ if (!btf_id_set8_contains(&bpf_tcp_ops_set_rcvlowat_kfunc_set, kfunc_id))
+ return 0;
+
+ if (prog->aux->st_ops != &bpf_tcp_ops)
+ return -EACCES;
+
+ moff = prog->aux->attach_st_ops_member_off;
+ if (moff != offsetof(struct bpf_tcp_ops, enqueue_rcvq) &&
+ moff != offsetof(struct bpf_tcp_ops, dequeue_rcvq))
+ return -EACCES;
+
+ return 0;
+}
+
+static const struct btf_kfunc_id_set bpf_tcp_ops_set_rcvlowat_kfunc_id_set = {
+ .owner = THIS_MODULE,
+ .set = &bpf_tcp_ops_set_rcvlowat_kfunc_set,
+ .filter = bpf_tcp_ops_set_rcvlowat_kfunc_filter,
+};
+
static int __init __bpf_tcp_ops_init(void)
{
- return register_bpf_struct_ops(&bpf_tcp_ops, bpf_tcp_ops);
+ int ret;
+
+ ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
+ &bpf_tcp_ops_set_flags_kfunc_id_set);
+ /* BPF_PROG_TYPE_CGROUP_{SOCKOPT,SKB} share BTF_KFUNC_HOOK_CGROUP. */
+ ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCKOPT,
+ &bpf_tcp_ops_set_flags_kfunc_id_set);
+ ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
+ &bpf_tcp_ops_set_rcvlowat_kfunc_id_set);
+ ret = ret ?: register_bpf_struct_ops(&bpf_tcp_ops, bpf_tcp_ops);
+
+ return ret;
}
+
late_initcall(__bpf_tcp_ops_init);
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 650a2e89950af..c3c756a1ba8cf 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1609,6 +1609,8 @@ void tcp_cleanup_rbuf(struct sock *sk, int copied)
"cleanup rbuf bug: copied %X seq %X rcvnxt %X\n",
tp->copied_seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt);
__tcp_cleanup_rbuf(sk, copied);
+
+ bpf_tcp_ops_call_flag(dequeue_rcvq, RCVQ, sk);
}
static void tcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
@@ -1825,8 +1827,7 @@ int tcp_peek_len(struct socket *sock)
return tcp_inq(sock->sk);
}
-/* Make sure sk_rcvbuf is big enough to satisfy SO_RCVLOWAT hint */
-int tcp_set_rcvlowat(struct sock *sk, int val)
+int __tcp_set_rcvlowat(struct sock *sk, int val, bool wakeup)
{
struct tcp_sock *tp = tcp_sk(sk);
int space, cap;
@@ -1839,7 +1840,8 @@ int tcp_set_rcvlowat(struct sock *sk, int val)
WRITE_ONCE(sk->sk_rcvlowat, val ? : 1);
/* Check if we need to signal EPOLLIN right now */
- tcp_data_ready(sk);
+ if (wakeup)
+ tcp_data_ready(sk);
if (sk->sk_userlocks & SOCK_RCVBUF_LOCK)
return 0;
@@ -1854,6 +1856,12 @@ int tcp_set_rcvlowat(struct sock *sk, int val)
return 0;
}
+/* Make sure sk_rcvbuf is big enough to satisfy SO_RCVLOWAT hint */
+int tcp_set_rcvlowat(struct sock *sk, int val)
+{
+ return __tcp_set_rcvlowat(sk, val, true);
+}
+
void tcp_set_rcvbuf(struct sock *sk, int val)
{
tcp_set_window_clamp(sk, tcp_win_from_space(sk, val));
@@ -2994,8 +3002,7 @@ void tcp_set_state(struct sock *sk, int state)
*/
BTF_TYPE_EMIT_ENUM(BPF_TCP_ESTABLISHED);
- if (BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk), BPF_SOCK_OPS_STATE_CB_FLAG))
- tcp_call_bpf_2arg(sk, BPF_SOCK_OPS_STATE_CB, oldstate, state);
+ tcp_call_bpf_flag(sk, BPF_SOCK_OPS_STATE_CB, oldstate, state);
bpf_tcp_ops_call(set_state, sk, state);
switch (state) {
@@ -5217,6 +5224,9 @@ static void __init tcp_struct_check(void)
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_txrx, lost_out);
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_txrx, sacked_out);
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_txrx, scaling_ratio);
+#ifdef CONFIG_BPF
+ CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_txrx, bpf_tcp_ops_flags);
+#endif
/* RX read-mostly hotpath cache lines */
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_rx, copied_seq);
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index 471c78be55137..6dfe40322fb59 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -281,6 +281,8 @@ void tcp_fastopen_add_skb(struct sock *sk, struct sk_buff *skb)
TCP_SKB_CB(skb)->seq++;
TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_SYN;
+ bpf_tcp_ops_call_flag(enqueue_rcvq, RCVQ, sk, skb);
+
tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
tcp_add_receive_queue(sk, skb);
tp->syn_data_acked = 1;
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 209db8effcc41..46f5c4fafa8db 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -146,14 +146,16 @@ EXPORT_SYMBOL_GPL(clean_acked_data_flush);
#ifdef CONFIG_CGROUP_BPF
static void bpf_skops_parse_hdr(struct sock *sk, struct sk_buff *skb)
{
- bool unknown_opt = tcp_sk(sk)->rx_opt.saw_unknown &&
- BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
- BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG);
- bool parse_all_opt = BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
- BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG);
struct bpf_sock_ops_kern sock_ops;
+ const struct tcp_sock *tp;
- if (likely(!unknown_opt && !parse_all_opt))
+ if (!cgroup_bpf_enabled(CGROUP_SOCK_OPS))
+ return;
+
+ tp = tcp_sk(sk);
+ if (!(tp->rx_opt.saw_unknown &&
+ BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG)) &&
+ !BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG))
return;
/* The skb will be handled in the
@@ -176,7 +178,7 @@ static void bpf_skops_parse_hdr(struct sock *sk, struct sk_buff *skb)
sock_ops.sk = sk;
bpf_skops_init_skb(&sock_ops, skb, tcp_hdrlen(skb));
- BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops);
+ __BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops);
}
static void bpf_skops_established(struct sock *sk, int bpf_op,
@@ -184,6 +186,9 @@ static void bpf_skops_established(struct sock *sk, int bpf_op,
{
struct bpf_sock_ops_kern sock_ops;
+ if (!cgroup_bpf_enabled(CGROUP_SOCK_OPS))
+ return;
+
sock_owned_by_me(sk);
memset(&sock_ops, 0, offsetof(struct bpf_sock_ops_kern, temp));
@@ -195,7 +200,7 @@ static void bpf_skops_established(struct sock *sk, int bpf_op,
if (skb)
bpf_skops_init_skb(&sock_ops, skb, tcp_hdrlen(skb));
- BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops);
+ __BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops);
}
#else
static void bpf_skops_parse_hdr(struct sock *sk, struct sk_buff *skb)
@@ -210,6 +215,11 @@ static void bpf_skops_established(struct sock *sk, int bpf_op,
static void bpf_tcp_ops_parse_hdr(struct sock *sk, struct sk_buff *skb)
{
+ const struct tcp_sock *tp;
+
+ if (!cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS))
+ return;
+
switch (sk->sk_state) {
case TCP_SYN_RECV:
case TCP_SYN_SENT:
@@ -217,7 +227,12 @@ static void bpf_tcp_ops_parse_hdr(struct sock *sk, struct sk_buff *skb)
return;
}
- bpf_tcp_ops_call(parse_hdr, sk, skb);
+ tp = tcp_sk(sk);
+
+ if ((tp->rx_opt.saw_unknown &&
+ BPF_TCP_OPS_TEST_FLAG(tp, PARSE_HDR_OPT_UNKNOWN)) ||
+ BPF_TCP_OPS_TEST_FLAG(tp, PARSE_HDR_OPT_ALL))
+ __bpf_tcp_ops_call(parse_hdr, sk, skb);
}
static __cold void tcp_gro_dev_warn(const struct sock *sk, const struct sk_buff *skb,
@@ -5350,6 +5365,8 @@ static void tcp_ofo_queue(struct sock *sk)
continue;
}
+ bpf_tcp_ops_call_flag(enqueue_rcvq, RCVQ, sk, skb);
+
tail = skb_peek_tail(&sk->sk_receive_queue);
eaten = tail && tcp_try_coalesce(sk, tail, skb, &fragstolen);
tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq);
@@ -5553,6 +5570,8 @@ static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb,
int eaten;
struct sk_buff *tail = skb_peek_tail(&sk->sk_receive_queue);
+ bpf_tcp_ops_call_flag(enqueue_rcvq, RCVQ, sk, skb);
+
eaten = (tail &&
tcp_try_coalesce(sk, tail,
skb, fragstolen)) ? 1 : 0;
diff --git a/net/ipv4/tcp_nv.c b/net/ipv4/tcp_nv.c
index f345897a68dfc..7b0dae23d9aa2 100644
--- a/net/ipv4/tcp_nv.c
+++ b/net/ipv4/tcp_nv.c
@@ -146,7 +146,7 @@ static void tcpnv_init(struct sock *sk)
* within a datacenter, where we have reasonable estimates of
* RTTs
*/
- base_rtt = tcp_call_bpf(sk, BPF_SOCK_OPS_BASE_RTT, 0, NULL);
+ base_rtt = tcp_call_bpf(sk, BPF_SOCK_OPS_BASE_RTT);
if (base_rtt > 0) {
ca->nv_base_rtt = base_rtt;
ca->nv_lower_bound_rtt = (base_rtt * 205) >> 8; /* 80% */
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 3ac465513bf51..db4fd1825d999 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -476,8 +476,9 @@ static u32 bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
struct bpf_sock_ops_kern sock_ops;
int err;
- if (likely(!BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
- BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG)) ||
+ if (!cgroup_bpf_enabled(CGROUP_SOCK_OPS) ||
+ !BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
+ BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG)||
!remaining)
return remaining;
@@ -518,7 +519,7 @@ static u32 bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
if (skb)
bpf_skops_init_skb(&sock_ops, skb, 0);
- err = BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(&sock_ops, sk);
+ err = __BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(&sock_ops, sk);
if (err || sock_ops.remaining_opt_len == remaining)
return remaining;
@@ -543,7 +544,8 @@ static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,
first_opt_off = tcp_hdrlen(skb) - max_opt_len;
- if (BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
+ if (cgroup_bpf_enabled(CGROUP_SOCK_OPS) &&
+ BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG)) {
struct bpf_sock_ops_kern sock_ops;
int err;
@@ -567,7 +569,7 @@ static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,
sock_ops.remaining_opt_len = max_opt_len;
bpf_skops_init_skb(&sock_ops, skb, first_opt_off);
- err = BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(&sock_ops, sk);
+ err = __BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(&sock_ops, sk);
if (!err)
nr_written = max_opt_len - sock_ops.remaining_opt_len;
}
@@ -581,8 +583,8 @@ static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,
* writer's bytes). The writer finds the append point by scanning from
* first_opt_off + nr_written to the first NOP.
*/
- bpf_tcp_ops_call(write_hdr_opt, sk, skb, req, syn_skb, synack_type,
- first_opt_off + nr_written);
+ bpf_tcp_ops_call_flag(write_hdr_opt, WRITE_HDR_OPT, sk, skb, req,
+ syn_skb, synack_type, first_opt_off + nr_written);
}
#else
static u32 bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
@@ -613,11 +615,13 @@ static u32 bpf_tcp_ops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
{
unsigned int remaining_out = remaining, reserved;
- if (!remaining)
- return 0;
+ if (!cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS) ||
+ !BPF_TCP_OPS_TEST_FLAG(tcp_sk(sk), WRITE_HDR_OPT)||
+ !remaining)
+ return remaining;
/* bpf_tcp_ops_reserve_hdr_opt() reserves space via remaining_out */
- bpf_tcp_ops_call(hdr_opt_len, sk, skb, req, syn_skb, synack_type, &remaining_out);
+ __bpf_tcp_ops_call(hdr_opt_len, sk, skb, req, syn_skb, synack_type, &remaining_out);
reserved = remaining - remaining_out;
if (!reserved)
@@ -1193,8 +1197,9 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
struct tcp_key *key)
{
struct tcp_sock *tp = tcp_sk(sk);
- unsigned int size = 0;
unsigned int eff_sacks;
+ unsigned int remaining;
+ unsigned int size = 0;
opts->options = 0;
opts->bpf_opt_len = 0;
@@ -1224,10 +1229,10 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
* left.
*/
if (sk_is_mptcp(sk)) {
- unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
bool has_ts = opts->options & OPTION_TS;
int opt_size;
+ remaining = MAX_TCP_OPTION_SPACE - size;
opts->mptcp.drop_ts = 0;
opt_size = mptcp_established_options(sk, skb, remaining, has_ts,
@@ -1244,7 +1249,8 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
eff_sacks = tp->rx_opt.num_sacks + tp->rx_opt.dsack;
if (unlikely(eff_sacks)) {
- const unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
+ remaining = MAX_TCP_OPTION_SPACE - size;
+
if (likely(remaining >= TCPOLEN_SACK_BASE_ALIGNED +
TCPOLEN_SACK_PERBLOCK)) {
opts->num_sack_blocks =
@@ -1275,24 +1281,14 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
}
}
- if (unlikely(BPF_SOCK_OPS_TEST_FLAG(tp,
- BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG))) {
- unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
+ remaining = MAX_TCP_OPTION_SPACE - size;
- remaining = bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,
- remaining);
-
- size = MAX_TCP_OPTION_SPACE - remaining;
- }
-
- if (cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS)) {
- unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
-
- remaining = bpf_tcp_ops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,
- remaining);
+ remaining = bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,
+ remaining);
+ remaining = bpf_tcp_ops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,
+ remaining);
- size = MAX_TCP_OPTION_SPACE - remaining;
- }
+ size = MAX_TCP_OPTION_SPACE - remaining;
return size;
}
@@ -3725,9 +3721,8 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
err = tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC);
}
- if (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RETRANS_CB_FLAG))
- tcp_call_bpf_3arg(sk, BPF_SOCK_OPS_RETRANS_CB,
- TCP_SKB_CB(skb)->seq, segs, err);
+ tcp_call_bpf_flag(sk, BPF_SOCK_OPS_RETRANS_CB,
+ TCP_SKB_CB(skb)->seq, segs, err);
bpf_tcp_ops_call(retrans, sk, skb, err);
if (unlikely(err) && err != -EBUSY)
@@ -4355,7 +4350,7 @@ int tcp_connect(struct sock *sk)
struct sk_buff *buff;
int err;
- tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_CONNECT_CB, 0, NULL);
+ tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_CONNECT_CB);
bpf_tcp_ops_call(connect, sk);
#if defined(CONFIG_TCP_MD5SIG) && defined(CONFIG_TCP_AO)
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 3d49adc517663..00debcba122b1 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -286,10 +286,8 @@ static int tcp_write_timeout(struct sock *sk)
tcp_fastopen_active_detect_blackhole(sk, expired);
mptcp_active_detect_blackhole(sk, expired);
- if (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RTO_CB_FLAG))
- tcp_call_bpf_3arg(sk, BPF_SOCK_OPS_RTO_CB,
- icsk->icsk_retransmits,
- icsk->icsk_rto, (int)expired);
+ tcp_call_bpf_flag(sk, BPF_SOCK_OPS_RTO_CB,
+ icsk->icsk_retransmits, icsk->icsk_rto, (int)expired);
bpf_tcp_ops_call(rto, sk);
if (expired) {
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index e0ed44b1bbcb7..6f70db7515dd4 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -7340,6 +7340,31 @@ enum {
*/
};
+/*
+ * Most callbacks of struct bpf_tcp_ops are placed in the slow
+ * path (e.g., one-shot connection setup or unlikely events like
+ * timers) and are invoked simply by defining non-NULL callbacks.
+ *
+ * Callbacks in the fast path, however, would incur noticeable
+ * overhead even when set to NULL, so they are disabled by default
+ * and must be explicitly enabled per socket via bpf_tcp_ops_set_flags().
+ *
+ * The flags are per-socket and shared by all effective bpf_tcp_ops
+ * programs.
+ */
+enum {
+ /* .rtt() */
+ BPF_TCP_OPS_FLAG_RTT = (1 << 0),
+ /* .parse_hdr() */
+ BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_ALL = (1 << 1),
+ BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_UNKNOWN = (1 << 2),
+ /* .hdr_opt_len() and .write_hdr_opt() */
+ BPF_TCP_OPS_FLAG_WRITE_HDR_OPT = (1 << 3),
+ /* .enqueue_rcvq() and .dequeue_rcvq() */
+ BPF_TCP_OPS_FLAG_RCVQ = (1 << 4),
+ BPF_TCP_OPS_FLAG_ALL = (1 << 5) - 1,
+};
+
/* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
* changes between the TCP and BPF versions. Ideally this should never happen.
* If it does, we need to add code to convert them before calling
diff --git a/tools/testing/selftests/bpf/prog_tests/tcp_autolowat.c b/tools/testing/selftests/bpf/prog_tests/tcp_autolowat.c
new file mode 100644
index 0000000000000..337f9d34a39c5
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/tcp_autolowat.c
@@ -0,0 +1,350 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright 2026 Google LLC */
+#include <sys/epoll.h>
+
+#include "test_progs.h"
+#include "cgroup_helpers.h"
+#include "network_helpers.h"
+
+#include "tcp_autolowat.skel.h"
+
+#define SOL_BPF 0xdeadbeef
+#define BPF_TCP_AUTOLOWAT 0x8badf00d
+
+struct rpc_descriptor {
+ u32 header_len;
+ u32 payload_len;
+};
+
+enum rpc_event_type {
+ RPC_EVENT_END,
+ RPC_EVENT_AUTOLOWAT,
+ RPC_EVENT_SEND,
+ RPC_EVENT_RECV,
+ RPC_EVENT_EPOLL,
+ RPC_EVENT_RCVLOWAT,
+};
+
+struct rpc_event {
+ enum rpc_event_type type;
+ union {
+ int len;
+ int nfds;
+ int val;
+ int rcvlowat;
+ };
+};
+
+#define RPC_DESC_SIZE (sizeof(struct rpc_descriptor))
+
+static struct rpc_test_case {
+ char data[4096];
+ struct rpc_descriptor desc[32];
+ struct rpc_event event[32];
+} rpc_test_cases[] = {
+ {
+ .desc = {
+ { .header_len = 100, .payload_len = 150 },
+ },
+ .event = {
+ { .type = RPC_EVENT_AUTOLOWAT, .val = 1},
+ /* Single full RPC message in skb. */
+ { .type = RPC_EVENT_SEND, .len = RPC_DESC_SIZE + 100 + 150},
+ { .type = RPC_EVENT_EPOLL, .nfds = 1},
+ { .type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE + 100 + 150},
+ },
+ },
+ {
+ .desc = {
+ {.header_len = 100, .payload_len = 150},
+ {.header_len = 100, .payload_len = 150},
+ {.header_len = 100, .payload_len = 150},
+ },
+ .event = {
+ { .type = RPC_EVENT_AUTOLOWAT, .val = 1},
+ /* Two full RPC messages in skb. */
+ {.type = RPC_EVENT_SEND, .len = (RPC_DESC_SIZE + 100 + 150) * 2},
+ {.type = RPC_EVENT_EPOLL, .nfds = 1},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = (RPC_DESC_SIZE + 100 + 150) * 2},
+ /* Single full RPC message in skb. */
+ { .type = RPC_EVENT_SEND, .len = RPC_DESC_SIZE + 100 + 150},
+ { .type = RPC_EVENT_EPOLL, .nfds = 1},
+ { .type = RPC_EVENT_RCVLOWAT, .rcvlowat = (RPC_DESC_SIZE + 100 + 150) * 3},
+ },
+ },
+ {
+ .desc = {
+ {.header_len = 100, .payload_len = 150},
+ {.header_len = 100, .payload_len = 150},
+ {.header_len = 100, .payload_len = 150},
+ },
+ .event = {
+ { .type = RPC_EVENT_AUTOLOWAT, .val = 1},
+ /* Two full RPC messages in skb. */
+ {.type = RPC_EVENT_SEND, .len = (RPC_DESC_SIZE + 100 + 150) * 2},
+ {.type = RPC_EVENT_EPOLL, .nfds = 1},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = (RPC_DESC_SIZE + 100 + 150) * 2},
+ /* Only the next descriptor in skb. */
+ { .type = RPC_EVENT_SEND, .len = RPC_DESC_SIZE},
+ { .type = RPC_EVENT_EPOLL, .nfds = 1},
+ { .type = RPC_EVENT_RCVLOWAT, .rcvlowat = (RPC_DESC_SIZE + 100 + 150) * 2},
+ },
+ },
+ {
+ .desc = {
+ {.header_len = 100, .payload_len = 150},
+ {.header_len = 200, .payload_len = 500},
+ },
+ .event = {
+ { .type = RPC_EVENT_AUTOLOWAT, .val = 1},
+ /* The first descriptor is partial. */
+ {.type = RPC_EVENT_SEND, .len = 1},
+ {.type = RPC_EVENT_EPOLL, .nfds = 0},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE},
+ /* The first descriptor is available. */
+ {.type = RPC_EVENT_SEND, .len = RPC_DESC_SIZE - 1},
+ {.type = RPC_EVENT_EPOLL, .nfds = 0},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE + 150 + 100},
+ /* The first header is ready. */
+ {.type = RPC_EVENT_SEND, .len = 100},
+ {.type = RPC_EVENT_EPOLL, .nfds = 0},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE + 150 + 100},
+ /* skb has the first payload and 1 byte of the next descriptor. */
+ {.type = RPC_EVENT_SEND, .len = 150 + 1},
+ {.type = RPC_EVENT_EPOLL, .nfds = 1},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE + 150 + 100},
+ /* After reading the first RPC message, SO_RCVLOWAT should be RPC_DESC_SIZE. */
+ {.type = RPC_EVENT_RECV, .len = RPC_DESC_SIZE + 150 + 100},
+ {.type = RPC_EVENT_EPOLL, .nfds = 0},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE},
+ /* The second descriptor is available. */
+ {.type = RPC_EVENT_SEND, .len = RPC_DESC_SIZE - 1},
+ {.type = RPC_EVENT_EPOLL, .nfds = 0},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE + 200 + 500},
+ },
+ },
+};
+
+struct tcp_autolowat_test_cb {
+ int saved_netns;
+ union {
+ int fd[4];
+ struct {
+ int server, client, child;
+ int epoll;
+ };
+ };
+};
+
+static void tcp_autolowat_teardown_cb(struct tcp_autolowat_test_cb *cb)
+{
+ int i, err;
+
+ for (i = 0; i < ARRAY_SIZE(cb->fd); i++) {
+ if (cb->fd[i] != -1)
+ close(cb->fd[i]);
+ }
+
+ if (cb->saved_netns != -1) {
+ err = setns(cb->saved_netns, CLONE_NEWNET);
+ ASSERT_OK(err, "restore netns");
+
+ close(cb->saved_netns);
+ }
+}
+
+static int tcp_autolowat_setup_cb(struct tcp_autolowat_test_cb *cb, int family)
+{
+ struct epoll_event ev = {};
+ int err;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(cb->fd); i++)
+ cb->fd[i] = -1;
+
+ cb->saved_netns = open("/proc/self/ns/net", O_RDONLY);
+ if (!ASSERT_OK_FD(cb->saved_netns, "save netns"))
+ goto err;
+
+ err = unshare(CLONE_NEWNET);
+ if (!ASSERT_OK(err, "unshare"))
+ goto err;
+
+ err = system("ip link set dev lo up");
+ if (!ASSERT_OK(err, "set up lo"))
+ goto err;
+
+ cb->server = start_server(family, SOCK_STREAM, NULL, 0, 0);
+ if (!ASSERT_OK_FD(cb->server, "start_server"))
+ goto err;
+
+ cb->client = connect_to_fd(cb->server, 0);
+ if (!ASSERT_OK_FD(cb->client, "connect_to_fd"))
+ goto err;
+
+ cb->child = accept(cb->server, NULL, NULL);
+ if (!ASSERT_OK_FD(cb->child, "accept"))
+ goto err;
+
+ cb->epoll = epoll_create1(0);
+ if (!ASSERT_OK_FD(cb->epoll, "epoll_create"))
+ goto err;
+
+ ev.events = EPOLLIN;
+ ev.data.fd = cb->child;
+
+ err = epoll_ctl(cb->epoll, EPOLL_CTL_ADD, cb->child, &ev);
+ if (!ASSERT_OK(err, "epoll_ctl"))
+ goto err;
+
+ return 0;
+
+err:
+ tcp_autolowat_teardown_cb(cb);
+ return -1;
+}
+
+static int tcp_autolowat_build_data(struct rpc_test_case *test_case)
+{
+ struct rpc_descriptor *desc = test_case->desc;
+ char *ptr = test_case->data;
+ int rpc_size;
+
+ memset(ptr, 0, sizeof(test_case->data));
+
+ while (desc->header_len + desc->payload_len) {
+ rpc_size = sizeof(*desc) + desc->header_len + desc->payload_len;
+
+ if (!ASSERT_LE(ptr + rpc_size - test_case->data,
+ sizeof(test_case->data), "data overflow"))
+ return 1;
+
+ memcpy(ptr, desc, sizeof(*desc));
+ ptr += rpc_size;
+ desc++;
+ }
+
+ if (!ASSERT_GT(ptr - test_case->data, 0, "no data"))
+ return 1;
+
+ return 0;
+}
+
+static void tcp_autolowat_run_rpc_test(struct tcp_autolowat_test_cb *cb,
+ struct rpc_test_case *test_case)
+{
+ struct rpc_event *event = test_case->event;
+ char *ptr = test_case->data;
+ struct epoll_event ev;
+ socklen_t optlen;
+ int err, optval;
+ char buf[4096];
+
+ if (tcp_autolowat_build_data(test_case))
+ return;
+
+ while (1) {
+ switch (event->type) {
+ case RPC_EVENT_END:
+ return;
+ case RPC_EVENT_AUTOLOWAT:
+ err = setsockopt(cb->child, SOL_BPF, BPF_TCP_AUTOLOWAT,
+ &event->val, sizeof(event->val));
+ if (!ASSERT_OK(err, "setsockopt"))
+ return;
+ break;
+ case RPC_EVENT_SEND:
+ err = send(cb->client, ptr, event->len, 0);
+ if (!ASSERT_EQ(err, event->len, "send"))
+ return;
+
+ ptr += event->len;
+ break;
+ case RPC_EVENT_RECV:
+ err = recv(cb->child, buf, event->len, 0);
+ if (!ASSERT_EQ(err, event->len, "recv"))
+ return;
+ break;
+ case RPC_EVENT_EPOLL:
+ err = epoll_wait(cb->epoll, &ev, 1, 100);
+ if (!ASSERT_EQ(err, event->nfds, "epoll_wait"))
+ return;
+ break;
+ case RPC_EVENT_RCVLOWAT:
+ optval = 0;
+ optlen = sizeof(optval);
+
+ err = getsockopt(cb->child, SOL_SOCKET, SO_RCVLOWAT, &optval, &optlen);
+ if (!ASSERT_OK(err, "getsockopt") ||
+ !ASSERT_EQ(optval, event->rcvlowat, "rcvlowat"))
+ return;
+ break;
+ }
+
+ event++;
+ }
+}
+
+static void tcp_autolowat_run_rpc_tests(struct tcp_autolowat *skel, int family)
+{
+ struct tcp_autolowat_test_cb cb;
+ int err;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(rpc_test_cases); i++) {
+ memset(skel->bss->test_name, 0, sizeof(skel->bss->test_name));
+
+ snprintf(skel->bss->test_name, sizeof(skel->bss->test_name),
+ "AF_INET%c rpc_test_cases[%d]",
+ family == AF_INET ? ' ' : '6', i);
+
+ if (!test__start_subtest(skel->bss->test_name))
+ continue;
+
+ err = tcp_autolowat_setup_cb(&cb, family);
+ if (err)
+ continue;
+
+ tcp_autolowat_run_rpc_test(&cb, &rpc_test_cases[i]);
+ tcp_autolowat_teardown_cb(&cb);
+ }
+}
+
+static void tcp_autolowat_run_tests(struct tcp_autolowat *skel)
+{
+ tcp_autolowat_run_rpc_tests(skel, AF_INET);
+ tcp_autolowat_run_rpc_tests(skel, AF_INET6);
+}
+
+void test_tcp_autolowat(void)
+{
+ struct tcp_autolowat *skel;
+ struct bpf_link *link[2];
+ int cgroup;
+
+ skel = tcp_autolowat__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "open_and_load"))
+ return;
+
+ cgroup = test__join_cgroup("/tcp_autolowat");
+ if (!ASSERT_GE(cgroup, 0, "join_cgroup"))
+ goto destroy_skel;
+
+ link[0] = bpf_map__attach_cgroup_opts(skel->maps.tcp_autolowat_ops, cgroup, NULL);
+ if (!ASSERT_OK_PTR(link[0], "attach_cgroup(tcp_autolowat_ops)"))
+ goto close_cgroup;
+
+ link[1] = bpf_program__attach_cgroup(skel->progs.tcp_autolowat_setsockopt, cgroup);
+ if (!ASSERT_OK_PTR(link[1], "attach_cgroup(SETSOCKOPT)"))
+ goto destroy_sockops;
+
+ tcp_autolowat_run_tests(skel);
+
+ bpf_link__destroy(link[1]);
+destroy_sockops:
+ bpf_link__destroy(link[0]);
+close_cgroup:
+ close(cgroup);
+destroy_skel:
+ tcp_autolowat__destroy(skel);
+}
diff --git a/tools/testing/selftests/bpf/progs/bpf_tcp_ops_hdr.c b/tools/testing/selftests/bpf/progs/bpf_tcp_ops_hdr.c
index f3e3dff13784c..706e94d794e46 100644
--- a/tools/testing/selftests/bpf/progs/bpf_tcp_ops_hdr.c
+++ b/tools/testing/selftests/bpf/progs/bpf_tcp_ops_hdr.c
@@ -18,6 +18,24 @@ int found_cnt;
__u8 found_d0;
__u8 found_d1;
+SEC("struct_ops")
+void BPF_PROG(test_listen, struct sock *sk)
+{
+ bpf_tcp_ops_set_flags((struct tcp_sock *)sk,
+ BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_ALL |
+ BPF_TCP_OPS_FLAG_WRITE_HDR_OPT,
+ 0);
+}
+
+SEC("struct_ops")
+void BPF_PROG(test_connect, struct sock *sk)
+{
+ bpf_tcp_ops_set_flags((struct tcp_sock *)sk,
+ BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_UNKNOWN |
+ BPF_TCP_OPS_FLAG_WRITE_HDR_OPT,
+ 0);
+}
+
SEC("struct_ops")
void BPF_PROG(test_hdr_opt_len, struct sock *sk, struct sk_buff *skb,
struct request_sock *req, struct sk_buff *syn_skb,
@@ -78,6 +96,8 @@ void BPF_PROG(test_parse_hdr, struct sock *sk, struct sk_buff *skb)
SEC(".struct_ops.link")
struct bpf_tcp_ops test_hdr_ops = {
+ .listen = (void *)test_listen,
+ .connect = (void *)test_connect,
.hdr_opt_len = (void *)test_hdr_opt_len,
.write_hdr_opt = (void *)test_write_hdr_opt,
.parse_hdr = (void *)test_parse_hdr,
diff --git a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
index 593b38f904174..4c999d59cbbce 100644
--- a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
+++ b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
@@ -79,6 +79,8 @@
#define NEXTHDR_TCP 6
+#define TCPHDR_FIN 0x01
+
#define TCPOPT_NOP 1
#define TCPOPT_EOL 0
#define TCPOPT_MSS 2
diff --git a/tools/testing/selftests/bpf/progs/tcp_autolowat.c b/tools/testing/selftests/bpf/progs/tcp_autolowat.c
new file mode 100644
index 0000000000000..8a55f3cee2609
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/tcp_autolowat.c
@@ -0,0 +1,294 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright 2026 Google LLC */
+#include "vmlinux.h"
+
+#include <string.h>
+#include <limits.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+#include <bpf/bpf_core_read.h>
+
+#include "bpf_tracing_net.h"
+
+#define SOL_BPF 0xdeadbeef
+#define BPF_TCP_AUTOLOWAT 0x8badf00d
+
+//#define DEBUG /* For verbose output. */
+
+struct rpc_descriptor {
+ u32 header_len;
+ u32 payload_len;
+};
+
+#define RPC_DESC_SIZE (sizeof(struct rpc_descriptor))
+#define MAX_RPC_DESC_PER_SKB 100
+
+struct tcp_autolowat_cb {
+ /* Don't put this field at the end; BPF verifier complains. */
+ char rpc_desc_buf[RPC_DESC_SIZE];
+ u32 rpc_desc_seq;
+ u32 rpc_end_seq;
+#ifdef DEBUG
+ u32 isn;
+#endif
+ u8 rpc_desc_buff_len;
+};
+
+struct {
+ __uint(type, BPF_MAP_TYPE_SK_STORAGE);
+ __uint(map_flags, BPF_F_NO_PREALLOC);
+ __type(key, int);
+ __type(value, struct tcp_autolowat_cb);
+} tcp_autolowat_map SEC(".maps");
+
+char test_name[64];
+
+#ifdef DEBUG
+#define LOG(str, ...) \
+ bpf_printk("%s: " str, test_name, ##__VA_ARGS__)
+#else
+#define LOG(...)
+#endif
+
+#define SEQ(val) \
+ (val - cb->isn)
+#define TP_SEQ(field) \
+ (tp->field - cb->isn)
+#define CB_SEQ(field) \
+ (cb->field - cb->isn)
+
+static int tcp_parse_descriptor(struct tcp_autolowat_cb *cb,
+ struct bpf_dynptr *dptr,
+ u32 seq, u32 end_seq)
+{
+ struct rpc_descriptor *rpc_desc;
+ u32 rpc_copied_seq;
+ u64 copy_len; /* u32 should work, but not for no_alu32 :/ */
+ u64 rpc_len;
+ int err;
+
+ rpc_copied_seq = cb->rpc_desc_seq + cb->rpc_desc_buff_len;
+
+ if (before(cb->rpc_desc_seq + RPC_DESC_SIZE, end_seq))
+ copy_len = RPC_DESC_SIZE - cb->rpc_desc_buff_len;
+ else
+ copy_len = end_seq - rpc_copied_seq;
+
+ if (copy_len == 0)
+ goto disable; /* FIN. */
+ if (copy_len > RPC_DESC_SIZE)
+ goto disable; /* always false, only for verifier. */
+ if (cb->rpc_desc_buff_len >= RPC_DESC_SIZE)
+ goto disable; /* always false, only for verifier. */
+
+ err = bpf_dynptr_read(cb->rpc_desc_buf + cb->rpc_desc_buff_len,
+ copy_len, dptr, rpc_copied_seq - seq, 0);
+ if (err)
+ goto disable;
+
+ cb->rpc_desc_buff_len += copy_len;
+
+ if (cb->rpc_desc_buff_len != RPC_DESC_SIZE) {
+ LOG("Copied %d bytes: rpc_desc_buff_len: %u", copy_len, cb->rpc_desc_buff_len);
+ goto partial;
+ }
+
+ rpc_desc = (struct rpc_descriptor *)cb->rpc_desc_buf;
+ rpc_len = RPC_DESC_SIZE + rpc_desc->header_len + rpc_desc->payload_len;
+
+ if (rpc_len > INT_MAX)
+ goto disable;
+
+ cb->rpc_end_seq = cb->rpc_desc_seq + rpc_len;
+
+ LOG("Copied full descriptor: rpc_desc_seq: %u, rpc_end_seq: %u, header_len: %u, payload_len: %u",
+ CB_SEQ(rpc_desc_seq), CB_SEQ(rpc_end_seq),
+ rpc_desc->header_len, rpc_desc->payload_len);
+
+ return 0;
+disable:
+ return -1;
+partial:
+ return 1;
+}
+
+static void tcp_set_autolowat(struct tcp_autolowat_cb *cb,
+ struct sock *sk)
+{
+ struct tcp_sock *tp = (struct tcp_sock *)sk;
+ u32 val; /* To handle wraparound. */
+
+ LOG("Setting rcvlowat: tp->copied_seq: %u, rpc_desc_seq: %u, rpc_end_seq: %u, rpc_desc_buff_len: %u",
+ TP_SEQ(copied_seq), CB_SEQ(rpc_desc_seq),
+ CB_SEQ(rpc_end_seq), cb->rpc_desc_buff_len);
+
+ if (before(tp->copied_seq, cb->rpc_desc_seq))
+ val = cb->rpc_desc_seq - tp->copied_seq;
+ else if (cb->rpc_desc_buff_len != RPC_DESC_SIZE)
+ val = RPC_DESC_SIZE;
+ else
+ val = cb->rpc_end_seq - tp->copied_seq;
+
+ if (val != tp->inet_conn.icsk_inet.sk.sk_rcvlowat) {
+ bpf_tcp_ops_set_rcvlowat(sk, val);
+
+ LOG("Set rcvlowat: expected: %u, actual: %d\n",
+ val, tp->inet_conn.icsk_inet.sk.sk_rcvlowat);
+ } else {
+ LOG("No need to set rcvlowat: %u\n", val);
+ }
+}
+
+static void tcp_disable_autolowat(struct sock *sk)
+{
+ bpf_tcp_ops_set_flags((struct tcp_sock *)sk, 0, BPF_TCP_OPS_FLAG_RCVQ);
+
+ bpf_tcp_ops_set_rcvlowat(sk, 1);
+
+ LOG("Disabled autolowat");
+}
+
+static void tcp_do_autolowat(struct tcp_autolowat_cb *cb,
+ struct sock *sk, struct sk_buff *skb)
+{
+ struct bpf_dynptr dptr;
+ struct tcp_skb_cb *tcb;
+ u32 seq, end_seq;
+ int ret = 0, i;
+
+ if (bpf_dynptr_from_skb((struct __sk_buff *)skb, 0, &dptr)) {
+ ret = -1;
+ goto update;
+ }
+
+ tcb = bpf_core_cast(skb->cb, struct tcp_skb_cb);
+ seq = tcb->seq;
+ end_seq = tcb->end_seq - !!(tcb->tcp_flags & TCPHDR_FIN);
+
+ LOG("Start parsing skb: seq: %u, end_seq: %u, len: %u, rpc_desc_seq: %u, rpc_end_seq: %u, rpc_buff_len: %u",
+ SEQ(seq), SEQ(end_seq), end_seq - seq,
+ CB_SEQ(rpc_desc_seq), CB_SEQ(rpc_end_seq), cb->rpc_desc_buff_len);
+
+ if (cb->rpc_desc_buff_len != RPC_DESC_SIZE) {
+ ret = tcp_parse_descriptor(cb, &dptr, seq, end_seq);
+ if (ret)
+ goto update;
+ }
+
+ i = 0;
+
+ while (1) {
+ if (i++ > MAX_RPC_DESC_PER_SKB) {
+ ret = -1;
+ break;
+ }
+
+ if (after(cb->rpc_end_seq, end_seq)) {
+ LOG("No more descriptor: rpc_end_seq: %u, end_seq: %u",
+ CB_SEQ(rpc_end_seq), SEQ(end_seq));
+ break;
+ }
+
+ cb->rpc_desc_seq = cb->rpc_end_seq;
+ cb->rpc_desc_buff_len = 0;
+
+ if (cb->rpc_end_seq == end_seq)
+ break;
+
+ LOG("Found next descriptor: rpc_end_seq: %u, end_seq: %u, len: %u",
+ CB_SEQ(rpc_end_seq), SEQ(end_seq), end_seq - cb->rpc_end_seq);
+
+ ret = tcp_parse_descriptor(cb, &dptr, seq, end_seq);
+ if (ret)
+ break;
+ }
+
+update:
+ if (ret >= 0)
+ tcp_set_autolowat(cb, sk);
+ else
+ tcp_disable_autolowat(sk);
+}
+
+SEC("struct_ops")
+void BPF_PROG(tcp_autolowat_enqueue_rcvq, struct sock *sk, struct sk_buff *skb)
+{
+ struct tcp_autolowat_cb *cb;
+
+ cb = bpf_sk_storage_get(&tcp_autolowat_map, sk, 0, 0);
+ if (!cb)
+ return;
+
+ tcp_do_autolowat(cb, sk, skb);
+}
+
+SEC("struct_ops")
+void BPF_PROG(tcp_autolowat_dequeue_rcvq, struct sock *sk)
+{
+ struct tcp_autolowat_cb *cb;
+
+ cb = bpf_sk_storage_get(&tcp_autolowat_map, sk, 0, 0);
+ if (!cb)
+ return;
+
+ tcp_set_autolowat(cb, sk);
+}
+
+SEC(".struct_ops.link")
+struct bpf_tcp_ops tcp_autolowat_ops = {
+ .enqueue_rcvq = (void *)tcp_autolowat_enqueue_rcvq,
+ .dequeue_rcvq = (void *)tcp_autolowat_dequeue_rcvq,
+};
+
+static int tcp_init_autolowat_cb(struct bpf_tcp_sock *btp)
+{
+ struct tcp_autolowat_cb *cb;
+ struct tcp_sock *tp;
+
+ cb = bpf_sk_storage_get(&tcp_autolowat_map, btp, 0,
+ BPF_SK_STORAGE_GET_F_CREATE);
+ if (!cb)
+ return -1;
+
+ tp = bpf_core_cast(btp, struct tcp_sock);
+
+ cb->rpc_desc_seq = tp->copied_seq;
+ cb->rpc_end_seq = tp->copied_seq;
+#ifdef DEBUG
+ cb->isn = tp->copied_seq;
+#endif
+
+ return bpf_tcp_ops_set_flags((struct tcp_sock *)btp,
+ BPF_TCP_OPS_FLAG_RCVQ, 0);
+}
+
+SEC("cgroup/setsockopt")
+int tcp_autolowat_setsockopt(struct bpf_sockopt *ctx)
+{
+ void *optval_end = ctx->optval_end;
+ int *optval = ctx->optval;
+ struct bpf_tcp_sock *btp;
+
+ if (ctx->level != SOL_BPF || ctx->optname != BPF_TCP_AUTOLOWAT)
+ goto out;
+
+ if (optval + 1 > optval_end)
+ return 0; /* -EPERM */
+
+ btp = bpf_tcp_sock(ctx->sk);
+ if (!btp)
+ goto out;
+
+ if (*optval && tcp_init_autolowat_cb(btp))
+ return 0; /* -EPERM */
+
+ /*
+ * BPF has consumed this option, don't call kernel
+ * setsockopt handler.
+ */
+ ctx->optlen = -1;
+out:
+ return 1;
+}
+
+char _license[] SEC("license") = "GPL";
|
| 3/2 | 2026/10/06 20:07 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26886 output: 40 thoughts: 979 Thoughts: **Analysis of the TCP BPF Patch for Fuzzing** Alright, let's break this down. The user wants to know if this patch series is fuzz-worthy with syzkaller, and they're after the relevant configs, symbols, and the reasoning behind that assessment. First, I need to understand what this patch actually *does*. Looks like it touches quite a few files, mainly around TCP internals and BPF integration. Specifically, it's adding new flags and callbacks to the `bpf_tcp_ops` structure. We see flags like `BPF_TCP_OPS_FLAG_RTT`, `BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_ALL`, etc., and callbacks for `enqueue_rcvq` and `dequeue_rcvq`. There are also new BPF kfuncs: `bpf_tcp_ops_set_flags` and `bpf_tcp_ops_set_rcvlowat`. Plus, the patch is making calls to `bpf_tcp_ops_call_flag` in several core TCP functions, like `tcp_queue_rcv`, `tcp_ofo_queue`, and `tcp_cleanup_rbuf`. Essentially, it's hooking BPF into various points within the TCP stack for more granular control and instrumentation. There are also changes to setsockopt/getsockopt restrictions, and some optimizations to fast path checks. Now, the crucial question: Is this reachable and fuzzable? Absolutely. This isn't some obscure corner of the kernel. We are dealing with the TCP stack – core networking – and BPF struct_ops (`BPF_PROG_TYPE_STRUCT_OPS`, `CGROUP_TCP_SOCK_OPS`). This means we can readily test this in a standard QEMU environment. And Syzkaller? Syzkaller has excellent support for BPF. We can load struct_ops, attach them to cgroups, use setsockopt, and interact with sockets. Given the specific functions the patch is modifying – `tcp_queue_rcv`, `tcp_ofo_queue`, `tcp_cleanup_rbuf`, etc. – we're talking about direct access to critical networking functionality via BPF. It's a goldmine for finding subtle bugs. Therefore, WorthFuzzing = true. This is a clear "yes." Next, I'll need to use my Kconfig knowledge to locate the right configs and identify the symbols. I'll focus my search around `bpf_tcp_ops.c` and `CGROUP_TCP_SOCK_OPS`. We want to make sure the relevant functionality is enabled in the fuzzing environment. |
| 4/2 | 2026/10/06 20:08 | tool | grepper |
0mArgs:{
"Expression": "bpf_tcp_ops",
"PathPrefixes": [
"net/ipv4/",
"kernel/bpf/"
]
}Results: {
"Output": "\nFull output is too long, showing 200 out of 336 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (8 files in total):\nnet/ipv4/Makefile:1\nnet/ipv4/af_inet.c:1\nnet/ipv4/bpf_tcp_ops.c:80\nnet/ipv4/tcp.c:3\nnet/ipv4/tcp_fastopen.c:1\nnet/ipv4/tcp_input.c:7\nnet/ipv4/tcp_output.c:10\nnet/ipv4/tcp_timer.c:1\n\nnet/ipv4/Makefile=72=obj-$(CONFIG_BPF_SYSCALL) += bpf_tcp_ca.o\nnet/ipv4/Makefile:73:obj-$(CONFIG_CGROUP_BPF) += bpf_tcp_ops.o\nnet/ipv4/Makefile-74-endif\n--\nnet/ipv4/af_inet.c=198=int __inet_listen_sk(struct sock *sk, int backlog)\n--\nnet/ipv4/af_inet.c-229-\t\ttcp_call_bpf(sk, BPF_SOCK_OPS_TCP_LISTEN_CB);\nnet/ipv4/af_inet.c:230:\t\tbpf_tcp_ops_call(listen, sk);\nnet/ipv4/af_inet.c-231-\t}\n--\nnet/ipv4/bpf_tcp_ops.c=83=static void dequeue_rcvq_stub(struct sock *sk)\n--\nnet/ipv4/bpf_tcp_ops.c-86-\nnet/ipv4/bpf_tcp_ops.c:87:static struct bpf_tcp_ops __bpf_tcp_ops = {\nnet/ipv4/bpf_tcp_ops.c-88-\t.timeout_init = timeout_init_stub,\n--\nnet/ipv4/bpf_tcp_ops.c-104-\nnet/ipv4/bpf_tcp_ops.c:105:BPF_CALL_4(bpf_tcp_ops_store_hdr_opt, void *, ctx, const void *, from,\nnet/ipv4/bpf_tcp_ops.c-106-\t u32, len, u64, flags)\n--\nnet/ipv4/bpf_tcp_ops.c-114-\t/*\nnet/ipv4/bpf_tcp_ops.c:115:\t * bpf_tcp_ops does not keep track of the end of the written TCP header\nnet/ipv4/bpf_tcp_ops.c-116-\t * options, so search for it every time the helper is called. The free\n--\nnet/ipv4/bpf_tcp_ops.c-134-\nnet/ipv4/bpf_tcp_ops.c:135:static const struct bpf_func_proto bpf_tcp_ops_store_hdr_opt_proto = {\nnet/ipv4/bpf_tcp_ops.c:136:\t.func\t\t= bpf_tcp_ops_store_hdr_opt,\nnet/ipv4/bpf_tcp_ops.c-137-\t.gpl_only\t= false,\n--\nnet/ipv4/bpf_tcp_ops.c-144-\nnet/ipv4/bpf_tcp_ops.c:145:BPF_CALL_4(bpf_tcp_ops_load_hdr_opt, void *, ctx, void *, search_res,\nnet/ipv4/bpf_tcp_ops.c-146-\t u32, len, u64, flags)\n--\nnet/ipv4/bpf_tcp_ops.c-153-\t * No flags supported. In particular BPF_LOAD_HDR_OPT_TCP_SYN, which\nnet/ipv4/bpf_tcp_ops.c:154:\t * loads from the saved SYN, is not available because bpf_tcp_ops has no\nnet/ipv4/bpf_tcp_ops.c-155-\t * carrier to track the SYN source across the hooks.\n--\nnet/ipv4/bpf_tcp_ops.c-165-\nnet/ipv4/bpf_tcp_ops.c:166:static const struct bpf_func_proto bpf_tcp_ops_load_hdr_opt_proto = {\nnet/ipv4/bpf_tcp_ops.c:167:\t.func\t\t= bpf_tcp_ops_load_hdr_opt,\nnet/ipv4/bpf_tcp_ops.c-168-\t.gpl_only\t= false,\n--\nnet/ipv4/bpf_tcp_ops.c-175-\nnet/ipv4/bpf_tcp_ops.c:176:BPF_CALL_3(bpf_tcp_ops_reserve_hdr_opt, void *, ctx, u32, len, u64, flags)\nnet/ipv4/bpf_tcp_ops.c-177-{\n--\nnet/ipv4/bpf_tcp_ops.c-190-\nnet/ipv4/bpf_tcp_ops.c:191:static const struct bpf_func_proto bpf_tcp_ops_reserve_hdr_opt_proto = {\nnet/ipv4/bpf_tcp_ops.c:192:\t.func\t\t= bpf_tcp_ops_reserve_hdr_opt,\nnet/ipv4/bpf_tcp_ops.c-193-\t.gpl_only\t= false,\n--\nnet/ipv4/bpf_tcp_ops.c-199-\nnet/ipv4/bpf_tcp_ops.c:200:BPF_CALL_0(bpf_tcp_ops_get_retval)\nnet/ipv4/bpf_tcp_ops.c-201-{\n--\nnet/ipv4/bpf_tcp_ops.c-205-\t/* bpf_get_retval() is only exposed to timeout_init/rwnd_init, which\nnet/ipv4/bpf_tcp_ops.c:206:\t * always run via bpf_tcp_ops_call_int(). Its run_ctx carries the int\nnet/ipv4/bpf_tcp_ops.c:207:\t * return value chained across the bpf_tcp_ops attached to the cgroup\nnet/ipv4/bpf_tcp_ops.c-208-\t * and is this program's saved_run_ctx.\n--\nnet/ipv4/bpf_tcp_ops.c-216-\nnet/ipv4/bpf_tcp_ops.c:217:const struct bpf_func_proto bpf_tcp_ops_get_retval_proto = {\nnet/ipv4/bpf_tcp_ops.c:218:\t.func\t\t= bpf_tcp_ops_get_retval,\nnet/ipv4/bpf_tcp_ops.c-219-\t.gpl_only\t= false,\n--\nnet/ipv4/bpf_tcp_ops.c=223=static bool is_sockopt_supported(u32 moff)\n--\nnet/ipv4/bpf_tcp_ops.c-225-\tswitch (moff) {\nnet/ipv4/bpf_tcp_ops.c:226:\tcase offsetof(struct bpf_tcp_ops, active_established):\nnet/ipv4/bpf_tcp_ops.c:227:\tcase offsetof(struct bpf_tcp_ops, passive_established):\nnet/ipv4/bpf_tcp_ops.c:228:\tcase offsetof(struct bpf_tcp_ops, rto):\nnet/ipv4/bpf_tcp_ops.c:229:\tcase offsetof(struct bpf_tcp_ops, rtt):\nnet/ipv4/bpf_tcp_ops.c:230:\tcase offsetof(struct bpf_tcp_ops, set_state):\nnet/ipv4/bpf_tcp_ops.c:231:\tcase offsetof(struct bpf_tcp_ops, retrans):\nnet/ipv4/bpf_tcp_ops.c:232:\tcase offsetof(struct bpf_tcp_ops, connect):\nnet/ipv4/bpf_tcp_ops.c:233:\tcase offsetof(struct bpf_tcp_ops, listen):\nnet/ipv4/bpf_tcp_ops.c:234:\tcase offsetof(struct bpf_tcp_ops, parse_hdr):\nnet/ipv4/bpf_tcp_ops.c-235-\t\treturn true;\n--\nnet/ipv4/bpf_tcp_ops.c=242=get_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)\n--\nnet/ipv4/bpf_tcp_ops.c-259-\tcase BPF_FUNC_get_retval:\nnet/ipv4/bpf_tcp_ops.c:260:\t\tif (moff == offsetof(struct bpf_tcp_ops, timeout_init) ||\nnet/ipv4/bpf_tcp_ops.c:261:\t\t moff == offsetof(struct bpf_tcp_ops, rwnd_init))\nnet/ipv4/bpf_tcp_ops.c:262:\t\t\treturn \u0026bpf_tcp_ops_get_retval_proto;\nnet/ipv4/bpf_tcp_ops.c-263-\t\treturn NULL;\nnet/ipv4/bpf_tcp_ops.c-264-\tcase BPF_FUNC_reserve_hdr_opt:\nnet/ipv4/bpf_tcp_ops.c:265:\t\tif (moff == offsetof(struct bpf_tcp_ops, hdr_opt_len))\nnet/ipv4/bpf_tcp_ops.c:266:\t\t\treturn \u0026bpf_tcp_ops_reserve_hdr_opt_proto;\nnet/ipv4/bpf_tcp_ops.c-267-\t\treturn NULL;\nnet/ipv4/bpf_tcp_ops.c-268-\tcase BPF_FUNC_load_hdr_opt:\nnet/ipv4/bpf_tcp_ops.c:269:\t\tif (moff == offsetof(struct bpf_tcp_ops, parse_hdr) ||\nnet/ipv4/bpf_tcp_ops.c:270:\t\t moff == offsetof(struct bpf_tcp_ops, write_hdr_opt))\nnet/ipv4/bpf_tcp_ops.c:271:\t\t\treturn \u0026bpf_tcp_ops_load_hdr_opt_proto;\nnet/ipv4/bpf_tcp_ops.c-272-\t\treturn NULL;\nnet/ipv4/bpf_tcp_ops.c-273-\tcase BPF_FUNC_store_hdr_opt:\nnet/ipv4/bpf_tcp_ops.c:274:\t\tif (moff == offsetof(struct bpf_tcp_ops, write_hdr_opt))\nnet/ipv4/bpf_tcp_ops.c:275:\t\t\treturn \u0026bpf_tcp_ops_store_hdr_opt_proto;\nnet/ipv4/bpf_tcp_ops.c-276-\t\treturn NULL;\n--\nnet/ipv4/bpf_tcp_ops.c=282=static bool is_valid_access(int off, int size, enum bpf_access_type type,\n--\nnet/ipv4/bpf_tcp_ops.c-296-\nnet/ipv4/bpf_tcp_ops.c:297:static int bpf_tcp_ops_init_member(const struct btf_type *t,\nnet/ipv4/bpf_tcp_ops.c-298-\t\t\t\t const struct btf_member *member,\n--\nnet/ipv4/bpf_tcp_ops.c-303-\nnet/ipv4/bpf_tcp_ops.c:304:static int bpf_tcp_ops_check_member(const struct btf_type *t,\nnet/ipv4/bpf_tcp_ops.c-305-\t\t\t\t const struct btf_member *member,\n--\nnet/ipv4/bpf_tcp_ops.c-313-\nnet/ipv4/bpf_tcp_ops.c:314:static int bpf_tcp_ops_init(struct btf *btf)\nnet/ipv4/bpf_tcp_ops.c-315-{\n--\nnet/ipv4/bpf_tcp_ops.c-318-\nnet/ipv4/bpf_tcp_ops.c:319:static int bpf_tcp_ops_validate(void *kdata)\nnet/ipv4/bpf_tcp_ops.c-320-{\n--\nnet/ipv4/bpf_tcp_ops.c-323-\nnet/ipv4/bpf_tcp_ops.c:324:static const struct bpf_verifier_ops bpf_tcp_ops_verifier = {\nnet/ipv4/bpf_tcp_ops.c-325-\t.get_func_proto\t\t= get_func_proto,\n--\nnet/ipv4/bpf_tcp_ops.c-328-\nnet/ipv4/bpf_tcp_ops.c:329:static struct bpf_struct_ops bpf_tcp_ops = {\nnet/ipv4/bpf_tcp_ops.c:330:\t.verifier_ops = \u0026bpf_tcp_ops_verifier,\nnet/ipv4/bpf_tcp_ops.c:331:\t.init_member = bpf_tcp_ops_init_member,\nnet/ipv4/bpf_tcp_ops.c:332:\t.check_member = bpf_tcp_ops_check_member,\nnet/ipv4/bpf_tcp_ops.c:333:\t.init = bpf_tcp_ops_init,\nnet/ipv4/bpf_tcp_ops.c:334:\t.validate = bpf_tcp_ops_validate,\nnet/ipv4/bpf_tcp_ops.c:335:\t.name = \"bpf_tcp_ops\",\nnet/ipv4/bpf_tcp_ops.c-336-\t.cgroup_atype = CGROUP_TCP_SOCK_OPS,\nnet/ipv4/bpf_tcp_ops.c:337:\t.cfi_stubs = \u0026__bpf_tcp_ops,\nnet/ipv4/bpf_tcp_ops.c-338-\t.owner = THIS_MODULE,\n--\nnet/ipv4/bpf_tcp_ops.c=341=__bpf_kfunc_start_defs();\nnet/ipv4/bpf_tcp_ops.c-342-\nnet/ipv4/bpf_tcp_ops.c:343:__bpf_kfunc int bpf_tcp_ops_set_flags(struct tcp_sock *tp, u32 enable, u32 disable)\nnet/ipv4/bpf_tcp_ops.c-344-{\n--\nnet/ipv4/bpf_tcp_ops.c-352-\nnet/ipv4/bpf_tcp_ops.c:353:\told = READ_ONCE(tp-\u003ebpf_tcp_ops_flags);\nnet/ipv4/bpf_tcp_ops.c-354-\n--\nnet/ipv4/bpf_tcp_ops.c-358-\t\t\tbreak;\nnet/ipv4/bpf_tcp_ops.c:359:\t} while (!try_cmpxchg(\u0026tp-\u003ebpf_tcp_ops_flags, \u0026old, new));\nnet/ipv4/bpf_tcp_ops.c-360-\n--\nnet/ipv4/bpf_tcp_ops.c-363-\nnet/ipv4/bpf_tcp_ops.c:364:__bpf_kfunc int bpf_tcp_ops_set_rcvlowat(struct sock *sk, int rcvlowat,\nnet/ipv4/bpf_tcp_ops.c-365-\t\t\t\t\t const struct bpf_prog_aux *aux)\n--\nnet/ipv4/bpf_tcp_ops.c-369-\nnet/ipv4/bpf_tcp_ops.c:370:\tif (moff == offsetof(struct bpf_tcp_ops, dequeue_rcvq))\nnet/ipv4/bpf_tcp_ops.c-371-\t\twakeup = true;\n--\nnet/ipv4/bpf_tcp_ops.c=379=__bpf_kfunc_end_defs();\nnet/ipv4/bpf_tcp_ops.c-380-\nnet/ipv4/bpf_tcp_ops.c:381:BTF_KFUNCS_START(bpf_tcp_ops_set_flags_kfunc_set)\nnet/ipv4/bpf_tcp_ops.c:382:BTF_ID_FLAGS(func, bpf_tcp_ops_set_flags)\nnet/ipv4/bpf_tcp_ops.c:383:BTF_KFUNCS_END(bpf_tcp_ops_set_flags_kfunc_set)\nnet/ipv4/bpf_tcp_ops.c-384-\nnet/ipv4/bpf_tcp_ops.c:385:BTF_KFUNCS_START(bpf_tcp_ops_set_rcvlowat_kfunc_set)\nnet/ipv4/bpf_tcp_ops.c:386:BTF_ID_FLAGS(func, bpf_tcp_ops_set_rcvlowat, KF_IMPLICIT_ARGS)\nnet/ipv4/bpf_tcp_ops.c:387:BTF_KFUNCS_END(bpf_tcp_ops_set_rcvlowat_kfunc_set)\nnet/ipv4/bpf_tcp_ops.c-388-\nnet/ipv4/bpf_tcp_ops.c:389:static int bpf_tcp_ops_set_flags_kfunc_filter(const struct bpf_prog *prog,\nnet/ipv4/bpf_tcp_ops.c-390-\t\t\t\t\t u32 kfunc_id)\nnet/ipv4/bpf_tcp_ops.c-391-{\nnet/ipv4/bpf_tcp_ops.c:392:\tif (!btf_id_set8_contains(\u0026bpf_tcp_ops_set_flags_kfunc_set, kfunc_id))\nnet/ipv4/bpf_tcp_ops.c-393-\t\treturn 0;\n--\nnet/ipv4/bpf_tcp_ops.c-395-\tif (prog-\u003etype == BPF_PROG_TYPE_STRUCT_OPS \u0026\u0026\nnet/ipv4/bpf_tcp_ops.c:396:\t prog-\u003eaux-\u003est_ops == \u0026bpf_tcp_ops)\nnet/ipv4/bpf_tcp_ops.c-397-\t\treturn 0;\n--\nnet/ipv4/bpf_tcp_ops.c-405-\nnet/ipv4/bpf_tcp_ops.c:406:static const struct btf_kfunc_id_set bpf_tcp_ops_set_flags_kfunc_id_set = {\nnet/ipv4/bpf_tcp_ops.c-407-\t.owner = THIS_MODULE,\nnet/ipv4/bpf_tcp_ops.c:408:\t.set = \u0026bpf_tcp_ops_set_flags_kfunc_set,\nnet/ipv4/bpf_tcp_ops.c:409:\t.filter = bpf_tcp_ops_set_flags_kfunc_filter,\nnet/ipv4/bpf_tcp_ops.c-410-};\nnet/ipv4/bpf_tcp_ops.c-411-\nnet/ipv4/bpf_tcp_ops.c:412:static int bpf_tcp_ops_set_rcvlowat_kfunc_filter(const struct bpf_prog *prog,\nnet/ipv4/bpf_tcp_ops.c-413-\t\t\t\t\t\t u32 kfunc_id)\n--\nnet/ipv4/bpf_tcp_ops.c-416-\nnet/ipv4/bpf_tcp_ops.c:417:\tif (!btf_id_set8_contains(\u0026bpf_tcp_ops_set_rcvlowat_kfunc_set, kfunc_id))\nnet/ipv4/bpf_tcp_ops.c-418-\t\treturn 0;\nnet/ipv4/bpf_tcp_ops.c-419-\nnet/ipv4/bpf_tcp_ops.c:420:\tif (prog-\u003eaux-\u003est_ops != \u0026bpf_tcp_ops)\nnet/ipv4/bpf_tcp_ops.c-421-\t\treturn -EACCES;\n--\nnet/ipv4/bpf_tcp_ops.c-423-\tmoff = prog-\u003eaux-\u003eattach_st_ops_member_off;\nnet/ipv4/bpf_tcp_ops.c:424:\tif (moff != offsetof(struct bpf_tcp_ops, enqueue_rcvq) \u0026\u0026\nnet/ipv4/bpf_tcp_ops.c:425:\t moff != offsetof(struct bpf_tcp_ops, dequeue_rcvq))\nnet/ipv4/bpf_tcp_ops.c-426-\t\treturn -EACCES;\n--\nnet/ipv4/bpf_tcp_ops.c-430-\nnet/ipv4/bpf_tcp_ops.c:431:static const struct btf_kfunc_id_set bpf_tcp_ops_set_rcvlowat_kfunc_id_set = {\nnet/ipv4/bpf_tcp_ops.c-432-\t.owner = THIS_MODULE,\n\n"
} |
| 5/2 | 2026/10/06 20:08 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 33941 output: 33 thoughts: 18 Thoughts: Okay, let's dive into this. Here's how I'd approach that snippet, as though it were my train of thought: **Checking the IPv4 Makefile** Alright, I'm thinking I need to understand something about the IPv4 networking stack build process. My gut feeling is that the relevant information is likely in the `net/ipv4/Makefile`. That's where I usually start when I'm looking at how IPv4 modules are compiled and linked. I'm going to jump straight to around line 73. That's often a good starting point for conditional compilation, object file handling, or perhaps even dependency definitions within that Makefile context. Let's see what that section reveals about the issue I'm working on... I'm expecting something related to a specific module, build flag, or object file. Perhaps that's where the problem lies. |
| 6/2 | 2026/10/06 20:08 | tool | read-file |
0mArgs:{
"File": "net/ipv4/Makefile",
"FirstLine": 65,
"LineCount": 20
}Results: {
"Contents": " 65:\tobj-$(CONFIG_NETLABEL) += cipso_ipv4.o\n 66:\t\n 67:\tobj-$(CONFIG_XFRM) += xfrm4_policy.o xfrm4_state.o xfrm4_input.o \\\n 68:\t\t\t xfrm4_output.o xfrm4_protocol.o\n 69:\tobj-$(CONFIG_TCP_AO) += tcp_ao.o\n 70:\t\n 71:\tifeq ($(CONFIG_BPF_JIT),y)\n 72:\tobj-$(CONFIG_BPF_SYSCALL) += bpf_tcp_ca.o\n 73:\tobj-$(CONFIG_CGROUP_BPF) += bpf_tcp_ops.o\n 74:\tendif\n 75:\t\n 76:\tifdef CONFIG_GCOV_PROFILE_NETFILTER\n 77:\tGCOV_PROFILE_netfilter.o := y\n 78:\tendif\n"
} |
| 7/2 | 2026/10/06 20:08 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34432 output: 40 thoughts: 68 Thoughts: Here's my take: **Investigating BPF and cgroup Interaction** Alright, let's break this down. Seeing this snippet: ```makefile ifeq ($(CONFIG_BPF_JIT),y) obj-$(CONFIG_CGROUP_BPF) += bpf_tcp_ops.o endif ``` immediately, my brain goes to "Okay, this is linking `bpf_tcp_ops.o` into the build, but only under specific conditions related to BPF JIT and cgroups." The `ifeq` statement screams "conditional compilation". Now, I need to confirm the dependencies and what this actually means in terms of kernel configuration. I'm going straight to `Kconfig` to verify the dependencies. I need to understand the relationship between `CGROUP_BPF` and `BPF_JIT`. Is `CGROUP_BPF` dependent on `BPF_JIT`, or are they orthogonal features? Knowing those dependencies are key to understanding the build path and when `bpf_tcp_ops.o` gets included, which I can then follow upstream to understand its functionality. |
| 8/2 | 2026/10/06 20:08 | tool | grepper |
0mArgs:{
"Expression": "config CGROUP_BPF",
"PathPrefixes": [
"init/Kconfig",
"kernel/bpf/"
]
}Results: {
"Output": "init/Kconfig=1358=config CGROUP_PERF\n--\ninit/Kconfig-1368-\ninit/Kconfig:1369:config CGROUP_BPF\ninit/Kconfig-1370-\tbool \"Support for eBPF programs attached to cgroups\"\n"
} |
| 9/2 | 2026/10/06 20:08 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34872 output: 33 thoughts: 18 Thoughts: Here's a summary of my thought process, as requested: **Diving into the Kernel Configuration Landscape** Okay, time to get to the heart of the matter. I need to take a look at the kernel's configuration files. Specifically, I'm going to focus on `init/Kconfig`. Based on the context, there's likely something interesting – perhaps a specific configuration option, a conditional dependency, or some logic that needs clarification – in that file. My immediate target is around line 1369. This is likely where the relevant definition or logic resides. I'll need to carefully dissect the code there, considering the broader implications within the build system. Let's dig in. |
| 10/2 | 2026/10/06 20:08 | tool | read-file |
0mArgs:{
"File": "init/Kconfig",
"FirstLine": 1368,
"LineCount": 25
}Results: {
"Contents": "1368:\t\n1369:\tconfig CGROUP_BPF\n1370:\t\tbool \"Support for eBPF programs attached to cgroups\"\n1371:\t\tdepends on BPF_SYSCALL\n1372:\t\tselect SOCK_CGROUP_DATA\n1373:\t\thelp\n1374:\t\t Allow attaching eBPF programs to a cgroup using the bpf(2)\n1375:\t\t syscall command BPF_PROG_ATTACH.\n1376:\t\n1377:\t\t In which context these programs are accessed depends on the type\n1378:\t\t of attachment. For instance, programs that are attached using\n1379:\t\t BPF_CGROUP_INET_INGRESS will be executed on the ingress path of\n1380:\t\t inet sockets.\n1381:\t\n1382:\tconfig CGROUP_MISC\n1383:\t\tbool \"Misc resource controller\"\n1384:\t\tdefault n\n1385:\t\thelp\n1386:\t\t Provides a controller for miscellaneous resources on a host.\n1387:\t\n1388:\t\t Miscellaneous scalar resources are the resources on the host system\n1389:\t\t which cannot be abstracted like the other cgroups. This controller\n1390:\t\t tracks and limits the miscellaneous resources used by a process\n1391:\t\t attached to a cgroup hierarchy.\n1392:\t\n"
} |
| 11/2 | 2026/10/06 20:08 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35443 output: 34 thoughts: 176 Thoughts: Okay, let me break this down. **Dependencies and Requirements for eBPF Compilation** Alright, so I'm looking at this build process and it's all about eBPF. I see that `CGROUP_BPF` is clearly dependent on `BPF_SYSCALL` – that makes perfect sense, cgroups and syscall hooks, they go hand-in-hand. Then I get to `bpf_tcp_ops.o`, and it pulls in both `BPF_JIT` (that's the Just-In-Time compiler, of course, because of the `ifeq` check for `CONFIG_BPF_JIT`) and, again, `CGROUP_BPF`. Got it. Now, what's missing...? I need to think about the networking side of this. Hold on, what about `NET` or `INET`? IPv4 specifically is enabled with `CONFIG_INET`, of course. Now, `bpf_tcp_ops` is also registering `bpf_struct_ops` through the `register_bpf_struct_ops` function. This is where I need to take a closer look, because `BPF_PROG_TYPE_STRUCT_OPS`, or how the struct ops are registered, might be implicitly dependent on either `BPF_JIT` or, for that matter, `BPF_SYSCALL` to work correctly. I need to know *exactly* what `register_bpf_struct_ops` does to confirm the chain of dependencies. I'll check that function. |
| 12/2 | 2026/10/06 20:08 | tool | grepper |
0mArgs:{
"Expression": "register_bpf_struct_ops",
"PathPrefixes": [
"kernel/bpf/"
]
}Results: {
"Output": "kernel/bpf/btf.c=10499=bpf_struct_ops_find(struct btf *btf, u32 type_id)\n--\nkernel/bpf/btf.c-10519-\nkernel/bpf/btf.c:10520:int __register_bpf_struct_ops(struct bpf_struct_ops *st_ops)\nkernel/bpf/btf.c-10521-{\n--\nkernel/bpf/btf.c-10547-}\nkernel/bpf/btf.c:10548:EXPORT_SYMBOL_GPL(__register_bpf_struct_ops);\nkernel/bpf/btf.c-10549-#endif\n"
} |
| 13/2 | 2026/10/06 20:08 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36188 output: 39 thoughts: 25 Thoughts: Okay, let's dive into this. Here's my take on those thoughts, as if they're my own: **Investigating Line 10549 in `kernel/bpf/btf.c`** Alright, time to get my hands dirty. My instinct is telling me there's something potentially interesting at line 10549 within the `kernel/bpf/btf.c` file. This is the BPF type format code, so whatever's happening there is core to how we're representing and handling types in BPF. I'm already thinking about potential culprits: is it a type definition, perhaps a helper function call related to type handling, or maybe even a tricky bit of pointer manipulation related to the BTF metadata? I'm probably looking at some core data structure related to type information, or a specific handling path. Perhaps I am on my way to finding a bug or a performance bottleneck. Either way, I need to understand the immediate context of that line to see the whole picture. Let's see what's actually there. |
| 14/2 | 2026/10/06 20:08 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/btf.c",
"FirstLine": 10490,
"LineCount": 40
}Results: {
"Contents": "10490:\t\tfor (i = 0; i \u003c cnt; i++) {\n10491:\t\t\tif (st_ops_list[i].value_id == value_id)\n10492:\t\t\t\treturn \u0026st_ops_list[i];\n10493:\t\t}\n10494:\t\n10495:\t\treturn NULL;\n10496:\t}\n10497:\t\n10498:\tconst struct bpf_struct_ops_desc *\n10499:\tbpf_struct_ops_find(struct btf *btf, u32 type_id)\n10500:\t{\n10501:\t\tconst struct bpf_struct_ops_desc *st_ops_list;\n10502:\t\tunsigned int i;\n10503:\t\tu32 cnt;\n10504:\t\n10505:\t\tif (!type_id)\n10506:\t\t\treturn NULL;\n10507:\t\tif (!btf-\u003estruct_ops_tab)\n10508:\t\t\treturn NULL;\n10509:\t\n10510:\t\tcnt = btf-\u003estruct_ops_tab-\u003ecnt;\n10511:\t\tst_ops_list = btf-\u003estruct_ops_tab-\u003eops;\n10512:\t\tfor (i = 0; i \u003c cnt; i++) {\n10513:\t\t\tif (st_ops_list[i].type_id == type_id)\n10514:\t\t\t\treturn \u0026st_ops_list[i];\n10515:\t\t}\n10516:\t\n10517:\t\treturn NULL;\n10518:\t}\n10519:\t\n10520:\tint __register_bpf_struct_ops(struct bpf_struct_ops *st_ops)\n10521:\t{\n10522:\t\tstruct bpf_verifier_log *log;\n10523:\t\tstruct btf *btf;\n10524:\t\tint err = 0;\n10525:\t\n10526:\t\tbtf = btf_get_module_btf(st_ops-\u003eowner);\n10527:\t\tif (!btf)\n10528:\t\t\treturn check_btf_kconfigs(st_ops-\u003eowner, \"struct_ops\");\n10529:\t\tif (IS_ERR(btf))\n"
} |
| 15/2 | 2026/10/06 20:08 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 37125 output: 39 thoughts: 16 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience and presented in the first person: **Diving into the `#ifdef` in `btf.c`** Alright, let's get down to brass tacks. I'm thinking, "Let's zoom in on that `#ifdef` construct within `btf.c`." It's likely a critical conditional compilation point, and my intuition is telling me that it is probably influencing how BTF (Berkeley eBPF Type Format) metadata is handled or generated. Given my background, I'm expecting this `#ifdef` to be gating some specific feature or platform-dependent behavior—maybe a particular compiler version, kernel feature, or architecture-specific optimization. I'm keen to understand the condition itself (what's being `#defined`) and how its presence or absence alters the subsequent code flow. The implications could be broad, affecting everything from BTF's accuracy and completeness to its performance characteristics on different systems. Time to unravel this conditional logic and see what nuances are revealed. |
| 16/2 | 2026/10/06 20:08 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/btf.c",
"FirstLine": 10400,
"LineCount": 40
}Results: {
"Contents": "10400:\t\t\treturn false;\n10401:\t\n10402:\t\treturn !strncmp(reg_name, arg_name, cmp_len);\n10403:\t}\n10404:\t\n10405:\t#ifdef CONFIG_BPF_JIT\n10406:\tstatic int\n10407:\tbtf_add_struct_ops(struct btf *btf, struct bpf_struct_ops *st_ops,\n10408:\t\t\t struct bpf_verifier_log *log)\n10409:\t{\n10410:\t\tstruct btf_struct_ops_tab *tab, *new_tab;\n10411:\t\tint cgroup_atype;\n10412:\t\tint i, err;\n10413:\t\n10414:\t\ttab = btf-\u003estruct_ops_tab;\n10415:\t\tif (!tab) {\n10416:\t\t\ttab = kzalloc_flex(*tab, ops, 4);\n10417:\t\t\tif (!tab)\n10418:\t\t\t\treturn -ENOMEM;\n10419:\t\t\ttab-\u003ecapacity = 4;\n10420:\t\t\tbtf-\u003estruct_ops_tab = tab;\n10421:\t\t}\n10422:\t\n10423:\t\tcgroup_atype = st_ops-\u003ecgroup_atype;\n10424:\t\tfor (i = 0; i \u003c tab-\u003ecnt; i++)\n10425:\t\t\tif (tab-\u003eops[i].st_ops == st_ops ||\n10426:\t\t\t (cgroup_atype \u0026\u0026 cgroup_atype == tab-\u003eops[i].st_ops-\u003ecgroup_atype))\n10427:\t\t\t\treturn -EEXIST;\n10428:\t\n10429:\t\tif (tab-\u003ecnt == tab-\u003ecapacity) {\n10430:\t\t\tnew_tab = krealloc(tab,\n10431:\t\t\t\t\t struct_size(tab, ops, tab-\u003ecapacity * 2),\n10432:\t\t\t\t\t GFP_KERNEL);\n10433:\t\t\tif (!new_tab)\n10434:\t\t\t\treturn -ENOMEM;\n10435:\t\t\ttab = new_tab;\n10436:\t\t\ttab-\u003ecapacity *= 2;\n10437:\t\t\tbtf-\u003estruct_ops_tab = tab;\n10438:\t\t}\n10439:\t\n"
} |
| 17/2 | 2026/10/06 20:08 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38049 output: 33 thoughts: 50 Thoughts: Okay, here's my take on those thoughts, framed as my own mental process: **Diving into BPF JIT and BTF Interplay** Alright, so `CONFIG_BPF_JIT` definitely controls the availability of `struct_ops`, that much is clear. But I need to refresh my memory on the relationship with `DEBUG_INFO_BTF`. Are there any subtle dependencies or requirements there that I'm missing? I suspect there's a connection, especially since we're talking about debug information and JIT compilation. Time to dig into the code… Let's start by looking at how `btf_get_module_btf` is implemented. I'll need to check if there are any subtle `struct_ops` requirements lurking in that function or elsewhere related to BTF handling. Gotta make sure everything is properly tied together in the right way. |
| 18/2 | 2026/10/06 20:08 | tool | grepper |
0mArgs:{
"Expression": "check_btf_kconfigs",
"PathPrefixes": [
"kernel/bpf/"
]
}Results: {
"Output": "kernel/bpf/btf.c=9175=struct btf *btf_get_module_btf(const struct module *module)\n--\nkernel/bpf/btf.c-9204-\nkernel/bpf/btf.c:9205:static int check_btf_kconfigs(const struct module *module, const char *feature)\nkernel/bpf/btf.c-9206-{\n--\nkernel/bpf/btf.c=9698=static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,\n--\nkernel/bpf/btf.c-9705-\tif (!btf)\nkernel/bpf/btf.c:9706:\t\treturn check_btf_kconfigs(kset-\u003eowner, \"kfunc\");\nkernel/bpf/btf.c-9707-\tif (IS_ERR(btf))\n--\nkernel/bpf/btf.c=9812=int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_cnt,\n--\nkernel/bpf/btf.c-9821-\tif (!btf)\nkernel/bpf/btf.c:9822:\t\treturn check_btf_kconfigs(owner, \"dtor kfuncs\");\nkernel/bpf/btf.c-9823-\tif (IS_ERR(btf))\n--\nkernel/bpf/btf.c=10520=int __register_bpf_struct_ops(struct bpf_struct_ops *st_ops)\n--\nkernel/bpf/btf.c-10527-\tif (!btf)\nkernel/bpf/btf.c:10528:\t\treturn check_btf_kconfigs(st_ops-\u003eowner, \"struct_ops\");\nkernel/bpf/btf.c-10529-\tif (IS_ERR(btf))\n"
} |
| 19/2 | 2026/10/06 20:08 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38838 output: 38 thoughts: 16 Thoughts: Okay, let's dive into this. Here's my take on those thoughts, as if they're my own: **Investigating `check_btf_kconfigs`** Alright, time to crack this open. Let me mentally walk through what's going on here. The task at hand is to understand the purpose and function of this `check_btf_kconfigs` thing. Given my expertise, I know "BTF" refers to BPF Type Format, and "kconfigs" obviously relates to kernel configuration. So, my initial hypothesis is that this likely involves verifying the configuration options relevant to BTF generation or usage within the kernel. I need to figure out *precisely* what these checks entail. Are we validating dependencies? Ensuring specific options are enabled? Or is it something more nuanced, like compatibility checks? I need to understand the scope and the specifics. Let's see what the code reveals. Time to dissect and analyze. |
| 20/2 | 2026/10/06 20:09 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/btf.c",
"FirstLine": 9204,
"LineCount": 20
}Results: {
"Contents": "9204:\t\n9205:\tstatic int check_btf_kconfigs(const struct module *module, const char *feature)\n9206:\t{\n9207:\t\tif (!module \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {\n9208:\t\t\tpr_err(\"missing vmlinux BTF, cannot register %s\\n\", feature);\n9209:\t\t\treturn -ENOENT;\n9210:\t\t}\n9211:\t\tif (module \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))\n9212:\t\t\tpr_warn(\"missing module BTF, cannot register %s\\n\", feature);\n9213:\t\treturn 0;\n9214:\t}\n9215:\t\n9216:\tBPF_CALL_4(bpf_btf_find_by_name_kind, char *, name, int, name_sz, u32, kind, int, flags)\n9217:\t{\n9218:\t\tstruct btf *btf = NULL;\n9219:\t\tint btf_obj_fd = 0;\n9220:\t\tlong ret;\n9221:\t\n9222:\t\tif (flags)\n9223:\t\t\treturn -EINVAL;\n"
} |
| 21/2 | 2026/10/06 20:09 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39428 output: 38 thoughts: 115 Thoughts: **Analyzing BTF Initialization and Module Loading** Okay, let's break this down. It seems like the behavior surrounding BTF (BPF Type Format) loading is conditional. My initial thought is that if `DEBUG_INFO_BTF` isn't enabled, then `btf_get_module_btf(NULL)` is going to return NULL. And further, it appears that `register_bpf_struct_ops` might bail out early, returning 0, if `!CONFIG_DEBUG_INFO_BTF`. That makes sense as an optimization. Now, the interesting bit. The code says `btf = btf_get_module_btf(st_ops->owner);`. The `owner` here is `THIS_MODULE`, which I know is NULL when we're dealing with a built-in module. So, we're calling `btf_get_module_btf` with NULL. That’s probably the key point here. I need to understand what `btf_get_module_btf` is supposed to do in that scenario. Let me dive into the implementation of `btf_get_module_btf` to clarify the intended behaviour. |
| 22/2 | 2026/10/06 20:10 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/btf.c",
"FirstLine": 9175,
"LineCount": 25
}Results: {
"Contents": "9175:\tstruct btf *btf_get_module_btf(const struct module *module)\n9176:\t{\n9177:\t#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\n9178:\t\tstruct btf_module *btf_mod, *tmp;\n9179:\t#endif\n9180:\t\tstruct btf *btf = NULL;\n9181:\t\n9182:\t\tif (!module) {\n9183:\t\t\tbtf = bpf_get_btf_vmlinux();\n9184:\t\t\tif (!IS_ERR_OR_NULL(btf))\n9185:\t\t\t\tbtf_get(btf);\n9186:\t\t\treturn btf;\n9187:\t\t}\n9188:\t\n9189:\t#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\n9190:\t\tmutex_lock(\u0026btf_module_mutex);\n9191:\t\tlist_for_each_entry_safe(btf_mod, tmp, \u0026btf_modules, list) {\n9192:\t\t\tif (btf_mod-\u003emodule != module)\n9193:\t\t\t\tcontinue;\n9194:\t\n9195:\t\t\tbtf_get(btf_mod-\u003ebtf);\n9196:\t\t\tbtf = btf_mod-\u003ebtf;\n9197:\t\t\tbreak;\n9198:\t\t}\n9199:\t\tmutex_unlock(\u0026btf_module_mutex);\n"
} |
| 23/2 | 2026/10/06 20:10 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 40232 output: 37 thoughts: 77 Thoughts: Okay, here's my understanding, assuming I'm an expert in this area: **Verifying the Dependency of `bpf_get_btf_vmlinux` on `CONFIG_DEBUG_INFO_BTF`** Right, so, let me see if I've got this straight. The `bpf_get_btf_vmlinux()` function is absolutely dependent on `CONFIG_DEBUG_INFO_BTF`. If that kernel configuration option isn't enabled, then there's simply no BTF (BTF stands for BPF Type Format) data baked into the `vmlinux` image. And without that `vmlinux` BTF, forget about registering things like those crucial `struct_ops` and `kfuncs` that we rely on for BPF introspection and instrumentation! That's a no-go. So, I need to double-check the logic surrounding `bpf_get_btf_vmlinux` to confirm this dependency is handled properly. This means a thorough verification of its behavior under the condition where `CONFIG_DEBUG_INFO_BTF` is disabled. I'll need to examine the code path of `bpf_get_btf_vmlinux` and its interactions to confirm this important point. |
| 24/2 | 2026/10/06 20:10 | tool | grepper |
0mArgs:{
"Expression": "bpf_get_btf_vmlinux",
"PathPrefixes": [
"kernel/bpf/"
]
}Results: {
"Output": "kernel/bpf/bpf_struct_ops.c=1078=static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr)\n--\nkernel/bpf/bpf_struct_ops.c-1106-\t} else {\nkernel/bpf/bpf_struct_ops.c:1107:\t\tbtf = bpf_get_btf_vmlinux();\nkernel/bpf/bpf_struct_ops.c-1108-\t\tif (IS_ERR(btf))\n--\nkernel/bpf/btf.c=699=s32 bpf_find_btf_id(const char *name, u32 kind, struct btf **btf_p)\n--\nkernel/bpf/btf.c-704-\nkernel/bpf/btf.c:705:\tbtf = bpf_get_btf_vmlinux();\nkernel/bpf/btf.c-706-\tif (IS_ERR(btf))\n--\nkernel/bpf/btf.c=6924=static struct btf *btf_parse_module(const char *module_name, const void *data,\n--\nkernel/bpf/btf.c-6932-\nkernel/bpf/btf.c:6933:\tvmlinux_btf = bpf_get_btf_vmlinux();\nkernel/bpf/btf.c-6934-\tif (IS_ERR(vmlinux_btf))\n--\nkernel/bpf/btf.c=8471=int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog)\n--\nkernel/bpf/btf.c-8634-\nkernel/bpf/btf.c:8635:\t\t\tvmlinux_btf = bpf_get_btf_vmlinux();\nkernel/bpf/btf.c-8636-\t\t\tref_t = btf_type_by_id(vmlinux_btf, kern_type_id);\n--\nkernel/bpf/btf.c=9175=struct btf *btf_get_module_btf(const struct module *module)\n--\nkernel/bpf/btf.c-9182-\tif (!module) {\nkernel/bpf/btf.c:9183:\t\tbtf = bpf_get_btf_vmlinux();\nkernel/bpf/btf.c-9184-\t\tif (!IS_ERR_OR_NULL(btf))\n--\nkernel/bpf/btf.c=9353=static int btf_check_kfunc_name(struct btf *btf, const char *func_name, u32 kind)\n--\nkernel/bpf/btf.c-9362-\nkernel/bpf/btf.c:9363:\tid = btf_find_by_name_kind(bpf_get_btf_vmlinux(), func_name, kind);\nkernel/bpf/btf.c-9364-\tif (id \u003e= 0) {\n--\nkernel/bpf/btf.c=10137=bpf_core_find_cands(struct bpf_core_ctx *ctx, u32 local_type_id)\n--\nkernel/bpf/btf.c-10147-\nkernel/bpf/btf.c:10148:\tmain_btf = bpf_get_btf_vmlinux();\nkernel/bpf/btf.c-10149-\tif (IS_ERR(main_btf))\n--\nkernel/bpf/inode.c=661=static int find_bpffs_btf_enums(struct bpffs_btf_enums *info)\n--\nkernel/bpf/inode.c-676-\nkernel/bpf/inode.c:677:\tbtf = bpf_get_btf_vmlinux();\nkernel/bpf/inode.c-678-\tif (IS_ERR(btf))\n--\nkernel/bpf/syscall.c=2953=static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_attr *attr_log)\n--\nkernel/bpf/syscall.c-3057-\t\t/* fall back to vmlinux BTF, if BTF type ID is specified */\nkernel/bpf/syscall.c:3058:\t\tattach_btf = bpf_get_btf_vmlinux();\nkernel/bpf/syscall.c-3059-\t\tif (IS_ERR(attach_btf)) {\n--\nkernel/bpf/verifier.c=20727=static int do_check_common(struct bpf_verifier_env *env, int subprog, bool is_sleepable)\n--\nkernel/bpf/verifier.c-20823-\t\t\t\tmark_reg_known_zero(env, regs, i);\nkernel/bpf/verifier.c:20824:\t\t\t\treg-\u003ebtf = bpf_get_btf_vmlinux(); /* can't fail at this point */\nkernel/bpf/verifier.c-20825-\t\t\t\treg-\u003ebtf_id = arg-\u003ebtf_id;\n--\nkernel/bpf/verifier.c=21873=int bpf_check_attach_btf_id_multi(struct btf *btf, struct bpf_prog *prog, u32 btf_id,\n--\nkernel/bpf/verifier.c-21929-\nkernel/bpf/verifier.c:21930:struct btf *bpf_get_btf_vmlinux(void)\nkernel/bpf/verifier.c-21931-{\n--\nkernel/bpf/verifier.c=22563=int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,\n--\nkernel/bpf/verifier.c-22632-\nkernel/bpf/verifier.c:22633:\tbpf_get_btf_vmlinux();\nkernel/bpf/verifier.c-22634-\n"
} |
| 25/2 | 2026/10/06 20:10 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 42199 output: 38 thoughts: 17 Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person: **Inspecting `bpf_get_btf_vmlinux`** Alright, let's dive into the `bpf_get_btf_vmlinux` function. My initial thought process here is to consider its *purpose* and how it fits into the broader BPF ecosystem. I know that BTF (BPF Type Format) is crucial for type information, enabling things like verifier checks and tools that understand the BPF bytecode more intelligently. So, this function *must* be about retrieving or accessing that BTF data related to the running vmlinux kernel, which, in and of itself, is usually a non-trivial process. I'm immediately considering potential implementation details. Is it pulling it directly from the kernel image? Or, is it relying on a pre-generated BTF file that's been packaged with the kernel or accessible elsewhere? Are there caching mechanisms involved, given that vmlinux BTF retrieval is an expensive operation, potentially? Next up, I'd want to examine the function's arguments. What information does it take as input? Kernel version? Architecture? A file path? I anticipate that it likely has a way to identify the correct vmlinux and retrieve the appropriate BTF. Any options related to error handling here? Does it account for cases where BTF is not available, or is corrupted? I'm also curious about its return value. Is it returning a pointer to the BTF data directly? Or, a handle or context for interacting with the BTF information? I would assume, since we are interacting with kernel data, that we are dealing with a kernel pointer, and thus will need special treatment. Knowing the return type is critical for how I will need to handle the data downstream. I'm hoping this is implemented efficiently. I'm keen to see if it makes use of any optimizations, such as mmaping the data, which could be beneficial. Finally, I'll be looking for concurrency considerations, especially if there's any shared state. Are there any locking mechanisms in place to guarantee data consistency, or thread safety when interacting with the returned BTF data? I'm expecting some level of sophistication here. |
| 26/2 | 2026/10/06 20:10 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 21930,
"LineCount": 25
}Results: {
"Contents": "21930:\tstruct btf *bpf_get_btf_vmlinux(void)\n21931:\t{\n21932:\t\t/* Pairs with the smp_store_release() on the parse path below. */\n21933:\t\tstruct btf *btf = smp_load_acquire(\u0026btf_vmlinux);\n21934:\t\n21935:\t\tif (!btf \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {\n21936:\t\t\tmutex_lock(\u0026btf_vmlinux_lock);\n21937:\t\t\tbtf = btf_vmlinux;\n21938:\t\t\tif (!btf) {\n21939:\t\t\t\tbtf = btf_parse_vmlinux();\n21940:\t\t\t\t/*\n21941:\t\t\t\t * Order the parsed BTF contents and the globals the\n21942:\t\t\t\t * parse populated (e.g. bpf_ctx_convert.t) before\n21943:\t\t\t\t * the pointer publication. Pairs with the acquire\n21944:\t\t\t\t * on the lockless fast path above.\n21945:\t\t\t\t */\n21946:\t\t\t\tsmp_store_release(\u0026btf_vmlinux, btf);\n21947:\t\t\t}\n21948:\t\t\tmutex_unlock(\u0026btf_vmlinux_lock);\n21949:\t\t}\n21950:\t\treturn btf;\n21951:\t}\n21952:\t\n21953:\t/*\n21954:\t * The add_fd_from_fd_array() is executed only if fd_array_cnt is non-zero. In\n"
} |
| 27/2 | 2026/10/06 20:10 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 43183 output: 30 thoughts: 896 Thoughts: **Analyzing BTF and BPF Dependencies for Network Functionality** Okay, so I've confirmed that `CONFIG_DEBUG_INFO_BTF` is *absolutely* necessary for the vmlinux BTF. No question about it. I started by looking at `__bpf_tcp_ops_init`, which registers several BTF-related items. The key part is how it handles the absence of BTF. `__register_bpf_struct_ops` calls `check_btf_kconfigs` if the BTF pointer (`btf`) is NULL. Now, I initially got a little tripped up, thinking that `check_btf_kconfigs` might return 0 even with `CONFIG_DEBUG_INFO_BTF` enabled under certain module conditions. But I realized that the core of the problem lies in the check itself. If `btf` is NULL, then the code *bypasses* the critical step of adding the `st_ops` to `btf->struct_ops_tab`. So, if the BTF info is not there, then no `struct_ops` are added, meaning they cannot be loaded or used without the `DEBUG_INFO_BTF` configuration. Now, my focus shifts to the other potentially relevant configs. I'm thinking about `CONFIG_INET`, `CONFIG_BPF_SYSCALL`, `CONFIG_CGROUP_BPF`, and `CONFIG_BPF_JIT`. Let's look at `CONFIG_BPF_JIT` and its influence. I've checked the `net/ipv4/Makefile`. Okay, so I see that `bpf_tcp_ops.o` is *only* compiled if both `CONFIG_BPF_JIT=y` *and* `CONFIG_CGROUP_BPF=y`. This means they are both important for `bpf_tcp_ops`. Let's clarify these dependencies to be completely certain. And as I thought, `CONFIG_CGROUP_BPF` has some important dependencies. It depends on `CONFIG_BPF_SYSCALL` (obviously) but also, I see in `init/Kconfig`, that it *also* depends on `CGROUPS`. |
| 28/2 | 2026/10/06 20:11 | tool | grepper |
0mArgs:{
"Expression": "menuconfig CGROUPS",
"PathPrefixes": [
"init/Kconfig"
]
}Results: {
"Output": "init/Kconfig=1058=config SLAB_OBJ_EXT\n--\ninit/Kconfig-1060-\ninit/Kconfig:1061:menuconfig CGROUPS\ninit/Kconfig-1062-\tbool \"Control Group support\"\n"
} |
| 29/2 | 2026/10/06 20:11 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 44672 output: 31 thoughts: 185 Thoughts: **Analyzing Kernel Configuration Options** Okay, let's dive into this configuration situation. I need to examine the interaction between certain kernel features. First, I'll focus on the `init/Kconfig` file, specifically lines 1061 to 1375. Aha, line 1370 is definitely within the `if CGROUPS` block. That means I need to consider these related configurations: `INET`, `CGROUP_BPF`, `BPF_SYSCALL`, `BPF_JIT`, and `DEBUG_INFO_BTF`. These are all relevant, given the presence of `CGROUPS`. Now, I'm going to look for other relevant configurations that might interact with these. Let's move over to `net/ipv4/tcp_fastopen.c`. I'm seeing a call to `bpf_tcp_ops_call_flag` with the `enqueue_rcvq`, `RCVQ`, `sk`, and `skb` parameters. This function call is making me think of `CONFIG_TCP_FASTOPEN`. Given the nature of fast open, it seems plausible that the configuration depends on `CONFIG_INET` or directly `CONFIG_TCP_FASTOPEN`. I need to verify that and, if so, understand the linkage. I'll need to double check the Kconfig file for `TCP_FASTOPEN` to pin this down. |
| 30/2 | 2026/10/06 20:11 | tool | grepper |
0mError:no matches Args: {
"Expression": "config TCP_FASTOPEN",
"PathPrefixes": [
"net/ipv4/"
]
}Results: {
"error": "no matches"
} |
| 31/2 | 2026/10/06 20:11 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 45203 output: 36 thoughts: 1784 Thoughts: **Analyzing TCP BPF Integration Patches for Fuzzing Focus** Alright, let's break down this patch. My immediate thought is, what novel attack surface does this introduce that I should focus on for fuzzing? This looks like a significant integration of BPF into various TCP functions, and that's usually interesting. So, `tcp_fastopen.c` is included in the build (`obj-y`). I need to get the specific changes that are relevant to generating test cases. First, I see several kfuncs added in `bpf_tcp_ops.c`. `bpf_tcp_ops_set_flags` and `bpf_tcp_ops_set_rcvlowat` look particularly interesting as new, exported symbols. Let's see if they're static - Nope! That's a good starting point to focus on fuzzing to cover these new functions. The filters `bpf_tcp_ops_set_flags_kfunc_filter` and `bpf_tcp_ops_set_rcvlowat_kfunc_filter` seem to control *where* those kfuncs can be called from. They might be interesting for verification, as well. Also, the `is_sockopt_supported` inline function could be exploited as well. Moving to `net/ipv4/tcp.c`, `__tcp_set_rcvlowat` appears as a new non-static function which will have new logic and handling to fuzz, specifically how it handles `wakeup`. The change to `tcp_cleanup_rbuf` calling `dequeue_rcvq` is another potential area. So any fuzzing around Receive Buffer Cleanup needs to check this new call path. Then, in `tcp_fastopen.c`, the call to `enqueue_rcvq` within `tcp_fastopen_add_skb` makes this relevant in fast open contexts. I'll need to consider how to create interesting fast open scenarios. In `tcp_input.c`, the additions of `enqueue_rcvq` calls in `tcp_queue_rcv` and `tcp_ofo_queue` are important. The `bpf_tcp_ops_parse_hdr` function has some logic change, so the BPF interaction there needs to be checked. Let's see who is calling `bpf_tcp_ops_parse_hdr`. I should be able to cover all call paths. The `bpf_skops_*` functions are all checking `cgroup_bpf_enabled()`, which seems like a precondition for some of these BPF features to be used. Finally, `tcp_output.c` adds `bpf_skops_*` and `bpf_tcp_ops_*` functions with `cgroup_bpf_enabled()` checks. I'll need to remember these functions, including their BPF flags when fuzzing this. The `tcp_established_options` refactor is a good place to start, as its code path is used in `tcp_output.c`. Okay, to summarize, the functions to concentrate on for my fuzzing campaign are: * `bpf_tcp_ops_set_flags`, `bpf_tcp_ops_set_rcvlowat`, their corresponding filters, and `is_sockopt_supported`. * `__tcp_set_rcvlowat`, `tcp_cleanup_rbuf` * `tcp_fastopen_add_skb` * `tcp_queue_rcv`, `tcp_ofo_queue` * All `bpf_tcp_ops_*` functions * `bpf_skops_*` functions The addition of the `enqueue_rcvq` and `dequeue_rcvq` callbacks in the `bpf_tcp_ops` struct is critical. I'll need to explore how these are used in different TCP states and conditions. Specifically, I'll need to examine where BPF programs are attached, as this dictates the execution flow. I need to design test cases that exercise the BPF program attachments and how flags/rcvlowat are affected. |
| 32/2 | 2026/10/06 20:12 | tool | grepper |
0mArgs:{
"Expression": "bpf_tcp_ops_parse_hdr",
"PathPrefixes": [
"net/ipv4/"
]
}Results: {
"Output": "net/ipv4/tcp_input.c=210=static void bpf_skops_established(struct sock *sk, int bpf_op,\n--\nnet/ipv4/tcp_input.c-215-\nnet/ipv4/tcp_input.c:216:static void bpf_tcp_ops_parse_hdr(struct sock *sk, struct sk_buff *skb)\nnet/ipv4/tcp_input.c-217-{\n--\nnet/ipv4/tcp_input.c=6359=static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,\n--\nnet/ipv4/tcp_input.c-6500-\tbpf_skops_parse_hdr(sk, skb);\nnet/ipv4/tcp_input.c:6501:\tbpf_tcp_ops_parse_hdr(sk, skb);\nnet/ipv4/tcp_input.c-6502-\n"
} |
| 33/2 | 2026/10/06 20:12 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 48155 output: 40 thoughts: 178 Thoughts: **Investigating TCP BPF Operations in vmlinux** Okay, let's see, I'm digging into some TCP BPF operations in the kernel, specifically within `net/ipv4/tcp_output.c`. I'm focusing on `bpf_tcp_ops_hdr_opt_len` and `bpf_skops_write_hdr_opt`. Now, I want to see how these relate to other symbols. I want to see which of these functions have unique addresses in vmlinux. I'll need to check the distinct addresses of the following: `bpf_tcp_ops_set_flags`, `bpf_tcp_ops_set_rcvlowat`, and then the lower-level functions that may be associated with it: `__tcp_set_rcvlowat`, `tcp_set_rcvlowat`, `tcp_queue_rcv`, `tcp_ofo_queue`, `tcp_fastopen_add_skb`, and `tcp_cleanup_rbuf`. Hold on... I'm just quickly trying to verify if `tcp_queue_rcv` or `tcp_ofo_queue` are static or exported. I need to know their visibility to see how they interact with the BPF code I'm looking at. |
| 34/2 | 2026/10/06 20:12 | tool | grepper |
0mArgs:{
"Expression": "tcp_queue_rcv\\(|tcp_ofo_queue\\(",
"PathPrefixes": [
"net/ipv4/"
]
}Results: {
"Output": "net/ipv4/tcp_input.c=5330=tcp_drop_reason(struct sock *sk, struct sk_buff *skb, enum skb_drop_reason reason)\n--\nnet/ipv4/tcp_input.c-5338- */\nnet/ipv4/tcp_input.c:5339:static void tcp_ofo_queue(struct sock *sk)\nnet/ipv4/tcp_input.c-5340-{\n--\nnet/ipv4/tcp_input.c=5416=static void tcp_data_queue_ofo(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv4/tcp_input.c-5566-\nnet/ipv4/tcp_input.c:5567:static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb,\nnet/ipv4/tcp_input.c-5568-\t\t\t\t bool *fragstolen)\n--\nnet/ipv4/tcp_input.c=5586=int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size)\n--\nnet/ipv4/tcp_input.c-5624-\nnet/ipv4/tcp_input.c:5625:\tif (tcp_queue_rcv(sk, skb, \u0026fragstolen)) {\nnet/ipv4/tcp_input.c-5626-\t\tWARN_ON_ONCE(fragstolen); /* should not happen */\n--\nnet/ipv4/tcp_input.c=5644=static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv4/tcp_input.c-5706-\nnet/ipv4/tcp_input.c:5707:\t\teaten = tcp_queue_rcv(sk, skb, \u0026fragstolen);\nnet/ipv4/tcp_input.c-5708-\t\tif (skb-\u003elen)\n--\nnet/ipv4/tcp_input.c-5713-\t\tif (!RB_EMPTY_ROOT(\u0026tp-\u003eout_of_order_queue)) {\nnet/ipv4/tcp_input.c:5714:\t\t\ttcp_ofo_queue(sk);\nnet/ipv4/tcp_input.c-5715-\n--\nnet/ipv4/tcp_input.c=6539=void tcp_rcv_established(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv4/tcp_input.c-6674-\t\t\t\t\t\t len - tcp_header_len);\nnet/ipv4/tcp_input.c:6675:\t\t\teaten = tcp_queue_rcv(sk, skb, \u0026fragstolen);\nnet/ipv4/tcp_input.c-6676-\n"
} |
| 35/2 | 2026/10/06 20:12 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 49366 output: 36 thoughts: 96 Thoughts: Here's my thought process, as requested: **Investigating TCP Queue Functions in the Kernel** Okay, so I'm looking at `net/ipv4/tcp_input.c` and immediately noticing that `tcp_queue_rcv` and `tcp_ofo_queue` are declared as `static`. Right, that's important. In a typical Linux kernel ELF file, with the usual caveats about optimization and inlining, static functions within a `.c` file usually end up as local symbols, meaning they're not directly visible outside that compilation unit. They can, of course, be inlined by the compiler if they are marked with the `inline` keyword or are small enough that the compiler chooses to inline them anyway. This is standard behavior. However, this raises a question. Is this the case with `tcp_fastopen_add_skb`? I need to check the declaration and see what's what. |
| 36/2 | 2026/10/06 20:12 | tool | grepper |
0mArgs:{
"Expression": "tcp_fastopen_add_skb\\(",
"PathPrefixes": [
"net/ipv4/"
]
}Results: {
"Output": "net/ipv4/tcp_fastopen.c=240=static void tcp_fastopen_cookie_gen(struct sock *sk,\n--\nnet/ipv4/tcp_fastopen.c-256- */\nnet/ipv4/tcp_fastopen.c:257:void tcp_fastopen_add_skb(struct sock *sk, struct sk_buff *skb)\nnet/ipv4/tcp_fastopen.c-258-{\n--\nnet/ipv4/tcp_fastopen.c=328=static struct sock *tcp_fastopen_create_child(struct sock *sk,\n--\nnet/ipv4/tcp_fastopen.c-377-\nnet/ipv4/tcp_fastopen.c:378:\ttcp_fastopen_add_skb(child, skb);\nnet/ipv4/tcp_fastopen.c-379-\n--\nnet/ipv4/tcp_input.c=6807=static bool tcp_rcv_fastopen_synack(struct sock *sk, struct sk_buff *synack,\n--\nnet/ipv4/tcp_input.c-6864-\nnet/ipv4/tcp_input.c:6865:\ttcp_fastopen_add_skb(sk, synack);\nnet/ipv4/tcp_input.c-6866-\n"
} |
| 37/2 | 2026/10/06 20:12 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50039 output: 31 thoughts: 857 Thoughts: **Analyzing TCP Function Visibility for Focused Fuzzing** Okay, so I'm looking at these TCP functions and figuring out which ones are relevant for targeted fuzzing, given the guidance on avoiding ubiquitous functions. I see that `tcp_fastopen_add_skb`, `__tcp_set_rcvlowat`, `tcp_set_rcvlowat`, `tcp_cleanup_rbuf`, `bpf_tcp_ops_set_flags`, and `bpf_tcp_ops_set_rcvlowat` are all non-static. My initial thought is that these are good candidates, but let's be thorough. `tcp_cleanup_rbuf` sticks out. I know that's a common receive buffer cleanup, called by `tcp_recvmsg` and `tcp_read_sock`. It's pretty generic. I need to make sure I'm not accidentally focusing the fuzzer on a lifecycle wrapper and diluting the fuzzing effort. I'm referring to Section 4 of whatever document I am looking at, and it clearly states that I should: 1) identify non-static, feature-specific caller functions if static inline functions are changed, and 2) list functions that implement the logic or are the API entrypoints for the feature I'm assessing. The instructions are very clear that I need to AVOID ubiquitous lifecycle hot-paths. So, `bpf_tcp_ops_set_flags`, `bpf_tcp_ops_set_rcvlowat`, `__tcp_set_rcvlowat`, `tcp_set_rcvlowat`, and `tcp_fastopen_add_skb` seem like good options because they appear to be specific feature entry points or directly implement logic. But, I should also check all functions that might be relevant from the `bpf_tcp_ops.c` file, since I'm concerned about bpf interactions. Right, so in `net/ipv4/bpf_tcp_ops.c` I see those functions plus `__bpf_tcp_ops_init` (which is called during init) and `is_sockopt_supported`, called by `get_func_proto`, that may be relevant. Finally, I should check the call sites for `tcp_set_rcvlowat`, just to be certain. This is a good practice to ensure I'm not missing anything. |
| 38/2 | 2026/10/06 20:12 | tool | grepper |
0mArgs:{
"Expression": "tcp_set_rcvlowat",
"PathPrefixes": [
"net/"
]
}Results: {
"Output": "net/ipv4/af_inet.c=1061=const struct proto_ops inet_stream_ops = {\n--\nnet/ipv4/af_inet.c-1091-#endif\nnet/ipv4/af_inet.c:1092:\t.set_rcvlowat\t = tcp_set_rcvlowat,\nnet/ipv4/af_inet.c-1093-\t.set_rcvbuf\t = tcp_set_rcvbuf,\n--\nnet/ipv4/bpf_tcp_ops.c=364=__bpf_kfunc int bpf_tcp_ops_set_rcvlowat(struct sock *sk, int rcvlowat,\n--\nnet/ipv4/bpf_tcp_ops.c-375-\nnet/ipv4/bpf_tcp_ops.c:376:\treturn __tcp_set_rcvlowat(sk, rcvlowat, wakeup);\nnet/ipv4/bpf_tcp_ops.c-377-}\n--\nnet/ipv4/tcp.c=1825=int tcp_peek_len(struct socket *sock)\n--\nnet/ipv4/tcp.c-1829-\nnet/ipv4/tcp.c:1830:int __tcp_set_rcvlowat(struct sock *sk, int val, bool wakeup)\nnet/ipv4/tcp.c-1831-{\n--\nnet/ipv4/tcp.c-1859-/* Make sure sk_rcvbuf is big enough to satisfy SO_RCVLOWAT hint */\nnet/ipv4/tcp.c:1860:int tcp_set_rcvlowat(struct sock *sk, int val)\nnet/ipv4/tcp.c-1861-{\nnet/ipv4/tcp.c:1862:\treturn __tcp_set_rcvlowat(sk, val, true);\nnet/ipv4/tcp.c-1863-}\n--\nnet/ipv6/af_inet6.c=660=const struct proto_ops inet6_stream_ops = {\n--\nnet/ipv6/af_inet6.c-690-#endif\nnet/ipv6/af_inet6.c:691:\t.set_rcvlowat\t = tcp_set_rcvlowat,\nnet/ipv6/af_inet6.c-692-\t.set_rcvbuf\t = tcp_set_rcvbuf,\n--\nnet/mptcp/protocol.c=4727=static const struct proto_ops mptcp_stream_ops = {\n--\nnet/mptcp/protocol.c-4745-\t.mmap\t\t = sock_no_mmap,\nnet/mptcp/protocol.c:4746:\t.set_rcvlowat\t = mptcp_set_rcvlowat,\nnet/mptcp/protocol.c-4747-\t.read_sock\t = mptcp_read_sock,\n--\nnet/mptcp/protocol.c=4836=static const struct proto_ops mptcp_v6_stream_ops = {\n--\nnet/mptcp/protocol.c-4857-#endif\nnet/mptcp/protocol.c:4858:\t.set_rcvlowat\t = mptcp_set_rcvlowat,\nnet/mptcp/protocol.c-4859-\t.read_sock\t = mptcp_read_sock,\n--\nnet/mptcp/protocol.h=871=static inline bool mptcp_epollin_ready(const struct sock *sk)\n--\nnet/mptcp/protocol.h-884-\nnet/mptcp/protocol.h:885:int mptcp_set_rcvlowat(struct sock *sk, int val);\nnet/mptcp/protocol.h-886-\n--\nnet/mptcp/sockopt.c=1606=void mptcp_sockopt_sync_locked(struct mptcp_sock *msk, struct sock *ssk)\n--\nnet/mptcp/sockopt.c-1629- */\nnet/mptcp/sockopt.c:1630:int mptcp_set_rcvlowat(struct sock *sk, int val)\nnet/mptcp/sockopt.c-1631-{\n"
} |
| 39/2 | 2026/10/06 20:12 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 52552 output: 238 thoughts: 1447 Thoughts: **Analysis of TCP BPF Integration and Fuzzing Considerations** Alright, let's break this down. My initial thought process is focusing on the key functions introduced or modified by this patch series. I'm starting by identifying the relevant symbols. I've noted that `tcp_set_rcvlowat` is the entry point, the `.set_rcvlowat` callback for `inet_stream_ops` and `inet6_stream_ops`, and that `__tcp_set_rcvlowat` is the core helper function. `bpf_tcp_ops_set_rcvlowat` is the kfunc. There's also `bpf_tcp_ops_set_flags`, which looks important, along with `tcp_fastopen_add_skb`, as it's directly tied to handling fastopen packets and utilizes the `bpf_tcp_ops_call_flag` with `enqueue_rcvq`. I’m also making sure I don’t forget other possible areas, for instance, `bpf_tcp_ops_hdr_opt_len`, `bpf_skops_write_hdr_opt` in `net/ipv4/tcp_output.c`. Checking their static nature helps assess their impact and if they're relevant. Similarly, I'm noting the static nature of `tcp_established_options`, `is_sockopt_supported`, `get_func_proto`, `bpf_tcp_ops_set_flags_kfunc_filter`, and `bpf_tcp_ops_set_rcvlowat_kfunc_filter`. This helps me filter the specific code that will be used. Given the analysis, the non-static symbols are, as I thought, the ones to zero in on: `bpf_tcp_ops_set_flags`, `bpf_tcp_ops_set_rcvlowat`, `__tcp_set_rcvlowat`, `tcp_set_rcvlowat`, and `tcp_fastopen_add_skb`. A final consideration is `tcp_cleanup_rbuf`. While it's called frequently during any socket read/recv activity, it’s not as tightly coupled with *directly* exercising the modified functionality. It's more of a general cleanup function, and I’ll focus on the more specific functions in the list above. Now, let's nail down the kernel configurations needed for this new functionality. I'm verifying that `INET` for core IPv4/TCP is in place, naturally. Then, `CGROUP_BPF` is essential given `bpf_tcp_ops.o` and related features, along with `CGROUP_TCP_SOCK_OPS`, and `CGROUP_SOCK_OPS`. We also need `BPF_SYSCALL` for BPF programs. `BPF_JIT` is needed for the BPF JIT, as indicated in `net/ipv4/Makefile`, and `DEBUG_INFO_BTF` is required for BTF support, essential for struct_ops registration. I'm also confirming that `CGROUPS` is a prerequisite for `CGROUP_BPF`. Finally, to address any MPTCP interactions, I'm checking the interaction between `BPF_TCP_OPS_FLAG_RCVQ` and `bpf_tcp_ops_set_flags` with MPTCP. The code explicitly checks for MPTCP sockets with `sk_is_mptcp`, and it will reject if those flags are enabled on an MPTCP socket, so that's covered. With all of that taken care of, let's assemble the results. The analysis indicates these changes represent a worthwhile fuzzing target because the patch series introduces fast-path callbacks (`BPF_TCP_OPS_FLAG_*`) and new callbacks (`enqueue_rcvq`, `dequeue_rcvq`) to `bpf_tcp_ops`. It also adds BPF kfuncs like `bpf_tcp_ops_set_flags` and `bpf_tcp_ops_set_rcvlowat` to manipulate TCP receive queue operations and SO_RCVLOWAT dynamically from BPF struct_ops programs. These changes touch core TCP and BPF struct_ops subsystems that are reachable in virtualized environments via BPF syscalls and standard TCP sockets. Here is the final set of configurations: - `WorthFuzzing`: true - `Reasoning`: The patch series adds fast-path callback flags (`BPF_TCP_OPS_FLAG_*`) and new callbacks (`enqueue_rcvq`, `dequeue_rcvq`) to `bpf_tcp_ops`, along with BPF kfuncs `bpf_tcp_ops_set_flags |
| 40/2 | 2026/10/06 20:13 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"INET",
"CGROUPS",
"CGROUP_BPF",
"BPF_SYSCALL",
"BPF_JIT",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"bpf_tcp_ops_set_flags",
"bpf_tcp_ops_set_rcvlowat",
"__tcp_set_rcvlowat",
"tcp_set_rcvlowat",
"tcp_fastopen_add_skb"
],
"Reasoning": "The patch series introduces new bpf_tcp_ops flags and callbacks (enqueue_rcvq, dequeue_rcvq) in core TCP hot paths, along with new BPF kfuncs (bpf_tcp_ops_set_flags and bpf_tcp_ops_set_rcvlowat) and logic for dynamic SO_RCVLOWAT tuning. These changes affect reachable TCP input/output paths and BPF struct_ops handling, making them relevant for fuzzing.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"INET",
"CGROUPS",
"CGROUP_BPF",
"BPF_SYSCALL",
"BPF_JIT",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"bpf_tcp_ops_set_flags",
"bpf_tcp_ops_set_rcvlowat",
"__tcp_set_rcvlowat",
"tcp_set_rcvlowat",
"tcp_fastopen_add_skb"
],
"Reasoning": "The patch series introduces new bpf_tcp_ops flags and callbacks (enqueue_rcvq, dequeue_rcvq) in core TCP hot paths, along with new BPF kfuncs (bpf_tcp_ops_set_flags and bpf_tcp_ops_set_rcvlowat) and logic for dynamic SO_RCVLOWAT tuning. These changes affect reachable TCP input/output paths and BPF struct_ops handling, making them relevant for fuzzing.",
"WorthFuzzing": true
} |
| 41/1 | 2026/10/06 20:13 | action | If |
1mArgs:{
"WorthFuzzing": true
}Results: null |
| 42/2 | 2026/10/06 20:13 | agent | kmsan-evaluator |
1mModel:core Args: null Results: {
"KMSANReasoning": "The patch adds BPF struct_ops callback support and flag-based invocation for TCP receive queue operations (enqueue_rcvq, dequeue_rcvq) and refactors existing TCP BPF hook calling paths.\n\nEvaluation against KMSAN criteria:\n1. No structures are copied to user space; no copy_to_user, put_user, netlink attributes, or ioctl/sockopt data disclosures to user space are introduced or altered.\n2. The newly added struct member (bpf_tcp_ops_flags in struct tcp_sock) resides in a zero-allocated structure (via sk_alloc with __GFP_ZERO) and is explicitly reset in tcp_clear_sock_ops_cb_flags().\n3. All local variables and arrays (such as __args[] in tcp_call_bpf_flag and sock_ops in __tcp_call_bpf) are fully initialized before read access.\n4. Any potential issues stemming from BPF callback invocation, such as socket reference safety, concurrent access to tcp_sock fields, or skb management, fall into concurrency, NULL dereference, or lifetime categories covered by LOCKDEP and KASAN, rather than uninitialized memory reads.\n\nTherefore, the patch introduces no uninitialized memory risks or info-leaks that would require a dedicated KMSAN fuzzing session.",
"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 03049c52daff18ae374ab888a324b6713ecef26a
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Oct 6 20:07:14 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst
index 0f6088c4ab8bb..e4776905e8821 100644
--- a/Documentation/networking/net_cachelines/tcp_sock.rst
+++ b/Documentation/networking/net_cachelines/tcp_sock.rst
@@ -151,6 +151,7 @@ u32 urg_seq
unsigned_int keepalive_time
unsigned_int keepalive_intvl
int linger2
+u32 bpf_tcp_ops_flags read_mostly read_mostly bpf_tcp_ops_hdr_opt_len,bpf_skops_write_hdr_opt(tx);bpf_tcp_ops_parse_hdr,tcp_bpf_rtt,tcp_cleanup_rbuf,tcp_queue_rcv,tcp_ofo_queue,tcp_fastopen_add_skb(rx);
u8 bpf_sock_ops_cb_flags
u8:1 bpf_chg_cc_inprogress
u16 timeout_rehash
diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
index 8a75a6cd73096..02ef7f899b3de 100644
--- a/include/linux/bpf-cgroup.h
+++ b/include/linux/bpf-cgroup.h
@@ -345,27 +345,19 @@ static inline bool cgroup_bpf_sock_enabled(struct sock *sk,
* calling bpf_setsockopt on listener-sk will not make sense anyway,
* so passing 'sock_ops->sk == req_sk' to the bpf prog is appropriate here.
*/
-#define BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(sock_ops, sk) \
-({ \
- int __ret = 0; \
- if (cgroup_bpf_enabled(CGROUP_SOCK_OPS)) \
- __ret = __cgroup_bpf_run_filter_sock_ops(sk, \
- sock_ops, \
- CGROUP_SOCK_OPS); \
- __ret; \
-})
-
-#define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) \
-({ \
- int __ret = 0; \
- if (cgroup_bpf_enabled(CGROUP_SOCK_OPS) && (sock_ops)->sk) { \
- typeof(sk) __sk = sk_to_full_sk((sock_ops)->sk); \
- if (__sk && sk_fullsock(__sk)) \
- __ret = __cgroup_bpf_run_filter_sock_ops(__sk, \
- sock_ops, \
- CGROUP_SOCK_OPS); \
- } \
- __ret; \
+#define __BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(sock_ops, sk) \
+ __cgroup_bpf_run_filter_sock_ops(sk, sock_ops, \
+ CGROUP_SOCK_OPS)
+
+#define __BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) \
+({ \
+ int __ret = 0; \
+ typeof(sk) __sk = sk_to_full_sk((sock_ops)->sk); \
+ if (__sk && sk_fullsock(__sk)) \
+ __ret = __cgroup_bpf_run_filter_sock_ops(__sk, \
+ sock_ops, \
+ CGROUP_SOCK_OPS); \
+ __ret; \
})
#define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(atype, major, minor, access) \
@@ -529,7 +521,7 @@ static inline int cgroup_bpf_struct_ops_attach(struct bpf_map *map,
#define BPF_CGROUP_RUN_PROG_UDP4_RECVMSG_LOCK(sk, uaddr, uaddrlen) ({ 0; })
#define BPF_CGROUP_RUN_PROG_UDP6_RECVMSG_LOCK(sk, uaddr, uaddrlen) ({ 0; })
#define BPF_CGROUP_RUN_PROG_UNIX_RECVMSG_LOCK(sk, uaddr, uaddrlen) ({ 0; })
-#define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; })
+#define __BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; })
#define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(atype, major, minor, access) ({ 0; })
#define BPF_CGROUP_RUN_PROG_SYSCTL(head,table,write,buf,count,pos) ({ 0; })
#define BPF_CGROUP_RUN_PROG_GETSOCKOPT(sock, level, optname, optval, \
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 6a8c77719322f..24bb751cc65a6 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -233,6 +233,13 @@ struct tcp_sock {
is_sack_reneg:1, /* in recovery from loss with SACK reneg? */
is_cwnd_limited:1,/* forward progress limited by snd_cwnd? */
recvmsg_inq : 1;/* Indicate # of bytes in queue upon recvmsg */
+#ifdef CONFIG_BPF
+ u32 bpf_tcp_ops_flags;
+#define BPF_TCP_OPS_TEST_FLAG(TP, ARG) \
+ (READ_ONCE((TP)->bpf_tcp_ops_flags) & BPF_TCP_OPS_FLAG_ ## ARG)
+#else
+#define BPF_TCP_OPS_TEST_FLAG(TP, ARG) (0)
+#endif
__cacheline_group_end(tcp_sock_read_txrx);
/* RX read-mostly hotpath cache lines */
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 4ecabf4989de9..f7624ab9b4208 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -512,6 +512,7 @@ void tcp_set_keepalive(struct sock *sk, int val);
void tcp_syn_ack_timeout(const struct request_sock *req);
int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
int flags);
+int __tcp_set_rcvlowat(struct sock *sk, int val, bool wakeup);
int tcp_set_rcvlowat(struct sock *sk, int val);
void tcp_set_rcvbuf(struct sock *sk, int val);
int tcp_set_window_clamp(struct sock *sk, int val);
@@ -2891,7 +2892,7 @@ static inline void bpf_skops_init_skb(struct bpf_sock_ops_kern *skops,
* program loaded).
*/
#ifdef CONFIG_BPF
-static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)
+static inline int __tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)
{
struct bpf_sock_ops_kern sock_ops;
int ret;
@@ -2908,7 +2909,7 @@ static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)
if (nargs > 0)
memcpy(sock_ops.args, args, nargs * sizeof(*args));
- ret = BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops);
+ ret = __BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops);
if (ret == 0)
ret = sock_ops.reply;
else
@@ -2916,42 +2917,37 @@ static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)
return ret;
}
-static inline int tcp_call_bpf_2arg(struct sock *sk, int op, u32 arg1, u32 arg2)
-{
- u32 args[2] = {arg1, arg2};
-
- return tcp_call_bpf(sk, op, 2, args);
-}
-
-static inline int tcp_call_bpf_3arg(struct sock *sk, int op, u32 arg1, u32 arg2,
- u32 arg3)
-{
- u32 args[3] = {arg1, arg2, arg3};
+#define tcp_call_bpf(sk, op) \
+({ \
+ int __ret = 0; \
+ if (cgroup_bpf_enabled(CGROUP_SOCK_OPS)) { \
+ __ret = __tcp_call_bpf(sk, op, 0, NULL); \
+ } \
+ __ret; \
+})
- return tcp_call_bpf(sk, op, 3, args);
-}
+#define tcp_call_bpf_flag(sk, op, ...) \
+do { \
+ if (cgroup_bpf_enabled(CGROUP_SOCK_OPS) && \
+ BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk), op ## _FLAG)) { \
+ u32 __args[] = { __VA_ARGS__ }; \
+ __tcp_call_bpf(sk, op, ARRAY_SIZE(__args), __args); \
+ } \
+} while (0)
static inline void tcp_clear_sock_ops_cb_flags(struct sock *sk)
{
tcp_sk(sk)->bpf_sock_ops_cb_flags = 0;
+ WRITE_ONCE(tcp_sk(sk)->bpf_tcp_ops_flags, 0);
}
#else
-static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)
-{
- return -EPERM;
-}
-
-static inline int tcp_call_bpf_2arg(struct sock *sk, int op, u32 arg1, u32 arg2)
+static inline int tcp_call_bpf(struct sock *sk, int op)
{
return -EPERM;
}
-static inline int tcp_call_bpf_3arg(struct sock *sk, int op, u32 arg1, u32 arg2,
- u32 arg3)
-{
- return -EPERM;
-}
+#define tcp_call_bpf_flag(sk, op, ...) do { } while (0)
static inline void tcp_clear_sock_ops_cb_flags(struct sock *sk)
{
@@ -2989,7 +2985,7 @@ struct bpf_tcp_ops {
/* Called when the retransmission timer fires. */
void (*rto)(struct sock *sk);
- /* Called on every RTT sample.
+ /* Called on every RTT sample if BPF_TCP_OPS_FLAG_RTT is enabled.
* @mrtt: the measured RTT, in microseconds.
* @srtt: the updated smoothed RTT.
*/
@@ -3016,6 +3012,10 @@ struct bpf_tcp_ops {
* Parse the TCP header options of an incoming skb received on an
* established connection. Use bpf_dynptr_from_skb()/bpf_skb_load_bytes()
* to access the options.
+ *
+ * Called if BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_ALL is enabled, or if
+ * BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_UNKNOWN is enabled and an unknown
+ * option is received.
*/
void (*parse_hdr)(struct sock *sk, struct sk_buff *skb);
@@ -3023,6 +3023,8 @@ struct bpf_tcp_ops {
* Reserve space in the outgoing TCP header for options to be written
* later by write_hdr_opt(). Call bpf_reserve_hdr_opt() to reserve bytes.
*
+ * Called if BPF_TCP_OPS_FLAG_WRITE_HDR_OPT is enabled.
+ *
* @skb: outgoing packet. NULL when called from tcp_current_mss()
* (MSS sizing).
* @req: request_sock on the synack path; NULL otherwise.
@@ -3041,6 +3043,8 @@ struct bpf_tcp_ops {
* Use bpf_store_hdr_opt() to write; it appends within the reserved window
* shared with legacy SOCKOPS.
*
+ * Called if BPF_TCP_OPS_FLAG_WRITE_HDR_OPT is enabled.
+ *
* @skb: outgoing packet.
* @req: request_sock on the synack path; NULL otherwise.
* @syn_skb: incoming SYN on the synack path; NULL otherwise.
@@ -3053,24 +3057,47 @@ struct bpf_tcp_ops {
struct request_sock *req, struct sk_buff *syn_skb,
enum tcp_synack_type synack_type,
u32 opt_off);
+
+ /*
+ * Called when an incoming skb is enqueued to sk->sk_receive_queue
+ * if BPF_TCP_OPS_FLAG_RCVQ is enabled.
+ */
+ void (*enqueue_rcvq)(struct sock *sk, struct sk_buff *skb);
+
+ /*
+ * Called after data is dequeued from sk->sk_receive_queue
+ * if BPF_TCP_OPS_FLAG_RCVQ is enabled.
+ */
+ void (*dequeue_rcvq)(struct sock *sk);
};
-#define bpf_tcp_ops_call(op, sk, ...) \
+#define __bpf_tcp_ops_call(op, sk, ...) \
do { \
- if (cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS)) { \
- const struct bpf_prog_array_item *item; \
- const struct bpf_tcp_ops *tcp_ops; \
- struct cgroup *cgrp; \
+ const struct bpf_prog_array_item *item; \
+ const struct bpf_tcp_ops *tcp_ops; \
+ struct cgroup *cgrp; \
\
- cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); \
- rcu_read_lock_dont_migrate(); \
- bpf_cgroup_struct_ops_foreach(tcp_ops, item, cgrp, \
- CGROUP_TCP_SOCK_OPS) { \
- if (tcp_ops->op) \
- tcp_ops->op(sk, ##__VA_ARGS__); \
- } \
- rcu_read_unlock_migrate(); \
+ cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); \
+ rcu_read_lock_dont_migrate(); \
+ bpf_cgroup_struct_ops_foreach(tcp_ops, item, cgrp, \
+ CGROUP_TCP_SOCK_OPS) { \
+ if (tcp_ops->op) \
+ tcp_ops->op(sk, ##__VA_ARGS__); \
} \
+ rcu_read_unlock_migrate(); \
+} while (0)
+
+#define bpf_tcp_ops_call(op, sk, ...) \
+do { \
+ if (cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS)) \
+ __bpf_tcp_ops_call(op, sk, ##__VA_ARGS__); \
+} while (0)
+
+#define bpf_tcp_ops_call_flag(op, flag, sk, ...) \
+do { \
+ if (cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS) && \
+ BPF_TCP_OPS_TEST_FLAG(tcp_sk(sk), flag)) \
+ __bpf_tcp_ops_call(op, sk, ##__VA_ARGS__); \
} while (0)
#define bpf_tcp_ops_call_int(op, init_retval, sk, ...) \
@@ -3106,7 +3133,9 @@ do { \
})
#else
-#define bpf_tcp_ops_call(op, sk, ...) do { } while (0)
+#define __bpf_tcp_ops_call(op, sk, ...) do { } while (0)
+#define bpf_tcp_ops_call(op, sk, ...) do { } while (0)
+#define bpf_tcp_ops_call_flag(op, flag, sk, ...) do { } while (0)
#define bpf_tcp_ops_call_int(op, init_retval, sk, ...) (init_retval)
#endif
@@ -3114,7 +3143,7 @@ static inline u32 tcp_timeout_init(struct sock *sk)
{
int timeout;
- timeout = tcp_call_bpf(sk, BPF_SOCK_OPS_TIMEOUT_INIT, 0, NULL);
+ timeout = tcp_call_bpf(sk, BPF_SOCK_OPS_TIMEOUT_INIT);
timeout = bpf_tcp_ops_call_int(timeout_init, timeout, sk);
if (timeout <= 0)
timeout = TCP_TIMEOUT_INIT;
@@ -3125,7 +3154,7 @@ static inline u32 tcp_rwnd_init_bpf(struct sock *sk)
{
int rwnd;
- rwnd = tcp_call_bpf(sk, BPF_SOCK_OPS_RWND_INIT, 0, NULL);
+ rwnd = tcp_call_bpf(sk, BPF_SOCK_OPS_RWND_INIT);
rwnd = bpf_tcp_ops_call_int(rwnd_init, rwnd, sk);
if (rwnd < 0)
rwnd = 0;
@@ -3134,14 +3163,13 @@ static inline u32 tcp_rwnd_init_bpf(struct sock *sk)
static inline bool tcp_bpf_ca_needs_ecn(struct sock *sk)
{
- return (tcp_call_bpf(sk, BPF_SOCK_OPS_NEEDS_ECN, 0, NULL) == 1);
+ return (tcp_call_bpf(sk, BPF_SOCK_OPS_NEEDS_ECN) == 1);
}
static inline void tcp_bpf_rtt(struct sock *sk, long mrtt, u32 srtt)
{
- if (BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk), BPF_SOCK_OPS_RTT_CB_FLAG))
- tcp_call_bpf_2arg(sk, BPF_SOCK_OPS_RTT_CB, mrtt, srtt);
- bpf_tcp_ops_call(rtt, sk, mrtt, srtt);
+ tcp_call_bpf_flag(sk, BPF_SOCK_OPS_RTT_CB, mrtt, srtt);
+ bpf_tcp_ops_call_flag(rtt, RTT, sk, mrtt, srtt);
}
#if IS_ENABLED(CONFIG_SMC)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index e0ed44b1bbcb7..6f70db7515dd4 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -7340,6 +7340,31 @@ enum {
*/
};
+/*
+ * Most callbacks of struct bpf_tcp_ops are placed in the slow
+ * path (e.g., one-shot connection setup or unlikely events like
+ * timers) and are invoked simply by defining non-NULL callbacks.
+ *
+ * Callbacks in the fast path, however, would incur noticeable
+ * overhead even when set to NULL, so they are disabled by default
+ * and must be explicitly enabled per socket via bpf_tcp_ops_set_flags().
+ *
+ * The flags are per-socket and shared by all effective bpf_tcp_ops
+ * programs.
+ */
+enum {
+ /* .rtt() */
+ BPF_TCP_OPS_FLAG_RTT = (1 << 0),
+ /* .parse_hdr() */
+ BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_ALL = (1 << 1),
+ BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_UNKNOWN = (1 << 2),
+ /* .hdr_opt_len() and .write_hdr_opt() */
+ BPF_TCP_OPS_FLAG_WRITE_HDR_OPT = (1 << 3),
+ /* .enqueue_rcvq() and .dequeue_rcvq() */
+ BPF_TCP_OPS_FLAG_RCVQ = (1 << 4),
+ BPF_TCP_OPS_FLAG_ALL = (1 << 5) - 1,
+};
+
/* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
* changes between the TCP and BPF versions. Ideally this should never happen.
* If it does, we need to add code to convert them before calling
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index cdcfc7d3c6d2e..035c83338e0f1 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -226,7 +226,7 @@ int __inet_listen_sk(struct sock *sk, int backlog)
if (err)
return err;
- tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_LISTEN_CB, 0, NULL);
+ tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_LISTEN_CB);
bpf_tcp_ops_call(listen, sk);
}
return 0;
diff --git a/net/ipv4/bpf_tcp_ops.c b/net/ipv4/bpf_tcp_ops.c
index 681fed6429999..2ba73dd6c52cc 100644
--- a/net/ipv4/bpf_tcp_ops.c
+++ b/net/ipv4/bpf_tcp_ops.c
@@ -76,6 +76,14 @@ static void write_hdr_opt_stub(struct sock *sk, struct sk_buff *skb,
{
}
+static void enqueue_rcvq_stub(struct sock *sk, struct sk_buff *skb)
+{
+}
+
+static void dequeue_rcvq_stub(struct sock *sk)
+{
+}
+
static struct bpf_tcp_ops __bpf_tcp_ops = {
.timeout_init = timeout_init_stub,
.rwnd_init = rwnd_init_stub,
@@ -90,6 +98,8 @@ static struct bpf_tcp_ops __bpf_tcp_ops = {
.parse_hdr = parse_hdr_stub,
.hdr_opt_len = hdr_opt_len_stub,
.write_hdr_opt = write_hdr_opt_stub,
+ .enqueue_rcvq = enqueue_rcvq_stub,
+ .dequeue_rcvq = dequeue_rcvq_stub,
};
BPF_CALL_4(bpf_tcp_ops_store_hdr_opt, void *, ctx, const void *, from,
@@ -210,6 +220,24 @@ const struct bpf_func_proto bpf_tcp_ops_get_retval_proto = {
.ret_type = RET_INTEGER,
};
+static bool is_sockopt_supported(u32 moff)
+{
+ switch (moff) {
+ case offsetof(struct bpf_tcp_ops, active_established):
+ case offsetof(struct bpf_tcp_ops, passive_established):
+ case offsetof(struct bpf_tcp_ops, rto):
+ case offsetof(struct bpf_tcp_ops, rtt):
+ case offsetof(struct bpf_tcp_ops, set_state):
+ case offsetof(struct bpf_tcp_ops, retrans):
+ case offsetof(struct bpf_tcp_ops, connect):
+ case offsetof(struct bpf_tcp_ops, listen):
+ case offsetof(struct bpf_tcp_ops, parse_hdr):
+ return true;
+ }
+
+ return false;
+}
+
static const struct bpf_func_proto *
get_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
{
@@ -221,22 +249,13 @@ get_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
case BPF_FUNC_sk_storage_delete:
return &bpf_sk_storage_delete_proto;
case BPF_FUNC_setsockopt:
- /* The sk may be an unlocked listener (synack path) or NULL
- * fullsock; disable for members that can run unlocked.
- */
- if (moff == offsetof(struct bpf_tcp_ops, rwnd_init) ||
- moff == offsetof(struct bpf_tcp_ops, timeout_init) ||
- moff == offsetof(struct bpf_tcp_ops, hdr_opt_len) ||
- moff == offsetof(struct bpf_tcp_ops, write_hdr_opt))
- return NULL;
- return &bpf_sk_setsockopt_proto;
+ if (is_sockopt_supported(moff))
+ return &bpf_sk_setsockopt_proto;
+ return NULL;
case BPF_FUNC_getsockopt:
- if (moff == offsetof(struct bpf_tcp_ops, rwnd_init) ||
- moff == offsetof(struct bpf_tcp_ops, timeout_init) ||
- moff == offsetof(struct bpf_tcp_ops, hdr_opt_len) ||
- moff == offsetof(struct bpf_tcp_ops, write_hdr_opt))
- return NULL;
- return &bpf_sk_getsockopt_proto;
+ if (is_sockopt_supported(moff))
+ return &bpf_sk_getsockopt_proto;
+ return NULL;
case BPF_FUNC_get_retval:
if (moff == offsetof(struct bpf_tcp_ops, timeout_init) ||
moff == offsetof(struct bpf_tcp_ops, rwnd_init))
@@ -319,8 +338,116 @@ static struct bpf_struct_ops bpf_tcp_ops = {
.owner = THIS_MODULE,
};
+__bpf_kfunc_start_defs();
+
+__bpf_kfunc int bpf_tcp_ops_set_flags(struct tcp_sock *tp, u32 enable, u32 disable)
+{
+ u32 old, new;
+
+ if ((enable & disable) || (enable | disable) & ~BPF_TCP_OPS_FLAG_ALL)
+ return -EINVAL;
+
+ if (sk_is_mptcp((struct sock *)tp) && (enable & BPF_TCP_OPS_FLAG_RCVQ))
+ return -EOPNOTSUPP;
+
+ old = READ_ONCE(tp->bpf_tcp_ops_flags);
+
+ do {
+ new = (old | enable) & ~disable;
+ if (new == old)
+ break;
+ } while (!try_cmpxchg(&tp->bpf_tcp_ops_flags, &old, new));
+
+ return 0;
+}
+
+__bpf_kfunc int bpf_tcp_ops_set_rcvlowat(struct sock *sk, int rcvlowat,
+ const struct bpf_prog_aux *aux)
+{
+ u32 moff = aux->attach_st_ops_member_off;
+ bool wakeup = false;
+
+ if (moff == offsetof(struct bpf_tcp_ops, dequeue_rcvq))
+ wakeup = true;
+
+ if (rcvlowat < 0)
+ rcvlowat = INT_MAX;
+
+ return __tcp_set_rcvlowat(sk, rcvlowat, wakeup);
+}
+
+__bpf_kfunc_end_defs();
+
+BTF_KFUNCS_START(bpf_tcp_ops_set_flags_kfunc_set)
+BTF_ID_FLAGS(func, bpf_tcp_ops_set_flags)
+BTF_KFUNCS_END(bpf_tcp_ops_set_flags_kfunc_set)
+
+BTF_KFUNCS_START(bpf_tcp_ops_set_rcvlowat_kfunc_set)
+BTF_ID_FLAGS(func, bpf_tcp_ops_set_rcvlowat, KF_IMPLICIT_ARGS)
+BTF_KFUNCS_END(bpf_tcp_ops_set_rcvlowat_kfunc_set)
+
+static int bpf_tcp_ops_set_flags_kfunc_filter(const struct bpf_prog *prog,
+ u32 kfunc_id)
+{
+ if (!btf_id_set8_contains(&bpf_tcp_ops_set_flags_kfunc_set, kfunc_id))
+ return 0;
+
+ if (prog->type == BPF_PROG_TYPE_STRUCT_OPS &&
+ prog->aux->st_ops == &bpf_tcp_ops)
+ return 0;
+
+ if (prog->type == BPF_PROG_TYPE_CGROUP_SOCKOPT ||
+ prog->type == BPF_PROG_TYPE_CGROUP_SKB)
+ return 0;
+
+ return -EACCES;
+}
+
+static const struct btf_kfunc_id_set bpf_tcp_ops_set_flags_kfunc_id_set = {
+ .owner = THIS_MODULE,
+ .set = &bpf_tcp_ops_set_flags_kfunc_set,
+ .filter = bpf_tcp_ops_set_flags_kfunc_filter,
+};
+
+static int bpf_tcp_ops_set_rcvlowat_kfunc_filter(const struct bpf_prog *prog,
+ u32 kfunc_id)
+{
+ u32 moff;
+
+ if (!btf_id_set8_contains(&bpf_tcp_ops_set_rcvlowat_kfunc_set, kfunc_id))
+ return 0;
+
+ if (prog->aux->st_ops != &bpf_tcp_ops)
+ return -EACCES;
+
+ moff = prog->aux->attach_st_ops_member_off;
+ if (moff != offsetof(struct bpf_tcp_ops, enqueue_rcvq) &&
+ moff != offsetof(struct bpf_tcp_ops, dequeue_rcvq))
+ return -EACCES;
+
+ return 0;
+}
+
+static const struct btf_kfunc_id_set bpf_tcp_ops_set_rcvlowat_kfunc_id_set = {
+ .owner = THIS_MODULE,
+ .set = &bpf_tcp_ops_set_rcvlowat_kfunc_set,
+ .filter = bpf_tcp_ops_set_rcvlowat_kfunc_filter,
+};
+
static int __init __bpf_tcp_ops_init(void)
{
- return register_bpf_struct_ops(&bpf_tcp_ops, bpf_tcp_ops);
+ int ret;
+
+ ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
+ &bpf_tcp_ops_set_flags_kfunc_id_set);
+ /* BPF_PROG_TYPE_CGROUP_{SOCKOPT,SKB} share BTF_KFUNC_HOOK_CGROUP. */
+ ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCKOPT,
+ &bpf_tcp_ops_set_flags_kfunc_id_set);
+ ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
+ &bpf_tcp_ops_set_rcvlowat_kfunc_id_set);
+ ret = ret ?: register_bpf_struct_ops(&bpf_tcp_ops, bpf_tcp_ops);
+
+ return ret;
}
+
late_initcall(__bpf_tcp_ops_init);
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 650a2e89950af..c3c756a1ba8cf 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1609,6 +1609,8 @@ void tcp_cleanup_rbuf(struct sock *sk, int copied)
"cleanup rbuf bug: copied %X seq %X rcvnxt %X\n",
tp->copied_seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt);
__tcp_cleanup_rbuf(sk, copied);
+
+ bpf_tcp_ops_call_flag(dequeue_rcvq, RCVQ, sk);
}
static void tcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
@@ -1825,8 +1827,7 @@ int tcp_peek_len(struct socket *sock)
return tcp_inq(sock->sk);
}
-/* Make sure sk_rcvbuf is big enough to satisfy SO_RCVLOWAT hint */
-int tcp_set_rcvlowat(struct sock *sk, int val)
+int __tcp_set_rcvlowat(struct sock *sk, int val, bool wakeup)
{
struct tcp_sock *tp = tcp_sk(sk);
int space, cap;
@@ -1839,7 +1840,8 @@ int tcp_set_rcvlowat(struct sock *sk, int val)
WRITE_ONCE(sk->sk_rcvlowat, val ? : 1);
/* Check if we need to signal EPOLLIN right now */
- tcp_data_ready(sk);
+ if (wakeup)
+ tcp_data_ready(sk);
if (sk->sk_userlocks & SOCK_RCVBUF_LOCK)
return 0;
@@ -1854,6 +1856,12 @@ int tcp_set_rcvlowat(struct sock *sk, int val)
return 0;
}
+/* Make sure sk_rcvbuf is big enough to satisfy SO_RCVLOWAT hint */
+int tcp_set_rcvlowat(struct sock *sk, int val)
+{
+ return __tcp_set_rcvlowat(sk, val, true);
+}
+
void tcp_set_rcvbuf(struct sock *sk, int val)
{
tcp_set_window_clamp(sk, tcp_win_from_space(sk, val));
@@ -2994,8 +3002,7 @@ void tcp_set_state(struct sock *sk, int state)
*/
BTF_TYPE_EMIT_ENUM(BPF_TCP_ESTABLISHED);
- if (BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk), BPF_SOCK_OPS_STATE_CB_FLAG))
- tcp_call_bpf_2arg(sk, BPF_SOCK_OPS_STATE_CB, oldstate, state);
+ tcp_call_bpf_flag(sk, BPF_SOCK_OPS_STATE_CB, oldstate, state);
bpf_tcp_ops_call(set_state, sk, state);
switch (state) {
@@ -5217,6 +5224,9 @@ static void __init tcp_struct_check(void)
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_txrx, lost_out);
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_txrx, sacked_out);
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_txrx, scaling_ratio);
+#ifdef CONFIG_BPF
+ CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_txrx, bpf_tcp_ops_flags);
+#endif
/* RX read-mostly hotpath cache lines */
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_rx, copied_seq);
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index 471c78be55137..6dfe40322fb59 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -281,6 +281,8 @@ void tcp_fastopen_add_skb(struct sock *sk, struct sk_buff *skb)
TCP_SKB_CB(skb)->seq++;
TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_SYN;
+ bpf_tcp_ops_call_flag(enqueue_rcvq, RCVQ, sk, skb);
+
tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
tcp_add_receive_queue(sk, skb);
tp->syn_data_acked = 1;
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 209db8effcc41..46f5c4fafa8db 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -146,14 +146,16 @@ EXPORT_SYMBOL_GPL(clean_acked_data_flush);
#ifdef CONFIG_CGROUP_BPF
static void bpf_skops_parse_hdr(struct sock *sk, struct sk_buff *skb)
{
- bool unknown_opt = tcp_sk(sk)->rx_opt.saw_unknown &&
- BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
- BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG);
- bool parse_all_opt = BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
- BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG);
struct bpf_sock_ops_kern sock_ops;
+ const struct tcp_sock *tp;
- if (likely(!unknown_opt && !parse_all_opt))
+ if (!cgroup_bpf_enabled(CGROUP_SOCK_OPS))
+ return;
+
+ tp = tcp_sk(sk);
+ if (!(tp->rx_opt.saw_unknown &&
+ BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG)) &&
+ !BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG))
return;
/* The skb will be handled in the
@@ -176,7 +178,7 @@ static void bpf_skops_parse_hdr(struct sock *sk, struct sk_buff *skb)
sock_ops.sk = sk;
bpf_skops_init_skb(&sock_ops, skb, tcp_hdrlen(skb));
- BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops);
+ __BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops);
}
static void bpf_skops_established(struct sock *sk, int bpf_op,
@@ -184,6 +186,9 @@ static void bpf_skops_established(struct sock *sk, int bpf_op,
{
struct bpf_sock_ops_kern sock_ops;
+ if (!cgroup_bpf_enabled(CGROUP_SOCK_OPS))
+ return;
+
sock_owned_by_me(sk);
memset(&sock_ops, 0, offsetof(struct bpf_sock_ops_kern, temp));
@@ -195,7 +200,7 @@ static void bpf_skops_established(struct sock *sk, int bpf_op,
if (skb)
bpf_skops_init_skb(&sock_ops, skb, tcp_hdrlen(skb));
- BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops);
+ __BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops);
}
#else
static void bpf_skops_parse_hdr(struct sock *sk, struct sk_buff *skb)
@@ -210,6 +215,11 @@ static void bpf_skops_established(struct sock *sk, int bpf_op,
static void bpf_tcp_ops_parse_hdr(struct sock *sk, struct sk_buff *skb)
{
+ const struct tcp_sock *tp;
+
+ if (!cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS))
+ return;
+
switch (sk->sk_state) {
case TCP_SYN_RECV:
case TCP_SYN_SENT:
@@ -217,7 +227,12 @@ static void bpf_tcp_ops_parse_hdr(struct sock *sk, struct sk_buff *skb)
return;
}
- bpf_tcp_ops_call(parse_hdr, sk, skb);
+ tp = tcp_sk(sk);
+
+ if ((tp->rx_opt.saw_unknown &&
+ BPF_TCP_OPS_TEST_FLAG(tp, PARSE_HDR_OPT_UNKNOWN)) ||
+ BPF_TCP_OPS_TEST_FLAG(tp, PARSE_HDR_OPT_ALL))
+ __bpf_tcp_ops_call(parse_hdr, sk, skb);
}
static __cold void tcp_gro_dev_warn(const struct sock *sk, const struct sk_buff *skb,
@@ -5350,6 +5365,8 @@ static void tcp_ofo_queue(struct sock *sk)
continue;
}
+ bpf_tcp_ops_call_flag(enqueue_rcvq, RCVQ, sk, skb);
+
tail = skb_peek_tail(&sk->sk_receive_queue);
eaten = tail && tcp_try_coalesce(sk, tail, skb, &fragstolen);
tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq);
@@ -5553,6 +5570,8 @@ static int __must_check tcp_queue_rcv(struct sock *sk, struct sk_buff *skb,
int eaten;
struct sk_buff *tail = skb_peek_tail(&sk->sk_receive_queue);
+ bpf_tcp_ops_call_flag(enqueue_rcvq, RCVQ, sk, skb);
+
eaten = (tail &&
tcp_try_coalesce(sk, tail,
skb, fragstolen)) ? 1 : 0;
diff --git a/net/ipv4/tcp_nv.c b/net/ipv4/tcp_nv.c
index f345897a68dfc..7b0dae23d9aa2 100644
--- a/net/ipv4/tcp_nv.c
+++ b/net/ipv4/tcp_nv.c
@@ -146,7 +146,7 @@ static void tcpnv_init(struct sock *sk)
* within a datacenter, where we have reasonable estimates of
* RTTs
*/
- base_rtt = tcp_call_bpf(sk, BPF_SOCK_OPS_BASE_RTT, 0, NULL);
+ base_rtt = tcp_call_bpf(sk, BPF_SOCK_OPS_BASE_RTT);
if (base_rtt > 0) {
ca->nv_base_rtt = base_rtt;
ca->nv_lower_bound_rtt = (base_rtt * 205) >> 8; /* 80% */
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 3ac465513bf51..db4fd1825d999 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -476,8 +476,9 @@ static u32 bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
struct bpf_sock_ops_kern sock_ops;
int err;
- if (likely(!BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
- BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG)) ||
+ if (!cgroup_bpf_enabled(CGROUP_SOCK_OPS) ||
+ !BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
+ BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG)||
!remaining)
return remaining;
@@ -518,7 +519,7 @@ static u32 bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
if (skb)
bpf_skops_init_skb(&sock_ops, skb, 0);
- err = BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(&sock_ops, sk);
+ err = __BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(&sock_ops, sk);
if (err || sock_ops.remaining_opt_len == remaining)
return remaining;
@@ -543,7 +544,8 @@ static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,
first_opt_off = tcp_hdrlen(skb) - max_opt_len;
- if (BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
+ if (cgroup_bpf_enabled(CGROUP_SOCK_OPS) &&
+ BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG)) {
struct bpf_sock_ops_kern sock_ops;
int err;
@@ -567,7 +569,7 @@ static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,
sock_ops.remaining_opt_len = max_opt_len;
bpf_skops_init_skb(&sock_ops, skb, first_opt_off);
- err = BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(&sock_ops, sk);
+ err = __BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(&sock_ops, sk);
if (!err)
nr_written = max_opt_len - sock_ops.remaining_opt_len;
}
@@ -581,8 +583,8 @@ static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,
* writer's bytes). The writer finds the append point by scanning from
* first_opt_off + nr_written to the first NOP.
*/
- bpf_tcp_ops_call(write_hdr_opt, sk, skb, req, syn_skb, synack_type,
- first_opt_off + nr_written);
+ bpf_tcp_ops_call_flag(write_hdr_opt, WRITE_HDR_OPT, sk, skb, req,
+ syn_skb, synack_type, first_opt_off + nr_written);
}
#else
static u32 bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
@@ -613,11 +615,13 @@ static u32 bpf_tcp_ops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
{
unsigned int remaining_out = remaining, reserved;
- if (!remaining)
- return 0;
+ if (!cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS) ||
+ !BPF_TCP_OPS_TEST_FLAG(tcp_sk(sk), WRITE_HDR_OPT)||
+ !remaining)
+ return remaining;
/* bpf_tcp_ops_reserve_hdr_opt() reserves space via remaining_out */
- bpf_tcp_ops_call(hdr_opt_len, sk, skb, req, syn_skb, synack_type, &remaining_out);
+ __bpf_tcp_ops_call(hdr_opt_len, sk, skb, req, syn_skb, synack_type, &remaining_out);
reserved = remaining - remaining_out;
if (!reserved)
@@ -1193,8 +1197,9 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
struct tcp_key *key)
{
struct tcp_sock *tp = tcp_sk(sk);
- unsigned int size = 0;
unsigned int eff_sacks;
+ unsigned int remaining;
+ unsigned int size = 0;
opts->options = 0;
opts->bpf_opt_len = 0;
@@ -1224,10 +1229,10 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
* left.
*/
if (sk_is_mptcp(sk)) {
- unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
bool has_ts = opts->options & OPTION_TS;
int opt_size;
+ remaining = MAX_TCP_OPTION_SPACE - size;
opts->mptcp.drop_ts = 0;
opt_size = mptcp_established_options(sk, skb, remaining, has_ts,
@@ -1244,7 +1249,8 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
eff_sacks = tp->rx_opt.num_sacks + tp->rx_opt.dsack;
if (unlikely(eff_sacks)) {
- const unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
+ remaining = MAX_TCP_OPTION_SPACE - size;
+
if (likely(remaining >= TCPOLEN_SACK_BASE_ALIGNED +
TCPOLEN_SACK_PERBLOCK)) {
opts->num_sack_blocks =
@@ -1275,24 +1281,14 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
}
}
- if (unlikely(BPF_SOCK_OPS_TEST_FLAG(tp,
- BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG))) {
- unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
+ remaining = MAX_TCP_OPTION_SPACE - size;
- remaining = bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,
- remaining);
-
- size = MAX_TCP_OPTION_SPACE - remaining;
- }
-
- if (cgroup_bpf_enabled(CGROUP_TCP_SOCK_OPS)) {
- unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
-
- remaining = bpf_tcp_ops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,
- remaining);
+ remaining = bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,
+ remaining);
+ remaining = bpf_tcp_ops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,
+ remaining);
- size = MAX_TCP_OPTION_SPACE - remaining;
- }
+ size = MAX_TCP_OPTION_SPACE - remaining;
return size;
}
@@ -3725,9 +3721,8 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
err = tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC);
}
- if (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RETRANS_CB_FLAG))
- tcp_call_bpf_3arg(sk, BPF_SOCK_OPS_RETRANS_CB,
- TCP_SKB_CB(skb)->seq, segs, err);
+ tcp_call_bpf_flag(sk, BPF_SOCK_OPS_RETRANS_CB,
+ TCP_SKB_CB(skb)->seq, segs, err);
bpf_tcp_ops_call(retrans, sk, skb, err);
if (unlikely(err) && err != -EBUSY)
@@ -4355,7 +4350,7 @@ int tcp_connect(struct sock *sk)
struct sk_buff *buff;
int err;
- tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_CONNECT_CB, 0, NULL);
+ tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_CONNECT_CB);
bpf_tcp_ops_call(connect, sk);
#if defined(CONFIG_TCP_MD5SIG) && defined(CONFIG_TCP_AO)
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 3d49adc517663..00debcba122b1 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -286,10 +286,8 @@ static int tcp_write_timeout(struct sock *sk)
tcp_fastopen_active_detect_blackhole(sk, expired);
mptcp_active_detect_blackhole(sk, expired);
- if (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RTO_CB_FLAG))
- tcp_call_bpf_3arg(sk, BPF_SOCK_OPS_RTO_CB,
- icsk->icsk_retransmits,
- icsk->icsk_rto, (int)expired);
+ tcp_call_bpf_flag(sk, BPF_SOCK_OPS_RTO_CB,
+ icsk->icsk_retransmits, icsk->icsk_rto, (int)expired);
bpf_tcp_ops_call(rto, sk);
if (expired) {
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index e0ed44b1bbcb7..6f70db7515dd4 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -7340,6 +7340,31 @@ enum {
*/
};
+/*
+ * Most callbacks of struct bpf_tcp_ops are placed in the slow
+ * path (e.g., one-shot connection setup or unlikely events like
+ * timers) and are invoked simply by defining non-NULL callbacks.
+ *
+ * Callbacks in the fast path, however, would incur noticeable
+ * overhead even when set to NULL, so they are disabled by default
+ * and must be explicitly enabled per socket via bpf_tcp_ops_set_flags().
+ *
+ * The flags are per-socket and shared by all effective bpf_tcp_ops
+ * programs.
+ */
+enum {
+ /* .rtt() */
+ BPF_TCP_OPS_FLAG_RTT = (1 << 0),
+ /* .parse_hdr() */
+ BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_ALL = (1 << 1),
+ BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_UNKNOWN = (1 << 2),
+ /* .hdr_opt_len() and .write_hdr_opt() */
+ BPF_TCP_OPS_FLAG_WRITE_HDR_OPT = (1 << 3),
+ /* .enqueue_rcvq() and .dequeue_rcvq() */
+ BPF_TCP_OPS_FLAG_RCVQ = (1 << 4),
+ BPF_TCP_OPS_FLAG_ALL = (1 << 5) - 1,
+};
+
/* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
* changes between the TCP and BPF versions. Ideally this should never happen.
* If it does, we need to add code to convert them before calling
diff --git a/tools/testing/selftests/bpf/prog_tests/tcp_autolowat.c b/tools/testing/selftests/bpf/prog_tests/tcp_autolowat.c
new file mode 100644
index 0000000000000..337f9d34a39c5
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/tcp_autolowat.c
@@ -0,0 +1,350 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright 2026 Google LLC */
+#include <sys/epoll.h>
+
+#include "test_progs.h"
+#include "cgroup_helpers.h"
+#include "network_helpers.h"
+
+#include "tcp_autolowat.skel.h"
+
+#define SOL_BPF 0xdeadbeef
+#define BPF_TCP_AUTOLOWAT 0x8badf00d
+
+struct rpc_descriptor {
+ u32 header_len;
+ u32 payload_len;
+};
+
+enum rpc_event_type {
+ RPC_EVENT_END,
+ RPC_EVENT_AUTOLOWAT,
+ RPC_EVENT_SEND,
+ RPC_EVENT_RECV,
+ RPC_EVENT_EPOLL,
+ RPC_EVENT_RCVLOWAT,
+};
+
+struct rpc_event {
+ enum rpc_event_type type;
+ union {
+ int len;
+ int nfds;
+ int val;
+ int rcvlowat;
+ };
+};
+
+#define RPC_DESC_SIZE (sizeof(struct rpc_descriptor))
+
+static struct rpc_test_case {
+ char data[4096];
+ struct rpc_descriptor desc[32];
+ struct rpc_event event[32];
+} rpc_test_cases[] = {
+ {
+ .desc = {
+ { .header_len = 100, .payload_len = 150 },
+ },
+ .event = {
+ { .type = RPC_EVENT_AUTOLOWAT, .val = 1},
+ /* Single full RPC message in skb. */
+ { .type = RPC_EVENT_SEND, .len = RPC_DESC_SIZE + 100 + 150},
+ { .type = RPC_EVENT_EPOLL, .nfds = 1},
+ { .type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE + 100 + 150},
+ },
+ },
+ {
+ .desc = {
+ {.header_len = 100, .payload_len = 150},
+ {.header_len = 100, .payload_len = 150},
+ {.header_len = 100, .payload_len = 150},
+ },
+ .event = {
+ { .type = RPC_EVENT_AUTOLOWAT, .val = 1},
+ /* Two full RPC messages in skb. */
+ {.type = RPC_EVENT_SEND, .len = (RPC_DESC_SIZE + 100 + 150) * 2},
+ {.type = RPC_EVENT_EPOLL, .nfds = 1},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = (RPC_DESC_SIZE + 100 + 150) * 2},
+ /* Single full RPC message in skb. */
+ { .type = RPC_EVENT_SEND, .len = RPC_DESC_SIZE + 100 + 150},
+ { .type = RPC_EVENT_EPOLL, .nfds = 1},
+ { .type = RPC_EVENT_RCVLOWAT, .rcvlowat = (RPC_DESC_SIZE + 100 + 150) * 3},
+ },
+ },
+ {
+ .desc = {
+ {.header_len = 100, .payload_len = 150},
+ {.header_len = 100, .payload_len = 150},
+ {.header_len = 100, .payload_len = 150},
+ },
+ .event = {
+ { .type = RPC_EVENT_AUTOLOWAT, .val = 1},
+ /* Two full RPC messages in skb. */
+ {.type = RPC_EVENT_SEND, .len = (RPC_DESC_SIZE + 100 + 150) * 2},
+ {.type = RPC_EVENT_EPOLL, .nfds = 1},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = (RPC_DESC_SIZE + 100 + 150) * 2},
+ /* Only the next descriptor in skb. */
+ { .type = RPC_EVENT_SEND, .len = RPC_DESC_SIZE},
+ { .type = RPC_EVENT_EPOLL, .nfds = 1},
+ { .type = RPC_EVENT_RCVLOWAT, .rcvlowat = (RPC_DESC_SIZE + 100 + 150) * 2},
+ },
+ },
+ {
+ .desc = {
+ {.header_len = 100, .payload_len = 150},
+ {.header_len = 200, .payload_len = 500},
+ },
+ .event = {
+ { .type = RPC_EVENT_AUTOLOWAT, .val = 1},
+ /* The first descriptor is partial. */
+ {.type = RPC_EVENT_SEND, .len = 1},
+ {.type = RPC_EVENT_EPOLL, .nfds = 0},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE},
+ /* The first descriptor is available. */
+ {.type = RPC_EVENT_SEND, .len = RPC_DESC_SIZE - 1},
+ {.type = RPC_EVENT_EPOLL, .nfds = 0},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE + 150 + 100},
+ /* The first header is ready. */
+ {.type = RPC_EVENT_SEND, .len = 100},
+ {.type = RPC_EVENT_EPOLL, .nfds = 0},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE + 150 + 100},
+ /* skb has the first payload and 1 byte of the next descriptor. */
+ {.type = RPC_EVENT_SEND, .len = 150 + 1},
+ {.type = RPC_EVENT_EPOLL, .nfds = 1},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE + 150 + 100},
+ /* After reading the first RPC message, SO_RCVLOWAT should be RPC_DESC_SIZE. */
+ {.type = RPC_EVENT_RECV, .len = RPC_DESC_SIZE + 150 + 100},
+ {.type = RPC_EVENT_EPOLL, .nfds = 0},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE},
+ /* The second descriptor is available. */
+ {.type = RPC_EVENT_SEND, .len = RPC_DESC_SIZE - 1},
+ {.type = RPC_EVENT_EPOLL, .nfds = 0},
+ {.type = RPC_EVENT_RCVLOWAT, .rcvlowat = RPC_DESC_SIZE + 200 + 500},
+ },
+ },
+};
+
+struct tcp_autolowat_test_cb {
+ int saved_netns;
+ union {
+ int fd[4];
+ struct {
+ int server, client, child;
+ int epoll;
+ };
+ };
+};
+
+static void tcp_autolowat_teardown_cb(struct tcp_autolowat_test_cb *cb)
+{
+ int i, err;
+
+ for (i = 0; i < ARRAY_SIZE(cb->fd); i++) {
+ if (cb->fd[i] != -1)
+ close(cb->fd[i]);
+ }
+
+ if (cb->saved_netns != -1) {
+ err = setns(cb->saved_netns, CLONE_NEWNET);
+ ASSERT_OK(err, "restore netns");
+
+ close(cb->saved_netns);
+ }
+}
+
+static int tcp_autolowat_setup_cb(struct tcp_autolowat_test_cb *cb, int family)
+{
+ struct epoll_event ev = {};
+ int err;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(cb->fd); i++)
+ cb->fd[i] = -1;
+
+ cb->saved_netns = open("/proc/self/ns/net", O_RDONLY);
+ if (!ASSERT_OK_FD(cb->saved_netns, "save netns"))
+ goto err;
+
+ err = unshare(CLONE_NEWNET);
+ if (!ASSERT_OK(err, "unshare"))
+ goto err;
+
+ err = system("ip link set dev lo up");
+ if (!ASSERT_OK(err, "set up lo"))
+ goto err;
+
+ cb->server = start_server(family, SOCK_STREAM, NULL, 0, 0);
+ if (!ASSERT_OK_FD(cb->server, "start_server"))
+ goto err;
+
+ cb->client = connect_to_fd(cb->server, 0);
+ if (!ASSERT_OK_FD(cb->client, "connect_to_fd"))
+ goto err;
+
+ cb->child = accept(cb->server, NULL, NULL);
+ if (!ASSERT_OK_FD(cb->child, "accept"))
+ goto err;
+
+ cb->epoll = epoll_create1(0);
+ if (!ASSERT_OK_FD(cb->epoll, "epoll_create"))
+ goto err;
+
+ ev.events = EPOLLIN;
+ ev.data.fd = cb->child;
+
+ err = epoll_ctl(cb->epoll, EPOLL_CTL_ADD, cb->child, &ev);
+ if (!ASSERT_OK(err, "epoll_ctl"))
+ goto err;
+
+ return 0;
+
+err:
+ tcp_autolowat_teardown_cb(cb);
+ return -1;
+}
+
+static int tcp_autolowat_build_data(struct rpc_test_case *test_case)
+{
+ struct rpc_descriptor *desc = test_case->desc;
+ char *ptr = test_case->data;
+ int rpc_size;
+
+ memset(ptr, 0, sizeof(test_case->data));
+
+ while (desc->header_len + desc->payload_len) {
+ rpc_size = sizeof(*desc) + desc->header_len + desc->payload_len;
+
+ if (!ASSERT_LE(ptr + rpc_size - test_case->data,
+ sizeof(test_case->data), "data overflow"))
+ return 1;
+
+ memcpy(ptr, desc, sizeof(*desc));
+ ptr += rpc_size;
+ desc++;
+ }
+
+ if (!ASSERT_GT(ptr - test_case->data, 0, "no data"))
+ return 1;
+
+ return 0;
+}
+
+static void tcp_autolowat_run_rpc_test(struct tcp_autolowat_test_cb *cb,
+ struct rpc_test_case *test_case)
+{
+ struct rpc_event *event = test_case->event;
+ char *ptr = test_case->data;
+ struct epoll_event ev;
+ socklen_t optlen;
+ int err, optval;
+ char buf[4096];
+
+ if (tcp_autolowat_build_data(test_case))
+ return;
+
+ while (1) {
+ switch (event->type) {
+ case RPC_EVENT_END:
+ return;
+ case RPC_EVENT_AUTOLOWAT:
+ err = setsockopt(cb->child, SOL_BPF, BPF_TCP_AUTOLOWAT,
+ &event->val, sizeof(event->val));
+ if (!ASSERT_OK(err, "setsockopt"))
+ return;
+ break;
+ case RPC_EVENT_SEND:
+ err = send(cb->client, ptr, event->len, 0);
+ if (!ASSERT_EQ(err, event->len, "send"))
+ return;
+
+ ptr += event->len;
+ break;
+ case RPC_EVENT_RECV:
+ err = recv(cb->child, buf, event->len, 0);
+ if (!ASSERT_EQ(err, event->len, "recv"))
+ return;
+ break;
+ case RPC_EVENT_EPOLL:
+ err = epoll_wait(cb->epoll, &ev, 1, 100);
+ if (!ASSERT_EQ(err, event->nfds, "epoll_wait"))
+ return;
+ break;
+ case RPC_EVENT_RCVLOWAT:
+ optval = 0;
+ optlen = sizeof(optval);
+
+ err = getsockopt(cb->child, SOL_SOCKET, SO_RCVLOWAT, &optval, &optlen);
+ if (!ASSERT_OK(err, "getsockopt") ||
+ !ASSERT_EQ(optval, event->rcvlowat, "rcvlowat"))
+ return;
+ break;
+ }
+
+ event++;
+ }
+}
+
+static void tcp_autolowat_run_rpc_tests(struct tcp_autolowat *skel, int family)
+{
+ struct tcp_autolowat_test_cb cb;
+ int err;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(rpc_test_cases); i++) {
+ memset(skel->bss->test_name, 0, sizeof(skel->bss->test_name));
+
+ snprintf(skel->bss->test_name, sizeof(skel->bss->test_name),
+ "AF_INET%c rpc_test_cases[%d]",
+ family == AF_INET ? ' ' : '6', i);
+
+ if (!test__start_subtest(skel->bss->test_name))
+ continue;
+
+ err = tcp_autolowat_setup_cb(&cb, family);
+ if (err)
+ continue;
+
+ tcp_autolowat_run_rpc_test(&cb, &rpc_test_cases[i]);
+ tcp_autolowat_teardown_cb(&cb);
+ }
+}
+
+static void tcp_autolowat_run_tests(struct tcp_autolowat *skel)
+{
+ tcp_autolowat_run_rpc_tests(skel, AF_INET);
+ tcp_autolowat_run_rpc_tests(skel, AF_INET6);
+}
+
+void test_tcp_autolowat(void)
+{
+ struct tcp_autolowat *skel;
+ struct bpf_link *link[2];
+ int cgroup;
+
+ skel = tcp_autolowat__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "open_and_load"))
+ return;
+
+ cgroup = test__join_cgroup("/tcp_autolowat");
+ if (!ASSERT_GE(cgroup, 0, "join_cgroup"))
+ goto destroy_skel;
+
+ link[0] = bpf_map__attach_cgroup_opts(skel->maps.tcp_autolowat_ops, cgroup, NULL);
+ if (!ASSERT_OK_PTR(link[0], "attach_cgroup(tcp_autolowat_ops)"))
+ goto close_cgroup;
+
+ link[1] = bpf_program__attach_cgroup(skel->progs.tcp_autolowat_setsockopt, cgroup);
+ if (!ASSERT_OK_PTR(link[1], "attach_cgroup(SETSOCKOPT)"))
+ goto destroy_sockops;
+
+ tcp_autolowat_run_tests(skel);
+
+ bpf_link__destroy(link[1]);
+destroy_sockops:
+ bpf_link__destroy(link[0]);
+close_cgroup:
+ close(cgroup);
+destroy_skel:
+ tcp_autolowat__destroy(skel);
+}
diff --git a/tools/testing/selftests/bpf/progs/bpf_tcp_ops_hdr.c b/tools/testing/selftests/bpf/progs/bpf_tcp_ops_hdr.c
index f3e3dff13784c..706e94d794e46 100644
--- a/tools/testing/selftests/bpf/progs/bpf_tcp_ops_hdr.c
+++ b/tools/testing/selftests/bpf/progs/bpf_tcp_ops_hdr.c
@@ -18,6 +18,24 @@ int found_cnt;
__u8 found_d0;
__u8 found_d1;
+SEC("struct_ops")
+void BPF_PROG(test_listen, struct sock *sk)
+{
+ bpf_tcp_ops_set_flags((struct tcp_sock *)sk,
+ BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_ALL |
+ BPF_TCP_OPS_FLAG_WRITE_HDR_OPT,
+ 0);
+}
+
+SEC("struct_ops")
+void BPF_PROG(test_connect, struct sock *sk)
+{
+ bpf_tcp_ops_set_flags((struct tcp_sock *)sk,
+ BPF_TCP_OPS_FLAG_PARSE_HDR_OPT_UNKNOWN |
+ BPF_TCP_OPS_FLAG_WRITE_HDR_OPT,
+ 0);
+}
+
SEC("struct_ops")
void BPF_PROG(test_hdr_opt_len, struct sock *sk, struct sk_buff *skb,
struct request_sock *req, struct sk_buff *syn_skb,
@@ -78,6 +96,8 @@ void BPF_PROG(test_parse_hdr, struct sock *sk, struct sk_buff *skb)
SEC(".struct_ops.link")
struct bpf_tcp_ops test_hdr_ops = {
+ .listen = (void *)test_listen,
+ .connect = (void *)test_connect,
.hdr_opt_len = (void *)test_hdr_opt_len,
.write_hdr_opt = (void *)test_write_hdr_opt,
.parse_hdr = (void *)test_parse_hdr,
diff --git a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
index 593b38f904174..4c999d59cbbce 100644
--- a/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
+++ b/tools/testing/selftests/bpf/progs/bpf_tracing_net.h
@@ -79,6 +79,8 @@
#define NEXTHDR_TCP 6
+#define TCPHDR_FIN 0x01
+
#define TCPOPT_NOP 1
#define TCPOPT_EOL 0
#define TCPOPT_MSS 2
diff --git a/tools/testing/selftests/bpf/progs/tcp_autolowat.c b/tools/testing/selftests/bpf/progs/tcp_autolowat.c
new file mode 100644
index 0000000000000..8a55f3cee2609
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/tcp_autolowat.c
@@ -0,0 +1,294 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright 2026 Google LLC */
+#include "vmlinux.h"
+
+#include <string.h>
+#include <limits.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+#include <bpf/bpf_core_read.h>
+
+#include "bpf_tracing_net.h"
+
+#define SOL_BPF 0xdeadbeef
+#define BPF_TCP_AUTOLOWAT 0x8badf00d
+
+//#define DEBUG /* For verbose output. */
+
+struct rpc_descriptor {
+ u32 header_len;
+ u32 payload_len;
+};
+
+#define RPC_DESC_SIZE (sizeof(struct rpc_descriptor))
+#define MAX_RPC_DESC_PER_SKB 100
+
+struct tcp_autolowat_cb {
+ /* Don't put this field at the end; BPF verifier complains. */
+ char rpc_desc_buf[RPC_DESC_SIZE];
+ u32 rpc_desc_seq;
+ u32 rpc_end_seq;
+#ifdef DEBUG
+ u32 isn;
+#endif
+ u8 rpc_desc_buff_len;
+};
+
+struct {
+ __uint(type, BPF_MAP_TYPE_SK_STORAGE);
+ __uint(map_flags, BPF_F_NO_PREALLOC);
+ __type(key, int);
+ __type(value, struct tcp_autolowat_cb);
+} tcp_autolowat_map SEC(".maps");
+
+char test_name[64];
+
+#ifdef DEBUG
+#define LOG(str, ...) \
+ bpf_printk("%s: " str, test_name, ##__VA_ARGS__)
+#else
+#define LOG(...)
+#endif
+
+#define SEQ(val) \
+ (val - cb->isn)
+#define TP_SEQ(field) \
+ (tp->field - cb->isn)
+#define CB_SEQ(field) \
+ (cb->field - cb->isn)
+
+static int tcp_parse_descriptor(struct tcp_autolowat_cb *cb,
+ struct bpf_dynptr *dptr,
+ u32 seq, u32 end_seq)
+{
+ struct rpc_descriptor *rpc_desc;
+ u32 rpc_copied_seq;
+ u64 copy_len; /* u32 should work, but not for no_alu32 :/ */
+ u64 rpc_len;
+ int err;
+
+ rpc_copied_seq = cb->rpc_desc_seq + cb->rpc_desc_buff_len;
+
+ if (before(cb->rpc_desc_seq + RPC_DESC_SIZE, end_seq))
+ copy_len = RPC_DESC_SIZE - cb->rpc_desc_buff_len;
+ else
+ copy_len = end_seq - rpc_copied_seq;
+
+ if (copy_len == 0)
+ goto disable; /* FIN. */
+ if (copy_len > RPC_DESC_SIZE)
+ goto disable; /* always false, only for verifier. */
+ if (cb->rpc_desc_buff_len >= RPC_DESC_SIZE)
+ goto disable; /* always false, only for verifier. */
+
+ err = bpf_dynptr_read(cb->rpc_desc_buf + cb->rpc_desc_buff_len,
+ copy_len, dptr, rpc_copied_seq - seq, 0);
+ if (err)
+ goto disable;
+
+ cb->rpc_desc_buff_len += copy_len;
+
+ if (cb->rpc_desc_buff_len != RPC_DESC_SIZE) {
+ LOG("Copied %d bytes: rpc_desc_buff_len: %u", copy_len, cb->rpc_desc_buff_len);
+ goto partial;
+ }
+
+ rpc_desc = (struct rpc_descriptor *)cb->rpc_desc_buf;
+ rpc_len = RPC_DESC_SIZE + rpc_desc->header_len + rpc_desc->payload_len;
+
+ if (rpc_len > INT_MAX)
+ goto disable;
+
+ cb->rpc_end_seq = cb->rpc_desc_seq + rpc_len;
+
+ LOG("Copied full descriptor: rpc_desc_seq: %u, rpc_end_seq: %u, header_len: %u, payload_len: %u",
+ CB_SEQ(rpc_desc_seq), CB_SEQ(rpc_end_seq),
+ rpc_desc->header_len, rpc_desc->payload_len);
+
+ return 0;
+disable:
+ return -1;
+partial:
+ return 1;
+}
+
+static void tcp_set_autolowat(struct tcp_autolowat_cb *cb,
+ struct sock *sk)
+{
+ struct tcp_sock *tp = (struct tcp_sock *)sk;
+ u32 val; /* To handle wraparound. */
+
+ LOG("Setting rcvlowat: tp->copied_seq: %u, rpc_desc_seq: %u, rpc_end_seq: %u, rpc_desc_buff_len: %u",
+ TP_SEQ(copied_seq), CB_SEQ(rpc_desc_seq),
+ CB_SEQ(rpc_end_seq), cb->rpc_desc_buff_len);
+
+ if (before(tp->copied_seq, cb->rpc_desc_seq))
+ val = cb->rpc_desc_seq - tp->copied_seq;
+ else if (cb->rpc_desc_buff_len != RPC_DESC_SIZE)
+ val = RPC_DESC_SIZE;
+ else
+ val = cb->rpc_end_seq - tp->copied_seq;
+
+ if (val != tp->inet_conn.icsk_inet.sk.sk_rcvlowat) {
+ bpf_tcp_ops_set_rcvlowat(sk, val);
+
+ LOG("Set rcvlowat: expected: %u, actual: %d\n",
+ val, tp->inet_conn.icsk_inet.sk.sk_rcvlowat);
+ } else {
+ LOG("No need to set rcvlowat: %u\n", val);
+ }
+}
+
+static void tcp_disable_autolowat(struct sock *sk)
+{
+ bpf_tcp_ops_set_flags((struct tcp_sock *)sk, 0, BPF_TCP_OPS_FLAG_RCVQ);
+
+ bpf_tcp_ops_set_rcvlowat(sk, 1);
+
+ LOG("Disabled autolowat");
+}
+
+static void tcp_do_autolowat(struct tcp_autolowat_cb *cb,
+ struct sock *sk, struct sk_buff *skb)
+{
+ struct bpf_dynptr dptr;
+ struct tcp_skb_cb *tcb;
+ u32 seq, end_seq;
+ int ret = 0, i;
+
+ if (bpf_dynptr_from_skb((struct __sk_buff *)skb, 0, &dptr)) {
+ ret = -1;
+ goto update;
+ }
+
+ tcb = bpf_core_cast(skb->cb, struct tcp_skb_cb);
+ seq = tcb->seq;
+ end_seq = tcb->end_seq - !!(tcb->tcp_flags & TCPHDR_FIN);
+
+ LOG("Start parsing skb: seq: %u, end_seq: %u, len: %u, rpc_desc_seq: %u, rpc_end_seq: %u, rpc_buff_len: %u",
+ SEQ(seq), SEQ(end_seq), end_seq - seq,
+ CB_SEQ(rpc_desc_seq), CB_SEQ(rpc_end_seq), cb->rpc_desc_buff_len);
+
+ if (cb->rpc_desc_buff_len != RPC_DESC_SIZE) {
+ ret = tcp_parse_descriptor(cb, &dptr, seq, end_seq);
+ if (ret)
+ goto update;
+ }
+
+ i = 0;
+
+ while (1) {
+ if (i++ > MAX_RPC_DESC_PER_SKB) {
+ ret = -1;
+ break;
+ }
+
+ if (after(cb->rpc_end_seq, end_seq)) {
+ LOG("No more descriptor: rpc_end_seq: %u, end_seq: %u",
+ CB_SEQ(rpc_end_seq), SEQ(end_seq));
+ break;
+ }
+
+ cb->rpc_desc_seq = cb->rpc_end_seq;
+ cb->rpc_desc_buff_len = 0;
+
+ if (cb->rpc_end_seq == end_seq)
+ break;
+
+ LOG("Found next descriptor: rpc_end_seq: %u, end_seq: %u, len: %u",
+ CB_SEQ(rpc_end_seq), SEQ(end_seq), end_seq - cb->rpc_end_seq);
+
+ ret = tcp_parse_descriptor(cb, &dptr, seq, end_seq);
+ if (ret)
+ break;
+ }
+
+update:
+ if (ret >= 0)
+ tcp_set_autolowat(cb, sk);
+ else
+ tcp_disable_autolowat(sk);
+}
+
+SEC("struct_ops")
+void BPF_PROG(tcp_autolowat_enqueue_rcvq, struct sock *sk, struct sk_buff *skb)
+{
+ struct tcp_autolowat_cb *cb;
+
+ cb = bpf_sk_storage_get(&tcp_autolowat_map, sk, 0, 0);
+ if (!cb)
+ return;
+
+ tcp_do_autolowat(cb, sk, skb);
+}
+
+SEC("struct_ops")
+void BPF_PROG(tcp_autolowat_dequeue_rcvq, struct sock *sk)
+{
+ struct tcp_autolowat_cb *cb;
+
+ cb = bpf_sk_storage_get(&tcp_autolowat_map, sk, 0, 0);
+ if (!cb)
+ return;
+
+ tcp_set_autolowat(cb, sk);
+}
+
+SEC(".struct_ops.link")
+struct bpf_tcp_ops tcp_autolowat_ops = {
+ .enqueue_rcvq = (void *)tcp_autolowat_enqueue_rcvq,
+ .dequeue_rcvq = (void *)tcp_autolowat_dequeue_rcvq,
+};
+
+static int tcp_init_autolowat_cb(struct bpf_tcp_sock *btp)
+{
+ struct tcp_autolowat_cb *cb;
+ struct tcp_sock *tp;
+
+ cb = bpf_sk_storage_get(&tcp_autolowat_map, btp, 0,
+ BPF_SK_STORAGE_GET_F_CREATE);
+ if (!cb)
+ return -1;
+
+ tp = bpf_core_cast(btp, struct tcp_sock);
+
+ cb->rpc_desc_seq = tp->copied_seq;
+ cb->rpc_end_seq = tp->copied_seq;
+#ifdef DEBUG
+ cb->isn = tp->copied_seq;
+#endif
+
+ return bpf_tcp_ops_set_flags((struct tcp_sock *)btp,
+ BPF_TCP_OPS_FLAG_RCVQ, 0);
+}
+
+SEC("cgroup/setsockopt")
+int tcp_autolowat_setsockopt(struct bpf_sockopt *ctx)
+{
+ void *optval_end = ctx->optval_end;
+ int *optval = ctx->optval;
+ struct bpf_tcp_sock *btp;
+
+ if (ctx->level != SOL_BPF || ctx->optname != BPF_TCP_AUTOLOWAT)
+ goto out;
+
+ if (optval + 1 > optval_end)
+ return 0; /* -EPERM */
+
+ btp = bpf_tcp_sock(ctx->sk);
+ if (!btp)
+ goto out;
+
+ if (*optval && tcp_init_autolowat_cb(btp))
+ return 0; /* -EPERM */
+
+ /*
+ * BPF has consumed this option, don't call kernel
+ * setsockopt handler.
+ */
+ ctx->optlen = -1;
+out:
+ return 1;
+}
+
+char _license[] SEC("license") = "GPL";
|
| 43/3 | 2026/10/06 20:13 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26098 output: 22 thoughts: 1857 Thoughts: **KMSAN Analysis of TCP BPF Patch** Alright, let's dive into this patch and assess the KMSAN implications. My primary concern, given my experience, is identifying if the code introduces or exposes risks related to uninitialized memory. KMSAN, as we know, is our go-to tool when standard sanitizers like KASAN might miss subtle issues arising from uninitialized reads, especially in kernel-to-user space interactions. My focus is drawn to the criteria outlined in the KMSAN guidelines: kernel structures sent to user space, conditional logic based on potentially uninitialized data, allocations of complex structures, and anything that could lead to reading outside of allocated buffer boundaries. First, I'll scrutinize the code modifications carefully: * **Structure Examination:** The addition of `u32 bpf_tcp_ops_flags` to `struct tcp_sock` is the immediate focal point. I need to know how this flag is initialized across various socket creation paths: `sk_alloc`, `tcp_create_openreq_child`, and `tcp_init_sock`. My experience tells me that socket allocation frequently relies on `sk_alloc`, and this function should ensure zero-initialization. However, I must verify this explicitly to eliminate any doubt. A quick check of kernel sources is in order. * **Data Flows and Conditional Logic:** The refactoring of `tcp_call_bpf` and `tcp_call_bpf_flag`, alongside the introduction of `__bpf_tcp_ops_call` and `bpf_tcp_ops_call_flag`, warrants careful consideration. I have to assess whether these changes introduce any new conditional logic paths that might depend on uninitialized values. Specifically, the use of flags within the BPF framework requires rigorous analysis. Any path that checks a flag without guaranteeing its initialization is a red flag. * **User-Space Exposure:** The patch introduces BPF-related functions like `enqueue_rcvq` and `dequeue_rcvq`. I will pay particular attention to situations where these BPF functions might operate on kernel data potentially accessible by user space. A subtle uninitialized value here could lead to information leaks. * **Buffer Boundaries and Lengths:** Several functions, like `bpf_skops_hdr_opt_len` and `bpf_skops_write_hdr_opt`, are modified. I'll meticulously review any changes to length calculations, bounds checks, or header options to ensure they don't inadvertently allow access to uninitialized portions of buffers. To summarize, my analysis will be systematic, ensuring no stone is left unturned. I will verify how `tcp_sock` is initialized and will ensure zero-initialization and pay close attention to any paths that might utilize conditionally read flags before initialization. I must rigorously analyze any BPF functions, especially those interacting with user-space memory, to prevent information leaks. Finally, I will carefully scrutinize buffer manipulations to prevent any out-of-bounds reads. Based on this thorough review I will determine if `NeedsKMSAN=true`. |
| 44/3 | 2026/10/06 20:13 | tool | grepper |
0mArgs:{
"Expression": "bpf_tcp_ops_flags"
}Results: {
"Output": "Documentation/networking/net_cachelines/tcp_sock.rst=153=int linger2\nDocumentation/networking/net_cachelines/tcp_sock.rst:154:u32 bpf_tcp_ops_flags read_mostly read_mostly bpf_tcp_ops_hdr_opt_len,bpf_skops_write_hdr_opt(t...\nDocumentation/networking/net_cachelines/tcp_sock.rst-155-u8 bpf_sock_ops_cb_flags\n--\ninclude/linux/tcp.h=197=struct tcp_sock {\n--\ninclude/linux/tcp.h-236-#ifdef CONFIG_BPF\ninclude/linux/tcp.h:237:\tu32\tbpf_tcp_ops_flags;\ninclude/linux/tcp.h-238-#define BPF_TCP_OPS_TEST_FLAG(TP, ARG) \\\ninclude/linux/tcp.h:239:\t(READ_ONCE((TP)-\u003ebpf_tcp_ops_flags) \u0026 BPF_TCP_OPS_FLAG_ ## ARG)\ninclude/linux/tcp.h-240-#else\n--\ninclude/net/tcp.h=2938=static inline void tcp_clear_sock_ops_cb_flags(struct sock *sk)\n--\ninclude/net/tcp.h-2940-\ttcp_sk(sk)-\u003ebpf_sock_ops_cb_flags = 0;\ninclude/net/tcp.h:2941:\tWRITE_ONCE(tcp_sk(sk)-\u003ebpf_tcp_ops_flags, 0);\ninclude/net/tcp.h-2942-}\n--\nnet/ipv4/bpf_tcp_ops.c=343=__bpf_kfunc int bpf_tcp_ops_set_flags(struct tcp_sock *tp, u32 enable, u32 disable)\n--\nnet/ipv4/bpf_tcp_ops.c-352-\nnet/ipv4/bpf_tcp_ops.c:353:\told = READ_ONCE(tp-\u003ebpf_tcp_ops_flags);\nnet/ipv4/bpf_tcp_ops.c-354-\n--\nnet/ipv4/bpf_tcp_ops.c-358-\t\t\tbreak;\nnet/ipv4/bpf_tcp_ops.c:359:\t} while (!try_cmpxchg(\u0026tp-\u003ebpf_tcp_ops_flags, \u0026old, new));\nnet/ipv4/bpf_tcp_ops.c-360-\n--\nnet/ipv4/tcp.c=5205=static void __init tcp_struct_check(void)\n--\nnet/ipv4/tcp.c-5227-#ifdef CONFIG_BPF\nnet/ipv4/tcp.c:5228:\tCACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_read_txrx, bpf_tcp_ops_flags);\nnet/ipv4/tcp.c-5229-#endif\n"
} |
| 45/3 | 2026/10/06 20:13 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29380 output: 24 thoughts: 22 Thoughts: Here's my thought process, as if I were considering this myself: **Tracing TCP Socket Initialization** Okay, so I need to understand how these `tcp_sock` fields are being set up. Seems like the logical starting point is the `tcp_init_sock` function, or at least wherever the core initialization happens. I need to trace this back. There's a lot of potential complexity here, but I have a feeling `tcp_init_sock` will be the key initial function. I'll probably have to dig through a few layers of abstraction to get the full picture, but it should be a pretty straightforward process. I need to nail down exactly *where* and *how* these critical `tcp_sock` members are getting their initial values. From there, I can get a good handle on subsequent manipulation within the system. Let's start digging! |
| 46/3 | 2026/10/06 20:14 | tool | grepper |
0mArgs:{
"Expression": "bpf_sock_ops_cb_flags"
}Results: {
"Output": "Documentation/networking/net_cachelines/tcp_sock.rst=154=u32 bpf_tcp_ops_flags read_mostly read_mostly bpf_tcp_ops_hdr_opt_len,bpf_skops_write_hdr_opt(t...\nDocumentation/networking/net_cachelines/tcp_sock.rst:155:u8 bpf_sock_ops_cb_flags\nDocumentation/networking/net_cachelines/tcp_sock.rst-156-u8:1 bpf_chg_cc_inprogress\n--\ninclude/linux/tcp.h=197=struct tcp_sock {\n--\ninclude/linux/tcp.h-484-#ifdef CONFIG_BPF\ninclude/linux/tcp.h:485:\tu8\tbpf_sock_ops_cb_flags; /* Control calling BPF programs\ninclude/linux/tcp.h-486-\t\t\t\t\t * values defined in uapi/linux/tcp.h\n--\ninclude/linux/tcp.h-493-\t\t\t\t\t */\ninclude/linux/tcp.h:494:#define BPF_SOCK_OPS_TEST_FLAG(TP, ARG) (TP-\u003ebpf_sock_ops_cb_flags \u0026 ARG)\ninclude/linux/tcp.h-495-#else\n--\ninclude/net/tcp.h=2938=static inline void tcp_clear_sock_ops_cb_flags(struct sock *sk)\ninclude/net/tcp.h-2939-{\ninclude/net/tcp.h:2940:\ttcp_sk(sk)-\u003ebpf_sock_ops_cb_flags = 0;\ninclude/net/tcp.h-2941-\tWRITE_ONCE(tcp_sk(sk)-\u003ebpf_tcp_ops_flags, 0);\n--\ninclude/uapi/linux/bpf.h=1566=union bpf_attr {\n--\ninclude/uapi/linux/bpf.h-3311- *\ninclude/uapi/linux/bpf.h:3312: * long bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *bpf_sock, int argval)\ninclude/uapi/linux/bpf.h-3313- * \tDescription\ninclude/uapi/linux/bpf.h:3314: * \t\tAttempt to set the value of the **bpf_sock_ops_cb_flags** field\ninclude/uapi/linux/bpf.h-3315- * \t\tfor the full TCP socket associated to *bpf_sock_ops* to\n--\ninclude/uapi/linux/bpf.h-3338- *\ninclude/uapi/linux/bpf.h:3339: * \t\t**bpf_sock_ops_cb_flags_set(bpf_sock,**\ninclude/uapi/linux/bpf.h:3340: * \t\t\t**bpf_sock-\u003ebpf_sock_ops_cb_flags \u0026 ~BPF_SOCK_OPS_RTO_CB_FLAG)**\ninclude/uapi/linux/bpf.h-3341- *\n--\ninclude/uapi/linux/bpf.h=7070=struct bpf_sock_ops {\n--\ninclude/uapi/linux/bpf.h-7089-\t__u32 srtt_us;\t\t/* Averaged RTT \u003c\u003c 3 in usecs */\ninclude/uapi/linux/bpf.h:7090:\t__u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */\ninclude/uapi/linux/bpf.h-7091-\t__u32 state;\n--\ninclude/uapi/linux/bpf.h-7146-\ninclude/uapi/linux/bpf.h:7147:/* Definitions for bpf_sock_ops_cb_flags */\ninclude/uapi/linux/bpf.h-7148-enum {\n--\nnet/core/filter.c=5516=static int bpf_sol_tcp_getsockopt(struct sock *sk, int optname,\n--\nnet/core/filter.c-5523-\tcase TCP_BPF_SOCK_OPS_CB_FLAGS: {\nnet/core/filter.c:5524:\t\tint cb_flags = tcp_sk(sk)-\u003ebpf_sock_ops_cb_flags;\nnet/core/filter.c-5525-\n--\nnet/core/filter.c=5548=static int bpf_sol_tcp_setsockopt(struct sock *sk, int optname,\n--\nnet/core/filter.c-5589-\t\t\treturn -EINVAL;\nnet/core/filter.c:5590:\t\ttp-\u003ebpf_sock_ops_cb_flags = val;\nnet/core/filter.c-5591-\t\tbreak;\n--\nnet/core/filter.c=6166=static const struct bpf_func_proto bpf_sock_ops_getsockopt_proto = {\n--\nnet/core/filter.c-6176-\nnet/core/filter.c:6177:BPF_CALL_2(bpf_sock_ops_cb_flags_set, struct bpf_sock_ops_kern *, bpf_sock,\nnet/core/filter.c-6178-\t int, argval)\n--\nnet/core/filter.c-6188-\nnet/core/filter.c:6189:\ttcp_sk(sk)-\u003ebpf_sock_ops_cb_flags = val;\nnet/core/filter.c-6190-\n--\nnet/core/filter.c-6193-\nnet/core/filter.c:6194:static const struct bpf_func_proto bpf_sock_ops_cb_flags_set_proto = {\nnet/core/filter.c:6195:\t.func\t\t= bpf_sock_ops_cb_flags_set,\nnet/core/filter.c-6196-\t.gpl_only\t= false,\n--\nnet/core/filter.c=8845=sock_ops_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)\n--\nnet/core/filter.c-8858-\tcase BPF_FUNC_sock_ops_cb_flags_set:\nnet/core/filter.c:8859:\t\treturn \u0026bpf_sock_ops_cb_flags_set_proto;\nnet/core/filter.c-8860-\tcase BPF_FUNC_sock_map_update:\n--\nnet/core/filter.c=10830=static u32 sock_ops_convert_ctx_access(enum bpf_access_type type,\n--\nnet/core/filter.c-11124-\nnet/core/filter.c:11125:\tcase offsetof(struct bpf_sock_ops, bpf_sock_ops_cb_flags):\nnet/core/filter.c:11126:\t\tSOCK_OPS_GET_FIELD(bpf_sock_ops_cb_flags, bpf_sock_ops_cb_flags,\nnet/core/filter.c-11127-\t\t\t\t struct tcp_sock);\n--\nsamples/bpf/tcp_dumpstats_kern.c=26=int _sockops(struct bpf_sock_ops *ctx)\n--\nsamples/bpf/tcp_dumpstats_kern.c-34-\tcase BPF_SOCK_OPS_TCP_CONNECT_CB:\nsamples/bpf/tcp_dumpstats_kern.c:35:\t\tbpf_sock_ops_cb_flags_set(ctx, BPF_SOCK_OPS_RTT_CB_FLAG);\nsamples/bpf/tcp_dumpstats_kern.c-36-\t\treturn 1;\n--\ntools/include/uapi/linux/bpf.h=1566=union bpf_attr {\n--\ntools/include/uapi/linux/bpf.h-3311- *\ntools/include/uapi/linux/bpf.h:3312: * long bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *bpf_sock, int argval)\ntools/include/uapi/linux/bpf.h-3313- * \tDescription\ntools/include/uapi/linux/bpf.h:3314: * \t\tAttempt to set the value of the **bpf_sock_ops_cb_flags** field\ntools/include/uapi/linux/bpf.h-3315- * \t\tfor the full TCP socket associated to *bpf_sock_ops* to\n--\ntools/include/uapi/linux/bpf.h-3338- *\ntools/include/uapi/linux/bpf.h:3339: * \t\t**bpf_sock_ops_cb_flags_set(bpf_sock,**\ntools/include/uapi/linux/bpf.h:3340: * \t\t\t**bpf_sock-\u003ebpf_sock_ops_cb_flags \u0026 ~BPF_SOCK_OPS_RTO_CB_FLAG)**\ntools/include/uapi/linux/bpf.h-3341- *\n--\ntools/include/uapi/linux/bpf.h=7070=struct bpf_sock_ops {\n--\ntools/include/uapi/linux/bpf.h-7089-\t__u32 srtt_us;\t\t/* Averaged RTT \u003c\u003c 3 in usecs */\ntools/include/uapi/linux/bpf.h:7090:\t__u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */\ntools/include/uapi/linux/bpf.h-7091-\t__u32 state;\n--\ntools/include/uapi/linux/bpf.h-7146-\ntools/include/uapi/linux/bpf.h:7147:/* Definitions for bpf_sock_ops_cb_flags */\ntools/include/uapi/linux/bpf.h-7148-enum {\n--\ntools/testing/selftests/bpf/prog_tests/setget_sockopt.c=157=static void test_nonstandard_opt(int family)\n--\ntools/testing/selftests/bpf/prog_tests/setget_sockopt.c-175-\t/* cgroup/getsockopt prog will intercept getsockopt() below and\ntools/testing/selftests/bpf/prog_tests/setget_sockopt.c:176:\t * retrieve the tcp socket bpf_sock_ops_cb_flags value for the\ntools/testing/selftests/bpf/prog_tests/setget_sockopt.c-177-\t * accept()ed socket; this was set earlier in the passive established\n--\ntools/testing/selftests/bpf/progs/net_timestamping.c=88=static bool bpf_test_access_cb_flags_set(struct bpf_sock_ops *skops)\n--\ntools/testing/selftests/bpf/progs/net_timestamping.c-91-\ntools/testing/selftests/bpf/progs/net_timestamping.c:92:\tret = bpf_sock_ops_cb_flags_set(skops, 0);\ntools/testing/selftests/bpf/progs/net_timestamping.c-93-\tif (ret != -EOPNOTSUPP)\n--\ntools/testing/selftests/bpf/progs/setget_sockopt.c=375=int _getsockopt(struct bpf_sockopt *ctx)\n--\ntools/testing/selftests/bpf/progs/setget_sockopt.c-385-\tif (ctx-\u003eoptval + sizeof(int) \u003c= ctx-\u003eoptval_end) {\ntools/testing/selftests/bpf/progs/setget_sockopt.c:386:\t\t*optval = tp-\u003ebpf_sock_ops_cb_flags;\ntools/testing/selftests/bpf/progs/setget_sockopt.c-387-\t\tctx-\u003eretval = 0;\n--\ntools/testing/selftests/bpf/progs/setget_sockopt.c=411=int skops_sockopt(struct bpf_sock_ops *skops)\n--\ntools/testing/selftests/bpf/progs/setget_sockopt.c-446-\t\t\t\ttest_tcp_saved_syn(skops, sk));\ntools/testing/selftests/bpf/progs/setget_sockopt.c:447:\t\tflags = skops-\u003ebpf_sock_ops_cb_flags | BPF_SOCK_OPS_STATE_CB_FLAG;\ntools/testing/selftests/bpf/progs/setget_sockopt.c-448-\t\tbpf_setsockopt(skops, SOL_TCP, TCP_BPF_SOCK_OPS_CB_FLAGS, \u0026flags, sizeof(flags));\n--\ntools/testing/selftests/bpf/progs/tcp_rtt.c=26=int _sockops(struct bpf_sock_ops *ctx)\n--\ntools/testing/selftests/bpf/progs/tcp_rtt.c-42-\tif (op == BPF_SOCK_OPS_TCP_CONNECT_CB) {\ntools/testing/selftests/bpf/progs/tcp_rtt.c:43:\t\tbpf_sock_ops_cb_flags_set(ctx, BPF_SOCK_OPS_RTT_CB_FLAG);\ntools/testing/selftests/bpf/progs/tcp_rtt.c-44-\t\treturn 1;\n--\ntools/testing/selftests/bpf/progs/test_misc_tcp_hdr_options.c=284=static int handle_passive_estab(struct bpf_sock_ops *skops)\n--\ntools/testing/selftests/bpf/progs/test_misc_tcp_hdr_options.c-288-\t/* No more write hdr cb */\ntools/testing/selftests/bpf/progs/test_misc_tcp_hdr_options.c:289:\tbpf_sock_ops_cb_flags_set(skops,\ntools/testing/selftests/bpf/progs/test_misc_tcp_hdr_options.c:290:\t\t\t\t skops-\u003ebpf_sock_ops_cb_flags \u0026\ntools/testing/selftests/bpf/progs/test_misc_tcp_hdr_options.c-291-\t\t\t\t ~BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG);\n--\ntools/testing/selftests/bpf/progs/test_tcp_hdr_options.c=462=static int handle_passive_estab(struct bpf_sock_ops *skops)\n--\ntools/testing/selftests/bpf/progs/test_tcp_hdr_options.c-467-\ntools/testing/selftests/bpf/progs/test_tcp_hdr_options.c:468:\tinherit_cb_flags = skops-\u003ebpf_sock_ops_cb_flags;\ntools/testing/selftests/bpf/progs/test_tcp_hdr_options.c-469-\n--\ntools/testing/selftests/bpf/progs/test_tcpbpf_kern.c=32=int bpf_testcb(struct bpf_sock_ops *skops)\n--\ntools/testing/selftests/bpf/progs/test_tcpbpf_kern.c-94-\t\t/* Test failure to set largest cb flag (assumes not defined) */\ntools/testing/selftests/bpf/progs/test_tcpbpf_kern.c:95:\t\tglobal.bad_cb_test_rv = bpf_sock_ops_cb_flags_set(skops, 0x80);\ntools/testing/selftests/bpf/progs/test_tcpbpf_kern.c-96-\t\t/* Set callback */\ntools/testing/selftests/bpf/progs/test_tcpbpf_kern.c:97:\t\tglobal.good_cb_test_rv = bpf_sock_ops_cb_flags_set(skops,\ntools/testing/selftests/bpf/progs/test_tcpbpf_kern.c-98-\t\t\t\t\t\t BPF_SOCK_OPS_STATE_CB_FLAG);\n--\ntools/testing/selftests/bpf/progs/test_tcpbpf_kern.c-141-\tcase BPF_SOCK_OPS_TCP_LISTEN_CB:\ntools/testing/selftests/bpf/progs/test_tcpbpf_kern.c:142:\t\tbpf_sock_ops_cb_flags_set(skops, BPF_SOCK_OPS_STATE_CB_FLAG);\ntools/testing/selftests/bpf/progs/test_tcpbpf_kern.c-143-\t\tv = bpf_setsockopt(skops, IPPROTO_TCP, TCP_SAVE_SYN,\n--\ntools/testing/selftests/bpf/progs/test_tcpnotify_kern.c=31=int bpf_testcb(struct bpf_sock_ops *skops)\n--\ntools/testing/selftests/bpf/progs/test_tcpnotify_kern.c-55-\tcase BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB:\ntools/testing/selftests/bpf/progs/test_tcpnotify_kern.c:56:\t\tbpf_sock_ops_cb_flags_set(skops, (BPF_SOCK_OPS_RETRANS_CB_FLAG|\ntools/testing/selftests/bpf/progs/test_tcpnotify_kern.c-57-\t\t\t\t\t BPF_SOCK_OPS_RTO_CB_FLAG));\n--\ntools/testing/selftests/bpf/test_tcp_hdr_options.h=106=static inline void clear_hdr_cb_flags(struct bpf_sock_ops *skops)\ntools/testing/selftests/bpf/test_tcp_hdr_options.h-107-{\ntools/testing/selftests/bpf/test_tcp_hdr_options.h:108:\tbpf_sock_ops_cb_flags_set(skops,\ntools/testing/selftests/bpf/test_tcp_hdr_options.h:109:\t\t\t\t skops-\u003ebpf_sock_ops_cb_flags \u0026\ntools/testing/selftests/bpf/test_tcp_hdr_options.h-110-\t\t\t\t ~(BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG |\n--\ntools/testing/selftests/bpf/test_tcp_hdr_options.h=114=static inline void set_hdr_cb_flags(struct bpf_sock_ops *skops, __u32 extra)\ntools/testing/selftests/bpf/test_tcp_hdr_options.h-115-{\ntools/testing/selftests/bpf/test_tcp_hdr_options.h:116:\tbpf_sock_ops_cb_flags_set(skops,\ntools/testing/selftests/bpf/test_tcp_hdr_options.h:117:\t\t\t\t skops-\u003ebpf_sock_ops_cb_flags |\ntools/testing/selftests/bpf/test_tcp_hdr_options.h-118-\t\t\t\t BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG |\n--\ntools/testing/selftests/bpf/test_tcp_hdr_options.h=123=clear_parse_all_hdr_cb_flags(struct bpf_sock_ops *skops)\ntools/testing/selftests/bpf/test_tcp_hdr_options.h-124-{\ntools/testing/selftests/bpf/test_tcp_hdr_options.h:125:\tbpf_sock_ops_cb_flags_set(skops,\ntools/testing/selftests/bpf/test_tcp_hdr_options.h:126:\t\t\t\t skops-\u003ebpf_sock_ops_cb_flags \u0026\ntools/testing/selftests/bpf/test_tcp_hdr_options.h-127-\t\t\t\t ~BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG);\n--\ntools/testing/selftests/bpf/test_tcp_hdr_options.h=131=set_parse_all_hdr_cb_flags(struct bpf_sock_ops *skops)\ntools/testing/selftests/bpf/test_tcp_hdr_options.h-132-{\ntools/testing/selftests/bpf/test_tcp_hdr_options.h:133:\tbpf_sock_ops_cb_flags_set(skops,\ntools/testing/selftests/bpf/test_tcp_hdr_options.h:134:\t\t\t\t skops-\u003ebpf_sock_ops_cb_flags |\ntools/testing/selftests/bpf/test_tcp_hdr_options.h-135-\t\t\t\t BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG);\n"
} |
| 47/3 | 2026/10/06 20:14 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34928 output: 19 thoughts: 11 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, presented in the first person: **Diving into `tcp_init_sock`** Alright, time to dig into `tcp_init_sock`. My initial thoughts are always about understanding the fundamental role this function plays. It's the starting point, the genesis of a TCP socket, so it has to set the stage properly. I expect to see the allocation of the necessary data structures – the `sock` itself, the `tcp_sock`, and potentially some ancillary structures depending on the specific kernel's implementation and the configured options. Immediately, I'm mentally checking for error handling. A core function like this *has* to gracefully handle allocation failures and invalid parameters. I'll be looking for well-defined error codes and, ideally, some sort of logging or debugging output. I'm hoping to see a solid foundation for tracing potential issues later down the line. I'm also curious about the initialization of the various fields within those structures. What defaults are being set? Are they sensible defaults that promote performance and security? Or are they overly generic, relying on subsequent configuration to achieve anything useful? I'm particularly interested in how things like congestion control algorithms, receive/send buffer sizes, and the initial state are handled. Are they set during `tcp_init_sock` or are those responsibilities left to other routines? The level of coupling here is telling. Beyond the basics, I'll be keeping an eye out for any subtle optimizations or potential pitfalls. Does it attempt to pre-allocate any resources that might be needed frequently? Does it consider the specific network stack configuration (e.g., MTU settings, routing information)? What assumptions are made about the underlying network hardware or virtual environment? Any of these subtle design choices can have far-reaching effects. The devil is in the details, after all. Finally, I’ll be paying close attention to any interaction with other kernel subsystems. Does `tcp_init_sock` involve any interactions with the memory management subsystem, the networking stack's lower layers, or potentially security modules? If so, I'll need to understand those dependencies thoroughly. Understanding these interactions is critical. |
| 48/3 | 2026/10/06 20:14 | tool | grepper |
0mArgs:{
"Expression": "tcp_init_sock"
}Results: {
"Output": "include/net/tcp.h=496=void tcp_close(struct sock *sk, long timeout);\ninclude/net/tcp.h:497:void tcp_init_sock(struct sock *sk);\ninclude/net/tcp.h-498-void tcp_init_transfer(struct sock *sk, int bpf_op, struct sk_buff *skb);\n--\nnet/ipv4/af_inet.c=1760=static __net_exit void ipv4_mib_exit_net(struct net *net)\n--\nnet/ipv4/af_inet.c-1768-#ifdef CONFIG_MPTCP\nnet/ipv4/af_inet.c:1769:\t/* allocated on demand, see mptcp_init_sock() */\nnet/ipv4/af_inet.c-1770-\tfree_percpu(net-\u003emib.mptcp_statistics);\n--\nnet/ipv4/tcp.c=402=void tcp_md5_destruct_sock(struct sock *sk)\n--\nnet/ipv4/tcp.c-419- */\nnet/ipv4/tcp.c:420:void tcp_init_sock(struct sock *sk)\nnet/ipv4/tcp.c-421-{\n--\nnet/ipv4/tcp_ipv4.c=2396=static int tcp_v4_init_sock(struct sock *sk)\n--\nnet/ipv4/tcp_ipv4.c-2399-\nnet/ipv4/tcp_ipv4.c:2400:\ttcp_init_sock(sk);\nnet/ipv4/tcp_ipv4.c-2401-\n--\nnet/ipv6/tcp_ipv6.c=2077=static int tcp_v6_init_sock(struct sock *sk)\n--\nnet/ipv6/tcp_ipv6.c-2080-\nnet/ipv6/tcp_ipv6.c:2081:\ttcp_init_sock(sk);\nnet/ipv6/tcp_ipv6.c-2082-\n--\nnet/mptcp/protocol.c=3123=static void mptcp_worker(struct work_struct *work)\n--\nnet/mptcp/protocol.c-3171-\nnet/mptcp/protocol.c:3172:static void __mptcp_init_sock(struct sock *sk)\nnet/mptcp/protocol.c-3173-{\n--\nnet/mptcp/protocol.c-3185-\nnet/mptcp/protocol.c:3186:\t/* msk does not go through tcp_init_sock(); seed RTO bounds. */\nnet/mptcp/protocol.c-3187-\ticsk-\u003eicsk_rto_min =\n--\nnet/mptcp/protocol.c=3215=static void mptcp_ca_reset(struct sock *sk)\n--\nnet/mptcp/protocol.c-3227-\nnet/mptcp/protocol.c:3228:static int mptcp_init_sock(struct sock *sk)\nnet/mptcp/protocol.c-3229-{\n--\nnet/mptcp/protocol.c-3232-\nnet/mptcp/protocol.c:3233:\t__mptcp_init_sock(sk);\nnet/mptcp/protocol.c-3234-\n--\nnet/mptcp/protocol.c-3249-\nnet/mptcp/protocol.c:3250:\t/* fetch the ca name; do it outside __mptcp_init_sock(), so that clone will\nnet/mptcp/protocol.c-3251-\t * propagate the correct value\n--\nnet/mptcp/protocol.c=3709=struct sock *mptcp_sk_clone_init(const struct sock *sk,\n--\nnet/mptcp/protocol.c-3726-\nnet/mptcp/protocol.c:3727:\t__mptcp_init_sock(nsk);\nnet/mptcp/protocol.c-3728-\n--\nnet/mptcp/protocol.c=4225=static struct proto mptcp_prot = {\n--\nnet/mptcp/protocol.c-4227-\t.owner\t\t= THIS_MODULE,\nnet/mptcp/protocol.c:4228:\t.init\t\t= mptcp_init_sock,\nnet/mptcp/protocol.c-4229-\t.connect\t= mptcp_connect,\n--\ntools/testing/selftests/bpf/prog_tests/sk_bypass_prot_mem.c=93=static long get_memory_allocated(struct test_case *test_case,\n--\ntools/testing/selftests/bpf/prog_tests/sk_bypass_prot_mem.c-100-\t/* AF_INET and AF_INET6 share the same memory_allocated.\ntools/testing/selftests/bpf/prog_tests/sk_bypass_prot_mem.c:101:\t * tcp_init_sock() is called by AF_INET and AF_INET6,\ntools/testing/selftests/bpf/prog_tests/sk_bypass_prot_mem.c-102-\t * but udp_lib_init_sock() is inline.\n--\ntools/testing/selftests/bpf/progs/sk_bypass_prot_mem.c=50=static void fentry_init_sock(struct sock *sk, bool *activated,\n--\ntools/testing/selftests/bpf/progs/sk_bypass_prot_mem.c-59-\ntools/testing/selftests/bpf/progs/sk_bypass_prot_mem.c:60:SEC(\"fentry/tcp_init_sock\")\ntools/testing/selftests/bpf/progs/sk_bypass_prot_mem.c:61:int BPF_PROG(fentry_tcp_init_sock, struct sock *sk)\ntools/testing/selftests/bpf/progs/sk_bypass_prot_mem.c-62-{\n"
} |
| 49/3 | 2026/10/06 20:14 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36957 output: 36 thoughts: 13 Thoughts: Okay, let's dive into this. Here's my take on those thoughts, as if they're my own: **Analyzing the TCP Socket Initialization** Right, let's get into the nitty-gritty. My immediate thought is to examine the `tcp_init_sock` implementation. I need to understand exactly how a TCP socket gets brought to life, initialized, and put into its initial state. What data structures are allocated and populated? What's the process for setting up the fundamental TCP control blocks? I want to see how the connection state variables are set initially - is it `CLOSED`, `LISTEN`, or something else? Understanding this initial state is crucial for following the connection lifecycle and diagnosing potential issues later on. Where are the initial sequence numbers chosen and how are they randomized? I'll probably start by tracing the function calls, checking for any subtle logic within that might affect performance or stability down the line. I'm looking for anything unusual or anything that violates my expectations of correct TCP behavior. Essentially, I'm trying to mentally reconstruct the initialization process from first principles. |
| 50/3 | 2026/10/06 20:14 | tool | read-file |
0mArgs:{
"File": "net/ipv4/tcp.c",
"FirstLine": 420,
"LineCount": 50
}Results: {
"Contents": " 420:\tvoid tcp_init_sock(struct sock *sk)\n 421:\t{\n 422:\t\tstruct inet_connection_sock *icsk = inet_csk(sk);\n 423:\t\tstruct tcp_sock *tp = tcp_sk(sk);\n 424:\t\tint rto_min_us, rto_max_ms;\n 425:\t\n 426:\t\ttp-\u003eout_of_order_queue = RB_ROOT;\n 427:\t\tsk-\u003etcp_rtx_queue = RB_ROOT;\n 428:\t\ttcp_init_xmit_timers(sk);\n 429:\t\tINIT_LIST_HEAD(\u0026tp-\u003etsq_node);\n 430:\t\tINIT_LIST_HEAD(\u0026tp-\u003etsorted_sent_queue);\n 431:\t\n 432:\t\ticsk-\u003eicsk_rto = TCP_TIMEOUT_INIT;\n 433:\t\n 434:\t\trto_max_ms = READ_ONCE(sock_net(sk)-\u003eipv4.sysctl_tcp_rto_max_ms);\n 435:\t\ticsk-\u003eicsk_rto_max = msecs_to_jiffies(rto_max_ms);\n 436:\t\n 437:\t\trto_min_us = READ_ONCE(sock_net(sk)-\u003eipv4.sysctl_tcp_rto_min_us);\n 438:\t\ticsk-\u003eicsk_rto_min = usecs_to_jiffies(rto_min_us);\n 439:\t\ticsk-\u003eicsk_delack_max = TCP_DELACK_MAX;\n 440:\t\ttp-\u003emdev_us = jiffies_to_usecs(TCP_TIMEOUT_INIT);\n 441:\t\tminmax_reset(\u0026tp-\u003ertt_min, tcp_jiffies32, ~0U);\n 442:\t\n 443:\t\t/* So many TCP implementations out there (incorrectly) count the\n 444:\t\t * initial SYN frame in their delayed-ACK and congestion control\n 445:\t\t * algorithms that we must have the following bandaid to talk\n 446:\t\t * efficiently to them. -DaveM\n 447:\t\t */\n 448:\t\ttcp_snd_cwnd_set(tp, TCP_INIT_CWND);\n 449:\t\n 450:\t\t/* There's a bubble in the pipe until at least the first ACK. */\n 451:\t\ttp-\u003eapp_limited = ~0U;\n 452:\t\ttp-\u003erate_app_limited = 1;\n 453:\t\n 454:\t\t/* See draft-stevens-tcpca-spec-01 for discussion of the\n 455:\t\t * initialization of these values.\n 456:\t\t */\n 457:\t\ttp-\u003esnd_ssthresh = TCP_INFINITE_SSTHRESH;\n 458:\t\ttp-\u003esnd_cwnd_clamp = ~0;\n 459:\t\ttp-\u003emss_cache = TCP_MSS_DEFAULT;\n 460:\t\n 461:\t\ttp-\u003ereordering = READ_ONCE(sock_net(sk)-\u003eipv4.sysctl_tcp_reordering);\n 462:\t\ttcp_assign_congestion_control(sk);\n 463:\t\n 464:\t\ttp-\u003etsoffset = 0;\n 465:\t\ttp-\u003erack.reo_wnd_steps = 1;\n 466:\t\n 467:\t\tsk-\u003esk_write_space = sk_stream_write_space;\n 468:\t\tsock_set_flag(sk, SOCK_USE_WRITE_QUEUE);\n 469:\t\n"
} |
| 51/3 | 2026/10/06 20:14 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38180 output: 33 thoughts: 51 Thoughts: Okay, here's my understanding, focusing on the core concept and using a first-person perspective as requested: **My Deep Dive into Socket Structure Initialization** Right, so I'm digging into `sk_alloc`, and the first thing that jumps out is that this function seems to be absolutely meticulous about initialization. From what I can gather, it's making sure that the entire socket structure is completely zeroed out. This is pretty standard practice, but it's always worth confirming the details. The critical aspect here is how this zeroing happens. It leverages `sk_prot_alloc`, which ultimately funnels the allocation through either `kmem_cache_alloc` (which will zero the allocated memory in the cache) or `kzalloc`. Both of these functions are geared towards providing a zero-initialized memory block. This zeroing ensures a clean slate, preventing any lingering data from previous allocations or other potential memory corruption issues. Let me quickly examine `sk_alloc` directly to make sure that's the behavior in this implementation. |
| 52/3 | 2026/10/06 20:14 | tool | grepper |
0mArgs:{
"Expression": "sk_prot_alloc",
"PathPrefixes": [
"net/core/sock.c"
]
}Results: {
"Output": "net/core/sock.c=2210=static void sock_copy(struct sock *nsk, const struct sock *osk)\n--\nnet/core/sock.c-2229-\t\t prot-\u003eobj_size - offsetof(struct sock, sk_dontcopy_end),\nnet/core/sock.c:2230:\t\t /* alloc is larger than struct, see sk_prot_alloc() */);\nnet/core/sock.c-2231-\n--\nnet/core/sock.c-2237-\nnet/core/sock.c:2238:static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority,\nnet/core/sock.c-2239-\t\tint family)\n--\nnet/core/sock.c=2303=struct sock *sk_alloc(struct net *net, int family, gfp_t priority,\n--\nnet/core/sock.c-2307-\nnet/core/sock.c:2308:\tsk = sk_prot_alloc(prot, priority | __GFP_ZERO, family);\nnet/core/sock.c-2309-\tif (sk) {\n--\nnet/core/sock.c=2480=struct sock *sk_clone(const struct sock *sk, const gfp_t priority,\n--\nnet/core/sock.c-2487-\nnet/core/sock.c:2488:\tnewsk = sk_prot_alloc(prot, priority, sk-\u003esk_family);\nnet/core/sock.c-2489-\tif (!newsk)\n"
} |
| 53/3 | 2026/10/06 20:14 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38888 output: 25 thoughts: 128 Thoughts: **Analyzing Memory Allocation and Callback Flag Clearing in TCP Sockets** Okay, so I'm looking at how memory is managed and some flags are cleared within the TCP stack. Specifically, `sk_alloc` uses `priority | __GFP_ZERO`. This means that when a socket is allocated, it's done with a certain priority and the memory is zeroed out. That's standard and important for security, but now I want to track down where this related function `tcp_clear_sock_ops_cb_flags(sk)` is called. This function is specifically designed to zero out some flags: `bpf_sock_ops_cb_flags` and `bpf_tcp_ops_flags` from the `tcp_sock` structure associated with a socket. It's important to understand *when* these flags are cleared, because that tells me something about the lifecycle and usage of these BPF-related callbacks within the TCP stack. I need to know the calling context to understand what event or action triggers this clearing of the BPF flags, and therefore when the BPF socket operations callbacks are being "reset" or disabled. Tracing back through the code, I can gain insight into how these BPF callbacks are initialized and deactivated. |
| 54/3 | 2026/10/06 20:14 | tool | grepper |
0mArgs:{
"Expression": "tcp_clear_sock_ops_cb_flags"
}Results: {
"Output": "include/net/tcp.h=2930=do {\t\t\t\t\t\t\t\t\t\\\n--\ninclude/net/tcp.h-2937-\ninclude/net/tcp.h:2938:static inline void tcp_clear_sock_ops_cb_flags(struct sock *sk)\ninclude/net/tcp.h-2939-{\n--\ninclude/net/tcp.h=2945=static inline int tcp_call_bpf(struct sock *sk, int op)\n--\ninclude/net/tcp.h-2951-\ninclude/net/tcp.h:2952:static inline void tcp_clear_sock_ops_cb_flags(struct sock *sk)\ninclude/net/tcp.h-2953-{\n--\nnet/ipv4/inet_connection_sock.c=1293=void inet_csk_prepare_for_destroy_sock(struct sock *sk)\n--\nnet/ipv4/inet_connection_sock.c-1295-\t/* The below has to be done to allow calling inet_csk_destroy_sock */\nnet/ipv4/inet_connection_sock.c:1296:\ttcp_clear_sock_ops_cb_flags(sk);\nnet/ipv4/inet_connection_sock.c-1297-\tsock_set_flag(sk, SOCK_DEAD);\n"
} |
| 55/3 | 2026/10/06 20:14 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39641 output: 23 thoughts: 688 Thoughts: **Analyzing the TCP BPF Callbacks**
Alright, let's dissect how these TCP BPF callbacks are handled. First, I'm checking the `tcp_call_bpf_flag` and `__tcp_call_bpf` functions. `__tcp_call_bpf` is the core function where the BPF program actually gets invoked. I see it initializes a `struct bpf_sock_ops_kern`, setting it to zero up to the `temp` member. This suggests `temp` marks a kind of boundary or possibly the end of the common, initialized part of the struct. It then fills in the `sock_ops` struct with socket information, determines if the socket is fully created, and copies arguments into the `sock_ops.args` array. Critically, it then calls `__BPF_CGROUP_RUN_PROG_SOCK_OPS`, which is where the BPF program execution happens, the return value of which is then converted into a usable return code.
The `tcp_call_bpf_flag` macro is used to check if the cgroup BPF is enabled and if a specific flag is set for the operation. It's essentially a conditional wrapper around `__tcp_call_bpf`. The most important thing here is the argument handling, `u32 __args[] = { __VA_ARGS__ };`. This creates a `u32` array from the variable arguments. I need to keep a close eye on this, especially type conversions.
Looking at some examples, I see some interesting scenarios. With `BPF_SOCK_OPS_RTT_CB`, `mrtt` which is a `long` gets converted to a `u32` within the array. `srtt` is already `u32`, so no immediate problems there, but this is worth noting. In `BPF_SOCK_OPS_STATE_CB`, it's a simple two-argument call. With `BPF_SOCK_OPS_RETRANS_CB`, we have three arguments; and in `BPF_SOCK_OPS_RTO_CB`, we also have three arguments, and `expired` which may be a `bool` cast to `int`.
So, the number and type of arguments are going to determine what exactly is being passed to the BPF program, and it appears the macro will handle the type conversions, though the loss of precision from `long` to `u32` in the first example is something I need to keep in mind, and that the calling context might expect some different type. Now, let's investigate the structure itself, `struct bpf_sock_ops_kern`, to understand what data it's holding and how it's used by the BPF program.
|
| 56/3 | 2026/10/06 20:14 | tool | grepper |
0mArgs:{
"Expression": "struct bpf_sock_ops_kern"
}Results: {
"Output": "\nFull output is too long, showing 200 out of 380 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (12 files in total):\ninclude/linux/bpf-cgroup.h:2\ninclude/linux/bpf_types.h:1\ninclude/linux/filter.h:3\ninclude/net/tcp.h:4\nkernel/bpf/cgroup.c:1\nnet/core/filter.c:66\nnet/core/sock.c:2\nnet/core/sock_map.c:3\nnet/ipv4/bpf_tcp_ops.c:2\nnet/ipv4/tcp_input.c:4\nnet/ipv4/tcp_output.c:4\ntools/testing/selftests/bpf/progs/net_timestamping.c:2\n\ninclude/linux/bpf-cgroup.h=19=struct bpf_prog;\ninclude/linux/bpf-cgroup.h:20:struct bpf_sock_ops_kern;\ninclude/linux/bpf-cgroup.h-21-struct bpf_cgroup_storage;\n--\ninclude/linux/bpf-cgroup.h=143=int __cgroup_bpf_run_filter_sock_ops(struct sock *sk,\ninclude/linux/bpf-cgroup.h:144:\t\t\t\t struct bpf_sock_ops_kern *sock_ops,\ninclude/linux/bpf-cgroup.h-145-\t\t\t\t enum cgroup_bpf_attach_type atype);\n--\ninclude/linux/bpf_types.h=29=BPF_PROG_TYPE(BPF_PROG_TYPE_SOCK_OPS, sock_ops,\ninclude/linux/bpf_types.h:30:\t struct bpf_sock_ops, struct bpf_sock_ops_kern)\ninclude/linux/bpf_types.h-31-BPF_PROG_TYPE(BPF_PROG_TYPE_SK_SKB, sk_skb,\n--\ninclude/linux/filter.h=1682=struct bpf_sock_addr_kern {\n--\ninclude/linux/filter.h-1693-\ninclude/linux/filter.h:1694:struct bpf_sock_ops_kern {\ninclude/linux/filter.h-1695-\tstruct\tsock *sk;\n--\ninclude/linux/filter.h=1903=static __always_inline long __bpf_xdp_redirect_map(struct bpf_map *map, u64 index,\n--\ninclude/linux/filter.h-1940-\ninclude/linux/filter.h:1941:int __bpf_sock_ops_load_hdr_opt(struct bpf_sock_ops_kern *bpf_sock,\ninclude/linux/filter.h-1942-\t\t\t\tvoid *search_res, u32 len, u64 flags);\ninclude/linux/filter.h:1943:int __bpf_sock_ops_store_hdr_opt(struct bpf_sock_ops_kern *bpf_sock,\ninclude/linux/filter.h-1944-\t\t\t\t const void *from, u32 len, u64 flags);\n--\ninclude/net/tcp.h=2868=static inline void tcp_bpf_clone(const struct sock *sk, struct sock *newsk)\n--\ninclude/net/tcp.h-2873-#ifdef CONFIG_CGROUP_BPF\ninclude/net/tcp.h:2874:static inline void bpf_skops_init_skb(struct bpf_sock_ops_kern *skops,\ninclude/net/tcp.h-2875-\t\t\t\t struct sk_buff *skb,\n--\ninclude/net/tcp.h-2881-#else\ninclude/net/tcp.h:2882:static inline void bpf_skops_init_skb(struct bpf_sock_ops_kern *skops,\ninclude/net/tcp.h-2883-\t\t\t\t struct sk_buff *skb,\n--\ninclude/net/tcp.h=2895=static inline int __tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)\ninclude/net/tcp.h-2896-{\ninclude/net/tcp.h:2897:\tstruct bpf_sock_ops_kern sock_ops;\ninclude/net/tcp.h-2898-\tint ret;\ninclude/net/tcp.h-2899-\ninclude/net/tcp.h:2900:\tmemset(\u0026sock_ops, 0, offsetof(struct bpf_sock_ops_kern, temp));\ninclude/net/tcp.h-2901-\tif (sk_fullsock(sk)) {\n--\nkernel/bpf/cgroup.c=1944=int __cgroup_bpf_run_filter_sock_ops(struct sock *sk,\nkernel/bpf/cgroup.c:1945:\t\t\t\t struct bpf_sock_ops_kern *sock_ops,\nkernel/bpf/cgroup.c-1946-\t\t\t\t enum cgroup_bpf_attach_type atype)\n--\nnet/core/filter.c=5353=const struct bpf_func_proto bpf_get_socket_ptr_cookie_proto = {\n--\nnet/core/filter.c-5359-\nnet/core/filter.c:5360:BPF_CALL_1(bpf_get_socket_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx)\nnet/core/filter.c-5361-{\n--\nnet/core/filter.c=5407=static const struct bpf_func_proto bpf_get_netns_cookie_sock_addr_proto = {\n--\nnet/core/filter.c-5413-\nnet/core/filter.c:5414:BPF_CALL_1(bpf_get_netns_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx)\nnet/core/filter.c-5415-{\n--\nnet/core/filter.c=5776=static int __bpf_setsockopt(struct sock *sk, int level, int optname,\n--\nnet/core/filter.c-5793-\nnet/core/filter.c:5794:static bool is_locked_tcp_sock_ops(struct bpf_sock_ops_kern *bpf_sock)\nnet/core/filter.c-5795-{\n--\nnet/core/filter.c=6030=static const struct bpf_func_proto bpf_sock_create_getsockopt_proto = {\n--\nnet/core/filter.c-6040-\nnet/core/filter.c:6041:BPF_CALL_5(bpf_sock_ops_setsockopt, struct bpf_sock_ops_kern *, bpf_sock,\nnet/core/filter.c-6042-\t int, level, int, optname, char *, optval, int, optlen)\n--\nnet/core/filter.c=6056=static const struct bpf_func_proto bpf_sock_ops_setsockopt_proto = {\n--\nnet/core/filter.c-6066-\nnet/core/filter.c:6067:static int bpf_sock_ops_get_syn(struct bpf_sock_ops_kern *bpf_sock,\nnet/core/filter.c-6068-\t\t\t\tint optname, const u8 **start)\n--\nnet/core/filter.c-6134-\nnet/core/filter.c:6135:BPF_CALL_5(bpf_sock_ops_getsockopt, struct bpf_sock_ops_kern *, bpf_sock,\nnet/core/filter.c-6136-\t int, level, int, optname, char *, optval, int, optlen)\n--\nnet/core/filter.c=6166=static const struct bpf_func_proto bpf_sock_ops_getsockopt_proto = {\n--\nnet/core/filter.c-6176-\nnet/core/filter.c:6177:BPF_CALL_2(bpf_sock_ops_cb_flags_set, struct bpf_sock_ops_kern *, bpf_sock,\nnet/core/filter.c-6178-\t int, argval)\n--\nnet/core/filter.c=8011=static const u8 *bpf_search_tcp_opt(const u8 *op, const u8 *opend,\n--\nnet/core/filter.c-8054-\nnet/core/filter.c:8055:int __bpf_sock_ops_load_hdr_opt(struct bpf_sock_ops_kern *bpf_sock,\nnet/core/filter.c-8056-\t\t\t\tvoid *search_res, u32 len, u64 flags)\n--\nnet/core/filter.c-8122-\nnet/core/filter.c:8123:BPF_CALL_4(bpf_sock_ops_load_hdr_opt, struct bpf_sock_ops_kern *, bpf_sock,\nnet/core/filter.c-8124-\t void *, search_res, u32, len, u64, flags)\n--\nnet/core/filter.c=8132=static const struct bpf_func_proto bpf_sock_ops_load_hdr_opt_proto = {\n--\nnet/core/filter.c-8141-\nnet/core/filter.c:8142:int __bpf_sock_ops_store_hdr_opt(struct bpf_sock_ops_kern *bpf_sock,\nnet/core/filter.c-8143-\t\t\t\t const void *from, u32 len, u64 flags)\n--\nnet/core/filter.c-8206-\nnet/core/filter.c:8207:BPF_CALL_4(bpf_sock_ops_store_hdr_opt, struct bpf_sock_ops_kern *, bpf_sock,\nnet/core/filter.c-8208-\t const void *, from, u32, len, u64, flags)\n--\nnet/core/filter.c=8216=static const struct bpf_func_proto bpf_sock_ops_store_hdr_opt_proto = {\n--\nnet/core/filter.c-8225-\nnet/core/filter.c:8226:BPF_CALL_3(bpf_sock_ops_reserve_hdr_opt, struct bpf_sock_ops_kern *, bpf_sock,\nnet/core/filter.c-8227-\t u32, len, u64, flags)\n--\nnet/core/filter.c=10830=static u32 sock_ops_convert_ctx_access(enum bpf_access_type type,\n--\nnet/core/filter.c-10850-\t\t\t*insn++ = BPF_STX_MEM(BPF_DW, si-\u003esrc_reg, reg,\t \\\nnet/core/filter.c:10851:\t\t\t\t\t offsetof(struct bpf_sock_ops_kern, \\\nnet/core/filter.c-10852-\t\t\t\t\t temp));\t\t\t \\\n--\nnet/core/filter.c-10856-\t\t*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(\t\t\t \\\nnet/core/filter.c:10857:\t\t\t\t\t\tstruct bpf_sock_ops_kern, \\\nnet/core/filter.c-10858-\t\t\t\t\t\tis_locked_tcp_sock),\t \\\nnet/core/filter.c-10859-\t\t\t\t fullsock_reg, si-\u003esrc_reg,\t \\\nnet/core/filter.c:10860:\t\t\t\t offsetof(struct bpf_sock_ops_kern, \\\nnet/core/filter.c-10861-\t\t\t\t\t is_locked_tcp_sock));\t \\\n--\nnet/core/filter.c-10864-\t\t\t*insn++ = BPF_LDX_MEM(BPF_DW, reg, si-\u003esrc_reg,\t \\\nnet/core/filter.c:10865:\t\t\t\t offsetof(struct bpf_sock_ops_kern, \\\nnet/core/filter.c-10866-\t\t\t\t temp));\t\t\t\t \\\nnet/core/filter.c-10867-\t\t*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(\t\t\t \\\nnet/core/filter.c:10868:\t\t\t\t\t\tstruct bpf_sock_ops_kern, sk),\\\nnet/core/filter.c-10869-\t\t\t\t si-\u003edst_reg, si-\u003esrc_reg,\t\t \\\nnet/core/filter.c:10870:\t\t\t\t offsetof(struct bpf_sock_ops_kern, sk));\\\nnet/core/filter.c-10871-\t\t*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(OBJ,\t\t \\\n--\nnet/core/filter.c-10877-\t\t\t*insn++ = BPF_LDX_MEM(BPF_DW, reg, si-\u003esrc_reg,\t \\\nnet/core/filter.c:10878:\t\t\t\t offsetof(struct bpf_sock_ops_kern, \\\nnet/core/filter.c-10879-\t\t\t\t temp));\t\t\t\t \\\n--\nnet/core/filter.c-10892-\t\t\t*insn++ = BPF_STX_MEM(BPF_DW, si-\u003esrc_reg, reg,\t \\\nnet/core/filter.c:10893:\t\t\t\t\t offsetof(struct bpf_sock_ops_kern, \\\nnet/core/filter.c-10894-\t\t\t\t\t temp));\t\t\t \\\n--\nnet/core/filter.c-10898-\t\t*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(\t\t\t \\\nnet/core/filter.c:10899:\t\t\t\t\t\tstruct bpf_sock_ops_kern, \\\nnet/core/filter.c-10900-\t\t\t\t\t\tis_fullsock),\t\t \\\nnet/core/filter.c-10901-\t\t\t\t fullsock_reg, si-\u003esrc_reg,\t \\\nnet/core/filter.c:10902:\t\t\t\t offsetof(struct bpf_sock_ops_kern, \\\nnet/core/filter.c-10903-\t\t\t\t\t is_fullsock));\t\t \\\n--\nnet/core/filter.c-10906-\t\t\t*insn++ = BPF_LDX_MEM(BPF_DW, reg, si-\u003esrc_reg,\t \\\nnet/core/filter.c:10907:\t\t\t\t offsetof(struct bpf_sock_ops_kern, \\\nnet/core/filter.c-10908-\t\t\t\t temp));\t\t\t\t \\\nnet/core/filter.c-10909-\t\t*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(\t\t\t \\\nnet/core/filter.c:10910:\t\t\t\t\t\tstruct bpf_sock_ops_kern, sk),\\\nnet/core/filter.c-10911-\t\t\t\t si-\u003edst_reg, si-\u003esrc_reg,\t\t \\\nnet/core/filter.c:10912:\t\t\t\t offsetof(struct bpf_sock_ops_kern, sk));\\\nnet/core/filter.c-10913-\t\tif (si-\u003edst_reg == si-\u003esrc_reg)\t{\t\t\t \\\n--\nnet/core/filter.c-10915-\t\t\t*insn++ = BPF_LDX_MEM(BPF_DW, reg, si-\u003esrc_reg,\t \\\nnet/core/filter.c:10916:\t\t\t\t offsetof(struct bpf_sock_ops_kern, \\\nnet/core/filter.c-10917-\t\t\t\t temp));\t\t\t\t \\\n--\nnet/core/filter.c-10943-\t\t*insn++ = BPF_STX_MEM(BPF_DW, si-\u003edst_reg, reg,\t\t \\\nnet/core/filter.c:10944:\t\t\t\t offsetof(struct bpf_sock_ops_kern, \\\nnet/core/filter.c-10945-\t\t\t\t\t temp));\t\t\t \\\nnet/core/filter.c-10946-\t\t*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(\t\t\t \\\nnet/core/filter.c:10947:\t\t\t\t\t\tstruct bpf_sock_ops_kern, \\\nnet/core/filter.c-10948-\t\t\t\t\t\tis_locked_tcp_sock),\t \\\nnet/core/filter.c-10949-\t\t\t\t reg, si-\u003edst_reg,\t\t\t \\\nnet/core/filter.c:10950:\t\t\t\t offsetof(struct bpf_sock_ops_kern, \\\nnet/core/filter.c-10951-\t\t\t\t\t is_locked_tcp_sock));\t \\\n--\nnet/core/filter.c-10953-\t\t*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(\t\t\t \\\nnet/core/filter.c:10954:\t\t\t\t\t\tstruct bpf_sock_ops_kern, sk),\\\nnet/core/filter.c-10955-\t\t\t\t reg, si-\u003edst_reg,\t\t\t \\\nnet/core/filter.c:10956:\t\t\t\t offsetof(struct bpf_sock_ops_kern, sk));\\\nnet/core/filter.c-10957-\t\t*insn++ = BPF_RAW_INSN(BPF_FIELD_SIZEOF(OBJ, OBJ_FIELD) | \\\n--\nnet/core/filter.c-10962-\t\t*insn++ = BPF_LDX_MEM(BPF_DW, reg, si-\u003edst_reg,\t\t \\\nnet/core/filter.c:10963:\t\t\t\t offsetof(struct bpf_sock_ops_kern, \\\nnet/core/filter.c-10964-\t\t\t\t\t temp));\t\t\t \\\n--\nnet/core/filter.c-10976-\tcase offsetof(struct bpf_sock_ops, op):\nnet/core/filter.c:10977:\t\t*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct bpf_sock_ops_kern,\nnet/core/filter.c-10978-\t\t\t\t\t\t op),\nnet/core/filter.c-10979-\t\t\t\t si-\u003edst_reg, si-\u003esrc_reg,\nnet/core/filter.c:10980:\t\t\t\t offsetof(struct bpf_sock_ops_kern, op));\nnet/core/filter.c-10981-\t\tbreak;\n--\nnet/core/filter.c-10985-\t\tBUILD_BUG_ON(sizeof_field(struct bpf_sock_ops, reply) !=\nnet/core/filter.c:10986:\t\t\t sizeof_field(struct bpf_sock_ops_kern, reply));\nnet/core/filter.c-10987-\t\tBUILD_BUG_ON(sizeof_field(struct bpf_sock_ops, replylong) !=\nnet/core/filter.c:10988:\t\t\t sizeof_field(struct bpf_sock_ops_kern, replylong));\nnet/core/filter.c-10989-\t\toff = si-\u003eoff;\nnet/core/filter.c-10990-\t\toff -= offsetof(struct bpf_sock_ops, replylong[0]);\nnet/core/filter.c:10991:\t\toff += offsetof(struct bpf_sock_ops_kern, replylong[0]);\nnet/core/filter.c-10992-\t\tif (type == BPF_WRITE)\n--\n\n"
} |
| 57/3 | 2026/10/06 20:14 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 46011 output: 36 thoughts: 25 Thoughts: Here's my take on those thoughts, tailored for an expert audience: **Diving into the BPF Socket Operations Structure** Alright, let's get down to brass tacks. I'm going to pull up `include/linux/filter.h` because, as we both know, that's where the rubber meets the road when it comes to BPF socket operations. Specifically, I'm thinking we need to dissect `struct bpf_sock_ops_kern`. That structure is fundamental to understanding how we can interact with and manipulate socket behavior within the kernel using BPF programs. I need to refresh my memory on the exact layout, the available hooks, and the fields that are exposed. Knowing this is critical to crafting effective and secure BPF programs. Time to see what we're working with in the current kernel version. |
| 58/3 | 2026/10/06 20:14 | tool | read-file |
0mArgs:{
"File": "include/linux/filter.h",
"FirstLine": 1693,
"LineCount": 40
}Results: {
"Contents": "1693:\t\n1694:\tstruct bpf_sock_ops_kern {\n1695:\t\tstruct\tsock *sk;\n1696:\t\tunion {\n1697:\t\t\tu32 args[4];\n1698:\t\t\tu32 reply;\n1699:\t\t\tu32 replylong[4];\n1700:\t\t};\n1701:\t\tstruct sk_buff\t*syn_skb;\n1702:\t\tstruct sk_buff\t*skb;\n1703:\t\tvoid\t*skb_data_end;\n1704:\t\tu8\top;\n1705:\t\tu8\tis_fullsock;\n1706:\t\tu8\tis_locked_tcp_sock;\n1707:\t\tu8\tremaining_opt_len;\n1708:\t\tu64\ttemp;\t\t\t/* temp and everything after is not\n1709:\t\t\t\t\t\t * initialized to 0 before calling\n1710:\t\t\t\t\t\t * the BPF program. New fields that\n1711:\t\t\t\t\t\t * should be initialized to 0 should\n1712:\t\t\t\t\t\t * be inserted before temp.\n1713:\t\t\t\t\t\t * temp is scratch storage used by\n1714:\t\t\t\t\t\t * sock_ops_convert_ctx_access\n1715:\t\t\t\t\t\t * as temporary storage of a register.\n1716:\t\t\t\t\t\t */\n1717:\t};\n1718:\t\n1719:\tstruct bpf_sysctl_kern {\n1720:\t\tstruct ctl_table_header *head;\n1721:\t\tconst struct ctl_table *table;\n1722:\t\tvoid *cur_val;\n1723:\t\tsize_t cur_len;\n1724:\t\tvoid *new_val;\n1725:\t\tsize_t new_len;\n1726:\t\tint new_updated;\n1727:\t\tint write;\n1728:\t\tloff_t *ppos;\n1729:\t\t/* Temporary \"register\" for indirect stores to ppos. */\n1730:\t\tu64 tmp_reg;\n1731:\t};\n1732:\t\n"
} |
| 59/3 | 2026/10/06 20:14 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 46804 output: 304 thoughts: 5012 Thoughts: **KMSAN Analysis of BPF TCP Opcode and Flag Handling** Alright, let's break this down. My primary concern here is the potential for uninitialized memory usage, particularly as it relates to BPF hooks and socket operations. I'm seeing a lot of `memset` calls, which is good, but I need to be sure that the *entire* scope of the changes is covered. Firstly, those `memset` lines: it's good that `sock_ops` is being zeroed before use in multiple places: `tcp_call_bpf`, `__tcp_call_bpf`, and their derivatives. It zero-initializes members before the BPF program runs, minimizing risks. It zeroes all members of `sock_ops` *before* execution. That's a strong indicator. Everything from `sk` to `temp` is getting a zero-out, and that temp member is key because it *follows* all the potentially used fields. The new `__bpf_tcp_ops_call` and `bpf_tcp_ops_call_flag` macros use function pointers to BPF callbacks. I have to look at how these callbacks are invoked and if any uninitialized data is passed to them. Now, looking at `bpf_tcp_ops_set_rcvlowat`, the variables there are locally declared and always initialized: `moff` from `aux->attach_st_ops_member_off`, `wakeup` to `false`, and `rcvlowat` either from the argument or explicitly set to `INT_MAX`. Then it uses `__tcp_set_rcvlowat`, where similar checks and assignments are performed. I need to be sure that `tcp_data_ready` and other functions it calls are not reading uninitialized memory. `__tcp_set_rcvlowat` has multiple branches, but each variable used is initialized. `is_sockopt_supported` is the new allowlist for `BPF_FUNC_setsockopt` and `BPF_FUNC_getsockopt`. This limits which `bpf_tcp_ops` functions can be called by those socket operations. `bpf_tcp_ops_hdr_opt_len` uses `remaining_out = remaining;` before calling a BPF callback, so the stack variable is fully initialized. Also, it uses `opts->options |= OPTION_BPF` if `remaining` is not zero, making sure `opts` is written, but is initialized by a caller. In `tcp_established_options`, the old and new code uses `bpf_skops_hdr_opt_len` and `bpf_tcp_ops_hdr_opt_len`. The checks are moved inside these functions, but both return `remaining` as is if they don't do anything, which results in `size` being initialized. Next, I need to check the added hooks `enqueue_rcvq` and `dequeue_rcvq`. They call functions like `bpf_tcp_ops_call_flag` with `sk` and `skb`. `sk` is the `struct sock *`, and `skb` is the `struct sk_buff *` – both kernel pointers, so they are initialized. `bpf_tcp_ops_set_flags` initializes `old`, uses `try_cmpxchg` for `new`, so no uninitialized variables there. Similar with `bpf_tcp_ops_set_rcvlowat`. `tcp_call_bpf_flag` initializes `__args` in multiple locations, `mrtt` and `srtt`, `oldstate` and `state`, and variables related to retransmission. The sizes of the arguments passed to `__tcp_call_bpf` are also managed, so no out-of-bounds reads. In `__tcp_call_bpf`, `sock_ops` is zeroed and `args` is copied, after zeroing. The `args` array has a fixed size, and `nargs` never exceeds the array bounds. The rest of `sock_ops` members are always zeroed. I need to confirm the use of `__BPF_CGROUP_RUN_PROG_SOCK_OPS`. It extracts the `struct sock*` from `sock_ops` and checks whether it is a full socket. The old macro already contained `typeof(sk) __sk = sk_to_full_sk((sock_ops)->sk);`. This is just type checking at compile time and does not appear to introduce any uninitialized memory. No data is copied to user space, so that's good. There are no socket options returning data to user space. Also, `bpf_tcp_ops_ |
| 60/3 | 2026/10/06 20:15 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch adds BPF struct_ops callback support and flag-based invocation for TCP receive queue operations (enqueue_rcvq, dequeue_rcvq) and refactors existing TCP BPF hook calling paths.\n\nEvaluation against KMSAN criteria:\n1. No structures are copied to user space; no copy_to_user, put_user, netlink attributes, or ioctl/sockopt data disclosures to user space are introduced or altered.\n2. The newly added struct member (bpf_tcp_ops_flags in struct tcp_sock) resides in a zero-allocated structure (via sk_alloc with __GFP_ZERO) and is explicitly reset in tcp_clear_sock_ops_cb_flags().\n3. All local variables and arrays (such as __args[] in tcp_call_bpf_flag and sock_ops in __tcp_call_bpf) are fully initialized before read access.\n4. Any potential issues stemming from BPF callback invocation, such as socket reference safety, concurrent access to tcp_sock fields, or skb management, fall into concurrency, NULL dereference, or lifetime categories covered by LOCKDEP and KASAN, rather than uninitialized memory reads.\n\nTherefore, the patch introduces no uninitialized memory risks or info-leaks that would require a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch adds BPF struct_ops callback support and flag-based invocation for TCP receive queue operations (enqueue_rcvq, dequeue_rcvq) and refactors existing TCP BPF hook calling paths.\n\nEvaluation against KMSAN criteria:\n1. No structures are copied to user space; no copy_to_user, put_user, netlink attributes, or ioctl/sockopt data disclosures to user space are introduced or altered.\n2. The newly added struct member (bpf_tcp_ops_flags in struct tcp_sock) resides in a zero-allocated structure (via sk_alloc with __GFP_ZERO) and is explicitly reset in tcp_clear_sock_ops_cb_flags().\n3. All local variables and arrays (such as __args[] in tcp_call_bpf_flag and sock_ops in __tcp_call_bpf) are fully initialized before read access.\n4. Any potential issues stemming from BPF callback invocation, such as socket reference safety, concurrent access to tcp_sock fields, or skb management, fall into concurrency, NULL dereference, or lifetime categories covered by LOCKDEP and KASAN, rather than uninitialized memory reads.\n\nTherefore, the patch introduces no uninitialized memory risks or info-leaks that would require a dedicated KMSAN fuzzing session.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|