Skip to content

Commit 8c26544

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf
Pablo Neira Ayuso says: ==================== Netfilter fixes for net The following patchset contains Netfilter fixes for net: 1) Endianness issue in IPv4 option support in nft_exthdr, from Stephen Suryaputra. 2) Removes the waitcount optimization in nft_compat, from Florian Westphal. 3) Remove ipv6 -> nf_defrag_ipv6 module dependency, from Florian Westphal. 4) Memleak in chain binding support, also from Florian. 5) Simplify nft_flowtable.sh selftest, from Fabian Frederick. 6) Optional MTU arguments for selftest nft_flowtable.sh, also from Fabian. 7) Remove noise error report when killing process in selftest nft_flowtable.sh, from Fabian Frederick. 8) Reject bogus getsockopt option length in ebtables, from Florian Westphal. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 71a5041 + 5c04da5 commit 8c26544

File tree

8 files changed

+73
-80
lines changed

8 files changed

+73
-80
lines changed

include/linux/netfilter_ipv6.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ struct nf_ipv6_ops {
5858
int (*output)(struct net *, struct sock *, struct sk_buff *));
5959
int (*reroute)(struct sk_buff *skb, const struct nf_queue_entry *entry);
6060
#if IS_MODULE(CONFIG_IPV6)
61-
int (*br_defrag)(struct net *net, struct sk_buff *skb, u32 user);
6261
int (*br_fragment)(struct net *net, struct sock *sk,
6362
struct sk_buff *skb,
6463
struct nf_bridge_frag_data *data,
@@ -117,23 +116,6 @@ static inline int nf_ip6_route(struct net *net, struct dst_entry **dst,
117116

118117
#include <net/netfilter/ipv6/nf_defrag_ipv6.h>
119118

120-
static inline int nf_ipv6_br_defrag(struct net *net, struct sk_buff *skb,
121-
u32 user)
122-
{
123-
#if IS_MODULE(CONFIG_IPV6)
124-
const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
125-
126-
if (!v6_ops)
127-
return 1;
128-
129-
return v6_ops->br_defrag(net, skb, user);
130-
#elif IS_BUILTIN(CONFIG_IPV6)
131-
return nf_ct_frag6_gather(net, skb, user);
132-
#else
133-
return 1;
134-
#endif
135-
}
136-
137119
int br_ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
138120
struct nf_bridge_frag_data *data,
139121
int (*output)(struct net *, struct sock *sk,

net/bridge/netfilter/ebtables.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,10 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
22382238
struct ebt_table *t;
22392239
struct net *net = sock_net(sk);
22402240

2241+
if ((cmd == EBT_SO_GET_INFO || cmd == EBT_SO_GET_INIT_INFO) &&
2242+
*len != sizeof(struct compat_ebt_replace))
2243+
return -EINVAL;
2244+
22412245
if (copy_from_user(&tmp, user, sizeof(tmp)))
22422246
return -EFAULT;
22432247

net/bridge/netfilter/nf_conntrack_bridge.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ static unsigned int nf_ct_br_defrag4(struct sk_buff *skb,
168168
static unsigned int nf_ct_br_defrag6(struct sk_buff *skb,
169169
const struct nf_hook_state *state)
170170
{
171+
#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
171172
u16 zone_id = NF_CT_DEFAULT_ZONE_ID;
172173
enum ip_conntrack_info ctinfo;
173174
struct br_input_skb_cb cb;
@@ -180,14 +181,17 @@ static unsigned int nf_ct_br_defrag6(struct sk_buff *skb,
180181

181182
br_skb_cb_save(skb, &cb, sizeof(struct inet6_skb_parm));
182183

183-
err = nf_ipv6_br_defrag(state->net, skb,
184-
IP_DEFRAG_CONNTRACK_BRIDGE_IN + zone_id);
184+
err = nf_ct_frag6_gather(state->net, skb,
185+
IP_DEFRAG_CONNTRACK_BRIDGE_IN + zone_id);
185186
/* queued */
186187
if (err == -EINPROGRESS)
187188
return NF_STOLEN;
188189

189190
br_skb_cb_restore(skb, &cb, IP6CB(skb)->frag_max_size);
190191
return err == 0 ? NF_ACCEPT : NF_DROP;
192+
#else
193+
return NF_ACCEPT;
194+
#endif
191195
}
192196

193197
static int nf_ct_br_ip_check(const struct sk_buff *skb)

net/ipv6/netfilter.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,6 @@ static const struct nf_ipv6_ops ipv6ops = {
245245
.route_input = ip6_route_input,
246246
.fragment = ip6_fragment,
247247
.reroute = nf_ip6_reroute,
248-
#if IS_MODULE(CONFIG_IPV6) && IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
249-
.br_defrag = nf_ct_frag6_gather,
250-
#endif
251248
#if IS_MODULE(CONFIG_IPV6)
252249
.br_fragment = br_ip6_fragment,
253250
#endif

net/netfilter/nf_tables_api.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,8 +2018,10 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
20182018
if (nla[NFTA_CHAIN_NAME]) {
20192019
chain->name = nla_strdup(nla[NFTA_CHAIN_NAME], GFP_KERNEL);
20202020
} else {
2021-
if (!(flags & NFT_CHAIN_BINDING))
2022-
return -EINVAL;
2021+
if (!(flags & NFT_CHAIN_BINDING)) {
2022+
err = -EINVAL;
2023+
goto err1;
2024+
}
20232025

20242026
snprintf(name, sizeof(name), "__chain%llu", ++chain_id);
20252027
chain->name = kstrdup(name, GFP_KERNEL);

net/netfilter/nft_compat.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ struct nft_xt_match_priv {
2727
void *info;
2828
};
2929

30-
static refcount_t nft_compat_pending_destroy = REFCOUNT_INIT(1);
31-
3230
static int nft_compat_chain_validate_dependency(const struct nft_ctx *ctx,
3331
const char *tablename)
3432
{
@@ -215,6 +213,17 @@ static int nft_parse_compat(const struct nlattr *attr, u16 *proto, bool *inv)
215213
return 0;
216214
}
217215

216+
static void nft_compat_wait_for_destructors(void)
217+
{
218+
/* xtables matches or targets can have side effects, e.g.
219+
* creation/destruction of /proc files.
220+
* The xt ->destroy functions are run asynchronously from
221+
* work queue. If we have pending invocations we thus
222+
* need to wait for those to finish.
223+
*/
224+
nf_tables_trans_destroy_flush_work();
225+
}
226+
218227
static int
219228
nft_target_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
220229
const struct nlattr * const tb[])
@@ -238,14 +247,7 @@ nft_target_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
238247

239248
nft_target_set_tgchk_param(&par, ctx, target, info, &e, proto, inv);
240249

241-
/* xtables matches or targets can have side effects, e.g.
242-
* creation/destruction of /proc files.
243-
* The xt ->destroy functions are run asynchronously from
244-
* work queue. If we have pending invocations we thus
245-
* need to wait for those to finish.
246-
*/
247-
if (refcount_read(&nft_compat_pending_destroy) > 1)
248-
nf_tables_trans_destroy_flush_work();
250+
nft_compat_wait_for_destructors();
249251

250252
ret = xt_check_target(&par, size, proto, inv);
251253
if (ret < 0)
@@ -260,7 +262,6 @@ nft_target_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
260262

261263
static void __nft_mt_tg_destroy(struct module *me, const struct nft_expr *expr)
262264
{
263-
refcount_dec(&nft_compat_pending_destroy);
264265
module_put(me);
265266
kfree(expr->ops);
266267
}
@@ -468,6 +469,8 @@ __nft_match_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
468469

469470
nft_match_set_mtchk_param(&par, ctx, match, info, &e, proto, inv);
470471

472+
nft_compat_wait_for_destructors();
473+
471474
return xt_check_match(&par, size, proto, inv);
472475
}
473476

@@ -716,14 +719,6 @@ static const struct nfnetlink_subsystem nfnl_compat_subsys = {
716719

717720
static struct nft_expr_type nft_match_type;
718721

719-
static void nft_mt_tg_deactivate(const struct nft_ctx *ctx,
720-
const struct nft_expr *expr,
721-
enum nft_trans_phase phase)
722-
{
723-
if (phase == NFT_TRANS_COMMIT)
724-
refcount_inc(&nft_compat_pending_destroy);
725-
}
726-
727722
static const struct nft_expr_ops *
728723
nft_match_select_ops(const struct nft_ctx *ctx,
729724
const struct nlattr * const tb[])
@@ -762,7 +757,6 @@ nft_match_select_ops(const struct nft_ctx *ctx,
762757
ops->type = &nft_match_type;
763758
ops->eval = nft_match_eval;
764759
ops->init = nft_match_init;
765-
ops->deactivate = nft_mt_tg_deactivate,
766760
ops->destroy = nft_match_destroy;
767761
ops->dump = nft_match_dump;
768762
ops->validate = nft_match_validate;
@@ -853,7 +847,6 @@ nft_target_select_ops(const struct nft_ctx *ctx,
853847
ops->size = NFT_EXPR_SIZE(XT_ALIGN(target->targetsize));
854848
ops->init = nft_target_init;
855849
ops->destroy = nft_target_destroy;
856-
ops->deactivate = nft_mt_tg_deactivate,
857850
ops->dump = nft_target_dump;
858851
ops->validate = nft_target_validate;
859852
ops->data = target;
@@ -917,8 +910,6 @@ static void __exit nft_compat_module_exit(void)
917910
nfnetlink_subsys_unregister(&nfnl_compat_subsys);
918911
nft_unregister_expr(&nft_target_type);
919912
nft_unregister_expr(&nft_match_type);
920-
921-
WARN_ON_ONCE(refcount_read(&nft_compat_pending_destroy) != 1);
922913
}
923914

924915
MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_NFT_COMPAT);

net/netfilter/nft_exthdr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void nft_exthdr_ipv6_eval(const struct nft_expr *expr,
4444

4545
err = ipv6_find_hdr(pkt->skb, &offset, priv->type, NULL, NULL);
4646
if (priv->flags & NFT_EXTHDR_F_PRESENT) {
47-
*dest = (err >= 0);
47+
nft_reg_store8(dest, err >= 0);
4848
return;
4949
} else if (err < 0) {
5050
goto err;
@@ -141,7 +141,7 @@ static void nft_exthdr_ipv4_eval(const struct nft_expr *expr,
141141

142142
err = ipv4_find_option(nft_net(pkt), skb, &offset, priv->type);
143143
if (priv->flags & NFT_EXTHDR_F_PRESENT) {
144-
*dest = (err >= 0);
144+
nft_reg_store8(dest, err >= 0);
145145
return;
146146
} else if (err < 0) {
147147
goto err;

tools/testing/selftests/netfilter/nft_flowtable.sh

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
# SPDX-License-Identifier: GPL-2.0
33
#
44
# This tests basic flowtable functionality.
5-
# Creates following topology:
5+
# Creates following default topology:
66
#
77
# Originator (MTU 9000) <-Router1-> MTU 1500 <-Router2-> Responder (MTU 2000)
88
# Router1 is the one doing flow offloading, Router2 has no special
99
# purpose other than having a link that is smaller than either Originator
1010
# and responder, i.e. TCPMSS announced values are too large and will still
1111
# result in fragmentation and/or PMTU discovery.
12+
#
13+
# You can check with different Orgininator/Link/Responder MTU eg:
14+
# sh nft_flowtable.sh -o1000 -l500 -r100
15+
#
16+
1217

1318
# Kselftest framework requirement - SKIP code is 4.
1419
ksft_skip=4
@@ -21,29 +26,18 @@ ns2out=""
2126

2227
log_netns=$(sysctl -n net.netfilter.nf_log_all_netns)
2328

24-
nft --version > /dev/null 2>&1
25-
if [ $? -ne 0 ];then
26-
echo "SKIP: Could not run test without nft tool"
27-
exit $ksft_skip
28-
fi
29-
30-
ip -Version > /dev/null 2>&1
31-
if [ $? -ne 0 ];then
32-
echo "SKIP: Could not run test without ip tool"
33-
exit $ksft_skip
34-
fi
35-
36-
which nc > /dev/null 2>&1
37-
if [ $? -ne 0 ];then
38-
echo "SKIP: Could not run test without nc (netcat)"
39-
exit $ksft_skip
40-
fi
29+
checktool (){
30+
$1 > /dev/null 2>&1
31+
if [ $? -ne 0 ];then
32+
echo "SKIP: Could not $2"
33+
exit $ksft_skip
34+
fi
35+
}
4136

42-
ip netns add nsr1
43-
if [ $? -ne 0 ];then
44-
echo "SKIP: Could not create net namespace"
45-
exit $ksft_skip
46-
fi
37+
checktool "nft --version" "run test without nft tool"
38+
checktool "ip -Version" "run test without ip tool"
39+
checktool "which nc" "run test without nc (netcat)"
40+
checktool "ip netns add nsr1" "create net namespace"
4741

4842
ip netns add ns1
4943
ip netns add ns2
@@ -89,11 +83,24 @@ ip -net nsr2 addr add dead:2::1/64 dev veth1
8983
# ns2 is going via nsr2 with a smaller mtu, so that TCPMSS announced by both peers
9084
# is NOT the lowest link mtu.
9185

92-
ip -net nsr1 link set veth0 mtu 9000
93-
ip -net ns1 link set eth0 mtu 9000
86+
omtu=9000
87+
lmtu=1500
88+
rmtu=2000
89+
90+
while getopts "o:l:r:" o
91+
do
92+
case $o in
93+
o) omtu=$OPTARG;;
94+
l) lmtu=$OPTARG;;
95+
r) rmtu=$OPTARG;;
96+
esac
97+
done
98+
99+
ip -net nsr1 link set veth0 mtu $omtu
100+
ip -net ns1 link set eth0 mtu $omtu
94101

95-
ip -net nsr2 link set veth1 mtu 2000
96-
ip -net ns2 link set eth0 mtu 2000
102+
ip -net nsr2 link set veth1 mtu $rmtu
103+
ip -net ns2 link set eth0 mtu $rmtu
97104

98105
# transfer-net between nsr1 and nsr2.
99106
# these addresses are not used for connections.
@@ -147,7 +154,7 @@ table inet filter {
147154
# as PMTUd is off.
148155
# This rule is deleted for the last test, when we expect PMTUd
149156
# to kick in and ensure all packets meet mtu requirements.
150-
meta length gt 1500 accept comment something-to-grep-for
157+
meta length gt $lmtu accept comment something-to-grep-for
151158
152159
# next line blocks connection w.o. working offload.
153160
# we only do this for reverse dir, because we expect packets to
@@ -243,8 +250,14 @@ test_tcp_forwarding_ip()
243250

244251
sleep 3
245252

246-
kill $lpid
247-
kill $cpid
253+
if ps -p $lpid > /dev/null;then
254+
kill $lpid
255+
fi
256+
257+
if ps -p $cpid > /dev/null;then
258+
kill $cpid
259+
fi
260+
248261
wait
249262

250263
check_transfer "$ns1in" "$ns2out" "ns1 -> ns2"

0 commit comments

Comments
 (0)