Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1845357lql; Wed, 13 Mar 2024 09:38:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU2df5hvg/xsFzZHzzIn7QCJWutybmUZqsJYecVBGTYX9VFuoB+7zZErn0kAT62UripwNUkkvqZ11Ohi3gPcJJp6nJKgIYzZfjuxBUVmA== X-Google-Smtp-Source: AGHT+IEDzhZSDdG69aiWBx8WE91Y5R04ZAk+zzekcpCvLJiUgd0vMlhL8t8IW/319rD5D+biQcC+ X-Received: by 2002:a05:620a:cf1:b0:787:ddd9:efa0 with SMTP id c17-20020a05620a0cf100b00787ddd9efa0mr349062qkj.24.1710347930092; Wed, 13 Mar 2024 09:38:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710347930; cv=pass; d=google.com; s=arc-20160816; b=D03pm2FDPEWxqSkIgdJrJG5ihhQp+HN5hBxsOBGy/tlPqIpMKPPaM7trUR2j9KzwWU bPVs2fQBzcsXumyYGPYF5noLwq2e6Ubx89MmG0szbH3Z3G9CSoVuP6EQBt4K6X62n7ao wJ4njU/aFlWHW8IwBEkzqKoexEgLArVo/d2KXN0fIpQ5kYABjm2G5epktJkmXSGMGmF3 XSJrPoyfj42uEsceQ6DbJjagdBDXBRwAvtjPJixBsQB598/oJ/dWrIo3R7w3UGWEJ7+a 5cSCLZGwVZE+yhRzH8pQtQLREGrVx7vl+usx7moh5GBzYJKY+86Xxy79Umru/oghstqV 2lLQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ubpHZq6JqHbB4ECuuKaevG/cFhryNTc4J6K1sAlCYd8=; fh=Hz8c0cvuizBTvk2uwiVsLHsBYTdo80IX+a/w+0BKbwg=; b=NTN5nmPvXU2GF65dQNNt7fg26KOJ6wG2eFkthgwdqv4FMNOFTe8EktjXC5Jxr7rEv9 SKRcV4b5VeMUiE+UzNo6S/t//qDHbIh8xKBdFZs9Djt/BQ3pAa6FiyjZ3x7Aiz6/gu47 AKagUvrmaZvDmPPWeZWXtuq5laA9Qv0+1BmZ9KyIcw4/NM01CpYNuM6bKaWxmMlwbJHK 7Qwps4FsEWz4KMUkESYNlTRIlcorhI/JUYDRG5tF6v+uIms6xZEKd+8lICnxUmapjuL3 9EdX7tAC/IAwGtCgFqn3kQU7JZcf4k3i+OYVKiMxmR+X7oaOl4GsGMrvmkrK+rYl4i8z 6AhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=McBDb8vf; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id vu27-20020a05620a561b00b00789cb264d41si1434756qkn.0.2024.03.13.09.38.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 09:38:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=McBDb8vf; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-101765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BC8DA1C21A9A for ; Wed, 13 Mar 2024 16:38:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C302260881; Wed, 13 Mar 2024 16:33:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="McBDb8vf" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF0DF60868; Wed, 13 Mar 2024 16:33:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710347590; cv=none; b=oNn97tQIHXaNzZyB7+heCWmYlXJaO6idgMJP35KBMEMviuLpQeWQ66hMPs/OOT39KpvTRYwUIz37Vs9HDDI5Rj0vnWurNB0yckzfpYWWqNDUVz69XDeAlIeiKCJJ9crslw+X4z+n5LgIig2B0Zh07JW7dpt36+fIeQa6awlN7Fc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710347590; c=relaxed/simple; bh=mvGDqoFENuXISP41FAYxHtREhJLJrSL0HMmGWeEAX4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JinMyhFSFg9DHjRQVs4PVAnnGXMY6hgNfGfwU8sddQ+zzsfYuBq+OUFuu40jnNOP9C+xNN8oLPk48T23/2rCHYvn22DGbKjTrId/r3WukQq/BzCu4dJBG8MHENMD+teCFpG+gsGu6tqNXV0lfBvp0xddLfTbA7GYdeu/5n2c3yg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=McBDb8vf; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AD07C433C7; Wed, 13 Mar 2024 16:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710347590; bh=mvGDqoFENuXISP41FAYxHtREhJLJrSL0HMmGWeEAX4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=McBDb8vffKgn315LnAXK4ymNXY0MfHU9aPZTxtA6FYTNRhOF50UUmZPo1wATWeqnr m8UOQ41pAGd6MKlkAFNPr9TBZo7ECM4C8a1+HR4SXVK/p/Gp6gtwIKTeYgki8pSAqc czoZ5gSJCJnkM3oz88rjDUn7Nw9zMQXJ7961Hnw3oNdzJRZR/yJWsnrgKil7Bcj+Go 9qnousPzCXtPJCnX6tEJhGmRkK/8rGqbeLN2KKpFer99cNZ2uHe90End5ryDfEvsNn v6GyM0eASCF+yfUIsArB+xi80S34hjtUPvbgswo5dq3k3tFqkypSx9bhOvsQDth0n4 NTcxnZsQD2A/A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eric Dumazet , syzbot+6a1423ff3f97159aae64@syzkaller.appspotmail.com, Jiri Pirko , "David S . Miller" , Sasha Levin Subject: [PATCH 6.7 26/61] geneve: make sure to pull inner header in geneve_rx() Date: Wed, 13 Mar 2024 12:32:01 -0400 Message-ID: <20240313163236.613880-27-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313163236.613880-1-sashal@kernel.org> References: <20240313163236.613880-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v6.x/stable-review/patch-6.7.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-6.7.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 6.7.10-rc1 X-KernelTest-Deadline: 2024-03-15T16:32+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Eric Dumazet [ Upstream commit 1ca1ba465e55b9460e4e75dec9fff31e708fec74 ] syzbot triggered a bug in geneve_rx() [1] Issue is similar to the one I fixed in commit 8d975c15c0cd ("ip6_tunnel: make sure to pull inner header in __ip6_tnl_rcv()") We have to save skb->network_header in a temporary variable in order to be able to recompute the network_header pointer after a pskb_inet_may_pull() call. pskb_inet_may_pull() makes sure the needed headers are in skb->head. [1] BUG: KMSAN: uninit-value in IP_ECN_decapsulate include/net/inet_ecn.h:302 [inline] BUG: KMSAN: uninit-value in geneve_rx drivers/net/geneve.c:279 [inline] BUG: KMSAN: uninit-value in geneve_udp_encap_recv+0x36f9/0x3c10 drivers/net/geneve.c:391 IP_ECN_decapsulate include/net/inet_ecn.h:302 [inline] geneve_rx drivers/net/geneve.c:279 [inline] geneve_udp_encap_recv+0x36f9/0x3c10 drivers/net/geneve.c:391 udp_queue_rcv_one_skb+0x1d39/0x1f20 net/ipv4/udp.c:2108 udp_queue_rcv_skb+0x6ae/0x6e0 net/ipv4/udp.c:2186 udp_unicast_rcv_skb+0x184/0x4b0 net/ipv4/udp.c:2346 __udp4_lib_rcv+0x1c6b/0x3010 net/ipv4/udp.c:2422 udp_rcv+0x7d/0xa0 net/ipv4/udp.c:2604 ip_protocol_deliver_rcu+0x264/0x1300 net/ipv4/ip_input.c:205 ip_local_deliver_finish+0x2b8/0x440 net/ipv4/ip_input.c:233 NF_HOOK include/linux/netfilter.h:314 [inline] ip_local_deliver+0x21f/0x490 net/ipv4/ip_input.c:254 dst_input include/net/dst.h:461 [inline] ip_rcv_finish net/ipv4/ip_input.c:449 [inline] NF_HOOK include/linux/netfilter.h:314 [inline] ip_rcv+0x46f/0x760 net/ipv4/ip_input.c:569 __netif_receive_skb_one_core net/core/dev.c:5534 [inline] __netif_receive_skb+0x1a6/0x5a0 net/core/dev.c:5648 process_backlog+0x480/0x8b0 net/core/dev.c:5976 __napi_poll+0xe3/0x980 net/core/dev.c:6576 napi_poll net/core/dev.c:6645 [inline] net_rx_action+0x8b8/0x1870 net/core/dev.c:6778 __do_softirq+0x1b7/0x7c5 kernel/softirq.c:553 do_softirq+0x9a/0xf0 kernel/softirq.c:454 __local_bh_enable_ip+0x9b/0xa0 kernel/softirq.c:381 local_bh_enable include/linux/bottom_half.h:33 [inline] rcu_read_unlock_bh include/linux/rcupdate.h:820 [inline] __dev_queue_xmit+0x2768/0x51c0 net/core/dev.c:4378 dev_queue_xmit include/linux/netdevice.h:3171 [inline] packet_xmit+0x9c/0x6b0 net/packet/af_packet.c:276 packet_snd net/packet/af_packet.c:3081 [inline] packet_sendmsg+0x8aef/0x9f10 net/packet/af_packet.c:3113 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg net/socket.c:745 [inline] __sys_sendto+0x735/0xa10 net/socket.c:2191 __do_sys_sendto net/socket.c:2203 [inline] __se_sys_sendto net/socket.c:2199 [inline] __x64_sys_sendto+0x125/0x1c0 net/socket.c:2199 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x63/0x6b Uninit was created at: slab_post_alloc_hook mm/slub.c:3819 [inline] slab_alloc_node mm/slub.c:3860 [inline] kmem_cache_alloc_node+0x5cb/0xbc0 mm/slub.c:3903 kmalloc_reserve+0x13d/0x4a0 net/core/skbuff.c:560 __alloc_skb+0x352/0x790 net/core/skbuff.c:651 alloc_skb include/linux/skbuff.h:1296 [inline] alloc_skb_with_frags+0xc8/0xbd0 net/core/skbuff.c:6394 sock_alloc_send_pskb+0xa80/0xbf0 net/core/sock.c:2783 packet_alloc_skb net/packet/af_packet.c:2930 [inline] packet_snd net/packet/af_packet.c:3024 [inline] packet_sendmsg+0x70c2/0x9f10 net/packet/af_packet.c:3113 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg net/socket.c:745 [inline] __sys_sendto+0x735/0xa10 net/socket.c:2191 __do_sys_sendto net/socket.c:2203 [inline] __se_sys_sendto net/socket.c:2199 [inline] __x64_sys_sendto+0x125/0x1c0 net/socket.c:2199 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xcf/0x1e0 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x63/0x6b Fixes: 2d07dc79fe04 ("geneve: add initial netdev driver for GENEVE tunnels") Reported-and-tested-by: syzbot+6a1423ff3f97159aae64@syzkaller.appspotmail.com Signed-off-by: Eric Dumazet Reviewed-by: Jiri Pirko Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/geneve.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c index acd9c615d1f4f..356da958ee81b 100644 --- a/drivers/net/geneve.c +++ b/drivers/net/geneve.c @@ -221,7 +221,7 @@ static void geneve_rx(struct geneve_dev *geneve, struct geneve_sock *gs, struct genevehdr *gnvh = geneve_hdr(skb); struct metadata_dst *tun_dst = NULL; unsigned int len; - int err = 0; + int nh, err = 0; void *oiph; if (ip_tunnel_collect_metadata() || gs->collect_md) { @@ -272,9 +272,23 @@ static void geneve_rx(struct geneve_dev *geneve, struct geneve_sock *gs, skb->pkt_type = PACKET_HOST; } - oiph = skb_network_header(skb); + /* Save offset of outer header relative to skb->head, + * because we are going to reset the network header to the inner header + * and might change skb->head. + */ + nh = skb_network_header(skb) - skb->head; + skb_reset_network_header(skb); + if (!pskb_inet_may_pull(skb)) { + DEV_STATS_INC(geneve->dev, rx_length_errors); + DEV_STATS_INC(geneve->dev, rx_errors); + goto drop; + } + + /* Get the outer header. */ + oiph = skb->head + nh; + if (geneve_get_sk_family(gs) == AF_INET) err = IP_ECN_decapsulate(oiph, skb); #if IS_ENABLED(CONFIG_IPV6) -- 2.43.0