Received: by 10.192.165.156 with SMTP id m28csp1067701imm; Wed, 11 Apr 2018 11:49:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+8raS3TIrmXlx3VYSnYO/WQ6rMF1n7jGmrD/cwtOHvKwFAhXFNa5hCDrrUj/MVZr3xAT/B X-Received: by 2002:a17:902:8211:: with SMTP id x17-v6mr6188879pln.130.1523472590550; Wed, 11 Apr 2018 11:49:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523472590; cv=none; d=google.com; s=arc-20160816; b=HmjHggAVMcFTlX7j933d0+h8r8MR3MbnNsW5zUibJFc+oMF2AcoXp895shEtR+PZS9 9BTc/HQHsXRLCfahMotQxGhQ8c2hcTjCs2KcH4bshr7haCEcW8qGqSr3DoaQJjnRRxZk HJ+hPgrnKDw4HuMW852cokcTKb9uZnmme2GM1QrglPD6O1oxDqeeB5b6OXzvkaQAH0Kd gkX/2i/miFLaLUcsbk7CrEG+GewRB8LivTH6hZHFr61DSl5dNiYl3qZxd54XfplMPgBD 0G+4evO5VMFT7lq0cAz8ec8juEdg8j6Jp+1gVQ4tkThfUlySOrdv3U/IsN+KNr22CmjD G6Ng== 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 :arc-authentication-results; bh=hGwiUD1GzwE8d65Ys2UUq5Wx/9rGuf9j+BG3S6BLU7s=; b=rxdPxasAEcpCTBDz/5PsrD1gkIcNXnd+ylB/aBJru//L03CkaNZEIZ1bnjIXemTTHH SWtS3YwNNSGHPn97b5x5dk6xcOR2+HM/JdXjFmrwyQsyQ0jx0nzNISZwkvdUAdrCHn8t /T0a0T0cGx2gE6cs+XFKoJMoc1EQ/ISAVauM631QUnvZGQndTDuYkJNW+sazR8mWTIXt Ub5NbRyq+jpLlTs/8mjzk7OGVfBo/7D1ZvxzZCN0xv5wswUwHnobez3nLIOnz36kMkv+ lrG2UXJjNXluFMyL6e1nwMt1H3MNfCwItxQk6im2O3IlLmtP+2ZhxMhKnhKoFGMInCIZ 08xw== ARC-Authentication-Results: i=1; mx.google.com; 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 u20si1077069pgv.12.2018.04.11.11.49.12; Wed, 11 Apr 2018 11:49:50 -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; 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 S1755211AbeDKSnA (ORCPT + 99 others); Wed, 11 Apr 2018 14:43:00 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57402 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755178AbeDKSm6 (ORCPT ); Wed, 11 Apr 2018 14:42:58 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id CDE15E9B; Wed, 11 Apr 2018 18:42:57 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , "David S. Miller" Subject: [PATCH 3.18 114/121] ip_tunnel: better validate user provided tunnel names Date: Wed, 11 Apr 2018 20:36:57 +0200 Message-Id: <20180411183503.848923992@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183456.195010921@linuxfoundation.org> References: <20180411183456.195010921@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: Eric Dumazet [ Upstream commit 9cb726a212a82c88c98aa9f0037fd04777cd8fe5 ] Use dev_valid_name() to make sure user does not provide illegal device name. syzbot caught the following bug : BUG: KASAN: stack-out-of-bounds in strlcpy include/linux/string.h:300 [inline] BUG: KASAN: stack-out-of-bounds in __ip_tunnel_create+0xca/0x6b0 net/ipv4/ip_tunnel.c:257 Write of size 20 at addr ffff8801ac79f810 by task syzkaller268107/4482 CPU: 0 PID: 4482 Comm: syzkaller268107 Not tainted 4.16.0+ #1 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:17 [inline] dump_stack+0x1b9/0x29f lib/dump_stack.c:53 print_address_description+0x6c/0x20b mm/kasan/report.c:256 kasan_report_error mm/kasan/report.c:354 [inline] kasan_report.cold.7+0xac/0x2f5 mm/kasan/report.c:412 check_memory_region_inline mm/kasan/kasan.c:260 [inline] check_memory_region+0x13e/0x1b0 mm/kasan/kasan.c:267 memcpy+0x37/0x50 mm/kasan/kasan.c:303 strlcpy include/linux/string.h:300 [inline] __ip_tunnel_create+0xca/0x6b0 net/ipv4/ip_tunnel.c:257 ip_tunnel_create net/ipv4/ip_tunnel.c:352 [inline] ip_tunnel_ioctl+0x818/0xd40 net/ipv4/ip_tunnel.c:861 ipip_tunnel_ioctl+0x1c5/0x420 net/ipv4/ipip.c:350 dev_ifsioc+0x43e/0xb90 net/core/dev_ioctl.c:334 dev_ioctl+0x69a/0xcc0 net/core/dev_ioctl.c:525 sock_ioctl+0x47e/0x680 net/socket.c:1015 vfs_ioctl fs/ioctl.c:46 [inline] file_ioctl fs/ioctl.c:500 [inline] do_vfs_ioctl+0x1cf/0x1650 fs/ioctl.c:684 ksys_ioctl+0xa9/0xd0 fs/ioctl.c:701 SYSC_ioctl fs/ioctl.c:708 [inline] SyS_ioctl+0x24/0x30 fs/ioctl.c:706 do_syscall_64+0x29e/0x9d0 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x42/0xb7 Fixes: c54419321455 ("GRE: Refactor GRE tunneling code.") Signed-off-by: Eric Dumazet Reported-by: syzbot Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/ip_tunnel.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -302,13 +302,14 @@ static struct net_device *__ip_tunnel_cr struct net_device *dev; char name[IFNAMSIZ]; - if (parms->name[0]) + err = -E2BIG; + if (parms->name[0]) { + if (!dev_valid_name(parms->name)) + goto failed; strlcpy(name, parms->name, IFNAMSIZ); - else { - if (strlen(ops->kind) > (IFNAMSIZ - 3)) { - err = -E2BIG; + } else { + if (strlen(ops->kind) > (IFNAMSIZ - 3)) goto failed; - } strlcpy(name, ops->kind, IFNAMSIZ); strncat(name, "%d", 2); }