From patchwork Tue Mar 6 15:54:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 882137 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="uFQmqYLj"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zwhDk4c5nz9shg for ; Wed, 7 Mar 2018 02:55:02 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753308AbeCFPy7 (ORCPT ); Tue, 6 Mar 2018 10:54:59 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:41895 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750797AbeCFPy6 (ORCPT ); Tue, 6 Mar 2018 10:54:58 -0500 Received: by mail-pg0-f67.google.com with SMTP id q27so8415159pgn.8 for ; Tue, 06 Mar 2018 07:54:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:mime-version :content-transfer-encoding; bh=eEC29dqMmavwtaRPVmIltcISc3KWk5JQptCBOx9/vH4=; b=uFQmqYLj93QquUfcJoj4TzA3ZCQ6r0q8dMW5GmCFdSTU5Oo9gYR32JxwCSWcS9QKEP RY2uEa/05e3Joae9p98L/8A+/qS+cIjCPUTUpJLoFpckPbkuCqnx7kbcmdx+Q675DYhQ xe/aQSkq34iupuJ5X7frOw4dsYrVFecEVNO8wq5kPwCRp7YewTOELqoqUO4SjBgVr+Da T9baIMzJK662Jvt8l6k+5ygcaqr/v/N5JAFI8kb0mQlE68znN5rbnNT3BlKdZVZThEaS wzKdhdQ1al/hOWuVsmpD0QK1j/lym9Zgq/yofrMme5YehiN6WPfyOfB7nLMTPuBvvoVg Q57g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:mime-version :content-transfer-encoding; bh=eEC29dqMmavwtaRPVmIltcISc3KWk5JQptCBOx9/vH4=; b=lsiYV1xqmQlSmtrc/dpCsoheoVpCx8hwUf3lTr1mliVakxrEy+K7gHqxgbSft4N2qX WvvzHxlCPmjAoHP/pUoA75t6NSqMsNgr4vnWDkrVCDwc0MEmcBQKs49g5bo+aJgC1Kr6 /8loOq5YcTrH2iVLm9RVAW0pa/mMPsPP+fD8kJTOBlZassteQIENuKIwNcEn/FbIfZAn ZS8bIjqGWYOqDhdY94T5ol2o2S3KQqPhDRyXnBYIK26s/7Q/Z2Ria25YtWB45GWqsP4C 7lvZAjFuFiV6DpkJHHbv/j24RINuNKKPGHT1yiA0o5MwsmOsnWl/rFs4FSkLoHg6oDoj FSEA== X-Gm-Message-State: APf1xPCcZi+4ZDuNYLjeC5dg42orzgb5RQr+8Ap1tiirDC1rA21n9fkt YPKlOawK9b7eah9EIW3ewkDENQ== X-Google-Smtp-Source: AG47ELvPxUwp9WfTDvUZxj2cHaP/K5J7Wx5gl//4L9ecTolrEdVtmU/VPPKg7uUmigvmNAeZ3YKmRQ== X-Received: by 10.101.65.131 with SMTP id a3mr15211802pgq.270.1520351697685; Tue, 06 Mar 2018 07:54:57 -0800 (PST) Received: from [10.1.104.57] ([207.198.105.19]) by smtp.googlemail.com with ESMTPSA id m3sm27886765pgs.90.2018.03.06.07.54.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Mar 2018 07:54:56 -0800 (PST) Message-ID: <1520351693.109662.17.camel@gmail.com> Subject: [PATCH net] l2tp: do not accept arbitrary sockets From: Eric Dumazet To: David Miller Cc: netdev , James Chapman , Guillaume Nault Date: Tue, 06 Mar 2018 07:54:53 -0800 X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eric Dumazet 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 ---  net/l2tp/l2tp_core.c |    8 ++++++--  1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index 83421c6f0bef1c48e35fe42000deea456ab1548d..e22512e328273b20b64d49390d0c583b2d960bb8 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -1457,9 +1457,14 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 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); @@ -1467,7 +1472,6 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 } 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);