Skip to content

Commit 3ebb41b

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) Postpone chain policy update to drop after transaction is complete, from Florian Westphal. 2) Add entry to flowtable after confirmation to fix UDP flows with packets going in one single direction. 3) Reference count leak in dst object, from Taehee Yoo. 4) Check for TTL field in flowtable datapath, from Taehee Yoo. 5) Fix h323 conntrack helper due to incorrect boundary check, from Jakub Jankowski. 6) Fix incorrect rcu dereference when fetching basechain stats, from Florian Westphal. 7) Missing error check when adding new entries to flowtable, from Taehee Yoo. 8) Use version field in nfnetlink message to honor the nfgen_family field, from Kristian Evensen. 9) Remove incorrect configuration check for CONFIG_NF_CONNTRACK_IPV6, from Subash Abhinov Kasiviswanathan. 10) Prevent dying entries from being added to the flowtable, from Taehee Yoo. 11) Don't hit WARN_ON() with malformed blob in ebtables with trailing data after last rule, reported by syzbot, patch from Florian Westphal. 12) Remove NFT_CT_TIMEOUT enumeration, never used in the kernel code. 13) Fix incorrect definition for NFT_LOGLEVEL_MAX, from Florian Westphal. This batch comes with a conflict that can be fixed with this patch: diff --cc include/uapi/linux/netfilter/nf_tables.h index 7bdb234,f0cf7b0f4f35..505393c --- a/include/uapi/linux/netfilter/nf_tables.h +++ b/include/uapi/linux/netfilter/nf_tables.h @@@ -966,6 -966,8 +966,7 @@@ enum nft_socket_keys * @NFT_CT_DST_IP: conntrack layer 3 protocol destination (IPv4 address) * @NFT_CT_SRC_IP6: conntrack layer 3 protocol source (IPv6 address) * @NFT_CT_DST_IP6: conntrack layer 3 protocol destination (IPv6 address) - * @NFT_CT_TIMEOUT: connection tracking timeout policy assigned to conntrack + * @NFT_CT_ID: conntrack id */ enum nft_ct_keys { NFT_CT_STATE, @@@ -991,6 -993,8 +992,7 @@@ NFT_CT_DST_IP, NFT_CT_SRC_IP6, NFT_CT_DST_IP6, - NFT_CT_TIMEOUT, + NFT_CT_ID, __NFT_CT_MAX }; #define NFT_CT_MAX (__NFT_CT_MAX - 1) That replaces the unused NFT_CT_TIMEOUT definition by NFT_CT_ID. If you prefer, I can also solve this conflict here, just let me know. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 3ee9ae7 + 92285a0 commit 3ebb41b

9 files changed

Lines changed: 89 additions & 37 deletions

File tree

‎include/uapi/linux/netfilter/nf_tables.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,6 @@ enum nft_socket_keys {
966966
* @NFT_CT_DST_IP: conntrack layer 3 protocol destination (IPv4 address)
967967
* @NFT_CT_SRC_IP6: conntrack layer 3 protocol source (IPv6 address)
968968
* @NFT_CT_DST_IP6: conntrack layer 3 protocol destination (IPv6 address)
969-
* @NFT_CT_TIMEOUT: connection tracking timeout policy assigned to conntrack
970969
* @NFT_CT_ID: conntrack id
971970
*/
972971
enum nft_ct_keys {
@@ -993,7 +992,6 @@ enum nft_ct_keys {
993992
NFT_CT_DST_IP,
994993
NFT_CT_SRC_IP6,
995994
NFT_CT_DST_IP6,
996-
NFT_CT_TIMEOUT,
997995
NFT_CT_ID,
998996
__NFT_CT_MAX
999997
};
@@ -1138,7 +1136,7 @@ enum nft_log_level {
11381136
NFT_LOGLEVEL_AUDIT,
11391137
__NFT_LOGLEVEL_MAX
11401138
};
1141-
#define NFT_LOGLEVEL_MAX (__NFT_LOGLEVEL_MAX + 1)
1139+
#define NFT_LOGLEVEL_MAX (__NFT_LOGLEVEL_MAX - 1)
11421140

11431141
/**
11441142
* enum nft_queue_attributes - nf_tables queue expression netlink attributes

‎net/bridge/netfilter/ebtables.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2153,7 +2153,9 @@ static int compat_copy_entries(unsigned char *data, unsigned int size_user,
21532153
if (ret < 0)
21542154
return ret;
21552155

2156-
WARN_ON(size_remaining);
2156+
if (size_remaining)
2157+
return -EINVAL;
2158+
21572159
return state->buf_kern_offset;
21582160
}
21592161

‎net/netfilter/nf_conntrack_h323_asn1.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static int nf_h323_error_boundary(struct bitstr *bs, size_t bytes, size_t bits)
172172
if (bits % BITS_PER_BYTE > 0)
173173
bytes++;
174174

175-
if (*bs->cur + bytes > *bs->end)
175+
if (bs->cur + bytes > bs->end)
176176
return 1;
177177

178178
return 0;

‎net/netfilter/nf_conntrack_h323_main.c‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -748,24 +748,19 @@ static int callforward_do_filter(struct net *net,
748748
}
749749
break;
750750
}
751-
#if IS_ENABLED(CONFIG_NF_CONNTRACK_IPV6)
751+
#if IS_ENABLED(CONFIG_IPV6)
752752
case AF_INET6: {
753-
const struct nf_ipv6_ops *v6ops;
754753
struct rt6_info *rt1, *rt2;
755754
struct flowi6 fl1, fl2;
756755

757-
v6ops = nf_get_ipv6_ops();
758-
if (!v6ops)
759-
return 0;
760-
761756
memset(&fl1, 0, sizeof(fl1));
762757
fl1.daddr = src->in6;
763758

764759
memset(&fl2, 0, sizeof(fl2));
765760
fl2.daddr = dst->in6;
766-
if (!v6ops->route(net, (struct dst_entry **)&rt1,
761+
if (!nf_ip6_route(net, (struct dst_entry **)&rt1,
767762
flowi6_to_flowi(&fl1), false)) {
768-
if (!v6ops->route(net, (struct dst_entry **)&rt2,
763+
if (!nf_ip6_route(net, (struct dst_entry **)&rt2,
769764
flowi6_to_flowi(&fl2), false)) {
770765
if (ipv6_addr_equal(rt6_nexthop(rt1, &fl1.daddr),
771766
rt6_nexthop(rt2, &fl2.daddr)) &&

‎net/netfilter/nf_conntrack_netlink.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ static int ctnetlink_del_conntrack(struct net *net, struct sock *ctnl,
12561256
struct nf_conntrack_tuple tuple;
12571257
struct nf_conn *ct;
12581258
struct nfgenmsg *nfmsg = nlmsg_data(nlh);
1259-
u_int8_t u3 = nfmsg->nfgen_family;
1259+
u_int8_t u3 = nfmsg->version ? nfmsg->nfgen_family : AF_UNSPEC;
12601260
struct nf_conntrack_zone zone;
12611261
int err;
12621262

‎net/netfilter/nf_flow_table_core.c‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,25 @@ static const struct rhashtable_params nf_flow_offload_rhash_params = {
185185

186186
int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow)
187187
{
188-
flow->timeout = (u32)jiffies;
188+
int err;
189189

190-
rhashtable_insert_fast(&flow_table->rhashtable,
191-
&flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL].node,
192-
nf_flow_offload_rhash_params);
193-
rhashtable_insert_fast(&flow_table->rhashtable,
194-
&flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY].node,
195-
nf_flow_offload_rhash_params);
190+
err = rhashtable_insert_fast(&flow_table->rhashtable,
191+
&flow->tuplehash[0].node,
192+
nf_flow_offload_rhash_params);
193+
if (err < 0)
194+
return err;
195+
196+
err = rhashtable_insert_fast(&flow_table->rhashtable,
197+
&flow->tuplehash[1].node,
198+
nf_flow_offload_rhash_params);
199+
if (err < 0) {
200+
rhashtable_remove_fast(&flow_table->rhashtable,
201+
&flow->tuplehash[0].node,
202+
nf_flow_offload_rhash_params);
203+
return err;
204+
}
205+
206+
flow->timeout = (u32)jiffies;
196207
return 0;
197208
}
198209
EXPORT_SYMBOL_GPL(flow_offload_add);
@@ -232,6 +243,7 @@ flow_offload_lookup(struct nf_flowtable *flow_table,
232243
{
233244
struct flow_offload_tuple_rhash *tuplehash;
234245
struct flow_offload *flow;
246+
struct flow_offload_entry *e;
235247
int dir;
236248

237249
tuplehash = rhashtable_lookup(&flow_table->rhashtable, tuple,
@@ -244,6 +256,10 @@ flow_offload_lookup(struct nf_flowtable *flow_table,
244256
if (flow->flags & (FLOW_OFFLOAD_DYING | FLOW_OFFLOAD_TEARDOWN))
245257
return NULL;
246258

259+
e = container_of(flow, struct flow_offload_entry, flow);
260+
if (unlikely(nf_ct_is_dying(e->ct)))
261+
return NULL;
262+
247263
return tuplehash;
248264
}
249265
EXPORT_SYMBOL_GPL(flow_offload_lookup);
@@ -290,8 +306,10 @@ static inline bool nf_flow_has_expired(const struct flow_offload *flow)
290306
static void nf_flow_offload_gc_step(struct flow_offload *flow, void *data)
291307
{
292308
struct nf_flowtable *flow_table = data;
309+
struct flow_offload_entry *e;
293310

294-
if (nf_flow_has_expired(flow) ||
311+
e = container_of(flow, struct flow_offload_entry, flow);
312+
if (nf_flow_has_expired(flow) || nf_ct_is_dying(e->ct) ||
295313
(flow->flags & (FLOW_OFFLOAD_DYING | FLOW_OFFLOAD_TEARDOWN)))
296314
flow_offload_del(flow_table, flow);
297315
}

‎net/netfilter/nf_flow_table_ip.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ static int nf_flow_tuple_ip(struct sk_buff *skb, const struct net_device *dev,
181181
iph->protocol != IPPROTO_UDP)
182182
return -1;
183183

184+
if (iph->ttl <= 1)
185+
return -1;
186+
184187
thoff = iph->ihl * 4;
185188
if (!pskb_may_pull(skb, thoff + sizeof(*ports)))
186189
return -1;
@@ -408,6 +411,9 @@ static int nf_flow_tuple_ipv6(struct sk_buff *skb, const struct net_device *dev,
408411
ip6h->nexthdr != IPPROTO_UDP)
409412
return -1;
410413

414+
if (ip6h->hop_limit <= 1)
415+
return -1;
416+
411417
thoff = sizeof(*ip6h);
412418
if (!pskb_may_pull(skb, thoff + sizeof(*ports)))
413419
return -1;

‎net/netfilter/nf_tables_api.c‎

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,33 +213,33 @@ static int nft_deltable(struct nft_ctx *ctx)
213213
return err;
214214
}
215215

216-
static int nft_trans_chain_add(struct nft_ctx *ctx, int msg_type)
216+
static struct nft_trans *nft_trans_chain_add(struct nft_ctx *ctx, int msg_type)
217217
{
218218
struct nft_trans *trans;
219219

220220
trans = nft_trans_alloc(ctx, msg_type, sizeof(struct nft_trans_chain));
221221
if (trans == NULL)
222-
return -ENOMEM;
222+
return ERR_PTR(-ENOMEM);
223223

224224
if (msg_type == NFT_MSG_NEWCHAIN)
225225
nft_activate_next(ctx->net, ctx->chain);
226226

227227
list_add_tail(&trans->list, &ctx->net->nft.commit_list);
228-
return 0;
228+
return trans;
229229
}
230230

231231
static int nft_delchain(struct nft_ctx *ctx)
232232
{
233-
int err;
233+
struct nft_trans *trans;
234234

235-
err = nft_trans_chain_add(ctx, NFT_MSG_DELCHAIN);
236-
if (err < 0)
237-
return err;
235+
trans = nft_trans_chain_add(ctx, NFT_MSG_DELCHAIN);
236+
if (IS_ERR(trans))
237+
return PTR_ERR(trans);
238238

239239
ctx->table->use--;
240240
nft_deactivate_next(ctx->net, ctx->chain);
241241

242-
return err;
242+
return 0;
243243
}
244244

245245
static void nft_rule_expr_activate(const struct nft_ctx *ctx,
@@ -1189,6 +1189,9 @@ static int nft_dump_stats(struct sk_buff *skb, struct nft_stats __percpu *stats)
11891189
u64 pkts, bytes;
11901190
int cpu;
11911191

1192+
if (!stats)
1193+
return 0;
1194+
11921195
memset(&total, 0, sizeof(total));
11931196
for_each_possible_cpu(cpu) {
11941197
cpu_stats = per_cpu_ptr(stats, cpu);
@@ -1246,6 +1249,7 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net,
12461249
if (nft_is_base_chain(chain)) {
12471250
const struct nft_base_chain *basechain = nft_base_chain(chain);
12481251
const struct nf_hook_ops *ops = &basechain->ops;
1252+
struct nft_stats __percpu *stats;
12491253
struct nlattr *nest;
12501254

12511255
nest = nla_nest_start_noflag(skb, NFTA_CHAIN_HOOK);
@@ -1267,8 +1271,9 @@ static int nf_tables_fill_chain_info(struct sk_buff *skb, struct net *net,
12671271
if (nla_put_string(skb, NFTA_CHAIN_TYPE, basechain->type->name))
12681272
goto nla_put_failure;
12691273

1270-
if (rcu_access_pointer(basechain->stats) &&
1271-
nft_dump_stats(skb, rcu_dereference(basechain->stats)))
1274+
stats = rcu_dereference_check(basechain->stats,
1275+
lockdep_commit_lock_is_held(net));
1276+
if (nft_dump_stats(skb, stats))
12721277
goto nla_put_failure;
12731278
}
12741279

@@ -1615,6 +1620,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
16151620
struct nft_base_chain *basechain;
16161621
struct nft_stats __percpu *stats;
16171622
struct net *net = ctx->net;
1623+
struct nft_trans *trans;
16181624
struct nft_chain *chain;
16191625
struct nft_rule **rules;
16201626
int err;
@@ -1662,7 +1668,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
16621668
ops->dev = hook.dev;
16631669

16641670
chain->flags |= NFT_BASE_CHAIN;
1665-
basechain->policy = policy;
1671+
basechain->policy = NF_ACCEPT;
16661672
} else {
16671673
chain = kzalloc(sizeof(*chain), GFP_KERNEL);
16681674
if (chain == NULL)
@@ -1698,13 +1704,18 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
16981704
if (err)
16991705
goto err2;
17001706

1701-
err = nft_trans_chain_add(ctx, NFT_MSG_NEWCHAIN);
1702-
if (err < 0) {
1707+
trans = nft_trans_chain_add(ctx, NFT_MSG_NEWCHAIN);
1708+
if (IS_ERR(trans)) {
1709+
err = PTR_ERR(trans);
17031710
rhltable_remove(&table->chains_ht, &chain->rhlhead,
17041711
nft_chain_ht_params);
17051712
goto err2;
17061713
}
17071714

1715+
nft_trans_chain_policy(trans) = -1;
1716+
if (nft_is_base_chain(chain))
1717+
nft_trans_chain_policy(trans) = policy;
1718+
17081719
table->use++;
17091720
list_add_tail_rcu(&chain->list, &table->chains);
17101721

@@ -6310,6 +6321,27 @@ static int nf_tables_validate(struct net *net)
63106321
return 0;
63116322
}
63126323

6324+
/* a drop policy has to be deferred until all rules have been activated,
6325+
* otherwise a large ruleset that contains a drop-policy base chain will
6326+
* cause all packets to get dropped until the full transaction has been
6327+
* processed.
6328+
*
6329+
* We defer the drop policy until the transaction has been finalized.
6330+
*/
6331+
static void nft_chain_commit_drop_policy(struct nft_trans *trans)
6332+
{
6333+
struct nft_base_chain *basechain;
6334+
6335+
if (nft_trans_chain_policy(trans) != NF_DROP)
6336+
return;
6337+
6338+
if (!nft_is_base_chain(trans->ctx.chain))
6339+
return;
6340+
6341+
basechain = nft_base_chain(trans->ctx.chain);
6342+
basechain->policy = NF_DROP;
6343+
}
6344+
63136345
static void nft_chain_commit_update(struct nft_trans *trans)
63146346
{
63156347
struct nft_base_chain *basechain;
@@ -6631,6 +6663,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
66316663
nf_tables_chain_notify(&trans->ctx, NFT_MSG_NEWCHAIN);
66326664
/* trans destroyed after rcu grace period */
66336665
} else {
6666+
nft_chain_commit_drop_policy(trans);
66346667
nft_clear(net, trans->ctx.chain);
66356668
nf_tables_chain_notify(&trans->ctx, NFT_MSG_NEWCHAIN);
66366669
nft_trans_destroy(trans);

‎net/netfilter/nft_flow_offload.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
9494
if (help)
9595
goto out;
9696

97-
if (ctinfo == IP_CT_NEW ||
98-
ctinfo == IP_CT_RELATED)
97+
if (!nf_ct_is_confirmed(ct))
9998
goto out;
10099

101100
if (test_and_set_bit(IPS_OFFLOAD_BIT, &ct->status))
@@ -113,6 +112,7 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
113112
if (ret < 0)
114113
goto err_flow_add;
115114

115+
dst_release(route.tuple[!dir].dst);
116116
return;
117117

118118
err_flow_add:

0 commit comments

Comments
 (0)