ipv6: invert join/leave anycast rtnl/socket locking order
Subsystems (3)
PATCH 1/1 ipv6: invert join/leave anycast rtnl/socket locking order
Commit baf606d9c9b1 ("ipv4,ipv6: grab rtnl before locking the socket") missed to update two setsockopt options, IPV6_JOIN_ANYCAST and IPV6_LEAVE_ANYCAST, causing a lock inverstion regarding the updated ones.
As ipv6_sock_ac_join and ipv6_sock_ac_leave are only called from do_ipv6_setsockopt, we are good to just move the rtnl lock upper.
--- net/ipv6/anycast.c | 9 ++++----- net/ipv6/ipv6_sockglue.c | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-)
net/ipv6/anycast.c +4 -5
@@ -60,6 +60,8 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr)int ishost = !net->ipv6.devconf_all->forwarding;int err =0 ; +ASSERT_RTNL (); +if (!ns_capable (net->user_ns,CAP_NET_ADMIN ))return -EPERM ;if (ipv6_addr_is_multicast (addr))
@@ -73,7 +75,6 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr) pac->acl_next =NULL ; pac->acl_addr = *addr; -rtnl_lock ();if (ifindex ==0 ) {struct rt6_info *rt;
@@ -130,7 +131,6 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr) } error: -rtnl_unlock ();if (pac)sock_kfree_s (sk, pac,sizeof (*pac));return err;
@@ -146,7 +146,8 @@ int ipv6_sock_ac_drop(struct sock *sk, int ifindex, const struct in6_addr *addr)struct ipv6_ac_socklist *pac, *prev_pac;struct net *net =sock_net (sk); -rtnl_lock (); +ASSERT_RTNL (); + prev_pac =NULL ;for (pac = np->ipv6_ac_list; pac; pac = pac->acl_next) { if ((ifindex == 0 || pac->acl_ifindex == ifindex) &&
@@ -155,7 +156,6 @@ int ipv6_sock_ac_drop(struct sock *sk, int ifindex, const struct in6_addr *addr) prev_pac = pac; }if (!pac) { -rtnl_unlock ();return -ENOENT ; }if (prev_pac)
@@ -166,7 +166,6 @@ int ipv6_sock_ac_drop(struct sock *sk, int ifindex, const struct in6_addr *addr) dev =__dev_get_by_index (net, pac->acl_ifindex);if (dev)ipv6_dev_ac_dec (dev, &pac->acl_addr); -rtnl_unlock ();sock_kfree_s (sk, pac,sizeof (*pac));return 0 ;
net/ipv6/ipv6_sockglue.c +2 -0
@@ -122,6 +122,8 @@ static bool setsockopt_needs_rtnl(int optname)switch (optname) {case IPV6_ADD_MEMBERSHIP :case IPV6_DROP_MEMBERSHIP : +case IPV6_JOIN_ANYCAST : +case IPV6_LEAVE_ANYCAST :case MCAST_JOIN_GROUP :case MCAST_LEAVE_GROUP :case MCAST_JOIN_SOURCE_GROUP :
Signature · 1 line
2.1.0
Hello.
Quoted 19 lines · Marcelo Ricardo Leitner
Commit
baf606d9c9b1("ipv4,ipv6: grab rtnl before locking the socket") missed to update two setsockopt options,IPV6_JOIN_ANYCASTandIPV6_LEAVE_ANYCAST, causing a lock inverstion regarding the updated ones.As
ipv6_sock_ac_joinandipv6_sock_ac_leaveare only called fromdo_ipv6_setsockopt, we are good to just move the rtnl lock upper.Fixes baf606d9c9b1 ("ipv4,ipv6: grab rtnl before locking the socket")Reported-by Ying Huang <[email protected]>Signed-off-by Marcelo Ricardo Leitner <[email protected]>--- net/ipv6/anycast.c | 9 ++++----- net/ipv6/ipv6_sockglue.c | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-)net/ipv6/anycast.c +0
-0
[...]
net/ipv6/anycast.c int ipv6_sock_ac_drop(struct sock *sk, int ifindex, const struct in6_addr *addr) · line 160
Quoted 7 lines
net/ipv6/anycast.c +0
-1@@ -155,7 +156,6 @@ int ipv6_sock_ac_drop(struct sock *sk, int ifindex, const struct in6_addr *addr) prev_pac = pac; }if (!pac) { -rtnl_unlock ();return -ENOENT ; }
Get rid of {} please, as they're not needed anymore.
[...]
WBR, Sergei
PATCH v2 1/1 ipv6: invert join/leave anycast rtnl/socket locking order
Commit baf606d9c9b1 ("ipv4,ipv6: grab rtnl before locking the socket") missed to update two setsockopt options, IPV6_JOIN_ANYCAST and IPV6_LEAVE_ANYCAST, causing a lock inverstion regarding to the updated ones.
As ipv6_sock_ac_join and ipv6_sock_ac_leave are only called from do_ipv6_setsockopt, we are good to just move the rtnl lock upper.
---
Notes:
v2:
removed {} that aren't needed anymore, as pointed by Sergei
net/ipv6/anycast.c | 12 +++++------- net/ipv6/ipv6_sockglue.c | 2 ++ 2 files changed, 7 insertions(+), 7 deletions(-)
net/ipv6/anycast.c +5 -7
@@ -60,6 +60,8 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr)int ishost = !net->ipv6.devconf_all->forwarding;int err =0 ; +ASSERT_RTNL (); +if (!ns_capable (net->user_ns,CAP_NET_ADMIN ))return -EPERM ;if (ipv6_addr_is_multicast (addr))
@@ -73,7 +75,6 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr) pac->acl_next =NULL ; pac->acl_addr = *addr; -rtnl_lock ();if (ifindex ==0 ) {struct rt6_info *rt;
@@ -130,7 +131,6 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr) } error: -rtnl_unlock ();if (pac)sock_kfree_s (sk, pac,sizeof (*pac));return err;
@@ -146,7 +146,8 @@ int ipv6_sock_ac_drop(struct sock *sk, int ifindex, const struct in6_addr *addr)struct ipv6_ac_socklist *pac, *prev_pac;struct net *net =sock_net (sk); -rtnl_lock (); +ASSERT_RTNL (); + prev_pac =NULL ;for (pac = np->ipv6_ac_list; pac; pac = pac->acl_next) { if ((ifindex == 0 || pac->acl_ifindex == ifindex) &&
@@ -154,10 +155,8 @@ int ipv6_sock_ac_drop(struct sock *sk, int ifindex, const struct in6_addr *addr)break ; prev_pac = pac; } -if (!pac) { -rtnl_unlock (); +if (!pac)return -ENOENT ; - }if (prev_pac) prev_pac->acl_next = pac->acl_next;else
@@ -166,7 +165,6 @@ int ipv6_sock_ac_drop(struct sock *sk, int ifindex, const struct in6_addr *addr) dev =__dev_get_by_index (net, pac->acl_ifindex);if (dev)ipv6_dev_ac_dec (dev, &pac->acl_addr); -rtnl_unlock ();sock_kfree_s (sk, pac,sizeof (*pac));return 0 ;
net/ipv6/ipv6_sockglue.c +2 -0
@@ -122,6 +122,8 @@ static bool setsockopt_needs_rtnl(int optname)switch (optname) {case IPV6_ADD_MEMBERSHIP :case IPV6_DROP_MEMBERSHIP : +case IPV6_JOIN_ANYCAST : +case IPV6_LEAVE_ANYCAST :case MCAST_JOIN_GROUP :case MCAST_LEAVE_GROUP :case MCAST_JOIN_SOURCE_GROUP :
Signature · 1 line
2.1.0
From: Marcelo Ricardo Leitner <[email protected]>
Date: Fri, 20 Mar 2015 11:37:17 -0300
Quoted 10 lines
Commit
baf606d9c9b1("ipv4,ipv6: grab rtnl before locking the socket") missed to update two setsockopt options,IPV6_JOIN_ANYCASTandIPV6_LEAVE_ANYCAST, causing a lock inverstion regarding to the updated ones.As
ipv6_sock_ac_joinandipv6_sock_ac_leaveare only called fromdo_ipv6_setsockopt, we are good to just move the rtnl lock upper.Fixes baf606d9c9b1 ("ipv4,ipv6: grab rtnl before locking the socket")Reported-by Ying Huang <[email protected]>Signed-off-by Marcelo Ricardo Leitner <[email protected]>
Applied, thank you.