Skip to content

Commit a26c1e4

Browse files
committed
netfilter: nf_tables: do not update stateful expressions if lookup is inverted
Initialize set lookup matching element to NULL. Otherwise, the NFT_LOOKUP_F_INV flag reverses the matching logic and it leads to deference an uninitialized pointer to the matching element. Make sure element data area and stateful expression are accessed if there is a matching set element. This patch undoes 24791b9 ("netfilter: nft_set_bitmap: initialize set element extension in lookups") which is not required anymore. Fixes: 339706b ("netfilter: nft_lookup: update element stateful expression") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 72239f2 commit a26c1e4

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

include/net/netfilter/nf_tables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ static inline void nft_set_elem_update_expr(const struct nft_set_ext *ext,
901901
{
902902
struct nft_expr *expr;
903903

904-
if (nft_set_ext_exists(ext, NFT_SET_EXT_EXPR)) {
904+
if (__nft_set_ext_exists(ext, NFT_SET_EXT_EXPR)) {
905905
expr = nft_set_ext_expr(ext);
906906
expr->ops->eval(expr, regs, pkt);
907907
}

net/netfilter/nft_lookup.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void nft_lookup_eval(const struct nft_expr *expr,
2929
{
3030
const struct nft_lookup *priv = nft_expr_priv(expr);
3131
const struct nft_set *set = priv->set;
32-
const struct nft_set_ext *ext;
32+
const struct nft_set_ext *ext = NULL;
3333
bool found;
3434

3535
found = set->ops->lookup(nft_net(pkt), set, &regs->data[priv->sreg],
@@ -39,11 +39,13 @@ void nft_lookup_eval(const struct nft_expr *expr,
3939
return;
4040
}
4141

42-
if (set->flags & NFT_SET_MAP)
43-
nft_data_copy(&regs->data[priv->dreg],
44-
nft_set_ext_data(ext), set->dlen);
42+
if (ext) {
43+
if (set->flags & NFT_SET_MAP)
44+
nft_data_copy(&regs->data[priv->dreg],
45+
nft_set_ext_data(ext), set->dlen);
4546

46-
nft_set_elem_update_expr(ext, regs, pkt);
47+
nft_set_elem_update_expr(ext, regs, pkt);
48+
}
4749
}
4850

4951
static const struct nla_policy nft_lookup_policy[NFTA_LOOKUP_MAX + 1] = {

net/netfilter/nft_set_bitmap.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ static bool nft_bitmap_lookup(const struct net *net, const struct nft_set *set,
8181
u32 idx, off;
8282

8383
nft_bitmap_location(set, key, &idx, &off);
84-
*ext = NULL;
8584

8685
return nft_bitmap_active(priv->bitmap, idx, off, genmask);
8786
}

0 commit comments

Comments
 (0)