From patchwork Mon Apr 15 22:20:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13630775 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) (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 A1E3F156877 for ; Mon, 15 Apr 2024 22:21:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.218 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713219683; cv=none; b=oc6Uy5+xl85NCW+VoZeqQcFIRqI6BeY6UuukFn5+ZkAvKAG4ir4XXN8iB1BNX/OlrwFAjxB71vwZgHzpgZdZO+4AV8NpkDUWoXulpwiZ7/RWC7Gh7+A3THjCX+1tczuB81kQJx1/O2wRpBZEcrrg0kdPZBRmBXzU2WVsR9RLdVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713219683; c=relaxed/simple; bh=hbJOiQQpN3UDR3lLMeXoC1zUKb91DNydxbm8q6EdOGA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bI6BJwIIcNAR9XIHnNKtCCDDL0ti4+qsjAfsXE9Ek4HTYLualQhyuIivXP/K1ZEB7uwdmBMDjA+m8cbUgwXltHYta2mpE1fpwAJ0FQRrPnThS/d5FAiP4aCO8TAEr10v7R5DuReTEjMVWQP/iaS6jSjzHYX3Ta6MSysBFsVKB6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=KbZmjZ+I; arc=none smtp.client-ip=99.78.197.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="KbZmjZ+I" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1713219682; x=1744755682; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QnmyPwUrh3piNZGp8bSCPPwglKyIZo3s9DxKu4PA88Q=; b=KbZmjZ+Ibl2Laq2M+j0oaEuBdwq436eL7yvO55A2YHIV5vayI4BuenNG nGgmbkdJ1nSQKv/LQq0jSia6jf4SVjzGceQSbeRpuN5V1zkW0PhkTHkuo 9SCWDFXmqtFyGl7wnfTbdXJ/Upkn4Zp6RpFdV6cAGujk/ALjPdxlzCQcI c=; X-IronPort-AV: E=Sophos;i="6.07,204,1708387200"; d="scan'208";a="288791228" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2024 22:21:20 +0000 Received: from EX19MTAUWA002.ant.amazon.com [10.0.7.35:58974] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.42.38:2525] with esmtp (Farcaster) id b572284f-d6c7-4751-9809-1c36b63ad3b0; Mon, 15 Apr 2024 22:21:19 +0000 (UTC) X-Farcaster-Flow-ID: b572284f-d6c7-4751-9809-1c36b63ad3b0 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 15 Apr 2024 22:21:19 +0000 Received: from 88665a182662.ant.amazon.com (10.106.101.23) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 15 Apr 2024 22:21:15 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern CC: Steffen Klassert , Herbert Xu , Willem de Bruijn , Kuniyuki Iwashima , Kuniyuki Iwashima , , syzkaller Subject: [PATCH v1 net 1/5] sit: Pull header after checking skb->protocol in sit_tunnel_xmit(). Date: Mon, 15 Apr 2024 15:20:37 -0700 Message-ID: <20240415222041.18537-2-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240415222041.18537-1-kuniyu@amazon.com> References: <20240415222041.18537-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D040UWB004.ant.amazon.com (10.13.138.91) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org syzkaller crafted a GSO packet of ETH_P_8021AD + ETH_P_NSH and sent it over sit0. After nsh_gso_segment(), skb->data - skb->head was 138, on the other hand, skb->network_header was 128. Later, sit_tunnel_xmit() called pskb_inet_may_pull() for the skb, and it caused underflow and triggered the warning in pskb_may_pull_reason(). pskb_network_may_pull(skb, nhlen) `- pskb_may_pull(skb, skb_network_offset(skb) + nhlen) -> skb_network_offset(skb) + nhlen = skb_network_offset(skb) + 0 (because skb->protocol is not IPv4/IPv6) = skb_network_header(skb) - skb->data = skb->head + skb->network_header - skb->data = 128 - 138 = -10 Let's check skb->protocol before pulling the next header in sit_tunnel_xmit(). WARNING: CPU: 1 PID: 5300 at include/linux/skbuff.h:2740 pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] WARNING: CPU: 1 PID: 5300 at include/linux/skbuff.h:2740 pskb_may_pull include/linux/skbuff.h:2756 [inline] WARNING: CPU: 1 PID: 5300 at include/linux/skbuff.h:2740 pskb_network_may_pull include/linux/skbuff.h:3077 [inline] WARNING: CPU: 1 PID: 5300 at include/linux/skbuff.h:2740 pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] WARNING: CPU: 1 PID: 5300 at include/linux/skbuff.h:2740 sit_tunnel_xmit+0x1080/0x1fd8 net/ipv6/sit.c:1068 Modules linked in: CPU: 1 PID: 5300 Comm: syz-executor.5 Not tainted 6.8.0-12821-g537c2e91d354-dirty #11 Hardware name: linux,dummy-virt (DT) pstate: 80400005 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] pc : pskb_may_pull include/linux/skbuff.h:2756 [inline] pc : pskb_network_may_pull include/linux/skbuff.h:3077 [inline] pc : pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] pc : sit_tunnel_xmit+0x1080/0x1fd8 net/ipv6/sit.c:1068 lr : pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] lr : pskb_may_pull include/linux/skbuff.h:2756 [inline] lr : pskb_network_may_pull include/linux/skbuff.h:3077 [inline] lr : pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] lr : sit_tunnel_xmit+0x1080/0x1fd8 net/ipv6/sit.c:1068 sp : ffff8000aa017260 x29: ffff8000aa0173e0 x28: ffff00000cd0c000 x27: ffff000046200080 x26: ffff700015402e64 x25: 00000000fffffff6 x24: 1fffe00009835b7f x23: dfff800000000000 x22: ffff00004c1adbf4 x21: ffff00004c1adbf8 x20: ffff00004c1adb40 x19: 1fffe00009835b7e x18: ffff800086d72d10 x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000001 x14: 1fffe0000a15c217 x13: 0000000000000000 x12: ffff8000aa017320 x11: 0000000000040000 x10: 0000000000000b86 x9 : ffff8000a2639000 x8 : 0000000000000b87 x7 : 0000000000000001 x6 : 0000000000000001 x5 : ffff8000aa016c98 x4 : ffff800086d8b120 x3 : ffff800083f7f7d4 x2 : 0000000000000001 x1 : 00000000fffffff6 x0 : 0000000000000000 Call trace: pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] pskb_may_pull include/linux/skbuff.h:2756 [inline] pskb_network_may_pull include/linux/skbuff.h:3077 [inline] pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] sit_tunnel_xmit+0x1080/0x1fd8 net/ipv6/sit.c:1068 __netdev_start_xmit include/linux/netdevice.h:4903 [inline] netdev_start_xmit include/linux/netdevice.h:4917 [inline] xmit_one net/core/dev.c:3531 [inline] dev_hard_start_xmit+0x1a0/0x370 net/core/dev.c:3547 __dev_queue_xmit+0x12e8/0x2b04 net/core/dev.c:4335 dev_queue_xmit include/linux/netdevice.h:3091 [inline] packet_xmit+0x6c/0x31c net/packet/af_packet.c:276 packet_snd net/packet/af_packet.c:3081 [inline] packet_sendmsg+0x3818/0x4e50 net/packet/af_packet.c:3113 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg net/socket.c:745 [inline] __sys_sendto+0x324/0x470 net/socket.c:2191 __do_sys_sendto net/socket.c:2203 [inline] __se_sys_sendto net/socket.c:2199 [inline] __arm64_sys_sendto+0xd8/0xf8 net/socket.c:2199 __invoke_syscall arch/arm64/kernel/syscall.c:34 [inline] invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:48 el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:133 do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:152 el0_svc+0x30/0x78 arch/arm64/kernel/entry-common.c:712 el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730 el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598 Reported-by: syzkaller Fixes: cb9f1b783850 ("ip: validate header length on virtual device xmit") Signed-off-by: Kuniyuki Iwashima --- net/ipv6/sit.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index 655c9b1a19b8..b83c28369d46 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -1065,14 +1065,17 @@ static netdev_tx_t sit_tunnel_xmit__(struct sk_buff *skb, static netdev_tx_t sit_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) { - if (!pskb_inet_may_pull(skb)) - goto tx_err; - switch (skb->protocol) { case htons(ETH_P_IP): + if (!pskb_network_may_pull(skb, sizeof(struct iphdr))) + goto tx_err; + sit_tunnel_xmit__(skb, dev, IPPROTO_IPIP); break; case htons(ETH_P_IPV6): + if (!pskb_network_may_pull(skb, sizeof(struct ipv6hdr))) + goto tx_err; + ipip6_tunnel_xmit(skb, dev); break; #if IS_ENABLED(CONFIG_MPLS) From patchwork Mon Apr 15 22:20:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13630776 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) (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 34A44157A45 for ; Mon, 15 Apr 2024 22:21:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.220 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713219709; cv=none; b=QKkgUwPYHLIq8XMDQm9G05V/qD5vGsoPsyTVc+w7mKpq/mCNRDZZ5ZeGmshJSD8TrCp6VrgNiR1k0qp9onag7VYGQTgP1RtvZdZZ05CuG8lP0tVB6cd8BNfI/y7jq2jh4EtmS0OEASeZGU7kKXymlZId+blAFWEVBW+G5rS7eio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713219709; c=relaxed/simple; bh=U0WlCd8qyzm3tVZvqvCve2MhSQ7qFGdHOYgusQ8tTGw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pGgYjLd8RmNgTxVL+R71Jx14ONPivTb3fbW63+QCNLW/la8CWzDveSJpj8EevQaXFt7RZv3q/IocnbDZBxJMGaoz9H3R/oQOrLZb72Mfk5MlToYsrUjN/Vokl0waGsi7CYtSH4dusYAW8cbUV1tp/W6ozfXp/7emWLEnURdjQkw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=P2FG6+b4; arc=none smtp.client-ip=99.78.197.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="P2FG6+b4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1713219708; x=1744755708; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zoa+doGoCmceiJSYQYuf6AonrWT64swiuttQPFu2cwA=; b=P2FG6+b4v1VOSfFW5c/hxXyvccGHv1chifmcFi7TwI//PRcATZP2XdPM BcGC9/PwoZPk4IIt2kVycqrBf+HO3TqQirNtJHYBqA5ChoCbV5wHUUKtt dtRA4cmtrKdHsCgOxqJDRG6gobvnjUQJaXQIf5oLXJyyho7z/NogIWRWL Q=; X-IronPort-AV: E=Sophos;i="6.07,204,1708387200"; d="scan'208";a="81411484" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2024 22:21:46 +0000 Received: from EX19MTAUWC002.ant.amazon.com [10.0.38.20:58673] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.20.81:2525] with esmtp (Farcaster) id 5ae9efaa-dbe2-4716-9d0b-e0dd4c89fde0; Mon, 15 Apr 2024 22:21:46 +0000 (UTC) X-Farcaster-Flow-ID: 5ae9efaa-dbe2-4716-9d0b-e0dd4c89fde0 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 15 Apr 2024 22:21:44 +0000 Received: from 88665a182662.ant.amazon.com (10.106.101.23) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 15 Apr 2024 22:21:40 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern CC: Steffen Klassert , Herbert Xu , Willem de Bruijn , Kuniyuki Iwashima , Kuniyuki Iwashima , , syzkaller Subject: [PATCH v1 net 2/5] vti: Pull header after checking skb->protocol in vti_tunnel_xmit(). Date: Mon, 15 Apr 2024 15:20:38 -0700 Message-ID: <20240415222041.18537-3-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240415222041.18537-1-kuniyu@amazon.com> References: <20240415222041.18537-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D039UWA003.ant.amazon.com (10.13.139.49) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org syzkaller demonstrated the underflow in pskb_network_may_pull() by sending a crafted VLAN packet over the tunnel device. Let's check skb->protocol before pulling the next header in vti_tunnel_xmit(). WARNING: CPU: 1 PID: 4534 at include/linux/skbuff.h:2740 pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] WARNING: CPU: 1 PID: 4534 at include/linux/skbuff.h:2740 pskb_may_pull include/linux/skbuff.h:2756 [inline] WARNING: CPU: 1 PID: 4534 at include/linux/skbuff.h:2740 pskb_network_may_pull include/linux/skbuff.h:3077 [inline] WARNING: CPU: 1 PID: 4534 at include/linux/skbuff.h:2740 pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] WARNING: CPU: 1 PID: 4534 at include/linux/skbuff.h:2740 vti_tunnel_xmit+0xd48/0x14b4 net/ipv4/ip_vti.c:283 Modules linked in: CPU: 1 PID: 4534 Comm: syz-executor.1 Not tainted 6.8.0-12821-g537c2e91d354-dirty #11 Hardware name: linux,dummy-virt (DT) pstate: 80400005 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] pc : pskb_may_pull include/linux/skbuff.h:2756 [inline] pc : pskb_network_may_pull include/linux/skbuff.h:3077 [inline] pc : pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] pc : vti_tunnel_xmit+0xd48/0x14b4 net/ipv4/ip_vti.c:283 lr : pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] lr : pskb_may_pull include/linux/skbuff.h:2756 [inline] lr : pskb_network_may_pull include/linux/skbuff.h:3077 [inline] lr : pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] lr : vti_tunnel_xmit+0xd48/0x14b4 net/ipv4/ip_vti.c:283 sp : ffff8000a99372a0 x29: ffff8000a99373e0 x28: ffff00000d188838 x27: ffff700015326e64 x26: ffff000061930080 x25: dfff800000000000 x24: ffff8000a9937320 x23: 0000000000000000 x22: ffff00000d188834 x21: 00000000fffffff6 x20: ffff00000d188780 x19: ffff000017580000 x18: ffff800086d72d10 x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000001 x14: 1fffe000029ce017 x13: 0000000000000000 x12: 0000000000000001 x11: 0000000000040000 x10: 0000000000000b7f x9 : ffff80008a3fa000 x8 : 0000000000000b80 x7 : 0000000000000001 x6 : 0000000000000001 x5 : ffff8000a9936c98 x4 : ffff800086d8b120 x3 : ffff800083f7f7d4 x2 : 0000000000000001 x1 : 00000000fffffff6 x0 : 0000000000000000 Call trace: pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] pskb_may_pull include/linux/skbuff.h:2756 [inline] pskb_network_may_pull include/linux/skbuff.h:3077 [inline] pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] vti_tunnel_xmit+0xd48/0x14b4 net/ipv4/ip_vti.c:283 __netdev_start_xmit include/linux/netdevice.h:4903 [inline] netdev_start_xmit include/linux/netdevice.h:4917 [inline] xmit_one net/core/dev.c:3531 [inline] dev_hard_start_xmit+0x1a0/0x370 net/core/dev.c:3547 __dev_queue_xmit+0x12e8/0x2b04 net/core/dev.c:4335 dev_queue_xmit include/linux/netdevice.h:3091 [inline] packet_xmit+0x6c/0x31c net/packet/af_packet.c:276 packet_snd net/packet/af_packet.c:3081 [inline] packet_sendmsg+0x3818/0x4e50 net/packet/af_packet.c:3113 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg net/socket.c:745 [inline] __sys_sendto+0x324/0x470 net/socket.c:2191 __do_sys_sendto net/socket.c:2203 [inline] __se_sys_sendto net/socket.c:2199 [inline] __arm64_sys_sendto+0xd8/0xf8 net/socket.c:2199 __invoke_syscall arch/arm64/kernel/syscall.c:34 [inline] invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:48 el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:133 do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:152 el0_svc+0x30/0x78 arch/arm64/kernel/entry-common.c:712 el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730 el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598 Reported-by: syzkaller Fixes: cb9f1b783850 ("ip: validate header length on virtual device xmit") Signed-off-by: Kuniyuki Iwashima --- net/ipv4/ip_vti.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c index ee587adb169f..8070d0c440f6 100644 --- a/net/ipv4/ip_vti.c +++ b/net/ipv4/ip_vti.c @@ -280,17 +280,20 @@ static netdev_tx_t vti_tunnel_xmit(struct sk_buff *skb, struct net_device *dev) struct ip_tunnel *tunnel = netdev_priv(dev); struct flowi fl; - if (!pskb_inet_may_pull(skb)) - goto tx_err; - memset(&fl, 0, sizeof(fl)); switch (skb->protocol) { case htons(ETH_P_IP): + if (!pskb_network_may_pull(skb, sizeof(struct iphdr))) + goto tx_err; + memset(IPCB(skb), 0, sizeof(*IPCB(skb))); xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET); break; case htons(ETH_P_IPV6): + if (!pskb_network_may_pull(skb, sizeof(struct ipv6hdr))) + goto tx_err; + memset(IP6CB(skb), 0, sizeof(*IP6CB(skb))); xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET6); break; From patchwork Mon Apr 15 22:20:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13630777 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) (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 E30CC82D93 for ; Mon, 15 Apr 2024 22:22:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.217 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713219733; cv=none; b=dDkxwdgmZynC0tB6dQRuGEcnYs+YWlPee3QWbQ5KYMvBfDZrgmcWT+fmc1eNgBzN/dk4DY2/UHqJ0eidBWhdqYDWrl5oSS0yLci29+R7I56+vnlj4VECFLoWT7jvkwT3RliUHQTAwsH1G2VslAzQuf2kRFQ/ckhOIQkMzI6id/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713219733; c=relaxed/simple; bh=Ike3Z376hm6QA/khoIY9KwpCfHhdZ5ESe1JvznrKG5E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KGLUjqsD+Y2Pi83xZJAl43ZERHDVzmZC3GAqnM0suOGSdq4vrmKn31feHOOLOnKdM8naIqoLOoy7DIbvMND9MDRZNPVAirEQMdaYtRu16uqyMDpuIHzywuUmpgYwbohaHidHgi3hJfnCJHxFZpdoIB3gjcMLDCVSLxyDBUfqg0Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=XDnUBWt+; arc=none smtp.client-ip=99.78.197.217 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="XDnUBWt+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1713219732; x=1744755732; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vKw6Q/QSUa5IPeKmagK7lj8OpEVewFK2AZCU26Llef0=; b=XDnUBWt+K9jzl29aNFWT8OhEttqqTFPEBr1nrIE4Ij03E/4pKB6LccoK DXtHfxTVQtDQKK2CFWMBMqpo0Lls70GlnJX3UlBfzxMXyjEwmD/6ABIpX Hd3K3kAHX50nNSN8fCCSUH6xcbVy4/BuPVh5tWi8jVBvSsQVQERYn+8Is E=; X-IronPort-AV: E=Sophos;i="6.07,204,1708387200"; d="scan'208";a="287780814" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2024 22:22:10 +0000 Received: from EX19MTAUWA001.ant.amazon.com [10.0.7.35:39384] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.0.162:2525] with esmtp (Farcaster) id b0074af8-d183-4672-9ba1-1ff12d0f758d; Mon, 15 Apr 2024 22:22:09 +0000 (UTC) X-Farcaster-Flow-ID: b0074af8-d183-4672-9ba1-1ff12d0f758d Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWA001.ant.amazon.com (10.250.64.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 15 Apr 2024 22:22:09 +0000 Received: from 88665a182662.ant.amazon.com (10.106.101.23) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 15 Apr 2024 22:22:06 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern CC: Steffen Klassert , Herbert Xu , Willem de Bruijn , Kuniyuki Iwashima , Kuniyuki Iwashima , , syzkaller Subject: [PATCH v1 net 3/5] ip6_vti: Pull header after checking skb->protocol in vti6_tnl_xmit(). Date: Mon, 15 Apr 2024 15:20:39 -0700 Message-ID: <20240415222041.18537-4-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240415222041.18537-1-kuniyu@amazon.com> References: <20240415222041.18537-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D038UWB004.ant.amazon.com (10.13.139.177) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org syzkaller demonstrated the underflow in pskb_network_may_pull() by sending a crafted VLAN packet over the tunnel device. Let's check skb->protocol before pulling the next header in vti6_tnl_xmit(). WARNING: CPU: 0 PID: 722 at include/linux/skbuff.h:2740 pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] WARNING: CPU: 0 PID: 722 at include/linux/skbuff.h:2740 pskb_may_pull include/linux/skbuff.h:2756 [inline] WARNING: CPU: 0 PID: 722 at include/linux/skbuff.h:2740 pskb_network_may_pull include/linux/skbuff.h:3077 [inline] WARNING: CPU: 0 PID: 722 at include/linux/skbuff.h:2740 pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] WARNING: CPU: 0 PID: 722 at include/linux/skbuff.h:2740 vti6_tnl_xmit+0x100c/0x16c0 net/ipv6/ip6_vti.c:560 Modules linked in: CPU: 0 PID: 722 Comm: syz-executor.3 Not tainted 6.8.0-12821-g537c2e91d354-dirty #11 Hardware name: linux,dummy-virt (DT) pstate: 80400005 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] pc : pskb_may_pull include/linux/skbuff.h:2756 [inline] pc : pskb_network_may_pull include/linux/skbuff.h:3077 [inline] pc : pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] pc : vti6_tnl_xmit+0x100c/0x16c0 net/ipv6/ip6_vti.c:560 lr : pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] lr : pskb_may_pull include/linux/skbuff.h:2756 [inline] lr : pskb_network_may_pull include/linux/skbuff.h:3077 [inline] lr : pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] lr : vti6_tnl_xmit+0x100c/0x16c0 net/ipv6/ip6_vti.c:560 sp : ffff8000a86d7280 x29: ffff8000a86d73e0 x28: ffff7000150dae64 x27: ffff8000a86d7320 x26: ffff00004fdd0010 x25: dfff800000000000 x24: 00000000fffffff6 x23: ffff00000a0ae478 x22: ffff00000a0ae498 x21: ffff00000a0ae474 x20: ffff00000a0ae3c0 x19: ffff0000178d6000 x18: ffff800086d72d10 x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000001 x14: 1fffe0000958b817 x13: 0000000000000000 x12: 0000000000000001 x11: 0000000000040000 x10: 0000000000000b8a x9 : ffff80008e699000 x8 : 0000000000000b8b x7 : 0000000000000001 x6 : 0000000000000001 x5 : ffff8000a86d6c98 x4 : ffff800086d8b120 x3 : ffff800083f7f7d4 x2 : 0000000000000001 x1 : 00000000fffffff6 x0 : 0000000000000000 Call trace: pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] pskb_may_pull include/linux/skbuff.h:2756 [inline] pskb_network_may_pull include/linux/skbuff.h:3077 [inline] pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] vti6_tnl_xmit+0x100c/0x16c0 net/ipv6/ip6_vti.c:560 __netdev_start_xmit include/linux/netdevice.h:4903 [inline] netdev_start_xmit include/linux/netdevice.h:4917 [inline] xmit_one net/core/dev.c:3531 [inline] dev_hard_start_xmit+0x1a0/0x370 net/core/dev.c:3547 __dev_queue_xmit+0x12e8/0x2b04 net/core/dev.c:4335 dev_queue_xmit include/linux/netdevice.h:3091 [inline] packet_xmit+0x6c/0x31c net/packet/af_packet.c:276 packet_snd net/packet/af_packet.c:3081 [inline] packet_sendmsg+0x3818/0x4e50 net/packet/af_packet.c:3113 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg net/socket.c:745 [inline] __sys_sendto+0x324/0x470 net/socket.c:2191 __do_sys_sendto net/socket.c:2203 [inline] __se_sys_sendto net/socket.c:2199 [inline] __arm64_sys_sendto+0xd8/0xf8 net/socket.c:2199 __invoke_syscall arch/arm64/kernel/syscall.c:34 [inline] invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:48 el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:133 do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:152 el0_svc+0x30/0x78 arch/arm64/kernel/entry-common.c:712 el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730 el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598 Reported-by: syzkaller Fixes: cb9f1b783850 ("ip: validate header length on virtual device xmit") Signed-off-by: Kuniyuki Iwashima --- net/ipv6/ip6_vti.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c index 7f4f976aa24a..98c738eb6166 100644 --- a/net/ipv6/ip6_vti.c +++ b/net/ipv6/ip6_vti.c @@ -557,13 +557,13 @@ vti6_tnl_xmit(struct sk_buff *skb, struct net_device *dev) struct flowi fl; int ret; - if (!pskb_inet_may_pull(skb)) - goto tx_err; - memset(&fl, 0, sizeof(fl)); switch (skb->protocol) { case htons(ETH_P_IPV6): + if (!pskb_network_may_pull(skb, sizeof(struct ipv6hdr))) + goto tx_err; + if ((t->parms.proto != IPPROTO_IPV6 && t->parms.proto != 0) || vti6_addr_conflict(t, ipv6_hdr(skb))) goto tx_err; @@ -572,6 +572,9 @@ vti6_tnl_xmit(struct sk_buff *skb, struct net_device *dev) xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET6); break; case htons(ETH_P_IP): + if (!pskb_network_may_pull(skb, sizeof(struct iphdr))) + goto tx_err; + memset(IPCB(skb), 0, sizeof(*IPCB(skb))); xfrm_decode_session(dev_net(dev), skb, &fl, AF_INET); break; From patchwork Mon Apr 15 22:20:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13630778 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52005.amazon.com (smtp-fw-52005.amazon.com [52.119.213.156]) (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 6A0A7156877 for ; Mon, 15 Apr 2024 22:22:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713219766; cv=none; b=eZ9lkWa4ycJ9EZSre1rjU6XgKA+o3Lf3Lblp/sS0XjG2CFlMN5BOTR89wZ0MbUBFeG+TitBCTo356O2f/yt1PSU5nAkzyi6PFb5WX7G2Cz1wxTqLrxYlv435W2M4aLoi5XLe4w+nKU0+IpyCjrui1En0B1tr2lKnyTd6GFJtyZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713219766; c=relaxed/simple; bh=SgDDhxiWD1mgii/Sd8sTubUx4noIOM44a0I611D3L08=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RBJCKSe4kItCI8WWEq+PjsI5NwXj49bf7qBDjAkqkGSL0OJgiyHTxQfgEzyEzR6CRqJ7CieuqSaKrUUgU6A4bTp29GNcjIG7puKreLziaz5guZr1nWiO9E7qzzAZke5BXZm5y/qjuq9/cnLdoyTQbBOtLtZNK6Pk1z4VJM0C/ko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=eyHSlLAN; arc=none smtp.client-ip=52.119.213.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="eyHSlLAN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1713219765; x=1744755765; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Zyw70dU/8zaiuuCf5rMIDkyoi35UeTutjUjbg7r79Zk=; b=eyHSlLANu+TNU26lo5bvEjvrscNy8zssPxGR1K6PxrGcYj8VpHfE9wJm oCpEYRGQ2vQgNgnPhUZ0WMJxrlA70lNf2Ct30E7/dPZQk3BesOo2muDdx 9S0TAnqYhtCCcpD08BQeoIak+Jfzu6rrEfwHMab8cGoGaEsplK5nE2sGv I=; X-IronPort-AV: E=Sophos;i="6.07,204,1708387200"; d="scan'208";a="647808591" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-52005.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2024 22:22:42 +0000 Received: from EX19MTAUWC001.ant.amazon.com [10.0.38.20:6278] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.6.244:2525] with esmtp (Farcaster) id b11cb1f2-b035-4a89-a4aa-847cf84a2f73; Mon, 15 Apr 2024 22:22:40 +0000 (UTC) X-Farcaster-Flow-ID: b11cb1f2-b035-4a89-a4aa-847cf84a2f73 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 15 Apr 2024 22:22:34 +0000 Received: from 88665a182662.ant.amazon.com (10.106.101.23) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 15 Apr 2024 22:22:31 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern CC: Steffen Klassert , Herbert Xu , Willem de Bruijn , Kuniyuki Iwashima , Kuniyuki Iwashima , , syzkaller Subject: [PATCH v1 net 4/5] ipip: Pull header after checking skb->protocol in ipip_tunnel_xmit(). Date: Mon, 15 Apr 2024 15:20:40 -0700 Message-ID: <20240415222041.18537-5-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240415222041.18537-1-kuniyu@amazon.com> References: <20240415222041.18537-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D033UWC002.ant.amazon.com (10.13.139.196) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org syzkaller demonstrated the underflow in pskb_network_may_pull() by sending a crafted VLAN packet over the tunnel device. Let's check skb->protocol before pulling the next header in ipip_tunnel_xmit(). WARNING: CPU: 0 PID: 4406 at include/linux/skbuff.h:2740 pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] WARNING: CPU: 0 PID: 4406 at include/linux/skbuff.h:2740 pskb_may_pull include/linux/skbuff.h:2756 [inline] WARNING: CPU: 0 PID: 4406 at include/linux/skbuff.h:2740 pskb_network_may_pull include/linux/skbuff.h:3077 [inline] WARNING: CPU: 0 PID: 4406 at include/linux/skbuff.h:2740 pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] WARNING: CPU: 0 PID: 4406 at include/linux/skbuff.h:2740 ipip_tunnel_xmit+0x2d4/0x430 net/ipv4/ipip.c:281 Modules linked in: CPU: 0 PID: 4406 Comm: syz-executor.1 Not tainted 6.8.0-12821-g537c2e91d354-dirty #11 Hardware name: linux,dummy-virt (DT) pstate: 80400005 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] pc : pskb_may_pull include/linux/skbuff.h:2756 [inline] pc : pskb_network_may_pull include/linux/skbuff.h:3077 [inline] pc : pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] pc : ipip_tunnel_xmit+0x2d4/0x430 net/ipv4/ipip.c:281 lr : pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] lr : pskb_may_pull include/linux/skbuff.h:2756 [inline] lr : pskb_network_may_pull include/linux/skbuff.h:3077 [inline] lr : pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] lr : ipip_tunnel_xmit+0x2d4/0x430 net/ipv4/ipip.c:281 sp : ffff8000a82673f0 x29: ffff8000a82673f0 x28: ffff00000fc24140 x27: ffff00006ab166ba x26: 1fffe00001f8483e x25: dfff800000000000 x24: ffff00003b898080 x23: 0000000000000000 x22: 00000000fffffff6 x21: ffff00000fc241f4 x20: ffff00000fc24140 x19: ffff000046206000 x18: ffff800086d72d10 x17: 00000000008a008a x16: 008a4f8900000000 x15: 0000000000000001 x14: 1ffff00011028fbc x13: 0000000000000004 x12: 0000000000000001 x11: 0000000000040000 x10: 0000000000000f68 x9 : ffff80008d25a000 x8 : 0000000000000f69 x7 : ffff8000800477bc x6 : ffff8000800479b8 x5 : ffff0000687ca948 x4 : ffff8000a8267028 x3 : ffff800083f7f890 x2 : 0000000000000001 x1 : 00000000fffffff6 x0 : 0000000000000000 Call trace: pskb_may_pull_reason include/linux/skbuff.h:2740 [inline] pskb_may_pull include/linux/skbuff.h:2756 [inline] pskb_network_may_pull include/linux/skbuff.h:3077 [inline] pskb_inet_may_pull include/net/ip_tunnels.h:361 [inline] ipip_tunnel_xmit+0x2d4/0x430 net/ipv4/ipip.c:281 __netdev_start_xmit include/linux/netdevice.h:4903 [inline] netdev_start_xmit include/linux/netdevice.h:4917 [inline] xmit_one net/core/dev.c:3531 [inline] dev_hard_start_xmit+0x1a0/0x370 net/core/dev.c:3547 __dev_queue_xmit+0x12e8/0x2b04 net/core/dev.c:4335 dev_queue_xmit include/linux/netdevice.h:3091 [inline] packet_xmit+0x6c/0x31c net/packet/af_packet.c:276 packet_snd net/packet/af_packet.c:3081 [inline] packet_sendmsg+0x3818/0x4e50 net/packet/af_packet.c:3113 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg net/socket.c:745 [inline] __sys_sendto+0x324/0x470 net/socket.c:2191 __do_sys_sendto net/socket.c:2203 [inline] __se_sys_sendto net/socket.c:2199 [inline] __arm64_sys_sendto+0xd8/0xf8 net/socket.c:2199 __invoke_syscall arch/arm64/kernel/syscall.c:34 [inline] invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:48 el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:133 do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:152 el0_svc+0x30/0x78 arch/arm64/kernel/entry-common.c:712 el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:730 el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:598 Reported-by: syzkaller Fixes: cb9f1b783850 ("ip: validate header length on virtual device xmit") Signed-off-by: Kuniyuki Iwashima --- net/ipv4/ipip.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c index f2696eaadbe6..3f96364d65fd 100644 --- a/net/ipv4/ipip.c +++ b/net/ipv4/ipip.c @@ -278,11 +278,11 @@ static netdev_tx_t ipip_tunnel_xmit(struct sk_buff *skb, const struct iphdr *tiph = &tunnel->parms.iph; u8 ipproto; - if (!pskb_inet_may_pull(skb)) - goto tx_error; - switch (skb->protocol) { case htons(ETH_P_IP): + if (!pskb_network_may_pull(skb, sizeof(struct iphdr))) + goto tx_error; + ipproto = IPPROTO_IPIP; break; #if IS_ENABLED(CONFIG_MPLS) From patchwork Mon Apr 15 22:20:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13630779 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) (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 44F10157485 for ; Mon, 15 Apr 2024 22:23:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.95.48.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713219784; cv=none; b=qa4KuD+rHNKbDJCb5ak/uZxqx8u+X2LQEQRdoqdoKPz135hxL+i5bqyFQ4GDGKzGeX/o0h/4K76Do4gDy4Rw5PbTSQwmKHKFAbDNapQJQ527du7xpTPVq6q2DyB5A4HeAgV9O4Esc3SB2rRQdrux9X2i/XjVpzV3xpMlnVMFkhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713219784; c=relaxed/simple; bh=rZNaumpJL8qQby42EPMBwsW5Bd2biWX7ivgCd0YiQkE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qcBYbN0UjiaThQwHAHtAoFQWay73suIV6A5IcWdGesXWIf+DNv/90nWSsIxMgE1Rhnr3wgeh8abp6Dt+4I+IsHqXN9uuhTHO+Dpsch/rttvke5x53UGT8v5hTQ/rxYiXthSIwnkuZSGoO/B6+bhb5ItLQ1m2R//t30AFmXWMQNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=IOTjPFG8; arc=none smtp.client-ip=52.95.48.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="IOTjPFG8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1713219784; x=1744755784; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KtIcr0SRhWnHUSyoZdWCkujc54b2qlsMzNxwvJkWJuE=; b=IOTjPFG82QDifXpRLqFtC9K6aNNQ0idyQI47qdD2S63iMHXwcvLaqAqp BRRQmQJi4LLJ/5FnDmrdRTrVS4QInVnXqt6S4u5RPyaAMgPEsy5kuqlnH IoIoEGxhWnnbLddmjKfI1WmekBUkQiPv66v+dZoLgFYEDVd54rBahKzIa s=; X-IronPort-AV: E=Sophos;i="6.07,204,1708387200"; d="scan'208";a="389775525" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-6001.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2024 22:23:01 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.38.20:26230] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.6.244:2525] with esmtp (Farcaster) id 75209ee7-56e7-47b1-b2da-9a8c1b99f0c4; Mon, 15 Apr 2024 22:22:59 +0000 (UTC) X-Farcaster-Flow-ID: 75209ee7-56e7-47b1-b2da-9a8c1b99f0c4 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 15 Apr 2024 22:22:59 +0000 Received: from 88665a182662.ant.amazon.com (10.106.101.23) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 15 Apr 2024 22:22:56 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern CC: Steffen Klassert , Herbert Xu , Willem de Bruijn , Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net 5/5] ip6_tunnel: Pull header after checking skb->protocol in ip6_tnl_start_xmit(). Date: Mon, 15 Apr 2024 15:20:41 -0700 Message-ID: <20240415222041.18537-6-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240415222041.18537-1-kuniyu@amazon.com> References: <20240415222041.18537-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D044UWB003.ant.amazon.com (10.13.139.168) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org syzkaller demonstrated the underflow in pskb_network_may_pull() by sending a crafted VLAN packet over tunnel devices: sit, ipip, vti, and vti6. The same warning will be triggered for ip6tnl, so let's check skb->protocol before pulling the next header in ip6_tnl_start_xmit(). Fixes: cb9f1b783850 ("ip: validate header length on virtual device xmit") Signed-off-by: Kuniyuki Iwashima --- net/ipv6/ip6_tunnel.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index e9cc315832cb..81be7a5be6c5 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -1424,14 +1424,17 @@ ip6_tnl_start_xmit(struct sk_buff *skb, struct net_device *dev) u8 ipproto; int ret; - if (!pskb_inet_may_pull(skb)) - goto tx_err; - switch (skb->protocol) { case htons(ETH_P_IP): + if (!pskb_network_may_pull(skb, sizeof(struct iphdr))) + goto tx_err; + ipproto = IPPROTO_IPIP; break; case htons(ETH_P_IPV6): + if (!pskb_network_may_pull(skb, sizeof(struct ipv6hdr))) + goto tx_err; + if (ip6_tnl_addr_conflict(t, ipv6_hdr(skb))) goto tx_err; ipproto = IPPROTO_IPV6;