Skip to content

Commit cf7af8e

Browse files
committed
netfilter: nf_ct_irc: cap packet search space to 4k
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2139501 commit 976bf59 Author: Florian Westphal <fw@strlen.de> Date: Tue Aug 9 15:16:35 2022 +0200 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: 7c4e983 ("net: allow gso_max_size to exceed 65536") Fixes: 0fe79f2 ("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> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
1 parent 4cca766 commit cf7af8e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

net/netfilter/nf_conntrack_irc.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ unsigned int (*nf_nat_irc_hook)(struct sk_buff *skb,
3939
EXPORT_SYMBOL_GPL(nf_nat_irc_hook);
4040

4141
#define HELPER_NAME "irc"
42+
#define MAX_SEARCH_SIZE 4095
4243

4344
MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
4445
MODULE_DESCRIPTION("IRC (DCC) connection tracking helper");
@@ -121,6 +122,7 @@ static int help(struct sk_buff *skb, unsigned int protoff,
121122
int i, ret = NF_ACCEPT;
122123
char *addr_beg_p, *addr_end_p;
123124
typeof(nf_nat_irc_hook) nf_nat_irc;
125+
unsigned int datalen;
124126

125127
/* If packet is coming from IRC server */
126128
if (dir == IP_CT_DIR_REPLY)
@@ -140,16 +142,20 @@ static int help(struct sk_buff *skb, unsigned int protoff,
140142
if (dataoff >= skb->len)
141143
return NF_ACCEPT;
142144

145+
datalen = skb->len - dataoff;
146+
if (datalen > MAX_SEARCH_SIZE)
147+
datalen = MAX_SEARCH_SIZE;
148+
143149
spin_lock_bh(&irc_buffer_lock);
144-
ib_ptr = skb_header_pointer(skb, dataoff, skb->len - dataoff,
150+
ib_ptr = skb_header_pointer(skb, dataoff, datalen,
145151
irc_buffer);
146152
if (!ib_ptr) {
147153
spin_unlock_bh(&irc_buffer_lock);
148154
return NF_ACCEPT;
149155
}
150156

151157
data = ib_ptr;
152-
data_limit = ib_ptr + skb->len - dataoff;
158+
data_limit = ib_ptr + datalen;
153159

154160
/* strlen("\1DCC SENT t AAAAAAAA P\1\n")=24
155161
* 5+MINMATCHLEN+strlen("t AAAAAAAA P\1\n")=14 */
@@ -251,7 +257,7 @@ static int __init nf_conntrack_irc_init(void)
251257
irc_exp_policy.max_expected = max_dcc_channels;
252258
irc_exp_policy.timeout = dcc_timeout;
253259

254-
irc_buffer = kmalloc(65536, GFP_KERNEL);
260+
irc_buffer = kmalloc(MAX_SEARCH_SIZE + 1, GFP_KERNEL);
255261
if (!irc_buffer)
256262
return -ENOMEM;
257263

0 commit comments

Comments
 (0)