Skip to content

Commit 794e687

Browse files
committed
netfilter: ctnetlink: only assign helpers for matching protocols
Make sure not to assign a helper for a different network or transport layer protocol to a connection. Additionally change expectation deletion by helper to compare the name directly - there might be multiple helper registrations using the same name, currently one of them is chosen in an unpredictable manner and only those expectations are removed. Signed-off-by: Patrick McHardy <kaber@trash.net>
1 parent 2eff25c commit 794e687

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

include/net/netfilter/nf_conntrack_helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct nf_conntrack_helper {
4040
};
4141

4242
extern struct nf_conntrack_helper *
43-
__nf_conntrack_helper_find_byname(const char *name);
43+
__nf_conntrack_helper_find(const char *name, u16 l3num, u8 protonum);
4444

4545
extern int nf_conntrack_helper_register(struct nf_conntrack_helper *);
4646
extern void nf_conntrack_helper_unregister(struct nf_conntrack_helper *);

net/netfilter/nf_conntrack_helper.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,23 @@ __nf_ct_helper_find(const struct nf_conntrack_tuple *tuple)
6565
}
6666

6767
struct nf_conntrack_helper *
68-
__nf_conntrack_helper_find_byname(const char *name)
68+
__nf_conntrack_helper_find(const char *name, u16 l3num, u8 protonum)
6969
{
7070
struct nf_conntrack_helper *h;
7171
struct hlist_node *n;
7272
unsigned int i;
7373

7474
for (i = 0; i < nf_ct_helper_hsize; i++) {
7575
hlist_for_each_entry_rcu(h, n, &nf_ct_helper_hash[i], hnode) {
76-
if (!strcmp(h->name, name))
76+
if (!strcmp(h->name, name) &&
77+
h->tuple.src.l3num == l3num &&
78+
h->tuple.dst.protonum == protonum)
7779
return h;
7880
}
7981
}
8082
return NULL;
8183
}
82-
EXPORT_SYMBOL_GPL(__nf_conntrack_helper_find_byname);
84+
EXPORT_SYMBOL_GPL(__nf_conntrack_helper_find);
8385

8486
struct nf_conn_help *nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp)
8587
{

net/netfilter/nf_conntrack_netlink.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,8 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])
10011001
return 0;
10021002
}
10031003

1004-
helper = __nf_conntrack_helper_find_byname(helpname);
1004+
helper = __nf_conntrack_helper_find(helpname, nf_ct_l3num(ct),
1005+
nf_ct_protonum(ct));
10051006
if (helper == NULL) {
10061007
#ifdef CONFIG_MODULES
10071008
spin_unlock_bh(&nf_conntrack_lock);
@@ -1012,7 +1013,8 @@ ctnetlink_change_helper(struct nf_conn *ct, const struct nlattr * const cda[])
10121013
}
10131014

10141015
spin_lock_bh(&nf_conntrack_lock);
1015-
helper = __nf_conntrack_helper_find_byname(helpname);
1016+
helper = __nf_conntrack_helper_find(helpname, nf_ct_l3num(ct),
1017+
nf_ct_protonum(ct));
10161018
if (helper)
10171019
return -EAGAIN;
10181020
#endif
@@ -1211,7 +1213,8 @@ ctnetlink_create_conntrack(struct net *net,
12111213
if (err < 0)
12121214
goto err2;
12131215

1214-
helper = __nf_conntrack_helper_find_byname(helpname);
1216+
helper = __nf_conntrack_helper_find(helpname, nf_ct_l3num(ct),
1217+
nf_ct_protonum(ct));
12151218
if (helper == NULL) {
12161219
rcu_read_unlock();
12171220
#ifdef CONFIG_MODULES
@@ -1221,7 +1224,9 @@ ctnetlink_create_conntrack(struct net *net,
12211224
}
12221225

12231226
rcu_read_lock();
1224-
helper = __nf_conntrack_helper_find_byname(helpname);
1227+
helper = __nf_conntrack_helper_find(helpname,
1228+
nf_ct_l3num(ct),
1229+
nf_ct_protonum(ct));
12251230
if (helper) {
12261231
err = -EAGAIN;
12271232
goto err2;
@@ -1714,7 +1719,6 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
17141719
struct net *net = sock_net(ctnl);
17151720
struct nf_conntrack_expect *exp;
17161721
struct nf_conntrack_tuple tuple;
1717-
struct nf_conntrack_helper *h;
17181722
struct nfgenmsg *nfmsg = nlmsg_data(nlh);
17191723
struct hlist_node *n, *next;
17201724
u_int8_t u3 = nfmsg->nfgen_family;
@@ -1751,18 +1755,13 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
17511755

17521756
/* delete all expectations for this helper */
17531757
spin_lock_bh(&nf_conntrack_lock);
1754-
h = __nf_conntrack_helper_find_byname(name);
1755-
if (!h) {
1756-
spin_unlock_bh(&nf_conntrack_lock);
1757-
return -EOPNOTSUPP;
1758-
}
17591758
for (i = 0; i < nf_ct_expect_hsize; i++) {
17601759
hlist_for_each_entry_safe(exp, n, next,
17611760
&net->ct.expect_hash[i],
17621761
hnode) {
17631762
m_help = nfct_help(exp->master);
1764-
if (m_help->helper == h
1765-
&& del_timer(&exp->timeout)) {
1763+
if (!strcmp(m_help->helper->name, name) &&
1764+
del_timer(&exp->timeout)) {
17661765
nf_ct_unlink_expect(exp);
17671766
nf_ct_expect_put(exp);
17681767
}

0 commit comments

Comments
 (0)