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 10/12] src: set_elem: list_del before freeing
Date: Wed, 28 Oct 2026 15:56:30 +0100	[thread overview]
Message-ID: <20261028145632.7089-11-fw@strlen.de> (raw)
In-Reply-To: <20261028145632.7089-1-fw@strlen.de>

LLM finding:
nftnl_expr_free() calls xfree(expr).
It never calls list_del(&expr->head).

After the loop, expr_list.next/.prev point into freed heap memory.
Next list_add results in UaF.

Looks like noone does such re-use, but as the API allows it, make
this safe.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/set_elem.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/set_elem.c b/src/set_elem.c
index 3504a2306e47..0170d0ccefd1 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -88,8 +88,10 @@ void nftnl_set_elem_unset(struct nftnl_set_elem *s, uint16_t attr)
 		break;
 	case NFTNL_SET_ELEM_EXPR:
 	case NFTNL_SET_ELEM_EXPRESSIONS:
-		list_for_each_entry_safe(expr, tmp, &s->expr_list, head)
+		list_for_each_entry_safe(expr, tmp, &s->expr_list, head) {
+			list_del(&expr->head);
 			nftnl_expr_free(expr);
+		}
 		break;
 	case NFTNL_SET_ELEM_OBJREF:
 		xfree(s->objref);
@@ -167,8 +169,10 @@ __nftnl_set_elem_set(struct nftnl_set_elem *s, uint16_t attr, const void *data,
 			return -1;
 		break;
 	case NFTNL_SET_ELEM_EXPR:
-		list_for_each_entry_safe(expr, tmp, &s->expr_list, head)
+		list_for_each_entry_safe(expr, tmp, &s->expr_list, head) {
+			list_del(&expr->head);
 			nftnl_expr_free(expr);
+		}
 
 		expr = (void *)data;
 		list_add(&expr->head, &s->expr_list);
-- 
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 ` [PATCH libftnl 05/12] src: object: don't permit to re-set or clear object type field Florian Westphal
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 ` Florian Westphal [this message]
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-11-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.