| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/11/17 07:46 | flow | patch-triage |
5mArgs:null Results: {
"EnableConfigs": [
"IP_VS",
"IP_VS_IPV6",
"IP_VS_PROTO_TCP",
"IP_VS_PROTO_UDP",
"IP_VS_PROTO_SCTP",
"IP_VS_PROTO_AH",
"IP_VS_PROTO_ESP",
"IP_VS_FTP",
"IP_VS_LBLC",
"IP_VS_LBLCR",
"NF_CONNTRACK",
"NF_CONNTRACK_FTP",
"NF_NAT",
"IPV6"
],
"FocusSymbols": [
"ipv6_find_hdr",
"ip_vs_conn_expire",
"ip_vs_conn_expire_now",
"ip_vs_conn_out_get",
"ip_vs_dest_update_overload",
"ip_vs_add_dest",
"ip_vs_del_dest",
"ip_vs_leave",
"ip_vs_new_conn_out",
"ip_vs_ftp_out",
"ip_vs_ftp_in",
"ip_vs_sync_conn",
"ip_vs_lblc_schedule",
"ip_vs_lblcr_schedule",
"ip_vs_nat_xmit",
"ip_vs_tunnel_xmit"
],
"KMSANReasoning": "The patch series makes several networking and IPVS improvements:\n1. Thread-safety and synchronization in IPVS sync (`ip_vs_sync.c`), copying connection sequence options under `cp-\u003elock`. The local variable `struct ip_vs_sync_conn_options opts` is strictly guarded by `flags \u0026 IP_VS_CONN_F_SEQ_MASK`, matching the condition under which it is populated from `cp-\u003esync_conn_opt` (which itself is zero-initialized on connection creation).\n2. RCU grace period and lifecycle fixes in `ip_vs_ctl.c` and `ip_vs_conn.c` (using `need_gp`, `rcu_state`, and `cond_synchronize_rcu`), where destination structures are zero-allocated via `kzalloc_obj`.\n3. Hook state propagation (`const struct nf_hook_state *state`) to xmit functions for accurate socket inspection during PMTU updates.\n4. Ordering fix for `nfct_seqadj_ext_add` in IPVS FTP conntrack handling to avoid conntrack extension reallocation bugs.\n5. Offset and length corrections for IPv6 fragment headers (`ipv6_find_hdr`) and ICMPv6 packets, operating on network skb data bounded by packet lengths.\n6. Input validation dropping connections with invalid zero ports.\n\nNone of these changes introduce or expose uninitialized memory reads or kernel-to-user information leaks:\n- No structures or paddings copied to user space are modified or added.\n- All newly added struct fields (`need_gp`, `rcu_state`) reside in zero-allocated heap memory (`kzalloc_obj`).\n- Potential issues introduced or touched by these changes are concurrency bugs, use-after-free/RCU issues, or skb boundary errors, all of which are covered by standard KASAN, LOCKDEP, and kernel debuggers.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch series modifies core networking code in IPVS and IPv6 extension header parsing. Changes include RCU grace-period synchronization when managing destination life cycles (trash/rehashing), lockdep assertions in destination lookups, refcount and timer synchronization overhauls in connection deletion/expiry, seqadj conntrack extension handling in the FTP helper, PMTU socket checks, and payload offset adjustments for IPv6 non-first fragments. All modified paths are reachable via standard networking and IPVS netlink/sockopt interfaces.",
"WorthFuzzing": true
} |
| 1/1 | 2026/11/17 07:46 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit c4e0762c669a3125d192b6e9d305ae1e8a4bed4e\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Tue Nov 17 07:46:41 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/include/net/ip_vs.h b/include/net/ip_vs.h\nindex 9a83bff32569da..fdb3a9063e6048 100644\n--- a/include/net/ip_vs.h\n+++ b/include/net/ip_vs.h\n@@ -731,7 +731,8 @@ struct ip_vs_protocol {\n \t\t\t int af, struct sk_buff *skb,\n \t\t\t struct ip_vs_proto_data *pd,\n \t\t\t int *verdict, struct ip_vs_conn **cpp,\n-\t\t\t struct ip_vs_iphdr *iph);\n+\t\t\t struct ip_vs_iphdr *iph,\n+\t\t\t const struct nf_hook_state *state);\n \n \tstruct ip_vs_conn *\n \t(*conn_in_get)(struct netns_ipvs *ipvs,\n@@ -872,7 +873,8 @@ struct ip_vs_conn {\n \t * NF_ACCEPT can be returned when destination is local.\n \t */\n \tint (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);\n+\t\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,\n+\t\t\t const struct nf_hook_state *state);\n \n \tstruct rcu_head\t\trcu_head;\n };\n@@ -1021,7 +1023,9 @@ struct ip_vs_dest {\n \n \tstruct rcu_head\t\trcu_head;\n \tstruct list_head\tt_list;\t\t/* in dest_trash */\n-\tunsigned int\t\tin_rs_table:1;\t/* we are in rs_table */\n+\tunsigned long\t\trcu_state;\t/* GP cookie on unlink (trash or rehash) */\n+\tunsigned int\t\tin_rs_table:1,\t/* we are in rs_table */\n+\t\t\t\tneed_gp:1;\t/* Need GP on rehash */\n };\n \n /* The scheduler object */\n@@ -1685,7 +1689,6 @@ static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp)\n /* put back the conn without restarting its timer */\n static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)\n {\n-\tsmp_mb__before_atomic();\n \trefcount_dec(\u0026cp-\u003erefcnt);\n }\n void ip_vs_conn_put(struct ip_vs_conn *cp);\n@@ -1871,7 +1874,8 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,\n \t struct ip_vs_proto_data *pd, int *ignored,\n \t struct ip_vs_iphdr *iph);\n int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,\n-\t\tstruct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph);\n+\t\tstruct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph,\n+\t\tconst struct nf_hook_state *state);\n \n void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);\n \n@@ -1923,7 +1927,7 @@ static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)\n \t\tkfree(dest);\n }\n \n-void ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload);\n+void ip_vs_dest_update_overload(struct ip_vs_dest *dest);\n \n /* Check if dest is in overloaded state */\n static inline bool ip_vs_dest_is_overloaded(const struct ip_vs_dest *dest)\n@@ -1986,32 +1990,46 @@ static inline int ip_vs_est_max_threads(struct netns_ipvs *ipvs)\n \n /* Various IPVS packet transmitters (from ip_vs_xmit.c) */\n int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,\n+\t\t const struct nf_hook_state *state);\n int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,\n+\t\t const struct nf_hook_state *state);\n int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,\n+\t\t const struct nf_hook_state *state);\n int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,\n+\t\t const struct nf_hook_state *state);\n int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,\n+\t\t const struct nf_hook_state *state);\n int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n \t\t struct ip_vs_protocol *pp, unsigned int toff,\n-\t\t unsigned int hooknum, struct ip_vs_iphdr *ciph);\n+\t\t const struct nf_hook_state *state,\n+\t\t struct ip_vs_iphdr *ciph);\n void ip_vs_dest_dst_rcu_free(struct rcu_head *head);\n \n #ifdef CONFIG_IP_VS_IPV6\n+int ip_vs_null_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,\n+\t\t const struct nf_hook_state *state);\n int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);\n+\t\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,\n+\t\t\t const struct nf_hook_state *state);\n int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,\n+\t\t const struct nf_hook_state *state);\n int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);\n+\t\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,\n+\t\t\t const struct nf_hook_state *state);\n int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,\n+\t\t const struct nf_hook_state *state);\n int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n \t\t struct ip_vs_protocol *pp, unsigned int toff,\n-\t\t unsigned int hooknum, struct ip_vs_iphdr *ciph);\n+\t\t const struct nf_hook_state *state,\n+\t\t struct ip_vs_iphdr *ciph);\n #endif\n \n #ifdef CONFIG_SYSCTL\ndiff --git a/net/ipv6/exthdrs_core.c b/net/ipv6/exthdrs_core.c\nindex 4a9748338cf400..e27f5b8cc15422 100644\n--- a/net/ipv6/exthdrs_core.c\n+++ b/net/ipv6/exthdrs_core.c\n@@ -179,7 +179,10 @@ EXPORT_SYMBOL_GPL(ipv6_find_tlv);\n *\n * Note that non-1st fragment is special case that \"the protocol number\n * of last header\" is \"next header\" field in Fragment header. In this case,\n- * *offset is meaningless and fragment offset is stored in *fragoff if fragoff\n+ * for target \u003c 0, *offset points immediately after the Fragment header,\n+ * at the start of the fragment payload. Callers must still account for\n+ * the nonzero fragment offset before interpreting the payload. The\n+ * fragment offset is stored in *fragoff if fragoff\n * isn't NULL.\n *\n * if flags is not NULL and it's a fragment, then the frag flag\n@@ -261,6 +264,7 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,\n \t\t\t\t hp-\u003enexthdr == NEXTHDR_NONE)) {\n \t\t\t\t\tif (fragoff)\n \t\t\t\t\t\t*fragoff = _frag_off;\n+\t\t\t\t\t*offset = start + sizeof(struct frag_hdr);\n \t\t\t\t\treturn hp-\u003enexthdr;\n \t\t\t\t}\n \t\t\t\tif (!found)\ndiff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c\nindex 94f25fb7d87e45..7cb8de634f5f9a 100644\n--- a/net/netfilter/ipvs/ip_vs_conn.c\n+++ b/net/netfilter/ipvs/ip_vs_conn.c\n@@ -293,7 +293,6 @@ static inline int ip_vs_conn_hash(struct ip_vs_conn *cp)\n \tcp-\u003eflags |= IP_VS_CONN_F_HASHED;\n \tWRITE_ONCE(cp-\u003ehn0.hash_key, hash_key);\n \tWRITE_ONCE(cp-\u003ehn1.hash_key, hash_key2);\n-\trefcount_inc(\u0026cp-\u003erefcnt);\n \thlist_bl_add_head_rcu(\u0026cp-\u003ehn0.node, head);\n \tif (use2)\n \t\thlist_bl_add_head_rcu(\u0026cp-\u003ehn1.node, head2);\n@@ -319,11 +318,27 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)\n \tstruct hlist_bl_head *head, *head2;\n \tu32 hash_key, hash_key2;\n \tstruct ip_vs_rht *t;\n-\tbool ret = false;\n \tbool use2;\n \n+\t/* No more users and no running/pending timer except us? */\n+\tif (!refcount_dec_if_one(\u0026cp-\u003erefcnt))\n+\t\treturn false;\n+\n+\t/* The ONE_PACKET connection is special:\n+\t * - the flag is present only for normal connections, not for templates\n+\t * - its timer is never started\n+\t * - it is never hashed, so you can not find it and delete it\n+\t * - it is not synced\n+\t * - it has only one user\n+\t * - it is freed after use immediately\n+\t */\n \tif (cp-\u003eflags \u0026 IP_VS_CONN_F_ONE_PACKET)\n-\t\treturn refcount_dec_if_one(\u0026cp-\u003erefcnt);\n+\t\treturn true;\n+\n+\t/* Add the needed ACQUIRE barrier between the above\n+\t * refcount_dec_if_one() call and the read of cp fields\n+\t */\n+\tsmp_acquire__after_ctrl_dep();\n \n \trcu_read_lock();\n \tlocal_bh_disable();\n@@ -337,15 +352,11 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)\n \t\t false /* new_hash2 */, \u0026head, \u0026head2);\n \n \tif (cp-\u003eflags \u0026 IP_VS_CONN_F_HASHED) {\n-\t\t/* Decrease refcnt and unlink conn only if we are last user */\n-\t\tif (use2 == ip_vs_conn_use_hash2(cp) \u0026\u0026\n-\t\t refcount_dec_if_one(\u0026cp-\u003erefcnt)) {\n-\t\t\thlist_bl_del_rcu(\u0026cp-\u003ehn0.node);\n-\t\t\tif (use2)\n-\t\t\t\thlist_bl_del_rcu(\u0026cp-\u003ehn1.node);\n-\t\t\tcp-\u003eflags \u0026= ~IP_VS_CONN_F_HASHED;\n-\t\t\tret = true;\n-\t\t}\n+\t\t/* Unlink conn as we are the last user */\n+\t\thlist_bl_del_rcu(\u0026cp-\u003ehn0.node);\n+\t\tif (use2)\n+\t\t\thlist_bl_del_rcu(\u0026cp-\u003ehn1.node);\n+\t\tcp-\u003eflags \u0026= ~IP_VS_CONN_F_HASHED;\n \t}\n \n \tconn_tab_unlock(head, head2);\n@@ -353,7 +364,7 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)\n \tlocal_bh_enable();\n \trcu_read_unlock();\n \n-\treturn ret;\n+\treturn true;\n }\n \n \n@@ -579,6 +590,8 @@ struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p)\n \t\t\t\t ip_vs_addr_equal(p-\u003eaf, p-\u003evaddr,\n \t\t\t\t\t\t \u0026cp-\u003ecaddr) \u0026\u0026\n \t\t\t\t ip_vs_addr_equal(p-\u003eaf, p-\u003ecaddr, saddr) \u0026\u0026\n+\t\t\t\t (!p-\u003evport ^\n+\t\t\t\t (!(cp-\u003eflags \u0026 IP_VS_CONN_F_NO_CPORT))) \u0026\u0026\n \t\t\t\t p-\u003eprotocol == cp-\u003eprotocol) {\n \t\t\t\t\tif (__ip_vs_conn_get(cp))\n \t\t\t\t\t\tgoto out;\n@@ -621,9 +634,12 @@ static void __ip_vs_conn_put_timer(struct ip_vs_conn *cp)\n {\n \tunsigned long t = (cp-\u003eflags \u0026 IP_VS_CONN_F_ONE_PACKET) ?\n \t\t0 : cp-\u003etimeout;\n-\tmod_timer(\u0026cp-\u003etimer, jiffies+t);\n \n-\t__ip_vs_conn_put(cp);\n+\t/* Handoff our reference to the timer if it was just armed,\n+\t * put the reference if timer was already pending.\n+\t */\n+\tif (mod_timer(\u0026cp-\u003etimer, jiffies + t))\n+\t\t__ip_vs_conn_put(cp);\n }\n \n void ip_vs_conn_put(struct ip_vs_conn *cp)\n@@ -1041,7 +1057,7 @@ static inline void ip_vs_bind_xmit(struct ip_vs_conn *cp)\n \t\tbreak;\n \n \tcase IP_VS_CONN_F_LOCALNODE:\n-\t\tcp-\u003epacket_xmit = ip_vs_null_xmit;\n+\t\tcp-\u003epacket_xmit = ip_vs_null_xmit_v6;\n \t\tbreak;\n \n \tcase IP_VS_CONN_F_BYPASS:\n@@ -1154,7 +1170,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)\n \t\t\tatomic_inc(\u0026dest-\u003eactiveconns);\n \t\ttc = atomic_inc_return(\u0026dest-\u003etotalconns);\n \t\tif (tc \u003e= READ_ONCE(dest-\u003eu_threshold_val))\n-\t\t\tip_vs_dest_update_overload(dest, true);\n+\t\t\tip_vs_dest_update_overload(dest);\n \t} else {\n \t\t/* It is a persistent connection/template, so increase\n \t\t the persistent connection counter */\n@@ -1247,7 +1263,7 @@ static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp)\n \t\t\tatomic_dec(\u0026dest-\u003eactiveconns);\n \t\ttc = atomic_fetch_dec(\u0026dest-\u003etotalconns);\n \t\tif (tc \u003c= READ_ONCE(dest-\u003el_threshold_val))\n-\t\t\tip_vs_dest_update_overload(dest, false);\n+\t\t\tip_vs_dest_update_overload(dest);\n \t} else {\n \t\t/* It is a persistent connection/template, so decrease\n \t\t the persistent connection counter */\n@@ -1322,36 +1338,48 @@ static void ip_vs_conn_rcu_free(struct rcu_head *head)\n \tkmem_cache_free(ip_vs_conn_cachep, cp);\n }\n \n-/* Try to delete connection while not holding reference */\n-static void ip_vs_conn_del(struct ip_vs_conn *cp)\n+/* Try to steal the reference from the pending timer.\n+ * It can be called concurrently and always under RCU lock\n+ * to protect from connection deletion from others.\n+ */\n+static bool ip_vs_conn_del_reference(struct ip_vs_conn *cp)\n {\n-\tif (timer_delete(\u0026cp-\u003etimer)) {\n-\t\t/* Drop cp-\u003econtrol chain too */\n-\t\tif (cp-\u003econtrol)\n-\t\t\tcp-\u003etimeout = 0;\n-\t\tip_vs_conn_expire(\u0026cp-\u003etimer);\n-\t}\n+\t/* Steal reference from the pending timer */\n+\tif (!timer_delete(\u0026cp-\u003etimer))\n+\t\treturn false;\n+\n+\t/* Drop cp-\u003econtrol chain too */\n+\tif (cp-\u003econtrol)\n+\t\tcp-\u003etimeout = 0;\n+\treturn true;\n }\n \n-/* Try to delete connection while holding reference */\n-static void ip_vs_conn_del_put(struct ip_vs_conn *cp)\n+/* Try to delete connection while not holding reference.\n+ * Used when we need to remove the connection immediately\n+ * and without overloading the timer processing.\n+ * OTOH, we use ip_vs_conn_expire_now() when we prefer to\n+ * leave the current context (packet processing) and to\n+ * remove the connection from timer.\n+ */\n+static void ip_vs_conn_del(struct ip_vs_conn *cp)\n {\n-\tif (timer_delete(\u0026cp-\u003etimer)) {\n-\t\t/* Drop cp-\u003econtrol chain too */\n-\t\tif (cp-\u003econtrol)\n-\t\t\tcp-\u003etimeout = 0;\n-\t\t__ip_vs_conn_put(cp);\n+\tif (ip_vs_conn_del_reference(cp))\n \t\tip_vs_conn_expire(\u0026cp-\u003etimer);\n-\t} else {\n-\t\t__ip_vs_conn_put(cp);\n-\t}\n }\n \n+/* Connection is removed in the following steps:\n+ * - timer expires (with ref) or connection is deleted (with stolen ref)\n+ * - there should be no more users except us (pending/running timer,\n+ * n_control\u003e0 or refcnt\u003e1)\n+ */\n static void ip_vs_conn_expire(struct timer_list *t)\n {\n \tstruct ip_vs_conn *cp = timer_container_of(cp, t, timer);\n \tstruct netns_ipvs *ipvs = cp-\u003eipvs;\n \n+\trcu_read_lock();\n+\n+repeat:\n \t/*\n \t *\tdo I control anybody?\n \t */\n@@ -1361,23 +1389,17 @@ static void ip_vs_conn_expire(struct timer_list *t)\n \t/* Unlink conn if not referenced anymore */\n \tif (likely(ip_vs_conn_unlink(cp))) {\n \t\tstruct ip_vs_conn *ct = cp-\u003econtrol;\n-\n-\t\t/* delete the timer if it is activated by other users */\n-\t\ttimer_delete(\u0026cp-\u003etimer);\n+\t\tbool next = false;\n \n \t\t/* does anybody control me? */\n \t\tif (ct) {\n-\t\t\tbool has_ref = !cp-\u003etimeout \u0026\u0026 __ip_vs_conn_get(ct);\n-\n \t\t\tip_vs_control_del(cp);\n \t\t\t/* Drop CTL or non-assured TPL if not used anymore */\n-\t\t\tif (has_ref \u0026\u0026 !atomic_read(\u0026ct-\u003en_control) \u0026\u0026\n+\t\t\tif (!cp-\u003etimeout \u0026\u0026 !atomic_read(\u0026ct-\u003en_control) \u0026\u0026\n \t\t\t (!(ct-\u003eflags \u0026 IP_VS_CONN_F_TEMPLATE) ||\n \t\t\t !(ct-\u003estate \u0026 IP_VS_CTPL_S_ASSURED))) {\n \t\t\t\tIP_VS_DBG(4, \"drop controlling connection\\n\");\n-\t\t\t\tip_vs_conn_del_put(ct);\n-\t\t\t} else if (has_ref) {\n-\t\t\t\t__ip_vs_conn_put(ct);\n+\t\t\t\tnext = ip_vs_conn_del_reference(ct);\n \t\t\t}\n \t\t}\n \n@@ -1405,7 +1427,11 @@ static void ip_vs_conn_expire(struct timer_list *t)\n \t\telse\n \t\t\tcall_rcu(\u0026cp-\u003ercu_head, ip_vs_conn_rcu_free);\n \t\tatomic_dec(\u0026ipvs-\u003econn_count);\n-\t\treturn;\n+\t\tif (next) {\n+\t\t\tcp = ct;\n+\t\t\tgoto repeat;\n+\t\t}\n+\t\tgoto out;\n \t}\n \n expire_later:\n@@ -1413,13 +1439,16 @@ static void ip_vs_conn_expire(struct timer_list *t)\n \t\t refcount_read(\u0026cp-\u003erefcnt),\n \t\t atomic_read(\u0026cp-\u003en_control));\n \n-\trefcount_inc(\u0026cp-\u003erefcnt);\n-\tcp-\u003etimeout = 60*HZ;\n+\tif (cp-\u003etimeout || atomic_read(\u0026cp-\u003en_control))\n+\t\tcp-\u003etimeout = 60 * HZ;\n \n \tif (ipvs-\u003esync_state \u0026 IP_VS_STATE_MASTER)\n \t\tip_vs_sync_conn(ipvs, cp, sysctl_sync_threshold(ipvs));\n \n \t__ip_vs_conn_put_timer(cp);\n+\n+out:\n+\trcu_read_unlock();\n }\n \n /* Modify timer, so that it expires as soon as possible.\n@@ -1432,7 +1461,7 @@ static void ip_vs_conn_expire(struct timer_list *t)\n void ip_vs_conn_expire_now(struct ip_vs_conn *cp)\n {\n \t/* Using mod_timer_pending will ensure the timer is not\n-\t * modified after the final timer_delete in ip_vs_conn_expire.\n+\t * started without giving it new reference.\n \t */\n \tif (timer_pending(\u0026cp-\u003etimer) \u0026\u0026\n \t time_after(cp-\u003etimer.expires, jiffies))\n@@ -1500,9 +1529,9 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,\n \tspin_lock_init(\u0026cp-\u003elock);\n \n \t/*\n-\t * Set the entry is referenced by the current thread before hashing\n-\t * it in the table, so that other thread run ip_vs_random_dropentry\n-\t * but cannot drop this entry.\n+\t * Set the entry as referenced by the current thread before starting\n+\t * the timer and giving it our reference to allow other threads to\n+\t * run ip_vs_random_dropentry() or any deletion method safely.\n \t */\n \trefcount_set(\u0026cp-\u003erefcnt, 1);\n \ndiff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c\nindex 8a3c880fdb266e..85ea82367cfe32 100644\n--- a/net/netfilter/ipvs/ip_vs_core.c\n+++ b/net/netfilter/ipvs/ip_vs_core.c\n@@ -760,7 +760,8 @@ static inline int ip_vs_addr_is_unicast(struct net *net, int af,\n * no destination is available for a new connection.\n */\n int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,\n-\t\tstruct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph)\n+\t\tstruct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph,\n+\t\tconst struct nf_hook_state *state)\n {\n \t__be16 _ports[2], *pptr, dport;\n \tstruct netns_ipvs *ipvs = svc-\u003eipvs;\n@@ -805,7 +806,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,\n \t\tip_vs_set_state(cp, IP_VS_DIR_INPUT, skb, pd, iph-\u003elen);\n \n \t\t/* transmit the first SYN packet */\n-\t\tret = cp-\u003epacket_xmit(skb, cp, pd-\u003epp, iph);\n+\t\tret = cp-\u003epacket_xmit(skb, cp, pd-\u003epp, iph, state);\n \t\t/* do not touch skb anymore */\n \n \t\tif ((cp-\u003eflags \u0026 IP_VS_CONN_F_ONE_PACKET) \u0026\u0026 cp-\u003econtrol)\n@@ -1206,6 +1207,13 @@ static int ip_vs_out_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,\n \t\t\t\t true, \u0026ciph))\n \t\treturn NF_ACCEPT; /* The packet looks wrong, ignore */\n \n+\t/* ipv6_find_hdr() does not include the embedded header for\n+\t * non-first fragments, add it so that ESP can pass and the\n+\t * NAT writable checks cover the rewritten addresses\n+\t */\n+\tif (ciph.len == ciph.off)\n+\t\tciph.len += sizeof(struct ipv6hdr);\n+\n \tpp = ip_vs_proto_get(ciph.protocol);\n \tif (!pp)\n \t\treturn NF_ACCEPT;\n@@ -1305,6 +1313,7 @@ static inline bool is_new_conn_expected(const struct ip_vs_conn *cp,\n * In fwmark-VS actual vaddr and vport are unknown to IPVS\n * 2) Real Server and Virtual Service were NOT configured without port:\n * This is to allow match of different VS to the same RS ip-addr\n+ * 3) Client port is not 0\n */\n struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,\n \t\t\t\t struct ip_vs_dest *dest,\n@@ -1328,7 +1337,7 @@ struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,\n \t/* check pre-requisites are satisfied */\n \tif (svc-\u003efwmark)\n \t\treturn NULL;\n-\tif (!vport || !dport)\n+\tif (!vport || !dport || !cport)\n \t\treturn NULL;\n \n \t/* for persistent service first create connection template */\n@@ -1647,7 +1656,8 @@ static unsigned int\n ip_vs_try_to_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \t\t struct ip_vs_proto_data *pd,\n \t\t int *verdict, struct ip_vs_conn **cpp,\n-\t\t struct ip_vs_iphdr *iph)\n+\t\t struct ip_vs_iphdr *iph,\n+\t\t const struct nf_hook_state *state)\n {\n \tstruct ip_vs_protocol *pp = pd-\u003epp;\n \n@@ -1657,7 +1667,8 @@ ip_vs_try_to_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \t\t */\n \n \t\t/* Schedule and create new connection entry into cpp */\n-\t\tif (!pp-\u003econn_schedule(ipvs, af, skb, pd, verdict, cpp, iph))\n+\t\tif (!pp-\u003econn_schedule(ipvs, af, skb, pd, verdict, cpp, iph,\n+\t\t\t\t state))\n \t\t\treturn 0;\n \t}\n \n@@ -1757,7 +1768,7 @@ static int ipvs_gre_decap(struct netns_ipvs *ipvs, struct sk_buff *skb,\n */\n static int\n ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,\n-\t unsigned int hooknum, struct ip_vs_iphdr *iph)\n+\t const struct nf_hook_state *state, struct ip_vs_iphdr *iph)\n {\n \tstruct icmphdr\t_icmph, *ic;\n \tstruct iphdr\t_ciph, *cih;\t/* The ip header contained within the ICMP */\n@@ -1776,7 +1787,8 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,\n \n \t/* reassemble IP fragments */\n \tif (ip_is_fragment(ip_hdr(skb))) {\n-\t\tif (ip_vs_gather_frags(ipvs, skb, ip_vs_defrag_user(hooknum)))\n+\t\tif (ip_vs_gather_frags(ipvs, skb,\n+\t\t\t\t ip_vs_defrag_user(state-\u003ehook)))\n \t\t\treturn NF_STOLEN;\n \t\tif (!ip_vs_fill_iph_skb(AF_INET, skb, false, iph))\n \t\t\treturn NF_ACCEPT;\n@@ -1893,7 +1905,8 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,\n \t\tif (tunnel || !sysctl_schedule_icmp(ipvs))\n \t\t\treturn NF_ACCEPT;\n \n-\t\tif (!ip_vs_try_to_schedule(ipvs, AF_INET, skb, pd, \u0026v, \u0026cp, \u0026ciph))\n+\t\tif (!ip_vs_try_to_schedule(ipvs, AF_INET, skb, pd, \u0026v, \u0026cp,\n+\t\t\t\t\t \u0026ciph, state))\n \t\t\treturn v;\n \t\tnew_cp = true;\n \t}\n@@ -1981,7 +1994,7 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,\n \n \t/* do the statistics and put it back */\n \tip_vs_in_stats(cp, skb);\n-\tverdict = ip_vs_icmp_xmit(skb, cp, pp, iph-\u003elen, hooknum, \u0026ciph);\n+\tverdict = ip_vs_icmp_xmit(skb, cp, pp, iph-\u003elen, state, \u0026ciph);\n \n out:\n \tif (likely(!new_cp))\n@@ -1994,7 +2007,7 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,\n \n #ifdef CONFIG_IP_VS_IPV6\n static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,\n-\t\t\t int *related, unsigned int hooknum,\n+\t\t\t int *related, const struct nf_hook_state *state,\n \t\t\t struct ip_vs_iphdr *iph)\n {\n \tstruct icmp6hdr\t_icmph, *ic;\n@@ -2036,6 +2049,13 @@ static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,\n \tif (!ip_vs_fill_iph_skb_icmp(AF_INET6, skb, offset, true, \u0026ciph))\n \t\treturn NF_ACCEPT;\n \n+\t/* ipv6_find_hdr() does not include the embedded header for\n+\t * non-first fragments, add it so that ESP can pass and the\n+\t * NAT writable checks cover the rewritten addresses\n+\t */\n+\tif (ciph.len == ciph.off)\n+\t\tciph.len += sizeof(struct ipv6hdr);\n+\n \tpd = ip_vs_proto_data_get(ipvs, ciph.protocol);\n \tif (!pd)\n \t\treturn NF_ACCEPT;\n@@ -2060,7 +2080,8 @@ static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,\n \t\tif (!sysctl_schedule_icmp(ipvs))\n \t\t\treturn NF_ACCEPT;\n \n-\t\tif (!ip_vs_try_to_schedule(ipvs, AF_INET6, skb, pd, \u0026v, \u0026cp, \u0026ciph))\n+\t\tif (!ip_vs_try_to_schedule(ipvs, AF_INET6, skb, pd, \u0026v, \u0026cp,\n+\t\t\t\t\t \u0026ciph, state))\n \t\t\treturn v;\n \n \t\tnew_cp = true;\n@@ -2081,7 +2102,7 @@ static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,\n \t/* do the statistics and put it back */\n \tip_vs_in_stats(cp, skb);\n \n-\tverdict = ip_vs_icmp_xmit_v6(skb, cp, pp, iph-\u003elen, hooknum, \u0026ciph);\n+\tverdict = ip_vs_icmp_xmit_v6(skb, cp, pp, iph-\u003elen, state, \u0026ciph);\n \n out:\n \tif (likely(!new_cp))\n@@ -2150,7 +2171,7 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state\n \t\tif (unlikely(iph.protocol == IPPROTO_ICMPV6)) {\n \t\t\tint related;\n \t\t\tint verdict = ip_vs_in_icmp_v6(ipvs, skb, \u0026related,\n-\t\t\t\t\t\t hooknum, \u0026iph);\n+\t\t\t\t\t\t state, \u0026iph);\n \n \t\t\tif (related)\n \t\t\t\treturn verdict;\n@@ -2160,7 +2181,7 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state\n \t\tif (unlikely(iph.protocol == IPPROTO_ICMP)) {\n \t\t\tint related;\n \t\t\tint verdict = ip_vs_in_icmp(ipvs, skb, \u0026related,\n-\t\t\t\t\t\t hooknum, \u0026iph);\n+\t\t\t\t\t\t state, \u0026iph);\n \n \t\t\tif (related)\n \t\t\t\treturn verdict;\n@@ -2248,7 +2269,8 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state\n \tif (unlikely(!cp)) {\n \t\tint v;\n \n-\t\tif (!ip_vs_try_to_schedule(ipvs, af, skb, pd, \u0026v, \u0026cp, \u0026iph))\n+\t\tif (!ip_vs_try_to_schedule(ipvs, af, skb, pd, \u0026v, \u0026cp, \u0026iph,\n+\t\t\t\t\t state))\n \t\t\treturn v;\n \t}\n \n@@ -2257,7 +2279,7 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state\n \tip_vs_in_stats(cp, skb);\n \tip_vs_set_state(cp, IP_VS_DIR_INPUT, skb, pd, iph.len);\n \tif (cp-\u003epacket_xmit)\n-\t\tret = cp-\u003epacket_xmit(skb, cp, pp, \u0026iph);\n+\t\tret = cp-\u003epacket_xmit(skb, cp, pp, \u0026iph, state);\n \t\t/* do not touch skb anymore */\n \telse {\n \t\tIP_VS_DBG_RL(\"warning: packet_xmit is null\");\n@@ -2320,11 +2342,11 @@ ip_vs_forward_icmp(void *priv, struct sk_buff *skb,\n \t\tif (iphdr.protocol != IPPROTO_ICMPV6)\n \t\t\treturn NF_ACCEPT;\n \n-\t\treturn ip_vs_in_icmp_v6(ipvs, skb, \u0026r, state-\u003ehook, \u0026iphdr);\n+\t\treturn ip_vs_in_icmp_v6(ipvs, skb, \u0026r, state, \u0026iphdr);\n #endif\n \t}\n \n-\treturn ip_vs_in_icmp(ipvs, skb, \u0026r, state-\u003ehook, \u0026iphdr);\n+\treturn ip_vs_in_icmp(ipvs, skb, \u0026r, state, \u0026iphdr);\n }\n \n static const struct nf_hook_ops ip_vs_ops4[] = {\ndiff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c\nindex ce9fe20d6106a8..be818bf7d3806c 100644\n--- a/net/netfilter/ipvs/ip_vs_ctl.c\n+++ b/net/netfilter/ipvs/ip_vs_ctl.c\n@@ -64,7 +64,8 @@ int ip_vs_get_debug_level(void)\n \n \n /* Protos */\n-static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup);\n+static void __ip_vs_del_service(struct ip_vs_service *svc,\n+\t\t\t\tstruct list_head *dest_trash, bool cleanup);\n \n \n #ifdef CONFIG_IP_VS_IPV6\n@@ -918,6 +919,11 @@ static void ip_vs_rs_hash(struct netns_ipvs *ipvs, struct ip_vs_dest *dest)\n \t */\n \thash = ip_vs_rs_hashkey(dest-\u003eaf, \u0026dest-\u003eaddr, port);\n \n+\t/* Need RCU grace period when rehashing */\n+\tif (dest-\u003eneed_gp) {\n+\t\tcond_synchronize_rcu(dest-\u003ercu_state);\n+\t\tdest-\u003eneed_gp = 0;\n+\t}\n \thlist_add_head_rcu(\u0026dest-\u003ed_list, \u0026ipvs-\u003ers_table[hash]);\n \tdest-\u003ein_rs_table = 1;\n }\n@@ -1111,6 +1117,8 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af,\n \tstruct ip_vs_dest *dest;\n \tstruct netns_ipvs *ipvs = svc-\u003eipvs;\n \n+\tlockdep_assert_held(\u0026ipvs-\u003eservice_mutex);\n+\n \t/*\n \t * Find the destination in trash\n \t */\n@@ -1144,24 +1152,57 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af,\n \treturn dest;\n }\n \n-/* Put destination in trash */\n-static void ip_vs_trash_put_dest(struct netns_ipvs *ipvs,\n+/* Add destination in temp list for trash */\n+static void ip_vs_trash_add_dest(struct netns_ipvs *ipvs,\n \t\t\t\t struct ip_vs_dest *dest, unsigned long istart,\n-\t\t\t\t bool cleanup)\n+\t\t\t\t struct list_head *dest_trash)\n {\n-\tspin_lock_bh(\u0026ipvs-\u003edest_trash_lock);\n \tIP_VS_DBG_BUF(3, \"Moving dest %s:%u into trash, dest-\u003erefcnt=%d\\n\",\n \t\t IP_VS_DBG_ADDR(dest-\u003eaf, \u0026dest-\u003eaddr), ntohs(dest-\u003eport),\n \t\t refcount_read(\u0026dest-\u003erefcnt));\n+\t/* dest lives in trash with reference */\n+\tlist_add(\u0026dest-\u003et_list, dest_trash);\n+\tdest-\u003eidle_start = istart;\n+}\n+\n+/* Put destinations in trash */\n+static void ip_vs_trash_put_dests(struct netns_ipvs *ipvs,\n+\t\t\t\t struct list_head *dest_trash, bool cleanup)\n+{\n+\tspin_lock_bh(\u0026ipvs-\u003edest_trash_lock);\n \tif (list_empty(\u0026ipvs-\u003edest_trash) \u0026\u0026 !cleanup)\n \t\tmod_timer(\u0026ipvs-\u003edest_trash_timer,\n \t\t\t jiffies + (IP_VS_DEST_TRASH_PERIOD \u003e\u003e 1));\n-\t/* dest lives in trash with reference */\n-\tlist_add(\u0026dest-\u003et_list, \u0026ipvs-\u003edest_trash);\n-\tdest-\u003eidle_start = istart;\n+\tlist_splice(dest_trash, \u0026ipvs-\u003edest_trash);\n \tspin_unlock_bh(\u0026ipvs-\u003edest_trash_lock);\n }\n \n+/* Put destination back in trash */\n+static void ip_vs_trash_put_back(struct netns_ipvs *ipvs,\n+\t\t\t\t struct ip_vs_dest *dest)\n+{\n+\tLIST_HEAD(dest_trash);\n+\n+\tip_vs_trash_add_dest(ipvs, dest, dest-\u003eidle_start, \u0026dest_trash);\n+\tip_vs_trash_put_dests(ipvs, \u0026dest_trash, false);\n+}\n+\n+/* Put destinations in trash and save the RCU state */\n+static void ip_vs_trash_save_dests(struct netns_ipvs *ipvs,\n+\t\t\t\t struct list_head *dest_trash, bool cleanup)\n+{\n+\tstruct ip_vs_dest *dest;\n+\tunsigned long rcu_state;\n+\n+\tif (!list_empty(dest_trash)) {\n+\t\t/* Remember when dests were removed and added to dest_trash */\n+\t\trcu_state = get_state_synchronize_rcu();\n+\t\tlist_for_each_entry(dest, dest_trash, t_list)\n+\t\t\tdest-\u003ercu_state = rcu_state;\n+\t\tip_vs_trash_put_dests(ipvs, dest_trash, cleanup);\n+\t}\n+}\n+\n static void ip_vs_dest_rcu_free(struct rcu_head *head)\n {\n \tstruct ip_vs_dest *dest;\n@@ -1304,12 +1345,12 @@ void ip_vs_stats_free(struct ip_vs_stats *stats)\n \t}\n }\n \n-/* Update overload flag based on number of dest conns and lower/upper\n+/* Update overload state based on number of dest conns and lower/upper\n * connection thresholds:\n- * - conns reach u_threshold and exceed it: set the flag\n- * - conns go below l_threshold (or 75% of u_threshold): clear the flag\n+ * - conns reach u_threshold and exceed it: set the overload state\n+ * - conns go below l_threshold (or 75% of u_threshold): clear the state\n */\n-static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)\n+static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest)\n {\n \tint conns;\n \tu32 l, u;\n@@ -1320,10 +1361,18 @@ static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)\n \t\t/* Low threshold defaults to 75% of upper threshold */\n \t\tl = READ_ONCE(dest-\u003el_threshold) ? : (u - (u \u003e\u003e 2));\n \t\tconns = atomic_read(\u0026dest-\u003etotalconns);\n-\t\tif (conns \u003e= (overload ? l : u)) {\n+\t\tif (conns \u003e= (ip_vs_dest_is_overloaded(dest) ? l : u)) {\n \t\t\tWRITE_ONCE(dest-\u003eu_threshold_val, INT_MAX);\n \t\t\tWRITE_ONCE(dest-\u003el_threshold_val, l);\n-\t\t\treturn;\n+\t\t\t/* Commit thresholds before repeating the check,\n+\t\t\t * it is paired with atomic_fetch_dec() in\n+\t\t\t * ip_vs_unbind_dest() to avoid entering the\n+\t\t\t * overload state forever.\n+\t\t\t */\n+\t\t\tsmp_mb();\n+\t\t\tconns = atomic_read(\u0026dest-\u003etotalconns);\n+\t\t\tif (conns \u003e= l)\n+\t\t\t\treturn;\n \t\t}\n \t}\n \n@@ -1331,10 +1380,10 @@ static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)\n \tWRITE_ONCE(dest-\u003el_threshold_val, 0);\n }\n \n-void ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)\n+void ip_vs_dest_update_overload(struct ip_vs_dest *dest)\n {\n \tspin_lock_bh(\u0026dest-\u003edst_lock);\n-\t__ip_vs_dest_update_overload(dest, overload);\n+\t__ip_vs_dest_update_overload(dest);\n \tspin_unlock_bh(\u0026dest-\u003edst_lock);\n }\n \n@@ -1369,8 +1418,16 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,\n \tif ((udest-\u003econn_flags \u0026 IP_VS_CONN_F_FWD_MASK) !=\n \t IP_VS_DFWD_METHOD(dest) ||\n \t udest-\u003etun_type != dest-\u003etun_type ||\n-\t udest-\u003etun_port != dest-\u003etun_port)\n+\t udest-\u003etun_port != dest-\u003etun_port) {\n+\t\tbool unlinked = dest-\u003ein_rs_table;\n+\n \t\tip_vs_rs_unhash(dest);\n+\t\tif (unlinked) {\n+\t\t\tdest-\u003ercu_state = get_state_synchronize_rcu();\n+\t\t\t/* Need grace period in this or next dest update */\n+\t\t\tdest-\u003eneed_gp = 1;\n+\t\t}\n+\t}\n \n \t/* set the tunnel info */\n \tdest-\u003etun_type = udest-\u003etun_type;\n@@ -1406,13 +1463,10 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,\n \n \tif (READ_ONCE(dest-\u003eu_threshold) != udest-\u003eu_threshold ||\n \t READ_ONCE(dest-\u003el_threshold) != udest-\u003el_threshold) {\n-\t\tbool overload;\n-\n \t\tspin_lock_bh(\u0026dest-\u003edst_lock);\n \t\tWRITE_ONCE(dest-\u003eu_threshold, udest-\u003eu_threshold);\n \t\tWRITE_ONCE(dest-\u003el_threshold, udest-\u003el_threshold);\n-\t\toverload = ip_vs_dest_is_overloaded(dest);\n-\t\t__ip_vs_dest_update_overload(dest, overload);\n+\t\t__ip_vs_dest_update_overload(dest);\n \t\tspin_unlock_bh(\u0026dest-\u003edst_lock);\n \t}\n \n@@ -1477,6 +1531,7 @@ ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)\n \tif (ret \u003c 0)\n \t\tgoto err_stats;\n \n+\tdest-\u003eu_threshold_val = INT_MAX;\n \tdest-\u003eaf = udest-\u003eaf;\n \tdest-\u003eprotocol = svc-\u003eprotocol;\n \tdest-\u003evaddr = svc-\u003eaddr;\n@@ -1556,6 +1611,11 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)\n \tdest = ip_vs_trash_get_dest(svc, udest-\u003eaf, \u0026daddr, dport);\n \n \tif (dest != NULL) {\n+\t\t/* Readers may still follow the n_list, d_list or estimator list\n+\t\t * links. Wait before reusing any of them.\n+\t\t */\n+\t\tcond_synchronize_rcu(dest-\u003ercu_state);\n+\n \t\tIP_VS_DBG_BUF(3, \"Get destination %s:%u from trash, \"\n \t\t\t \"dest-\u003erefcnt=%d, service %u/%s:%u\\n\",\n \t\t\t IP_VS_DBG_ADDR(udest-\u003eaf, \u0026daddr), ntohs(dport),\n@@ -1566,11 +1626,14 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)\n \n \t\tret = ip_vs_start_estimator(svc-\u003eipvs, \u0026dest-\u003estats);\n \t\t/* On error put back dest into the trash */\n-\t\tif (ret \u003c 0)\n-\t\t\tip_vs_trash_put_dest(svc-\u003eipvs, dest, dest-\u003eidle_start,\n-\t\t\t\t\t false);\n-\t\telse\n+\t\tif (ret \u003c 0) {\n+\t\t\tip_vs_trash_put_back(svc-\u003eipvs, dest);\n+\t\t} else {\n+\t\t\t/* need_gp matters only on dest edit, reinit it */\n+\t\t\tdest-\u003eneed_gp = 0;\n+\n \t\t\t__ip_vs_update_dest(svc, dest, udest, 1);\n+\t\t}\n \t} else {\n \t\t/*\n \t\t * Allocate and initialize the dest structure\n@@ -1634,7 +1697,7 @@ ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)\n *\tDelete a destination (must be already unlinked from the service)\n */\n static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest,\n-\t\t\t bool cleanup)\n+\t\t\t struct list_head *dest_trash, bool cleanup)\n {\n \tip_vs_stop_estimator(ipvs, \u0026dest-\u003estats);\n \n@@ -1643,7 +1706,7 @@ static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest,\n \t */\n \tip_vs_rs_unhash(dest);\n \n-\tip_vs_trash_put_dest(ipvs, dest, 0, cleanup);\n+\tip_vs_trash_add_dest(ipvs, dest, 0, dest_trash);\n \n \t/* Queue up delayed work to expire all no destination connections.\n \t * No-op when CONFIG_SYSCTL is disabled.\n@@ -1693,6 +1756,7 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)\n {\n \tstruct ip_vs_dest *dest;\n \t__be16 dport = udest-\u003eport;\n+\tLIST_HEAD(dest_trash);\n \n \t/* We use function that requires RCU lock */\n \trcu_read_lock();\n@@ -1712,7 +1776,9 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)\n \t/*\n \t *\tDelete the destination\n \t */\n-\t__ip_vs_del_dest(svc-\u003eipvs, dest, false);\n+\t__ip_vs_del_dest(svc-\u003eipvs, dest, \u0026dest_trash, false);\n+\n+\tip_vs_trash_save_dests(svc-\u003eipvs, \u0026dest_trash, false);\n \n \treturn 0;\n }\n@@ -2057,7 +2123,8 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)\n *\t- The service must be unlinked, unlocked and not referenced!\n *\t- We are called under _bh lock\n */\n-static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)\n+static void __ip_vs_del_service(struct ip_vs_service *svc,\n+\t\t\t\tstruct list_head *dest_trash, bool cleanup)\n {\n \tstruct ip_vs_dest *dest, *nxt;\n \tstruct ip_vs_scheduler *old_sched;\n@@ -2091,7 +2158,7 @@ static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)\n \t */\n \tlist_for_each_entry_safe(dest, nxt, \u0026svc-\u003edestinations, n_list) {\n \t\t__ip_vs_unlink_dest(svc, dest, 0);\n-\t\t__ip_vs_del_dest(svc-\u003eipvs, dest, cleanup);\n+\t\t__ip_vs_del_dest(svc-\u003eipvs, dest, dest_trash, cleanup);\n \t}\n \n \t/*\n@@ -2114,7 +2181,8 @@ static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)\n /*\n * Unlink a service from list and try to delete it if its refcnt reached 0\n */\n-static void ip_vs_unlink_service(struct ip_vs_service *svc, bool cleanup)\n+static void ip_vs_unlink_service(struct ip_vs_service *svc,\n+\t\t\t\t struct list_head *dest_trash, bool cleanup)\n {\n \tip_vs_unregister_conntrack(svc);\n \t/* Hold svc to avoid double release from dest_trash */\n@@ -2124,7 +2192,7 @@ static void ip_vs_unlink_service(struct ip_vs_service *svc, bool cleanup)\n \t */\n \tip_vs_svc_unhash(svc);\n \n-\t__ip_vs_del_service(svc, cleanup);\n+\t__ip_vs_del_service(svc, dest_trash, cleanup);\n }\n \n /*\n@@ -2134,12 +2202,14 @@ static int ip_vs_del_service(struct ip_vs_service *svc)\n {\n \tstruct netns_ipvs *ipvs;\n \tstruct ip_vs_rht *t, *p;\n+\tLIST_HEAD(dest_trash);\n \tint ns;\n \n \tif (svc == NULL)\n \t\treturn -EEXIST;\n \tipvs = svc-\u003eipvs;\n-\tip_vs_unlink_service(svc, false);\n+\tip_vs_unlink_service(svc, \u0026dest_trash, false);\n+\tip_vs_trash_save_dests(ipvs, \u0026dest_trash, false);\n \n \t/* Drop the table if no more services */\n \tns = ip_vs_get_num_services(ipvs);\n@@ -2190,6 +2260,7 @@ static int ip_vs_flush(struct netns_ipvs *ipvs, bool cleanup)\n \tstruct hlist_bl_node *ne;\n \tstruct hlist_bl_node *e;\n \tstruct ip_vs_rht *t, *p;\n+\tLIST_HEAD(dest_trash);\n \n \t/* Stop the resizer and drop the tables */\n \tif (!test_and_set_bit(IP_VS_WORK_SVC_NORESIZE, \u0026ipvs-\u003ework_flags))\n@@ -2199,8 +2270,9 @@ static int ip_vs_flush(struct netns_ipvs *ipvs, bool cleanup)\n \tif (ip_vs_get_num_services(ipvs)) {\n \t\tip_vs_rht_walk_buckets(ipvs-\u003esvc_table, head) {\n \t\t\thlist_bl_for_each_entry_safe(svc, e, ne, head, s_list)\n-\t\t\t\tip_vs_unlink_service(svc, cleanup);\n+\t\t\t\tip_vs_unlink_service(svc, \u0026dest_trash, cleanup);\n \t\t}\n+\t\tip_vs_trash_save_dests(ipvs, \u0026dest_trash, cleanup);\n \t}\n \n \t/* Unregister the hash table and release it after RCU grace period */\ndiff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c\nindex 9e3e005a826353..81c3a2fd27b397 100644\n--- a/net/netfilter/ipvs/ip_vs_ftp.c\n+++ b/net/netfilter/ipvs/ip_vs_ftp.c\n@@ -29,6 +29,7 @@\n #include \u003clinux/netfilter.h\u003e\n #include \u003cnet/netfilter/nf_conntrack.h\u003e\n #include \u003cnet/netfilter/nf_conntrack_expect.h\u003e\n+#include \u003cnet/netfilter/nf_conntrack_seqadj.h\u003e\n #include \u003cnet/netfilter/nf_nat.h\u003e\n #include \u003cnet/netfilter/nf_nat_helper.h\u003e\n #include \u003clinux/gfp.h\u003e\n@@ -62,6 +63,17 @@ static unsigned short ports[IP_VS_APP_MAX_PORTS] = {21, 0};\n module_param_array(ports, ushort, \u0026ports_count, 0444);\n MODULE_PARM_DESC(ports, \"Ports to monitor for FTP control commands\");\n \n+static bool is_control_port(u16 port)\n+{\n+\tunsigned int i;\n+\n+\tfor (i = 0; i \u003c ports_count; i++) {\n+\t\tif (ports[i] == port)\n+\t\t\treturn true;\n+\t}\n+\treturn false;\n+}\n+\n \n static char *ip_vs_ftp_data_ptr(struct sk_buff *skb, struct ip_vs_iphdr *ipvsh)\n {\n@@ -319,6 +331,10 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,\n \t\treturn 1;\n \t}\n \n+\t/* Do not redirect data to control ports */\n+\tif (!port || is_control_port(ntohs(port)))\n+\t\treturn 0;\n+\n \t/* Now update or create a connection entry for it */\n \t{\n \t\tstruct ip_vs_conn_param p;\n@@ -368,20 +384,26 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,\n \tbuf_len = strlen(buf);\n \n \tct = nf_ct_get(skb, \u0026ctinfo);\n-\tif (ct) {\n-\t\tbool mangled;\n+\tif (ct \u0026\u0026 !nf_ct_is_template(ct)) {\n+\t\tbool mangled = false;\n \n \t\t/* If mangling fails this function will return 0\n \t\t * which will cause the packet to be dropped.\n \t\t * Mangling can only fail under memory pressure,\n \t\t * hopefully it will succeed on the retransmitted\n \t\t * packet.\n+\t\t *\n+\t\t * Add the seqadj extension before the expectation is\n+\t\t * linked into the helper extension: adding it later\n+\t\t * reallocates ct-\u003eext under the expectation list.\n \t\t */\n-\t\tmangled = nf_nat_mangle_tcp_packet(skb, ct, ctinfo,\n-\t\t\t\t\t\t ipvsh-\u003elen,\n-\t\t\t\t\t\t start - data,\n-\t\t\t\t\t\t end - start,\n-\t\t\t\t\t\t buf, buf_len);\n+\t\tif (nf_ct_is_confirmed(ct) || nfct_seqadj(ct) ||\n+\t\t nfct_seqadj_ext_add(ct))\n+\t\t\tmangled = nf_nat_mangle_tcp_packet(skb, ct, ctinfo,\n+\t\t\t\t\t\t\t ipvsh-\u003elen,\n+\t\t\t\t\t\t\t start - data,\n+\t\t\t\t\t\t\t end - start,\n+\t\t\t\t\t\t\t buf, buf_len);\n \t\tif (mangled) {\n \t\t\tip_vs_nfct_expect_related(skb, ct, n_cp,\n \t\t\t\t\t\t ipvsh-\u003eprotocol, 0, 0);\n@@ -529,6 +551,9 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,\n \t\treturn 1;\n \t}\n \n+\tif (!port || is_control_port(ntohs(cp-\u003evport) - 1))\n+\t\treturn 0;\n+\n \t/* Passive mode off */\n \tcp-\u003eapp_data = (void *) IP_VS_FTP_ACTIVE;\n \ndiff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c\nindex e1111c3b27211a..f5ce1f2afb8606 100644\n--- a/net/netfilter/ipvs/ip_vs_lblc.c\n+++ b/net/netfilter/ipvs/ip_vs_lblc.c\n@@ -467,10 +467,11 @@ is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc)\n \t\tstruct ip_vs_dest *d;\n \n \t\tlist_for_each_entry_rcu(d, \u0026svc-\u003edestinations, n_list) {\n-\t\t\tif (atomic_read(\u0026d-\u003eactiveconns)*2\n-\t\t\t \u003c atomic_read(\u0026d-\u003eweight)) {\n+\t\t\tif (ip_vs_dest_is_overloaded(d))\n+\t\t\t\tcontinue;\n+\t\t\tif (atomic_read(\u0026d-\u003eactiveconns) * 2 \u003c\n+\t\t\t atomic_read(\u0026d-\u003eweight))\n \t\t\t\treturn 1;\n-\t\t\t}\n \t\t}\n \t}\n \treturn 0;\n@@ -507,6 +508,7 @@ ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,\n \n \t\tdest = en-\u003edest;\n \t\tif ((dest-\u003ecflags \u0026 IP_VS_DEST_CF_AVAILABLE) \u0026\u0026\n+\t\t !ip_vs_dest_is_overloaded(dest) \u0026\u0026\n \t\t atomic_read(\u0026dest-\u003eweight) \u003e 0 \u0026\u0026 !is_overloaded(dest, svc))\n \t\t\tgoto out;\n \t}\ndiff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c\nindex dfb5bf83750dba..4046608922e7cb 100644\n--- a/net/netfilter/ipvs/ip_vs_lblcr.c\n+++ b/net/netfilter/ipvs/ip_vs_lblcr.c\n@@ -630,10 +630,11 @@ is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc)\n \t\tstruct ip_vs_dest *d;\n \n \t\tlist_for_each_entry_rcu(d, \u0026svc-\u003edestinations, n_list) {\n-\t\t\tif (atomic_read(\u0026d-\u003eactiveconns)*2\n-\t\t\t \u003c atomic_read(\u0026d-\u003eweight)) {\n+\t\t\tif (ip_vs_dest_is_overloaded(d))\n+\t\t\t\tcontinue;\n+\t\t\tif (atomic_read(\u0026d-\u003eactiveconns) * 2 \u003c\n+\t\t\t atomic_read(\u0026d-\u003eweight))\n \t\t\t\treturn 1;\n-\t\t\t}\n \t\t}\n \t}\n \treturn 0;\n@@ -658,9 +659,6 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,\n \tif (en) {\n \t\ten-\u003elastuse = jiffies;\n \n-\t\t/* Get the least loaded destination */\n-\t\tdest = ip_vs_dest_set_min(\u0026en-\u003eset);\n-\n \t\t/* More than one destination + enough time passed by, cleanup */\n \t\tif (atomic_read(\u0026en-\u003eset.size) \u003e 1 \u0026\u0026\n \t\t time_after(jiffies, en-\u003eset.lastmod +\n@@ -676,6 +674,9 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,\n \t\t\tspin_unlock_bh(\u0026svc-\u003esched_lock);\n \t\t}\n \n+\t\t/* Get the least loaded destination */\n+\t\tdest = ip_vs_dest_set_min(\u0026en-\u003eset);\n+\n \t\t/* If the destination is not overloaded, use it */\n \t\tif (dest \u0026\u0026 !is_overloaded(dest, svc))\n \t\t\tgoto out;\ndiff --git a/net/netfilter/ipvs/ip_vs_proto_ah_esp.c b/net/netfilter/ipvs/ip_vs_proto_ah_esp.c\nindex 44e14acc187ee3..c7f90b29be51b3 100644\n--- a/net/netfilter/ipvs/ip_vs_proto_ah_esp.c\n+++ b/net/netfilter/ipvs/ip_vs_proto_ah_esp.c\n@@ -102,7 +102,7 @@ static int\n ah_esp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \t\t struct ip_vs_proto_data *pd,\n \t\t int *verdict, struct ip_vs_conn **cpp,\n-\t\t struct ip_vs_iphdr *iph)\n+\t\t struct ip_vs_iphdr *iph, const struct nf_hook_state *state)\n {\n \t/*\n \t * AH/ESP is only related traffic. Pass the packet to IP stack.\ndiff --git a/net/netfilter/ipvs/ip_vs_proto_sctp.c b/net/netfilter/ipvs/ip_vs_proto_sctp.c\nindex fb8af6b15a3999..3d773c881f75aa 100644\n--- a/net/netfilter/ipvs/ip_vs_proto_sctp.c\n+++ b/net/netfilter/ipvs/ip_vs_proto_sctp.c\n@@ -17,7 +17,7 @@ static int\n sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \t\t struct ip_vs_proto_data *pd,\n \t\t int *verdict, struct ip_vs_conn **cpp,\n-\t\t struct ip_vs_iphdr *iph)\n+\t\t struct ip_vs_iphdr *iph, const struct nf_hook_state *state)\n {\n \tstruct ip_vs_service *svc;\n \tstruct sctp_chunkhdr _schunkh, *sch;\n@@ -30,6 +30,7 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \t\t\tsch = skb_header_pointer(skb, iph-\u003elen + sizeof(_sctph),\n \t\t\t\t\t\t sizeof(_schunkh), \u0026_schunkh);\n \t\t\tif (sch) {\n+\t\t\t\t/* Accept packet without scheduling? */\n \t\t\t\tif (sch-\u003etype == SCTP_CID_ABORT ||\n \t\t\t\t !(sysctl_sloppy_sctp(ipvs) ||\n \t\t\t\t sch-\u003etype == SCTP_CID_INIT))\n@@ -56,6 +57,12 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \tif (svc) {\n \t\tint ignored;\n \n+\t\t/* Do not create connection for port 0 */\n+\t\tif (!ports[0] || !ports[1]) {\n+\t\t\t*verdict = NF_DROP;\n+\t\t\treturn 0;\n+\t\t}\n+\n \t\tif (ip_vs_todrop(ipvs)) {\n \t\t\t/*\n \t\t\t * It seems that we are very loaded.\n@@ -71,7 +78,8 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \t\t*cpp = ip_vs_schedule(svc, skb, pd, \u0026ignored, iph);\n \t\tif (!*cpp \u0026\u0026 ignored \u003c= 0) {\n \t\t\tif (!ignored)\n-\t\t\t\t*verdict = ip_vs_leave(svc, skb, pd, iph);\n+\t\t\t\t*verdict = ip_vs_leave(svc, skb, pd, iph,\n+\t\t\t\t\t\t state);\n \t\t\telse\n \t\t\t\t*verdict = NF_DROP;\n \t\t\treturn 0;\ndiff --git a/net/netfilter/ipvs/ip_vs_proto_tcp.c b/net/netfilter/ipvs/ip_vs_proto_tcp.c\nindex fec0e8b47b7165..13ac917a0ac8d1 100644\n--- a/net/netfilter/ipvs/ip_vs_proto_tcp.c\n+++ b/net/netfilter/ipvs/ip_vs_proto_tcp.c\n@@ -35,7 +35,7 @@ static int\n tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \t\t struct ip_vs_proto_data *pd,\n \t\t int *verdict, struct ip_vs_conn **cpp,\n-\t\t struct ip_vs_iphdr *iph)\n+\t\t struct ip_vs_iphdr *iph, const struct nf_hook_state *state)\n {\n \tstruct ip_vs_service *svc;\n \tstruct tcphdr _tcph, *th;\n@@ -48,6 +48,7 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \tif (likely(!ip_vs_iph_icmp(iph))) {\n \t\tth = skb_header_pointer(skb, iph-\u003elen, sizeof(_tcph), \u0026_tcph);\n \t\tif (th) {\n+\t\t\t/* Accept packet without scheduling? */\n \t\t\tif (th-\u003erst || !(sysctl_sloppy_tcp(ipvs) || th-\u003esyn))\n \t\t\t\treturn 1;\n \t\t\tports = \u0026th-\u003esource;\n@@ -74,6 +75,12 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \tif (svc) {\n \t\tint ignored;\n \n+\t\t/* Do not create connection for port 0 */\n+\t\tif (!ports[0] || !ports[1]) {\n+\t\t\t*verdict = NF_DROP;\n+\t\t\treturn 0;\n+\t\t}\n+\n \t\tif (ip_vs_todrop(ipvs)) {\n \t\t\t/*\n \t\t\t * It seems that we are very loaded.\n@@ -90,7 +97,8 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \t\t*cpp = ip_vs_schedule(svc, skb, pd, \u0026ignored, iph);\n \t\tif (!*cpp \u0026\u0026 ignored \u003c= 0) {\n \t\t\tif (!ignored)\n-\t\t\t\t*verdict = ip_vs_leave(svc, skb, pd, iph);\n+\t\t\t\t*verdict = ip_vs_leave(svc, skb, pd, iph,\n+\t\t\t\t\t\t state);\n \t\t\telse\n \t\t\t\t*verdict = NF_DROP;\n \t\t\treturn 0;\ndiff --git a/net/netfilter/ipvs/ip_vs_proto_udp.c b/net/netfilter/ipvs/ip_vs_proto_udp.c\nindex f32785682402dd..760b019e6a06d4 100644\n--- a/net/netfilter/ipvs/ip_vs_proto_udp.c\n+++ b/net/netfilter/ipvs/ip_vs_proto_udp.c\n@@ -31,7 +31,7 @@ static int\n udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \t\t struct ip_vs_proto_data *pd,\n \t\t int *verdict, struct ip_vs_conn **cpp,\n-\t\t struct ip_vs_iphdr *iph)\n+\t\t struct ip_vs_iphdr *iph, const struct nf_hook_state *state)\n {\n \tstruct ip_vs_service *svc;\n \tstruct udphdr _udph, *uh;\n@@ -62,6 +62,12 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \tif (svc) {\n \t\tint ignored;\n \n+\t\t/* Do not create connection for port 0 */\n+\t\tif (!ports[0] || !ports[1]) {\n+\t\t\t*verdict = NF_DROP;\n+\t\t\treturn 0;\n+\t\t}\n+\n \t\tif (ip_vs_todrop(ipvs)) {\n \t\t\t/*\n \t\t\t * It seems that we are very loaded.\n@@ -78,7 +84,8 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,\n \t\t*cpp = ip_vs_schedule(svc, skb, pd, \u0026ignored, iph);\n \t\tif (!*cpp \u0026\u0026 ignored \u003c= 0) {\n \t\t\tif (!ignored)\n-\t\t\t\t*verdict = ip_vs_leave(svc, skb, pd, iph);\n+\t\t\t\t*verdict = ip_vs_leave(svc, skb, pd, iph,\n+\t\t\t\t\t\t state);\n \t\t\telse\n \t\t\t\t*verdict = NF_DROP;\n \t\t\treturn 0;\ndiff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c\nindex 157f5c8361ab46..7e562e745ab5d5 100644\n--- a/net/netfilter/ipvs/ip_vs_sync.c\n+++ b/net/netfilter/ipvs/ip_vs_sync.c\n@@ -539,6 +539,7 @@ static int ip_vs_sync_conn_needed(struct netns_ipvs *ipvs,\n static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,\n \t\t\t int pkts)\n {\n+\tstruct ip_vs_sync_conn_options opts;\n \tstruct ip_vs_sync_mesg_v0 *m;\n \tstruct ip_vs_sync_conn_v0 *s;\n \tstruct ip_vs_sync_buff *buff;\n@@ -557,6 +558,14 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,\n \tif (!ip_vs_sync_conn_needed(ipvs, cp, pkts))\n \t\treturn;\n \n+\tif (flags \u0026 IP_VS_CONN_F_SEQ_MASK) {\n+\t\t/* Take atomic snapshot of flags and seqs */\n+\t\tspin_lock_bh(\u0026cp-\u003elock);\n+\t\tflags = cp-\u003eflags;\n+\t\tmemcpy(\u0026opts, \u0026cp-\u003esync_conn_opt, sizeof(opts));\n+\t\tspin_unlock_bh(\u0026cp-\u003elock);\n+\t}\n+\n \tspin_lock_bh(\u0026ipvs-\u003esync_buff_lock);\n \tif (!(ipvs-\u003esync_state \u0026 IP_VS_STATE_MASTER)) {\n \t\tspin_unlock_bh(\u0026ipvs-\u003esync_buff_lock);\n@@ -604,7 +613,7 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,\n \tif (seq_mask) {\n \t\tstruct ip_vs_sync_conn_options *opt =\n \t\t\t(struct ip_vs_sync_conn_options *)\u0026s[1];\n-\t\tmemcpy(opt, \u0026cp-\u003esync_conn_opt, sizeof(*opt));\n+\t\tmemcpy(opt, \u0026opts, sizeof(*opt));\n \t}\n \n \tm-\u003enr_conns++;\n@@ -630,6 +639,7 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,\n */\n void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)\n {\n+\tstruct ip_vs_sync_conn_options opts;\n \tstruct ip_vs_sync_mesg *m;\n \tunion ip_vs_sync_conn *s;\n \tstruct ip_vs_sync_buff *buff;\n@@ -651,6 +661,13 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)\n \tif (!ip_vs_sync_conn_needed(ipvs, cp, pkts))\n \t\tgoto control;\n \tflags = READ_ONCE(cp-\u003eflags);\n+\tif (flags \u0026 IP_VS_CONN_F_SEQ_MASK) {\n+\t\t/* Take atomic snapshot of flags and seqs */\n+\t\tspin_lock_bh(\u0026cp-\u003elock);\n+\t\tflags = cp-\u003eflags;\n+\t\tmemcpy(\u0026opts, \u0026cp-\u003esync_conn_opt, sizeof(opts));\n+\t\tspin_unlock_bh(\u0026cp-\u003elock);\n+\t}\n \n \t/* Sanity checks */\n \tpe_name_len = 0;\n@@ -732,7 +749,7 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)\n \ts-\u003ev4.vport = cp-\u003evport;\n \ts-\u003ev4.dport = cp-\u003edport;\n \ts-\u003ev4.fwmark = htonl(cp-\u003efwmark);\n-\ts-\u003ev4.timeout = htonl(cp-\u003etimeout / HZ);\n+\ts-\u003ev4.timeout = htonl(max(1UL, cp-\u003etimeout / HZ));\n \tm-\u003enr_conns++;\n \n #ifdef CONFIG_IP_VS_IPV6\n@@ -752,9 +769,9 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)\n \tif (seq_mask) {\n \t\t*(p++) = IPVS_OPT_SEQ_DATA;\n \t\t*(p++) = sizeof(struct ip_vs_sync_conn_options);\n-\t\thton_seq(\u0026cp-\u003ein_seq, (struct ip_vs_seq *)p);\n+\t\thton_seq(\u0026opts.in_seq, (struct ip_vs_seq *)p);\n \t\tp += sizeof(struct ip_vs_seq);\n-\t\thton_seq(\u0026cp-\u003eout_seq, (struct ip_vs_seq *)p);\n+\t\thton_seq(\u0026opts.out_seq, (struct ip_vs_seq *)p);\n \t\tp += sizeof(struct ip_vs_seq);\n \t}\n \t/* Handle pe data */\n@@ -850,9 +867,29 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa\n \t\t\t unsigned long timeout, __u32 fwmark,\n \t\t\t struct ip_vs_sync_conn_options *opt)\n {\n+\tstruct ip_vs_conn *cp_new = NULL;\n \tstruct ip_vs_dest *dest;\n \tstruct ip_vs_conn *cp;\n \n+\t/* Templates require cport 0. Ordinary connections require\n+\t * NO_CPORT exactly when cport is 0.\n+\t */\n+\tif (flags \u0026 IP_VS_CONN_F_TEMPLATE) {\n+\t\tif (param-\u003ecport) {\n+\t\t\tIP_VS_DBG(2, \"BACKUP, template with cport dropped\\n\");\n+\t\t\tkfree(param-\u003epe_data);\n+\t\t\treturn;\n+\t\t}\n+\t} else if (!param-\u003ecport \u0026\u0026 !(flags \u0026 IP_VS_CONN_F_NO_CPORT)) {\n+\t\tIP_VS_DBG(2, \"BACKUP, conn without cport dropped\\n\");\n+\t\tkfree(param-\u003epe_data);\n+\t\treturn;\n+\t} else if (param-\u003ecport \u0026\u0026 (flags \u0026 IP_VS_CONN_F_NO_CPORT)) {\n+\t\tIP_VS_DBG(2, \"BACKUP, conn with cport and NO_CPORT dropped\\n\");\n+\t\tkfree(param-\u003epe_data);\n+\t\treturn;\n+\t}\n+\n \tif (!(flags \u0026 IP_VS_CONN_F_TEMPLATE)) {\n \t\tcp = ip_vs_conn_in_get(param);\n \t\tif (cp \u0026\u0026 ((cp-\u003edport != dport) ||\n@@ -891,9 +928,6 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa\n \t\tflags \u0026= IP_VS_CONN_F_BACKUP_UPD_MASK;\n \t\tflags |= cp-\u003eflags \u0026 ~IP_VS_CONN_F_BACKUP_UPD_MASK;\n \t\tcp-\u003eflags = flags;\n-\t\tspin_unlock_bh(\u0026cp-\u003elock);\n-\t\tif (!dest)\n-\t\t\tip_vs_try_bind_dest(cp);\n \t} else {\n \t\t/*\n \t\t * Find the appropriate destination for the connection.\n@@ -920,6 +954,8 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa\n \t\t}\n \t\tif (!(flags \u0026 IP_VS_CONN_F_TEMPLATE))\n \t\t\tkfree(param-\u003epe_data);\n+\t\tcp_new = cp;\n+\t\tspin_lock_bh(\u0026cp-\u003elock);\n \t}\n \n \tif (opt) {\n@@ -951,6 +987,9 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa\n \t\telse\n \t\t\tcp-\u003etimeout = (3*60*HZ);\n \t}\n+\tspin_unlock_bh(\u0026cp-\u003elock);\n+\tif (!dest \u0026\u0026 !cp_new)\n+\t\tip_vs_try_bind_dest(cp);\n \tip_vs_conn_put(cp);\n }\n \ndiff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c\nindex ebc6b697ae5160..c777493eee7493 100644\n--- a/net/netfilter/ipvs/ip_vs_xmit.c\n+++ b/net/netfilter/ipvs/ip_vs_xmit.c\n@@ -205,13 +205,24 @@ static inline bool crosses_local_route_boundary(int skb_af, struct sk_buff *skb,\n \treturn false;\n }\n \n-static inline void maybe_update_pmtu(int skb_af, struct sk_buff *skb, int mtu)\n+static inline void maybe_update_pmtu(int skb_af, struct sk_buff *skb, int mtu,\n+\t\t\t\t const struct nf_hook_state *state)\n {\n-\tstruct sock *sk = skb-\u003esk;\n-\tstruct rtable *ort = skb_rtable(skb);\n-\n-\tif (!skb-\u003edev \u0026\u0026 sk \u0026\u0026 sk_fullsock(sk))\n-\t\tort-\u003edst.ops-\u003eupdate_pmtu(\u0026ort-\u003edst, sk, NULL, mtu, true);\n+\tstruct dst_entry *dst = skb_dst(skb);\n+\tstruct sock *sk = state-\u003esk;\n+\n+\t/* The update_pmtu handlers are missing some checks for:\n+\t * - skb-\u003edev: present for tunnels, not for IPVS, so we do not\n+\t * provide skb, only sk\n+\t * - present daddr: so, we require TCP_ESTABLISHED (connected socket)\n+\t *\n+\t * In some states the senders ignore the PMTU events:\n+\t * - sk_fullsock(): so use the TCP_ESTABLISHED check\n+\t */\n+\tif (sk \u0026\u0026 sk-\u003esk_state == TCP_ESTABLISHED \u0026\u0026\n+\t state-\u003ehook == NF_INET_LOCAL_OUT \u0026\u0026\n+\t sk-\u003esk_family == dst-\u003eops-\u003efamily)\n+\t\tdst-\u003eops-\u003eupdate_pmtu(dst, sk, NULL, mtu, false);\n }\n \n static inline bool ensure_mtu_is_adequate(struct netns_ipvs *ipvs, int skb_af,\n@@ -316,7 +327,7 @@ static int\n __ip_vs_get_out_rt(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,\n \t\t struct ip_vs_dest *dest,\n \t\t __be32 daddr, int rt_mode, __be32 *ret_saddr,\n-\t\t struct ip_vs_iphdr *ipvsh)\n+\t\t struct ip_vs_iphdr *ipvsh, const struct nf_hook_state *state)\n {\n \tstruct net *net = ipvs-\u003enet;\n \tstruct ip_vs_dest_dst *dest_dst;\n@@ -417,7 +428,7 @@ __ip_vs_get_out_rt(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,\n \t\t\tIP_VS_DBG_RL(\"%s(): mtu less than 68\\n\", __func__);\n \t\t\tgoto err_put;\n \t\t}\n-\t\tmaybe_update_pmtu(skb_af, skb, mtu);\n+\t\tmaybe_update_pmtu(skb_af, skb, mtu, state);\n \t}\n \n \tif (!ensure_mtu_is_adequate(ipvs, skb_af, rt_mode, ipvsh, skb, mtu))\n@@ -489,7 +500,8 @@ static int\n __ip_vs_get_out_rt_v6(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,\n \t\t struct ip_vs_dest *dest,\n \t\t struct in6_addr *daddr, struct in6_addr *ret_saddr,\n-\t\t struct ip_vs_iphdr *ipvsh, int do_xfrm, int rt_mode)\n+\t\t struct ip_vs_iphdr *ipvsh, int do_xfrm, int rt_mode,\n+\t\t const struct nf_hook_state *state)\n {\n \tstruct net *net = ipvs-\u003enet;\n \tstruct ip_vs_dest_dst *dest_dst;\n@@ -596,7 +608,7 @@ __ip_vs_get_out_rt_v6(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,\n \t\t\t\t IPV6_MIN_MTU);\n \t\t\tgoto err_put;\n \t\t}\n-\t\tmaybe_update_pmtu(skb_af, skb, mtu);\n+\t\tmaybe_update_pmtu(skb_af, skb, mtu, state);\n \t}\n \n \tif (!ensure_mtu_is_adequate(ipvs, skb_af, rt_mode, ipvsh, skb, mtu))\n@@ -720,12 +732,26 @@ static inline int ip_vs_send_or_cont(int pf, struct sk_buff *skb,\n */\n int\n ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\tstruct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)\n+\t\tstruct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,\n+\t\tconst struct nf_hook_state *state)\n {\n \t/* we do not touch skb and do not need pskb ptr */\n \treturn ip_vs_send_or_cont(NFPROTO_IPV4, skb, cp, 1);\n }\n \n+#ifdef CONFIG_IP_VS_IPV6\n+/*\n+ * NULL transmitter (do nothing except return NF_ACCEPT)\n+ */\n+int\n+ip_vs_null_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,\n+\t\t const struct nf_hook_state *state)\n+{\n+\t/* we do not touch skb and do not need pskb ptr */\n+\treturn ip_vs_send_or_cont(NFPROTO_IPV6, skb, cp, 1);\n+}\n+#endif\n \n /*\n * Bypass transmitter\n@@ -734,10 +760,11 @@ ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n */\n int\n ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,\n+\t\t const struct nf_hook_state *state)\n {\n \tif (__ip_vs_get_out_rt(cp-\u003eipvs, cp-\u003eaf, skb, NULL, ip_hdr(skb)-\u003edaddr,\n-\t\t\t IP_VS_RT_MODE_NON_LOCAL, NULL, ipvsh) \u003c 0)\n+\t\t\t IP_VS_RT_MODE_NON_LOCAL, NULL, ipvsh, state) \u003c 0)\n \t\tgoto tx_error;\n \n \tip_send_check(ip_hdr(skb));\n@@ -757,13 +784,15 @@ ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n #ifdef CONFIG_IP_VS_IPV6\n int\n ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,\n+\t\t const struct nf_hook_state *state)\n {\n \tstruct ipv6hdr *iph = ipv6_hdr(skb);\n \n \tif (__ip_vs_get_out_rt_v6(cp-\u003eipvs, cp-\u003eaf, skb, NULL,\n \t\t\t\t \u0026iph-\u003edaddr, NULL,\n-\t\t\t\t ipvsh, 0, IP_VS_RT_MODE_NON_LOCAL) \u003c 0)\n+\t\t\t\t ipvsh, 0, IP_VS_RT_MODE_NON_LOCAL,\n+\t\t\t\t state) \u003c 0)\n \t\tgoto tx_error;\n \n \t/* Another hack: avoid icmp_send in ip_fragment */\n@@ -785,7 +814,8 @@ ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n */\n int\n ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)\n+\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,\n+\t const struct nf_hook_state *state)\n {\n \tstruct rtable *rt;\t\t/* Route to the other host */\n \tint local, rc, was_input;\n@@ -805,7 +835,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n \tlocal = __ip_vs_get_out_rt(cp-\u003eipvs, cp-\u003eaf, skb, cp-\u003edest, cp-\u003edaddr.ip,\n \t\t\t\t IP_VS_RT_MODE_LOCAL |\n \t\t\t\t IP_VS_RT_MODE_NON_LOCAL |\n-\t\t\t\t IP_VS_RT_MODE_RDR, NULL, ipvsh);\n+\t\t\t\t IP_VS_RT_MODE_RDR, NULL, ipvsh, state);\n \tif (local \u003c 0)\n \t\tgoto tx_error;\n \trt = skb_rtable(skb);\n@@ -869,7 +899,8 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n #ifdef CONFIG_IP_VS_IPV6\n int\n ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,\n+\t\t const struct nf_hook_state *state)\n {\n \tstruct rt6_info *rt;\t\t/* Route to the other host */\n \tint local, rc;\n@@ -889,7 +920,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n \t\t\t\t NULL, ipvsh, 0,\n \t\t\t\t IP_VS_RT_MODE_LOCAL |\n \t\t\t\t IP_VS_RT_MODE_NON_LOCAL |\n-\t\t\t\t IP_VS_RT_MODE_RDR);\n+\t\t\t\t IP_VS_RT_MODE_RDR, state);\n \tif (local \u003c 0)\n \t\tgoto tx_error;\n \trt = dst_rt6_info(skb_dst(skb));\n@@ -1145,7 +1176,8 @@ ipvs_gre_encap(struct net *net, struct sk_buff *skb,\n */\n int\n ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,\n+\t\t const struct nf_hook_state *state)\n {\n \tstruct netns_ipvs *ipvs = cp-\u003eipvs;\n \tstruct net *net = ipvs-\u003enet;\n@@ -1167,7 +1199,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n \t\t\t\t IP_VS_RT_MODE_LOCAL |\n \t\t\t\t IP_VS_RT_MODE_NON_LOCAL |\n \t\t\t\t IP_VS_RT_MODE_CONNECT |\n-\t\t\t\t IP_VS_RT_MODE_TUNNEL, \u0026saddr, ipvsh);\n+\t\t\t\t IP_VS_RT_MODE_TUNNEL, \u0026saddr, ipvsh, state);\n \tif (local \u003c 0)\n \t\tgoto tx_error;\n \tif (local)\n@@ -1276,7 +1308,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n \n \tret = ip_vs_tunnel_xmit_prepare(skb, cp);\n \tif (ret == NF_ACCEPT)\n-\t\tip_local_out(net, skb-\u003esk, skb);\n+\t\tip_local_out(net, NULL, skb);\n \telse if (ret == NF_DROP)\n \t\tkfree_skb(skb);\n \n@@ -1290,7 +1322,8 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n #ifdef CONFIG_IP_VS_IPV6\n int\n ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,\n+\t\t const struct nf_hook_state *state)\n {\n \tstruct netns_ipvs *ipvs = cp-\u003eipvs;\n \tstruct net *net = ipvs-\u003enet;\n@@ -1312,7 +1345,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n \t\t\t\t \u0026saddr, ipvsh, 1,\n \t\t\t\t IP_VS_RT_MODE_LOCAL |\n \t\t\t\t IP_VS_RT_MODE_NON_LOCAL |\n-\t\t\t\t IP_VS_RT_MODE_TUNNEL);\n+\t\t\t\t IP_VS_RT_MODE_TUNNEL, state);\n \tif (local \u003c 0)\n \t\tgoto tx_error;\n \tif (local)\n@@ -1418,7 +1451,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n \n \tret = ip_vs_tunnel_xmit_prepare(skb, cp);\n \tif (ret == NF_ACCEPT)\n-\t\tip6_local_out(net, skb-\u003esk, skb);\n+\t\tip6_local_out(net, NULL, skb);\n \telse if (ret == NF_DROP)\n \t\tkfree_skb(skb);\n \n@@ -1437,14 +1470,15 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n */\n int\n ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)\n+\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,\n+\t const struct nf_hook_state *state)\n {\n \tint local;\n \n \tlocal = __ip_vs_get_out_rt(cp-\u003eipvs, cp-\u003eaf, skb, cp-\u003edest, cp-\u003edaddr.ip,\n \t\t\t\t IP_VS_RT_MODE_LOCAL |\n \t\t\t\t IP_VS_RT_MODE_NON_LOCAL |\n-\t\t\t\t IP_VS_RT_MODE_KNOWN_NH, NULL, ipvsh);\n+\t\t\t\t IP_VS_RT_MODE_KNOWN_NH, NULL, ipvsh, state);\n \tif (local \u003c 0)\n \t\tgoto tx_error;\n \tif (local)\n@@ -1467,7 +1501,8 @@ ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n #ifdef CONFIG_IP_VS_IPV6\n int\n ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)\n+\t\t struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,\n+\t\t const struct nf_hook_state *state)\n {\n \tint local;\n \n@@ -1476,7 +1511,7 @@ ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n \t\t\t\t NULL, ipvsh, 0,\n \t\t\t\t IP_VS_RT_MODE_LOCAL |\n \t\t\t\t IP_VS_RT_MODE_NON_LOCAL |\n-\t\t\t\t IP_VS_RT_MODE_KNOWN_NH);\n+\t\t\t\t IP_VS_RT_MODE_KNOWN_NH, state);\n \tif (local \u003c 0)\n \t\tgoto tx_error;\n \tif (local)\n@@ -1503,7 +1538,7 @@ ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n int\n ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n \t\tstruct ip_vs_protocol *pp, unsigned int toff,\n-\t\tunsigned int hooknum, struct ip_vs_iphdr *ciph)\n+\t\tconst struct nf_hook_state *state, struct ip_vs_iphdr *ciph)\n {\n \tstruct rtable\t*rt;\t/* Route to the other host */\n \tint rc;\n@@ -1517,7 +1552,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n \t translate address/port back */\n \tif (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {\n \t\tif (cp-\u003epacket_xmit)\n-\t\t\trc = cp-\u003epacket_xmit(skb, cp, pp, ciph);\n+\t\t\trc = cp-\u003epacket_xmit(skb, cp, pp, ciph, state);\n \t\telse\n \t\t\trc = NF_ACCEPT;\n \t\t/* do not touch skb anymore */\n@@ -1531,11 +1566,11 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n \twas_input = rt_is_input_route(skb_rtable(skb));\n \n \t/* LOCALNODE from FORWARD hook is not supported */\n-\trt_mode = (hooknum != NF_INET_FORWARD) ?\n+\trt_mode = (state-\u003ehook != NF_INET_FORWARD) ?\n \t\t IP_VS_RT_MODE_LOCAL | IP_VS_RT_MODE_NON_LOCAL |\n \t\t IP_VS_RT_MODE_RDR : IP_VS_RT_MODE_NON_LOCAL;\n-\tlocal = __ip_vs_get_out_rt(cp-\u003eipvs, cp-\u003eaf, skb, cp-\u003edest, cp-\u003edaddr.ip, rt_mode,\n-\t\t\t\t NULL, ciph);\n+\tlocal = __ip_vs_get_out_rt(cp-\u003eipvs, cp-\u003eaf, skb, cp-\u003edest,\n+\t\t\t\t cp-\u003edaddr.ip, rt_mode, NULL, ciph, state);\n \tif (local \u003c 0)\n \t\tgoto tx_error;\n \trt = skb_rtable(skb);\n@@ -1597,8 +1632,8 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,\n #ifdef CONFIG_IP_VS_IPV6\n int\n ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n-\t\tstruct ip_vs_protocol *pp, unsigned int toff,\n-\t\tunsigned int hooknum, struct ip_vs_iphdr *ciph)\n+\t\t struct ip_vs_protocol *pp, unsigned int toff,\n+\t\t const struct nf_hook_state *state, struct ip_vs_iphdr *ciph)\n {\n \tbool has_ports = false;\n \tstruct rt6_info\t*rt;\t/* Route to the other host */\n@@ -1612,7 +1647,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n \t translate address/port back */\n \tif (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {\n \t\tif (cp-\u003epacket_xmit)\n-\t\t\trc = cp-\u003epacket_xmit(skb, cp, pp, ciph);\n+\t\t\trc = cp-\u003epacket_xmit(skb, cp, pp, ciph, state);\n \t\telse\n \t\t\trc = NF_ACCEPT;\n \t\t/* do not touch skb anymore */\n@@ -1625,11 +1660,12 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,\n \t */\n \n \t/* LOCALNODE from FORWARD hook is not supported */\n-\trt_mode = (hooknum != NF_INET_FORWARD) ?\n+\trt_mode = (state-\u003ehook != NF_INET_FORWARD) ?\n \t\t IP_VS_RT_MODE_LOCAL | IP_VS_RT_MODE_NON_LOCAL |\n \t\t IP_VS_RT_MODE_RDR : IP_VS_RT_MODE_NON_LOCAL;\n \tlocal = __ip_vs_get_out_rt_v6(cp-\u003eipvs, cp-\u003eaf, skb, cp-\u003edest,\n-\t\t\t\t \u0026cp-\u003edaddr.in6, NULL, ciph, 0, rt_mode);\n+\t\t\t\t \u0026cp-\u003edaddr.in6, NULL, ciph, 0, rt_mode,\n+\t\t\t\t state);\n \tif (local \u003c 0)\n \t\tgoto tx_error;\n \trt = dst_rt6_info(skb_dst(skb));\n"
} |
| 2/1 | 2026/11/17 07:46 | agent | patch-evaluator |
2mModel:core Args: null Results: {
"EnableConfigs": [
"IP_VS",
"IP_VS_IPV6",
"IP_VS_PROTO_TCP",
"IP_VS_PROTO_UDP",
"IP_VS_PROTO_SCTP",
"IP_VS_PROTO_AH",
"IP_VS_PROTO_ESP",
"IP_VS_FTP",
"IP_VS_LBLC",
"IP_VS_LBLCR",
"NF_CONNTRACK",
"NF_CONNTRACK_FTP",
"NF_NAT",
"IPV6"
],
"FocusSymbols": [
"ipv6_find_hdr",
"ip_vs_conn_expire",
"ip_vs_conn_expire_now",
"ip_vs_conn_out_get",
"ip_vs_dest_update_overload",
"ip_vs_add_dest",
"ip_vs_del_dest",
"ip_vs_leave",
"ip_vs_new_conn_out",
"ip_vs_ftp_out",
"ip_vs_ftp_in",
"ip_vs_sync_conn",
"ip_vs_lblc_schedule",
"ip_vs_lblcr_schedule",
"ip_vs_nat_xmit",
"ip_vs_tunnel_xmit"
],
"Reasoning": "The patch series modifies core networking code in IPVS and IPv6 extension header parsing. Changes include RCU grace-period synchronization when managing destination life cycles (trash/rehashing), lockdep assertions in destination lookups, refcount and timer synchronization overhauls in connection deletion/expiry, seqadj conntrack extension handling in the FTP helper, PMTU socket checks, and payload offset adjustments for IPv6 non-first fragments. All modified paths are reachable via standard networking and IPVS netlink/sockopt interfaces.",
"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 c4e0762c669a3125d192b6e9d305ae1e8a4bed4e
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Nov 17 07:46:41 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index 9a83bff32569da..fdb3a9063e6048 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -731,7 +731,8 @@ struct ip_vs_protocol {
int af, struct sk_buff *skb,
struct ip_vs_proto_data *pd,
int *verdict, struct ip_vs_conn **cpp,
- struct ip_vs_iphdr *iph);
+ struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
struct ip_vs_conn *
(*conn_in_get)(struct netns_ipvs *ipvs,
@@ -872,7 +873,8 @@ struct ip_vs_conn {
* NF_ACCEPT can be returned when destination is local.
*/
int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
struct rcu_head rcu_head;
};
@@ -1021,7 +1023,9 @@ struct ip_vs_dest {
struct rcu_head rcu_head;
struct list_head t_list; /* in dest_trash */
- unsigned int in_rs_table:1; /* we are in rs_table */
+ unsigned long rcu_state; /* GP cookie on unlink (trash or rehash) */
+ unsigned int in_rs_table:1, /* we are in rs_table */
+ need_gp:1; /* Need GP on rehash */
};
/* The scheduler object */
@@ -1685,7 +1689,6 @@ static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp)
/* put back the conn without restarting its timer */
static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
{
- smp_mb__before_atomic();
refcount_dec(&cp->refcnt);
}
void ip_vs_conn_put(struct ip_vs_conn *cp);
@@ -1871,7 +1874,8 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
struct ip_vs_proto_data *pd, int *ignored,
struct ip_vs_iphdr *iph);
int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
- struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph);
+ struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);
@@ -1923,7 +1927,7 @@ static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)
kfree(dest);
}
-void ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload);
+void ip_vs_dest_update_overload(struct ip_vs_dest *dest);
/* Check if dest is in overloaded state */
static inline bool ip_vs_dest_is_overloaded(const struct ip_vs_dest *dest)
@@ -1986,32 +1990,46 @@ static inline int ip_vs_est_max_threads(struct netns_ipvs *ipvs)
/* Various IPVS packet transmitters (from ip_vs_xmit.c) */
int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
struct ip_vs_protocol *pp, unsigned int toff,
- unsigned int hooknum, struct ip_vs_iphdr *ciph);
+ const struct nf_hook_state *state,
+ struct ip_vs_iphdr *ciph);
void ip_vs_dest_dst_rcu_free(struct rcu_head *head);
#ifdef CONFIG_IP_VS_IPV6
+int ip_vs_null_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
struct ip_vs_protocol *pp, unsigned int toff,
- unsigned int hooknum, struct ip_vs_iphdr *ciph);
+ const struct nf_hook_state *state,
+ struct ip_vs_iphdr *ciph);
#endif
#ifdef CONFIG_SYSCTL
diff --git a/net/ipv6/exthdrs_core.c b/net/ipv6/exthdrs_core.c
index 4a9748338cf400..e27f5b8cc15422 100644
--- a/net/ipv6/exthdrs_core.c
+++ b/net/ipv6/exthdrs_core.c
@@ -179,7 +179,10 @@ EXPORT_SYMBOL_GPL(ipv6_find_tlv);
*
* Note that non-1st fragment is special case that "the protocol number
* of last header" is "next header" field in Fragment header. In this case,
- * *offset is meaningless and fragment offset is stored in *fragoff if fragoff
+ * for target < 0, *offset points immediately after the Fragment header,
+ * at the start of the fragment payload. Callers must still account for
+ * the nonzero fragment offset before interpreting the payload. The
+ * fragment offset is stored in *fragoff if fragoff
* isn't NULL.
*
* if flags is not NULL and it's a fragment, then the frag flag
@@ -261,6 +264,7 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
hp->nexthdr == NEXTHDR_NONE)) {
if (fragoff)
*fragoff = _frag_off;
+ *offset = start + sizeof(struct frag_hdr);
return hp->nexthdr;
}
if (!found)
diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 94f25fb7d87e45..7cb8de634f5f9a 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -293,7 +293,6 @@ static inline int ip_vs_conn_hash(struct ip_vs_conn *cp)
cp->flags |= IP_VS_CONN_F_HASHED;
WRITE_ONCE(cp->hn0.hash_key, hash_key);
WRITE_ONCE(cp->hn1.hash_key, hash_key2);
- refcount_inc(&cp->refcnt);
hlist_bl_add_head_rcu(&cp->hn0.node, head);
if (use2)
hlist_bl_add_head_rcu(&cp->hn1.node, head2);
@@ -319,11 +318,27 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)
struct hlist_bl_head *head, *head2;
u32 hash_key, hash_key2;
struct ip_vs_rht *t;
- bool ret = false;
bool use2;
+ /* No more users and no running/pending timer except us? */
+ if (!refcount_dec_if_one(&cp->refcnt))
+ return false;
+
+ /* The ONE_PACKET connection is special:
+ * - the flag is present only for normal connections, not for templates
+ * - its timer is never started
+ * - it is never hashed, so you can not find it and delete it
+ * - it is not synced
+ * - it has only one user
+ * - it is freed after use immediately
+ */
if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
- return refcount_dec_if_one(&cp->refcnt);
+ return true;
+
+ /* Add the needed ACQUIRE barrier between the above
+ * refcount_dec_if_one() call and the read of cp fields
+ */
+ smp_acquire__after_ctrl_dep();
rcu_read_lock();
local_bh_disable();
@@ -337,15 +352,11 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)
false /* new_hash2 */, &head, &head2);
if (cp->flags & IP_VS_CONN_F_HASHED) {
- /* Decrease refcnt and unlink conn only if we are last user */
- if (use2 == ip_vs_conn_use_hash2(cp) &&
- refcount_dec_if_one(&cp->refcnt)) {
- hlist_bl_del_rcu(&cp->hn0.node);
- if (use2)
- hlist_bl_del_rcu(&cp->hn1.node);
- cp->flags &= ~IP_VS_CONN_F_HASHED;
- ret = true;
- }
+ /* Unlink conn as we are the last user */
+ hlist_bl_del_rcu(&cp->hn0.node);
+ if (use2)
+ hlist_bl_del_rcu(&cp->hn1.node);
+ cp->flags &= ~IP_VS_CONN_F_HASHED;
}
conn_tab_unlock(head, head2);
@@ -353,7 +364,7 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)
local_bh_enable();
rcu_read_unlock();
- return ret;
+ return true;
}
@@ -579,6 +590,8 @@ struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p)
ip_vs_addr_equal(p->af, p->vaddr,
&cp->caddr) &&
ip_vs_addr_equal(p->af, p->caddr, saddr) &&
+ (!p->vport ^
+ (!(cp->flags & IP_VS_CONN_F_NO_CPORT))) &&
p->protocol == cp->protocol) {
if (__ip_vs_conn_get(cp))
goto out;
@@ -621,9 +634,12 @@ static void __ip_vs_conn_put_timer(struct ip_vs_conn *cp)
{
unsigned long t = (cp->flags & IP_VS_CONN_F_ONE_PACKET) ?
0 : cp->timeout;
- mod_timer(&cp->timer, jiffies+t);
- __ip_vs_conn_put(cp);
+ /* Handoff our reference to the timer if it was just armed,
+ * put the reference if timer was already pending.
+ */
+ if (mod_timer(&cp->timer, jiffies + t))
+ __ip_vs_conn_put(cp);
}
void ip_vs_conn_put(struct ip_vs_conn *cp)
@@ -1041,7 +1057,7 @@ static inline void ip_vs_bind_xmit(struct ip_vs_conn *cp)
break;
case IP_VS_CONN_F_LOCALNODE:
- cp->packet_xmit = ip_vs_null_xmit;
+ cp->packet_xmit = ip_vs_null_xmit_v6;
break;
case IP_VS_CONN_F_BYPASS:
@@ -1154,7 +1170,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
atomic_inc(&dest->activeconns);
tc = atomic_inc_return(&dest->totalconns);
if (tc >= READ_ONCE(dest->u_threshold_val))
- ip_vs_dest_update_overload(dest, true);
+ ip_vs_dest_update_overload(dest);
} else {
/* It is a persistent connection/template, so increase
the persistent connection counter */
@@ -1247,7 +1263,7 @@ static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp)
atomic_dec(&dest->activeconns);
tc = atomic_fetch_dec(&dest->totalconns);
if (tc <= READ_ONCE(dest->l_threshold_val))
- ip_vs_dest_update_overload(dest, false);
+ ip_vs_dest_update_overload(dest);
} else {
/* It is a persistent connection/template, so decrease
the persistent connection counter */
@@ -1322,36 +1338,48 @@ static void ip_vs_conn_rcu_free(struct rcu_head *head)
kmem_cache_free(ip_vs_conn_cachep, cp);
}
-/* Try to delete connection while not holding reference */
-static void ip_vs_conn_del(struct ip_vs_conn *cp)
+/* Try to steal the reference from the pending timer.
+ * It can be called concurrently and always under RCU lock
+ * to protect from connection deletion from others.
+ */
+static bool ip_vs_conn_del_reference(struct ip_vs_conn *cp)
{
- if (timer_delete(&cp->timer)) {
- /* Drop cp->control chain too */
- if (cp->control)
- cp->timeout = 0;
- ip_vs_conn_expire(&cp->timer);
- }
+ /* Steal reference from the pending timer */
+ if (!timer_delete(&cp->timer))
+ return false;
+
+ /* Drop cp->control chain too */
+ if (cp->control)
+ cp->timeout = 0;
+ return true;
}
-/* Try to delete connection while holding reference */
-static void ip_vs_conn_del_put(struct ip_vs_conn *cp)
+/* Try to delete connection while not holding reference.
+ * Used when we need to remove the connection immediately
+ * and without overloading the timer processing.
+ * OTOH, we use ip_vs_conn_expire_now() when we prefer to
+ * leave the current context (packet processing) and to
+ * remove the connection from timer.
+ */
+static void ip_vs_conn_del(struct ip_vs_conn *cp)
{
- if (timer_delete(&cp->timer)) {
- /* Drop cp->control chain too */
- if (cp->control)
- cp->timeout = 0;
- __ip_vs_conn_put(cp);
+ if (ip_vs_conn_del_reference(cp))
ip_vs_conn_expire(&cp->timer);
- } else {
- __ip_vs_conn_put(cp);
- }
}
+/* Connection is removed in the following steps:
+ * - timer expires (with ref) or connection is deleted (with stolen ref)
+ * - there should be no more users except us (pending/running timer,
+ * n_control>0 or refcnt>1)
+ */
static void ip_vs_conn_expire(struct timer_list *t)
{
struct ip_vs_conn *cp = timer_container_of(cp, t, timer);
struct netns_ipvs *ipvs = cp->ipvs;
+ rcu_read_lock();
+
+repeat:
/*
* do I control anybody?
*/
@@ -1361,23 +1389,17 @@ static void ip_vs_conn_expire(struct timer_list *t)
/* Unlink conn if not referenced anymore */
if (likely(ip_vs_conn_unlink(cp))) {
struct ip_vs_conn *ct = cp->control;
-
- /* delete the timer if it is activated by other users */
- timer_delete(&cp->timer);
+ bool next = false;
/* does anybody control me? */
if (ct) {
- bool has_ref = !cp->timeout && __ip_vs_conn_get(ct);
-
ip_vs_control_del(cp);
/* Drop CTL or non-assured TPL if not used anymore */
- if (has_ref && !atomic_read(&ct->n_control) &&
+ if (!cp->timeout && !atomic_read(&ct->n_control) &&
(!(ct->flags & IP_VS_CONN_F_TEMPLATE) ||
!(ct->state & IP_VS_CTPL_S_ASSURED))) {
IP_VS_DBG(4, "drop controlling connection\n");
- ip_vs_conn_del_put(ct);
- } else if (has_ref) {
- __ip_vs_conn_put(ct);
+ next = ip_vs_conn_del_reference(ct);
}
}
@@ -1405,7 +1427,11 @@ static void ip_vs_conn_expire(struct timer_list *t)
else
call_rcu(&cp->rcu_head, ip_vs_conn_rcu_free);
atomic_dec(&ipvs->conn_count);
- return;
+ if (next) {
+ cp = ct;
+ goto repeat;
+ }
+ goto out;
}
expire_later:
@@ -1413,13 +1439,16 @@ static void ip_vs_conn_expire(struct timer_list *t)
refcount_read(&cp->refcnt),
atomic_read(&cp->n_control));
- refcount_inc(&cp->refcnt);
- cp->timeout = 60*HZ;
+ if (cp->timeout || atomic_read(&cp->n_control))
+ cp->timeout = 60 * HZ;
if (ipvs->sync_state & IP_VS_STATE_MASTER)
ip_vs_sync_conn(ipvs, cp, sysctl_sync_threshold(ipvs));
__ip_vs_conn_put_timer(cp);
+
+out:
+ rcu_read_unlock();
}
/* Modify timer, so that it expires as soon as possible.
@@ -1432,7 +1461,7 @@ static void ip_vs_conn_expire(struct timer_list *t)
void ip_vs_conn_expire_now(struct ip_vs_conn *cp)
{
/* Using mod_timer_pending will ensure the timer is not
- * modified after the final timer_delete in ip_vs_conn_expire.
+ * started without giving it new reference.
*/
if (timer_pending(&cp->timer) &&
time_after(cp->timer.expires, jiffies))
@@ -1500,9 +1529,9 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
spin_lock_init(&cp->lock);
/*
- * Set the entry is referenced by the current thread before hashing
- * it in the table, so that other thread run ip_vs_random_dropentry
- * but cannot drop this entry.
+ * Set the entry as referenced by the current thread before starting
+ * the timer and giving it our reference to allow other threads to
+ * run ip_vs_random_dropentry() or any deletion method safely.
*/
refcount_set(&cp->refcnt, 1);
diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
index 8a3c880fdb266e..85ea82367cfe32 100644
--- a/net/netfilter/ipvs/ip_vs_core.c
+++ b/net/netfilter/ipvs/ip_vs_core.c
@@ -760,7 +760,8 @@ static inline int ip_vs_addr_is_unicast(struct net *net, int af,
* no destination is available for a new connection.
*/
int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
- struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph)
+ struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state)
{
__be16 _ports[2], *pptr, dport;
struct netns_ipvs *ipvs = svc->ipvs;
@@ -805,7 +806,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
ip_vs_set_state(cp, IP_VS_DIR_INPUT, skb, pd, iph->len);
/* transmit the first SYN packet */
- ret = cp->packet_xmit(skb, cp, pd->pp, iph);
+ ret = cp->packet_xmit(skb, cp, pd->pp, iph, state);
/* do not touch skb anymore */
if ((cp->flags & IP_VS_CONN_F_ONE_PACKET) && cp->control)
@@ -1206,6 +1207,13 @@ static int ip_vs_out_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,
true, &ciph))
return NF_ACCEPT; /* The packet looks wrong, ignore */
+ /* ipv6_find_hdr() does not include the embedded header for
+ * non-first fragments, add it so that ESP can pass and the
+ * NAT writable checks cover the rewritten addresses
+ */
+ if (ciph.len == ciph.off)
+ ciph.len += sizeof(struct ipv6hdr);
+
pp = ip_vs_proto_get(ciph.protocol);
if (!pp)
return NF_ACCEPT;
@@ -1305,6 +1313,7 @@ static inline bool is_new_conn_expected(const struct ip_vs_conn *cp,
* In fwmark-VS actual vaddr and vport are unknown to IPVS
* 2) Real Server and Virtual Service were NOT configured without port:
* This is to allow match of different VS to the same RS ip-addr
+ * 3) Client port is not 0
*/
struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
struct ip_vs_dest *dest,
@@ -1328,7 +1337,7 @@ struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
/* check pre-requisites are satisfied */
if (svc->fwmark)
return NULL;
- if (!vport || !dport)
+ if (!vport || !dport || !cport)
return NULL;
/* for persistent service first create connection template */
@@ -1647,7 +1656,8 @@ static unsigned int
ip_vs_try_to_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
struct ip_vs_proto_data *pd,
int *verdict, struct ip_vs_conn **cpp,
- struct ip_vs_iphdr *iph)
+ struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state)
{
struct ip_vs_protocol *pp = pd->pp;
@@ -1657,7 +1667,8 @@ ip_vs_try_to_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
*/
/* Schedule and create new connection entry into cpp */
- if (!pp->conn_schedule(ipvs, af, skb, pd, verdict, cpp, iph))
+ if (!pp->conn_schedule(ipvs, af, skb, pd, verdict, cpp, iph,
+ state))
return 0;
}
@@ -1757,7 +1768,7 @@ static int ipvs_gre_decap(struct netns_ipvs *ipvs, struct sk_buff *skb,
*/
static int
ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,
- unsigned int hooknum, struct ip_vs_iphdr *iph)
+ const struct nf_hook_state *state, struct ip_vs_iphdr *iph)
{
struct icmphdr _icmph, *ic;
struct iphdr _ciph, *cih; /* The ip header contained within the ICMP */
@@ -1776,7 +1787,8 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,
/* reassemble IP fragments */
if (ip_is_fragment(ip_hdr(skb))) {
- if (ip_vs_gather_frags(ipvs, skb, ip_vs_defrag_user(hooknum)))
+ if (ip_vs_gather_frags(ipvs, skb,
+ ip_vs_defrag_user(state->hook)))
return NF_STOLEN;
if (!ip_vs_fill_iph_skb(AF_INET, skb, false, iph))
return NF_ACCEPT;
@@ -1893,7 +1905,8 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,
if (tunnel || !sysctl_schedule_icmp(ipvs))
return NF_ACCEPT;
- if (!ip_vs_try_to_schedule(ipvs, AF_INET, skb, pd, &v, &cp, &ciph))
+ if (!ip_vs_try_to_schedule(ipvs, AF_INET, skb, pd, &v, &cp,
+ &ciph, state))
return v;
new_cp = true;
}
@@ -1981,7 +1994,7 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,
/* do the statistics and put it back */
ip_vs_in_stats(cp, skb);
- verdict = ip_vs_icmp_xmit(skb, cp, pp, iph->len, hooknum, &ciph);
+ verdict = ip_vs_icmp_xmit(skb, cp, pp, iph->len, state, &ciph);
out:
if (likely(!new_cp))
@@ -1994,7 +2007,7 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,
#ifdef CONFIG_IP_VS_IPV6
static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,
- int *related, unsigned int hooknum,
+ int *related, const struct nf_hook_state *state,
struct ip_vs_iphdr *iph)
{
struct icmp6hdr _icmph, *ic;
@@ -2036,6 +2049,13 @@ static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,
if (!ip_vs_fill_iph_skb_icmp(AF_INET6, skb, offset, true, &ciph))
return NF_ACCEPT;
+ /* ipv6_find_hdr() does not include the embedded header for
+ * non-first fragments, add it so that ESP can pass and the
+ * NAT writable checks cover the rewritten addresses
+ */
+ if (ciph.len == ciph.off)
+ ciph.len += sizeof(struct ipv6hdr);
+
pd = ip_vs_proto_data_get(ipvs, ciph.protocol);
if (!pd)
return NF_ACCEPT;
@@ -2060,7 +2080,8 @@ static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,
if (!sysctl_schedule_icmp(ipvs))
return NF_ACCEPT;
- if (!ip_vs_try_to_schedule(ipvs, AF_INET6, skb, pd, &v, &cp, &ciph))
+ if (!ip_vs_try_to_schedule(ipvs, AF_INET6, skb, pd, &v, &cp,
+ &ciph, state))
return v;
new_cp = true;
@@ -2081,7 +2102,7 @@ static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,
/* do the statistics and put it back */
ip_vs_in_stats(cp, skb);
- verdict = ip_vs_icmp_xmit_v6(skb, cp, pp, iph->len, hooknum, &ciph);
+ verdict = ip_vs_icmp_xmit_v6(skb, cp, pp, iph->len, state, &ciph);
out:
if (likely(!new_cp))
@@ -2150,7 +2171,7 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state
if (unlikely(iph.protocol == IPPROTO_ICMPV6)) {
int related;
int verdict = ip_vs_in_icmp_v6(ipvs, skb, &related,
- hooknum, &iph);
+ state, &iph);
if (related)
return verdict;
@@ -2160,7 +2181,7 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state
if (unlikely(iph.protocol == IPPROTO_ICMP)) {
int related;
int verdict = ip_vs_in_icmp(ipvs, skb, &related,
- hooknum, &iph);
+ state, &iph);
if (related)
return verdict;
@@ -2248,7 +2269,8 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state
if (unlikely(!cp)) {
int v;
- if (!ip_vs_try_to_schedule(ipvs, af, skb, pd, &v, &cp, &iph))
+ if (!ip_vs_try_to_schedule(ipvs, af, skb, pd, &v, &cp, &iph,
+ state))
return v;
}
@@ -2257,7 +2279,7 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state
ip_vs_in_stats(cp, skb);
ip_vs_set_state(cp, IP_VS_DIR_INPUT, skb, pd, iph.len);
if (cp->packet_xmit)
- ret = cp->packet_xmit(skb, cp, pp, &iph);
+ ret = cp->packet_xmit(skb, cp, pp, &iph, state);
/* do not touch skb anymore */
else {
IP_VS_DBG_RL("warning: packet_xmit is null");
@@ -2320,11 +2342,11 @@ ip_vs_forward_icmp(void *priv, struct sk_buff *skb,
if (iphdr.protocol != IPPROTO_ICMPV6)
return NF_ACCEPT;
- return ip_vs_in_icmp_v6(ipvs, skb, &r, state->hook, &iphdr);
+ return ip_vs_in_icmp_v6(ipvs, skb, &r, state, &iphdr);
#endif
}
- return ip_vs_in_icmp(ipvs, skb, &r, state->hook, &iphdr);
+ return ip_vs_in_icmp(ipvs, skb, &r, state, &iphdr);
}
static const struct nf_hook_ops ip_vs_ops4[] = {
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index ce9fe20d6106a8..be818bf7d3806c 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -64,7 +64,8 @@ int ip_vs_get_debug_level(void)
/* Protos */
-static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup);
+static void __ip_vs_del_service(struct ip_vs_service *svc,
+ struct list_head *dest_trash, bool cleanup);
#ifdef CONFIG_IP_VS_IPV6
@@ -918,6 +919,11 @@ static void ip_vs_rs_hash(struct netns_ipvs *ipvs, struct ip_vs_dest *dest)
*/
hash = ip_vs_rs_hashkey(dest->af, &dest->addr, port);
+ /* Need RCU grace period when rehashing */
+ if (dest->need_gp) {
+ cond_synchronize_rcu(dest->rcu_state);
+ dest->need_gp = 0;
+ }
hlist_add_head_rcu(&dest->d_list, &ipvs->rs_table[hash]);
dest->in_rs_table = 1;
}
@@ -1111,6 +1117,8 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af,
struct ip_vs_dest *dest;
struct netns_ipvs *ipvs = svc->ipvs;
+ lockdep_assert_held(&ipvs->service_mutex);
+
/*
* Find the destination in trash
*/
@@ -1144,24 +1152,57 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af,
return dest;
}
-/* Put destination in trash */
-static void ip_vs_trash_put_dest(struct netns_ipvs *ipvs,
+/* Add destination in temp list for trash */
+static void ip_vs_trash_add_dest(struct netns_ipvs *ipvs,
struct ip_vs_dest *dest, unsigned long istart,
- bool cleanup)
+ struct list_head *dest_trash)
{
- spin_lock_bh(&ipvs->dest_trash_lock);
IP_VS_DBG_BUF(3, "Moving dest %s:%u into trash, dest->refcnt=%d\n",
IP_VS_DBG_ADDR(dest->af, &dest->addr), ntohs(dest->port),
refcount_read(&dest->refcnt));
+ /* dest lives in trash with reference */
+ list_add(&dest->t_list, dest_trash);
+ dest->idle_start = istart;
+}
+
+/* Put destinations in trash */
+static void ip_vs_trash_put_dests(struct netns_ipvs *ipvs,
+ struct list_head *dest_trash, bool cleanup)
+{
+ spin_lock_bh(&ipvs->dest_trash_lock);
if (list_empty(&ipvs->dest_trash) && !cleanup)
mod_timer(&ipvs->dest_trash_timer,
jiffies + (IP_VS_DEST_TRASH_PERIOD >> 1));
- /* dest lives in trash with reference */
- list_add(&dest->t_list, &ipvs->dest_trash);
- dest->idle_start = istart;
+ list_splice(dest_trash, &ipvs->dest_trash);
spin_unlock_bh(&ipvs->dest_trash_lock);
}
+/* Put destination back in trash */
+static void ip_vs_trash_put_back(struct netns_ipvs *ipvs,
+ struct ip_vs_dest *dest)
+{
+ LIST_HEAD(dest_trash);
+
+ ip_vs_trash_add_dest(ipvs, dest, dest->idle_start, &dest_trash);
+ ip_vs_trash_put_dests(ipvs, &dest_trash, false);
+}
+
+/* Put destinations in trash and save the RCU state */
+static void ip_vs_trash_save_dests(struct netns_ipvs *ipvs,
+ struct list_head *dest_trash, bool cleanup)
+{
+ struct ip_vs_dest *dest;
+ unsigned long rcu_state;
+
+ if (!list_empty(dest_trash)) {
+ /* Remember when dests were removed and added to dest_trash */
+ rcu_state = get_state_synchronize_rcu();
+ list_for_each_entry(dest, dest_trash, t_list)
+ dest->rcu_state = rcu_state;
+ ip_vs_trash_put_dests(ipvs, dest_trash, cleanup);
+ }
+}
+
static void ip_vs_dest_rcu_free(struct rcu_head *head)
{
struct ip_vs_dest *dest;
@@ -1304,12 +1345,12 @@ void ip_vs_stats_free(struct ip_vs_stats *stats)
}
}
-/* Update overload flag based on number of dest conns and lower/upper
+/* Update overload state based on number of dest conns and lower/upper
* connection thresholds:
- * - conns reach u_threshold and exceed it: set the flag
- * - conns go below l_threshold (or 75% of u_threshold): clear the flag
+ * - conns reach u_threshold and exceed it: set the overload state
+ * - conns go below l_threshold (or 75% of u_threshold): clear the state
*/
-static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)
+static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest)
{
int conns;
u32 l, u;
@@ -1320,10 +1361,18 @@ static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)
/* Low threshold defaults to 75% of upper threshold */
l = READ_ONCE(dest->l_threshold) ? : (u - (u >> 2));
conns = atomic_read(&dest->totalconns);
- if (conns >= (overload ? l : u)) {
+ if (conns >= (ip_vs_dest_is_overloaded(dest) ? l : u)) {
WRITE_ONCE(dest->u_threshold_val, INT_MAX);
WRITE_ONCE(dest->l_threshold_val, l);
- return;
+ /* Commit thresholds before repeating the check,
+ * it is paired with atomic_fetch_dec() in
+ * ip_vs_unbind_dest() to avoid entering the
+ * overload state forever.
+ */
+ smp_mb();
+ conns = atomic_read(&dest->totalconns);
+ if (conns >= l)
+ return;
}
}
@@ -1331,10 +1380,10 @@ static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)
WRITE_ONCE(dest->l_threshold_val, 0);
}
-void ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)
+void ip_vs_dest_update_overload(struct ip_vs_dest *dest)
{
spin_lock_bh(&dest->dst_lock);
- __ip_vs_dest_update_overload(dest, overload);
+ __ip_vs_dest_update_overload(dest);
spin_unlock_bh(&dest->dst_lock);
}
@@ -1369,8 +1418,16 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
if ((udest->conn_flags & IP_VS_CONN_F_FWD_MASK) !=
IP_VS_DFWD_METHOD(dest) ||
udest->tun_type != dest->tun_type ||
- udest->tun_port != dest->tun_port)
+ udest->tun_port != dest->tun_port) {
+ bool unlinked = dest->in_rs_table;
+
ip_vs_rs_unhash(dest);
+ if (unlinked) {
+ dest->rcu_state = get_state_synchronize_rcu();
+ /* Need grace period in this or next dest update */
+ dest->need_gp = 1;
+ }
+ }
/* set the tunnel info */
dest->tun_type = udest->tun_type;
@@ -1406,13 +1463,10 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
if (READ_ONCE(dest->u_threshold) != udest->u_threshold ||
READ_ONCE(dest->l_threshold) != udest->l_threshold) {
- bool overload;
-
spin_lock_bh(&dest->dst_lock);
WRITE_ONCE(dest->u_threshold, udest->u_threshold);
WRITE_ONCE(dest->l_threshold, udest->l_threshold);
- overload = ip_vs_dest_is_overloaded(dest);
- __ip_vs_dest_update_overload(dest, overload);
+ __ip_vs_dest_update_overload(dest);
spin_unlock_bh(&dest->dst_lock);
}
@@ -1477,6 +1531,7 @@ ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
if (ret < 0)
goto err_stats;
+ dest->u_threshold_val = INT_MAX;
dest->af = udest->af;
dest->protocol = svc->protocol;
dest->vaddr = svc->addr;
@@ -1556,6 +1611,11 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
dest = ip_vs_trash_get_dest(svc, udest->af, &daddr, dport);
if (dest != NULL) {
+ /* Readers may still follow the n_list, d_list or estimator list
+ * links. Wait before reusing any of them.
+ */
+ cond_synchronize_rcu(dest->rcu_state);
+
IP_VS_DBG_BUF(3, "Get destination %s:%u from trash, "
"dest->refcnt=%d, service %u/%s:%u\n",
IP_VS_DBG_ADDR(udest->af, &daddr), ntohs(dport),
@@ -1566,11 +1626,14 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
ret = ip_vs_start_estimator(svc->ipvs, &dest->stats);
/* On error put back dest into the trash */
- if (ret < 0)
- ip_vs_trash_put_dest(svc->ipvs, dest, dest->idle_start,
- false);
- else
+ if (ret < 0) {
+ ip_vs_trash_put_back(svc->ipvs, dest);
+ } else {
+ /* need_gp matters only on dest edit, reinit it */
+ dest->need_gp = 0;
+
__ip_vs_update_dest(svc, dest, udest, 1);
+ }
} else {
/*
* Allocate and initialize the dest structure
@@ -1634,7 +1697,7 @@ ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
* Delete a destination (must be already unlinked from the service)
*/
static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest,
- bool cleanup)
+ struct list_head *dest_trash, bool cleanup)
{
ip_vs_stop_estimator(ipvs, &dest->stats);
@@ -1643,7 +1706,7 @@ static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest,
*/
ip_vs_rs_unhash(dest);
- ip_vs_trash_put_dest(ipvs, dest, 0, cleanup);
+ ip_vs_trash_add_dest(ipvs, dest, 0, dest_trash);
/* Queue up delayed work to expire all no destination connections.
* No-op when CONFIG_SYSCTL is disabled.
@@ -1693,6 +1756,7 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
{
struct ip_vs_dest *dest;
__be16 dport = udest->port;
+ LIST_HEAD(dest_trash);
/* We use function that requires RCU lock */
rcu_read_lock();
@@ -1712,7 +1776,9 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
/*
* Delete the destination
*/
- __ip_vs_del_dest(svc->ipvs, dest, false);
+ __ip_vs_del_dest(svc->ipvs, dest, &dest_trash, false);
+
+ ip_vs_trash_save_dests(svc->ipvs, &dest_trash, false);
return 0;
}
@@ -2057,7 +2123,8 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)
* - The service must be unlinked, unlocked and not referenced!
* - We are called under _bh lock
*/
-static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)
+static void __ip_vs_del_service(struct ip_vs_service *svc,
+ struct list_head *dest_trash, bool cleanup)
{
struct ip_vs_dest *dest, *nxt;
struct ip_vs_scheduler *old_sched;
@@ -2091,7 +2158,7 @@ static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)
*/
list_for_each_entry_safe(dest, nxt, &svc->destinations, n_list) {
__ip_vs_unlink_dest(svc, dest, 0);
- __ip_vs_del_dest(svc->ipvs, dest, cleanup);
+ __ip_vs_del_dest(svc->ipvs, dest, dest_trash, cleanup);
}
/*
@@ -2114,7 +2181,8 @@ static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)
/*
* Unlink a service from list and try to delete it if its refcnt reached 0
*/
-static void ip_vs_unlink_service(struct ip_vs_service *svc, bool cleanup)
+static void ip_vs_unlink_service(struct ip_vs_service *svc,
+ struct list_head *dest_trash, bool cleanup)
{
ip_vs_unregister_conntrack(svc);
/* Hold svc to avoid double release from dest_trash */
@@ -2124,7 +2192,7 @@ static void ip_vs_unlink_service(struct ip_vs_service *svc, bool cleanup)
*/
ip_vs_svc_unhash(svc);
- __ip_vs_del_service(svc, cleanup);
+ __ip_vs_del_service(svc, dest_trash, cleanup);
}
/*
@@ -2134,12 +2202,14 @@ static int ip_vs_del_service(struct ip_vs_service *svc)
{
struct netns_ipvs *ipvs;
struct ip_vs_rht *t, *p;
+ LIST_HEAD(dest_trash);
int ns;
if (svc == NULL)
return -EEXIST;
ipvs = svc->ipvs;
- ip_vs_unlink_service(svc, false);
+ ip_vs_unlink_service(svc, &dest_trash, false);
+ ip_vs_trash_save_dests(ipvs, &dest_trash, false);
/* Drop the table if no more services */
ns = ip_vs_get_num_services(ipvs);
@@ -2190,6 +2260,7 @@ static int ip_vs_flush(struct netns_ipvs *ipvs, bool cleanup)
struct hlist_bl_node *ne;
struct hlist_bl_node *e;
struct ip_vs_rht *t, *p;
+ LIST_HEAD(dest_trash);
/* Stop the resizer and drop the tables */
if (!test_and_set_bit(IP_VS_WORK_SVC_NORESIZE, &ipvs->work_flags))
@@ -2199,8 +2270,9 @@ static int ip_vs_flush(struct netns_ipvs *ipvs, bool cleanup)
if (ip_vs_get_num_services(ipvs)) {
ip_vs_rht_walk_buckets(ipvs->svc_table, head) {
hlist_bl_for_each_entry_safe(svc, e, ne, head, s_list)
- ip_vs_unlink_service(svc, cleanup);
+ ip_vs_unlink_service(svc, &dest_trash, cleanup);
}
+ ip_vs_trash_save_dests(ipvs, &dest_trash, cleanup);
}
/* Unregister the hash table and release it after RCU grace period */
diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c
index 9e3e005a826353..81c3a2fd27b397 100644
--- a/net/netfilter/ipvs/ip_vs_ftp.c
+++ b/net/netfilter/ipvs/ip_vs_ftp.c
@@ -29,6 +29,7 @@
#include <linux/netfilter.h>
#include <net/netfilter/nf_conntrack.h>
#include <net/netfilter/nf_conntrack_expect.h>
+#include <net/netfilter/nf_conntrack_seqadj.h>
#include <net/netfilter/nf_nat.h>
#include <net/netfilter/nf_nat_helper.h>
#include <linux/gfp.h>
@@ -62,6 +63,17 @@ static unsigned short ports[IP_VS_APP_MAX_PORTS] = {21, 0};
module_param_array(ports, ushort, &ports_count, 0444);
MODULE_PARM_DESC(ports, "Ports to monitor for FTP control commands");
+static bool is_control_port(u16 port)
+{
+ unsigned int i;
+
+ for (i = 0; i < ports_count; i++) {
+ if (ports[i] == port)
+ return true;
+ }
+ return false;
+}
+
static char *ip_vs_ftp_data_ptr(struct sk_buff *skb, struct ip_vs_iphdr *ipvsh)
{
@@ -319,6 +331,10 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
return 1;
}
+ /* Do not redirect data to control ports */
+ if (!port || is_control_port(ntohs(port)))
+ return 0;
+
/* Now update or create a connection entry for it */
{
struct ip_vs_conn_param p;
@@ -368,20 +384,26 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
buf_len = strlen(buf);
ct = nf_ct_get(skb, &ctinfo);
- if (ct) {
- bool mangled;
+ if (ct && !nf_ct_is_template(ct)) {
+ bool mangled = false;
/* If mangling fails this function will return 0
* which will cause the packet to be dropped.
* Mangling can only fail under memory pressure,
* hopefully it will succeed on the retransmitted
* packet.
+ *
+ * Add the seqadj extension before the expectation is
+ * linked into the helper extension: adding it later
+ * reallocates ct->ext under the expectation list.
*/
- mangled = nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
- ipvsh->len,
- start - data,
- end - start,
- buf, buf_len);
+ if (nf_ct_is_confirmed(ct) || nfct_seqadj(ct) ||
+ nfct_seqadj_ext_add(ct))
+ mangled = nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
+ ipvsh->len,
+ start - data,
+ end - start,
+ buf, buf_len);
if (mangled) {
ip_vs_nfct_expect_related(skb, ct, n_cp,
ipvsh->protocol, 0, 0);
@@ -529,6 +551,9 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,
return 1;
}
+ if (!port || is_control_port(ntohs(cp->vport) - 1))
+ return 0;
+
/* Passive mode off */
cp->app_data = (void *) IP_VS_FTP_ACTIVE;
diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
index e1111c3b27211a..f5ce1f2afb8606 100644
--- a/net/netfilter/ipvs/ip_vs_lblc.c
+++ b/net/netfilter/ipvs/ip_vs_lblc.c
@@ -467,10 +467,11 @@ is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc)
struct ip_vs_dest *d;
list_for_each_entry_rcu(d, &svc->destinations, n_list) {
- if (atomic_read(&d->activeconns)*2
- < atomic_read(&d->weight)) {
+ if (ip_vs_dest_is_overloaded(d))
+ continue;
+ if (atomic_read(&d->activeconns) * 2 <
+ atomic_read(&d->weight))
return 1;
- }
}
}
return 0;
@@ -507,6 +508,7 @@ ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
dest = en->dest;
if ((dest->cflags & IP_VS_DEST_CF_AVAILABLE) &&
+ !ip_vs_dest_is_overloaded(dest) &&
atomic_read(&dest->weight) > 0 && !is_overloaded(dest, svc))
goto out;
}
diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
index dfb5bf83750dba..4046608922e7cb 100644
--- a/net/netfilter/ipvs/ip_vs_lblcr.c
+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
@@ -630,10 +630,11 @@ is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc)
struct ip_vs_dest *d;
list_for_each_entry_rcu(d, &svc->destinations, n_list) {
- if (atomic_read(&d->activeconns)*2
- < atomic_read(&d->weight)) {
+ if (ip_vs_dest_is_overloaded(d))
+ continue;
+ if (atomic_read(&d->activeconns) * 2 <
+ atomic_read(&d->weight))
return 1;
- }
}
}
return 0;
@@ -658,9 +659,6 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
if (en) {
en->lastuse = jiffies;
- /* Get the least loaded destination */
- dest = ip_vs_dest_set_min(&en->set);
-
/* More than one destination + enough time passed by, cleanup */
if (atomic_read(&en->set.size) > 1 &&
time_after(jiffies, en->set.lastmod +
@@ -676,6 +674,9 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
spin_unlock_bh(&svc->sched_lock);
}
+ /* Get the least loaded destination */
+ dest = ip_vs_dest_set_min(&en->set);
+
/* If the destination is not overloaded, use it */
if (dest && !is_overloaded(dest, svc))
goto out;
diff --git a/net/netfilter/ipvs/ip_vs_proto_ah_esp.c b/net/netfilter/ipvs/ip_vs_proto_ah_esp.c
index 44e14acc187ee3..c7f90b29be51b3 100644
--- a/net/netfilter/ipvs/ip_vs_proto_ah_esp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_ah_esp.c
@@ -102,7 +102,7 @@ static int
ah_esp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
struct ip_vs_proto_data *pd,
int *verdict, struct ip_vs_conn **cpp,
- struct ip_vs_iphdr *iph)
+ struct ip_vs_iphdr *iph, const struct nf_hook_state *state)
{
/*
* AH/ESP is only related traffic. Pass the packet to IP stack.
diff --git a/net/netfilter/ipvs/ip_vs_proto_sctp.c b/net/netfilter/ipvs/ip_vs_proto_sctp.c
index fb8af6b15a3999..3d773c881f75aa 100644
--- a/net/netfilter/ipvs/ip_vs_proto_sctp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_sctp.c
@@ -17,7 +17,7 @@ static int
sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
struct ip_vs_proto_data *pd,
int *verdict, struct ip_vs_conn **cpp,
- struct ip_vs_iphdr *iph)
+ struct ip_vs_iphdr *iph, const struct nf_hook_state *state)
{
struct ip_vs_service *svc;
struct sctp_chunkhdr _schunkh, *sch;
@@ -30,6 +30,7 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
sch = skb_header_pointer(skb, iph->len + sizeof(_sctph),
sizeof(_schunkh), &_schunkh);
if (sch) {
+ /* Accept packet without scheduling? */
if (sch->type == SCTP_CID_ABORT ||
!(sysctl_sloppy_sctp(ipvs) ||
sch->type == SCTP_CID_INIT))
@@ -56,6 +57,12 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
if (svc) {
int ignored;
+ /* Do not create connection for port 0 */
+ if (!ports[0] || !ports[1]) {
+ *verdict = NF_DROP;
+ return 0;
+ }
+
if (ip_vs_todrop(ipvs)) {
/*
* It seems that we are very loaded.
@@ -71,7 +78,8 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
*cpp = ip_vs_schedule(svc, skb, pd, &ignored, iph);
if (!*cpp && ignored <= 0) {
if (!ignored)
- *verdict = ip_vs_leave(svc, skb, pd, iph);
+ *verdict = ip_vs_leave(svc, skb, pd, iph,
+ state);
else
*verdict = NF_DROP;
return 0;
diff --git a/net/netfilter/ipvs/ip_vs_proto_tcp.c b/net/netfilter/ipvs/ip_vs_proto_tcp.c
index fec0e8b47b7165..13ac917a0ac8d1 100644
--- a/net/netfilter/ipvs/ip_vs_proto_tcp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_tcp.c
@@ -35,7 +35,7 @@ static int
tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
struct ip_vs_proto_data *pd,
int *verdict, struct ip_vs_conn **cpp,
- struct ip_vs_iphdr *iph)
+ struct ip_vs_iphdr *iph, const struct nf_hook_state *state)
{
struct ip_vs_service *svc;
struct tcphdr _tcph, *th;
@@ -48,6 +48,7 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
if (likely(!ip_vs_iph_icmp(iph))) {
th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph);
if (th) {
+ /* Accept packet without scheduling? */
if (th->rst || !(sysctl_sloppy_tcp(ipvs) || th->syn))
return 1;
ports = &th->source;
@@ -74,6 +75,12 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
if (svc) {
int ignored;
+ /* Do not create connection for port 0 */
+ if (!ports[0] || !ports[1]) {
+ *verdict = NF_DROP;
+ return 0;
+ }
+
if (ip_vs_todrop(ipvs)) {
/*
* It seems that we are very loaded.
@@ -90,7 +97,8 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
*cpp = ip_vs_schedule(svc, skb, pd, &ignored, iph);
if (!*cpp && ignored <= 0) {
if (!ignored)
- *verdict = ip_vs_leave(svc, skb, pd, iph);
+ *verdict = ip_vs_leave(svc, skb, pd, iph,
+ state);
else
*verdict = NF_DROP;
return 0;
diff --git a/net/netfilter/ipvs/ip_vs_proto_udp.c b/net/netfilter/ipvs/ip_vs_proto_udp.c
index f32785682402dd..760b019e6a06d4 100644
--- a/net/netfilter/ipvs/ip_vs_proto_udp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_udp.c
@@ -31,7 +31,7 @@ static int
udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
struct ip_vs_proto_data *pd,
int *verdict, struct ip_vs_conn **cpp,
- struct ip_vs_iphdr *iph)
+ struct ip_vs_iphdr *iph, const struct nf_hook_state *state)
{
struct ip_vs_service *svc;
struct udphdr _udph, *uh;
@@ -62,6 +62,12 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
if (svc) {
int ignored;
+ /* Do not create connection for port 0 */
+ if (!ports[0] || !ports[1]) {
+ *verdict = NF_DROP;
+ return 0;
+ }
+
if (ip_vs_todrop(ipvs)) {
/*
* It seems that we are very loaded.
@@ -78,7 +84,8 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
*cpp = ip_vs_schedule(svc, skb, pd, &ignored, iph);
if (!*cpp && ignored <= 0) {
if (!ignored)
- *verdict = ip_vs_leave(svc, skb, pd, iph);
+ *verdict = ip_vs_leave(svc, skb, pd, iph,
+ state);
else
*verdict = NF_DROP;
return 0;
diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
index 157f5c8361ab46..7e562e745ab5d5 100644
--- a/net/netfilter/ipvs/ip_vs_sync.c
+++ b/net/netfilter/ipvs/ip_vs_sync.c
@@ -539,6 +539,7 @@ static int ip_vs_sync_conn_needed(struct netns_ipvs *ipvs,
static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,
int pkts)
{
+ struct ip_vs_sync_conn_options opts;
struct ip_vs_sync_mesg_v0 *m;
struct ip_vs_sync_conn_v0 *s;
struct ip_vs_sync_buff *buff;
@@ -557,6 +558,14 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,
if (!ip_vs_sync_conn_needed(ipvs, cp, pkts))
return;
+ if (flags & IP_VS_CONN_F_SEQ_MASK) {
+ /* Take atomic snapshot of flags and seqs */
+ spin_lock_bh(&cp->lock);
+ flags = cp->flags;
+ memcpy(&opts, &cp->sync_conn_opt, sizeof(opts));
+ spin_unlock_bh(&cp->lock);
+ }
+
spin_lock_bh(&ipvs->sync_buff_lock);
if (!(ipvs->sync_state & IP_VS_STATE_MASTER)) {
spin_unlock_bh(&ipvs->sync_buff_lock);
@@ -604,7 +613,7 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,
if (seq_mask) {
struct ip_vs_sync_conn_options *opt =
(struct ip_vs_sync_conn_options *)&s[1];
- memcpy(opt, &cp->sync_conn_opt, sizeof(*opt));
+ memcpy(opt, &opts, sizeof(*opt));
}
m->nr_conns++;
@@ -630,6 +639,7 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,
*/
void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)
{
+ struct ip_vs_sync_conn_options opts;
struct ip_vs_sync_mesg *m;
union ip_vs_sync_conn *s;
struct ip_vs_sync_buff *buff;
@@ -651,6 +661,13 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)
if (!ip_vs_sync_conn_needed(ipvs, cp, pkts))
goto control;
flags = READ_ONCE(cp->flags);
+ if (flags & IP_VS_CONN_F_SEQ_MASK) {
+ /* Take atomic snapshot of flags and seqs */
+ spin_lock_bh(&cp->lock);
+ flags = cp->flags;
+ memcpy(&opts, &cp->sync_conn_opt, sizeof(opts));
+ spin_unlock_bh(&cp->lock);
+ }
/* Sanity checks */
pe_name_len = 0;
@@ -732,7 +749,7 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)
s->v4.vport = cp->vport;
s->v4.dport = cp->dport;
s->v4.fwmark = htonl(cp->fwmark);
- s->v4.timeout = htonl(cp->timeout / HZ);
+ s->v4.timeout = htonl(max(1UL, cp->timeout / HZ));
m->nr_conns++;
#ifdef CONFIG_IP_VS_IPV6
@@ -752,9 +769,9 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)
if (seq_mask) {
*(p++) = IPVS_OPT_SEQ_DATA;
*(p++) = sizeof(struct ip_vs_sync_conn_options);
- hton_seq(&cp->in_seq, (struct ip_vs_seq *)p);
+ hton_seq(&opts.in_seq, (struct ip_vs_seq *)p);
p += sizeof(struct ip_vs_seq);
- hton_seq(&cp->out_seq, (struct ip_vs_seq *)p);
+ hton_seq(&opts.out_seq, (struct ip_vs_seq *)p);
p += sizeof(struct ip_vs_seq);
}
/* Handle pe data */
@@ -850,9 +867,29 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
unsigned long timeout, __u32 fwmark,
struct ip_vs_sync_conn_options *opt)
{
+ struct ip_vs_conn *cp_new = NULL;
struct ip_vs_dest *dest;
struct ip_vs_conn *cp;
+ /* Templates require cport 0. Ordinary connections require
+ * NO_CPORT exactly when cport is 0.
+ */
+ if (flags & IP_VS_CONN_F_TEMPLATE) {
+ if (param->cport) {
+ IP_VS_DBG(2, "BACKUP, template with cport dropped\n");
+ kfree(param->pe_data);
+ return;
+ }
+ } else if (!param->cport && !(flags & IP_VS_CONN_F_NO_CPORT)) {
+ IP_VS_DBG(2, "BACKUP, conn without cport dropped\n");
+ kfree(param->pe_data);
+ return;
+ } else if (param->cport && (flags & IP_VS_CONN_F_NO_CPORT)) {
+ IP_VS_DBG(2, "BACKUP, conn with cport and NO_CPORT dropped\n");
+ kfree(param->pe_data);
+ return;
+ }
+
if (!(flags & IP_VS_CONN_F_TEMPLATE)) {
cp = ip_vs_conn_in_get(param);
if (cp && ((cp->dport != dport) ||
@@ -891,9 +928,6 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
flags &= IP_VS_CONN_F_BACKUP_UPD_MASK;
flags |= cp->flags & ~IP_VS_CONN_F_BACKUP_UPD_MASK;
cp->flags = flags;
- spin_unlock_bh(&cp->lock);
- if (!dest)
- ip_vs_try_bind_dest(cp);
} else {
/*
* Find the appropriate destination for the connection.
@@ -920,6 +954,8 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
}
if (!(flags & IP_VS_CONN_F_TEMPLATE))
kfree(param->pe_data);
+ cp_new = cp;
+ spin_lock_bh(&cp->lock);
}
if (opt) {
@@ -951,6 +987,9 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
else
cp->timeout = (3*60*HZ);
}
+ spin_unlock_bh(&cp->lock);
+ if (!dest && !cp_new)
+ ip_vs_try_bind_dest(cp);
ip_vs_conn_put(cp);
}
diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
index ebc6b697ae5160..c777493eee7493 100644
--- a/net/netfilter/ipvs/ip_vs_xmit.c
+++ b/net/netfilter/ipvs/ip_vs_xmit.c
@@ -205,13 +205,24 @@ static inline bool crosses_local_route_boundary(int skb_af, struct sk_buff *skb,
return false;
}
-static inline void maybe_update_pmtu(int skb_af, struct sk_buff *skb, int mtu)
+static inline void maybe_update_pmtu(int skb_af, struct sk_buff *skb, int mtu,
+ const struct nf_hook_state *state)
{
- struct sock *sk = skb->sk;
- struct rtable *ort = skb_rtable(skb);
-
- if (!skb->dev && sk && sk_fullsock(sk))
- ort->dst.ops->update_pmtu(&ort->dst, sk, NULL, mtu, true);
+ struct dst_entry *dst = skb_dst(skb);
+ struct sock *sk = state->sk;
+
+ /* The update_pmtu handlers are missing some checks for:
+ * - skb->dev: present for tunnels, not for IPVS, so we do not
+ * provide skb, only sk
+ * - present daddr: so, we require TCP_ESTABLISHED (connected socket)
+ *
+ * In some states the senders ignore the PMTU events:
+ * - sk_fullsock(): so use the TCP_ESTABLISHED check
+ */
+ if (sk && sk->sk_state == TCP_ESTABLISHED &&
+ state->hook == NF_INET_LOCAL_OUT &&
+ sk->sk_family == dst->ops->family)
+ dst->ops->update_pmtu(dst, sk, NULL, mtu, false);
}
static inline bool ensure_mtu_is_adequate(struct netns_ipvs *ipvs, int skb_af,
@@ -316,7 +327,7 @@ static int
__ip_vs_get_out_rt(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,
struct ip_vs_dest *dest,
__be32 daddr, int rt_mode, __be32 *ret_saddr,
- struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_iphdr *ipvsh, const struct nf_hook_state *state)
{
struct net *net = ipvs->net;
struct ip_vs_dest_dst *dest_dst;
@@ -417,7 +428,7 @@ __ip_vs_get_out_rt(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,
IP_VS_DBG_RL("%s(): mtu less than 68\n", __func__);
goto err_put;
}
- maybe_update_pmtu(skb_af, skb, mtu);
+ maybe_update_pmtu(skb_af, skb, mtu, state);
}
if (!ensure_mtu_is_adequate(ipvs, skb_af, rt_mode, ipvsh, skb, mtu))
@@ -489,7 +500,8 @@ static int
__ip_vs_get_out_rt_v6(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,
struct ip_vs_dest *dest,
struct in6_addr *daddr, struct in6_addr *ret_saddr,
- struct ip_vs_iphdr *ipvsh, int do_xfrm, int rt_mode)
+ struct ip_vs_iphdr *ipvsh, int do_xfrm, int rt_mode,
+ const struct nf_hook_state *state)
{
struct net *net = ipvs->net;
struct ip_vs_dest_dst *dest_dst;
@@ -596,7 +608,7 @@ __ip_vs_get_out_rt_v6(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,
IPV6_MIN_MTU);
goto err_put;
}
- maybe_update_pmtu(skb_af, skb, mtu);
+ maybe_update_pmtu(skb_af, skb, mtu, state);
}
if (!ensure_mtu_is_adequate(ipvs, skb_af, rt_mode, ipvsh, skb, mtu))
@@ -720,12 +732,26 @@ static inline int ip_vs_send_or_cont(int pf, struct sk_buff *skb,
*/
int
ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
/* we do not touch skb and do not need pskb ptr */
return ip_vs_send_or_cont(NFPROTO_IPV4, skb, cp, 1);
}
+#ifdef CONFIG_IP_VS_IPV6
+/*
+ * NULL transmitter (do nothing except return NF_ACCEPT)
+ */
+int
+ip_vs_null_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
+{
+ /* we do not touch skb and do not need pskb ptr */
+ return ip_vs_send_or_cont(NFPROTO_IPV6, skb, cp, 1);
+}
+#endif
/*
* Bypass transmitter
@@ -734,10 +760,11 @@ ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
*/
int
ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
if (__ip_vs_get_out_rt(cp->ipvs, cp->af, skb, NULL, ip_hdr(skb)->daddr,
- IP_VS_RT_MODE_NON_LOCAL, NULL, ipvsh) < 0)
+ IP_VS_RT_MODE_NON_LOCAL, NULL, ipvsh, state) < 0)
goto tx_error;
ip_send_check(ip_hdr(skb));
@@ -757,13 +784,15 @@ ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
#ifdef CONFIG_IP_VS_IPV6
int
ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
struct ipv6hdr *iph = ipv6_hdr(skb);
if (__ip_vs_get_out_rt_v6(cp->ipvs, cp->af, skb, NULL,
&iph->daddr, NULL,
- ipvsh, 0, IP_VS_RT_MODE_NON_LOCAL) < 0)
+ ipvsh, 0, IP_VS_RT_MODE_NON_LOCAL,
+ state) < 0)
goto tx_error;
/* Another hack: avoid icmp_send in ip_fragment */
@@ -785,7 +814,8 @@ ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
*/
int
ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
struct rtable *rt; /* Route to the other host */
int local, rc, was_input;
@@ -805,7 +835,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
local = __ip_vs_get_out_rt(cp->ipvs, cp->af, skb, cp->dest, cp->daddr.ip,
IP_VS_RT_MODE_LOCAL |
IP_VS_RT_MODE_NON_LOCAL |
- IP_VS_RT_MODE_RDR, NULL, ipvsh);
+ IP_VS_RT_MODE_RDR, NULL, ipvsh, state);
if (local < 0)
goto tx_error;
rt = skb_rtable(skb);
@@ -869,7 +899,8 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
#ifdef CONFIG_IP_VS_IPV6
int
ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
struct rt6_info *rt; /* Route to the other host */
int local, rc;
@@ -889,7 +920,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
NULL, ipvsh, 0,
IP_VS_RT_MODE_LOCAL |
IP_VS_RT_MODE_NON_LOCAL |
- IP_VS_RT_MODE_RDR);
+ IP_VS_RT_MODE_RDR, state);
if (local < 0)
goto tx_error;
rt = dst_rt6_info(skb_dst(skb));
@@ -1145,7 +1176,8 @@ ipvs_gre_encap(struct net *net, struct sk_buff *skb,
*/
int
ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
struct netns_ipvs *ipvs = cp->ipvs;
struct net *net = ipvs->net;
@@ -1167,7 +1199,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
IP_VS_RT_MODE_LOCAL |
IP_VS_RT_MODE_NON_LOCAL |
IP_VS_RT_MODE_CONNECT |
- IP_VS_RT_MODE_TUNNEL, &saddr, ipvsh);
+ IP_VS_RT_MODE_TUNNEL, &saddr, ipvsh, state);
if (local < 0)
goto tx_error;
if (local)
@@ -1276,7 +1308,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
ret = ip_vs_tunnel_xmit_prepare(skb, cp);
if (ret == NF_ACCEPT)
- ip_local_out(net, skb->sk, skb);
+ ip_local_out(net, NULL, skb);
else if (ret == NF_DROP)
kfree_skb(skb);
@@ -1290,7 +1322,8 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
#ifdef CONFIG_IP_VS_IPV6
int
ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
struct netns_ipvs *ipvs = cp->ipvs;
struct net *net = ipvs->net;
@@ -1312,7 +1345,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
&saddr, ipvsh, 1,
IP_VS_RT_MODE_LOCAL |
IP_VS_RT_MODE_NON_LOCAL |
- IP_VS_RT_MODE_TUNNEL);
+ IP_VS_RT_MODE_TUNNEL, state);
if (local < 0)
goto tx_error;
if (local)
@@ -1418,7 +1451,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
ret = ip_vs_tunnel_xmit_prepare(skb, cp);
if (ret == NF_ACCEPT)
- ip6_local_out(net, skb->sk, skb);
+ ip6_local_out(net, NULL, skb);
else if (ret == NF_DROP)
kfree_skb(skb);
@@ -1437,14 +1470,15 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
*/
int
ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
int local;
local = __ip_vs_get_out_rt(cp->ipvs, cp->af, skb, cp->dest, cp->daddr.ip,
IP_VS_RT_MODE_LOCAL |
IP_VS_RT_MODE_NON_LOCAL |
- IP_VS_RT_MODE_KNOWN_NH, NULL, ipvsh);
+ IP_VS_RT_MODE_KNOWN_NH, NULL, ipvsh, state);
if (local < 0)
goto tx_error;
if (local)
@@ -1467,7 +1501,8 @@ ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
#ifdef CONFIG_IP_VS_IPV6
int
ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
int local;
@@ -1476,7 +1511,7 @@ ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
NULL, ipvsh, 0,
IP_VS_RT_MODE_LOCAL |
IP_VS_RT_MODE_NON_LOCAL |
- IP_VS_RT_MODE_KNOWN_NH);
+ IP_VS_RT_MODE_KNOWN_NH, state);
if (local < 0)
goto tx_error;
if (local)
@@ -1503,7 +1538,7 @@ ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
int
ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
struct ip_vs_protocol *pp, unsigned int toff,
- unsigned int hooknum, struct ip_vs_iphdr *ciph)
+ const struct nf_hook_state *state, struct ip_vs_iphdr *ciph)
{
struct rtable *rt; /* Route to the other host */
int rc;
@@ -1517,7 +1552,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
translate address/port back */
if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
if (cp->packet_xmit)
- rc = cp->packet_xmit(skb, cp, pp, ciph);
+ rc = cp->packet_xmit(skb, cp, pp, ciph, state);
else
rc = NF_ACCEPT;
/* do not touch skb anymore */
@@ -1531,11 +1566,11 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
was_input = rt_is_input_route(skb_rtable(skb));
/* LOCALNODE from FORWARD hook is not supported */
- rt_mode = (hooknum != NF_INET_FORWARD) ?
+ rt_mode = (state->hook != NF_INET_FORWARD) ?
IP_VS_RT_MODE_LOCAL | IP_VS_RT_MODE_NON_LOCAL |
IP_VS_RT_MODE_RDR : IP_VS_RT_MODE_NON_LOCAL;
- local = __ip_vs_get_out_rt(cp->ipvs, cp->af, skb, cp->dest, cp->daddr.ip, rt_mode,
- NULL, ciph);
+ local = __ip_vs_get_out_rt(cp->ipvs, cp->af, skb, cp->dest,
+ cp->daddr.ip, rt_mode, NULL, ciph, state);
if (local < 0)
goto tx_error;
rt = skb_rtable(skb);
@@ -1597,8 +1632,8 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
#ifdef CONFIG_IP_VS_IPV6
int
ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, unsigned int toff,
- unsigned int hooknum, struct ip_vs_iphdr *ciph)
+ struct ip_vs_protocol *pp, unsigned int toff,
+ const struct nf_hook_state *state, struct ip_vs_iphdr *ciph)
{
bool has_ports = false;
struct rt6_info *rt; /* Route to the other host */
@@ -1612,7 +1647,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
translate address/port back */
if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
if (cp->packet_xmit)
- rc = cp->packet_xmit(skb, cp, pp, ciph);
+ rc = cp->packet_xmit(skb, cp, pp, ciph, state);
else
rc = NF_ACCEPT;
/* do not touch skb anymore */
@@ -1625,11 +1660,12 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
*/
/* LOCALNODE from FORWARD hook is not supported */
- rt_mode = (hooknum != NF_INET_FORWARD) ?
+ rt_mode = (state->hook != NF_INET_FORWARD) ?
IP_VS_RT_MODE_LOCAL | IP_VS_RT_MODE_NON_LOCAL |
IP_VS_RT_MODE_RDR : IP_VS_RT_MODE_NON_LOCAL;
local = __ip_vs_get_out_rt_v6(cp->ipvs, cp->af, skb, cp->dest,
- &cp->daddr.in6, NULL, ciph, 0, rt_mode);
+ &cp->daddr.in6, NULL, ciph, 0, rt_mode,
+ state);
if (local < 0)
goto tx_error;
rt = dst_rt6_info(skb_dst(skb));
|
| 3/2 | 2026/11/17 07:46 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29455 output: 35 thoughts: 925 Thoughts: **Initial Assessment of the Kernel Patch Series** Okay, so I've got a patch series here applied as HEAD in the kernel workspace. My first instinct, as always, is to understand the impact of these changes. Ideally, I'd run `git log` to review the commit messages directly, but it looks like I don't have that tool at my immediate disposal. No problem. Let's see... I *do* have `grepper`, `codesearch-dir-index`, `read-file`, and `set-results`. Since I have the diff in the prompt itself, I can work with that directly. Right, the diff reveals modifications across a significant chunk of code. Specifically, the affected files are: `include/net/ip_vs.h`, `net/ipv6/exthdrs_core.c`, and a whole slew of files within `net/netfilter/ipvs/`. So, this touches IPVS (IP Virtual Server) within the netfilter subsystem, plus some IPv6 extension header handling. That screams "core networking" to me. Now, a key question for me is reachability. Is IPVS accessible in standard virtualized environments like QEMU or Syzkaller? The answer is a resounding YES. IPVS is configured via netlink/generic netlink, uses sockopts, processes packets via netfilter hooks (e.g., `NF_INET_LOCAL_IN`, `NF_INET_LOCAL_OUT`), and Syzkaller specifically fuzzed IPVS extensively. Okay, is this patch series worth fuzzing? Let's see... I need to apply the fuzzing criteria. This patch modifies core networking, and it introduces locking changes like RCU grace periods, timers, seqadj conntrack, refcounting, and PMTU handling. Given that this touches core networking and involves locking, *absolutely* this warrants fuzzing; I'm setting `WorthFuzzing=true`. Now, time to move on to the next questions. What kernel configurations are needed to enable all or at least the critical parts of this code? Also, what are the best `FocusSymbols` to target during fuzzing? I need to dive into the Kconfig files and the modified code to get a good handle on that. I'll start by searching `net/netfilter/ipvs/Kconfig` and related configuration options. |
| 4/2 | 2026/11/17 07:46 | tool | grepper |
0mArgs:{
"Expression": "config IP_VS",
"PathPrefixes": [
"net/netfilter/ipvs/Kconfig"
]
}Results: {
"Output": "net/netfilter/ipvs/Kconfig-4-#\nnet/netfilter/ipvs/Kconfig:5:menuconfig IP_VS\nnet/netfilter/ipvs/Kconfig-6-\ttristate \"IP virtual server support\"\n--\nnet/netfilter/ipvs/Kconfig=286=comment 'IPVS SH scheduler'\nnet/netfilter/ipvs/Kconfig-287-\nnet/netfilter/ipvs/Kconfig:288:config IP_VS_SH_TAB_BITS\nnet/netfilter/ipvs/Kconfig-289-\tint \"IPVS source hashing table size (the Nth power of 2)\"\n--\nnet/netfilter/ipvs/Kconfig=301=comment 'IPVS MH scheduler'\nnet/netfilter/ipvs/Kconfig-302-\nnet/netfilter/ipvs/Kconfig:303:config IP_VS_MH_TAB_INDEX\nnet/netfilter/ipvs/Kconfig-304-\tint \"IPVS maglev hashing table index of size (the prime numbers)\"\n"
} |
| 5/2 | 2026/11/17 07:46 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31187 output: 36 thoughts: 45 Thoughts: Okay, let's dive into this. Here's my thought process on the matter: **Examining IPVS Configuration Options** Alright, I need to get a handle on the available configuration options for IPVS. My immediate instinct is to look at the relevant Kconfig file, specifically `net/netfilter/ipvs/Kconfig`. That's where I'll find the definitions for things like `IP_VS`, `IP_VS_IPV6`, and the protocol-specific options such as `IP_VS_PROTO_TCP`. Grabbing that will give me a solid overview of what's available and how things are set up at the kernel configuration level. That's the best way to get a good handle on its architecture at this stage. |
| 6/2 | 2026/11/17 07:47 | tool | read-file |
0mArgs:{
"File": "net/netfilter/ipvs/Kconfig",
"FirstLine": 1,
"LineCount": 80
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\t#\n 3:\t# IP Virtual Server configuration\n 4:\t#\n 5:\tmenuconfig IP_VS\n 6:\t\ttristate \"IP virtual server support\"\n 7:\t\tdepends on INET \u0026\u0026 NETFILTER\n 8:\t\tdepends on (NF_CONNTRACK || NF_CONNTRACK=n)\n 9:\t\thelp\n 10:\t\t IP Virtual Server support will let you build a high-performance\n 11:\t\t virtual server based on cluster of two or more real servers. This\n 12:\t\t option must be enabled for at least one of the clustered computers\n 13:\t\t that will take care of intercepting incoming connections to a\n 14:\t\t single IP address and scheduling them to real servers.\n 15:\t\n 16:\t\t Three request dispatching techniques are implemented, they are\n 17:\t\t virtual server via NAT, virtual server via tunneling and virtual\n 18:\t\t server via direct routing. The several scheduling algorithms can\n 19:\t\t be used to choose which server the connection is directed to,\n 20:\t\t thus load balancing can be achieved among the servers. For more\n 21:\t\t information and its administration program, please visit the\n 22:\t\t following URL: \u003chttp://www.linuxvirtualserver.org/\u003e.\n 23:\t\n 24:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 25:\t\t module, choose M here. If unsure, say N.\n 26:\t\n 27:\tif IP_VS\n 28:\t\n 29:\tconfig\tIP_VS_IPV6\n 30:\t\tbool \"IPv6 support for IPVS\"\n 31:\t\tdepends on IPV6 = y || IP_VS = IPV6\n 32:\t\tselect NF_DEFRAG_IPV6\n 33:\t\thelp\n 34:\t\t Add IPv6 support to IPVS.\n 35:\t\n 36:\t\t Say Y if unsure.\n 37:\t\n 38:\tconfig\tIP_VS_DEBUG\n 39:\t\tbool \"IP virtual server debugging\"\n 40:\t\thelp\n 41:\t\t Say Y here if you want to get additional messages useful in\n 42:\t\t debugging the IP virtual server code. You can change the debug\n 43:\t\t level in /proc/sys/net/ipv4/vs/debug_level\n 44:\t\n 45:\tconfig\tIP_VS_TAB_BITS\n 46:\t\tint \"IPVS connection table size (the Nth power of 2)\"\n 47:\t\trange 8 20 if !64BIT\n 48:\t\trange 8 27 if 64BIT\n 49:\t\tdefault 12\n 50:\t\thelp\n 51:\t\t The IPVS connection hash table uses the chaining scheme to handle\n 52:\t\t hash collisions. Using a big IPVS connection hash table will greatly\n 53:\t\t reduce conflicts when there are hundreds of thousands of connections\n 54:\t\t in the hash table.\n 55:\t\n 56:\t\t Note the table size must be power of 2. The table size will be the\n 57:\t\t value of 2 to the your input number power. The number to choose is\n 58:\t\t from 8 to 27 for 64BIT(20 otherwise), the default number is 12,\n 59:\t\t which means the table size is 4096. Don't input the number too\n 60:\t\t small, otherwise you will lose performance on it. You can adapt the\n 61:\t\t table size yourself, according to your virtual server application.\n 62:\t\t It is good to set the table size not far less than the number of\n 63:\t\t connections per second multiplying average lasting time of\n 64:\t\t connection in the table. For example, your virtual server gets 200\n 65:\t\t connections per second, the connection lasts for 200 seconds in\n 66:\t\t average in the connection table, the table size should be not far\n 67:\t\t less than 200x200, it is good to set the table size 32768 (2**15).\n 68:\t\n 69:\t\t Another note that each connection occupies 128 bytes effectively and\n 70:\t\t each hash entry uses 8 bytes, so you can estimate how much memory is\n 71:\t\t needed for your box.\n 72:\t\n 73:\t\t You can overwrite this number setting conn_tab_bits module parameter\n 74:\t\t or by appending ip_vs.conn_tab_bits=? to the kernel command line if\n 75:\t\t IP VS was compiled built-in.\n 76:\t\n 77:\tcomment \"IPVS transport protocol load balancing support\"\n 78:\t\n 79:\tconfig\tIP_VS_PROTO_TCP\n 80:\t\tbool \"TCP load balancing support\"\n"
} |
| 7/2 | 2026/11/17 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32685 output: 38 thoughts: 28 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving Deeper into IPVS Configuration** Alright, so I need to get a comprehensive picture of what's going on with IPVS and its configuration options. I've got a specific question I'm trying to answer, but to fully understand the scope of the changes, I'm thinking I should take a look at `net/netfilter/ipvs/Kconfig`. It's likely that file will illuminate the dependencies, other protocols, and scheduler modifications associated with this IPVS module. I'm hoping it'll provide context for the behavior I'm seeing and help me track down the relevant code paths. Going directly to that Kconfig file should be the most efficient path to getting the full picture. |
| 8/2 | 2026/11/17 07:47 | tool | read-file |
0mArgs:{
"File": "net/netfilter/ipvs/Kconfig",
"FirstLine": 81,
"LineCount": 100
}Results: {
"Contents": " 81:\t\thelp\n 82:\t\t This option enables support for load balancing TCP transport\n 83:\t\t protocol. Say Y if unsure.\n 84:\t\n 85:\tconfig\tIP_VS_PROTO_UDP\n 86:\t\tbool \"UDP load balancing support\"\n 87:\t\thelp\n 88:\t\t This option enables support for load balancing UDP transport\n 89:\t\t protocol. Say Y if unsure.\n 90:\t\n 91:\tconfig\tIP_VS_PROTO_AH_ESP\n 92:\t\tdef_bool IP_VS_PROTO_ESP || IP_VS_PROTO_AH\n 93:\t\n 94:\tconfig\tIP_VS_PROTO_ESP\n 95:\t\tbool \"ESP load balancing support\"\n 96:\t\thelp\n 97:\t\t This option enables support for load balancing ESP (Encapsulation\n 98:\t\t Security Payload) transport protocol. Say Y if unsure.\n 99:\t\n 100:\tconfig\tIP_VS_PROTO_AH\n 101:\t\tbool \"AH load balancing support\"\n 102:\t\thelp\n 103:\t\t This option enables support for load balancing AH (Authentication\n 104:\t\t Header) transport protocol. Say Y if unsure.\n 105:\t\n 106:\tconfig IP_VS_PROTO_SCTP\n 107:\t\tbool \"SCTP load balancing support\"\n 108:\t\tselect NET_CRC32C\n 109:\t\thelp\n 110:\t\t This option enables support for load balancing SCTP transport\n 111:\t\t protocol. Say Y if unsure.\n 112:\t\n 113:\tcomment \"IPVS scheduler\"\n 114:\t\n 115:\tconfig\tIP_VS_RR\n 116:\t\ttristate \"round-robin scheduling\"\n 117:\t\thelp\n 118:\t\t The robin-robin scheduling algorithm simply directs network\n 119:\t\t connections to different real servers in a round-robin manner.\n 120:\t\n 121:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 122:\t\t module, choose M here. If unsure, say N.\n 123:\t \n 124:\tconfig\tIP_VS_WRR\n 125:\t\ttristate \"weighted round-robin scheduling\"\n 126:\t\thelp\n 127:\t\t The weighted robin-robin scheduling algorithm directs network\n 128:\t\t connections to different real servers based on server weights\n 129:\t\t in a round-robin manner. Servers with higher weights receive\n 130:\t\t new connections first than those with less weights, and servers\n 131:\t\t with higher weights get more connections than those with less\n 132:\t\t weights and servers with equal weights get equal connections.\n 133:\t\n 134:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 135:\t\t module, choose M here. If unsure, say N.\n 136:\t\n 137:\tconfig\tIP_VS_LC\n 138:\t\ttristate \"least-connection scheduling\"\n 139:\t\thelp\n 140:\t\t The least-connection scheduling algorithm directs network\n 141:\t\t connections to the server with the least number of active \n 142:\t\t connections.\n 143:\t\n 144:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 145:\t\t module, choose M here. If unsure, say N.\n 146:\t\n 147:\tconfig\tIP_VS_WLC\n 148:\t\ttristate \"weighted least-connection scheduling\"\n 149:\t\thelp\n 150:\t\t The weighted least-connection scheduling algorithm directs network\n 151:\t\t connections to the server with the least active connections\n 152:\t\t normalized by the server weight.\n 153:\t\n 154:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 155:\t\t module, choose M here. If unsure, say N.\n 156:\t\n 157:\tconfig IP_VS_FO\n 158:\t\t\ttristate \"weighted failover scheduling\"\n 159:\t\thelp\n 160:\t\t The weighted failover scheduling algorithm directs network\n 161:\t\t connections to the server with the highest weight that is\n 162:\t\t currently available.\n 163:\t\n 164:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 165:\t\t module, choose M here. If unsure, say N.\n 166:\t\n 167:\tconfig IP_VS_OVF\n 168:\t\ttristate \"weighted overflow scheduling\"\n 169:\t\thelp\n 170:\t\t The weighted overflow scheduling algorithm directs network\n 171:\t\t connections to the server with the highest weight that is\n 172:\t\t currently available and overflows to the next when active\n 173:\t\t connections exceed the node's weight.\n 174:\t\n 175:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 176:\t\t module, choose M here. If unsure, say N.\n 177:\t\n 178:\tconfig\tIP_VS_LBLC\n 179:\t\ttristate \"locality-based least-connection scheduling\"\n 180:\t\thelp\n"
} |
| 9/2 | 2026/11/17 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34349 output: 38 thoughts: 26 Thoughts: Okay, here's my interpretation of what's going on in those Kconfig lines, presented as a personal thought process, as requested: **Diving into the IPVS Kconfig** Alright, let's zero in on lines 181 to 250 of `net/netfilter/ipvs/Kconfig`. I'm going to quickly skim this section to understand what it configures. I can expect this to be a definition of a feature or a module within the larger IPVS framework. Since it's Kconfig, it should be setting up a configuration option, presumably with dependencies, default values, and a helpful prompt to guide the user. First, I'm expecting to see the `config` keyword, followed by the name of the option. Then, there'll be a type definition, typically `bool`, `tristate`, `string`, `int`, or `hex`. This tells the kernel what kind of input to expect for this option. Following that, there will be the prompt, which is crucial for giving users the context about what they're configuring. The prompt usually starts with the 'menuconfig' and includes the text displayed to the user. I'll need to absorb this text to determine what the option actually *does* in the context of IPVS. Next, I'll be looking for `depends on` statements. These are *key*. They specify the prerequisites for this option to even be presented or enabled. This will give me insight into what other parts of the kernel or IPVS must be configured *before* this becomes relevant. These dependencies could be on other Kconfig symbols, on processor architecture, or even on kernel features. I'm also expecting `select` statements, though less frequently. If present, it will tell me what this option enables or makes available. Default values are also critical. The default setting is what will be used if the user doesn't explicitly choose a different value. I'll need to figure out what the default choice is, and *why* it's the default, to understand common usage scenarios. Finally, any `help` text will be valuable. This will give me a more in-depth description of the feature, any implications of enabling or disabling it, and any warnings. The `help` section will tell me if there are any specific use cases to keep in mind, or any limitations I need to be aware of. Essentially, I'm looking for a self-contained unit of configuration: What is it? What does it depend on? What are the potential impacts? And what does it help me to do? That should be a good starting point for understanding how this part of IPVS is configured. |
| 10/2 | 2026/11/17 07:47 | tool | read-file |
0mArgs:{
"File": "net/netfilter/ipvs/Kconfig",
"FirstLine": 181,
"LineCount": 70
}Results: {
"Contents": " 181:\t\t The locality-based least-connection scheduling algorithm is for\n 182:\t\t destination IP load balancing. It is usually used in cache cluster.\n 183:\t\t This algorithm usually directs packet destined for an IP address to\n 184:\t\t its server if the server is alive and under load. If the server is\n 185:\t\t overloaded (its active connection numbers is larger than its weight)\n 186:\t\t and there is a server in its half load, then allocate the weighted\n 187:\t\t least-connection server to this IP address.\n 188:\t\n 189:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 190:\t\t module, choose M here. If unsure, say N.\n 191:\t\n 192:\tconfig IP_VS_LBLCR\n 193:\t\ttristate \"locality-based least-connection with replication scheduling\"\n 194:\t\thelp\n 195:\t\t The locality-based least-connection with replication scheduling\n 196:\t\t algorithm is also for destination IP load balancing. It is \n 197:\t\t usually used in cache cluster. It differs from the LBLC scheduling\n 198:\t\t as follows: the load balancer maintains mappings from a target\n 199:\t\t to a set of server nodes that can serve the target. Requests for\n 200:\t\t a target are assigned to the least-connection node in the target's\n 201:\t\t server set. If all the node in the server set are over loaded,\n 202:\t\t it picks up a least-connection node in the cluster and adds it\n 203:\t\t in the sever set for the target. If the server set has not been\n 204:\t\t modified for the specified time, the most loaded node is removed\n 205:\t\t from the server set, in order to avoid high degree of replication.\n 206:\t\n 207:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 208:\t\t module, choose M here. If unsure, say N.\n 209:\t\n 210:\tconfig\tIP_VS_DH\n 211:\t\ttristate \"destination hashing scheduling\"\n 212:\t\thelp\n 213:\t\t The destination hashing scheduling algorithm assigns network\n 214:\t\t connections to the servers through looking up a statically assigned\n 215:\t\t hash table by their destination IP addresses.\n 216:\t\n 217:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 218:\t\t module, choose M here. If unsure, say N.\n 219:\t\n 220:\tconfig\tIP_VS_SH\n 221:\t\ttristate \"source hashing scheduling\"\n 222:\t\thelp\n 223:\t\t The source hashing scheduling algorithm assigns network\n 224:\t\t connections to the servers through looking up a statically assigned\n 225:\t\t hash table by their source IP addresses.\n 226:\t\n 227:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 228:\t\t module, choose M here. If unsure, say N.\n 229:\t\n 230:\tconfig\tIP_VS_MH\n 231:\t\ttristate \"maglev hashing scheduling\"\n 232:\t\thelp\n 233:\t\t The maglev consistent hashing scheduling algorithm provides the\n 234:\t\t Google's Maglev hashing algorithm as a IPVS scheduler. It assigns\n 235:\t\t network connections to the servers through looking up a statically\n 236:\t\t assigned special hash table called the lookup table. Maglev hashing\n 237:\t\t is to assign a preference list of all the lookup table positions\n 238:\t\t to each destination.\n 239:\t\n 240:\t\t Through this operation, The maglev hashing gives an almost equal\n 241:\t\t share of the lookup table to each of the destinations and provides\n 242:\t\t minimal disruption by using the lookup table. When the set of\n 243:\t\t destinations changes, a connection will likely be sent to the same\n 244:\t\t destination as it was before.\n 245:\t\n 246:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 247:\t\t module, choose M here. If unsure, say N.\n 248:\t\n 249:\tconfig\tIP_VS_SED\n 250:\t\ttristate \"shortest expected delay scheduling\"\n"
} |
| 11/2 | 2026/11/17 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36162 output: 38 thoughts: 28 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Examining Kconfig for IPVS FTP Options** Alright, let's drill down into the IPVS Kconfig file. I'm specifically interested in ensuring the dependencies for FTP support are properly configured within the IPVS framework. I'll need to confirm the presence and status of options like `IP_VS_FTP`, to make sure all the necessary components are available and not missing any obvious dependencies. I want to make sure I have the context of the greater file and other configurations to get a full understanding. We know it, of course, but it’s still worth confirming these specific items as well. We need to be thorough. |
| 12/2 | 2026/11/17 07:47 | tool | read-file |
0mArgs:{
"File": "net/netfilter/ipvs/Kconfig",
"FirstLine": 251,
"LineCount": 70
}Results: {
"Contents": " 251:\t\thelp\n 252:\t\t The shortest expected delay scheduling algorithm assigns network\n 253:\t\t connections to the server with the shortest expected delay. The \n 254:\t\t expected delay that the job will experience is (Ci + 1) / Ui if \n 255:\t\t sent to the ith server, in which Ci is the number of connections\n 256:\t\t on the ith server and Ui is the fixed service rate (weight)\n 257:\t\t of the ith server.\n 258:\t\n 259:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 260:\t\t module, choose M here. If unsure, say N.\n 261:\t\n 262:\tconfig\tIP_VS_NQ\n 263:\t\ttristate \"never queue scheduling\"\n 264:\t\thelp\n 265:\t\t The never queue scheduling algorithm adopts a two-speed model.\n 266:\t\t When there is an idle server available, the job will be sent to\n 267:\t\t the idle server, instead of waiting for a fast one. When there\n 268:\t\t is no idle server available, the job will be sent to the server\n 269:\t\t that minimize its expected delay (The Shortest Expected Delay\n 270:\t\t scheduling algorithm).\n 271:\t\n 272:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 273:\t\t module, choose M here. If unsure, say N.\n 274:\t\n 275:\tconfig\tIP_VS_TWOS\n 276:\t\ttristate \"weighted random twos choice least-connection scheduling\"\n 277:\t\thelp\n 278:\t\t The weighted random twos choice least-connection scheduling\n 279:\t\t algorithm picks two random real servers and directs network\n 280:\t\t connections to the server with the least active connections\n 281:\t\t normalized by the server weight.\n 282:\t\n 283:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 284:\t\t module, choose M here. If unsure, say N.\n 285:\t\n 286:\tcomment 'IPVS SH scheduler'\n 287:\t\n 288:\tconfig IP_VS_SH_TAB_BITS\n 289:\t\tint \"IPVS source hashing table size (the Nth power of 2)\"\n 290:\t\trange 4 20\n 291:\t\tdefault 8\n 292:\t\thelp\n 293:\t\t The source hashing scheduler maps source IPs to destinations\n 294:\t\t stored in a hash table. This table is tiled by each destination\n 295:\t\t until all slots in the table are filled. When using weights to\n 296:\t\t allow destinations to receive more connections, the table is\n 297:\t\t tiled an amount proportional to the weights specified. The table\n 298:\t\t needs to be large enough to effectively fit all the destinations\n 299:\t\t multiplied by their respective weights.\n 300:\t\n 301:\tcomment 'IPVS MH scheduler'\n 302:\t\n 303:\tconfig IP_VS_MH_TAB_INDEX\n 304:\t\tint \"IPVS maglev hashing table index of size (the prime numbers)\"\n 305:\t\trange 8 17\n 306:\t\tdefault 12\n 307:\t\thelp\n 308:\t\t The maglev hashing scheduler maps source IPs to destinations\n 309:\t\t stored in a hash table. This table is assigned by a preference\n 310:\t\t list of the positions to each destination until all slots in\n 311:\t\t the table are filled. The index determines the prime for size of\n 312:\t\t the table as 251, 509, 1021, 2039, 4093, 8191, 16381, 32749,\n 313:\t\t 65521 or 131071. When using weights to allow destinations to\n 314:\t\t receive more connections, the table is assigned an amount\n 315:\t\t proportional to the weights specified. The table needs to be large\n 316:\t\t enough to effectively fit all the destinations multiplied by their\n 317:\t\t respective weights.\n 318:\t\n 319:\tcomment 'IPVS application helper'\n 320:\t\n"
} |
| 13/2 | 2026/11/17 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 37551 output: 38 thoughts: 26 Thoughts: Okay, let's dive into this. Here's my take on those lines in `net/netfilter/ipvs/Kconfig`, summarized as my own thought process: **Diving Deep into IPVS Configuration** Alright, I need to get a handle on the tail end of the IPVS Kconfig file. Specifically, I'm going to focus my expert eye on the lines from 320 to the end. I want to see what's being configured, what dependencies are in play, and how everything ties together at this point in the file. I'm expecting to see the more specific, perhaps less commonly tweaked, IPVS options in this section. Maybe some advanced features, experimental settings, or configurations that build on the core IPVS setup that's defined earlier in the file. I anticipate seeing dependencies here, likely on the core IPVS modules being enabled. I'll need to pay close attention to the `select` and `depends on` statements. The devil's always in the details with Kconfig, especially when looking at the specific features. I'm ready to figure out the granularity of options here – are these broad feature toggles, or are we drilling down to really granular control over specific IPVS behaviors? I'll also be on the lookout for anything that might be deprecated, or flagged as experimental. The end of a Kconfig file often holds the less-frequently-used or more niche options, and I want to identify those. This section is going to paint the complete picture of IPVS and its features. Let's see what gems are hidden down here. |
| 14/2 | 2026/11/17 07:47 | tool | read-file |
0mArgs:{
"File": "net/netfilter/ipvs/Kconfig",
"FirstLine": 320,
"LineCount": 40
}Results: {
"Contents": " 320:\t\n 321:\tconfig\tIP_VS_FTP\n 322:\t\ttristate \"FTP protocol helper\"\n 323:\t\tdepends on IP_VS_PROTO_TCP \u0026\u0026 NF_CONNTRACK \u0026\u0026 NF_NAT \u0026\u0026 \\\n 324:\t\t\tNF_CONNTRACK_FTP\n 325:\t\tselect IP_VS_NFCT\n 326:\t\thelp\n 327:\t\t FTP is a protocol that transfers IP address and/or port number in\n 328:\t\t the payload. In the virtual server via Network Address Translation,\n 329:\t\t the IP address and port number of real servers cannot be sent to\n 330:\t\t clients in ftp connections directly, so FTP protocol helper is\n 331:\t\t required for tracking the connection and mangling it back to that of\n 332:\t\t virtual service.\n 333:\t\n 334:\t\t If you want to compile it in kernel, say Y. To compile it as a\n 335:\t\t module, choose M here. If unsure, say N.\n 336:\t\n 337:\tconfig\tIP_VS_NFCT\n 338:\t\tbool \"Netfilter connection tracking\"\n 339:\t\tdepends on NF_CONNTRACK\n 340:\t\thelp\n 341:\t\t The Netfilter connection tracking support allows the IPVS\n 342:\t\t connection state to be exported to the Netfilter framework\n 343:\t\t for filtering purposes.\n 344:\t\n 345:\tconfig\tIP_VS_PE_SIP\n 346:\t\ttristate \"SIP persistence engine\"\n 347:\t\tdepends on IP_VS_PROTO_UDP\n 348:\t\tdepends on NF_CONNTRACK_SIP\n 349:\t\thelp\n 350:\t\t Allow persistence based on the SIP Call-ID\n 351:\t\n 352:\tconfig GCOV_PROFILE_IPVS\n 353:\t\tbool \"Enable GCOV profiling for IPVS\"\n 354:\t\tdepends on GCOV_KERNEL\n 355:\t\thelp\n 356:\t\t Enable GCOV profiling for IPVS to check which functions/lines\n 357:\t\t are executed.\n 358:\t\n 359:\t\t If unsure, say N.\n"
} |
| 15/2 | 2026/11/17 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38545 output: 35 thoughts: 26 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience and presented in the first person: **Investigating the IPVS Makefile for Compilation Details** Alright, before I dive into the specifics of these modifications, I need to understand how these files are actually built. I'm going to head straight to the `net/netfilter/ipvs/` directory. The Makefile there is the obvious place to start. I need to see how the object files are created, what compiler flags are being used, and crucially, how these new files are integrated into the overall IPVS module. I'll be looking for things like include paths, specific compiler directives that might be relevant to the changes I'm reviewing, and dependencies. Are there any custom build rules or macros that are defined within the Makefile itself that I should be aware of? Understanding the build process is essential to ensure that the modifications I'm looking at have been integrated in a maintainable way and that all the edge cases in compilation have been covered. I want to see this implemented in the cleanest way possible. It's a key first step in understanding the complete picture. |
| 16/2 | 2026/11/17 07:47 | tool | read-file |
0mArgs:{
"File": "net/netfilter/ipvs/Makefile",
"FirstLine": 1,
"LineCount": 50
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0\n 2:\t#\n 3:\t# Makefile for the IPVS modules on top of IPv4.\n 4:\t#\n 5:\t\n 6:\t# IPVS transport protocol load balancing support\n 7:\tip_vs_proto-objs-y :=\n 8:\tip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_TCP) += ip_vs_proto_tcp.o\n 9:\tip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_UDP) += ip_vs_proto_udp.o\n 10:\tip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_AH_ESP) += ip_vs_proto_ah_esp.o\n 11:\tip_vs_proto-objs-$(CONFIG_IP_VS_PROTO_SCTP) += ip_vs_proto_sctp.o\n 12:\t\n 13:\tip_vs-extra_objs-y :=\n 14:\tip_vs-extra_objs-$(CONFIG_IP_VS_NFCT) += ip_vs_nfct.o\n 15:\t\n 16:\tip_vs-objs :=\tip_vs_conn.o ip_vs_core.o ip_vs_ctl.o ip_vs_sched.o\t \\\n 17:\t\t\tip_vs_xmit.o ip_vs_app.o ip_vs_sync.o\t \t\t \\\n 18:\t\t\tip_vs_est.o ip_vs_proto.o ip_vs_pe.o\t\t\t \\\n 19:\t\t\t$(ip_vs_proto-objs-y) $(ip_vs-extra_objs-y)\n 20:\t\n 21:\t\n 22:\t# IPVS core\n 23:\tobj-$(CONFIG_IP_VS) += ip_vs.o\n 24:\t\n 25:\t# IPVS schedulers\n 26:\tobj-$(CONFIG_IP_VS_RR) += ip_vs_rr.o\n 27:\tobj-$(CONFIG_IP_VS_WRR) += ip_vs_wrr.o\n 28:\tobj-$(CONFIG_IP_VS_LC) += ip_vs_lc.o\n 29:\tobj-$(CONFIG_IP_VS_WLC) += ip_vs_wlc.o\n 30:\tobj-$(CONFIG_IP_VS_FO) += ip_vs_fo.o\n 31:\tobj-$(CONFIG_IP_VS_OVF) += ip_vs_ovf.o\n 32:\tobj-$(CONFIG_IP_VS_LBLC) += ip_vs_lblc.o\n 33:\tobj-$(CONFIG_IP_VS_LBLCR) += ip_vs_lblcr.o\n 34:\tobj-$(CONFIG_IP_VS_DH) += ip_vs_dh.o\n 35:\tobj-$(CONFIG_IP_VS_SH) += ip_vs_sh.o\n 36:\tobj-$(CONFIG_IP_VS_MH) += ip_vs_mh.o\n 37:\tobj-$(CONFIG_IP_VS_SED) += ip_vs_sed.o\n 38:\tobj-$(CONFIG_IP_VS_NQ) += ip_vs_nq.o\n 39:\tobj-$(CONFIG_IP_VS_TWOS) += ip_vs_twos.o\n 40:\t\n 41:\t# IPVS application helpers\n 42:\tobj-$(CONFIG_IP_VS_FTP) += ip_vs_ftp.o\n 43:\t\n 44:\t# IPVS connection template retrievers\n 45:\tobj-$(CONFIG_IP_VS_PE_SIP) += ip_vs_pe_sip.o\n 46:\tifdef CONFIG_GCOV_PROFILE_IPVS\n 47:\tGCOV_PROFILE := y\n 48:\tendif\n"
} |
| 17/2 | 2026/11/17 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39829 output: 33 thoughts: 504 Thoughts: **Analyzing the Diff: IPVS and IPv6 Integration** Okay, let's break down this diff. The key files that have been modified are: `include/net/ip_vs.h`, and then a series of files within `net/ipv6` and `net/netfilter/ipvs`. The `include/net/ip_vs.h` file is obviously a central header. Then, `net/ipv6/exthdrs_core.c` is definitely important; it's compiled into the IPv6 stack, either built-in or as a module, under `CONFIG_IPV6`, so changes there are relevant. Now, all those `ip_vs_*` files are clearly part of the IPVS subsystem. Specifically: * `net/netfilter/ipvs/ip_vs_conn.c`, `ip_vs_core.c`, and `ip_vs_ctl.c` look like the core components of IPVS. * `ip_vs_ftp.c` seems to add FTP support, dependent on TCP, connection tracking, NAT, and FTP connection tracking. * `ip_vs_lblc.c`, `ip_vs_lblcr.c` look like specific load-balancing algorithms. * `ip_vs_proto_ah_esp.c`, `ip_vs_proto_sctp.c`, `ip_vs_proto_tcp.c`, and `ip_vs_proto_udp.c` imply protocol-specific handling within IPVS, so that makes sense. * `ip_vs_sync.c` is probably related to synchronization and `ip_vs_xmit.c` to transmission. And, it has a dependency on `CONFIG_IP_VS_IPV6`, so this is a key area of focus for the changes. The interesting piece is the use of `ipv6_find_hdr` in `net/ipv6/exthdrs_core.c`. I need to figure out how or if this function is used by IPVS at all. Is this file even compiled if IPv6 isn't enabled? I'll check the Makefile in `net/ipv6` to confirm this. This will likely give me a good idea of why these files are being touched in the first place, and if there's any direct integration I need to be aware of. |
| 18/2 | 2026/11/17 07:47 | tool | grepper |
0mArgs:{
"Expression": "exthdrs_core",
"PathPrefixes": [
"net/ipv6/Makefile"
]
}Results: {
"Output": "net/ipv6/Makefile=44=obj-$(CONFIG_IPV6_FOU) += fou6.o\nnet/ipv6/Makefile-45-\nnet/ipv6/Makefile:46:obj-y += addrconf_core.o exthdrs_core.o ip6_checksum.o ip6_icmp.o\nnet/ipv6/Makefile-47-obj-$(CONFIG_INET) += output_core.o protocol.o \\\n"
} |
| 19/2 | 2026/11/17 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 40999 output: 26 thoughts: 52 Thoughts: Here's my thought process, as requested: **Navigating the Kernel Build System for IPv6 Header Options** Okay, so I'm digging into how IPv6 extension headers are built within the Linux kernel. My initial thought is that `net/ipv6/exthdrs_core.o` is going to be compiled if `CONFIG_IPV6` is enabled, and the `obj-y` assignment implies it's a part of the build within that `net/ipv6/` directory. That feels right, it's pretty standard practice. However, I should quickly verify this. It's best practice to be thorough when tracking down dependencies like this. I'm going to double check `net/Makefile`. I will verify that the module is included based on `CONFIG_IPV6`, just to be certain. I want to be 100% accurate. |
| 20/2 | 2026/11/17 07:47 | tool | grepper |
0mArgs:{
"Expression": "ipv6",
"PathPrefixes": [
"net/Makefile"
]
}Results: {
"Output": "net/Makefile=21=obj-$(CONFIG_INET_PSP)\t\t+= psp/\nnet/Makefile:22:obj-y\t\t\t\t+= ipv6/\nnet/Makefile-23-obj-$(CONFIG_PACKET)\t\t+= packet/\n"
} |
| 21/2 | 2026/11/17 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41334 output: 59 thoughts: 2927 Thoughts: **Deep Dive into IPVS: A Fuzzing Perspective**
Okay, so `net/Makefile` includes `ipv6/`, and `exthdrs_core.o` is built-in. That triggers a line of thought about IPVS and its dependencies on `CONFIG_IP_VS`, and `NETFILTER`, and even IPv6. Right, let's zero in on this commit and understand the changes. We need to see what's *different* and what that reveals about potential vulnerabilities or new functionality. We're looking for the key functions to target for fuzzing.
1. **`net/ipv6/exthdrs_core.c`**: The `ipv6_find_hdr` function has a significant update, specifically dealing with fragment headers. It's handling the offset within the fragment more carefully, ensuring correct interpretation, particularly in the context of IPVS. Crucially, it clarifies how `ipv6_find_hdr` interacts with IPVS logic in `net/netfilter/ipvs/ip_vs_core.c` where extra `sizeof(struct ipv6hdr)` is added in the case of non-first fragments. It's crucial this is right because incorrect interpretation could lead to security issues, data corruption, or even denial-of-service. This might be a source of problems, and the fix implies a potential off-by-one or data-interpretation bug that's now explicitly addressed.
2. **Connection Management (`net/netfilter/ipvs/ip_vs_conn.c`)**: This is a major area of change! It's all about lifetime, timers, refcounting, and unlinking. We see:
* Refcount and lock ordering changes in `ip_vs_conn_unlink`, including an added `smp_acquire__after_ctrl_dep()`. This suggests a bug fix or optimization related to concurrency.
* Timer management getting a serious overhaul (`__ip_vs_conn_put_timer`, `ip_vs_conn_del_reference`, `ip_vs_conn_del`, `ip_vs_conn_expire`). The addition of `ip_vs_conn_del_reference` to steal a ref from a pending timer, and the RCU usage with the `repeat:` loop means complex race conditions may have been addressed. If the refcounting is wrong, this could lead to use-after-free, double-free, or memory leaks. The changes to timer handling and refcount logic are screaming "race conditions" and "concurrency bugs."
* `ip_vs_bind_xmit` now uses `ip_vs_null_xmit_v6` when dealing with IPv6 and the `IP_VS_CONN_F_LOCALNODE` flag, possibly a new optimization path.
* The `ip_vs_conn_out_get` condition change suggests a subtle modification to connection selection.
* The changed prototype for `ip_vs_dest_update_overload` and implementation, along with `smp_mb()` and re-checking `totalconns`, points to another fix related to concurrent updates of the overload state.
3. **Destination Management (`net/netfilter/ipvs/ip_vs_ctl.c`)**: This is where things get really interesting, especially for fuzzing! This includes major changes surrounding destination trash and RCU grace periods! Destinations are now being trashed, synchronized with RCU, and potentially re-used. This is a *massive* concurrency minefield. The usage of `cond_synchronize_rcu`, `dest->rcu_state`, and `dest->need_gp` is telling. We're looking at protecting against use-after-free and related issues. The `lockdep_assert_held(&ipvs->service_mutex)` calls provide a clue for checking lock ordering and potential lock bugs that were found, or might still exist. Batched trash dest handling with `ip_vs_trash_save_dests` is likely performance or bug related.
4. **FTP Helper (`net/netfilter/ipvs/ip_vs_ftp.c`)**: The `is_control_port()` helper is interesting, but the real key is the addition of `nfct_seqadj_ext_add(ct)`. This suggests modifications to connection tracking and sequence adjustment with respect to FTP. This addition, alongside the conditional call to `nf_nat_mangle_tcp_packet`, hints at subtle manipulation of network packets. This could be exploitable, or it might be another concurrency concern (two threads trying to mangle the same packet).
5. **Load Balancing (`net/netfilter/ipvs/ip_vs
|
| 22/2 | 2026/11/17 07:48 | tool | grepper |
0mArgs:{
"Expression": "ip_vs_add_dest|ip_vs_del_dest|ip_vs_edit_dest",
"PathPrefixes": [
"net/netfilter/ipvs/ip_vs_ctl.c"
]
}Results: {
"Output": "net/netfilter/ipvs/ip_vs_ctl.c=1566=static int\nnet/netfilter/ipvs/ip_vs_ctl.c:1567:ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)\nnet/netfilter/ipvs/ip_vs_ctl.c-1568-{\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=1651=static int\nnet/netfilter/ipvs/ip_vs_ctl.c:1652:ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)\nnet/netfilter/ipvs/ip_vs_ctl.c-1653-{\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1698- */\nnet/netfilter/ipvs/ip_vs_ctl.c:1699:static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest,\nnet/netfilter/ipvs/ip_vs_ctl.c-1700-\t\t\t struct list_head *dest_trash, bool cleanup)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=1754=static int\nnet/netfilter/ipvs/ip_vs_ctl.c:1755:ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)\nnet/netfilter/ipvs/ip_vs_ctl.c-1756-{\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1778-\t */\nnet/netfilter/ipvs/ip_vs_ctl.c:1779:\t__ip_vs_del_dest(svc-\u003eipvs, dest, \u0026dest_trash, false);\nnet/netfilter/ipvs/ip_vs_ctl.c-1780-\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=2126=static void __ip_vs_del_service(struct ip_vs_service *svc,\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-2160-\t\t__ip_vs_unlink_dest(svc, dest, 0);\nnet/netfilter/ipvs/ip_vs_ctl.c:2161:\t\t__ip_vs_del_dest(svc-\u003eipvs, dest, dest_trash, cleanup);\nnet/netfilter/ipvs/ip_vs_ctl.c-2162-\t}\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=3545=do_ip_vs_set_ctl(struct sock *sk, int cmd, sockptr_t ptr, unsigned int len)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-3674-\tcase IP_VS_SO_SET_ADDDEST:\nnet/netfilter/ipvs/ip_vs_ctl.c:3675:\t\tret = ip_vs_add_dest(svc, \u0026udest);\nnet/netfilter/ipvs/ip_vs_ctl.c-3676-\t\tbreak;\nnet/netfilter/ipvs/ip_vs_ctl.c-3677-\tcase IP_VS_SO_SET_EDITDEST:\nnet/netfilter/ipvs/ip_vs_ctl.c:3678:\t\tret = ip_vs_edit_dest(svc, \u0026udest);\nnet/netfilter/ipvs/ip_vs_ctl.c-3679-\t\tbreak;\nnet/netfilter/ipvs/ip_vs_ctl.c-3680-\tcase IP_VS_SO_SET_DELDEST:\nnet/netfilter/ipvs/ip_vs_ctl.c:3681:\t\tret = ip_vs_del_dest(svc, \u0026udest);\nnet/netfilter/ipvs/ip_vs_ctl.c-3682-\t\tbreak;\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=4758=static int ip_vs_genl_set_cmd(struct sk_buff *skb, struct genl_info *info)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-4868-\tcase IPVS_CMD_NEW_DEST:\nnet/netfilter/ipvs/ip_vs_ctl.c:4869:\t\tret = ip_vs_add_dest(svc, \u0026udest);\nnet/netfilter/ipvs/ip_vs_ctl.c-4870-\t\tbreak;\nnet/netfilter/ipvs/ip_vs_ctl.c-4871-\tcase IPVS_CMD_SET_DEST:\nnet/netfilter/ipvs/ip_vs_ctl.c:4872:\t\tret = ip_vs_edit_dest(svc, \u0026udest);\nnet/netfilter/ipvs/ip_vs_ctl.c-4873-\t\tbreak;\nnet/netfilter/ipvs/ip_vs_ctl.c-4874-\tcase IPVS_CMD_DEL_DEST:\nnet/netfilter/ipvs/ip_vs_ctl.c:4875:\t\tret = ip_vs_del_dest(svc, \u0026udest);\nnet/netfilter/ipvs/ip_vs_ctl.c-4876-\t\tbreak;\n"
} |
| 23/2 | 2026/11/17 07:48 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 46716 output: 42 thoughts: 579 Thoughts: **Analyzing IPVS Symbol Visibility** Okay, so I'm digging into the IPVS code again, specifically looking at symbol visibility. I'm starting with `ip_vs_ctl.c`, and I see `ip_vs_add_dest`, `ip_vs_edit_dest`, `ip_vs_del_dest`, and `ip_vs_del_service`. These are all declared static within that file, which makes me think they *won't* have symbols in `vmlinux`, unless inlined. But then, `ip_vs_genl_set_cmd` and `do_ip_vs_set_ctl` are entry points, so obviously those will be visible. Then I realized I missed `ip_vs_dest_update_overload`, also defined in `ip_vs_ctl.c`, and that one *is* non-static. Interesting. Alright, let's move on to `ip_vs_core.c`. I have `ip_vs_leave` and `ip_vs_new_conn_out` which are non-static. The static ones in this file include `ip_vs_in_icmp`, `ip_vs_in_icmp_v6`, `ip_vs_in_hook` (which, of course, is a netfilter hook), `ip_vs_forward_icmp`, and `ip_vs_out_icmp_v6`. So, the core functionality has both internal and externally exposed functions. Now, let's jump over to `ip_vs_xmit.c`. Here, the pattern seems pretty clear. I've got `ip_vs_null_xmit`, `ip_vs_null_xmit_v6`, `ip_vs_bypass_xmit`, `ip_vs_bypass_xmit_v6`, `ip_vs_nat_xmit`, `ip_vs_nat_xmit_v6`, `ip_vs_tunnel_xmit`, `ip_vs_tunnel_xmit_v6`, `ip_vs_dr_xmit`, `ip_vs_dr_xmit_v6`, `ip_vs_icmp_xmit`, and `ip_vs_icmp_xmit_v6`, and they're *all* non-static. Makes sense; these are the transmission functions, so they need to be callable from other parts of the kernel. Finally, `ip_vs_ftp.c`. I see `ip_vs_ftp_out` and `ip_vs_ftp_in`, both static *function pointers* associated with IPVS application helpers. Now, I should make sure I didn't miss something. I will re-check `ip_vs_ftp.c` to make sure there are *no* non-static functions, or, perhaps, if they are defined inside a `struct ip_vs_app`. |
| 24/2 | 2026/11/17 07:48 | tool | grepper |
0mArgs:{
"Expression": "ip_vs_ftp_",
"PathPrefixes": [
"net/netfilter/ipvs/ip_vs_ftp.c"
]
}Results: {
"Output": "net/netfilter/ipvs/ip_vs_ftp.c=66=static bool is_control_port(u16 port)\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-77-\nnet/netfilter/ipvs/ip_vs_ftp.c:78:static char *ip_vs_ftp_data_ptr(struct sk_buff *skb, struct ip_vs_iphdr *ipvsh)\nnet/netfilter/ipvs/ip_vs_ftp.c-79-{\n--\nnet/netfilter/ipvs/ip_vs_ftp.c=88=static int\nnet/netfilter/ipvs/ip_vs_ftp.c:89:ip_vs_ftp_init_conn(struct ip_vs_app *app, struct ip_vs_conn *cp)\nnet/netfilter/ipvs/ip_vs_ftp.c-90-{\n--\nnet/netfilter/ipvs/ip_vs_ftp.c=97=static int\nnet/netfilter/ipvs/ip_vs_ftp.c:98:ip_vs_ftp_done_conn(struct ip_vs_app *app, struct ip_vs_conn *cp)\nnet/netfilter/ipvs/ip_vs_ftp.c-99-{\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-107- */\nnet/netfilter/ipvs/ip_vs_ftp.c:108:static int ip_vs_ftp_get_addrport(char *data, char *data_limit,\nnet/netfilter/ipvs/ip_vs_ftp.c-109-\t\t\t\t const char *pattern, size_t plen,\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-265- */\nnet/netfilter/ipvs/ip_vs_ftp.c:266:static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,\nnet/netfilter/ipvs/ip_vs_ftp.c-267-\t\t\t struct sk_buff *skb, int *diff,\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-291-\tif (cp-\u003eapp_data == (void *) IP_VS_FTP_PASV) {\nnet/netfilter/ipvs/ip_vs_ftp.c:292:\t\tdata = ip_vs_ftp_data_ptr(skb, ipvsh);\nnet/netfilter/ipvs/ip_vs_ftp.c-293-\t\tdata_limit = skb_tail_pointer(skb);\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-297-\nnet/netfilter/ipvs/ip_vs_ftp.c:298:\t\tif (ip_vs_ftp_get_addrport(data, data_limit,\nnet/netfilter/ipvs/ip_vs_ftp.c-299-\t\t\t\t\t SERVER_STRING_PASV,\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-308-\t} else if (cp-\u003eapp_data == (void *) IP_VS_FTP_EPSV) {\nnet/netfilter/ipvs/ip_vs_ftp.c:309:\t\tdata = ip_vs_ftp_data_ptr(skb, ipvsh);\nnet/netfilter/ipvs/ip_vs_ftp.c-310-\t\tdata_limit = skb_tail_pointer(skb);\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-318-\t\tfrom = cp-\u003edaddr;\nnet/netfilter/ipvs/ip_vs_ftp.c:319:\t\tif (ip_vs_ftp_get_addrport(data, data_limit,\nnet/netfilter/ipvs/ip_vs_ftp.c-320-\t\t\t\t\t SERVER_STRING_EPSV,\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-445- */\nnet/netfilter/ipvs/ip_vs_ftp.c:446:static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,\nnet/netfilter/ipvs/ip_vs_ftp.c-447-\t\t\tstruct sk_buff *skb, int *diff,\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-466-\nnet/netfilter/ipvs/ip_vs_ftp.c:467:\tdata = data_start = ip_vs_ftp_data_ptr(skb, ipvsh);\nnet/netfilter/ipvs/ip_vs_ftp.c-468-\tdata_limit = skb_tail_pointer(skb);\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-519-\tif (cp-\u003eaf == AF_INET \u0026\u0026\nnet/netfilter/ipvs/ip_vs_ftp.c:520:\t ip_vs_ftp_get_addrport(data_start, data_limit,\nnet/netfilter/ipvs/ip_vs_ftp.c-521-\t\t\t\t CLIENT_STRING_PORT,\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-533-\t\t\t ntohs(cp-\u003evport)-1);\nnet/netfilter/ipvs/ip_vs_ftp.c:534:\t} else if (ip_vs_ftp_get_addrport(data_start, data_limit,\nnet/netfilter/ipvs/ip_vs_ftp.c-535-\t\t\t\t\t CLIENT_STRING_EPRT,\n--\nnet/netfilter/ipvs/ip_vs_ftp.c=589=static struct ip_vs_app ip_vs_ftp = {\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-594-\t.incs_list =\tLIST_HEAD_INIT(ip_vs_ftp.incs_list),\nnet/netfilter/ipvs/ip_vs_ftp.c:595:\t.init_conn =\tip_vs_ftp_init_conn,\nnet/netfilter/ipvs/ip_vs_ftp.c:596:\t.done_conn =\tip_vs_ftp_done_conn,\nnet/netfilter/ipvs/ip_vs_ftp.c-597-\t.bind_conn =\tNULL,\nnet/netfilter/ipvs/ip_vs_ftp.c-598-\t.unbind_conn =\tNULL,\nnet/netfilter/ipvs/ip_vs_ftp.c:599:\t.pkt_out =\tip_vs_ftp_out,\nnet/netfilter/ipvs/ip_vs_ftp.c:600:\t.pkt_in =\tip_vs_ftp_in,\nnet/netfilter/ipvs/ip_vs_ftp.c-601-};\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-605- */\nnet/netfilter/ipvs/ip_vs_ftp.c:606:static int __net_init __ip_vs_ftp_init(struct net *net)\nnet/netfilter/ipvs/ip_vs_ftp.c-607-{\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-634- */\nnet/netfilter/ipvs/ip_vs_ftp.c:635:static void __ip_vs_ftp_exit(struct net *net)\nnet/netfilter/ipvs/ip_vs_ftp.c-636-{\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-644-\nnet/netfilter/ipvs/ip_vs_ftp.c:645:static struct pernet_operations ip_vs_ftp_ops = {\nnet/netfilter/ipvs/ip_vs_ftp.c:646:\t.init = __ip_vs_ftp_init,\nnet/netfilter/ipvs/ip_vs_ftp.c:647:\t.exit = __ip_vs_ftp_exit,\nnet/netfilter/ipvs/ip_vs_ftp.c-648-};\nnet/netfilter/ipvs/ip_vs_ftp.c-649-\nnet/netfilter/ipvs/ip_vs_ftp.c:650:static int __init ip_vs_ftp_init(void)\nnet/netfilter/ipvs/ip_vs_ftp.c-651-{\nnet/netfilter/ipvs/ip_vs_ftp.c-652-\t/* rcu_barrier() is called by netns on error */\nnet/netfilter/ipvs/ip_vs_ftp.c:653:\treturn register_pernet_subsys(\u0026ip_vs_ftp_ops);\nnet/netfilter/ipvs/ip_vs_ftp.c-654-}\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-658- */\nnet/netfilter/ipvs/ip_vs_ftp.c:659:static void __exit ip_vs_ftp_exit(void)\nnet/netfilter/ipvs/ip_vs_ftp.c-660-{\nnet/netfilter/ipvs/ip_vs_ftp.c-661-\texiting_module = true;\nnet/netfilter/ipvs/ip_vs_ftp.c:662:\tunregister_pernet_subsys(\u0026ip_vs_ftp_ops);\nnet/netfilter/ipvs/ip_vs_ftp.c-663-\t/* rcu_barrier() is called by netns */\n--\nnet/netfilter/ipvs/ip_vs_ftp.c-666-\nnet/netfilter/ipvs/ip_vs_ftp.c:667:module_init(ip_vs_ftp_init);\nnet/netfilter/ipvs/ip_vs_ftp.c:668:module_exit(ip_vs_ftp_exit);\nnet/netfilter/ipvs/ip_vs_ftp.c-669-MODULE_LICENSE(\"GPL\");\n"
} |
| 25/2 | 2026/11/17 07:48 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50466 output: 34 thoughts: 113 Thoughts: **Analyzing the FTP Packet Handling Logic** Okay, so I need to understand how FTP traffic is being managed within this IPVS setup. Looking at the code, `ip_vs_ftp_out` and `ip_vs_ftp_in` are the static functions responsible for handling FTP-specific packets. They are invoked through the `ip_vs_ftp` application structure, specifically via the `app->pkt_out` and `app->pkt_in` function pointers. These function pointers are, in turn, called from `ip_vs_app_pkt_out` and `ip_vs_app_pkt_in` within `ip_vs_app.c`. Right, that's the calling chain. So, to really understand the logic, I need to dig into the implementation of `ip_vs_app_pkt_out` in `ip_vs_app.c`. That's where the core packet processing for outbound traffic happens, and thus where I need to focus my attention. Let's see what's going on in there. |
| 26/2 | 2026/11/17 07:48 | tool | grepper |
0mArgs:{
"Expression": "app-\u003epkt_out",
"PathPrefixes": [
"net/netfilter/ipvs/"
]
}Results: {
"Output": "net/netfilter/ipvs/ip_vs_app.c=359=static inline int app_tcp_pkt_out(struct ip_vs_conn *cp, struct sk_buff *skb,\n--\nnet/netfilter/ipvs/ip_vs_app.c-387-\t */\nnet/netfilter/ipvs/ip_vs_app.c:388:\tif (app-\u003epkt_out == NULL)\nnet/netfilter/ipvs/ip_vs_app.c-389-\t\treturn 1;\nnet/netfilter/ipvs/ip_vs_app.c-390-\nnet/netfilter/ipvs/ip_vs_app.c:391:\tif (!app-\u003epkt_out(app, cp, skb, \u0026diff, ipvsh))\nnet/netfilter/ipvs/ip_vs_app.c-392-\t\treturn 0;\n--\nnet/netfilter/ipvs/ip_vs_app.c=409=int ip_vs_app_pkt_out(struct ip_vs_conn *cp, struct sk_buff *skb,\n--\nnet/netfilter/ipvs/ip_vs_app.c-427-\t */\nnet/netfilter/ipvs/ip_vs_app.c:428:\tif (app-\u003epkt_out == NULL)\nnet/netfilter/ipvs/ip_vs_app.c-429-\t\treturn 1;\nnet/netfilter/ipvs/ip_vs_app.c-430-\nnet/netfilter/ipvs/ip_vs_app.c:431:\treturn app-\u003epkt_out(app, cp, skb, NULL, ipvsh);\nnet/netfilter/ipvs/ip_vs_app.c-432-}\n"
} |
| 27/2 | 2026/11/17 07:48 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 51289 output: 36 thoughts: 2500 Thoughts: **Analysis of IPVS Code and Configuration Requirements for Fuzzing** Alright, let's break this down. My goal is to identify key kernel functions for fuzzing, specifically within the IPVS (IP Virtual Server) subsystem, and determine the necessary configurations. `ip_vs_app_pkt_out` and `ip_vs_app_pkt_in` are non-static in `ip_vs_app.c`, which makes them accessible. However, `ip_vs_ftp_out` and `ip_vs_ftp_in`, while static, are passed by address in a global struct. This is important because static functions passed this way *won't* be inlined and *will* have symbols in the object file, and that's something the fuzzer can key on. I need to make sure I pick the right symbols, so I need to avoid ubiquitous functions (memory allocators, core synchronization primitives, etc.) which would be a waste of fuzzing effort. Instead, I need to pinpoint specific feature logic and entry points. I have reviewed the files `ip_vs_lblc.c` and `ip_vs_lblcr.c` and they have `ip_vs_lblc_schedule` and `ip_vs_lblcr_schedule` which are assigned to scheduler structs, so I will take note of these. `ipv6_find_hdr` is EXPORT_SYMBOL, so it is a good starting point. I can pull that in. In the sync module, `ip_vs_sync_conn` is non-static, while `ip_vs_proc_conn` is static. From `ip_vs_conn.c`, I've noted several non-static functions: `ip_vs_conn_new`, `ip_vs_conn_expire_now`, `ip_vs_conn_out_get`, and `ip_vs_conn_put`. `ip_vs_conn_expire` is a timer callback (static function), but its address is passed to `timer_setup`. Also, I've seen that `ip_vs_leave`, `ip_vs_new_conn_out`, `ip_vs_dest_update_overload`, `ip_vs_add_dest`, `ip_vs_del_dest` are worth noting. From `ip_vs_xmit.c`, I need to keep in mind the various xmit functions, including their IPv6 variants, like `ip_vs_nat_xmit`, `ip_vs_tunnel_xmit`, etc. Now, based on the principle of targeting specific feature logic, I've identified several key functions that seem promising: * `ipv6_find_hdr` (net/ipv6/exthdrs_core.c) * `ip_vs_conn_expire` (net/netfilter/ipvs/ip_vs_conn.c) * `ip_vs_conn_expire_now` (net/netfilter/ipvs/ip_vs_conn.c) * `ip_vs_conn_out_get` (net/netfilter/ipvs/ip_vs_conn.c) * `ip_vs_leave` (net/netfilter/ipvs/ip_vs_core.c) * `ip_vs_new_conn_out` (net/netfilter/ipvs/ip_vs_core.c) * `ip_vs_dest_update_overload` (net/netfilter/ipvs/ip_vs_ctl.c) * `ip_vs_add_dest` (net/netfilter/ipvs/ip_vs_ctl.c) * `ip_vs_del_dest` (net/netfilter/ipvs/ip_vs_ctl.c) * `ip_vs_sync_conn` (net/netfilter/ipvs/ip_vs_sync.c) * `ip_vs_ftp_out` (net/netfilter/ipvs/ip_vs_ftp.c) * `ip_vs_ftp_in` (net/netfilter/ipvs/ip_vs_ftp.c) * `ip_vs_nat_xmit` (net/netfilter/ipvs/ip_vs_xmit.c) * `ip_vs_tunnel_xmit` (net/netfilter/ipvs/ip_vs_xmit.c) * `ip_vs_lblc_schedule` (net/netfilter/ipvs/ip_vs_lblc.c) * |
| 28/2 | 2026/11/17 07:48 | tool | grepper |
0mArgs:{
"Expression": "#if",
"PathPrefixes": [
"net/ipv6/exthdrs_core.c"
]
}Results: {
"Output": "no matches"
} |
| 29/2 | 2026/11/17 07:48 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 54864 output: 426 thoughts: 1108 Thoughts: **Analyzing the IPVS and IPv6 Changes for Fuzzing** Okay, so I need to assess this patch series for fuzzing potential. First, `exthdrs_core.c` isn't using `#ifdef` preprocessor directives, but it's compiled into `ipv6/` via `net/ipv6/Makefile`, and requires `CONFIG_IPV6` for IPv6 networking. This is a good starting point. Next, I'll examine the locking and RCU aspects. I see `lockdep_assert_held(&ipvs->service_mutex)` in `ip_vs_trash_get_dest()` within `ip_vs_ctl.c`, confirming some locking is in place, which could have interesting fuzzing angles. I also see `cond_synchronize_rcu(dest->rcu_state)` in `ip_vs_rs_hash()` and `ip_vs_add_dest()`, suggesting RCU synchronization is crucial. Further, `smp_acquire__after_ctrl_dep()` is in `ip_vs_conn_unlink()`. Lastly, changes to `maybe_update_pmtu` in `ip_vs_xmit.c` can be explored. Let's quickly check the associated configs. I've got to make sure all dependencies are accounted for: `IP_VS`, `IP_VS_IPV6`, `IP_VS_PROTO_TCP`, `IP_VS_PROTO_UDP`, `IP_VS_PROTO_SCTP`, `IP_VS_PROTO_AH`, `IP_VS_PROTO_ESP`, `IP_VS_FTP`, `IP_VS_LBLC`, `IP_VS_LBLCR`, `NF_CONNTRACK_FTP`, `NF_CONNTRACK`, `NF_NAT`, and `IPV6`. Now, let's look at `ip_vs_sync.c`. Does it have its own config? No, according to `net/netfilter/ipvs/Makefile`, `ip_vs_sync.o` is part of `ip_vs.o` and thus enabled by `CONFIG_IP_VS`. That's good to know, no separate config. Alright, time to solidify my assessment. It's a "WorthFuzzing" situation, definitely. This series has some significant, far-reaching changes. It's touching core IPVS, specifically with IPv6 extensions. I need to clearly articulate the reasoning: the patch series modifies IPVS significantly, encompassing RCU grace period tracking, lockdep assertions, connection timer and refcount lifecycle changes, conntrack sequence and control port adjustments, overload state management and memory barriers, PMTU handling updates, and handling of non-first IPv6 fragment offsets. It affects core networking code reachable from userspace and when handling packet reception. I need a set of *specific* symbols as the "FocusSymbols". I am going to concentrate on the following which seem to be key modification points: `ipv6_find_hdr`, `ip_vs_conn_expire`, `ip_vs_conn_expire_now`, `ip_vs_conn_out_get`, `ip_vs_dest_update_overload`, `ip_vs_add_dest`, `ip_vs_del_dest`, `ip_vs_leave`, `ip_vs_new_conn_out`, `ip_vs_ftp_out`, `ip_vs_ftp_in`, `ip_vs_sync_conn`, `ip_vs_lblc_schedule`, `ip_vs_lblcr_schedule`, `ip_vs_nat_xmit`, `ip_vs_tunnel_xmit`. Finally, the following configurations are required to reproduce the effects of the changes: `IP_VS`, `IP_VS_IPV6`, `IP_VS_PROTO_TCP`, `IP_VS_PROTO_UDP`, `IP_VS_PROTO_SCTP`, `IP_VS_PROTO_AH`, `IP_VS_PROTO_ESP`, `IP_VS_FTP`, `IP_VS_LBLC`, `IP_VS_LBLCR`, `NF_CONNTRACK`, `NF_CONNTRACK_FTP`, `NF_NAT`, `IPV6`. Okay, I think I have everything. Let's run `set-results`. |
| 30/2 | 2026/11/17 07:49 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"IP_VS",
"IP_VS_IPV6",
"IP_VS_PROTO_TCP",
"IP_VS_PROTO_UDP",
"IP_VS_PROTO_SCTP",
"IP_VS_PROTO_AH",
"IP_VS_PROTO_ESP",
"IP_VS_FTP",
"IP_VS_LBLC",
"IP_VS_LBLCR",
"NF_CONNTRACK",
"NF_CONNTRACK_FTP",
"NF_NAT",
"IPV6"
],
"FocusSymbols": [
"ipv6_find_hdr",
"ip_vs_conn_expire",
"ip_vs_conn_expire_now",
"ip_vs_conn_out_get",
"ip_vs_dest_update_overload",
"ip_vs_add_dest",
"ip_vs_del_dest",
"ip_vs_leave",
"ip_vs_new_conn_out",
"ip_vs_ftp_out",
"ip_vs_ftp_in",
"ip_vs_sync_conn",
"ip_vs_lblc_schedule",
"ip_vs_lblcr_schedule",
"ip_vs_nat_xmit",
"ip_vs_tunnel_xmit"
],
"Reasoning": "The patch series modifies core networking code in IPVS and IPv6 extension header parsing. Changes include RCU grace-period synchronization when managing destination life cycles (trash/rehashing), lockdep assertions in destination lookups, refcount and timer synchronization overhauls in connection deletion/expiry, seqadj conntrack extension handling in the FTP helper, PMTU socket checks, and payload offset adjustments for IPv6 non-first fragments. All modified paths are reachable via standard networking and IPVS netlink/sockopt interfaces.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"IP_VS",
"IP_VS_IPV6",
"IP_VS_PROTO_TCP",
"IP_VS_PROTO_UDP",
"IP_VS_PROTO_SCTP",
"IP_VS_PROTO_AH",
"IP_VS_PROTO_ESP",
"IP_VS_FTP",
"IP_VS_LBLC",
"IP_VS_LBLCR",
"NF_CONNTRACK",
"NF_CONNTRACK_FTP",
"NF_NAT",
"IPV6"
],
"FocusSymbols": [
"ipv6_find_hdr",
"ip_vs_conn_expire",
"ip_vs_conn_expire_now",
"ip_vs_conn_out_get",
"ip_vs_dest_update_overload",
"ip_vs_add_dest",
"ip_vs_del_dest",
"ip_vs_leave",
"ip_vs_new_conn_out",
"ip_vs_ftp_out",
"ip_vs_ftp_in",
"ip_vs_sync_conn",
"ip_vs_lblc_schedule",
"ip_vs_lblcr_schedule",
"ip_vs_nat_xmit",
"ip_vs_tunnel_xmit"
],
"Reasoning": "The patch series modifies core networking code in IPVS and IPv6 extension header parsing. Changes include RCU grace-period synchronization when managing destination life cycles (trash/rehashing), lockdep assertions in destination lookups, refcount and timer synchronization overhauls in connection deletion/expiry, seqadj conntrack extension handling in the FTP helper, PMTU socket checks, and payload offset adjustments for IPv6 non-first fragments. All modified paths are reachable via standard networking and IPVS netlink/sockopt interfaces.",
"WorthFuzzing": true
} |
| 31/1 | 2026/11/17 07:49 | action | If |
3mArgs:{
"WorthFuzzing": true
}Results: null |
| 32/2 | 2026/11/17 07:49 | agent | kmsan-evaluator |
3mModel:core Args: null Results: {
"KMSANReasoning": "The patch series makes several networking and IPVS improvements:\n1. Thread-safety and synchronization in IPVS sync (`ip_vs_sync.c`), copying connection sequence options under `cp-\u003elock`. The local variable `struct ip_vs_sync_conn_options opts` is strictly guarded by `flags \u0026 IP_VS_CONN_F_SEQ_MASK`, matching the condition under which it is populated from `cp-\u003esync_conn_opt` (which itself is zero-initialized on connection creation).\n2. RCU grace period and lifecycle fixes in `ip_vs_ctl.c` and `ip_vs_conn.c` (using `need_gp`, `rcu_state`, and `cond_synchronize_rcu`), where destination structures are zero-allocated via `kzalloc_obj`.\n3. Hook state propagation (`const struct nf_hook_state *state`) to xmit functions for accurate socket inspection during PMTU updates.\n4. Ordering fix for `nfct_seqadj_ext_add` in IPVS FTP conntrack handling to avoid conntrack extension reallocation bugs.\n5. Offset and length corrections for IPv6 fragment headers (`ipv6_find_hdr`) and ICMPv6 packets, operating on network skb data bounded by packet lengths.\n6. Input validation dropping connections with invalid zero ports.\n\nNone of these changes introduce or expose uninitialized memory reads or kernel-to-user information leaks:\n- No structures or paddings copied to user space are modified or added.\n- All newly added struct fields (`need_gp`, `rcu_state`) reside in zero-allocated heap memory (`kzalloc_obj`).\n- Potential issues introduced or touched by these changes are concurrency bugs, use-after-free/RCU issues, or skb boundary errors, all of which are covered by standard KASAN, LOCKDEP, and kernel debuggers.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit c4e0762c669a3125d192b6e9d305ae1e8a4bed4e
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Nov 17 07:46:41 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index 9a83bff32569da..fdb3a9063e6048 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -731,7 +731,8 @@ struct ip_vs_protocol {
int af, struct sk_buff *skb,
struct ip_vs_proto_data *pd,
int *verdict, struct ip_vs_conn **cpp,
- struct ip_vs_iphdr *iph);
+ struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
struct ip_vs_conn *
(*conn_in_get)(struct netns_ipvs *ipvs,
@@ -872,7 +873,8 @@ struct ip_vs_conn {
* NF_ACCEPT can be returned when destination is local.
*/
int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
struct rcu_head rcu_head;
};
@@ -1021,7 +1023,9 @@ struct ip_vs_dest {
struct rcu_head rcu_head;
struct list_head t_list; /* in dest_trash */
- unsigned int in_rs_table:1; /* we are in rs_table */
+ unsigned long rcu_state; /* GP cookie on unlink (trash or rehash) */
+ unsigned int in_rs_table:1, /* we are in rs_table */
+ need_gp:1; /* Need GP on rehash */
};
/* The scheduler object */
@@ -1685,7 +1689,6 @@ static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp)
/* put back the conn without restarting its timer */
static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
{
- smp_mb__before_atomic();
refcount_dec(&cp->refcnt);
}
void ip_vs_conn_put(struct ip_vs_conn *cp);
@@ -1871,7 +1874,8 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
struct ip_vs_proto_data *pd, int *ignored,
struct ip_vs_iphdr *iph);
int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
- struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph);
+ struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);
@@ -1923,7 +1927,7 @@ static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)
kfree(dest);
}
-void ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload);
+void ip_vs_dest_update_overload(struct ip_vs_dest *dest);
/* Check if dest is in overloaded state */
static inline bool ip_vs_dest_is_overloaded(const struct ip_vs_dest *dest)
@@ -1986,32 +1990,46 @@ static inline int ip_vs_est_max_threads(struct netns_ipvs *ipvs)
/* Various IPVS packet transmitters (from ip_vs_xmit.c) */
int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
struct ip_vs_protocol *pp, unsigned int toff,
- unsigned int hooknum, struct ip_vs_iphdr *ciph);
+ const struct nf_hook_state *state,
+ struct ip_vs_iphdr *ciph);
void ip_vs_dest_dst_rcu_free(struct rcu_head *head);
#ifdef CONFIG_IP_VS_IPV6
+int ip_vs_null_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state);
int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
struct ip_vs_protocol *pp, unsigned int toff,
- unsigned int hooknum, struct ip_vs_iphdr *ciph);
+ const struct nf_hook_state *state,
+ struct ip_vs_iphdr *ciph);
#endif
#ifdef CONFIG_SYSCTL
diff --git a/net/ipv6/exthdrs_core.c b/net/ipv6/exthdrs_core.c
index 4a9748338cf400..e27f5b8cc15422 100644
--- a/net/ipv6/exthdrs_core.c
+++ b/net/ipv6/exthdrs_core.c
@@ -179,7 +179,10 @@ EXPORT_SYMBOL_GPL(ipv6_find_tlv);
*
* Note that non-1st fragment is special case that "the protocol number
* of last header" is "next header" field in Fragment header. In this case,
- * *offset is meaningless and fragment offset is stored in *fragoff if fragoff
+ * for target < 0, *offset points immediately after the Fragment header,
+ * at the start of the fragment payload. Callers must still account for
+ * the nonzero fragment offset before interpreting the payload. The
+ * fragment offset is stored in *fragoff if fragoff
* isn't NULL.
*
* if flags is not NULL and it's a fragment, then the frag flag
@@ -261,6 +264,7 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
hp->nexthdr == NEXTHDR_NONE)) {
if (fragoff)
*fragoff = _frag_off;
+ *offset = start + sizeof(struct frag_hdr);
return hp->nexthdr;
}
if (!found)
diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 94f25fb7d87e45..7cb8de634f5f9a 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -293,7 +293,6 @@ static inline int ip_vs_conn_hash(struct ip_vs_conn *cp)
cp->flags |= IP_VS_CONN_F_HASHED;
WRITE_ONCE(cp->hn0.hash_key, hash_key);
WRITE_ONCE(cp->hn1.hash_key, hash_key2);
- refcount_inc(&cp->refcnt);
hlist_bl_add_head_rcu(&cp->hn0.node, head);
if (use2)
hlist_bl_add_head_rcu(&cp->hn1.node, head2);
@@ -319,11 +318,27 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)
struct hlist_bl_head *head, *head2;
u32 hash_key, hash_key2;
struct ip_vs_rht *t;
- bool ret = false;
bool use2;
+ /* No more users and no running/pending timer except us? */
+ if (!refcount_dec_if_one(&cp->refcnt))
+ return false;
+
+ /* The ONE_PACKET connection is special:
+ * - the flag is present only for normal connections, not for templates
+ * - its timer is never started
+ * - it is never hashed, so you can not find it and delete it
+ * - it is not synced
+ * - it has only one user
+ * - it is freed after use immediately
+ */
if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
- return refcount_dec_if_one(&cp->refcnt);
+ return true;
+
+ /* Add the needed ACQUIRE barrier between the above
+ * refcount_dec_if_one() call and the read of cp fields
+ */
+ smp_acquire__after_ctrl_dep();
rcu_read_lock();
local_bh_disable();
@@ -337,15 +352,11 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)
false /* new_hash2 */, &head, &head2);
if (cp->flags & IP_VS_CONN_F_HASHED) {
- /* Decrease refcnt and unlink conn only if we are last user */
- if (use2 == ip_vs_conn_use_hash2(cp) &&
- refcount_dec_if_one(&cp->refcnt)) {
- hlist_bl_del_rcu(&cp->hn0.node);
- if (use2)
- hlist_bl_del_rcu(&cp->hn1.node);
- cp->flags &= ~IP_VS_CONN_F_HASHED;
- ret = true;
- }
+ /* Unlink conn as we are the last user */
+ hlist_bl_del_rcu(&cp->hn0.node);
+ if (use2)
+ hlist_bl_del_rcu(&cp->hn1.node);
+ cp->flags &= ~IP_VS_CONN_F_HASHED;
}
conn_tab_unlock(head, head2);
@@ -353,7 +364,7 @@ static inline bool ip_vs_conn_unlink(struct ip_vs_conn *cp)
local_bh_enable();
rcu_read_unlock();
- return ret;
+ return true;
}
@@ -579,6 +590,8 @@ struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p)
ip_vs_addr_equal(p->af, p->vaddr,
&cp->caddr) &&
ip_vs_addr_equal(p->af, p->caddr, saddr) &&
+ (!p->vport ^
+ (!(cp->flags & IP_VS_CONN_F_NO_CPORT))) &&
p->protocol == cp->protocol) {
if (__ip_vs_conn_get(cp))
goto out;
@@ -621,9 +634,12 @@ static void __ip_vs_conn_put_timer(struct ip_vs_conn *cp)
{
unsigned long t = (cp->flags & IP_VS_CONN_F_ONE_PACKET) ?
0 : cp->timeout;
- mod_timer(&cp->timer, jiffies+t);
- __ip_vs_conn_put(cp);
+ /* Handoff our reference to the timer if it was just armed,
+ * put the reference if timer was already pending.
+ */
+ if (mod_timer(&cp->timer, jiffies + t))
+ __ip_vs_conn_put(cp);
}
void ip_vs_conn_put(struct ip_vs_conn *cp)
@@ -1041,7 +1057,7 @@ static inline void ip_vs_bind_xmit(struct ip_vs_conn *cp)
break;
case IP_VS_CONN_F_LOCALNODE:
- cp->packet_xmit = ip_vs_null_xmit;
+ cp->packet_xmit = ip_vs_null_xmit_v6;
break;
case IP_VS_CONN_F_BYPASS:
@@ -1154,7 +1170,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
atomic_inc(&dest->activeconns);
tc = atomic_inc_return(&dest->totalconns);
if (tc >= READ_ONCE(dest->u_threshold_val))
- ip_vs_dest_update_overload(dest, true);
+ ip_vs_dest_update_overload(dest);
} else {
/* It is a persistent connection/template, so increase
the persistent connection counter */
@@ -1247,7 +1263,7 @@ static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp)
atomic_dec(&dest->activeconns);
tc = atomic_fetch_dec(&dest->totalconns);
if (tc <= READ_ONCE(dest->l_threshold_val))
- ip_vs_dest_update_overload(dest, false);
+ ip_vs_dest_update_overload(dest);
} else {
/* It is a persistent connection/template, so decrease
the persistent connection counter */
@@ -1322,36 +1338,48 @@ static void ip_vs_conn_rcu_free(struct rcu_head *head)
kmem_cache_free(ip_vs_conn_cachep, cp);
}
-/* Try to delete connection while not holding reference */
-static void ip_vs_conn_del(struct ip_vs_conn *cp)
+/* Try to steal the reference from the pending timer.
+ * It can be called concurrently and always under RCU lock
+ * to protect from connection deletion from others.
+ */
+static bool ip_vs_conn_del_reference(struct ip_vs_conn *cp)
{
- if (timer_delete(&cp->timer)) {
- /* Drop cp->control chain too */
- if (cp->control)
- cp->timeout = 0;
- ip_vs_conn_expire(&cp->timer);
- }
+ /* Steal reference from the pending timer */
+ if (!timer_delete(&cp->timer))
+ return false;
+
+ /* Drop cp->control chain too */
+ if (cp->control)
+ cp->timeout = 0;
+ return true;
}
-/* Try to delete connection while holding reference */
-static void ip_vs_conn_del_put(struct ip_vs_conn *cp)
+/* Try to delete connection while not holding reference.
+ * Used when we need to remove the connection immediately
+ * and without overloading the timer processing.
+ * OTOH, we use ip_vs_conn_expire_now() when we prefer to
+ * leave the current context (packet processing) and to
+ * remove the connection from timer.
+ */
+static void ip_vs_conn_del(struct ip_vs_conn *cp)
{
- if (timer_delete(&cp->timer)) {
- /* Drop cp->control chain too */
- if (cp->control)
- cp->timeout = 0;
- __ip_vs_conn_put(cp);
+ if (ip_vs_conn_del_reference(cp))
ip_vs_conn_expire(&cp->timer);
- } else {
- __ip_vs_conn_put(cp);
- }
}
+/* Connection is removed in the following steps:
+ * - timer expires (with ref) or connection is deleted (with stolen ref)
+ * - there should be no more users except us (pending/running timer,
+ * n_control>0 or refcnt>1)
+ */
static void ip_vs_conn_expire(struct timer_list *t)
{
struct ip_vs_conn *cp = timer_container_of(cp, t, timer);
struct netns_ipvs *ipvs = cp->ipvs;
+ rcu_read_lock();
+
+repeat:
/*
* do I control anybody?
*/
@@ -1361,23 +1389,17 @@ static void ip_vs_conn_expire(struct timer_list *t)
/* Unlink conn if not referenced anymore */
if (likely(ip_vs_conn_unlink(cp))) {
struct ip_vs_conn *ct = cp->control;
-
- /* delete the timer if it is activated by other users */
- timer_delete(&cp->timer);
+ bool next = false;
/* does anybody control me? */
if (ct) {
- bool has_ref = !cp->timeout && __ip_vs_conn_get(ct);
-
ip_vs_control_del(cp);
/* Drop CTL or non-assured TPL if not used anymore */
- if (has_ref && !atomic_read(&ct->n_control) &&
+ if (!cp->timeout && !atomic_read(&ct->n_control) &&
(!(ct->flags & IP_VS_CONN_F_TEMPLATE) ||
!(ct->state & IP_VS_CTPL_S_ASSURED))) {
IP_VS_DBG(4, "drop controlling connection\n");
- ip_vs_conn_del_put(ct);
- } else if (has_ref) {
- __ip_vs_conn_put(ct);
+ next = ip_vs_conn_del_reference(ct);
}
}
@@ -1405,7 +1427,11 @@ static void ip_vs_conn_expire(struct timer_list *t)
else
call_rcu(&cp->rcu_head, ip_vs_conn_rcu_free);
atomic_dec(&ipvs->conn_count);
- return;
+ if (next) {
+ cp = ct;
+ goto repeat;
+ }
+ goto out;
}
expire_later:
@@ -1413,13 +1439,16 @@ static void ip_vs_conn_expire(struct timer_list *t)
refcount_read(&cp->refcnt),
atomic_read(&cp->n_control));
- refcount_inc(&cp->refcnt);
- cp->timeout = 60*HZ;
+ if (cp->timeout || atomic_read(&cp->n_control))
+ cp->timeout = 60 * HZ;
if (ipvs->sync_state & IP_VS_STATE_MASTER)
ip_vs_sync_conn(ipvs, cp, sysctl_sync_threshold(ipvs));
__ip_vs_conn_put_timer(cp);
+
+out:
+ rcu_read_unlock();
}
/* Modify timer, so that it expires as soon as possible.
@@ -1432,7 +1461,7 @@ static void ip_vs_conn_expire(struct timer_list *t)
void ip_vs_conn_expire_now(struct ip_vs_conn *cp)
{
/* Using mod_timer_pending will ensure the timer is not
- * modified after the final timer_delete in ip_vs_conn_expire.
+ * started without giving it new reference.
*/
if (timer_pending(&cp->timer) &&
time_after(cp->timer.expires, jiffies))
@@ -1500,9 +1529,9 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
spin_lock_init(&cp->lock);
/*
- * Set the entry is referenced by the current thread before hashing
- * it in the table, so that other thread run ip_vs_random_dropentry
- * but cannot drop this entry.
+ * Set the entry as referenced by the current thread before starting
+ * the timer and giving it our reference to allow other threads to
+ * run ip_vs_random_dropentry() or any deletion method safely.
*/
refcount_set(&cp->refcnt, 1);
diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
index 8a3c880fdb266e..85ea82367cfe32 100644
--- a/net/netfilter/ipvs/ip_vs_core.c
+++ b/net/netfilter/ipvs/ip_vs_core.c
@@ -760,7 +760,8 @@ static inline int ip_vs_addr_is_unicast(struct net *net, int af,
* no destination is available for a new connection.
*/
int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
- struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph)
+ struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state)
{
__be16 _ports[2], *pptr, dport;
struct netns_ipvs *ipvs = svc->ipvs;
@@ -805,7 +806,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
ip_vs_set_state(cp, IP_VS_DIR_INPUT, skb, pd, iph->len);
/* transmit the first SYN packet */
- ret = cp->packet_xmit(skb, cp, pd->pp, iph);
+ ret = cp->packet_xmit(skb, cp, pd->pp, iph, state);
/* do not touch skb anymore */
if ((cp->flags & IP_VS_CONN_F_ONE_PACKET) && cp->control)
@@ -1206,6 +1207,13 @@ static int ip_vs_out_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,
true, &ciph))
return NF_ACCEPT; /* The packet looks wrong, ignore */
+ /* ipv6_find_hdr() does not include the embedded header for
+ * non-first fragments, add it so that ESP can pass and the
+ * NAT writable checks cover the rewritten addresses
+ */
+ if (ciph.len == ciph.off)
+ ciph.len += sizeof(struct ipv6hdr);
+
pp = ip_vs_proto_get(ciph.protocol);
if (!pp)
return NF_ACCEPT;
@@ -1305,6 +1313,7 @@ static inline bool is_new_conn_expected(const struct ip_vs_conn *cp,
* In fwmark-VS actual vaddr and vport are unknown to IPVS
* 2) Real Server and Virtual Service were NOT configured without port:
* This is to allow match of different VS to the same RS ip-addr
+ * 3) Client port is not 0
*/
struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
struct ip_vs_dest *dest,
@@ -1328,7 +1337,7 @@ struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
/* check pre-requisites are satisfied */
if (svc->fwmark)
return NULL;
- if (!vport || !dport)
+ if (!vport || !dport || !cport)
return NULL;
/* for persistent service first create connection template */
@@ -1647,7 +1656,8 @@ static unsigned int
ip_vs_try_to_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
struct ip_vs_proto_data *pd,
int *verdict, struct ip_vs_conn **cpp,
- struct ip_vs_iphdr *iph)
+ struct ip_vs_iphdr *iph,
+ const struct nf_hook_state *state)
{
struct ip_vs_protocol *pp = pd->pp;
@@ -1657,7 +1667,8 @@ ip_vs_try_to_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
*/
/* Schedule and create new connection entry into cpp */
- if (!pp->conn_schedule(ipvs, af, skb, pd, verdict, cpp, iph))
+ if (!pp->conn_schedule(ipvs, af, skb, pd, verdict, cpp, iph,
+ state))
return 0;
}
@@ -1757,7 +1768,7 @@ static int ipvs_gre_decap(struct netns_ipvs *ipvs, struct sk_buff *skb,
*/
static int
ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,
- unsigned int hooknum, struct ip_vs_iphdr *iph)
+ const struct nf_hook_state *state, struct ip_vs_iphdr *iph)
{
struct icmphdr _icmph, *ic;
struct iphdr _ciph, *cih; /* The ip header contained within the ICMP */
@@ -1776,7 +1787,8 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,
/* reassemble IP fragments */
if (ip_is_fragment(ip_hdr(skb))) {
- if (ip_vs_gather_frags(ipvs, skb, ip_vs_defrag_user(hooknum)))
+ if (ip_vs_gather_frags(ipvs, skb,
+ ip_vs_defrag_user(state->hook)))
return NF_STOLEN;
if (!ip_vs_fill_iph_skb(AF_INET, skb, false, iph))
return NF_ACCEPT;
@@ -1893,7 +1905,8 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,
if (tunnel || !sysctl_schedule_icmp(ipvs))
return NF_ACCEPT;
- if (!ip_vs_try_to_schedule(ipvs, AF_INET, skb, pd, &v, &cp, &ciph))
+ if (!ip_vs_try_to_schedule(ipvs, AF_INET, skb, pd, &v, &cp,
+ &ciph, state))
return v;
new_cp = true;
}
@@ -1981,7 +1994,7 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,
/* do the statistics and put it back */
ip_vs_in_stats(cp, skb);
- verdict = ip_vs_icmp_xmit(skb, cp, pp, iph->len, hooknum, &ciph);
+ verdict = ip_vs_icmp_xmit(skb, cp, pp, iph->len, state, &ciph);
out:
if (likely(!new_cp))
@@ -1994,7 +2007,7 @@ ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,
#ifdef CONFIG_IP_VS_IPV6
static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,
- int *related, unsigned int hooknum,
+ int *related, const struct nf_hook_state *state,
struct ip_vs_iphdr *iph)
{
struct icmp6hdr _icmph, *ic;
@@ -2036,6 +2049,13 @@ static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,
if (!ip_vs_fill_iph_skb_icmp(AF_INET6, skb, offset, true, &ciph))
return NF_ACCEPT;
+ /* ipv6_find_hdr() does not include the embedded header for
+ * non-first fragments, add it so that ESP can pass and the
+ * NAT writable checks cover the rewritten addresses
+ */
+ if (ciph.len == ciph.off)
+ ciph.len += sizeof(struct ipv6hdr);
+
pd = ip_vs_proto_data_get(ipvs, ciph.protocol);
if (!pd)
return NF_ACCEPT;
@@ -2060,7 +2080,8 @@ static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,
if (!sysctl_schedule_icmp(ipvs))
return NF_ACCEPT;
- if (!ip_vs_try_to_schedule(ipvs, AF_INET6, skb, pd, &v, &cp, &ciph))
+ if (!ip_vs_try_to_schedule(ipvs, AF_INET6, skb, pd, &v, &cp,
+ &ciph, state))
return v;
new_cp = true;
@@ -2081,7 +2102,7 @@ static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,
/* do the statistics and put it back */
ip_vs_in_stats(cp, skb);
- verdict = ip_vs_icmp_xmit_v6(skb, cp, pp, iph->len, hooknum, &ciph);
+ verdict = ip_vs_icmp_xmit_v6(skb, cp, pp, iph->len, state, &ciph);
out:
if (likely(!new_cp))
@@ -2150,7 +2171,7 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state
if (unlikely(iph.protocol == IPPROTO_ICMPV6)) {
int related;
int verdict = ip_vs_in_icmp_v6(ipvs, skb, &related,
- hooknum, &iph);
+ state, &iph);
if (related)
return verdict;
@@ -2160,7 +2181,7 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state
if (unlikely(iph.protocol == IPPROTO_ICMP)) {
int related;
int verdict = ip_vs_in_icmp(ipvs, skb, &related,
- hooknum, &iph);
+ state, &iph);
if (related)
return verdict;
@@ -2248,7 +2269,8 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state
if (unlikely(!cp)) {
int v;
- if (!ip_vs_try_to_schedule(ipvs, af, skb, pd, &v, &cp, &iph))
+ if (!ip_vs_try_to_schedule(ipvs, af, skb, pd, &v, &cp, &iph,
+ state))
return v;
}
@@ -2257,7 +2279,7 @@ ip_vs_in_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *state
ip_vs_in_stats(cp, skb);
ip_vs_set_state(cp, IP_VS_DIR_INPUT, skb, pd, iph.len);
if (cp->packet_xmit)
- ret = cp->packet_xmit(skb, cp, pp, &iph);
+ ret = cp->packet_xmit(skb, cp, pp, &iph, state);
/* do not touch skb anymore */
else {
IP_VS_DBG_RL("warning: packet_xmit is null");
@@ -2320,11 +2342,11 @@ ip_vs_forward_icmp(void *priv, struct sk_buff *skb,
if (iphdr.protocol != IPPROTO_ICMPV6)
return NF_ACCEPT;
- return ip_vs_in_icmp_v6(ipvs, skb, &r, state->hook, &iphdr);
+ return ip_vs_in_icmp_v6(ipvs, skb, &r, state, &iphdr);
#endif
}
- return ip_vs_in_icmp(ipvs, skb, &r, state->hook, &iphdr);
+ return ip_vs_in_icmp(ipvs, skb, &r, state, &iphdr);
}
static const struct nf_hook_ops ip_vs_ops4[] = {
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index ce9fe20d6106a8..be818bf7d3806c 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -64,7 +64,8 @@ int ip_vs_get_debug_level(void)
/* Protos */
-static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup);
+static void __ip_vs_del_service(struct ip_vs_service *svc,
+ struct list_head *dest_trash, bool cleanup);
#ifdef CONFIG_IP_VS_IPV6
@@ -918,6 +919,11 @@ static void ip_vs_rs_hash(struct netns_ipvs *ipvs, struct ip_vs_dest *dest)
*/
hash = ip_vs_rs_hashkey(dest->af, &dest->addr, port);
+ /* Need RCU grace period when rehashing */
+ if (dest->need_gp) {
+ cond_synchronize_rcu(dest->rcu_state);
+ dest->need_gp = 0;
+ }
hlist_add_head_rcu(&dest->d_list, &ipvs->rs_table[hash]);
dest->in_rs_table = 1;
}
@@ -1111,6 +1117,8 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af,
struct ip_vs_dest *dest;
struct netns_ipvs *ipvs = svc->ipvs;
+ lockdep_assert_held(&ipvs->service_mutex);
+
/*
* Find the destination in trash
*/
@@ -1144,24 +1152,57 @@ ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af,
return dest;
}
-/* Put destination in trash */
-static void ip_vs_trash_put_dest(struct netns_ipvs *ipvs,
+/* Add destination in temp list for trash */
+static void ip_vs_trash_add_dest(struct netns_ipvs *ipvs,
struct ip_vs_dest *dest, unsigned long istart,
- bool cleanup)
+ struct list_head *dest_trash)
{
- spin_lock_bh(&ipvs->dest_trash_lock);
IP_VS_DBG_BUF(3, "Moving dest %s:%u into trash, dest->refcnt=%d\n",
IP_VS_DBG_ADDR(dest->af, &dest->addr), ntohs(dest->port),
refcount_read(&dest->refcnt));
+ /* dest lives in trash with reference */
+ list_add(&dest->t_list, dest_trash);
+ dest->idle_start = istart;
+}
+
+/* Put destinations in trash */
+static void ip_vs_trash_put_dests(struct netns_ipvs *ipvs,
+ struct list_head *dest_trash, bool cleanup)
+{
+ spin_lock_bh(&ipvs->dest_trash_lock);
if (list_empty(&ipvs->dest_trash) && !cleanup)
mod_timer(&ipvs->dest_trash_timer,
jiffies + (IP_VS_DEST_TRASH_PERIOD >> 1));
- /* dest lives in trash with reference */
- list_add(&dest->t_list, &ipvs->dest_trash);
- dest->idle_start = istart;
+ list_splice(dest_trash, &ipvs->dest_trash);
spin_unlock_bh(&ipvs->dest_trash_lock);
}
+/* Put destination back in trash */
+static void ip_vs_trash_put_back(struct netns_ipvs *ipvs,
+ struct ip_vs_dest *dest)
+{
+ LIST_HEAD(dest_trash);
+
+ ip_vs_trash_add_dest(ipvs, dest, dest->idle_start, &dest_trash);
+ ip_vs_trash_put_dests(ipvs, &dest_trash, false);
+}
+
+/* Put destinations in trash and save the RCU state */
+static void ip_vs_trash_save_dests(struct netns_ipvs *ipvs,
+ struct list_head *dest_trash, bool cleanup)
+{
+ struct ip_vs_dest *dest;
+ unsigned long rcu_state;
+
+ if (!list_empty(dest_trash)) {
+ /* Remember when dests were removed and added to dest_trash */
+ rcu_state = get_state_synchronize_rcu();
+ list_for_each_entry(dest, dest_trash, t_list)
+ dest->rcu_state = rcu_state;
+ ip_vs_trash_put_dests(ipvs, dest_trash, cleanup);
+ }
+}
+
static void ip_vs_dest_rcu_free(struct rcu_head *head)
{
struct ip_vs_dest *dest;
@@ -1304,12 +1345,12 @@ void ip_vs_stats_free(struct ip_vs_stats *stats)
}
}
-/* Update overload flag based on number of dest conns and lower/upper
+/* Update overload state based on number of dest conns and lower/upper
* connection thresholds:
- * - conns reach u_threshold and exceed it: set the flag
- * - conns go below l_threshold (or 75% of u_threshold): clear the flag
+ * - conns reach u_threshold and exceed it: set the overload state
+ * - conns go below l_threshold (or 75% of u_threshold): clear the state
*/
-static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)
+static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest)
{
int conns;
u32 l, u;
@@ -1320,10 +1361,18 @@ static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)
/* Low threshold defaults to 75% of upper threshold */
l = READ_ONCE(dest->l_threshold) ? : (u - (u >> 2));
conns = atomic_read(&dest->totalconns);
- if (conns >= (overload ? l : u)) {
+ if (conns >= (ip_vs_dest_is_overloaded(dest) ? l : u)) {
WRITE_ONCE(dest->u_threshold_val, INT_MAX);
WRITE_ONCE(dest->l_threshold_val, l);
- return;
+ /* Commit thresholds before repeating the check,
+ * it is paired with atomic_fetch_dec() in
+ * ip_vs_unbind_dest() to avoid entering the
+ * overload state forever.
+ */
+ smp_mb();
+ conns = atomic_read(&dest->totalconns);
+ if (conns >= l)
+ return;
}
}
@@ -1331,10 +1380,10 @@ static void __ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)
WRITE_ONCE(dest->l_threshold_val, 0);
}
-void ip_vs_dest_update_overload(struct ip_vs_dest *dest, bool overload)
+void ip_vs_dest_update_overload(struct ip_vs_dest *dest)
{
spin_lock_bh(&dest->dst_lock);
- __ip_vs_dest_update_overload(dest, overload);
+ __ip_vs_dest_update_overload(dest);
spin_unlock_bh(&dest->dst_lock);
}
@@ -1369,8 +1418,16 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
if ((udest->conn_flags & IP_VS_CONN_F_FWD_MASK) !=
IP_VS_DFWD_METHOD(dest) ||
udest->tun_type != dest->tun_type ||
- udest->tun_port != dest->tun_port)
+ udest->tun_port != dest->tun_port) {
+ bool unlinked = dest->in_rs_table;
+
ip_vs_rs_unhash(dest);
+ if (unlinked) {
+ dest->rcu_state = get_state_synchronize_rcu();
+ /* Need grace period in this or next dest update */
+ dest->need_gp = 1;
+ }
+ }
/* set the tunnel info */
dest->tun_type = udest->tun_type;
@@ -1406,13 +1463,10 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
if (READ_ONCE(dest->u_threshold) != udest->u_threshold ||
READ_ONCE(dest->l_threshold) != udest->l_threshold) {
- bool overload;
-
spin_lock_bh(&dest->dst_lock);
WRITE_ONCE(dest->u_threshold, udest->u_threshold);
WRITE_ONCE(dest->l_threshold, udest->l_threshold);
- overload = ip_vs_dest_is_overloaded(dest);
- __ip_vs_dest_update_overload(dest, overload);
+ __ip_vs_dest_update_overload(dest);
spin_unlock_bh(&dest->dst_lock);
}
@@ -1477,6 +1531,7 @@ ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
if (ret < 0)
goto err_stats;
+ dest->u_threshold_val = INT_MAX;
dest->af = udest->af;
dest->protocol = svc->protocol;
dest->vaddr = svc->addr;
@@ -1556,6 +1611,11 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
dest = ip_vs_trash_get_dest(svc, udest->af, &daddr, dport);
if (dest != NULL) {
+ /* Readers may still follow the n_list, d_list or estimator list
+ * links. Wait before reusing any of them.
+ */
+ cond_synchronize_rcu(dest->rcu_state);
+
IP_VS_DBG_BUF(3, "Get destination %s:%u from trash, "
"dest->refcnt=%d, service %u/%s:%u\n",
IP_VS_DBG_ADDR(udest->af, &daddr), ntohs(dport),
@@ -1566,11 +1626,14 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
ret = ip_vs_start_estimator(svc->ipvs, &dest->stats);
/* On error put back dest into the trash */
- if (ret < 0)
- ip_vs_trash_put_dest(svc->ipvs, dest, dest->idle_start,
- false);
- else
+ if (ret < 0) {
+ ip_vs_trash_put_back(svc->ipvs, dest);
+ } else {
+ /* need_gp matters only on dest edit, reinit it */
+ dest->need_gp = 0;
+
__ip_vs_update_dest(svc, dest, udest, 1);
+ }
} else {
/*
* Allocate and initialize the dest structure
@@ -1634,7 +1697,7 @@ ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
* Delete a destination (must be already unlinked from the service)
*/
static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest,
- bool cleanup)
+ struct list_head *dest_trash, bool cleanup)
{
ip_vs_stop_estimator(ipvs, &dest->stats);
@@ -1643,7 +1706,7 @@ static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest,
*/
ip_vs_rs_unhash(dest);
- ip_vs_trash_put_dest(ipvs, dest, 0, cleanup);
+ ip_vs_trash_add_dest(ipvs, dest, 0, dest_trash);
/* Queue up delayed work to expire all no destination connections.
* No-op when CONFIG_SYSCTL is disabled.
@@ -1693,6 +1756,7 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
{
struct ip_vs_dest *dest;
__be16 dport = udest->port;
+ LIST_HEAD(dest_trash);
/* We use function that requires RCU lock */
rcu_read_lock();
@@ -1712,7 +1776,9 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
/*
* Delete the destination
*/
- __ip_vs_del_dest(svc->ipvs, dest, false);
+ __ip_vs_del_dest(svc->ipvs, dest, &dest_trash, false);
+
+ ip_vs_trash_save_dests(svc->ipvs, &dest_trash, false);
return 0;
}
@@ -2057,7 +2123,8 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)
* - The service must be unlinked, unlocked and not referenced!
* - We are called under _bh lock
*/
-static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)
+static void __ip_vs_del_service(struct ip_vs_service *svc,
+ struct list_head *dest_trash, bool cleanup)
{
struct ip_vs_dest *dest, *nxt;
struct ip_vs_scheduler *old_sched;
@@ -2091,7 +2158,7 @@ static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)
*/
list_for_each_entry_safe(dest, nxt, &svc->destinations, n_list) {
__ip_vs_unlink_dest(svc, dest, 0);
- __ip_vs_del_dest(svc->ipvs, dest, cleanup);
+ __ip_vs_del_dest(svc->ipvs, dest, dest_trash, cleanup);
}
/*
@@ -2114,7 +2181,8 @@ static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup)
/*
* Unlink a service from list and try to delete it if its refcnt reached 0
*/
-static void ip_vs_unlink_service(struct ip_vs_service *svc, bool cleanup)
+static void ip_vs_unlink_service(struct ip_vs_service *svc,
+ struct list_head *dest_trash, bool cleanup)
{
ip_vs_unregister_conntrack(svc);
/* Hold svc to avoid double release from dest_trash */
@@ -2124,7 +2192,7 @@ static void ip_vs_unlink_service(struct ip_vs_service *svc, bool cleanup)
*/
ip_vs_svc_unhash(svc);
- __ip_vs_del_service(svc, cleanup);
+ __ip_vs_del_service(svc, dest_trash, cleanup);
}
/*
@@ -2134,12 +2202,14 @@ static int ip_vs_del_service(struct ip_vs_service *svc)
{
struct netns_ipvs *ipvs;
struct ip_vs_rht *t, *p;
+ LIST_HEAD(dest_trash);
int ns;
if (svc == NULL)
return -EEXIST;
ipvs = svc->ipvs;
- ip_vs_unlink_service(svc, false);
+ ip_vs_unlink_service(svc, &dest_trash, false);
+ ip_vs_trash_save_dests(ipvs, &dest_trash, false);
/* Drop the table if no more services */
ns = ip_vs_get_num_services(ipvs);
@@ -2190,6 +2260,7 @@ static int ip_vs_flush(struct netns_ipvs *ipvs, bool cleanup)
struct hlist_bl_node *ne;
struct hlist_bl_node *e;
struct ip_vs_rht *t, *p;
+ LIST_HEAD(dest_trash);
/* Stop the resizer and drop the tables */
if (!test_and_set_bit(IP_VS_WORK_SVC_NORESIZE, &ipvs->work_flags))
@@ -2199,8 +2270,9 @@ static int ip_vs_flush(struct netns_ipvs *ipvs, bool cleanup)
if (ip_vs_get_num_services(ipvs)) {
ip_vs_rht_walk_buckets(ipvs->svc_table, head) {
hlist_bl_for_each_entry_safe(svc, e, ne, head, s_list)
- ip_vs_unlink_service(svc, cleanup);
+ ip_vs_unlink_service(svc, &dest_trash, cleanup);
}
+ ip_vs_trash_save_dests(ipvs, &dest_trash, cleanup);
}
/* Unregister the hash table and release it after RCU grace period */
diff --git a/net/netfilter/ipvs/ip_vs_ftp.c b/net/netfilter/ipvs/ip_vs_ftp.c
index 9e3e005a826353..81c3a2fd27b397 100644
--- a/net/netfilter/ipvs/ip_vs_ftp.c
+++ b/net/netfilter/ipvs/ip_vs_ftp.c
@@ -29,6 +29,7 @@
#include <linux/netfilter.h>
#include <net/netfilter/nf_conntrack.h>
#include <net/netfilter/nf_conntrack_expect.h>
+#include <net/netfilter/nf_conntrack_seqadj.h>
#include <net/netfilter/nf_nat.h>
#include <net/netfilter/nf_nat_helper.h>
#include <linux/gfp.h>
@@ -62,6 +63,17 @@ static unsigned short ports[IP_VS_APP_MAX_PORTS] = {21, 0};
module_param_array(ports, ushort, &ports_count, 0444);
MODULE_PARM_DESC(ports, "Ports to monitor for FTP control commands");
+static bool is_control_port(u16 port)
+{
+ unsigned int i;
+
+ for (i = 0; i < ports_count; i++) {
+ if (ports[i] == port)
+ return true;
+ }
+ return false;
+}
+
static char *ip_vs_ftp_data_ptr(struct sk_buff *skb, struct ip_vs_iphdr *ipvsh)
{
@@ -319,6 +331,10 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
return 1;
}
+ /* Do not redirect data to control ports */
+ if (!port || is_control_port(ntohs(port)))
+ return 0;
+
/* Now update or create a connection entry for it */
{
struct ip_vs_conn_param p;
@@ -368,20 +384,26 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
buf_len = strlen(buf);
ct = nf_ct_get(skb, &ctinfo);
- if (ct) {
- bool mangled;
+ if (ct && !nf_ct_is_template(ct)) {
+ bool mangled = false;
/* If mangling fails this function will return 0
* which will cause the packet to be dropped.
* Mangling can only fail under memory pressure,
* hopefully it will succeed on the retransmitted
* packet.
+ *
+ * Add the seqadj extension before the expectation is
+ * linked into the helper extension: adding it later
+ * reallocates ct->ext under the expectation list.
*/
- mangled = nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
- ipvsh->len,
- start - data,
- end - start,
- buf, buf_len);
+ if (nf_ct_is_confirmed(ct) || nfct_seqadj(ct) ||
+ nfct_seqadj_ext_add(ct))
+ mangled = nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
+ ipvsh->len,
+ start - data,
+ end - start,
+ buf, buf_len);
if (mangled) {
ip_vs_nfct_expect_related(skb, ct, n_cp,
ipvsh->protocol, 0, 0);
@@ -529,6 +551,9 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,
return 1;
}
+ if (!port || is_control_port(ntohs(cp->vport) - 1))
+ return 0;
+
/* Passive mode off */
cp->app_data = (void *) IP_VS_FTP_ACTIVE;
diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
index e1111c3b27211a..f5ce1f2afb8606 100644
--- a/net/netfilter/ipvs/ip_vs_lblc.c
+++ b/net/netfilter/ipvs/ip_vs_lblc.c
@@ -467,10 +467,11 @@ is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc)
struct ip_vs_dest *d;
list_for_each_entry_rcu(d, &svc->destinations, n_list) {
- if (atomic_read(&d->activeconns)*2
- < atomic_read(&d->weight)) {
+ if (ip_vs_dest_is_overloaded(d))
+ continue;
+ if (atomic_read(&d->activeconns) * 2 <
+ atomic_read(&d->weight))
return 1;
- }
}
}
return 0;
@@ -507,6 +508,7 @@ ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
dest = en->dest;
if ((dest->cflags & IP_VS_DEST_CF_AVAILABLE) &&
+ !ip_vs_dest_is_overloaded(dest) &&
atomic_read(&dest->weight) > 0 && !is_overloaded(dest, svc))
goto out;
}
diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
index dfb5bf83750dba..4046608922e7cb 100644
--- a/net/netfilter/ipvs/ip_vs_lblcr.c
+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
@@ -630,10 +630,11 @@ is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc)
struct ip_vs_dest *d;
list_for_each_entry_rcu(d, &svc->destinations, n_list) {
- if (atomic_read(&d->activeconns)*2
- < atomic_read(&d->weight)) {
+ if (ip_vs_dest_is_overloaded(d))
+ continue;
+ if (atomic_read(&d->activeconns) * 2 <
+ atomic_read(&d->weight))
return 1;
- }
}
}
return 0;
@@ -658,9 +659,6 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
if (en) {
en->lastuse = jiffies;
- /* Get the least loaded destination */
- dest = ip_vs_dest_set_min(&en->set);
-
/* More than one destination + enough time passed by, cleanup */
if (atomic_read(&en->set.size) > 1 &&
time_after(jiffies, en->set.lastmod +
@@ -676,6 +674,9 @@ ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
spin_unlock_bh(&svc->sched_lock);
}
+ /* Get the least loaded destination */
+ dest = ip_vs_dest_set_min(&en->set);
+
/* If the destination is not overloaded, use it */
if (dest && !is_overloaded(dest, svc))
goto out;
diff --git a/net/netfilter/ipvs/ip_vs_proto_ah_esp.c b/net/netfilter/ipvs/ip_vs_proto_ah_esp.c
index 44e14acc187ee3..c7f90b29be51b3 100644
--- a/net/netfilter/ipvs/ip_vs_proto_ah_esp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_ah_esp.c
@@ -102,7 +102,7 @@ static int
ah_esp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
struct ip_vs_proto_data *pd,
int *verdict, struct ip_vs_conn **cpp,
- struct ip_vs_iphdr *iph)
+ struct ip_vs_iphdr *iph, const struct nf_hook_state *state)
{
/*
* AH/ESP is only related traffic. Pass the packet to IP stack.
diff --git a/net/netfilter/ipvs/ip_vs_proto_sctp.c b/net/netfilter/ipvs/ip_vs_proto_sctp.c
index fb8af6b15a3999..3d773c881f75aa 100644
--- a/net/netfilter/ipvs/ip_vs_proto_sctp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_sctp.c
@@ -17,7 +17,7 @@ static int
sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
struct ip_vs_proto_data *pd,
int *verdict, struct ip_vs_conn **cpp,
- struct ip_vs_iphdr *iph)
+ struct ip_vs_iphdr *iph, const struct nf_hook_state *state)
{
struct ip_vs_service *svc;
struct sctp_chunkhdr _schunkh, *sch;
@@ -30,6 +30,7 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
sch = skb_header_pointer(skb, iph->len + sizeof(_sctph),
sizeof(_schunkh), &_schunkh);
if (sch) {
+ /* Accept packet without scheduling? */
if (sch->type == SCTP_CID_ABORT ||
!(sysctl_sloppy_sctp(ipvs) ||
sch->type == SCTP_CID_INIT))
@@ -56,6 +57,12 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
if (svc) {
int ignored;
+ /* Do not create connection for port 0 */
+ if (!ports[0] || !ports[1]) {
+ *verdict = NF_DROP;
+ return 0;
+ }
+
if (ip_vs_todrop(ipvs)) {
/*
* It seems that we are very loaded.
@@ -71,7 +78,8 @@ sctp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
*cpp = ip_vs_schedule(svc, skb, pd, &ignored, iph);
if (!*cpp && ignored <= 0) {
if (!ignored)
- *verdict = ip_vs_leave(svc, skb, pd, iph);
+ *verdict = ip_vs_leave(svc, skb, pd, iph,
+ state);
else
*verdict = NF_DROP;
return 0;
diff --git a/net/netfilter/ipvs/ip_vs_proto_tcp.c b/net/netfilter/ipvs/ip_vs_proto_tcp.c
index fec0e8b47b7165..13ac917a0ac8d1 100644
--- a/net/netfilter/ipvs/ip_vs_proto_tcp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_tcp.c
@@ -35,7 +35,7 @@ static int
tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
struct ip_vs_proto_data *pd,
int *verdict, struct ip_vs_conn **cpp,
- struct ip_vs_iphdr *iph)
+ struct ip_vs_iphdr *iph, const struct nf_hook_state *state)
{
struct ip_vs_service *svc;
struct tcphdr _tcph, *th;
@@ -48,6 +48,7 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
if (likely(!ip_vs_iph_icmp(iph))) {
th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph);
if (th) {
+ /* Accept packet without scheduling? */
if (th->rst || !(sysctl_sloppy_tcp(ipvs) || th->syn))
return 1;
ports = &th->source;
@@ -74,6 +75,12 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
if (svc) {
int ignored;
+ /* Do not create connection for port 0 */
+ if (!ports[0] || !ports[1]) {
+ *verdict = NF_DROP;
+ return 0;
+ }
+
if (ip_vs_todrop(ipvs)) {
/*
* It seems that we are very loaded.
@@ -90,7 +97,8 @@ tcp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
*cpp = ip_vs_schedule(svc, skb, pd, &ignored, iph);
if (!*cpp && ignored <= 0) {
if (!ignored)
- *verdict = ip_vs_leave(svc, skb, pd, iph);
+ *verdict = ip_vs_leave(svc, skb, pd, iph,
+ state);
else
*verdict = NF_DROP;
return 0;
diff --git a/net/netfilter/ipvs/ip_vs_proto_udp.c b/net/netfilter/ipvs/ip_vs_proto_udp.c
index f32785682402dd..760b019e6a06d4 100644
--- a/net/netfilter/ipvs/ip_vs_proto_udp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_udp.c
@@ -31,7 +31,7 @@ static int
udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
struct ip_vs_proto_data *pd,
int *verdict, struct ip_vs_conn **cpp,
- struct ip_vs_iphdr *iph)
+ struct ip_vs_iphdr *iph, const struct nf_hook_state *state)
{
struct ip_vs_service *svc;
struct udphdr _udph, *uh;
@@ -62,6 +62,12 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
if (svc) {
int ignored;
+ /* Do not create connection for port 0 */
+ if (!ports[0] || !ports[1]) {
+ *verdict = NF_DROP;
+ return 0;
+ }
+
if (ip_vs_todrop(ipvs)) {
/*
* It seems that we are very loaded.
@@ -78,7 +84,8 @@ udp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
*cpp = ip_vs_schedule(svc, skb, pd, &ignored, iph);
if (!*cpp && ignored <= 0) {
if (!ignored)
- *verdict = ip_vs_leave(svc, skb, pd, iph);
+ *verdict = ip_vs_leave(svc, skb, pd, iph,
+ state);
else
*verdict = NF_DROP;
return 0;
diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
index 157f5c8361ab46..7e562e745ab5d5 100644
--- a/net/netfilter/ipvs/ip_vs_sync.c
+++ b/net/netfilter/ipvs/ip_vs_sync.c
@@ -539,6 +539,7 @@ static int ip_vs_sync_conn_needed(struct netns_ipvs *ipvs,
static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,
int pkts)
{
+ struct ip_vs_sync_conn_options opts;
struct ip_vs_sync_mesg_v0 *m;
struct ip_vs_sync_conn_v0 *s;
struct ip_vs_sync_buff *buff;
@@ -557,6 +558,14 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,
if (!ip_vs_sync_conn_needed(ipvs, cp, pkts))
return;
+ if (flags & IP_VS_CONN_F_SEQ_MASK) {
+ /* Take atomic snapshot of flags and seqs */
+ spin_lock_bh(&cp->lock);
+ flags = cp->flags;
+ memcpy(&opts, &cp->sync_conn_opt, sizeof(opts));
+ spin_unlock_bh(&cp->lock);
+ }
+
spin_lock_bh(&ipvs->sync_buff_lock);
if (!(ipvs->sync_state & IP_VS_STATE_MASTER)) {
spin_unlock_bh(&ipvs->sync_buff_lock);
@@ -604,7 +613,7 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,
if (seq_mask) {
struct ip_vs_sync_conn_options *opt =
(struct ip_vs_sync_conn_options *)&s[1];
- memcpy(opt, &cp->sync_conn_opt, sizeof(*opt));
+ memcpy(opt, &opts, sizeof(*opt));
}
m->nr_conns++;
@@ -630,6 +639,7 @@ static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,
*/
void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)
{
+ struct ip_vs_sync_conn_options opts;
struct ip_vs_sync_mesg *m;
union ip_vs_sync_conn *s;
struct ip_vs_sync_buff *buff;
@@ -651,6 +661,13 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)
if (!ip_vs_sync_conn_needed(ipvs, cp, pkts))
goto control;
flags = READ_ONCE(cp->flags);
+ if (flags & IP_VS_CONN_F_SEQ_MASK) {
+ /* Take atomic snapshot of flags and seqs */
+ spin_lock_bh(&cp->lock);
+ flags = cp->flags;
+ memcpy(&opts, &cp->sync_conn_opt, sizeof(opts));
+ spin_unlock_bh(&cp->lock);
+ }
/* Sanity checks */
pe_name_len = 0;
@@ -732,7 +749,7 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)
s->v4.vport = cp->vport;
s->v4.dport = cp->dport;
s->v4.fwmark = htonl(cp->fwmark);
- s->v4.timeout = htonl(cp->timeout / HZ);
+ s->v4.timeout = htonl(max(1UL, cp->timeout / HZ));
m->nr_conns++;
#ifdef CONFIG_IP_VS_IPV6
@@ -752,9 +769,9 @@ void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)
if (seq_mask) {
*(p++) = IPVS_OPT_SEQ_DATA;
*(p++) = sizeof(struct ip_vs_sync_conn_options);
- hton_seq(&cp->in_seq, (struct ip_vs_seq *)p);
+ hton_seq(&opts.in_seq, (struct ip_vs_seq *)p);
p += sizeof(struct ip_vs_seq);
- hton_seq(&cp->out_seq, (struct ip_vs_seq *)p);
+ hton_seq(&opts.out_seq, (struct ip_vs_seq *)p);
p += sizeof(struct ip_vs_seq);
}
/* Handle pe data */
@@ -850,9 +867,29 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
unsigned long timeout, __u32 fwmark,
struct ip_vs_sync_conn_options *opt)
{
+ struct ip_vs_conn *cp_new = NULL;
struct ip_vs_dest *dest;
struct ip_vs_conn *cp;
+ /* Templates require cport 0. Ordinary connections require
+ * NO_CPORT exactly when cport is 0.
+ */
+ if (flags & IP_VS_CONN_F_TEMPLATE) {
+ if (param->cport) {
+ IP_VS_DBG(2, "BACKUP, template with cport dropped\n");
+ kfree(param->pe_data);
+ return;
+ }
+ } else if (!param->cport && !(flags & IP_VS_CONN_F_NO_CPORT)) {
+ IP_VS_DBG(2, "BACKUP, conn without cport dropped\n");
+ kfree(param->pe_data);
+ return;
+ } else if (param->cport && (flags & IP_VS_CONN_F_NO_CPORT)) {
+ IP_VS_DBG(2, "BACKUP, conn with cport and NO_CPORT dropped\n");
+ kfree(param->pe_data);
+ return;
+ }
+
if (!(flags & IP_VS_CONN_F_TEMPLATE)) {
cp = ip_vs_conn_in_get(param);
if (cp && ((cp->dport != dport) ||
@@ -891,9 +928,6 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
flags &= IP_VS_CONN_F_BACKUP_UPD_MASK;
flags |= cp->flags & ~IP_VS_CONN_F_BACKUP_UPD_MASK;
cp->flags = flags;
- spin_unlock_bh(&cp->lock);
- if (!dest)
- ip_vs_try_bind_dest(cp);
} else {
/*
* Find the appropriate destination for the connection.
@@ -920,6 +954,8 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
}
if (!(flags & IP_VS_CONN_F_TEMPLATE))
kfree(param->pe_data);
+ cp_new = cp;
+ spin_lock_bh(&cp->lock);
}
if (opt) {
@@ -951,6 +987,9 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa
else
cp->timeout = (3*60*HZ);
}
+ spin_unlock_bh(&cp->lock);
+ if (!dest && !cp_new)
+ ip_vs_try_bind_dest(cp);
ip_vs_conn_put(cp);
}
diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
index ebc6b697ae5160..c777493eee7493 100644
--- a/net/netfilter/ipvs/ip_vs_xmit.c
+++ b/net/netfilter/ipvs/ip_vs_xmit.c
@@ -205,13 +205,24 @@ static inline bool crosses_local_route_boundary(int skb_af, struct sk_buff *skb,
return false;
}
-static inline void maybe_update_pmtu(int skb_af, struct sk_buff *skb, int mtu)
+static inline void maybe_update_pmtu(int skb_af, struct sk_buff *skb, int mtu,
+ const struct nf_hook_state *state)
{
- struct sock *sk = skb->sk;
- struct rtable *ort = skb_rtable(skb);
-
- if (!skb->dev && sk && sk_fullsock(sk))
- ort->dst.ops->update_pmtu(&ort->dst, sk, NULL, mtu, true);
+ struct dst_entry *dst = skb_dst(skb);
+ struct sock *sk = state->sk;
+
+ /* The update_pmtu handlers are missing some checks for:
+ * - skb->dev: present for tunnels, not for IPVS, so we do not
+ * provide skb, only sk
+ * - present daddr: so, we require TCP_ESTABLISHED (connected socket)
+ *
+ * In some states the senders ignore the PMTU events:
+ * - sk_fullsock(): so use the TCP_ESTABLISHED check
+ */
+ if (sk && sk->sk_state == TCP_ESTABLISHED &&
+ state->hook == NF_INET_LOCAL_OUT &&
+ sk->sk_family == dst->ops->family)
+ dst->ops->update_pmtu(dst, sk, NULL, mtu, false);
}
static inline bool ensure_mtu_is_adequate(struct netns_ipvs *ipvs, int skb_af,
@@ -316,7 +327,7 @@ static int
__ip_vs_get_out_rt(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,
struct ip_vs_dest *dest,
__be32 daddr, int rt_mode, __be32 *ret_saddr,
- struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_iphdr *ipvsh, const struct nf_hook_state *state)
{
struct net *net = ipvs->net;
struct ip_vs_dest_dst *dest_dst;
@@ -417,7 +428,7 @@ __ip_vs_get_out_rt(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,
IP_VS_DBG_RL("%s(): mtu less than 68\n", __func__);
goto err_put;
}
- maybe_update_pmtu(skb_af, skb, mtu);
+ maybe_update_pmtu(skb_af, skb, mtu, state);
}
if (!ensure_mtu_is_adequate(ipvs, skb_af, rt_mode, ipvsh, skb, mtu))
@@ -489,7 +500,8 @@ static int
__ip_vs_get_out_rt_v6(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,
struct ip_vs_dest *dest,
struct in6_addr *daddr, struct in6_addr *ret_saddr,
- struct ip_vs_iphdr *ipvsh, int do_xfrm, int rt_mode)
+ struct ip_vs_iphdr *ipvsh, int do_xfrm, int rt_mode,
+ const struct nf_hook_state *state)
{
struct net *net = ipvs->net;
struct ip_vs_dest_dst *dest_dst;
@@ -596,7 +608,7 @@ __ip_vs_get_out_rt_v6(struct netns_ipvs *ipvs, int skb_af, struct sk_buff *skb,
IPV6_MIN_MTU);
goto err_put;
}
- maybe_update_pmtu(skb_af, skb, mtu);
+ maybe_update_pmtu(skb_af, skb, mtu, state);
}
if (!ensure_mtu_is_adequate(ipvs, skb_af, rt_mode, ipvsh, skb, mtu))
@@ -720,12 +732,26 @@ static inline int ip_vs_send_or_cont(int pf, struct sk_buff *skb,
*/
int
ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
/* we do not touch skb and do not need pskb ptr */
return ip_vs_send_or_cont(NFPROTO_IPV4, skb, cp, 1);
}
+#ifdef CONFIG_IP_VS_IPV6
+/*
+ * NULL transmitter (do nothing except return NF_ACCEPT)
+ */
+int
+ip_vs_null_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
+{
+ /* we do not touch skb and do not need pskb ptr */
+ return ip_vs_send_or_cont(NFPROTO_IPV6, skb, cp, 1);
+}
+#endif
/*
* Bypass transmitter
@@ -734,10 +760,11 @@ ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
*/
int
ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
if (__ip_vs_get_out_rt(cp->ipvs, cp->af, skb, NULL, ip_hdr(skb)->daddr,
- IP_VS_RT_MODE_NON_LOCAL, NULL, ipvsh) < 0)
+ IP_VS_RT_MODE_NON_LOCAL, NULL, ipvsh, state) < 0)
goto tx_error;
ip_send_check(ip_hdr(skb));
@@ -757,13 +784,15 @@ ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
#ifdef CONFIG_IP_VS_IPV6
int
ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
struct ipv6hdr *iph = ipv6_hdr(skb);
if (__ip_vs_get_out_rt_v6(cp->ipvs, cp->af, skb, NULL,
&iph->daddr, NULL,
- ipvsh, 0, IP_VS_RT_MODE_NON_LOCAL) < 0)
+ ipvsh, 0, IP_VS_RT_MODE_NON_LOCAL,
+ state) < 0)
goto tx_error;
/* Another hack: avoid icmp_send in ip_fragment */
@@ -785,7 +814,8 @@ ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
*/
int
ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
struct rtable *rt; /* Route to the other host */
int local, rc, was_input;
@@ -805,7 +835,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
local = __ip_vs_get_out_rt(cp->ipvs, cp->af, skb, cp->dest, cp->daddr.ip,
IP_VS_RT_MODE_LOCAL |
IP_VS_RT_MODE_NON_LOCAL |
- IP_VS_RT_MODE_RDR, NULL, ipvsh);
+ IP_VS_RT_MODE_RDR, NULL, ipvsh, state);
if (local < 0)
goto tx_error;
rt = skb_rtable(skb);
@@ -869,7 +899,8 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
#ifdef CONFIG_IP_VS_IPV6
int
ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
struct rt6_info *rt; /* Route to the other host */
int local, rc;
@@ -889,7 +920,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
NULL, ipvsh, 0,
IP_VS_RT_MODE_LOCAL |
IP_VS_RT_MODE_NON_LOCAL |
- IP_VS_RT_MODE_RDR);
+ IP_VS_RT_MODE_RDR, state);
if (local < 0)
goto tx_error;
rt = dst_rt6_info(skb_dst(skb));
@@ -1145,7 +1176,8 @@ ipvs_gre_encap(struct net *net, struct sk_buff *skb,
*/
int
ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
struct netns_ipvs *ipvs = cp->ipvs;
struct net *net = ipvs->net;
@@ -1167,7 +1199,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
IP_VS_RT_MODE_LOCAL |
IP_VS_RT_MODE_NON_LOCAL |
IP_VS_RT_MODE_CONNECT |
- IP_VS_RT_MODE_TUNNEL, &saddr, ipvsh);
+ IP_VS_RT_MODE_TUNNEL, &saddr, ipvsh, state);
if (local < 0)
goto tx_error;
if (local)
@@ -1276,7 +1308,7 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
ret = ip_vs_tunnel_xmit_prepare(skb, cp);
if (ret == NF_ACCEPT)
- ip_local_out(net, skb->sk, skb);
+ ip_local_out(net, NULL, skb);
else if (ret == NF_DROP)
kfree_skb(skb);
@@ -1290,7 +1322,8 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
#ifdef CONFIG_IP_VS_IPV6
int
ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
struct netns_ipvs *ipvs = cp->ipvs;
struct net *net = ipvs->net;
@@ -1312,7 +1345,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
&saddr, ipvsh, 1,
IP_VS_RT_MODE_LOCAL |
IP_VS_RT_MODE_NON_LOCAL |
- IP_VS_RT_MODE_TUNNEL);
+ IP_VS_RT_MODE_TUNNEL, state);
if (local < 0)
goto tx_error;
if (local)
@@ -1418,7 +1451,7 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
ret = ip_vs_tunnel_xmit_prepare(skb, cp);
if (ret == NF_ACCEPT)
- ip6_local_out(net, skb->sk, skb);
+ ip6_local_out(net, NULL, skb);
else if (ret == NF_DROP)
kfree_skb(skb);
@@ -1437,14 +1470,15 @@ ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
*/
int
ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
int local;
local = __ip_vs_get_out_rt(cp->ipvs, cp->af, skb, cp->dest, cp->daddr.ip,
IP_VS_RT_MODE_LOCAL |
IP_VS_RT_MODE_NON_LOCAL |
- IP_VS_RT_MODE_KNOWN_NH, NULL, ipvsh);
+ IP_VS_RT_MODE_KNOWN_NH, NULL, ipvsh, state);
if (local < 0)
goto tx_error;
if (local)
@@ -1467,7 +1501,8 @@ ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
#ifdef CONFIG_IP_VS_IPV6
int
ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh)
+ struct ip_vs_protocol *pp, struct ip_vs_iphdr *ipvsh,
+ const struct nf_hook_state *state)
{
int local;
@@ -1476,7 +1511,7 @@ ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
NULL, ipvsh, 0,
IP_VS_RT_MODE_LOCAL |
IP_VS_RT_MODE_NON_LOCAL |
- IP_VS_RT_MODE_KNOWN_NH);
+ IP_VS_RT_MODE_KNOWN_NH, state);
if (local < 0)
goto tx_error;
if (local)
@@ -1503,7 +1538,7 @@ ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
int
ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
struct ip_vs_protocol *pp, unsigned int toff,
- unsigned int hooknum, struct ip_vs_iphdr *ciph)
+ const struct nf_hook_state *state, struct ip_vs_iphdr *ciph)
{
struct rtable *rt; /* Route to the other host */
int rc;
@@ -1517,7 +1552,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
translate address/port back */
if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
if (cp->packet_xmit)
- rc = cp->packet_xmit(skb, cp, pp, ciph);
+ rc = cp->packet_xmit(skb, cp, pp, ciph, state);
else
rc = NF_ACCEPT;
/* do not touch skb anymore */
@@ -1531,11 +1566,11 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
was_input = rt_is_input_route(skb_rtable(skb));
/* LOCALNODE from FORWARD hook is not supported */
- rt_mode = (hooknum != NF_INET_FORWARD) ?
+ rt_mode = (state->hook != NF_INET_FORWARD) ?
IP_VS_RT_MODE_LOCAL | IP_VS_RT_MODE_NON_LOCAL |
IP_VS_RT_MODE_RDR : IP_VS_RT_MODE_NON_LOCAL;
- local = __ip_vs_get_out_rt(cp->ipvs, cp->af, skb, cp->dest, cp->daddr.ip, rt_mode,
- NULL, ciph);
+ local = __ip_vs_get_out_rt(cp->ipvs, cp->af, skb, cp->dest,
+ cp->daddr.ip, rt_mode, NULL, ciph, state);
if (local < 0)
goto tx_error;
rt = skb_rtable(skb);
@@ -1597,8 +1632,8 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
#ifdef CONFIG_IP_VS_IPV6
int
ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
- struct ip_vs_protocol *pp, unsigned int toff,
- unsigned int hooknum, struct ip_vs_iphdr *ciph)
+ struct ip_vs_protocol *pp, unsigned int toff,
+ const struct nf_hook_state *state, struct ip_vs_iphdr *ciph)
{
bool has_ports = false;
struct rt6_info *rt; /* Route to the other host */
@@ -1612,7 +1647,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
translate address/port back */
if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
if (cp->packet_xmit)
- rc = cp->packet_xmit(skb, cp, pp, ciph);
+ rc = cp->packet_xmit(skb, cp, pp, ciph, state);
else
rc = NF_ACCEPT;
/* do not touch skb anymore */
@@ -1625,11 +1660,12 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
*/
/* LOCALNODE from FORWARD hook is not supported */
- rt_mode = (hooknum != NF_INET_FORWARD) ?
+ rt_mode = (state->hook != NF_INET_FORWARD) ?
IP_VS_RT_MODE_LOCAL | IP_VS_RT_MODE_NON_LOCAL |
IP_VS_RT_MODE_RDR : IP_VS_RT_MODE_NON_LOCAL;
local = __ip_vs_get_out_rt_v6(cp->ipvs, cp->af, skb, cp->dest,
- &cp->daddr.in6, NULL, ciph, 0, rt_mode);
+ &cp->daddr.in6, NULL, ciph, 0, rt_mode,
+ state);
if (local < 0)
goto tx_error;
rt = dst_rt6_info(skb_dst(skb));
|
| 33/3 | 2026/11/17 07:49 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28667 output: 43 thoughts: 1918 Thoughts: **Analyzing the IPVS Patch for Potential Uninitialized Memory Risks** Okay, let's break this down. My initial thought is to go through this patch methodically, change by change, to understand what's being modified within the IPVS subsystem. I need to understand the scope of the alterations before I can assess the KMSAN implications. First, it seems like the changes are spread across various IPVS files, with the common theme of adding `const struct nf_hook_state *state` to a bunch of functions. The introduction of `rcu_state` and `need_gp` fields to `struct ip_vs_dest` is something I need to keep in mind, as well as the changes to locking, refcounting, and synchronization. The refactorings around connection expiry and deletion are potentially touchy areas. The focus on `struct ip_vs_sync_conn_options opts` in `ip_vs_sync.c` is where my attention will focus. Now, considering the KMSAN versus KASAN distinction, I have to remember that KMSAN's job is to detect uninitialized memory reads, something that standard KASAN and other debugging tools might miss. Therefore, I only need to consider setting `NeedsKMSAN=true` if this patch introduces or modifies code that has a risk of exposing uninitialized memory to user space, relies on potentially uninitialized variables, involves uninitialized fields in complex data structures, or makes changes to bounds checks that could lead to uninitialized reads. It's a question of looking for data leaks, essentially. My focus goes to `ip_vs_sync.c`. I need to review what's going on around lines 540-620. Let's look at `ip_vs_sync_conn_v0`. The introduction of `struct ip_vs_sync_conn_options opts;` seems like the interesting part here. Is it initialized? Reading through the code, I see a potential race condition and then it uses memcpy. The local `opts` variable within `ip_vs_sync_conn_v0` is copied after the lock, but before the subsequent memcpy. *Ah-ha!* This looks like it avoids the uninitialized memory issue, as the content of `cp->sync_conn_opt` is copied into `opts` before any other operation. I think this patch doesn't need `NeedsKMSAN=true`. |
| 34/3 | 2026/11/17 07:49 | tool | read-file |
0mArgs:{
"File": "net/netfilter/ipvs/ip_vs_sync.c",
"FirstLine": 535,
"LineCount": 85
}Results: {
"Contents": " 535:\t/*\n 536:\t * Version 0 , could be switched in by sys_ctl.\n 537:\t * Add an ip_vs_conn information into the current sync_buff.\n 538:\t */\n 539:\tstatic void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,\n 540:\t\t\t\t int pkts)\n 541:\t{\n 542:\t\tstruct ip_vs_sync_conn_options opts;\n 543:\t\tstruct ip_vs_sync_mesg_v0 *m;\n 544:\t\tstruct ip_vs_sync_conn_v0 *s;\n 545:\t\tstruct ip_vs_sync_buff *buff;\n 546:\t\tstruct ipvs_master_sync_state *ms;\n 547:\t\tu32 flags, seq_mask;\n 548:\t\tunsigned int len;\n 549:\t\tint id;\n 550:\t\n 551:\t\tif (unlikely(cp-\u003eaf != AF_INET))\n 552:\t\t\treturn;\n 553:\t\tflags = READ_ONCE(cp-\u003eflags);\n 554:\t\t/* Do not sync ONE PACKET */\n 555:\t\tif (flags \u0026 IP_VS_CONN_F_ONE_PACKET)\n 556:\t\t\treturn;\n 557:\t\n 558:\t\tif (!ip_vs_sync_conn_needed(ipvs, cp, pkts))\n 559:\t\t\treturn;\n 560:\t\n 561:\t\tif (flags \u0026 IP_VS_CONN_F_SEQ_MASK) {\n 562:\t\t\t/* Take atomic snapshot of flags and seqs */\n 563:\t\t\tspin_lock_bh(\u0026cp-\u003elock);\n 564:\t\t\tflags = cp-\u003eflags;\n 565:\t\t\tmemcpy(\u0026opts, \u0026cp-\u003esync_conn_opt, sizeof(opts));\n 566:\t\t\tspin_unlock_bh(\u0026cp-\u003elock);\n 567:\t\t}\n 568:\t\n 569:\t\tspin_lock_bh(\u0026ipvs-\u003esync_buff_lock);\n 570:\t\tif (!(ipvs-\u003esync_state \u0026 IP_VS_STATE_MASTER)) {\n 571:\t\t\tspin_unlock_bh(\u0026ipvs-\u003esync_buff_lock);\n 572:\t\t\treturn;\n 573:\t\t}\n 574:\t\n 575:\t\tid = select_master_thread_id(ipvs, cp);\n 576:\t\tms = \u0026ipvs-\u003ems[id];\n 577:\t\tbuff = ms-\u003esync_buff;\n 578:\t\tseq_mask = flags \u0026 IP_VS_CONN_F_SEQ_MASK;\n 579:\t\tlen = seq_mask ? FULL_CONN_SIZE : SIMPLE_CONN_SIZE;\n 580:\t\tif (buff) {\n 581:\t\t\tm = (struct ip_vs_sync_mesg_v0 *) buff-\u003emesg;\n 582:\t\t\t/* Send buffer if it is for v1 */\n 583:\t\t\tif (buff-\u003ehead + len \u003e buff-\u003eend || !m-\u003enr_conns) {\n 584:\t\t\t\tsb_queue_tail(ipvs, ms);\n 585:\t\t\t\tms-\u003esync_buff = NULL;\n 586:\t\t\t\tbuff = NULL;\n 587:\t\t\t}\n 588:\t\t}\n 589:\t\tif (!buff) {\n 590:\t\t\tbuff = ip_vs_sync_buff_create_v0(ipvs, len);\n 591:\t\t\tif (!buff) {\n 592:\t\t\t\tspin_unlock_bh(\u0026ipvs-\u003esync_buff_lock);\n 593:\t\t\t\tpr_err(\"ip_vs_sync_buff_create failed.\\n\");\n 594:\t\t\t\treturn;\n 595:\t\t\t}\n 596:\t\t\tms-\u003esync_buff = buff;\n 597:\t\t}\n 598:\t\n 599:\t\tm = (struct ip_vs_sync_mesg_v0 *) buff-\u003emesg;\n 600:\t\ts = (struct ip_vs_sync_conn_v0 *) buff-\u003ehead;\n 601:\t\n 602:\t\t/* copy members */\n 603:\t\ts-\u003ereserved = 0;\n 604:\t\ts-\u003eprotocol = cp-\u003eprotocol;\n 605:\t\ts-\u003ecport = cp-\u003ecport;\n 606:\t\ts-\u003evport = cp-\u003evport;\n 607:\t\ts-\u003edport = cp-\u003edport;\n 608:\t\ts-\u003ecaddr = cp-\u003ecaddr.ip;\n 609:\t\ts-\u003evaddr = cp-\u003evaddr.ip;\n 610:\t\ts-\u003edaddr = cp-\u003edaddr.ip;\n 611:\t\ts-\u003eflags = htons(flags \u0026 ~IP_VS_CONN_F_HASHED);\n 612:\t\ts-\u003estate = htons(cp-\u003estate);\n 613:\t\tif (seq_mask) {\n 614:\t\t\tstruct ip_vs_sync_conn_options *opt =\n 615:\t\t\t\t(struct ip_vs_sync_conn_options *)\u0026s[1];\n 616:\t\t\tmemcpy(opt, \u0026opts, sizeof(*opt));\n 617:\t\t}\n 618:\t\n 619:\t\tm-\u003enr_conns++;\n"
} |
| 35/3 | 2026/11/17 07:49 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32532 output: 43 thoughts: 603 Thoughts: **Analyzing Potential Race Conditions in Connection Synchronization** Okay, here's what I'm seeing. I'm focusing on this section of code, particularly around how connection flags and sequence mask are handled. I see a critical block of code centered around line 561, specifically dealing with connection synchronization. The initial check, `if (flags & IP_VS_CONN_F_ONE_PACKET)`, is straightforward; if this flag is set, we bail out early. Then, we get to the core of the logic. My immediate concern is around potential race conditions, which is always where my attention goes in these types of scenarios. I need to understand how `flags` changes. Line 553, `flags = READ_ONCE(cp->flags);`, is critical as it's the initial read. What happens if initially `IP_VS_CONN_F_SEQ_MASK` isn't set? Well, at line 561, `flags & IP_VS_CONN_F_SEQ_MASK` would evaluate to zero, and the code inside that `if` statement is skipped. Since `flags` is local, it won't be updated. Then, at line 578, `seq_mask` would also be zero. This is fine, as `if (seq_mask)` won't execute either, and the connection syncing logic is skipped entirely. Now, let's explore the more interesting scenario, around the lock. What if `IP_VS_CONN_F_SEQ_MASK` *wasn't* set at line 561? But *inside* the locked block, `flags = cp->flags` changed it to zero? This is where it gets interesting, and concerning. Inside the critical section, `flags` is re-assigned, and `seq_mask` will correctly reflect the *current* state. The key is that the initial `flags` read, outside the lock, might have been different than what's inside the critical section. So, if `flags & IP_VS_CONN_F_SEQ_MASK` is 0 at line 561, it doesn't execute that code and does not acquire the options. If the `flags` change inside the critical section, this would be a problem as the options would not be synced appropriately. This might require further investigation into how `cp->flags` is modified. So, what about the other way around? Can `flags & IP_VS_CONN_F_SEQ_MASK` be 0 at line 561, and then somehow become non-zero? No, the local `flags` wasn't updated in that case. My next step is to examine how `ip_vs_sync_conn` is used to get a better overview of what's going on. |
| 36/3 | 2026/11/17 07:49 | tool | read-file |
0mArgs:{
"File": "net/netfilter/ipvs/ip_vs_sync.c",
"FirstLine": 650,
"LineCount": 80
}Results: {
"Contents": " 650:\t\tu32 flags, seq_mask;\n 651:\t\n 652:\t\t/* Handle old version of the protocol */\n 653:\t\tif (sysctl_sync_ver(ipvs) == 0) {\n 654:\t\t\tip_vs_sync_conn_v0(ipvs, cp, pkts);\n 655:\t\t\treturn;\n 656:\t\t}\n 657:\t\t/* Do not sync ONE PACKET */\n 658:\t\tif (cp-\u003eflags \u0026 IP_VS_CONN_F_ONE_PACKET)\n 659:\t\t\tgoto control;\n 660:\tsloop:\n 661:\t\tif (!ip_vs_sync_conn_needed(ipvs, cp, pkts))\n 662:\t\t\tgoto control;\n 663:\t\tflags = READ_ONCE(cp-\u003eflags);\n 664:\t\tif (flags \u0026 IP_VS_CONN_F_SEQ_MASK) {\n 665:\t\t\t/* Take atomic snapshot of flags and seqs */\n 666:\t\t\tspin_lock_bh(\u0026cp-\u003elock);\n 667:\t\t\tflags = cp-\u003eflags;\n 668:\t\t\tmemcpy(\u0026opts, \u0026cp-\u003esync_conn_opt, sizeof(opts));\n 669:\t\t\tspin_unlock_bh(\u0026cp-\u003elock);\n 670:\t\t}\n 671:\t\n 672:\t\t/* Sanity checks */\n 673:\t\tpe_name_len = 0;\n 674:\t\tif (cp-\u003epe_data_len) {\n 675:\t\t\tif (!cp-\u003epe_data || !cp-\u003edest) {\n 676:\t\t\t\tIP_VS_ERR_RL(\"SYNC, connection pe_data invalid\\n\");\n 677:\t\t\t\treturn;\n 678:\t\t\t}\n 679:\t\t\tpe_name_len = strnlen(cp-\u003epe-\u003ename, IP_VS_PENAME_MAXLEN);\n 680:\t\t}\n 681:\t\n 682:\t\tspin_lock_bh(\u0026ipvs-\u003esync_buff_lock);\n 683:\t\tif (!(ipvs-\u003esync_state \u0026 IP_VS_STATE_MASTER)) {\n 684:\t\t\tspin_unlock_bh(\u0026ipvs-\u003esync_buff_lock);\n 685:\t\t\treturn;\n 686:\t\t}\n 687:\t\n 688:\t\tid = select_master_thread_id(ipvs, cp);\n 689:\t\tms = \u0026ipvs-\u003ems[id];\n 690:\t\n 691:\t#ifdef CONFIG_IP_VS_IPV6\n 692:\t\tif (cp-\u003eaf == AF_INET6)\n 693:\t\t\tlen = sizeof(struct ip_vs_sync_v6);\n 694:\t\telse\n 695:\t#endif\n 696:\t\t\tlen = sizeof(struct ip_vs_sync_v4);\n 697:\t\n 698:\t\tseq_mask = flags \u0026 IP_VS_CONN_F_SEQ_MASK;\n 699:\t\tif (seq_mask)\n 700:\t\t\tlen += sizeof(struct ip_vs_sync_conn_options) + 2;\n 701:\t\n 702:\t\tif (cp-\u003epe_data_len)\n 703:\t\t\tlen += cp-\u003epe_data_len + 2;\t/* + Param hdr field */\n 704:\t\tif (pe_name_len)\n 705:\t\t\tlen += pe_name_len + 2;\n 706:\t\n 707:\t\t/* check if there is a space for this one */\n 708:\t\tpad = 0;\n 709:\t\tbuff = ms-\u003esync_buff;\n 710:\t\tif (buff) {\n 711:\t\t\tm = buff-\u003emesg;\n 712:\t\t\tpad = (4 - (size_t) buff-\u003ehead) \u0026 3;\n 713:\t\t\t/* Send buffer if it is for v0 */\n 714:\t\t\tif (buff-\u003ehead + len + pad \u003e buff-\u003eend || m-\u003ereserved) {\n 715:\t\t\t\tsb_queue_tail(ipvs, ms);\n 716:\t\t\t\tms-\u003esync_buff = NULL;\n 717:\t\t\t\tbuff = NULL;\n 718:\t\t\t\tpad = 0;\n 719:\t\t\t}\n 720:\t\t}\n 721:\t\n 722:\t\tif (!buff) {\n 723:\t\t\tbuff = ip_vs_sync_buff_create(ipvs, len);\n 724:\t\t\tif (!buff) {\n 725:\t\t\t\tspin_unlock_bh(\u0026ipvs-\u003esync_buff_lock);\n 726:\t\t\t\tpr_err(\"ip_vs_sync_buff_create failed.\\n\");\n 727:\t\t\t\treturn;\n 728:\t\t\t}\n 729:\t\t\tms-\u003esync_buff = buff;\n"
} |
| 37/3 | 2026/11/17 07:49 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35036 output: 43 thoughts: 195 Thoughts: **Diving into `ip_vs_sync_conn`** Okay, let's trace through this `ip_vs_sync_conn` function and see what's happening. I see that lines 769 and onward deal with the `seq_mask`. Interesting, it appears we're packing sequence data in the options. `IPVS_OPT_SEQ_DATA`, the size of `struct ip_vs_sync_conn_options`... then there's the `hton_seq` calls. We're converting the `in_seq` and `out_seq` values to network byte order and embedding them directly into the buffer `p`. Fine. Wait a second... what's this `sloop` thing I'm seeing? Let me jump back a bit... ah, line 660, that's where `sloop` is defined. Now, where did I see a `goto sloop`? It's always useful to know where those come from. Okay, let's scroll through the code from line 780 to 820 and see where that `goto` is directing me back to. |
| 38/3 | 2026/11/17 07:49 | tool | read-file |
0mArgs:{
"File": "net/netfilter/ipvs/ip_vs_sync.c",
"FirstLine": 775,
"LineCount": 50
}Results: {
"Contents": " 775:\t\t\tp += sizeof(struct ip_vs_seq);\n 776:\t\t}\n 777:\t\t/* Handle pe data */\n 778:\t\tif (cp-\u003epe_data_len \u0026\u0026 cp-\u003epe_data) {\n 779:\t\t\t*(p++) = IPVS_OPT_PE_DATA;\n 780:\t\t\t*(p++) = cp-\u003epe_data_len;\n 781:\t\t\tmemcpy(p, cp-\u003epe_data, cp-\u003epe_data_len);\n 782:\t\t\tp += cp-\u003epe_data_len;\n 783:\t\t\tif (pe_name_len) {\n 784:\t\t\t\t/* Add PE_NAME */\n 785:\t\t\t\t*(p++) = IPVS_OPT_PE_NAME;\n 786:\t\t\t\t*(p++) = pe_name_len;\n 787:\t\t\t\tmemcpy(p, cp-\u003epe-\u003ename, pe_name_len);\n 788:\t\t\t\tp += pe_name_len;\n 789:\t\t\t}\n 790:\t\t}\n 791:\t\n 792:\t\tspin_unlock_bh(\u0026ipvs-\u003esync_buff_lock);\n 793:\t\n 794:\tcontrol:\n 795:\t\t/* synchronize its controller if it has */\n 796:\t\tcp = cp-\u003econtrol;\n 797:\t\tif (!cp)\n 798:\t\t\treturn;\n 799:\t\tif (cp-\u003eflags \u0026 IP_VS_CONN_F_TEMPLATE)\n 800:\t\t\tpkts = atomic_inc_return(\u0026cp-\u003ein_pkts);\n 801:\t\telse\n 802:\t\t\tpkts = sysctl_sync_threshold(ipvs);\n 803:\t\tgoto sloop;\n 804:\t}\n 805:\t\n 806:\t/*\n 807:\t * fill_param used by version 1\n 808:\t */\n 809:\tstatic inline int\n 810:\tip_vs_conn_fill_param_sync(struct netns_ipvs *ipvs, int af, union ip_vs_sync_conn *sc,\n 811:\t\t\t\t struct ip_vs_conn_param *p,\n 812:\t\t\t\t __u8 *pe_data, unsigned int pe_data_len,\n 813:\t\t\t\t __u8 *pe_name, unsigned int pe_name_len)\n 814:\t{\n 815:\t#ifdef CONFIG_IP_VS_IPV6\n 816:\t\tif (af == AF_INET6)\n 817:\t\t\tip_vs_conn_fill_param(ipvs, af, sc-\u003ev6.protocol,\n 818:\t\t\t\t\t (const union nf_inet_addr *)\u0026sc-\u003ev6.caddr,\n 819:\t\t\t\t\t sc-\u003ev6.cport,\n 820:\t\t\t\t\t (const union nf_inet_addr *)\u0026sc-\u003ev6.vaddr,\n 821:\t\t\t\t\t sc-\u003ev6.vport, p);\n 822:\t\telse\n 823:\t#endif\n 824:\t\t\tip_vs_conn_fill_param(ipvs, af, sc-\u003ev4.protocol,\n"
} |
| 39/3 | 2026/11/17 07:49 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36341 output: 19 thoughts: 345 Thoughts: **Analyzing a Potential Data Leak in `ip_vs_sync_conn`** Okay, so I'm looking at this `ip_vs_sync_conn` function and immediately a potential issue is jumping out at me. We've got this `struct ip_vs_sync_conn_options opts;` declared right at the top, which isn't inherently problematic. The interesting part is at the `sloop:` label. Here's what's catching my eye: `opts` gets copied *conditionally*. If the `flags` field has a specific bit set (`IP_VS_CONN_F_SEQ_MASK`), then `opts` gets populated. Otherwise, it doesn't. Then comes the line `seq_mask = flags & IP_VS_CONN_F_SEQ_MASK;`. If `seq_mask` is zero, we *don't* read from `opts`. That *should* be fine, right? But... wait a minute. Let's trace a potential scenario. Imagine this: in the first loop iteration (`cp`), the flag *is* set, so `opts` *is* written to. Then we `goto control`, increment `cp`, and enter the loop again. If the flag *is* set again, then `opts` gets overwritten. Fine, no problem. If the flag is *not* set on the second time around, `seq_mask` is zero, so `opts` isn't read, the previous `opts` values are not really used. But, if the flag *isn't* set in the first iteration, `opts` *isn't* written to. Then the `seq_mask` is zero, and so the if statement that uses opts will not be entered. The more I think about it, the more I wonder: What if `cp->sync_conn_opt` itself contains *uninitialized* memory? Where does *that* come from, anyway? That's the key question. We have a potentially uninitialized variable copied into an `opts`, and in one case it's not used, but the value may have been set in a previous iteration. Okay, time to fire up the search tools and see where `sync_conn_opt` is actually populated. I need to understand where this data is coming from to determine if there's a real vulnerability here or if I'm just chasing shadows. |
| 40/3 | 2026/11/17 07:49 | tool | grepper |
0mArgs:{
"Expression": "sync_conn_opt"
}Results: {
"Output": "include/net/ip_vs.h=811=struct ip_vs_conn {\n--\ninclude/net/ip_vs.h-852-\t/* 128/168 */\ninclude/net/ip_vs.h:853:\tstruct_group(sync_conn_opt,\ninclude/net/ip_vs.h-854-\t\tstruct ip_vs_seq in_seq; /* incoming seq. struct */\n--\nnet/netfilter/ipvs/ip_vs_sync.c-13- * time-outs, and firewall marks.\nnet/netfilter/ipvs/ip_vs_sync.c:14: * In ver.1 \"ip_vs_sync_conn_options\" will be sent in netw. order.\nnet/netfilter/ipvs/ip_vs_sync.c-15- * Ver. 0 can be turned on by sysctl -w net.ipv4.vs.sync_version=0\n--\nnet/netfilter/ipvs/ip_vs_sync.c=70=struct ip_vs_sync_conn_v0 {\n--\nnet/netfilter/ipvs/ip_vs_sync.c-88-\nnet/netfilter/ipvs/ip_vs_sync.c:89:struct ip_vs_sync_conn_options {\nnet/netfilter/ipvs/ip_vs_sync.c-90-\tstruct ip_vs_seq in_seq; /* incoming seq. struct */\n--\nnet/netfilter/ipvs/ip_vs_sync.c=196=struct ip_vs_sync_thread_data {\n--\nnet/netfilter/ipvs/ip_vs_sync.c-206-#define FULL_CONN_SIZE \\\nnet/netfilter/ipvs/ip_vs_sync.c:207:(sizeof(struct ip_vs_sync_conn_v0) + sizeof(struct ip_vs_sync_conn_options))\nnet/netfilter/ipvs/ip_vs_sync.c-208-\n--\nnet/netfilter/ipvs/ip_vs_sync.c=539=static void ip_vs_sync_conn_v0(struct netns_ipvs *ipvs, struct ip_vs_conn *cp,\n--\nnet/netfilter/ipvs/ip_vs_sync.c-541-{\nnet/netfilter/ipvs/ip_vs_sync.c:542:\tstruct ip_vs_sync_conn_options opts;\nnet/netfilter/ipvs/ip_vs_sync.c-543-\tstruct ip_vs_sync_mesg_v0 *m;\n--\nnet/netfilter/ipvs/ip_vs_sync.c-564-\t\tflags = cp-\u003eflags;\nnet/netfilter/ipvs/ip_vs_sync.c:565:\t\tmemcpy(\u0026opts, \u0026cp-\u003esync_conn_opt, sizeof(opts));\nnet/netfilter/ipvs/ip_vs_sync.c-566-\t\tspin_unlock_bh(\u0026cp-\u003elock);\n--\nnet/netfilter/ipvs/ip_vs_sync.c-613-\tif (seq_mask) {\nnet/netfilter/ipvs/ip_vs_sync.c:614:\t\tstruct ip_vs_sync_conn_options *opt =\nnet/netfilter/ipvs/ip_vs_sync.c:615:\t\t\t(struct ip_vs_sync_conn_options *)\u0026s[1];\nnet/netfilter/ipvs/ip_vs_sync.c-616-\t\tmemcpy(opt, \u0026opts, sizeof(*opt));\n--\nnet/netfilter/ipvs/ip_vs_sync.c=640=void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts)\nnet/netfilter/ipvs/ip_vs_sync.c-641-{\nnet/netfilter/ipvs/ip_vs_sync.c:642:\tstruct ip_vs_sync_conn_options opts;\nnet/netfilter/ipvs/ip_vs_sync.c-643-\tstruct ip_vs_sync_mesg *m;\n--\nnet/netfilter/ipvs/ip_vs_sync.c-667-\t\tflags = cp-\u003eflags;\nnet/netfilter/ipvs/ip_vs_sync.c:668:\t\tmemcpy(\u0026opts, \u0026cp-\u003esync_conn_opt, sizeof(opts));\nnet/netfilter/ipvs/ip_vs_sync.c-669-\t\tspin_unlock_bh(\u0026cp-\u003elock);\n--\nnet/netfilter/ipvs/ip_vs_sync.c-699-\tif (seq_mask)\nnet/netfilter/ipvs/ip_vs_sync.c:700:\t\tlen += sizeof(struct ip_vs_sync_conn_options) + 2;\nnet/netfilter/ipvs/ip_vs_sync.c-701-\n--\nnet/netfilter/ipvs/ip_vs_sync.c-770-\t\t*(p++) = IPVS_OPT_SEQ_DATA;\nnet/netfilter/ipvs/ip_vs_sync.c:771:\t\t*(p++) = sizeof(struct ip_vs_sync_conn_options);\nnet/netfilter/ipvs/ip_vs_sync.c-772-\t\thton_seq(\u0026opts.in_seq, (struct ip_vs_seq *)p);\n--\nnet/netfilter/ipvs/ip_vs_sync.c=863=static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *param,\n--\nnet/netfilter/ipvs/ip_vs_sync.c-867-\t\t\t unsigned long timeout, __u32 fwmark,\nnet/netfilter/ipvs/ip_vs_sync.c:868:\t\t\t struct ip_vs_sync_conn_options *opt)\nnet/netfilter/ipvs/ip_vs_sync.c-869-{\n--\nnet/netfilter/ipvs/ip_vs_sync.c=1014=static void ip_vs_process_message_v0(struct netns_ipvs *ipvs, const char *buffer,\n--\nnet/netfilter/ipvs/ip_vs_sync.c-1018-\tstruct ip_vs_sync_conn_v0 *s;\nnet/netfilter/ipvs/ip_vs_sync.c:1019:\tstruct ip_vs_sync_conn_options *opt;\nnet/netfilter/ipvs/ip_vs_sync.c-1020-\tstruct ip_vs_protocol *pp;\n--\nnet/netfilter/ipvs/ip_vs_sync.c-1035-\t\tif (flags \u0026 IP_VS_CONN_F_SEQ_MASK) {\nnet/netfilter/ipvs/ip_vs_sync.c:1036:\t\t\topt = (struct ip_vs_sync_conn_options *)\u0026s[1];\nnet/netfilter/ipvs/ip_vs_sync.c-1037-\t\t\tp += FULL_CONN_SIZE;\n--\nnet/netfilter/ipvs/ip_vs_sync.c=1089=static inline int ip_vs_proc_seqopt(__u8 *p, unsigned int plen,\nnet/netfilter/ipvs/ip_vs_sync.c-1090-\t\t\t\t __u32 *opt_flags,\nnet/netfilter/ipvs/ip_vs_sync.c:1091:\t\t\t\t struct ip_vs_sync_conn_options *opt)\nnet/netfilter/ipvs/ip_vs_sync.c-1092-{\nnet/netfilter/ipvs/ip_vs_sync.c:1093:\tstruct ip_vs_sync_conn_options *topt;\nnet/netfilter/ipvs/ip_vs_sync.c-1094-\nnet/netfilter/ipvs/ip_vs_sync.c:1095:\ttopt = (struct ip_vs_sync_conn_options *)p;\nnet/netfilter/ipvs/ip_vs_sync.c-1096-\nnet/netfilter/ipvs/ip_vs_sync.c:1097:\tif (plen != sizeof(struct ip_vs_sync_conn_options)) {\nnet/netfilter/ipvs/ip_vs_sync.c-1098-\t\tIP_VS_DBG(2, \"BACKUP, bogus conn options length\\n\");\n--\nnet/netfilter/ipvs/ip_vs_sync.c=1131=static inline int ip_vs_proc_sync_conn(struct netns_ipvs *ipvs, __u8 *p, __u8 *msg_end)\nnet/netfilter/ipvs/ip_vs_sync.c-1132-{\nnet/netfilter/ipvs/ip_vs_sync.c:1133:\tstruct ip_vs_sync_conn_options opt;\nnet/netfilter/ipvs/ip_vs_sync.c-1134-\tunion ip_vs_sync_conn *s;\n"
} |
| 41/3 | 2026/11/17 07:49 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39483 output: 30 thoughts: 64 Thoughts: Here's my take on the `struct ip_vs_conn` allocation process, as I understand it: **Deconstructing `ip_vs_conn` Allocation** Alright, let's dive into how `struct ip_vs_conn` is actually allocated. I need to refresh my memory on the specifics. My instinct says I should start with the `ip_vs_conn_new` function. Let me check the source code - the `ip_vs_conn.c` file should contain the key details around that function, and that's exactly where I'll find what I'm looking for. Let's see what interesting tidbits are hiding in there. |
| 42/3 | 2026/11/17 07:50 | tool | grepper |
0mArgs:{
"Expression": "kmem_cache_.*alloc.*ip_vs_conn_cachep"
}Results: {
"Output": "net/netfilter/ipvs/ip_vs_conn.c=1476=ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,\n--\nnet/netfilter/ipvs/ip_vs_conn.c-1492-\nnet/netfilter/ipvs/ip_vs_conn.c:1493:\tcp = kmem_cache_alloc(ip_vs_conn_cachep, GFP_ATOMIC);\nnet/netfilter/ipvs/ip_vs_conn.c-1494-\tif (cp == NULL) {\n"
} |
| 43/3 | 2026/11/17 07:50 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39880 output: 44 thoughts: 43 Thoughts: Okay, let's dive into this. **My Analysis of `ip_vs_conn_new`** Right, I'm heading into `net/netfilter/ipvs/ip_vs_conn.c`, specifically lines 1490 through 1560 within the `ip_vs_conn_new` function. I need to refresh my understanding of how new connections are being handled within IPVS. I'm focusing on this specific section because I suspect it might relate to a recent performance bottleneck I've been seeing in a particular test environment. I expect this section deals with the initialization of the connection structure, maybe memory allocation, and the setting of essential connection parameters. I also think I should be on the lookout for potential race conditions or locking issues within this critical path. I'm particularly interested in how the various connection states are initialized, and if any of the default values here could contribute to unexpected behavior under heavy load. I want to pay attention to how and when the conntrack helpers are invoked. Let's see if this analysis can yield useful information. |
| 44/3 | 2026/11/17 07:50 | tool | read-file |
0mArgs:{
"File": "net/netfilter/ipvs/ip_vs_conn.c",
"FirstLine": 1490,
"LineCount": 70
}Results: {
"Contents": "1490:\t\t\t\treturn NULL;\n1491:\t\t} while (!atomic_try_cmpxchg(\u0026ipvs-\u003econn_count, \u0026count, count + 1));\n1492:\t\n1493:\t\tcp = kmem_cache_alloc(ip_vs_conn_cachep, GFP_ATOMIC);\n1494:\t\tif (cp == NULL) {\n1495:\t\t\tatomic_dec(\u0026ipvs-\u003econn_count);\n1496:\t\t\tIP_VS_ERR_RL(\"%s(): no memory\\n\", __func__);\n1497:\t\t\treturn NULL;\n1498:\t\t}\n1499:\t\n1500:\t\tINIT_HLIST_BL_NODE(\u0026cp-\u003ehn0.node);\n1501:\t\tINIT_HLIST_BL_NODE(\u0026cp-\u003ehn1.node);\n1502:\t\ttimer_setup(\u0026cp-\u003etimer, ip_vs_conn_expire, 0);\n1503:\t\tcp-\u003eipvs\t = ipvs;\n1504:\t\tcp-\u003ehn0.dir\t = 0;\n1505:\t\tcp-\u003eaf\t\t = p-\u003eaf;\n1506:\t\tcp-\u003ehn1.dir\t = 1;\n1507:\t\tcp-\u003edaf\t\t = dest_af;\n1508:\t\tcp-\u003eprotocol\t = p-\u003eprotocol;\n1509:\t\tip_vs_addr_set(p-\u003eaf, \u0026cp-\u003ecaddr, p-\u003ecaddr);\n1510:\t\tcp-\u003ecport\t = p-\u003ecport;\n1511:\t\t/* proto should only be IPPROTO_IP if p-\u003evaddr is a fwmark */\n1512:\t\tip_vs_addr_set(p-\u003eprotocol == IPPROTO_IP ? AF_UNSPEC : p-\u003eaf,\n1513:\t\t\t \u0026cp-\u003evaddr, p-\u003evaddr);\n1514:\t\tcp-\u003evport\t = p-\u003evport;\n1515:\t\tip_vs_addr_set(cp-\u003edaf, \u0026cp-\u003edaddr, daddr);\n1516:\t\tcp-\u003edport = dport;\n1517:\t\tcp-\u003eflags\t = flags;\n1518:\t\tcp-\u003efwmark = fwmark;\n1519:\t\tif (flags \u0026 IP_VS_CONN_F_TEMPLATE \u0026\u0026 p-\u003epe) {\n1520:\t\t\tip_vs_pe_get(p-\u003epe);\n1521:\t\t\tcp-\u003epe = p-\u003epe;\n1522:\t\t\tcp-\u003epe_data = p-\u003epe_data;\n1523:\t\t\tcp-\u003epe_data_len = p-\u003epe_data_len;\n1524:\t\t} else {\n1525:\t\t\tcp-\u003epe = NULL;\n1526:\t\t\tcp-\u003epe_data = NULL;\n1527:\t\t\tcp-\u003epe_data_len = 0;\n1528:\t\t}\n1529:\t\tspin_lock_init(\u0026cp-\u003elock);\n1530:\t\n1531:\t\t/*\n1532:\t\t * Set the entry as referenced by the current thread before starting\n1533:\t\t * the timer and giving it our reference to allow other threads to\n1534:\t\t * run ip_vs_random_dropentry() or any deletion method safely.\n1535:\t\t */\n1536:\t\trefcount_set(\u0026cp-\u003erefcnt, 1);\n1537:\t\n1538:\t\tcp-\u003econtrol = NULL;\n1539:\t\tatomic_set(\u0026cp-\u003en_control, 0);\n1540:\t\tatomic_set(\u0026cp-\u003ein_pkts, 0);\n1541:\t\n1542:\t\tcp-\u003epacket_xmit = NULL;\n1543:\t\tcp-\u003eapp = NULL;\n1544:\t\tcp-\u003eapp_data = NULL;\n1545:\t\t/* reset struct ip_vs_seq */\n1546:\t\tmemset(\u0026cp-\u003ein_seq, 0, sizeof(cp-\u003ein_seq));\n1547:\t\tmemset(\u0026cp-\u003eout_seq, 0, sizeof(cp-\u003eout_seq));\n1548:\t\n1549:\t\tif (unlikely(flags \u0026 IP_VS_CONN_F_NO_CPORT)) {\n1550:\t\t\tint af_id = ip_vs_af_index(cp-\u003eaf);\n1551:\t\n1552:\t\t\tatomic_inc(\u0026ipvs-\u003eno_cport_conns[af_id]);\n1553:\t\t}\n1554:\t\n1555:\t\t/* Bind the connection with a destination server */\n1556:\t\tcp-\u003edest = NULL;\n1557:\t\tip_vs_bind_dest(cp, dest);\n1558:\t\n1559:\t\t/* Set its state and timeout */\n"
} |
| 45/3 | 2026/11/17 07:50 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41415 output: 41 thoughts: 1206 Thoughts: **Analyzing Potential Synchronization Issues and Extension Header Handling** Okay, let's break this down. My initial concern was about potential data races related to sequence number synchronization within the IPVS code. Specifically, I'm examining how the `sync_conn_opt` data is handled when it is sent to other machines. I see that `in_seq` and `out_seq`, which constitute `sync_conn_opt`, are initialized to zero using `memset` upon connection allocation. Prior to the patch, the code directly `memcpy`'d `cp->sync_conn_opt`, which could potentially cause problems. The patch addresses this with a lock in the code: This ensures a consistent snapshot. The code then uses this snapshot (`opts`) in both `v0` and `v1` versions of `ip_vs_sync_conn`. In the v1 implementation, `opts` is encoded into a byte stream, and, critically, `seq_mask` (derived from `flags`) determines whether or not `opts` is actually used. Now, I need to confirm that `opts` is always correctly populated. The initial thought was about scenarios where `IP_VS_CONN_F_SEQ_MASK` might change concurrently. But, I believe the logic is sound because `flags` is first read with `READ_ONCE`, and then checked to see if it is set. Even if `flags` were not set initially, `if (flags & IP_VS_CONN_F_SEQ_MASK)` isn't entered and `flags` does not change. Later `seq_mask = flags & IP_VS_CONN_F_SEQ_MASK` which means that the lock is never dropped and the memory never read uninitialized. Therefore, since `seq_mask` will be zero if the initial check is false, the code never attempts to read the uninitialized memory and the `opts` variable is never used uninitialized. Now, shifting gears, I'm going to look at `net/ipv6/exthdrs_core.c` and a potential vulnerability with how IPv6 extension headers are handled. Specifically, I'm focused on the changes in `ipv6_find_hdr` that pertain to fragment handling. The key line to observe is how the offset is calculated. Before this change, when encountering a non-first fragment, `*offset` was not updated. The updated code now sets `*offset = start + sizeof(struct frag_hdr);` which makes sense, but requires careful review. |
| 46/3 | 2026/11/17 07:50 | tool | read-file |
0mArgs:{
"File": "net/ipv6/exthdrs_core.c",
"FirstLine": 235,
"LineCount": 55
}Results: {
"Contents": " 235:\t\n 236:\t\t\t\trh = skb_header_pointer(skb, start, sizeof(_rh),\n 237:\t\t\t\t\t\t\t\u0026_rh);\n 238:\t\t\t\tif (!rh)\n 239:\t\t\t\t\treturn -EBADMSG;\n 240:\t\n 241:\t\t\t\tif (flags \u0026\u0026 (*flags \u0026 IP6_FH_F_SKIP_RH) \u0026\u0026\n 242:\t\t\t\t rh-\u003esegments_left == 0)\n 243:\t\t\t\t\tfound = false;\n 244:\t\t\t}\n 245:\t\n 246:\t\t\tif (nexthdr == NEXTHDR_FRAGMENT) {\n 247:\t\t\t\tunsigned short _frag_off;\n 248:\t\t\t\t__be16 *fp;\n 249:\t\n 250:\t\t\t\tif (flags)\t/* Indicate that this is a fragment */\n 251:\t\t\t\t\t*flags |= IP6_FH_F_FRAG;\n 252:\t\t\t\tfp = skb_header_pointer(skb,\n 253:\t\t\t\t\t\t\tstart+offsetof(struct frag_hdr,\n 254:\t\t\t\t\t\t\t\t frag_off),\n 255:\t\t\t\t\t\t\tsizeof(_frag_off),\n 256:\t\t\t\t\t\t\t\u0026_frag_off);\n 257:\t\t\t\tif (!fp)\n 258:\t\t\t\t\treturn -EBADMSG;\n 259:\t\n 260:\t\t\t\t_frag_off = ntohs(*fp) \u0026 ~0x7;\n 261:\t\t\t\tif (_frag_off) {\n 262:\t\t\t\t\tif (target \u003c 0 \u0026\u0026\n 263:\t\t\t\t\t ((!ipv6_ext_hdr(hp-\u003enexthdr)) ||\n 264:\t\t\t\t\t hp-\u003enexthdr == NEXTHDR_NONE)) {\n 265:\t\t\t\t\t\tif (fragoff)\n 266:\t\t\t\t\t\t\t*fragoff = _frag_off;\n 267:\t\t\t\t\t\t*offset = start + sizeof(struct frag_hdr);\n 268:\t\t\t\t\t\treturn hp-\u003enexthdr;\n 269:\t\t\t\t\t}\n 270:\t\t\t\t\tif (!found)\n 271:\t\t\t\t\t\treturn -ENOENT;\n 272:\t\t\t\t\tif (fragoff)\n 273:\t\t\t\t\t\t*fragoff = _frag_off;\n 274:\t\t\t\t\tbreak;\n 275:\t\t\t\t}\n 276:\t\t\t\thdrlen = 8;\n 277:\t\t\t} else if (nexthdr == NEXTHDR_AUTH) {\n 278:\t\t\t\tif (flags \u0026\u0026 (*flags \u0026 IP6_FH_F_AUTH) \u0026\u0026 (target \u003c 0))\n 279:\t\t\t\t\tbreak;\n 280:\t\t\t\thdrlen = ipv6_authlen(hp);\n 281:\t\t\t} else\n 282:\t\t\t\thdrlen = ipv6_optlen(hp);\n 283:\t\n 284:\t\t\tif (!found) {\n 285:\t\t\t\tif (skb-\u003elen - start \u003c hdrlen)\n 286:\t\t\t\t\treturn -EBADMSG;\n 287:\t\n 288:\t\t\t\tnexthdr = hp-\u003enexthdr;\n 289:\t\t\t\tstart += hdrlen;\n"
} |
| 47/3 | 2026/11/17 07:50 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 43990 output: 41 thoughts: 509 Thoughts: **IPv6 Fragment Handling and ESP with NAT: A Deep Dive** Okay, let's break this down. I'm looking at `ipv6_find_hdr` and immediately see something important regarding fragment handling. It looks like when a non-first fragment is identified, the offset is set to `start + sizeof(struct frag_hdr)`. Got it. Now, the context is about ESP, which is immediately interesting. I'm digging into `ip_vs_core.c`, specifically the `ip_vs_out_icmp_v6` and `ip_vs_in_icmp_v6` functions, and I'm catching something here. The code includes a crucial comment: "ipv6_find_hdr() does not include the embedded header for non-first fragments, add it so that ESP can pass and the NAT writable checks cover the rewritten addresses". Right, so the `ipv6_find_hdr` function doesn't account for the IPv6 header in non-first fragments. This is a potential issue for ESP because it works by encapsulating other headers inside an IPv6 header. Without this inclusion, the code might misinterpret the packet length or make incorrect NAT decisions. The code then adds `sizeof(struct ipv6hdr)` to `ciph.len` if `ciph.len == ciph.off`. This must be a deliberate correction. `ciph` is a structure that looks like it is describing the current header being processed. The check for `ciph.len == ciph.off` seems to indicate it is the first fragment, the correction appears to add the header length, essentially telling the system that the `ciph` structure has had the appropriate header appended, and length updated. This is likely done to ensure the NAT-related checks are correct, especially when rewriting addresses, because the length must be calculated correctly to avoid errors. Now, I want to confirm what `ciph` is and where it is being used. I need to investigate `ip_vs_fill_iph_skb_icmp`. I'll need to understand how the `ciph` structure is populated and subsequently utilized to confirm my hypothesis. |
| 48/3 | 2026/11/17 07:50 | tool | grepper |
0mArgs:{
"Expression": "ip_vs_fill_iph_skb_icmp",
"PathPrefixes": [
"net/netfilter/ipvs/"
]
}Results: {
"Output": "net/netfilter/ipvs/ip_vs_core.c=1092=static int ip_vs_out_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb,\n--\nnet/netfilter/ipvs/ip_vs_core.c-1138-\toffset += sizeof(_icmph);\nnet/netfilter/ipvs/ip_vs_core.c:1139:\tif (!ip_vs_fill_iph_skb_icmp(AF_INET, skb, offset, true, \u0026ciph))\nnet/netfilter/ipvs/ip_vs_core.c-1140-\t\treturn NF_ACCEPT; /* The packet looks wrong, ignore */\n--\nnet/netfilter/ipvs/ip_vs_core.c=1170=static int ip_vs_out_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,\n--\nnet/netfilter/ipvs/ip_vs_core.c-1205-\nnet/netfilter/ipvs/ip_vs_core.c:1206:\tif (!ip_vs_fill_iph_skb_icmp(AF_INET6, skb, ipvsh-\u003elen + sizeof(_icmph),\nnet/netfilter/ipvs/ip_vs_core.c-1207-\t\t\t\t true, \u0026ciph))\n--\nnet/netfilter/ipvs/ip_vs_core.c=1770=ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,\n--\nnet/netfilter/ipvs/ip_vs_core.c-1876-\nnet/netfilter/ipvs/ip_vs_core.c:1877:\tif (!ip_vs_fill_iph_skb_icmp(AF_INET, skb, offset, !tunnel, \u0026ciph))\nnet/netfilter/ipvs/ip_vs_core.c-1878-\t\treturn NF_ACCEPT;\n--\nnet/netfilter/ipvs/ip_vs_core.c=2009=static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,\n--\nnet/netfilter/ipvs/ip_vs_core.c-2048-\toffset = iph-\u003elen + sizeof(_icmph);\nnet/netfilter/ipvs/ip_vs_core.c:2049:\tif (!ip_vs_fill_iph_skb_icmp(AF_INET6, skb, offset, true, \u0026ciph))\nnet/netfilter/ipvs/ip_vs_core.c-2050-\t\treturn NF_ACCEPT;\n"
} |
| 49/3 | 2026/11/17 07:50 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 45680 output: 26 thoughts: 23 Thoughts: Here's my analysis of the provided thought process, tailored for an expert audience: **Analyzing the Function Definition of `ip_vs_fill_iph_skb_icmp`** Okay, so the task at hand is to understand the implications of `ip_vs_fill_iph_skb_icmp`. I need to figure out the context of this function, and the most immediate step is to pinpoint its declaration. Given my existing understanding of the Linux kernel's IP Virtual Server (IPVS) implementation, I can make a few educated guesses about its purpose. Given the name, I'd anticipate it deals with ICMP traffic, likely crafting or manipulating ICMP packets within the context of IPVS. But the specifics – the exact data structures it uses, the conditions it's invoked under – remain opaque without locating its definition. It is a critical component for IPVS. I'll need to drill down into the kernel source to find it. Time to fire up the tools. |
| 50/3 | 2026/11/17 07:50 | tool | grepper |
0mArgs:{
"Expression": "ip_vs_fill_iph_skb_icmp"
}Results: {
"Output": "include/net/ip_vs.h=137=static inline int\ninclude/net/ip_vs.h:138:ip_vs_fill_iph_skb_icmp(int af, const struct sk_buff *skb, int offset,\ninclude/net/ip_vs.h-139-\t\t\tbool inverse, struct ip_vs_iphdr *iphdr)\n--\nnet/netfilter/ipvs/ip_vs_core.c=1092=static int ip_vs_out_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb,\n--\nnet/netfilter/ipvs/ip_vs_core.c-1138-\toffset += sizeof(_icmph);\nnet/netfilter/ipvs/ip_vs_core.c:1139:\tif (!ip_vs_fill_iph_skb_icmp(AF_INET, skb, offset, true, \u0026ciph))\nnet/netfilter/ipvs/ip_vs_core.c-1140-\t\treturn NF_ACCEPT; /* The packet looks wrong, ignore */\n--\nnet/netfilter/ipvs/ip_vs_core.c=1170=static int ip_vs_out_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,\n--\nnet/netfilter/ipvs/ip_vs_core.c-1205-\nnet/netfilter/ipvs/ip_vs_core.c:1206:\tif (!ip_vs_fill_iph_skb_icmp(AF_INET6, skb, ipvsh-\u003elen + sizeof(_icmph),\nnet/netfilter/ipvs/ip_vs_core.c-1207-\t\t\t\t true, \u0026ciph))\n--\nnet/netfilter/ipvs/ip_vs_core.c=1770=ip_vs_in_icmp(struct netns_ipvs *ipvs, struct sk_buff *skb, int *related,\n--\nnet/netfilter/ipvs/ip_vs_core.c-1876-\nnet/netfilter/ipvs/ip_vs_core.c:1877:\tif (!ip_vs_fill_iph_skb_icmp(AF_INET, skb, offset, !tunnel, \u0026ciph))\nnet/netfilter/ipvs/ip_vs_core.c-1878-\t\treturn NF_ACCEPT;\n--\nnet/netfilter/ipvs/ip_vs_core.c=2009=static int ip_vs_in_icmp_v6(struct netns_ipvs *ipvs, struct sk_buff *skb,\n--\nnet/netfilter/ipvs/ip_vs_core.c-2048-\toffset = iph-\u003elen + sizeof(_icmph);\nnet/netfilter/ipvs/ip_vs_core.c:2049:\tif (!ip_vs_fill_iph_skb_icmp(AF_INET6, skb, offset, true, \u0026ciph))\nnet/netfilter/ipvs/ip_vs_core.c-2050-\t\treturn NF_ACCEPT;\n"
} |
| 51/3 | 2026/11/17 07:50 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 46710 output: 37 thoughts: 30 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into the IPVS ICMP Handling** Alright, let's get down to brass tacks. I need to refresh my memory on the intricacies of the IPVS ICMP handling, particularly how it interacts with the SKB (Socket Buffer). I'm thinking specifically about that function, `ip_vs_fill_iph_skb_icmp`, in `include/net/ip_vs.h`. I recall it being a key piece in ensuring proper ICMP echo reply generation or, potentially, ICMP error messages for connection tracking and redirection. I need to understand how the function populates the IP header fields in the SKB to construct correct ICMP packets, particularly when dealing with NAT or other forms of VS-specific address manipulation. I want to check how source address and port rewriting is implemented. Are they using those techniques? Are any special flags set to the SKB for further processing down the line? This is critical for understanding the overall performance and correctness of IPVS's connection management, particularly under high load. I need to look for any potential areas where incorrect header manipulation could lead to ICMP issues, like broken NAT or asymmetric routing. |
| 52/3 | 2026/11/17 07:51 | tool | read-file |
0mArgs:{
"File": "include/net/ip_vs.h",
"FirstLine": 135,
"LineCount": 80
}Results: {
"Contents": " 135:\t}\n 136:\t\n 137:\tstatic inline int\n 138:\tip_vs_fill_iph_skb_icmp(int af, const struct sk_buff *skb, int offset,\n 139:\t\t\t\tbool inverse, struct ip_vs_iphdr *iphdr)\n 140:\t{\n 141:\t\tint hdr_flags = IP_VS_HDR_ICMP;\n 142:\t\n 143:\t\tif (inverse)\n 144:\t\t\thdr_flags |= IP_VS_HDR_INVERSE;\n 145:\t\n 146:\t\treturn ip_vs_fill_iph_skb_off(af, skb, offset, hdr_flags, iphdr);\n 147:\t}\n 148:\t\n 149:\tstatic inline int\n 150:\tip_vs_fill_iph_skb(int af, const struct sk_buff *skb, bool inverse,\n 151:\t\t\t struct ip_vs_iphdr *iphdr)\n 152:\t{\n 153:\t\tint hdr_flags = 0;\n 154:\t\n 155:\t\tif (inverse)\n 156:\t\t\thdr_flags |= IP_VS_HDR_INVERSE;\n 157:\t\n 158:\t\treturn ip_vs_fill_iph_skb_off(af, skb, skb_network_offset(skb),\n 159:\t\t\t\t\t hdr_flags, iphdr);\n 160:\t}\n 161:\t\n 162:\tstatic inline bool\n 163:\tip_vs_iph_inverse(const struct ip_vs_iphdr *iph)\n 164:\t{\n 165:\t\treturn !!(iph-\u003ehdr_flags \u0026 IP_VS_HDR_INVERSE);\n 166:\t}\n 167:\t\n 168:\tstatic inline bool\n 169:\tip_vs_iph_icmp(const struct ip_vs_iphdr *iph)\n 170:\t{\n 171:\t\treturn !!(iph-\u003ehdr_flags \u0026 IP_VS_HDR_ICMP);\n 172:\t}\n 173:\t\n 174:\tstatic inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,\n 175:\t\t\t\t\t const union nf_inet_addr *src)\n 176:\t{\n 177:\t#ifdef CONFIG_IP_VS_IPV6\n 178:\t\tif (af == AF_INET6)\n 179:\t\t\tdst-\u003ein6 = src-\u003ein6;\n 180:\t\telse\n 181:\t#endif\n 182:\t\tdst-\u003eip = src-\u003eip;\n 183:\t}\n 184:\t\n 185:\tstatic inline void ip_vs_addr_set(int af, union nf_inet_addr *dst,\n 186:\t\t\t\t\t const union nf_inet_addr *src)\n 187:\t{\n 188:\t#ifdef CONFIG_IP_VS_IPV6\n 189:\t\tif (af == AF_INET6) {\n 190:\t\t\tdst-\u003ein6 = src-\u003ein6;\n 191:\t\t\treturn;\n 192:\t\t}\n 193:\t#endif\n 194:\t\tdst-\u003eip = src-\u003eip;\n 195:\t\tdst-\u003eall[1] = 0;\n 196:\t\tdst-\u003eall[2] = 0;\n 197:\t\tdst-\u003eall[3] = 0;\n 198:\t}\n 199:\t\n 200:\tstatic inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,\n 201:\t\t\t\t\t const union nf_inet_addr *b)\n 202:\t{\n 203:\t#ifdef CONFIG_IP_VS_IPV6\n 204:\t\tif (af == AF_INET6)\n 205:\t\t\treturn ipv6_addr_equal(\u0026a-\u003ein6, \u0026b-\u003ein6);\n 206:\t#endif\n 207:\t\treturn a-\u003eip == b-\u003eip;\n 208:\t}\n 209:\t\n 210:\t#ifdef CONFIG_IP_VS_DEBUG\n 211:\t#include \u003clinux/net.h\u003e\n 212:\t\n 213:\tint ip_vs_get_debug_level(void);\n 214:\t\n"
} |
| 53/3 | 2026/11/17 07:51 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 48205 output: 26 thoughts: 18 Thoughts: Okay, here's my interpretation of what's going on with `ip_vs_fill_iph_skb_off`, from my perspective as someone deeply familiar with networking and kernel internals: **Diving into `ip_vs_fill_iph_skb_off` - A Deep Dive into IP Virtual Server (IPVS) Packet Manipulation** Alright, let's break down `ip_vs_fill_iph_skb_off`. I immediately recognize this function as a critical piece in the IPVS machinery, specifically dealing with the manipulation and forwarding of IP packets. The name itself gives away a lot: we're filling in, or setting up, the IP header within an `skb` (socket buffer) with an offset. That "off" likely refers to the starting position of the *new* IP header that IPVS is constructing. My guess is, we're likely in the midst of a NAT (Network Address Translation) scenario, or perhaps direct routing. The incoming packet needs to be altered to reflect the new destination or source, or both. The function will almost certainly be responsible for: * **Creating a new IP header:** The original IP header is probably stripped or copied and modified to point to the virtual service's internal target, a new source or destination IP address, etc. * **Calculating checksums:** I can almost guarantee this function will handle or invoke routines to calculate the new IP header checksum correctly. Mistakes here would lead to dropped packets. * **Handling Fragmentation:** I need to look closely at whether this function worries about packet fragmentation. If the resulting packet size is different, there's a chance the packet needs to be fragmented to fit on the network. * **Setting IP Options:** The handling of IP options is another area of concern. IP options are sometimes used to set parameters for packets. Options will need to be correctly transferred if they are needed, dropped if they aren't, or possibly handled on a per-connection basis. The use of an `offset` is significant. It's likely we aren't writing directly to the start of the `skb`'s data buffer. The offset allows for inserting the new IP header at a specific location, perhaps after another header that needs to be preserved, like a TCP header, or even another, inner IP header if we're dealing with encapsulated packets. The underlying networking stack probably manages the "skb" structure, and the function is responsible for adjusting the data pointers and lengths within the `skb` to reflect the changes. I'd expect internal pointers in the skb struct to be correctly adjusted after the new header is written. I'd want to examine its interaction with other IPVS functions, to understand how it fits into the larger packet processing flow, and particularly how it handles conntrack entries or other connection tracking mechanisms. I'd also be curious about any locking mechanisms used to protect access to shared data structures like the `skb`. This is all about ensuring the integrity of the data while it is being changed to reflect the virtualized service. Finally, of course, the goal is to make all these operations as fast as possible, so it's a good place to look for optimization strategies. |
| 54/3 | 2026/11/17 07:51 | tool | grepper |
0mArgs:{
"Expression": "ip_vs_fill_iph_skb_off"
}Results: {
"Output": "include/net/ip_vs.h=93=static inline int\ninclude/net/ip_vs.h:94:ip_vs_fill_iph_skb_off(int af, const struct sk_buff *skb, int offset,\ninclude/net/ip_vs.h-95-\t\t int hdr_flags, struct ip_vs_iphdr *iphdr)\n--\ninclude/net/ip_vs.h=138=ip_vs_fill_iph_skb_icmp(int af, const struct sk_buff *skb, int offset,\n--\ninclude/net/ip_vs.h-145-\ninclude/net/ip_vs.h:146:\treturn ip_vs_fill_iph_skb_off(af, skb, offset, hdr_flags, iphdr);\ninclude/net/ip_vs.h-147-}\n--\ninclude/net/ip_vs.h=150=ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, bool inverse,\n--\ninclude/net/ip_vs.h-157-\ninclude/net/ip_vs.h:158:\treturn ip_vs_fill_iph_skb_off(af, skb, skb_network_offset(skb),\ninclude/net/ip_vs.h-159-\t\t\t\t hdr_flags, iphdr);\n"
} |
| 55/3 | 2026/11/17 07:51 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 49276 output: 36 thoughts: 30 Thoughts: Okay, here's my interpretation of that thought process, assuming I'm already well-versed in IPVS internals: **Diving into the `ip_vs_fill_iph_skb_off` Function** Alright, so the first thing I'm doing is zeroing in on `ip_vs_fill_iph_skb_off`. I'm familiar with the naming convention; it clearly suggests something to do with filling in the IP header within an SKB (Socket Buffer) and likely involves some kind of offset or positioning within that buffer. The `ip_vs_` prefix tells me this function is, of course, a core component of the IP Virtual Server (IPVS) module. The fact that I'm going straight to the header file, `include/net/ip_vs.h`, tells me I'm likely interested in understanding the function's *interface* and perhaps its *purpose* within the broader IPVS architecture, rather than the nitty-gritty implementation details right away. I'm probably looking for the function's prototype, any inline comments, and maybe related macros or structures that give me a context for how this function fits into the overall scheme of IPVS's network manipulation and forwarding. I expect this function has a very important part to play in the critical data path. Time to see what I can learn. |
| 56/3 | 2026/11/17 07:51 | tool | read-file |
0mArgs:{
"File": "include/net/ip_vs.h",
"FirstLine": 90,
"LineCount": 45
}Results: {
"Contents": " 90:\t * IPv6 requires some extra work, as finding proper header position,\n 91:\t * depend on the IPv6 extension headers.\n 92:\t */\n 93:\tstatic inline int\n 94:\tip_vs_fill_iph_skb_off(int af, const struct sk_buff *skb, int offset,\n 95:\t\t\t int hdr_flags, struct ip_vs_iphdr *iphdr)\n 96:\t{\n 97:\t\tiphdr-\u003ehdr_flags = hdr_flags;\n 98:\t\tiphdr-\u003eoff = offset;\n 99:\t\n 100:\t#ifdef CONFIG_IP_VS_IPV6\n 101:\t\tif (af == AF_INET6) {\n 102:\t\t\tstruct ipv6hdr _iph;\n 103:\t\t\tconst struct ipv6hdr *iph = skb_header_pointer(\n 104:\t\t\t\tskb, offset, sizeof(_iph), \u0026_iph);\n 105:\t\t\tif (!iph)\n 106:\t\t\t\treturn 0;\n 107:\t\n 108:\t\t\tiphdr-\u003esaddr.in6 = iph-\u003esaddr;\n 109:\t\t\tiphdr-\u003edaddr.in6 = iph-\u003edaddr;\n 110:\t\t\t/* ipv6_find_hdr() updates len, flags */\n 111:\t\t\tiphdr-\u003elen\t = offset;\n 112:\t\t\tiphdr-\u003eflags\t = 0;\n 113:\t\t\tiphdr-\u003eprotocol = ipv6_find_hdr(skb, \u0026iphdr-\u003elen, -1,\n 114:\t\t\t\t\t\t\t \u0026iphdr-\u003efragoffs,\n 115:\t\t\t\t\t\t\t \u0026iphdr-\u003eflags);\n 116:\t\t\tif (iphdr-\u003eprotocol \u003c 0)\n 117:\t\t\t\treturn 0;\n 118:\t\t} else\n 119:\t#endif\n 120:\t\t{\n 121:\t\t\tstruct iphdr _iph;\n 122:\t\t\tconst struct iphdr *iph = skb_header_pointer(\n 123:\t\t\t\tskb, offset, sizeof(_iph), \u0026_iph);\n 124:\t\t\tif (!iph)\n 125:\t\t\t\treturn 0;\n 126:\t\n 127:\t\t\tiphdr-\u003elen\t= offset + iph-\u003eihl * 4;\n 128:\t\t\tiphdr-\u003efragoffs\t= 0;\n 129:\t\t\tiphdr-\u003eprotocol\t= iph-\u003eprotocol;\n 130:\t\t\tiphdr-\u003esaddr.ip\t= iph-\u003esaddr;\n 131:\t\t\tiphdr-\u003edaddr.ip\t= iph-\u003edaddr;\n 132:\t\t}\n 133:\t\n 134:\t\treturn 1;\n"
} |
| 57/3 | 2026/11/17 07:51 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50328 output: 49 thoughts: 350 Thoughts: **Analyzing IPv6 Fragment Handling and Potential User-Space Exposure in IPVS** Okay, let's break this down. My immediate focus is on how IPv6 fragments are handled within the IPVS code, specifically around `ip_vs_fill_iph_skb_off`. I see that the length field (`iphdr->len`) is being manipulated, and the protocol is being determined using `ipv6_find_hdr`. The key here is the *offset* value, which, with the old code, wasn't being updated by `ipv6_find_hdr` when dealing with non-first fragments. The current code update *does* update the offset now, specifically setting it to `start + sizeof(struct frag_hdr)`. This change in behavior could potentially impact how we interpret fragment lengths. I'm also noting the adjustment to `ciph.len` in `ip_vs_out_icmp_v6` and `ip_vs_in_icmp_v6` for non-first fragments, which seems to compensate for this difference. It's a key part of the logic, and I need to consider it for potential vulnerabilities. Now, my primary concern is to look for potential data exposure. I need to carefully examine `ip_vs_ctl.c` to see if any of the core IPVS structures—`ip_vs_dest`, `ip_vs_service`, or anything else touched within that file—are copied to user space or exposed via Netlink attributes. Specifically, I'll be investigating how destination information is exported, focusing on functions like `ip_vs_genl_dump_dest`, `ip_vs_genl_fill_dest`, and `do_ip_vs_get_ctl`. My goal is to determine if the changes to fragment handling could lead to a situation where sensitive or incorrectly calculated data is leaked to user space through these control paths. I want to look specifically for any possible integer overflows, off-by-one errors, or incorrect buffer lengths that might now exist or were previously present, because of these code changes. I'll need to scrutinize any interactions between the kernel and user space related to destination information in light of the fragment handling logic. |
| 58/3 | 2026/11/17 07:51 | tool | grepper |
0mArgs:{
"Expression": "rcu_state|need_gp",
"PathPrefixes": [
"net/netfilter/ipvs/",
"include/net/ip_vs.h"
]
}Results: {
"Output": "include/net/ip_vs.h=974=struct ip_vs_dest {\n--\ninclude/net/ip_vs.h-1025-\tstruct list_head\tt_list;\t\t/* in dest_trash */\ninclude/net/ip_vs.h:1026:\tunsigned long\t\trcu_state;\t/* GP cookie on unlink (trash or rehash) */\ninclude/net/ip_vs.h-1027-\tunsigned int\t\tin_rs_table:1,\t/* we are in rs_table */\ninclude/net/ip_vs.h:1028:\t\t\t\tneed_gp:1;\t/* Need GP on rehash */\ninclude/net/ip_vs.h-1029-};\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=887=static void ip_vs_rs_hash(struct netns_ipvs *ipvs, struct ip_vs_dest *dest)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-922-\t/* Need RCU grace period when rehashing */\nnet/netfilter/ipvs/ip_vs_ctl.c:923:\tif (dest-\u003eneed_gp) {\nnet/netfilter/ipvs/ip_vs_ctl.c:924:\t\tcond_synchronize_rcu(dest-\u003ercu_state);\nnet/netfilter/ipvs/ip_vs_ctl.c:925:\t\tdest-\u003eneed_gp = 0;\nnet/netfilter/ipvs/ip_vs_ctl.c-926-\t}\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=1191=static void ip_vs_trash_save_dests(struct netns_ipvs *ipvs,\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1194-\tstruct ip_vs_dest *dest;\nnet/netfilter/ipvs/ip_vs_ctl.c:1195:\tunsigned long rcu_state;\nnet/netfilter/ipvs/ip_vs_ctl.c-1196-\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1198-\t\t/* Remember when dests were removed and added to dest_trash */\nnet/netfilter/ipvs/ip_vs_ctl.c:1199:\t\trcu_state = get_state_synchronize_rcu();\nnet/netfilter/ipvs/ip_vs_ctl.c-1200-\t\tlist_for_each_entry(dest, dest_trash, t_list)\nnet/netfilter/ipvs/ip_vs_ctl.c:1201:\t\t\tdest-\u003ercu_state = rcu_state;\nnet/netfilter/ipvs/ip_vs_ctl.c-1202-\t\tip_vs_trash_put_dests(ipvs, dest_trash, cleanup);\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=1394=__ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1425-\t\tif (unlinked) {\nnet/netfilter/ipvs/ip_vs_ctl.c:1426:\t\t\tdest-\u003ercu_state = get_state_synchronize_rcu();\nnet/netfilter/ipvs/ip_vs_ctl.c-1427-\t\t\t/* Need grace period in this or next dest update */\nnet/netfilter/ipvs/ip_vs_ctl.c:1428:\t\t\tdest-\u003eneed_gp = 1;\nnet/netfilter/ipvs/ip_vs_ctl.c-1429-\t\t}\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=1567=ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1616-\t\t */\nnet/netfilter/ipvs/ip_vs_ctl.c:1617:\t\tcond_synchronize_rcu(dest-\u003ercu_state);\nnet/netfilter/ipvs/ip_vs_ctl.c-1618-\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1631-\t\t} else {\nnet/netfilter/ipvs/ip_vs_ctl.c:1632:\t\t\t/* need_gp matters only on dest edit, reinit it */\nnet/netfilter/ipvs/ip_vs_ctl.c:1633:\t\t\tdest-\u003eneed_gp = 0;\nnet/netfilter/ipvs/ip_vs_ctl.c-1634-\n"
} |
| 59/3 | 2026/11/17 07:51 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 52395 output: 36 thoughts: 74 Thoughts: Okay, let's dive into this `ip_vs_dest` struct and make sure things are initialized properly. My immediate concern is ensuring that the `rcu_state` and `need_gp` fields aren't being read before they're written to. That's a classic source of hard-to-debug memory errors, and I need to rule it out. **Investigating ip_vs_dest Allocation and Initialization** So, the first thing I need to do is pinpoint *exactly* where and how `ip_vs_dest` instances are allocated. I'm going to start digging for calls to memory allocation functions, specifically `kzalloc` or `kmem_cache_alloc`. Those are the usual suspects in the kernel for this sort of thing. I want to trace the allocation path and confirm whether the struct's members are getting initialized *before* they're potentially used. This should highlight the initialization path, or lack thereof. Let's get to it. |
| 60/3 | 2026/11/17 07:51 | tool | grepper |
0mArgs:{
"Expression": "alloc.*ip_vs_dest",
"PathPrefixes": [
"net/netfilter/ipvs/"
]
}Results: {
"Output": "net/netfilter/ipvs/ip_vs_ctl.c=1497=ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1521-\nnet/netfilter/ipvs/ip_vs_ctl.c:1522:\tdest = kzalloc_obj(struct ip_vs_dest);\nnet/netfilter/ipvs/ip_vs_ctl.c-1523-\tif (dest == NULL)\n--\nnet/netfilter/ipvs/ip_vs_xmit.c=58=static inline struct ip_vs_dest_dst *ip_vs_dest_dst_alloc(void)\nnet/netfilter/ipvs/ip_vs_xmit.c-59-{\nnet/netfilter/ipvs/ip_vs_xmit.c:60:\treturn kmalloc_obj(struct ip_vs_dest_dst, GFP_ATOMIC);\nnet/netfilter/ipvs/ip_vs_xmit.c-61-}\n"
} |
| 61/3 | 2026/11/17 07:51 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 52999 output: 35 thoughts: 286 Thoughts: **Analyzing the Lifecycle of an `ip_vs_dest` Structure** Okay, so I'm looking at how `ip_vs_new_dest` initializes the `ip_vs_dest` structure. It uses `kzalloc_obj`, which is key - that means `dest` starts completely zeroed out. Specifically, `need_gp` is zero, and so is `rcu_state`. This is important. Then I see `dest->need_gp` being checked in `ip_vs_rs_hash`. It's only going to be non-zero (thus triggering the conditional) if it was previously set to 1 during an `unlinked` state within `__ip_vs_update_dest`. That’s the typical flow. Now, the trash handling is where it gets interesting. Before putting destinations into the trash, `ip_vs_trash_save_dests` is responsible for setting `dest->rcu_state`. This is how the RCU state gets initialized. When `ip_vs_add_dest` pulls it back from the trash, it calls `cond_synchronize_rcu(dest->rcu_state)`. That `rcu_state` value *should* have been properly initialized during that previous trash save operation. But, the question I'm asking myself is: Is there any scenario, *any path at all*, where an `ip_vs_dest` ends up in the trash *without* `ip_vs_trash_save_dests` ever being called first? That's the critical question here! If so, we're in trouble with that `rcu_state` and the RCU synchronization. I need to make sure that condition cannot be met, otherwise, the logic is vulnerable. I'll need to meticulously audit all the call sites of `ip_vs_trash_add_dest`, `ip_vs_trash_put_back`, and `ip_vs_trash_put_dests` to be sure. This is where I need to dig deep! |
| 62/3 | 2026/11/17 07:51 | tool | grepper |
0mArgs:{
"Expression": "ip_vs_trash_",
"PathPrefixes": [
"net/netfilter/ipvs/"
]
}Results: {
"Output": "net/netfilter/ipvs/ip_vs_ctl.c=1113=static struct ip_vs_dest *\nnet/netfilter/ipvs/ip_vs_ctl.c:1114:ip_vs_trash_get_dest(struct ip_vs_service *svc, int dest_af,\nnet/netfilter/ipvs/ip_vs_ctl.c-1115-\t\t const union nf_inet_addr *daddr, __be16 dport)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1155-/* Add destination in temp list for trash */\nnet/netfilter/ipvs/ip_vs_ctl.c:1156:static void ip_vs_trash_add_dest(struct netns_ipvs *ipvs,\nnet/netfilter/ipvs/ip_vs_ctl.c-1157-\t\t\t\t struct ip_vs_dest *dest, unsigned long istart,\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1168-/* Put destinations in trash */\nnet/netfilter/ipvs/ip_vs_ctl.c:1169:static void ip_vs_trash_put_dests(struct netns_ipvs *ipvs,\nnet/netfilter/ipvs/ip_vs_ctl.c-1170-\t\t\t\t struct list_head *dest_trash, bool cleanup)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1180-/* Put destination back in trash */\nnet/netfilter/ipvs/ip_vs_ctl.c:1181:static void ip_vs_trash_put_back(struct netns_ipvs *ipvs,\nnet/netfilter/ipvs/ip_vs_ctl.c-1182-\t\t\t\t struct ip_vs_dest *dest)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1185-\nnet/netfilter/ipvs/ip_vs_ctl.c:1186:\tip_vs_trash_add_dest(ipvs, dest, dest-\u003eidle_start, \u0026dest_trash);\nnet/netfilter/ipvs/ip_vs_ctl.c:1187:\tip_vs_trash_put_dests(ipvs, \u0026dest_trash, false);\nnet/netfilter/ipvs/ip_vs_ctl.c-1188-}\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1190-/* Put destinations in trash and save the RCU state */\nnet/netfilter/ipvs/ip_vs_ctl.c:1191:static void ip_vs_trash_save_dests(struct netns_ipvs *ipvs,\nnet/netfilter/ipvs/ip_vs_ctl.c-1192-\t\t\t\t struct list_head *dest_trash, bool cleanup)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1201-\t\t\tdest-\u003ercu_state = rcu_state;\nnet/netfilter/ipvs/ip_vs_ctl.c:1202:\t\tip_vs_trash_put_dests(ipvs, dest_trash, cleanup);\nnet/netfilter/ipvs/ip_vs_ctl.c-1203-\t}\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=1215=static void ip_vs_dest_free(struct ip_vs_dest *dest)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1231- */\nnet/netfilter/ipvs/ip_vs_ctl.c:1232:static void ip_vs_trash_cleanup(struct netns_ipvs *ipvs)\nnet/netfilter/ipvs/ip_vs_ctl.c-1233-{\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=1567=ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1610-\t */\nnet/netfilter/ipvs/ip_vs_ctl.c:1611:\tdest = ip_vs_trash_get_dest(svc, udest-\u003eaf, \u0026daddr, dport);\nnet/netfilter/ipvs/ip_vs_ctl.c-1612-\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1629-\t\tif (ret \u003c 0) {\nnet/netfilter/ipvs/ip_vs_ctl.c:1630:\t\t\tip_vs_trash_put_back(svc-\u003eipvs, dest);\nnet/netfilter/ipvs/ip_vs_ctl.c-1631-\t\t} else {\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=1699=static void __ip_vs_del_dest(struct netns_ipvs *ipvs, struct ip_vs_dest *dest,\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1708-\nnet/netfilter/ipvs/ip_vs_ctl.c:1709:\tip_vs_trash_add_dest(ipvs, dest, 0, dest_trash);\nnet/netfilter/ipvs/ip_vs_ctl.c-1710-\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=1755=ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-1780-\nnet/netfilter/ipvs/ip_vs_ctl.c:1781:\tip_vs_trash_save_dests(svc-\u003eipvs, \u0026dest_trash, false);\nnet/netfilter/ipvs/ip_vs_ctl.c-1782-\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=2201=static int ip_vs_del_service(struct ip_vs_service *svc)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-2211-\tip_vs_unlink_service(svc, \u0026dest_trash, false);\nnet/netfilter/ipvs/ip_vs_ctl.c:2212:\tip_vs_trash_save_dests(ipvs, \u0026dest_trash, false);\nnet/netfilter/ipvs/ip_vs_ctl.c-2213-\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=2255=static int ip_vs_flush(struct netns_ipvs *ipvs, bool cleanup)\n--\nnet/netfilter/ipvs/ip_vs_ctl.c-2274-\t\t}\nnet/netfilter/ipvs/ip_vs_ctl.c:2275:\t\tip_vs_trash_save_dests(ipvs, \u0026dest_trash, cleanup);\nnet/netfilter/ipvs/ip_vs_ctl.c-2276-\t}\n--\nnet/netfilter/ipvs/ip_vs_ctl.c=5388=void __net_exit ip_vs_control_net_cleanup(struct netns_ipvs *ipvs)\nnet/netfilter/ipvs/ip_vs_ctl.c-5389-{\nnet/netfilter/ipvs/ip_vs_ctl.c:5390:\tip_vs_trash_cleanup(ipvs);\nnet/netfilter/ipvs/ip_vs_ctl.c-5391-\tip_vs_control_net_cleanup_sysctl(ipvs);\n"
} |
| 63/3 | 2026/11/17 07:51 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 55697 output: 444 thoughts: 3078 Thoughts: **KMSAN Reasoning for IPVS Patch** Alright, let's break down this IPVS patch and determine if we need KMSAN. My initial thought process revolves around ensuring data integrity and preventing potential vulnerabilities. I started by tracing the initialization and usage of `dest->rcu_state`, confirming it's consistently initialized and handled safely within the RCU context. Then, I dug deeper into `ip_vs_conn_expire` and its reference counting logic – race conditions are my primary concern here, so I'm paying close attention to atomic operations and RCU synchronization. Next, I shifted to `ip_vs_sync.c` and scrutinized the connection option parameter validation, specifically the template/cport handling. The logic appears sound, explicitly checking for invalid combinations of flags and port values received from sync messages. The goal here is to prevent the introduction of corrupted connection state. I then examined the FTP helper code, confirming the crucial control port checks and the SEQ adjustment logic which is related to connection tracking extensions. I was particularly interested in how they are mangling TCP packets and whether these modifications introduce any memory corruption risks. The sequence adjustment logic had my attention, specifically with conntrack extensions – preventing reallocation bugs is important. The hook state parameter passing in `ip_vs_xmit.c` came next. I focused on `maybe_update_pmtu` which handles Path MTU discovery. The previous reliance on `skb->sk` felt a bit risky and I needed to verify that the replacement using the hook state is more robust, especially concerning socket state. I investigated if any kernel structures are exposed to userspace via `copy_to_user`, `nla_put`, or any similar mechanism. No such modifications or additions were detected during my thorough review of the diff. Then I conducted a comprehensive search using `grep` within the patch for the presence of potential information leaks or data copying that could jeopardize memory safety. My search returned zero results. I then revisited the four KMSAN criteria: 1. **User-space Data Exposure:** The patch doesn't modify or introduce any kernel structures that are sent to user space directly. 2. **Uninitialized Variable Usage:** There's the `opts` struct in `ip_vs_sync.c`. However, its use is carefully guarded by the `seq_mask` flag, ensuring it's only read if it was initialized. Zero-initialized data structures (`kzalloc_obj`) like `struct ip_vs_dest` are used. Explicit checks are in place to ensure correct usage. 3. **Complex Data Structure Initialization:** None. 4. **Bounds Check Vulnerabilities:** The fragment offset and IPv6 header length updates appear safe; checks are present against `skb->len` which is validated on input, and KASAN would catch any out-of-bounds access. So, the focus of this patch seems to be on protecting against concurrency bugs. Refcount overflows/underflows, use-after-free conditions, RCU synchronization, and lock management are central themes. These are exactly the kinds of issues that KASAN, LOCKDEP, and KCSAN excel at detecting. I am confident that none of the changes introduce risks specific to KMSAN. This patch focuses on control flow changes, synchronization and reference counting. Therefore, my conclusion is that `NeedsKMSAN = false`. I am now ready to formulate a clear KMSAN reasoning, contrasting KASAN vs. KMSAN to present my findings. |
| 64/3 | 2026/11/17 07:52 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series makes several networking and IPVS improvements:\n1. Thread-safety and synchronization in IPVS sync (`ip_vs_sync.c`), copying connection sequence options under `cp-\u003elock`. The local variable `struct ip_vs_sync_conn_options opts` is strictly guarded by `flags \u0026 IP_VS_CONN_F_SEQ_MASK`, matching the condition under which it is populated from `cp-\u003esync_conn_opt` (which itself is zero-initialized on connection creation).\n2. RCU grace period and lifecycle fixes in `ip_vs_ctl.c` and `ip_vs_conn.c` (using `need_gp`, `rcu_state`, and `cond_synchronize_rcu`), where destination structures are zero-allocated via `kzalloc_obj`.\n3. Hook state propagation (`const struct nf_hook_state *state`) to xmit functions for accurate socket inspection during PMTU updates.\n4. Ordering fix for `nfct_seqadj_ext_add` in IPVS FTP conntrack handling to avoid conntrack extension reallocation bugs.\n5. Offset and length corrections for IPv6 fragment headers (`ipv6_find_hdr`) and ICMPv6 packets, operating on network skb data bounded by packet lengths.\n6. Input validation dropping connections with invalid zero ports.\n\nNone of these changes introduce or expose uninitialized memory reads or kernel-to-user information leaks:\n- No structures or paddings copied to user space are modified or added.\n- All newly added struct fields (`need_gp`, `rcu_state`) reside in zero-allocated heap memory (`kzalloc_obj`).\n- Potential issues introduced or touched by these changes are concurrency bugs, use-after-free/RCU issues, or skb boundary errors, all of which are covered by standard KASAN, LOCKDEP, and kernel debuggers.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series makes several networking and IPVS improvements:\n1. Thread-safety and synchronization in IPVS sync (`ip_vs_sync.c`), copying connection sequence options under `cp-\u003elock`. The local variable `struct ip_vs_sync_conn_options opts` is strictly guarded by `flags \u0026 IP_VS_CONN_F_SEQ_MASK`, matching the condition under which it is populated from `cp-\u003esync_conn_opt` (which itself is zero-initialized on connection creation).\n2. RCU grace period and lifecycle fixes in `ip_vs_ctl.c` and `ip_vs_conn.c` (using `need_gp`, `rcu_state`, and `cond_synchronize_rcu`), where destination structures are zero-allocated via `kzalloc_obj`.\n3. Hook state propagation (`const struct nf_hook_state *state`) to xmit functions for accurate socket inspection during PMTU updates.\n4. Ordering fix for `nfct_seqadj_ext_add` in IPVS FTP conntrack handling to avoid conntrack extension reallocation bugs.\n5. Offset and length corrections for IPv6 fragment headers (`ipv6_find_hdr`) and ICMPv6 packets, operating on network skb data bounded by packet lengths.\n6. Input validation dropping connections with invalid zero ports.\n\nNone of these changes introduce or expose uninitialized memory reads or kernel-to-user information leaks:\n- No structures or paddings copied to user space are modified or added.\n- All newly added struct fields (`need_gp`, `rcu_state`) reside in zero-allocated heap memory (`kzalloc_obj`).\n- Potential issues introduced or touched by these changes are concurrency bugs, use-after-free/RCU issues, or skb boundary errors, all of which are covered by standard KASAN, LOCKDEP, and kernel debuggers.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|