From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH libftnl 03/12] src: move several MNL_STRING types to MNL_NUL_STRING
Date: Wed, 28 Oct 2026 15:56:23 +0100 [thread overview]
Message-ID: <20261028145632.7089-4-fw@strlen.de> (raw)
In-Reply-To: <20261028145632.7089-1-fw@strlen.de>
LLM finding:
mnl_attr_get_str() returns a pointer into a fixed-length TLV payload with
no guaranteed NUL terminator.
This is the classic 'NLA_STRING' vs. 'NUL_STRING'.
libmnl only checks for terminating NUL when asked to validate a
NUL_STRING attribute. As we parse nf_tables data coming from kernel,
we can actually rely on the kernel including the terminating NUL
character for us, even for NLA_STRING.
Just switch those affected attributes (strdup() after
mnl_attr_validate(... MNL_STRING) to MNL_NUL_STRING.
This doesn't break any existing users, closes the finding and
hardens future users that might parse netlink attributes coming
from a different source than the kernel.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
src/chain.c | 2 +-
src/expr/data_reg.c | 2 +-
src/set.c | 2 +-
src/utils.c | 5 +++--
4 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/chain.c b/src/chain.c
index 13b0231ee345..c72505c22e17 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -613,7 +613,7 @@ static int nftnl_chain_parse_hook_cb(const struct nlattr *attr, void *data)
abi_breakage();
break;
case NFTA_HOOK_DEV:
- if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0)
+ if (mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
abi_breakage();
break;
}
diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c
index 0a1c0bdee6c2..e38e493f0592 100644
--- a/src/expr/data_reg.c
+++ b/src/expr/data_reg.c
@@ -155,7 +155,7 @@ static int nftnl_verdict_parse_cb(const struct nlattr *attr, void *data)
abi_breakage();
break;
case NFTA_VERDICT_CHAIN:
- if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0)
+ if (mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
abi_breakage();
break;
}
diff --git a/src/set.c b/src/set.c
index f7b0526253ff..22fd4a839f80 100644
--- a/src/set.c
+++ b/src/set.c
@@ -491,7 +491,7 @@ static int nftnl_set_parse_attr_cb(const struct nlattr *attr, void *data)
case NFTA_SET_TABLE:
case NFTA_SET_NAME:
case NFTA_SET_TYPE:
- if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0)
+ if (mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
abi_breakage();
break;
case NFTA_SET_HANDLE:
diff --git a/src/utils.c b/src/utils.c
index f7d035baa3ae..95a252ed44f3 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -200,14 +200,15 @@ void nftnl_attr_put_ifname(struct nlmsghdr *nlh, const char *ifname)
char *nftnl_attr_get_ifname(const struct nlattr *attr)
{
+ uint16_t dlen = mnl_attr_get_payload_len(attr);
const char *dev = mnl_attr_get_str(attr);
char buf[IFNAMSIZ];
switch (mnl_attr_get_type(attr)) {
case NFTA_DEVICE_NAME:
- return strdup(dev);
+ return strndup(dev, dlen);
case NFTA_DEVICE_PREFIX:
- snprintf(buf, IFNAMSIZ, "%s*", dev);
+ snprintf(buf, IFNAMSIZ, "%.*s*", (int)dlen, dev);
return strdup(buf);
default:
return NULL;
--
2.55.0
next prev 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 ` Florian Westphal [this message]
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 ` [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-4-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.