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 --- 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 #include #include #include #include #include #include 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