Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: nf_ct_irc: cap packet search space to 4k

This uses a pseudo-linearization scheme with a 64k global buffer,
but BIG TCP arrival means IPv6 TCP stack can generate skbs
that exceed this size.

In practice, IRC commands are not expected to exceed 512 bytes, plus
this is interactive protocol, so we should not see large packets
in practice.

Given most IRC connections nowadays use TLS so this helper could also be
removed in the near future.

Fixes: 7c4e983c4f3c ("net: allow gso_max_size to exceed 65536")
Fixes: 0fe79f28bfaf ("net: allow gro_max_size to exceed 65536")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Florian Westphal and committed by
Pablo Neira Ayuso
976bf59c c783a29c

+9 -3
+9 -3
net/netfilter/nf_conntrack_irc.c
··· 39 39 EXPORT_SYMBOL_GPL(nf_nat_irc_hook); 40 40 41 41 #define HELPER_NAME "irc" 42 + #define MAX_SEARCH_SIZE 4095 42 43 43 44 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); 44 45 MODULE_DESCRIPTION("IRC (DCC) connection tracking helper"); ··· 122 121 int i, ret = NF_ACCEPT; 123 122 char *addr_beg_p, *addr_end_p; 124 123 typeof(nf_nat_irc_hook) nf_nat_irc; 124 + unsigned int datalen; 125 125 126 126 /* If packet is coming from IRC server */ 127 127 if (dir == IP_CT_DIR_REPLY) ··· 142 140 if (dataoff >= skb->len) 143 141 return NF_ACCEPT; 144 142 143 + datalen = skb->len - dataoff; 144 + if (datalen > MAX_SEARCH_SIZE) 145 + datalen = MAX_SEARCH_SIZE; 146 + 145 147 spin_lock_bh(&irc_buffer_lock); 146 - ib_ptr = skb_header_pointer(skb, dataoff, skb->len - dataoff, 148 + ib_ptr = skb_header_pointer(skb, dataoff, datalen, 147 149 irc_buffer); 148 150 if (!ib_ptr) { 149 151 spin_unlock_bh(&irc_buffer_lock); ··· 155 149 } 156 150 157 151 data = ib_ptr; 158 - data_limit = ib_ptr + skb->len - dataoff; 152 + data_limit = ib_ptr + datalen; 159 153 160 154 /* strlen("\1DCC SENT t AAAAAAAA P\1\n")=24 161 155 * 5+MINMATCHLEN+strlen("t AAAAAAAA P\1\n")=14 */ ··· 257 251 irc_exp_policy.max_expected = max_dcc_channels; 258 252 irc_exp_policy.timeout = dcc_timeout; 259 253 260 - irc_buffer = kmalloc(65536, GFP_KERNEL); 254 + irc_buffer = kmalloc(MAX_SEARCH_SIZE + 1, GFP_KERNEL); 261 255 if (!irc_buffer) 262 256 return -ENOMEM; 263 257