Skip to content

Commit f50ee3a

Browse files
committed
Florian Westphal says: ==================== netfilter updates for net Patch 1, from Pablo Neira Ayuso, fixes a performance regression (since 6.4) when a large pending set update has to be canceled towards the end of the transaction. Patch 2 from myself, silences an incorrect compiler warning reported with a few (older) compiler toolchains. Patch 3, from Kees Cook, adds __counted_by annotation to nft_pipapo set backend type. I took this for net instead of -next given infra is already in place and no actual code change is made. Patch 4, from Pablo Neira Ayso, disables timeout resets on stateful element reset. The rest should only affect internal object state, e.g. reset a quota or counter, but not affect a pending timeout. Patches 5 and 6 fix NULL dereferences in 'inner header' match, control plane doesn't test for netlink attribute presence before accessing them. Broken since feature was added in 6.2, fixes from Xingyuan Mo. Last patch, from myself, fixes a bogus rule match when skb has a 0-length mac header, in this case we'd fetch data from network header instead of canceling rule evaluation. This is a day 0 bug, present since nftables was merged in 3.13. * tag 'nf-23-10-12' of https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf: netfilter: nft_payload: fix wrong mac header matching nf_tables: fix NULL pointer dereference in nft_expr_inner_parse() nf_tables: fix NULL pointer dereference in nft_inner_init() netfilter: nf_tables: do not refresh timeout when resetting element netfilter: nf_tables: Annotate struct nft_pipapo_match with __counted_by netfilter: nfnetlink_log: silence bogus compiler warning netfilter: nf_tables: do not remove elements if set backend implements .abort ==================== Link: https://lore.kernel.org/r/20231012085724.15155-1-fw@strlen.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 2c0d808 + d351c1e commit f50ee3a

5 files changed

Lines changed: 14 additions & 18 deletions

File tree

net/netfilter/nf_tables_api.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,7 +3166,7 @@ int nft_expr_inner_parse(const struct nft_ctx *ctx, const struct nlattr *nla,
31663166
if (err < 0)
31673167
return err;
31683168

3169-
if (!tb[NFTA_EXPR_DATA])
3169+
if (!tb[NFTA_EXPR_DATA] || !tb[NFTA_EXPR_NAME])
31703170
return -EINVAL;
31713171

31723172
type = __nft_expr_type_get(ctx->family, tb[NFTA_EXPR_NAME]);
@@ -5556,7 +5556,6 @@ static int nf_tables_fill_setelem(struct sk_buff *skb,
55565556
const struct nft_set_ext *ext = nft_set_elem_ext(set, elem->priv);
55575557
unsigned char *b = skb_tail_pointer(skb);
55585558
struct nlattr *nest;
5559-
u64 timeout = 0;
55605559

55615560
nest = nla_nest_start_noflag(skb, NFTA_LIST_ELEM);
55625561
if (nest == NULL)
@@ -5592,15 +5591,11 @@ static int nf_tables_fill_setelem(struct sk_buff *skb,
55925591
htonl(*nft_set_ext_flags(ext))))
55935592
goto nla_put_failure;
55945593

5595-
if (nft_set_ext_exists(ext, NFT_SET_EXT_TIMEOUT)) {
5596-
timeout = *nft_set_ext_timeout(ext);
5597-
if (nla_put_be64(skb, NFTA_SET_ELEM_TIMEOUT,
5598-
nf_jiffies64_to_msecs(timeout),
5599-
NFTA_SET_ELEM_PAD))
5600-
goto nla_put_failure;
5601-
} else if (set->flags & NFT_SET_TIMEOUT) {
5602-
timeout = READ_ONCE(set->timeout);
5603-
}
5594+
if (nft_set_ext_exists(ext, NFT_SET_EXT_TIMEOUT) &&
5595+
nla_put_be64(skb, NFTA_SET_ELEM_TIMEOUT,
5596+
nf_jiffies64_to_msecs(*nft_set_ext_timeout(ext)),
5597+
NFTA_SET_ELEM_PAD))
5598+
goto nla_put_failure;
56045599

56055600
if (nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION)) {
56065601
u64 expires, now = get_jiffies_64();
@@ -5615,9 +5610,6 @@ static int nf_tables_fill_setelem(struct sk_buff *skb,
56155610
nf_jiffies64_to_msecs(expires),
56165611
NFTA_SET_ELEM_PAD))
56175612
goto nla_put_failure;
5618-
5619-
if (reset)
5620-
*nft_set_ext_expiration(ext) = now + timeout;
56215613
}
56225614

56235615
if (nft_set_ext_exists(ext, NFT_SET_EXT_USERDATA)) {
@@ -10347,7 +10339,10 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action)
1034710339
break;
1034810340
}
1034910341
te = (struct nft_trans_elem *)trans->data;
10350-
nft_setelem_remove(net, te->set, &te->elem);
10342+
if (!te->set->ops->abort ||
10343+
nft_setelem_is_catchall(te->set, &te->elem))
10344+
nft_setelem_remove(net, te->set, &te->elem);
10345+
1035110346
if (!nft_setelem_is_catchall(te->set, &te->elem))
1035210347
atomic_dec(&te->set->nelems);
1035310348

net/netfilter/nfnetlink_log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,8 @@ nfulnl_log_packet(struct net *net,
698698
unsigned int plen = 0;
699699
struct nfnl_log_net *log = nfnl_log_pernet(net);
700700
const struct nfnl_ct_hook *nfnl_ct = NULL;
701+
enum ip_conntrack_info ctinfo = 0;
701702
struct nf_conn *ct = NULL;
702-
enum ip_conntrack_info ctinfo;
703703

704704
if (li_user && li_user->type == NF_LOG_TYPE_ULOG)
705705
li = li_user;

net/netfilter/nft_inner.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ static int nft_inner_init(const struct nft_ctx *ctx,
298298
int err;
299299

300300
if (!tb[NFTA_INNER_FLAGS] ||
301+
!tb[NFTA_INNER_NUM] ||
301302
!tb[NFTA_INNER_HDRSIZE] ||
302303
!tb[NFTA_INNER_TYPE] ||
303304
!tb[NFTA_INNER_EXPR])

net/netfilter/nft_payload.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void nft_payload_eval(const struct nft_expr *expr,
179179

180180
switch (priv->base) {
181181
case NFT_PAYLOAD_LL_HEADER:
182-
if (!skb_mac_header_was_set(skb))
182+
if (!skb_mac_header_was_set(skb) || skb_mac_header_len(skb) == 0)
183183
goto err;
184184

185185
if (skb_vlan_tag_present(skb) &&

net/netfilter/nft_set_pipapo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct nft_pipapo_match {
147147
unsigned long * __percpu *scratch;
148148
size_t bsize_max;
149149
struct rcu_head rcu;
150-
struct nft_pipapo_field f[];
150+
struct nft_pipapo_field f[] __counted_by(field_count);
151151
};
152152

153153
/**

0 commit comments

Comments
 (0)