All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH libftnl 05/12] src: object: don't permit to re-set or clear object type field
Date: Wed, 28 Oct 2026 15:56:25 +0100	[thread overview]
Message-ID: <20261028145632.7089-6-fw@strlen.de> (raw)
In-Reply-To: <20261028145632.7089-1-fw@strlen.de>

LLM finding:
If obj->ops was previously valid (object already typed) and the caller passes
an invalid type, obj->ops is nulled. The object is left in an inconsistent state.
flags still has the NFTNL_OBJ_TYPE bit set.

Subsequent default-path sets will fail.
get/build/output calls that dereference obj->ops will segfault.

Don't permit identity change.

The object type uses a set of common flags plus a set of type
specific flags.  The latter overlaps.

Permitting identity switch is just asking for trouble.
Moreover, there is a latent crash bug:

If a future type introduces a flag overlapping with
NFTNL_OBJ_TUNNEL_OPTS, we free a pointer inside union.

Check we have the correct subtype before freeing.
This is NOT a bug at this time, nftables neither switches
ops nor does it call nftnl_obj_unset().

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/object.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/object.c b/src/object.c
index 1198be6965d9..d35e050b9d83 100644
--- a/src/object.c
+++ b/src/object.c
@@ -56,7 +56,8 @@ void nftnl_obj_free(const struct nftnl_obj *obj)
 		xfree(obj->name);
 	if (obj->flags & (1 << NFTNL_OBJ_USERDATA))
 		nftnl_mem_blob_free(&obj->user_data);
-	if (obj->flags & (1 << NFTNL_OBJ_TUNNEL_OPTS)) {
+	if (obj->ops && obj->ops->type == NFT_OBJECT_TUNNEL &&
+	    obj->flags & (1 << NFTNL_OBJ_TUNNEL_OPTS)) {
 		nftnl_tunnel_opts_free(obj->data.tunnel.tun_opts);
 		xfree(obj->data.tunnel.tun_opts);
 	}
@@ -86,13 +87,21 @@ void nftnl_obj_unset(struct nftnl_obj *obj, uint16_t attr)
 	case NFTNL_OBJ_USERDATA:
 		nftnl_mem_blob_free(&obj->user_data);
 		break;
-	case NFTNL_OBJ_TYPE:
 	case NFTNL_OBJ_FAMILY:
 	case NFTNL_OBJ_USE:
 	case NFTNL_OBJ_HANDLE:
 		break;
+	case NFTNL_OBJ_TYPE:
+		/* don't allow to morph one object type
+		 * to another.
+		 */
+		return;
 	default:
-		break;
+		/* object type specific. Clearing e.g.
+		 * NFTNL_OBJ_TUNNEL_OPTS results
+		 * in memory leak.
+		 */
+		return;
 	}
 
 	obj->flags &= ~(1 << attr);
@@ -121,6 +130,8 @@ int nftnl_obj_set_data(struct nftnl_obj *obj, uint16_t attr,
 		return nftnl_set_str_attr(&obj->name, &obj->flags,
 					  attr, data, data_len);
 	case NFTNL_OBJ_TYPE:
+		if (obj->ops)	/* don't permit object type change */
+			return -1;
 		obj->ops = nftnl_obj_ops_lookup(*((uint32_t *)data));
 		if (!obj->ops)
 			return -1;
-- 
2.55.0


  parent reply	other threads:[~2026-10-28 14:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 14:56 [PATCH libftnl 00/12] more misc LLM fixes Florian Westphal
2026-10-28 14:56 ` [PATCH libftnl 01/12] src: common: mnl_nlmsg_batch_start may return NULL Florian Westphal
2026-10-28 14:56 ` [PATCH libftnl 02/12] src: fix uninitialised attr arrays Florian Westphal
2026-10-28 14:56 ` [PATCH libftnl 03/12] src: move several MNL_STRING types to MNL_NUL_STRING Florian Westphal
2026-10-28 14:56 ` [PATCH libftnl 04/12] src: expr: make sure NFTA_EXPR_NAME was parsed successfuly Florian Westphal
2026-10-28 14:56 ` Florian Westphal [this message]
2026-10-28 14:56 ` [PATCH libftnl 06/12] include: drop semicolon at end of xfree macro Florian Westphal
2026-10-28 14:56 ` [PATCH libftnl 07/12] src: ruleset: remove set_elem member from union Florian Westphal
2026-10-28 14:56 ` [PATCH libftnl 08/12] src: set: clear field_len array before copying Florian Westphal
2026-10-29 17:17   ` Phil Sutter
2026-10-28 14:56 ` [PATCH libftnl 09/12] src: set: check for empty list explicitly Florian Westphal
2026-10-28 14:56 ` [PATCH libftnl 10/12] src: set_elem: list_del before freeing Florian Westphal
2026-10-28 14:56 ` [PATCH libftnl 11/12] src: udata: clamp buf->end to actally copied size Florian Westphal
2026-10-28 14:56 ` [PATCH libftnl 12/12] src: remove all remaining MNL_STRING users Florian Westphal
2026-10-29 17:19 ` [PATCH libftnl 00/12] more misc LLM fixes Phil Sutter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261028145632.7089-6-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.