From patchwork Mon Jun 1 16:34:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Bohrer X-Patchwork-Id: 479110 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id B52651412E5 for ; Tue, 2 Jun 2015 02:35:01 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=mtxkBqxb; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752912AbbFAQe5 (ORCPT ); Mon, 1 Jun 2015 12:34:57 -0400 Received: from mail-oi0-f48.google.com ([209.85.218.48]:34651 "EHLO mail-oi0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752717AbbFAQez (ORCPT ); Mon, 1 Jun 2015 12:34:55 -0400 Received: by oifu123 with SMTP id u123so105782294oif.1 for ; Mon, 01 Jun 2015 09:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=K4uTtETXW0denWHrGAE44KvRWR13mXQwa0z9peeXcW4=; b=mtxkBqxbR/EfDklCCk9lhbqgCmgA4EfjGcbsJQgbuJADAv4MZnIy9cShvWzZU2hE1c q/ZTENBMqXU9OQMnZEowjDMvf/eyQF/6hD5RzF38aCm8QwoQMmg+hTLP/ChGxTRYwSTM V8M3TGR3pDN2VU/FmRFQx9K6fkPKCg5sCr9rFflglA50KkHxlWZWbCwDgptj/2kUFHh3 IwzG7McULS9KcgGQyyRTM1IFmeUWhU2MKdmNLwyCW8lMw4QB8E/e4ttc2PapueaG2UFs 0eDs1zytZnQZtVAtDkrfzJ4KJvSJJ5rmhuwo8TdMSKm5ZQr8g7fNlpWqBZaXpinaLwPO PIgg== X-Received: by 10.182.58.81 with SMTP id o17mr8736321obq.76.1433176495324; Mon, 01 Jun 2015 09:34:55 -0700 (PDT) Received: from sbohrermbp13-local.rgmadvisors.com ([173.227.92.65]) by mx.google.com with ESMTPSA id h195sm7891702oig.1.2015.06.01.09.34.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Jun 2015 09:34:54 -0700 (PDT) From: Shawn Bohrer To: netdev@vger.kernel.org Cc: "Yurij M. Plotnikov" , Alexandra.Kossovsky@oktetlabs.ru, Eric Dumazet , Oliver Graff , davem@davemloft.net, Shawn Bohrer Subject: [PATCH] ipv4/udp: Verify multicast group is ours in upd_v4_early_demux() Date: Mon, 1 Jun 2015 11:34:25 -0500 Message-Id: <1433176465-22941-1-git-send-email-shawn.bohrer@gmail.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1432663193.4060.280.camel@edumazet-glaptop2.roam.corp.google.com> References: <1432663193.4060.280.camel@edumazet-glaptop2.roam.corp.google.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Shawn Bohrer 421b3885bf6d56391297844f43fb7154a6396e12 "udp: ipv4: Add udp early demux" introduced a regression that allowed sockets bound to INADDR_ANY to receive packets from multicast groups that the socket had not joined. For example a socket that had joined 224.168.2.9 could also receive packets from 225.168.2.9 despite not having joined that group if ip_early_demux is enabled. Fix this by calling ip_check_mc_rcu() in udp_v4_early_demux() to verify that the multicast packet is indeed ours. Signed-off-by: Shawn Bohrer Reported-by: Yurij M. Plotnikov --- net/ipv4/udp.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index d10b7e0..17d31f5 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -90,6 +90,7 @@ #include #include #include +#include #include #include #include @@ -1959,7 +1960,7 @@ void udp_v4_early_demux(struct sk_buff *skb) struct net *net = dev_net(skb->dev); const struct iphdr *iph; const struct udphdr *uh; - struct sock *sk; + struct sock *sk = NULL; struct dst_entry *dst; int dif = skb->dev->ifindex; @@ -1971,10 +1972,17 @@ void udp_v4_early_demux(struct sk_buff *skb) uh = udp_hdr(skb); if (skb->pkt_type == PACKET_BROADCAST || - skb->pkt_type == PACKET_MULTICAST) - sk = __udp4_lib_mcast_demux_lookup(net, uh->dest, iph->daddr, - uh->source, iph->saddr, dif); - else if (skb->pkt_type == PACKET_HOST) + skb->pkt_type == PACKET_MULTICAST) { + struct in_device *in_dev = __in_dev_get_rcu(skb->dev); + + if (in_dev) { + int our = ip_check_mc_rcu(in_dev, iph->daddr, iph->saddr, + iph->protocol); + if (our) + sk = __udp4_lib_mcast_demux_lookup(net, uh->dest, iph->daddr, + uh->source, iph->saddr, dif); + } + } else if (skb->pkt_type == PACKET_HOST) sk = __udp4_lib_demux_lookup(net, uh->dest, iph->daddr, uh->source, iph->saddr, dif); else