Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2506593imm; Mon, 28 May 2018 09:21:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoYqUHQirWE+9LvgheqzBzThEmlM7ejFNx0LPCfDbKdj5mE/X0nZvq0/oMKdj3CwIiDPkba X-Received: by 2002:a62:2218:: with SMTP id i24-v6mr14117671pfi.53.1527524516830; Mon, 28 May 2018 09:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527524516; cv=none; d=google.com; s=arc-20160816; b=n1aFA5xg8WZKjjM9vC0d2BDT+4Q2ieZgsdoDiQBtMUGfaJxiU+j/15UHwKBQTmpvmd I1f11q427Xq37ci4NQJEM5jBsYwIvkC+NbmSbPwOcnZYmk1sIqBv+d862wug1EuN9PdW +qg9aZBN0PwCTuIalsznERAItEy2wujUbqljCkIAulKVW4SLHXh4DzL3OTZ+u6MulSp6 cfhsz1XXsaWZSFwU+SPnvgMakNUaTL+J+8AZaxU5v+P0ntlGHSBlCvRxVT8+5mzplEpO MAPPZpfznF40UG2OAqJlUzQd7uMlOI0sOz1+dA3ArwaCzlp3L4yIG/HGoHmGE4ggTMC2 EM9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=QHiU5UDSEulQOWezEAzUBt79rpRXbJegZwmv5ZEEzgc=; b=zEYXlwmO9HUspocZy9B7iMolE1ED1Ov8GNwd825PAVd7Xc0MtbqxpKQuLwvK03EhyG 8pZqwk8YyXteFYBSzDdoXm4WLY97MgG4yRTLrHHGWY2/ULHVEHPtoKcypV4XsB+UOK2D 4gGzxPM37At7ny7voUkI5uXG8vTtIFgDi7kDGzS0FDPIA0lGgCOhUAoeUFUQ+xG+XC74 uyHF7p0UnUKra4aVaX0v5qD1AmZVpGfjAwmij4SdEjegwvUoiVaIwUtfz5CPio5FujAt IEQ5VwkH6fCBt7eGTjF19gcIHRMy03YVuGOjLUT1Dj4UKZHi6AL7TcyuIT8V+wDcgsBE WaGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wRpGXw78; 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 b14-v6si14527300pgr.112.2018.05.28.09.21.42; Mon, 28 May 2018 09:21:56 -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=wRpGXw78; 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 S936692AbeE1QVJ (ORCPT + 99 others); Mon, 28 May 2018 12:21:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:60028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965019AbeE1KLu (ORCPT ); Mon, 28 May 2018 06:11:50 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 43988208A6; Mon, 28 May 2018 10:11:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502309; bh=NoIjtK+DqDG9PhEEW+CiQvNaVeietQbaELhAhl9e97M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wRpGXw78ZyxTo2KyWkEB0DCbwVzydAj+saU6B2I9L+DYxTFadI+/VeKJJpfF2S09F VeLVhkhpI1L4ML/G+h8IeRJh7wdAI0ijmkDWDXK7iGIliufnUto0RgHAugOhbYzw+7 Ommiw7SCr3DRI8mb2WM+fKJ5fYTnIb8HUawsx4vg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Toshiaki Makita , "David S. Miller" , Sasha Levin Subject: [PATCH 3.18 107/185] net: Fix untag for vlan packets without ethernet header Date: Mon, 28 May 2018 12:02:28 +0200 Message-Id: <20180528100100.574795974@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Toshiaki Makita [ Upstream commit ae4745730cf8e693d354ccd4dbaf59ea440c09a9 ] In some situation vlan packets do not have ethernet headers. One example is packets from tun devices. Users can specify vlan protocol in tun_pi field instead of IP protocol, and skb_vlan_untag() attempts to untag such packets. skb_vlan_untag() (more precisely, skb_reorder_vlan_header() called by it) however did not expect packets without ethernet headers, so in such a case size argument for memmove() underflowed and triggered crash. ==== BUG: unable to handle kernel paging request at ffff8801cccb8000 IP: __memmove+0x24/0x1a0 arch/x86/lib/memmove_64.S:43 PGD 9cee067 P4D 9cee067 PUD 1d9401063 PMD 1cccb7063 PTE 2810100028101 Oops: 000b [#1] SMP KASAN Dumping ftrace buffer: (ftrace buffer empty) Modules linked in: CPU: 1 PID: 17663 Comm: syz-executor2 Not tainted 4.16.0-rc7+ #368 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:__memmove+0x24/0x1a0 arch/x86/lib/memmove_64.S:43 RSP: 0018:ffff8801cc046e28 EFLAGS: 00010287 RAX: ffff8801ccc244c4 RBX: fffffffffffffffe RCX: fffffffffff6c4c2 RDX: fffffffffffffffe RSI: ffff8801cccb7ffc RDI: ffff8801cccb8000 RBP: ffff8801cc046e48 R08: ffff8801ccc244be R09: ffffed0039984899 R10: 0000000000000001 R11: ffffed0039984898 R12: ffff8801ccc244c4 R13: ffff8801ccc244c0 R14: ffff8801d96b7c06 R15: ffff8801d96b7b40 FS: 00007febd562d700(0000) GS:ffff8801db300000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffff8801cccb8000 CR3: 00000001ccb2f006 CR4: 00000000001606e0 DR0: 0000000020000000 DR1: 0000000020000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000600 Call Trace: memmove include/linux/string.h:360 [inline] skb_reorder_vlan_header net/core/skbuff.c:5031 [inline] skb_vlan_untag+0x470/0xc40 net/core/skbuff.c:5061 __netif_receive_skb_core+0x119c/0x3460 net/core/dev.c:4460 __netif_receive_skb+0x2c/0x1b0 net/core/dev.c:4627 netif_receive_skb_internal+0x10b/0x670 net/core/dev.c:4701 netif_receive_skb+0xae/0x390 net/core/dev.c:4725 tun_rx_batched.isra.50+0x5ee/0x870 drivers/net/tun.c:1555 tun_get_user+0x299e/0x3c20 drivers/net/tun.c:1962 tun_chr_write_iter+0xb9/0x160 drivers/net/tun.c:1990 call_write_iter include/linux/fs.h:1782 [inline] new_sync_write fs/read_write.c:469 [inline] __vfs_write+0x684/0x970 fs/read_write.c:482 vfs_write+0x189/0x510 fs/read_write.c:544 SYSC_write fs/read_write.c:589 [inline] SyS_write+0xef/0x220 fs/read_write.c:581 do_syscall_64+0x281/0x940 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x42/0xb7 RIP: 0033:0x454879 RSP: 002b:00007febd562cc68 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 RAX: ffffffffffffffda RBX: 00007febd562d6d4 RCX: 0000000000454879 RDX: 0000000000000157 RSI: 0000000020000180 RDI: 0000000000000014 RBP: 000000000072bea0 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff R13: 00000000000006b0 R14: 00000000006fc120 R15: 0000000000000000 Code: 90 90 90 90 90 90 90 48 89 f8 48 83 fa 20 0f 82 03 01 00 00 48 39 fe 7d 0f 49 89 f0 49 01 d0 49 39 f8 0f 8f 9f 00 00 00 48 89 d1 a4 c3 48 81 fa a8 02 00 00 72 05 40 38 fe 74 3b 48 83 ea 20 RIP: __memmove+0x24/0x1a0 arch/x86/lib/memmove_64.S:43 RSP: ffff8801cc046e28 CR2: ffff8801cccb8000 ==== We don't need to copy headers for packets which do not have preceding headers of vlan headers, so skip memmove() in that case. Fixes: 4bbb3e0e8239 ("net: Fix vlan untag for bridge and vlan_dev with reorder_hdr off") Reported-by: Eric Dumazet Signed-off-by: Toshiaki Makita Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/core/skbuff.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -4137,8 +4137,10 @@ static struct sk_buff *skb_reorder_vlan_ } mac_len = skb->data - skb_mac_header(skb); - memmove(skb_mac_header(skb) + VLAN_HLEN, skb_mac_header(skb), - mac_len - VLAN_HLEN - ETH_TLEN); + if (likely(mac_len > VLAN_HLEN + ETH_TLEN)) { + memmove(skb_mac_header(skb) + VLAN_HLEN, skb_mac_header(skb), + mac_len - VLAN_HLEN - ETH_TLEN); + } skb->mac_header += VLAN_HLEN; return skb; }