Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9933957ybi; Wed, 24 Jul 2019 12:35:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLavscdWoG+SkvB9dgVTD0+7Z5pMFBY1xcKj8rHjp1OHU7MvAaDJJdLiJJ5zbXb+9sWK0/ X-Received: by 2002:a17:90a:e38f:: with SMTP id b15mr90959045pjz.85.1563996943631; Wed, 24 Jul 2019 12:35:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563996943; cv=none; d=google.com; s=arc-20160816; b=u1uwqOOZBLMYE8skhwyWXarouqw+EL7y1dhfiP5lAu6KHVEqoKdwxzHoAmwK1FhbZG 6rNSNKjxNfHbGRsHRdGWD52zOnN2aDMYEtCPBt+v7WeQ6Inju59Y5bGsjL5ySNGo6nLw 8QuPKOJE0XKSWLtBdDEiUlCH72JI6QBHZ6uFVLkpKCTTsFHNEz8Nl+BTtSnO34z9QDed hX0oQiXweQ58YBrErvhrLglKGYTrH30yEGMbbA0Ur/2O4c18PxXA6HU6//J8wRuMoa8v OwXii06t9XwlZq0rtrdOQ2fcwqWTwf5TdAJy05a+mKdCi2rhiKs0RJSyFaEJLw/S324j tp+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=to9NXAUacviWTggIuhTODbDZs2fYhQqhcnM4iY4RmNk=; b=QWNzmS07wmpnPJToBp/5vEv6oKLX4PwLr9eH8frE1JrppsNCu/qoC1j0MLZ0tJZ6gZ eqQom7dFZbRP/I1axQ/WfyV2n/n8t0tnWsfeK0+IgdOQfAXSPDxmQ43kHOFWvQfZ8NcL Mz2Q7Lysk4qNqndTL7CglIkQomYaJpXHVUrXyYMLYD5Q+QYPBk31djPsqowG1XsXEiHI b+szwoBSAeU3dsoxbIdpNoOpKKssRzUAApDMoo7MAslzq9/PnuXhrBRPSN5iuJtZQUHa yLkwHtwRTF5ZzS6GsBzPuJFEAk5bM7OBabbCIqg3/6biI+6691yLe6h8IfDJv8yb7yit x4rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yfWpeJa4; 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 cj12si14492327plb.237.2019.07.24.12.35.28; Wed, 24 Jul 2019 12:35:43 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=yfWpeJa4; 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 S2388842AbfGXTdV (ORCPT + 99 others); Wed, 24 Jul 2019 15:33:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:55076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388834AbfGXTdT (ORCPT ); Wed, 24 Jul 2019 15:33:19 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 38BF322BEA; Wed, 24 Jul 2019 19:33:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996798; bh=Q1EZqeCQWhCsHZTbAIDBuishbOzwnTWReFcUtB+aeCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yfWpeJa4cM1ehjdLoV2hP0LiCyK2Zwq/vDvpoMwhuhfm0TXsLsSS6/U2myQ8liTDK l4bWTUwzM4UR9xWxRgG1RL0tp02KnT23rOTcglO606XC6mHEl57hPoyL3IblSzVq95 j5/dJIp97z0FMrKF4zU2sot8gdvKoNVQaMe42n/Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , Cong Wang , "David S. Miller" , Sasha Levin , syzbot+e5be16aa39ad6e755391@syzkaller.appspotmail.com Subject: [PATCH 5.2 221/413] bonding: validate ip header before check IPPROTO_IGMP Date: Wed, 24 Jul 2019 21:18:32 +0200 Message-Id: <20190724191750.592371357@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 9d1bc24b52fb8c5d859f9a47084bf1179470e04c ] bond_xmit_roundrobin() checks for IGMP packets but it parses the IP header even before checking skb->protocol. We should validate the IP header with pskb_may_pull() before using iph->protocol. Reported-and-tested-by: syzbot+e5be16aa39ad6e755391@syzkaller.appspotmail.com Fixes: a2fd940f4cff ("bonding: fix broken multicast with round-robin mode") Cc: Jay Vosburgh Cc: Veaceslav Falico Cc: Andy Gospodarek Signed-off-by: Cong Wang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/bonding/bond_main.c | 37 ++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 799fc38c5c34..b0aab3a0a1bf 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -3866,8 +3866,8 @@ static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev) { struct bonding *bond = netdev_priv(bond_dev); - struct iphdr *iph = ip_hdr(skb); struct slave *slave; + int slave_cnt; u32 slave_id; /* Start with the curr_active_slave that joined the bond as the @@ -3876,23 +3876,32 @@ static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb, * send the join/membership reports. The curr_active_slave found * will send all of this type of traffic. */ - if (iph->protocol == IPPROTO_IGMP && skb->protocol == htons(ETH_P_IP)) { - slave = rcu_dereference(bond->curr_active_slave); - if (slave) - bond_dev_queue_xmit(bond, skb, slave->dev); - else - bond_xmit_slave_id(bond, skb, 0); - } else { - int slave_cnt = READ_ONCE(bond->slave_cnt); + if (skb->protocol == htons(ETH_P_IP)) { + int noff = skb_network_offset(skb); + struct iphdr *iph; - if (likely(slave_cnt)) { - slave_id = bond_rr_gen_slave_id(bond); - bond_xmit_slave_id(bond, skb, slave_id % slave_cnt); - } else { - bond_tx_drop(bond_dev, skb); + if (unlikely(!pskb_may_pull(skb, noff + sizeof(*iph)))) + goto non_igmp; + + iph = ip_hdr(skb); + if (iph->protocol == IPPROTO_IGMP) { + slave = rcu_dereference(bond->curr_active_slave); + if (slave) + bond_dev_queue_xmit(bond, skb, slave->dev); + else + bond_xmit_slave_id(bond, skb, 0); + return NETDEV_TX_OK; } } +non_igmp: + slave_cnt = READ_ONCE(bond->slave_cnt); + if (likely(slave_cnt)) { + slave_id = bond_rr_gen_slave_id(bond); + bond_xmit_slave_id(bond, skb, slave_id % slave_cnt); + } else { + bond_tx_drop(bond_dev, skb); + } return NETDEV_TX_OK; } -- 2.20.1