Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3787303ybi; Mon, 29 Jul 2019 12:36:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwaJeX/BuUgPJmeGw09eTk3W7FqbiQAigSnXcMYoMdM8SbhsIdyHgtCcSrSgf6gR48RbUZL X-Received: by 2002:a17:90a:9505:: with SMTP id t5mr112516805pjo.96.1564429019077; Mon, 29 Jul 2019 12:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429019; cv=none; d=google.com; s=arc-20160816; b=H2xfRQDDsYRD8FV0J3L1AjIpW12mP7aZkP7L8Fm+t75uJ2xefDxTlcsTKqcV+Fo+MG 1Jt7MnucDEBLreJIdPROk3lpsumsnm+CTIB+CpTQrULiRCsy5namq01QxuK4zCdrbOVI XXV2ski1E/ZMS4ZPRkwe2kl/XWIXakoEIfuxs9tWY1/dG2DXYKymAFTBTWNz50TGq1UE O6irr71fwSvcistl9fxZ1feAULidSxMyJaaHO0H4Q0jp7MceTy7tOHDIOS6SnGvn9NrE DzoVDhgmJ7sIPOmWTU8AVWLIMNgiigImS7a3+03EN5hioGbwDTTVJgcpUkA3sQxaowpq Wq7g== 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=aACq2gvKPipymYvM7dfwTZop9J89kpyPkNnjykromrM=; b=pm5llYdU5gNgsaD4uLml3U6lC9zXMhv5cPHvcSE/jzze41XXQ0TFL6Jy1LqnON7lRP gqLrZ/uTRQqNXWlOXdJjP/sOR5G7xQy2uSE9GM0YrEk6EXGqEOA3of5k2kCv3xJuip7l uAD3zAOaf+/3CNUQJqMsc9WA1e+ruj8TJ+aJ2x13+DoT87cvNN5v2fgvgIzl7XWbeKUl gJqeGe/P+RIa4DyS3G9JtxMGIDgfLvbxE0RtP1hci3yKdWfFYYNP/kAiWNUhbHvksrNc CW5crVFSfTPAqmsB3/PtxwHGHMNoFLrAyMH6MbfttPAIMkD+VDZuYsgyM8Si73tnSK4N 9xGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DNc4lPc2; 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 ci23si50686408pjb.106.2019.07.29.12.36.43; Mon, 29 Jul 2019 12:36:59 -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=DNc4lPc2; 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 S1729975AbfG2Tdq (ORCPT + 99 others); Mon, 29 Jul 2019 15:33:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:48008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729402AbfG2Tdo (ORCPT ); Mon, 29 Jul 2019 15:33:44 -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 443A12070B; Mon, 29 Jul 2019 19:33:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428822; bh=6tIyMhAmocpLo35jAQBAWhLR5BOUQsgzB1G264Fvzv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DNc4lPc2UNY+tNlVhsQ2qaLKMqph9DVR70RihN6789vag5IyQqwrLBINB+o3N5PTy yi4cDQ6oJyJLXsbgZrAN/6mlLTN3kGGVGjtCuv7ZEXdx6xhp8YZcghYwWpIfT/cUII lAz6ZyVdC9AkDw0qu/8LHTBZpArb4IM20cj2FuUw= 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.14 198/293] bonding: validate ip header before check IPPROTO_IGMP Date: Mon, 29 Jul 2019 21:21:29 +0200 Message-Id: <20190729190839.642048519@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@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 @@ -3817,8 +3817,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 @@ -3827,23 +3827,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; }