Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2283650imm; Thu, 7 Jun 2018 08:10:19 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKE0l3t5xY8cinbXzvxEd4nk2689yFYhy8+6TLmGVI1flmbA+m6kqJywO0UGIGY/9J1Q0bv X-Received: by 2002:a17:902:d711:: with SMTP id w17-v6mr2440410ply.200.1528384219018; Thu, 07 Jun 2018 08:10:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528384218; cv=none; d=google.com; s=arc-20160816; b=YNoJI7TahhBBExACyqHkcnvCp/i1GWYC5AugzmM1i+G45yb3LBd2VQ5zcD9n9x9EZc waPxuAbp+jTGFITjjONGD8h9/UZnBmbmH7okKFbV5l2KGSFj0nzzwR6aYRHiC1kHEPns sfR3hf4ocmgpq0fZefO2Q9Zwc2zEzItKIal2/STJ62cwSkmht6f8qTdMeqS+RIUedGKE frBLpknti1L2ZTjvpSaGOcyirTmZbc5aDpR/UBw6i1YceWxY7Qfaap4bzxe9TqpJ24Hf qoIDK3QNt8EYNgJYLwn91OixpXYSBZ3qsgb7hUIluqgcUzfdqzFOe9zoqdZS16opHfyO y0xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=U5qS+7PsOvfw2kOnLYtI5B3O5uoLnk9zBd4fH2XbPe8=; b=z6ZkF9nTnbC30WFN6gO/e889/xGs5t8VkFmuJli0RSDPiWpHNp56tZ3DljTAbPkUdc RxWMtewfcimFnGcDyq4thmsh8EePR7kFuxs2O5eFKNXUtyyq65hcSaW5q/SllUKvrUTq fHljMM3oZcv/HfmjUBXu8j2p5LlqFlqRcJxX0gbMVEB/vl0b5jh/jvfxvN7At1mXXLJt yKVXCvjLQVlxau/s3GLoo2RJ9/AD0XziFbqNobk/ADJMFEKI63fDFTwFIweeeBWD7M2c dTdFKL8Dr9MTAOiIbwdkM5eOcnM4nkWGS/yWF+5r4Q6BlRbar3vd6ENov1DIYKYOkeTo XO2g== 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 t5-v6si3320643pgr.690.2018.06.07.08.10.01; Thu, 07 Jun 2018 08:10:18 -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 S935623AbeFGPIg (ORCPT + 99 others); Thu, 7 Jun 2018 11:08:36 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41522 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935927AbeFGPDk (ORCPT ); Thu, 7 Jun 2018 11:03:40 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbS-0005hO-9s; Thu, 07 Jun 2018 15:09:26 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvbB-0003C6-TZ; Thu, 07 Jun 2018 15:09:09 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Guillaume Nault" , "Eric Dumazet" , "syzbot" , "David S. Miller" , "James Chapman" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 330/410] l2tp: do not accept arbitrary sockets In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet commit 17cfe79a65f98abe535261856c5aef14f306dff7 upstream. 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: Ben Hutchings --- 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 @@ -1581,9 +1581,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); @@ -1591,7 +1596,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);