Received: by 10.192.165.156 with SMTP id m28csp19427imm; Tue, 10 Apr 2018 15:30:20 -0700 (PDT) X-Google-Smtp-Source: AIpwx49xx58pdGVDQ08q3BQAQqdx8qrDt1S28jQtgMZ4b0sSfvbJldJBU6lEs08wLbpLykpGz8hG X-Received: by 10.167.131.217 with SMTP id j25mr1806676pfn.5.1523399420905; Tue, 10 Apr 2018 15:30:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523399420; cv=none; d=google.com; s=arc-20160816; b=qQstS2HheQUdjCpOq898gA9WnzEfaZ4n6a+e1PX+INyCfH+A9aXyZuP1irOP7xkrbd 5J2VRJg+dapRW7rTD0lZDBjq/91VIC0M1XJkmm9jNcsCJn0KRQxwqXogMdPjWl1Ejsk8 w8ht/6pnl1tItBjR4WxGLqiRrooL0mhkZvHNWx1JluRl9DCUV85tGlrN+6KAOpGESbtZ EY8iNf6llbYnZ8CjJ1cnqPRAfZ99g6tppyoYlgVtU8FDDZ5l+yANAUjidbk0zNazPTzh dLjUGdVUbIz2QpSTVA8CuxSMR8fRjDCWUXbTP5hn7lWaJ9O0aiW1Jfk/3Ab1ATNFTimf NOAQ== 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=PGxSG3D/HG/3mTLTy2/D+ZltJW6DBNsUORCWkbykswA=; b=pvZe/T1uaphLvM8DidFl6+a0lrq6fROLqPYyHsZdyu71hy0PXLGNtdkJVOxy9+Gu3J u6r/ZTrPf4uffB1aY5/Mu2feGcXNjZwnHzUf4DXV5dugjSNN3iMOWktKQf4oQ65GLZam 7Gn0Bf9eZ6nSFmN3kbtxNjef5jIBlEb1b7HUXwj7fyF/JjDYfZkOPX7Qpa2bsUAdgU0X x/+fC+RxLpYr00iBGkp+13FTO0t/ObES9UyK89HWJ+W7nSjFZPx3/bjsM0E6J+E7aPOn NDkwR9QD/LWUC+ZB1mVXaeAmr6/+8MukvWrVH1gSLSoTJhLfGqvugd2pShAA7/Y11wRr WmVg== 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 65-v6si3448925plb.573.2018.04.10.15.29.43; Tue, 10 Apr 2018 15:30:20 -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 S1752820AbeDJWY4 (ORCPT + 99 others); Tue, 10 Apr 2018 18:24:56 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36904 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752796AbeDJWYx (ORCPT ); Tue, 10 Apr 2018 18:24:53 -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 4464BD66; Tue, 10 Apr 2018 22:24:52 +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 4.16 14/18] ip6_gre: better validate user provided tunnel names Date: Wed, 11 Apr 2018 00:23:49 +0200 Message-Id: <20180410212759.338481628@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180410212758.564682823@linuxfoundation.org> References: <20180410212758.564682823@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 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 5f42df013b8bc1b6511af7a04bf93b014884ae2a ] 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 ip6gre_tunnel_locate+0x334/0x860 net/ipv6/ip6_gre.c:339 Write of size 20 at addr ffff8801afb9f7b8 by task syzkaller851048/4466 CPU: 1 PID: 4466 Comm: syzkaller851048 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] ip6gre_tunnel_locate+0x334/0x860 net/ipv6/ip6_gre.c:339 ip6gre_tunnel_ioctl+0x69d/0x12e0 net/ipv6/ip6_gre.c:1195 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: c12b395a4664 ("gre: Support GRE over IPv6") Signed-off-by: Eric Dumazet Reported-by: syzbot Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv6/ip6_gre.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -335,11 +335,13 @@ static struct ip6_tnl *ip6gre_tunnel_loc if (t || !create) return t; - if (parms->name[0]) + if (parms->name[0]) { + if (!dev_valid_name(parms->name)) + return NULL; strlcpy(name, parms->name, IFNAMSIZ); - else + } else { strcpy(name, "ip6gre%d"); - + } dev = alloc_netdev(sizeof(*t), name, NET_NAME_UNKNOWN, ip6gre_tunnel_setup); if (!dev)