From 2b520a7489abb510c1b0fbe4a5da3d9c5a4e6b8a Mon Sep 17 00:00:00 2001 From: Guoxin Pu Date: Fri, 12 Jun 2026 16:59:39 +0800 Subject: [PATCH] rtnetlink: provide permanent hardware address in RTM_NEWLINK Backport upstream commit f74877a5457d34d604dba6dbbb13c4c05bac8b93: rtnetlink: provide permanent hardware address in RTM_NEWLINK Permanent hardware address of a network device was traditionally provided via ethtool ioctl. Expose it in RTM_NEWLINK as IFLA_PERM_ADDRESS when dev->perm_addr is not all zeros, and reject attempts to set the attribute from userspace. This 4.19 tree does not have NLA_REJECT, so reject IFLA_PERM_ADDRESS explicitly from validate_linkmsg(). Backport motivation: systemd v255 matches PermanentMACAddress= by first reading IFLA_PERM_ADDRESS and falling back to ETHTOOL_GPERMADDR. On stmmac platform devices, the ethtool fallback can fail during .link processing because the interface is not yet running and stmmac_ethtool_ops.begin returns -EBUSY. Providing the permanent address through rtnetlink makes the match work before networkd brings the interface up. Signed-off-by: Guoxin Pu --- include/uapi/linux/if_link.h | 1 + net/core/rtnetlink.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 43391e2d115..2b0b3131619 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -166,6 +166,7 @@ enum { IFLA_NEW_IFINDEX, IFLA_MIN_MTU, IFLA_MAX_MTU, + IFLA_PERM_ADDRESS, __IFLA_MAX }; diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 2837cc03f69..191440ac68f 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1027,6 +1027,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, + nla_total_size(4) /* IFLA_CARRIER_DOWN_COUNT */ + nla_total_size(4) /* IFLA_MIN_MTU */ + nla_total_size(4) /* IFLA_MAX_MTU */ + + nla_total_size(MAX_ADDR_LEN) /* IFLA_PERM_ADDRESS */ + 0; } @@ -1657,6 +1658,10 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, goto nla_put_failure; } + if (memchr_inv(dev->perm_addr, '\0', dev->addr_len) && + nla_put(skb, IFLA_PERM_ADDRESS, dev->addr_len, dev->perm_addr)) + goto nla_put_failure; + if (rtnl_phys_port_id_fill(skb, dev)) goto nla_put_failure; @@ -2074,6 +2079,9 @@ static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[]) return -EINVAL; } + if (tb[IFLA_PERM_ADDRESS]) + return -EINVAL; + if (tb[IFLA_AF_SPEC]) { struct nlattr *af; int rem, err; -- Gitee