Skip to contentSkip to conversation

netfilter: nf_tables: validate objref and objrefmap expressions

PATCH Superseded Fernando Fernandez Mancera 3 participants 5 messages Oct 4, 2025 – Oct 8, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: nf_tables: validate objref and objrefmap expressions

Referencing a synproxy stateful object can cause a kernel crash due to its usage on the OUTPUT hook. See the following trace:

BUG: TASK stack guard page was hit at 000000008bda5b8c (stack is 000000003ab1c4a5..00000000494d8b12)
[...]
Call Trace:
 <TASK>
 __find_rr_leaf+0x99/0x230
 fib6_table_lookup+0x13b/0x2d0
 ip6_pol_route+0xa4/0x400
 fib6_rule_lookup+0x156/0x240
 ip6_route_output_flags+0xc6/0x150
 __nf_ip6_route+0x23/0x50
 synproxy_send_tcp_ipv6+0x106/0x200 [nf_synproxy_core 2531b21bd6e9569ffd76f28a949f7f2922fec65d]
 synproxy_send_client_synack_ipv6+0x1aa/0x1f0 [nf_synproxy_core 2531b21bd6e9569ffd76f28a949f7f2922fec65d]
 nft_synproxy_do_eval+0x263/0x310 [nft_synproxy 1dcf907d37286d566a63aee8e263fccf6aba22d5]
 nft_do_chain+0x5a8/0x5f0 [nf_tables 5137ebab9ca1fa5980eb27e6394e4f7bf139224e]
 nft_do_chain_inet+0x98/0x110 [nf_tables 5137ebab9ca1fa5980eb27e6394e4f7bf139224e]
 nf_hook_slow+0x43/0xc0
 __ip6_local_out+0xf0/0x170
 ip6_local_out+0x17/0x70
 synproxy_send_tcp_ipv6+0x1a2/0x200 [nf_synproxy_core 2531b21bd6e9569ffd76f28a949f7f2922fec65d]
 synproxy_send_client_synack_ipv6+0x1aa/0x1f0 [nf_synproxy_core 2531b21bd6e9569ffd76f28a949f7f2922fec65d]

[...]

To avoid such situations, implement objref and objrefmap expression validate function. Currently, only NFT_OBJECT_SYNPROXY object type requires validation. This will also handle a jump to a chain using a synproxy object from the OUTPUT hook.

Now when trying to reference a synproxy object in the OUTPUT hook, nft will produce the following error:

synproxy_crash.nft:11:3-26: Error: Could not process rule: Operation not supported

		synproxy name mysynproxy
		^^^^^^^^^^^^^^^^^^^^^^^^
Fixes ee394f96ad75 ("netfilter: nft_synproxy: add synproxy stateful object support")
---
 include/net/netfilter/nf_tables.h      |  5 +++
 include/net/netfilter/nf_tables_core.h |  2 +
 net/netfilter/nf_tables_api.c          | 43 +++++++++++++++++++++
 net/netfilter/nft_objref.c             | 52 ++++++++++++++++++++++++++
 4 files changed, 102 insertions(+)
include/net/netfilter/nf_tables.h +5 -0
index fab7dc73f738..5994f465cbdc 100644
@@ -1135,6 +1135,11 @@ int nft_setelem_validate(const struct nft_ctx *ctx, struct nft_set *set,
 			 const struct nft_set_iter *iter,
 			 struct nft_elem_priv *elem_priv);
 int nft_set_catchall_validate(const struct nft_ctx *ctx, struct nft_set *set);
+int nft_setelem_obj_validate(const struct nft_ctx *ctx, struct nft_set *set,
+			     const struct nft_set_iter *iter,
+			     struct nft_elem_priv *elem_priv);
+int nft_set_catchall_obj_validate(const struct nft_ctx *ctx,
+				  struct nft_set *set);
 int nf_tables_bind_chain(const struct nft_ctx *ctx, struct nft_chain *chain);
 void nf_tables_unbind_chain(const struct nft_ctx *ctx, struct nft_chain *chain);
 
include/net/netfilter/nf_tables_core.h +2 -0
index b8df5acbb723..097564ec998d 100644
@@ -180,6 +180,8 @@ void nft_payload_inner_eval(const struct nft_expr *expr, struct nft_regs *regs,
 
 void nft_objref_eval(const struct nft_expr *expr, struct nft_regs *regs,
 		     const struct nft_pktinfo *pkt);
+int nft_objref_validate_obj(const struct nft_ctx *ctx,
+			    const struct nft_object *obj);
 void nft_objref_map_eval(const struct nft_expr *expr, struct nft_regs *regs,
 			 const struct nft_pktinfo *pkt);
 struct nft_elem_priv *nft_dynset_new(struct nft_set *set,
net/netfilter/nf_tables_api.c +43 -0

49 lines not on this page · raw message

net/netfilter/nft_objref.c +52 -0

76 lines not on this page · raw message

Signature · 1 line
2.51.0
maintainer
#1 lore raw
Quoted 2 lines · Fernando Fernandez Mancera

Referencing a synproxy stateful object can cause a kernel crash due to its usage on the OUTPUT hook. See the following trace:

I edited this slightly to mention the recursion and applied this patch to nf:testing.

Let me know if I messed anything up.

I did not alter the actual code changes; patch LGTM.

#2 lore raw
Quoted 9 lines · Florian Westphal
Quoted 2 lines · Fernando Fernandez Mancera

Referencing a synproxy stateful object can cause a kernel crash due to its usage on the OUTPUT hook. See the following trace:

I edited this slightly to mention the recursion and applied this patch to nf:testing.

Let me know if I messed anything up.

All looks good, thank you Florian!

#3 lore raw
In reply to Fernando Fernandez Mancera

Hi Fernando,

On Sun, Oct 05, 2025 at 01:04:24AM +0200, Fernando Fernandez Mancera wrote:
[...]

Quoted 11 lines

To avoid such situations, implement objref and objrefmap expression validate function. Currently, only NFT_OBJECT_SYNPROXY object type requires validation. This will also handle a jump to a chain using a synproxy object from the OUTPUT hook.

Now when trying to reference a synproxy object in the OUTPUT hook, nft will produce the following error:

synproxy_crash.nft:11:3-26: Error: Could not process rule: Operation not supported

		synproxy name mysynproxy
		^^^^^^^^^^^^^^^^^^^^^^^^

Object maps only store one type of object, ie. all objects are of the same type.

        if (nla[NFTA_SET_OBJ_TYPE] != NULL) {
                if (!(flags & NFT_SET_OBJECT))
                        return -EINVAL;

                desc.objtype = ntohl(nla_get_be32(nla[NFTA_SET_OBJ_TYPE]));
                if (desc.objtype == NFT_OBJECT_UNSPEC ||
                    desc.objtype > NFT_OBJECT_MAX)
                        return -EOPNOTSUPP;
        } else if (flags & NFT_SET_OBJECT)
                return -EINVAL;
        else
                desc.objtype = NFT_OBJECT_UNSPEC;

I think it should be possible to simplify this patch: From objref, you could check if map is of NFT_OBJECT_SYNPROXY type, then check if the right hook type is used.

Thanks.

#4 lore raw
Quoted 32 lines · Pablo Neira Ayuso

Hi Fernando,

On Sun, Oct 05, 2025 at 01:04:24AM +0200, Fernando Fernandez Mancera wrote:
[...]

Quoted 11 lines

To avoid such situations, implement objref and objrefmap expression validate function. Currently, only NFT_OBJECT_SYNPROXY object type requires validation. This will also handle a jump to a chain using a synproxy object from the OUTPUT hook.

Now when trying to reference a synproxy object in the OUTPUT hook, nft will produce the following error:

synproxy_crash.nft:11:3-26: Error: Could not process rule: Operation not supported

		synproxy name mysynproxy
		^^^^^^^^^^^^^^^^^^^^^^^^

Object maps only store one type of object, ie. all objects are of the same type.

         if (nla[NFTA_SET_OBJ_TYPE] != NULL) {
                 if (!(flags & NFT_SET_OBJECT))
                         return -EINVAL;

                 desc.objtype = ntohl(nla_get_be32(nla[NFTA_SET_OBJ_TYPE]));
                 if (desc.objtype == NFT_OBJECT_UNSPEC ||
                     desc.objtype > NFT_OBJECT_MAX)
                         return -EOPNOTSUPP;
         } else if (flags & NFT_SET_OBJECT)
                 return -EINVAL;
         else
                 desc.objtype = NFT_OBJECT_UNSPEC;
Quoted 4 lines

I think it should be possible to simplify this patch: From objref, you could check if map is of NFT_OBJECT_SYNPROXY type, then check if the right hook type is used.

Ah right, it makes sense. Thank you, let me send a V2.

Quoted 2 lines

Thanks.