Skip to content

Commit d7c3d53

Browse files
David Aherngregkh
authored andcommitted
net: Allow IP_MULTICAST_IF to set index to L3 slave
[ Upstream commit 7bb387c5ab12aeac3d5eea28686489ff46b53ca9 ] IP_MULTICAST_IF fails if sk_bound_dev_if is already set and the new index does not match it. e.g., ntpd[15381]: setsockopt IP_MULTICAST_IF 192.168.1.23 fails: Invalid argument Relax the check in setsockopt to allow setting mc_index to an L3 slave if sk_bound_dev_if points to an L3 master. Make a similar change for IPv6. In this case change the device lookup to take the rcu_read_lock avoiding a refcnt. The rcu lock is also needed for the lookup of a potential L3 master device. This really only silences a setsockopt failure since uses of mc_index are secondary to sk_bound_dev_if if it is set. In both cases, if either index is an L3 slave or master, lookups are directed to the same FIB table so relaxing the check at setsockopt time causes no harm. Patch is based on a suggested change by Darwin for a problem noted in their code base. Suggested-by: Darwin Dingel <darwin.dingel@alliedtelesis.co.nz> Signed-off-by: David Ahern <dsa@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7783955 commit d7c3d53

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

net/ipv4/ip_sockglue.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
808808
{
809809
struct ip_mreqn mreq;
810810
struct net_device *dev = NULL;
811+
int midx;
811812

812813
if (sk->sk_type == SOCK_STREAM)
813814
goto e_inval;
@@ -852,11 +853,15 @@ static int do_ip_setsockopt(struct sock *sk, int level,
852853
err = -EADDRNOTAVAIL;
853854
if (!dev)
854855
break;
856+
857+
midx = l3mdev_master_ifindex(dev);
858+
855859
dev_put(dev);
856860

857861
err = -EINVAL;
858862
if (sk->sk_bound_dev_if &&
859-
mreq.imr_ifindex != sk->sk_bound_dev_if)
863+
mreq.imr_ifindex != sk->sk_bound_dev_if &&
864+
(!midx || midx != sk->sk_bound_dev_if))
860865
break;
861866

862867
inet->mc_index = mreq.imr_ifindex;

net/ipv6/ipv6_sockglue.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,16 +583,24 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
583583

584584
if (val) {
585585
struct net_device *dev;
586+
int midx;
586587

587-
if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != val)
588-
goto e_inval;
588+
rcu_read_lock();
589589

590-
dev = dev_get_by_index(net, val);
590+
dev = dev_get_by_index_rcu(net, val);
591591
if (!dev) {
592+
rcu_read_unlock();
592593
retv = -ENODEV;
593594
break;
594595
}
595-
dev_put(dev);
596+
midx = l3mdev_master_ifindex_rcu(dev);
597+
598+
rcu_read_unlock();
599+
600+
if (sk->sk_bound_dev_if &&
601+
sk->sk_bound_dev_if != val &&
602+
(!midx || midx != sk->sk_bound_dev_if))
603+
goto e_inval;
596604
}
597605
np->mcast_oif = val;
598606
retv = 0;

0 commit comments

Comments
 (0)