Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp878074rwb; Mon, 26 Sep 2022 07:03:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7xh0A5PR6SDKgQwEUhL1vWuwZkWnpSlY0p9IPGBgz24Wr9Z37+rkkbx11AT6k+8CxrkDm/ X-Received: by 2002:a63:5266:0:b0:439:920b:fc65 with SMTP id s38-20020a635266000000b00439920bfc65mr19847093pgl.417.1664200992745; Mon, 26 Sep 2022 07:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664200992; cv=none; d=google.com; s=arc-20160816; b=0u7Ggppj3cSnfOpbvEaAx6JnOUT44vCHmHtxjqRUqikPvkEFL88shX6wsX4zM1any+ HD4psUNkdZKAHOtEf1KpksRJxfjJZopc/Zdgk/8Bu3Yyu8F5gBHd+A5vikFlYMkXxxYw b4aiq1Gkz2UeF6IYB7BKowJ4/Zpq0NpxD3W8fguKYUm4SJhJPeT04f2pMWfO5ZA7eY28 tnF4sWTKKFW9k1B5WwsRlNte5a+QIVXrela5ME+ehA5H8wRjDeJwWM2CoTCBIgWkGxTM Cc8cWjHf8bZ3FpvRJAeeW2NXzXlq/lT0hW0+m6+wWva2HpwYfOs9kem3OUv0dlktRMvT W5Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=V1N8dMZGQ9xgzCu3cmnDurnZfrmQlfPdjnHcm6FnFOY=; b=QtCTtTgfPEknrWSIE9MKPBZHi1Q4PjtOewsMs1Tz/y4VvSC+vWLNmRDMnD1s503ai9 PUC5PuyWDFZw5kNrzteTQ3IvIJhLWnVy5j7Lxhy5Ip2DKUf+Ud+7mQatZXaN638is82T 2i4le4jMSzQLU+w+uhbwgJgYx/2WGOpylk1ia78Z7XnLrRSrkLAkEoYk4xecYt4r2g6A 9SyJIDCRIVv6Qx8OSR0JNucJUmsgRKsfCnS2ZnhRInj1i4MNm62+A6j7AHCbjLDNf+rO fIuO37mBWKsHQiRXiLfgss8UtRSg8Dof1idGgT0aNdE5U0YhP8l0k4I1AiOcEyZao55f wsDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=R+y4O8jZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p2-20020a056a000b4200b0054598afeb07si20705192pfo.56.2022.09.26.07.02.59; Mon, 26 Sep 2022 07:03:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=R+y4O8jZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238634AbiIZLqh (ORCPT + 99 others); Mon, 26 Sep 2022 07:46:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238523AbiIZLnm (ORCPT ); Mon, 26 Sep 2022 07:43:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B45F672ECB; Mon, 26 Sep 2022 03:46:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A8CCAB8013C; Mon, 26 Sep 2022 10:46:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F284CC433D6; Mon, 26 Sep 2022 10:46:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664189162; bh=bmroqRKWsjXUI/29mh4EiyjfVVI8ExrtCJQ14Y306Mg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R+y4O8jZml9NJF6wwd9Oey2X3aFT5/fuOg7MYZLxn3PUksF+HLH6hbUnMwHA7MKHi YBtBKNkThwT1w9yPfCRu5RAZI39OfpDYVMJFjX+8LojNKhhFl2alDuhwHDV+Uy/dXk gyQAzwXUumOV9q+OBNro2zaGucTkcZfMYk1zIn5E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lu Wei , Eric Dumazet , "David S. Miller" , Sasha Levin Subject: [PATCH 5.19 093/207] ipvlan: Fix out-of-bound bugs caused by unset skb->mac_header Date: Mon, 26 Sep 2022 12:11:22 +0200 Message-Id: <20220926100810.760620649@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100806.522017616@linuxfoundation.org> References: <20220926100806.522017616@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lu Wei [ Upstream commit 81225b2ea161af48e093f58e8dfee6d705b16af4 ] If an AF_PACKET socket is used to send packets through ipvlan and the default xmit function of the AF_PACKET socket is changed from dev_queue_xmit() to packet_direct_xmit() via setsockopt() with the option name of PACKET_QDISC_BYPASS, the skb->mac_header may not be reset and remains as the initial value of 65535, this may trigger slab-out-of-bounds bugs as following: ================================================================= UG: KASAN: slab-out-of-bounds in ipvlan_xmit_mode_l2+0xdb/0x330 [ipvlan] PU: 2 PID: 1768 Comm: raw_send Kdump: loaded Not tainted 6.0.0-rc4+ #6 ardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-1.fc33 all Trace: print_address_description.constprop.0+0x1d/0x160 print_report.cold+0x4f/0x112 kasan_report+0xa3/0x130 ipvlan_xmit_mode_l2+0xdb/0x330 [ipvlan] ipvlan_start_xmit+0x29/0xa0 [ipvlan] __dev_direct_xmit+0x2e2/0x380 packet_direct_xmit+0x22/0x60 packet_snd+0x7c9/0xc40 sock_sendmsg+0x9a/0xa0 __sys_sendto+0x18a/0x230 __x64_sys_sendto+0x74/0x90 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd The root cause is: 1. packet_snd() only reset skb->mac_header when sock->type is SOCK_RAW and skb->protocol is not specified as in packet_parse_headers() 2. packet_direct_xmit() doesn't reset skb->mac_header as dev_queue_xmit() In this case, skb->mac_header is 65535 when ipvlan_xmit_mode_l2() is called. So when ipvlan_xmit_mode_l2() gets mac header with eth_hdr() which use "skb->head + skb->mac_header", out-of-bound access occurs. This patch replaces eth_hdr() with skb_eth_hdr() in ipvlan_xmit_mode_l2() and reset mac header in multicast to solve this out-of-bound bug. Fixes: 2ad7bf363841 ("ipvlan: Initial check-in of the IPVLAN driver.") Signed-off-by: Lu Wei Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ipvlan/ipvlan_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/ipvlan/ipvlan_core.c b/drivers/net/ipvlan/ipvlan_core.c index 6ffb27419e64..c58123e13689 100644 --- a/drivers/net/ipvlan/ipvlan_core.c +++ b/drivers/net/ipvlan/ipvlan_core.c @@ -495,7 +495,6 @@ static int ipvlan_process_v6_outbound(struct sk_buff *skb) static int ipvlan_process_outbound(struct sk_buff *skb) { - struct ethhdr *ethh = eth_hdr(skb); int ret = NET_XMIT_DROP; /* The ipvlan is a pseudo-L2 device, so the packets that we receive @@ -505,6 +504,8 @@ static int ipvlan_process_outbound(struct sk_buff *skb) if (skb_mac_header_was_set(skb)) { /* In this mode we dont care about * multicast and broadcast traffic */ + struct ethhdr *ethh = eth_hdr(skb); + if (is_multicast_ether_addr(ethh->h_dest)) { pr_debug_ratelimited( "Dropped {multi|broad}cast of type=[%x]\n", @@ -589,7 +590,7 @@ static int ipvlan_xmit_mode_l3(struct sk_buff *skb, struct net_device *dev) static int ipvlan_xmit_mode_l2(struct sk_buff *skb, struct net_device *dev) { const struct ipvl_dev *ipvlan = netdev_priv(dev); - struct ethhdr *eth = eth_hdr(skb); + struct ethhdr *eth = skb_eth_hdr(skb); struct ipvl_addr *addr; void *lyr3h; int addr_type; @@ -619,6 +620,7 @@ static int ipvlan_xmit_mode_l2(struct sk_buff *skb, struct net_device *dev) return dev_forward_skb(ipvlan->phy_dev, skb); } else if (is_multicast_ether_addr(eth->h_dest)) { + skb_reset_mac_header(skb); ipvlan_skb_crossing_ns(skb, NULL); ipvlan_multicast_enqueue(ipvlan->port, skb, true); return NET_XMIT_SUCCESS; -- 2.35.1