Received: by 10.223.185.116 with SMTP id b49csp6418690wrg; Wed, 28 Feb 2018 09:05:13 -0800 (PST) X-Google-Smtp-Source: AG47ELu113Tqc6NsxuoKrwNYTSrak805azMQj0FEaz86p7yNOx27p+G3khbSQPddIT2LiZGbyrEB X-Received: by 10.98.238.2 with SMTP id e2mr10442233pfi.68.1519837513677; Wed, 28 Feb 2018 09:05:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519837513; cv=none; d=google.com; s=arc-20160816; b=Og71udE6l+PK3zZFUhqK+l0Zm1PgxhQdfSvnvjVBXDQ089NPxcUH3zez/Si9z8u/tz 4jcqS6Uts5e6tLDOkH+AEiXpJSuPclJgqjSUFc4pIptNGfiHaUnMfPJEmnzBvvJQNo0r QRGHOoMCHd9bqc4jLTR+kOt7kAJ13BePn6OKMP3FOV6YX9ldkMEyZ82RIsHg43juCZns vrl7LrzIc8kvvX8NSWQB2/kKuImneizhxOIKHz9rnCZtAdQ+c3QRI7Aulh32gQPCtTGk fl6wsr1bvZFTWNoQ2L/Ut0zm1AtkqMXg3piTzHd4yi8mdmi0cORVRkR3zMlNPZ+Zs0cq xFQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=lnri/b9NrEVJvrpxjdq4oTKVorzJYw5G3lpfMjaZKrs=; b=auMsM5c2PQ+ARNX6qw2so0iP8oUeddHCdW/DTcmh1gOBXoBhegS3FFQ2E18d0pNJ3K yXG3JWvQMoJXYHPZimJwyYpT6syk5/Scv2iBa0k9ewE7BcwaBim/5mfkkG8hP5jj8J32 dgR+iEnNuy60JVKfthAUoukxOkyUN1PfHM8j2kSO8Bf4MEdsvRgMeLpf56PVCBjV779K NusUoSJUtT9owM7kyLG4g1NanyTzXwxj/GDGSH40XlR0kSpfS5J2/6+7tRR3E6lFGOsL I1ZxxHvwM6lpeC7sH9zC4Cf4svHozZk94R8TW2HwZy/dzTVyI4VRh2XzxdVLm2KYIb0P hn0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f63si1498873pfb.145.2018.02.28.09.04.40; Wed, 28 Feb 2018 09:05:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933745AbeB1Pvq (ORCPT + 99 others); Wed, 28 Feb 2018 10:51:46 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34347 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933733AbeB1Pvn (ORCPT ); Wed, 28 Feb 2018 10:51:43 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yo-0006XQ-8U; Wed, 28 Feb 2018 15:22:26 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yk-0000Hs-DX; Wed, 28 Feb 2018 15:22:22 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Andrew Lunn" , "Kevin Cernekee" , "David S. Miller" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 223/254] net: igmp: Use correct source address on IGMPv3 reports In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Kevin Cernekee commit a46182b00290839fa3fa159d54fd3237bd8669f0 upstream. Closing a multicast socket after the final IPv4 address is deleted from an interface can generate a membership report that uses the source IP from a different interface. The following test script, run from an isolated netns, reproduces the issue: #!/bin/bash ip link add dummy0 type dummy ip link add dummy1 type dummy ip link set dummy0 up ip link set dummy1 up ip addr add 10.1.1.1/24 dev dummy0 ip addr add 192.168.99.99/24 dev dummy1 tcpdump -U -i dummy0 & socat EXEC:"sleep 2" \ UDP4-DATAGRAM:239.101.1.68:8889,ip-add-membership=239.0.1.68:10.1.1.1 & sleep 1 ip addr del 10.1.1.1/24 dev dummy0 sleep 5 kill %tcpdump RFC 3376 specifies that the report must be sent with a valid IP source address from the destination subnet, or from address 0.0.0.0. Add an extra check to make sure this is the case. Signed-off-by: Kevin Cernekee Reviewed-by: Andrew Lunn Signed-off-by: David S. Miller Signed-off-by: Ben Hutchings --- net/ipv4/igmp.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -89,6 +89,7 @@ #include #include #include +#include #include #include @@ -323,6 +324,23 @@ igmp_scount(struct ip_mc_list *pmc, int return scount; } +/* source address selection per RFC 3376 section 4.2.13 */ +static __be32 igmpv3_get_srcaddr(struct net_device *dev, + const struct flowi4 *fl4) +{ + struct in_device *in_dev = __in_dev_get_rcu(dev); + + if (!in_dev) + return htonl(INADDR_ANY); + + for_ifa(in_dev) { + if (inet_ifa_match(fl4->saddr, ifa)) + return fl4->saddr; + } endfor_ifa(in_dev); + + return htonl(INADDR_ANY); +} + static struct sk_buff *igmpv3_newpack(struct net_device *dev, unsigned int mtu) { struct sk_buff *skb; @@ -370,7 +388,7 @@ static struct sk_buff *igmpv3_newpack(st pip->frag_off = htons(IP_DF); pip->ttl = 1; pip->daddr = fl4.daddr; - pip->saddr = fl4.saddr; + pip->saddr = igmpv3_get_srcaddr(dev, &fl4); pip->protocol = IPPROTO_IGMP; pip->tot_len = 0; /* filled in later */ ip_select_ident(skb, NULL);