Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1034982ybi; Fri, 2 Aug 2019 08:17:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2cCKEQ7RdoOr0fReyVRhNjg6Rif/d5gUIDwcT6lk8aR3Ci9s/slixBM1JBn4qTZdGKLJ5 X-Received: by 2002:a63:c442:: with SMTP id m2mr126944247pgg.286.1564759039521; Fri, 02 Aug 2019 08:17:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564759039; cv=none; d=google.com; s=arc-20160816; b=z8+pl2JpFKYXdAMegsKIAYDa2GX6FH3XqQOv9VfURWGsY6MEMLWiss0H2OH919dL0t mkM9rvG/gdnExmHUeomuMpcQtIHuhYFSxrXlIsHME+fmHzpx9TpZNavwXPhr1esMOoWL CtYR+YE5lIjGkTfRpy0ozN7Q+vtveyHgFSrWLts2K5gzWSTKoE3igoaf23xNEA1PCZge zSiLobfw7buGuPlKrXeKHztTGJQkedtjT+rgpxYyXqC2qEP0iTmztpu6enVD+jGokm2J Il+HhPh2amSvyGeUes/Hsv6JEw7n3WF0QYer3rlQXeArZinJTfpegl66c3QDKHXBytTe EzJw== 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=rHvgfVVMPGiCiE0VAyPGAgA5L5sD+mP5COpwZ9E9A4I=; b=02Cp6SR86Ln1a28l6I4W85U4Bro1l19aM93ziiPqt8iavlJpdeB+7y5peWWDsiIQY4 ME02qwjSgPrqUI58IYnP+cPtQOI19RATS7+GXvXAfJoxBMvX0kQ/ifiIlAXp/XqUMQOB b750YsUSTvyeirx9Egkjt6YjnuuAn642x59CFAa6SiFaImZsJi6Cm10+uZoMsEKT9Khm VY0ccaSr4p5R4ZbDQOIcnmCkVmtY3nJc84G9jB1b5q3/7IPwg+PQgH7aZgpFNCZljuen mzNfQ9bvT1SWCpoRpspdffusoBdcuPUXtumFN8ZO81fFjIguFZEz1lDnORlaNJ2FTKTU yBsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sVSBKqqs; 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 h129si39687204pgc.508.2019.08.02.08.17.04; Fri, 02 Aug 2019 08:17:19 -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=sVSBKqqs; 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 S2391522AbfHBJeT (ORCPT + 99 others); Fri, 2 Aug 2019 05:34:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:34090 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729449AbfHBJeR (ORCPT ); Fri, 2 Aug 2019 05:34:17 -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 C6B5A2183F; Fri, 2 Aug 2019 09:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564738456; bh=7m3ruUCgKo9KO242W+P8KIiIhfOU3zmmj6FT3Ptvf7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sVSBKqqsDepKPjDGo8cqS73XuDKsOzuCn2xIsidVCigEAwVr+6tj/ucu1p7tajCHl F26EG+IgTNdjjtB9UNksCbxS/vSI7f6dCgMZ8X2uIGMdMpKVTa1PMTErdZLxC1pYL7 4BQWH11o32yBXQyNdPAOwxfvkVLZmXyIP3FZUKfI= 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" , syzbot+e5be16aa39ad6e755391@syzkaller.appspotmail.com Subject: [PATCH 4.4 096/158] bonding: validate ip header before check IPPROTO_IGMP Date: Fri, 2 Aug 2019 11:28:37 +0200 Message-Id: <20190802092223.896649587@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802092203.671944552@linuxfoundation.org> References: <20190802092203.671944552@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 From: Cong Wang [ 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: Greg Kroah-Hartman --- drivers/net/bonding/bond_main.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -3714,8 +3714,8 @@ static u32 bond_rr_gen_slave_id(struct b static int 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 @@ -3724,23 +3724,32 @@ static int bond_xmit_roundrobin(struct s * 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 = ACCESS_ONCE(bond->slave_cnt); + if (skb->protocol == htons(ETH_P_IP)) { + int noff = skb_network_offset(skb); + struct iphdr *iph; + + if (unlikely(!pskb_may_pull(skb, noff + sizeof(*iph)))) + goto non_igmp; - 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); + 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 = ACCESS_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; }