net: mctp: Don't access ifa_index when missing
Matt Johnston
maintainerPATCH v2 1/1 net: mctp: Don't access ifa_index when missing
In mctp_dump_addrinfo, ifa_index can be used to filter interfaces, but only when the struct ifaddrmsg is provided. Otherwise it will be comparing to uninitialised memory - reproducible in the syzkaller case from dhcpd, or busybox "ip addr show".
The kernel MCTP implementation has always filtered by ifa_index, so existing userspace programs expecting to dump MCTP addresses must already be passing a valid ifa_index value (either 0 or a real index).
BUG: KMSAN: uninit-value in mctp_dump_addrinfo+0x208/0xac0 net/mctp/device.c:128 mctp_dump_addrinfo+0x208/0xac0 net/mctp/device.c:128 rtnl_dump_all+0x3ec/0x5b0 net/core/rtnetlink.c:4380 rtnl_dumpit+0xd5/0x2f0 net/core/rtnetlink.c:6824 netlink_dump+0x97b/0x1690 net/netlink/af_netlink.c:2309
---
Changes in v2:
- Don't test for ifa_family=AF_MCTP
- Fail if strict_check is set and header is short
- Link to v1: https://lore.kernel.org/r/[email protected]
--- net/mctp/device.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
net/mctp/device.c +11 -4
@@ -117,11 +117,18 @@ static int mctp_dump_addrinfo(struct sk_buff *skb, struct netlink_callback *cb)struct net_device *dev;struct ifaddrmsg *hdr;struct mctp_dev *mdev; -int ifindex, rc; +int ifindex =0 , rc; - hdr =nlmsg_data (cb->nlh); -// filter by ifindex if requested - ifindex = hdr->ifa_index; +/* Filter by ifindex if a header is provided */ +if (cb->nlh->nlmsg_len >=nlmsg_msg_size (sizeof (*hdr))) { + hdr =nlmsg_data (cb->nlh); + ifindex = hdr->ifa_index; + }else { +if (cb->strict_check) { +NL_SET_ERR_MSG (cb->extack,"mctp: Invalid header for addr dump request" ); +return -EINVAL ; + } + }rcu_read_lock ();for_each_netdev_dump (net, dev, mcb->ifindex) {
---
base-commit: ebd297a2affadb6f6f4d2e5d975c1eda18ac762d
change-id: 20250505-mctp-addr-dump-673e0fdc7894
Best regards,
Signature · 1 line
Matt Johnston <[email protected]>
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Thu, 08 May 2025 13:18:32 +0800 you wrote:
In
mctp_dump_addrinfo,ifa_indexcan be used to filter interfaces, but only when the struct ifaddrmsg is provided. Otherwise it will be comparing to uninitialised memory - reproducible in the syzkaller case from dhcpd, or busybox "ip addr show".The kernel MCTP implementation has always filtered by
ifa_index, so existing userspace programs expecting to dump MCTP addresses must already be passing a validifa_indexvalue (either 0 or a real index).[...]
Here is the summary with links:
- [net,v2] net: mctp: Don't access ifa_index when missing
https://git.kernel.org/netdev/net/c/f11cf946c0a9
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html