Adopting nlmsg_payload() in IPv4/IPv6
Subsystems (3)
cover Adopting nlmsg_payload() in IPv4/IPv6
The commit 95d06e92a4019 ("netlink: Introduce nlmsg_payload helper") introduced the nlmsg_payload() helper function.
This patchset aims to replace manual implementations with the nlmsg_payload() helper in IPv4 and IPv6 files, one file per patch.
---
Breno Leitao (8):
ipv6: Use nlmsg_payload in addrlabel file
ipv6: Use nlmsg_payload in addrconf file
ipv6: Use nlmsg_payload in route file
ipv4: Use nlmsg_payload in devinet file
ipv4: Use nlmsg_payload in fib_frontend file
ipv4: Use nlmsg_payload in route file
ipv4: Use nlmsg_payload in ipmr file
vxlan: Use nlmsg_payload in vxlan_vnifilter_dump
drivers/net/vxlan/vxlan_vnifilter.c | 5 ++--- net/ipv4/devinet.c | 4 ++-- net/ipv4/fib_frontend.c | 4 ++-- net/ipv4/ipmr.c | 8 ++++---- net/ipv4/route.c | 4 ++-- net/ipv6/addrconf.c | 4 ++-- net/ipv6/addrlabel.c | 8 ++++---- net/ipv6/route.c | 4 ++-- 8 files changed, 20 insertions(+), 21 deletions(-)
---
base-commit: 96f8bf85d11acdd3ebc9a91f41cb18eac6f8e26d
change-id: 20250415-nlmsg_v2-204ca5de7791
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
PATCH 1/8 ipv6: Use nlmsg_payload in addrlabel file
Leverage the new nlmsg_payload() helper to avoid checking for message size and then reading the nlmsg data.
This changes function ip6addrlbl_valid_get_req() and ip6addrlbl_valid_dump_req().
--- net/ipv6/addrlabel.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/ipv6/addrlabel.c +4 -4
@@ -473,12 +473,12 @@ static int ip6addrlbl_valid_dump_req(const struct nlmsghdr *nlh, {struct ifaddrlblmsg *ifal; -if (nlh->nlmsg_len <nlmsg_msg_size (sizeof (*ifal))) { + ifal =nlmsg_payload (nlh,sizeof (*ifal)); +if (!ifal) {NL_SET_ERR_MSG_MOD (extack,"Invalid header for address label dump request" );return -EINVAL ; } - ifal =nlmsg_data (nlh);if (ifal->__ifal_reserved || ifal->ifal_prefixlen || ifal->ifal_flags || ifal->ifal_index || ifal->ifal_seq) {NL_SET_ERR_MSG_MOD (extack,"Invalid values in header for address label dump request" );
@@ -543,7 +543,8 @@ static int ip6addrlbl_valid_get_req(struct sk_buff *skb,struct ifaddrlblmsg *ifal;int i, err; -if (nlh->nlmsg_len <nlmsg_msg_size (sizeof (*ifal))) { + ifal =nlmsg_payload (nlh,sizeof (*ifal)); +if (!ifal) {NL_SET_ERR_MSG_MOD (extack,"Invalid header for addrlabel get request" );return -EINVAL ; }
@@ -552,7 +553,6 @@ static int ip6addrlbl_valid_get_req(struct sk_buff *skb,return nlmsg_parse_deprecated (nlh,sizeof (*ifal), tb,IFAL_MAX , ifal_policy, extack); - ifal =nlmsg_data (nlh);if (ifal->__ifal_reserved || ifal->ifal_flags || ifal->ifal_seq) {NL_SET_ERR_MSG_MOD (extack,"Invalid values in header for addrlabel get request" );return -EINVAL ;
Signature · 1 line
2.47.1
Re: [PATCH net-next 1/8] ipv6: Use nlmsg_payload in addrlabel file
From: Breno Leitao <[email protected]>
Date: Tue, 15 Apr 2025 12:28:52 -0700
Quoted 7 lines
Leverage the new
nlmsg_payload()helper to avoid checking for message size and then reading the nlmsg data.This changes function
ip6addrlbl_valid_get_req()andip6addrlbl_valid_dump_req().Signed-off-by Breno Leitao <[email protected]>
PATCH 2/8 ipv6: Use nlmsg_payload in addrconf file
In reply to Breno LeitaoLeverage the new nlmsg_payload() helper to avoid checking for message size and then reading the nlmsg data.
--- net/ipv6/addrconf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv6/addrconf.c +2 -2
@@ -6112,7 +6112,8 @@ static int inet6_valid_dump_ifinfo(const struct nlmsghdr *nlh, {struct ifinfomsg *ifm; -if (nlh->nlmsg_len <nlmsg_msg_size (sizeof (*ifm))) { + ifm =nlmsg_payload (nlh,sizeof (*ifm)); +if (!ifm) {NL_SET_ERR_MSG_MOD (extack,"Invalid header for link dump request" );return -EINVAL ; }
@@ -6122,7 +6123,6 @@ static int inet6_valid_dump_ifinfo(const struct nlmsghdr *nlh,return -EINVAL ; } - ifm =nlmsg_data (nlh);if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags || ifm->ifi_change || ifm->ifi_index) {NL_SET_ERR_MSG_MOD (extack,"Invalid values in header for dump request" );
Signature · 1 line
2.47.1
Re: [PATCH net-next 2/8] ipv6: Use nlmsg_payload in addrconf file
From: Breno Leitao <[email protected]>
Date: Tue, 15 Apr 2025 12:28:53 -0700
Quoted 4 lines
Leverage the new
nlmsg_payload()helper to avoid checking for message size and then reading the nlmsg data.Signed-off-by Breno Leitao <[email protected]>
PATCH 3/8 ipv6: Use nlmsg_payload in route file
In reply to Breno LeitaoLeverage the new nlmsg_payload() helper to avoid checking for message size and then reading the nlmsg data.
--- net/ipv6/route.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv6/route.c +2 -2
@@ -6029,7 +6029,8 @@ static int inet6_rtm_valid_getroute_req(struct sk_buff *skb,struct rtmsg *rtm;int i, err; -if (nlh->nlmsg_len <nlmsg_msg_size (sizeof (*rtm))) { + rtm =nlmsg_payload (nlh,sizeof (*rtm)); +if (!rtm) {NL_SET_ERR_MSG_MOD (extack,"Invalid header for get route request" );return -EINVAL ;
@@ -6039,7 +6040,6 @@ static int inet6_rtm_valid_getroute_req(struct sk_buff *skb,return nlmsg_parse_deprecated (nlh,sizeof (*rtm), tb,RTA_MAX , rtm_ipv6_policy, extack); - rtm =nlmsg_data (nlh); if ((rtm->rtm_src_len && rtm->rtm_src_len != 128) || (rtm->rtm_dst_len && rtm->rtm_dst_len != 128) || rtm->rtm_table || rtm->rtm_protocol || rtm->rtm_scope ||
Signature · 1 line
2.47.1
Re: [PATCH net-next 3/8] ipv6: Use nlmsg_payload in route file
From: Breno Leitao <[email protected]>
Date: Tue, 15 Apr 2025 12:28:54 -0700
Quoted 4 lines
Leverage the new
nlmsg_payload()helper to avoid checking for message size and then reading the nlmsg data.Signed-off-by Breno Leitao <[email protected]>
PATCH 4/8 ipv4: Use nlmsg_payload in devinet file
In reply to Breno LeitaoLeverage the new nlmsg_payload() helper to avoid checking for message size and then reading the nlmsg data.
--- net/ipv4/devinet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/devinet.c +2 -2
@@ -1792,12 +1792,12 @@ static int inet_valid_dump_ifaddr_req(const struct nlmsghdr *nlh,struct ifaddrmsg *ifm;int err, i; -if (nlh->nlmsg_len <nlmsg_msg_size (sizeof (*ifm))) { + ifm =nlmsg_payload (nlh,sizeof (*ifm)); +if (!ifm) {NL_SET_ERR_MSG (extack,"ipv4: Invalid header for address dump request" );return -EINVAL ; } - ifm =nlmsg_data (nlh);if (ifm->ifa_prefixlen || ifm->ifa_flags || ifm->ifa_scope) {NL_SET_ERR_MSG (extack,"ipv4: Invalid values in header for address dump request" );return -EINVAL ;
Signature · 1 line
2.47.1
Re: [PATCH net-next 4/8] ipv4: Use nlmsg_payload in devinet file
From: Breno Leitao <[email protected]>
Date: Tue, 15 Apr 2025 12:28:55 -0700
Quoted 4 lines
Leverage the new
nlmsg_payload()helper to avoid checking for message size and then reading the nlmsg data.Signed-off-by Breno Leitao <[email protected]>
PATCH 5/8 ipv4: Use nlmsg_payload in fib_frontend file
In reply to Breno LeitaoLeverage the new nlmsg_payload() helper to avoid checking for message size and then reading the nlmsg data.
--- net/ipv4/fib_frontend.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/fib_frontend.c +2 -2
@@ -948,12 +948,12 @@ int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,if (filter->rtnl_held)ASSERT_RTNL (); -if (nlh->nlmsg_len <nlmsg_msg_size (sizeof (*rtm))) { + rtm =nlmsg_payload (nlh,sizeof (*rtm)); +if (!rtm) {NL_SET_ERR_MSG (extack,"Invalid header for FIB dump request" );return -EINVAL ; } - rtm =nlmsg_data (nlh);if (rtm->rtm_dst_len || rtm->rtm_src_len || rtm->rtm_tos || rtm->rtm_scope) {NL_SET_ERR_MSG (extack,"Invalid values in header for FIB dump request" );
Signature · 1 line
2.47.1
Re: [PATCH net-next 5/8] ipv4: Use nlmsg_payload in fib_frontend file
From: Breno Leitao <[email protected]>
Date: Tue, 15 Apr 2025 12:28:56 -0700
Quoted 4 lines
Leverage the new
nlmsg_payload()helper to avoid checking for message size and then reading the nlmsg data.Signed-off-by Breno Leitao <[email protected]>
PATCH 6/8 ipv4: Use nlmsg_payload in route file
In reply to Breno LeitaoLeverage the new nlmsg_payload() helper to avoid checking for message size and then reading the nlmsg data.
--- net/ipv4/route.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/route.c +2 -2
@@ -3205,7 +3205,8 @@ static int inet_rtm_valid_getroute_req(struct sk_buff *skb,struct rtmsg *rtm;int i, err; -if (nlh->nlmsg_len <nlmsg_msg_size (sizeof (*rtm))) { + rtm =nlmsg_payload (nlh,sizeof (*rtm)); +if (!rtm) {NL_SET_ERR_MSG (extack,"ipv4: Invalid header for route get request" );return -EINVAL ;
@@ -3215,7 +3216,6 @@ static int inet_rtm_valid_getroute_req(struct sk_buff *skb,return nlmsg_parse_deprecated (nlh,sizeof (*rtm), tb,RTA_MAX , rtm_ipv4_policy, extack); - rtm =nlmsg_data (nlh); if ((rtm->rtm_src_len && rtm->rtm_src_len != 32) || (rtm->rtm_dst_len && rtm->rtm_dst_len != 32) || rtm->rtm_table || rtm->rtm_protocol ||
Signature · 1 line
2.47.1
Re: [PATCH net-next 6/8] ipv4: Use nlmsg_payload in route file
From: Breno Leitao <[email protected]>
Date: Tue, 15 Apr 2025 12:28:57 -0700
Quoted 4 lines
Leverage the new
nlmsg_payload()helper to avoid checking for message size and then reading the nlmsg data.Signed-off-by Breno Leitao <[email protected]>
PATCH 7/8 ipv4: Use nlmsg_payload in ipmr file
In reply to Breno LeitaoLeverage the new nlmsg_payload() helper to avoid checking for message size and then reading the nlmsg data.
--- net/ipv4/ipmr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/ipv4/ipmr.c +4 -4
@@ -2511,7 +2511,8 @@ static int ipmr_rtm_valid_getroute_req(struct sk_buff *skb,struct rtmsg *rtm;int i, err; -if (nlh->nlmsg_len <nlmsg_msg_size (sizeof (*rtm))) { + rtm =nlmsg_payload (nlh,sizeof (*rtm)); +if (!rtm) {NL_SET_ERR_MSG (extack,"ipv4: Invalid header for multicast route get request" );return -EINVAL ; }
@@ -2520,7 +2521,6 @@ static int ipmr_rtm_valid_getroute_req(struct sk_buff *skb,return nlmsg_parse_deprecated (nlh,sizeof (*rtm), tb,RTA_MAX , rtm_ipv4_policy, extack); - rtm =nlmsg_data (nlh); if ((rtm->rtm_src_len && rtm->rtm_src_len != 32) || (rtm->rtm_dst_len && rtm->rtm_dst_len != 32) || rtm->rtm_tos || rtm->rtm_table || rtm->rtm_protocol ||
@@ -2836,7 +2836,8 @@ static int ipmr_valid_dumplink(const struct nlmsghdr *nlh, {struct ifinfomsg *ifm; -if (nlh->nlmsg_len <nlmsg_msg_size (sizeof (*ifm))) { + ifm =nlmsg_payload (nlh,sizeof (*ifm)); +if (!ifm) {NL_SET_ERR_MSG (extack,"ipv4: Invalid header for ipmr link dump" );return -EINVAL ; }
@@ -2846,7 +2847,6 @@ static int ipmr_valid_dumplink(const struct nlmsghdr *nlh,return -EINVAL ; } - ifm =nlmsg_data (nlh);if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags || ifm->ifi_change || ifm->ifi_index) {NL_SET_ERR_MSG (extack,"Invalid values in header for ipmr link dump request" );
Signature · 1 line
2.47.1
Re: [PATCH net-next 7/8] ipv4: Use nlmsg_payload in ipmr file
From: Breno Leitao <[email protected]>
Date: Tue, 15 Apr 2025 12:28:58 -0700
Quoted 4 lines
Leverage the new
nlmsg_payload()helper to avoid checking for message size and then reading the nlmsg data.Signed-off-by Breno Leitao <[email protected]>
PATCH 8/8 vxlan: Use nlmsg_payload in vxlan_vnifilter_dump
In reply to Breno LeitaoLeverage the new nlmsg_payload() helper to avoid checking for message size and then reading the nlmsg data.
--- drivers/net/vxlan/vxlan_vnifilter.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/vxlan/vxlan_vnifilter.c +2 -3
@@ -411,13 +411,12 @@ static int vxlan_vnifilter_dump(struct sk_buff *skb, struct netlink_callback *cbstruct tunnel_msg *tmsg;struct net_device *dev; -if (cb->nlh->nlmsg_len <nlmsg_msg_size (sizeof (struct tunnel_msg ))) { + tmsg =nlmsg_payload (cb->nlh,sizeof (*tmsg)); +if (!tmsg) {NL_SET_ERR_MSG (cb->extack,"Invalid msg length" );return -EINVAL ; } - tmsg =nlmsg_data (cb->nlh); -if (tmsg->flags & ~TUNNEL_MSG_VALID_USER_FLAGS ) {NL_SET_ERR_MSG (cb->extack,"Invalid tunnelmsg flags in ancillary header" );return -EINVAL ;
Signature · 1 line
2.47.1
Re: [PATCH net-next 8/8] vxlan: Use nlmsg_payload in vxlan_vnifilter_dump
From: Breno Leitao <[email protected]>
Date: Tue, 15 Apr 2025 12:28:59 -0700
Quoted 4 lines
Leverage the new
nlmsg_payload()helper to avoid checking for message size and then reading the nlmsg data.Signed-off-by Breno Leitao <[email protected]>
Just grepped nlmsg_msg_size() and looks like the next series is last :)
neigh_valid_dump_reqrtnl_valid_dump_ifinfo_reqrtnl_valid_getlink_reqvalid_fdb_get_strictvalid_bridge_getlink_reqrtnl_valid_stats_reqrtnl_mdb_valid_dump_req
Re: [PATCH net-next 8/8] vxlan: Use nlmsg_payload in vxlan_vnifilter_dump
Hello Kuniyuki,
Quoted 11 lines · Kuniyuki Iwashima
From: Breno Leitao <[email protected]>
Date: Tue, 15 Apr 2025 12:28:59 -0700Quoted 4 lines
Leverage the new
nlmsg_payload()helper to avoid checking for message size and then reading the nlmsg data.Signed-off-by Breno Leitao <[email protected]>Reviewed-by Kuniyuki Iwashima <[email protected]>Just grepped
nlmsg_msg_size()and looks like the next series is last :)
Quoted 7 lines
neigh_valid_dump_reqrtnl_valid_dump_ifinfo_reqrtnl_valid_getlink_reqvalid_fdb_get_strictvalid_bridge_getlink_reqrtnl_valid_stats_reqrtnl_mdb_valid_dump_req
Right, that matches my list as well.
Thanks for all this review,
--breno
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Tue, 15 Apr 2025 12:28:51 -0700 you wrote:
The commit
95d06e92a4019("netlink: Introducenlmsg_payloadhelper") introduced thenlmsg_payload()helper function.This patchset aims to replace manual implementations with the
nlmsg_payload()helper in IPv4 and IPv6 files, one file per patch.Signed-off-by Breno Leitao <[email protected]>[...]
Here is the summary with links:
- [net-next,1/8] ipv6: Use nlmsg_payload in addrlabel file
https://git.kernel.org/netdev/net-next/c/5ef4097ed155 - [net-next,2/8] ipv6: Use nlmsg_payload in addrconf file https://git.kernel.org/netdev/net-next/c/6c454270a851 - [net-next,3/8] ipv6: Use nlmsg_payload in route file https://git.kernel.org/netdev/net-next/c/bc05add844fc - [net-next,4/8] ipv4: Use nlmsg_payload in devinet file https://git.kernel.org/netdev/net-next/c/7d82cc229c09 - [net-next,5/8] ipv4: Use nlmsg_payload in fib_frontend file https://git.kernel.org/netdev/net-next/c/b411638fb925 - [net-next,6/8] ipv4: Use nlmsg_payload in route file https://git.kernel.org/netdev/net-next/c/d5ce0ed528c4 - [net-next,7/8] ipv4: Use nlmsg_payload in ipmr file https://git.kernel.org/netdev/net-next/c/04e00a849e7c - [net-next,8/8] vxlan: Use nlmsg_payload in vxlan_vnifilter_dump https://git.kernel.org/netdev/net-next/c/9b1097a4108f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html