--- zzzz-none-000/linux-5.4.213/net/netfilter/nf_conntrack_standalone.c 2022-09-15 10:04:56.000000000 +0000 +++ miami-7690-761/linux-5.4.213/net/netfilter/nf_conntrack_standalone.c 2024-05-29 11:20:02.000000000 +0000 @@ -9,6 +9,7 @@ #include #include #include +#include #include #ifdef CONFIG_SYSCTL #include @@ -24,6 +25,9 @@ #include #include +/* Do not check the TCP window for incoming packets */ +static int nf_ct_tcp_no_window_check __read_mostly = 1; + static bool enable_hooks __read_mostly; MODULE_PARM_DESC(enable_hooks, "Always enable conntrack hooks"); module_param(enable_hooks, bool, 0000); @@ -455,6 +459,56 @@ return 0; } +struct kill_request { + u16 family; + union nf_inet_addr addr; +}; + +static int kill_matching(struct nf_conn *i, void *data) +{ + struct kill_request *kr = data; + struct nf_conntrack_tuple *t1 = &i->tuplehash[IP_CT_DIR_ORIGINAL].tuple; + struct nf_conntrack_tuple *t2 = &i->tuplehash[IP_CT_DIR_REPLY].tuple; + + if (!kr->family) + return 1; + + if (t1->src.l3num != kr->family) + return 0; + + return (nf_inet_addr_cmp(&kr->addr, &t1->src.u3) || + nf_inet_addr_cmp(&kr->addr, &t1->dst.u3) || + nf_inet_addr_cmp(&kr->addr, &t2->src.u3) || + nf_inet_addr_cmp(&kr->addr, &t2->dst.u3)); +} + +static int ct_file_write(struct file *file, char *buf, size_t count) +{ + struct seq_file *seq = file->private_data; + struct net *net = seq_file_net(seq); + struct kill_request kr = { }; + + if (count == 0) + return 0; + + if (count >= INET6_ADDRSTRLEN) + count = INET6_ADDRSTRLEN - 1; + + if (strnchr(buf, count, ':')) { + kr.family = AF_INET6; + if (!in6_pton(buf, count, (void *)&kr.addr, '\n', NULL)) + return -EINVAL; + } else if (strnchr(buf, count, '.')) { + kr.family = AF_INET; + if (!in4_pton(buf, count, (void *)&kr.addr, '\n', NULL)) + return -EINVAL; + } + + nf_ct_iterate_cleanup_net(net, kill_matching, &kr, 0, 0); + + return 0; +} + static const struct seq_operations ct_cpu_seq_ops = { .start = ct_cpu_seq_start, .next = ct_cpu_seq_next, @@ -468,8 +522,9 @@ kuid_t root_uid; kgid_t root_gid; - pde = proc_create_net("nf_conntrack", 0440, net->proc_net, &ct_seq_ops, - sizeof(struct ct_iter_state)); + pde = proc_create_net_data_write("nf_conntrack", 0440, net->proc_net, + &ct_seq_ops, &ct_file_write, + sizeof(struct ct_iter_state), NULL); if (!pde) goto out_nf_conntrack; @@ -598,6 +653,7 @@ NF_SYSCTL_CT_PROTO_TIMEOUT_GRE_STREAM, #endif + NF_SYSCTL_CT_PROTO_TCP_NO_WINDOW_CHECK, __NF_SYSCTL_CT_LAST_SYSCTL, }; @@ -924,6 +980,13 @@ .proc_handler = proc_dointvec_jiffies, }, #endif + [NF_SYSCTL_CT_PROTO_TCP_NO_WINDOW_CHECK] = { + .procname = "nf_conntrack_tcp_no_window_check", + .data = &nf_ct_tcp_no_window_check, + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = proc_dointvec, + }, {} };