Received: by 10.213.65.68 with SMTP id h4csp1794883imn; Thu, 29 Mar 2018 11:09:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx49O2m4CdMtyu2kgENJYhnA5pHJAs2CVP6S44jp476vkFZlhzVlhEN0Rt+0/tKYeCXMourC6 X-Received: by 2002:a17:902:6b02:: with SMTP id o2-v6mr9624940plk.334.1522346969471; Thu, 29 Mar 2018 11:09:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522346969; cv=none; d=google.com; s=arc-20160816; b=jnfjFMAP09AWmSbsHszKw35+fxfgFUMjtBWRyzbH+xdyl4Ca2fpzrEE2PYBz0joyPw z1pEfKJsqdmBiTzs7j5611MVAJ+O1D5dOJJo3AW5NPs/y1VB+ET+KmRZIwlXyqHAwYk8 HGsXIEpSVHE5KIG7XFPaZuvZAbmuMvgXqhFfaeIr7b9v4hdO0SczCqGc/i4vBf+32NnF WGAkR0OsJNaONVfqAHSwmoCfSfWDg2X+yTywZUNzHS+zaeOMqw/0NksoSsiJOGXdqGce L8/jUrYed0ixbm0d8Y3SZ8cyKSrEQY5n7EkYXYt+XqiPhEqBwsR6CJvfS0yQ2PiVfVmz pOXA== 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=8E9HWXFSCs6I99c4at4UySf2uX8gvGrhEF9rHHGiaXY=; b=q46+p9dk/FyBUEbvmMxuB17rKiYpPl9tVIP7aK6lEE7lDUwvym4WJt5JHt8qGDVEdm Ril7WPMemPp2bVRmTgcjJ5U4Z5R9n2NwvCAtZzaGH9fPtblK9kK/lZAs+dbuaNkA4R6H 7bc9d59lRXWog2R5S4F1hKggRp+FFzT0CB6dsOUNrsn5z1TVyL1EbJoRwKfBrrGNyHqr XIeSfYwy9tNOTmcgN/kMM1qZ3verfpHwj6wLJDmGSnMzGsfv2+wRDAMYIZ1T7GrkBv/H pCzCgbctex1+CUplwW7OcGU26rqw1cwCAA1rS09YrMY5Qlkzch3bkb8f339GuIdpmqFL nP/g== 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 g7si4851339pfm.106.2018.03.29.11.09.15; Thu, 29 Mar 2018 11:09:29 -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 S1754195AbeC2SIA (ORCPT + 99 others); Thu, 29 Mar 2018 14:08:00 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60440 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754076AbeC2SH4 (ORCPT ); Thu, 29 Mar 2018 14:07:56 -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 320CFBB6; Thu, 29 Mar 2018 18:07:55 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guillaume Nault , James Chapman , Eric Dumazet , syzbot , "David S. Miller" Subject: [PATCH 4.4 06/20] l2tp: do not accept arbitrary sockets Date: Thu, 29 Mar 2018 20:00:42 +0200 Message-Id: <20180329175742.147256854@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180329175741.886181131@linuxfoundation.org> References: <20180329175741.886181131@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 17cfe79a65f98abe535261856c5aef14f306dff7 ] syzkaller found an issue caused by lack of sufficient checks in l2tp_tunnel_create() RAW sockets can not be considered as UDP ones for instance. In another patch, we shall replace all pr_err() by less intrusive pr_debug() so that syzkaller can find other bugs faster. Acked-by: Guillaume Nault Acked-by: James Chapman ================================================================== BUG: KASAN: slab-out-of-bounds in setup_udp_tunnel_sock+0x3ee/0x5f0 net/ipv4/udp_tunnel.c:69 dst_release: dst:00000000d53d0d0f refcnt:-1 Write of size 1 at addr ffff8801d013b798 by task syz-executor3/6242 CPU: 1 PID: 6242 Comm: syz-executor3 Not tainted 4.16.0-rc2+ #253 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+0x194/0x24d lib/dump_stack.c:53 print_address_description+0x73/0x250 mm/kasan/report.c:256 kasan_report_error mm/kasan/report.c:354 [inline] kasan_report+0x23b/0x360 mm/kasan/report.c:412 __asan_report_store1_noabort+0x17/0x20 mm/kasan/report.c:435 setup_udp_tunnel_sock+0x3ee/0x5f0 net/ipv4/udp_tunnel.c:69 l2tp_tunnel_create+0x1354/0x17f0 net/l2tp/l2tp_core.c:1596 pppol2tp_connect+0x14b1/0x1dd0 net/l2tp/l2tp_ppp.c:707 SYSC_connect+0x213/0x4a0 net/socket.c:1640 SyS_connect+0x24/0x30 net/socket.c:1621 do_syscall_64+0x280/0x940 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x42/0xb7 Fixes: fd558d186df2 ("l2tp: Split pppol2tp patch into separate l2tp and ppp parts") Signed-off-by: Eric Dumazet Reported-by: syzbot Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/l2tp/l2tp_core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -1518,9 +1518,14 @@ int l2tp_tunnel_create(struct net *net, encap = cfg->encap; /* Quick sanity checks */ + err = -EPROTONOSUPPORT; + if (sk->sk_type != SOCK_DGRAM) { + pr_debug("tunl %hu: fd %d wrong socket type\n", + tunnel_id, fd); + goto err; + } switch (encap) { case L2TP_ENCAPTYPE_UDP: - err = -EPROTONOSUPPORT; if (sk->sk_protocol != IPPROTO_UDP) { pr_err("tunl %hu: fd %d wrong protocol, got %d, expected %d\n", tunnel_id, fd, sk->sk_protocol, IPPROTO_UDP); @@ -1528,7 +1533,6 @@ int l2tp_tunnel_create(struct net *net, } break; case L2TP_ENCAPTYPE_IP: - err = -EPROTONOSUPPORT; if (sk->sk_protocol != IPPROTO_L2TP) { pr_err("tunl %hu: fd %d wrong protocol, got %d, expected %d\n", tunnel_id, fd, sk->sk_protocol, IPPROTO_L2TP);