Received: by 10.223.176.5 with SMTP id f5csp3408120wra; Mon, 29 Jan 2018 12:45:03 -0800 (PST) X-Google-Smtp-Source: AH8x226tRYeJKREYXAhqnNPnTn/7Tr+ujpti8K0JdTyOc8a0GmkU3gQOzgUHRSVso4E/Tha24tQ5 X-Received: by 2002:a17:902:bc3:: with SMTP id 61-v6mr20823788plr.407.1517258703505; Mon, 29 Jan 2018 12:45:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517258703; cv=none; d=google.com; s=arc-20160816; b=dOMqj2WG5OszIRh2m87kgSBGckocOBigyZSeiDUc5gPDqJnQ138CbLpgSvufiKguva 2XWp8d9yzOoytBwODr2Hthalf/2xVljfW6o3CJVOAB3eHHETF38eFiVnudwaMFGS8+Bk y+iZU+AHBMFGYFppAomt99moGECObmEVF1savcaQlYJR+4RUup4Jmh60taEphoB5KnPN unx6l14tliUJZgEXvVqHn1KgPrxy+5dqh7Z6YRupz9PbcmVSfAd2ZtHPp+NOOHp46jYC 7Q7vUGcDdLiQx3vhlnudqWOwaWVOYSBY0g+pgOIytFliAMbK91W5BZ0GJb1gB9+c+h0k sTTw== 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=VuF6N5YJNnxPXTQTuz7QGtF5+rIRh+XmnDViMughAp4=; b=Eef26Mv3Nmt8k69UgrO2cic2gyPpzJHg1Yw/sfP6SfsCck8D64yn+B369kUF/X0MXU Ire0zlISgisQAjwMTJFirYxT+1d+1MA4adkNv4At/u2ewk82wb09McO4XAAB8hqrXoYu coQg74PLXisjfVQAEJN21zuSG3EadzA4PBoMMxxjyqY7pOaYWqMPXinHa9oOj7uJ7sE+ 5gZWoaHv0iPNjfT879oLw3aL0OUhd/xsGYhkNaAlWXRWrWMg1Y1UxpMXIMYjc7bb5sD2 D75MIuTh7QgMXxA/110XMPb3WsPIPK2O8fEGXDyUOoKNfBj++eOqiFTtG4m9M1jcKY6X lpuw== 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 n14si12704804pfh.229.2018.01.29.12.44.48; Mon, 29 Jan 2018 12:45:03 -0800 (PST) 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 S1754098AbeA2UnY (ORCPT + 99 others); Mon, 29 Jan 2018 15:43:24 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:35702 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753648AbeA2UMm (ORCPT ); Mon, 29 Jan 2018 15:12:42 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E31592F49; Mon, 29 Jan 2018 13:03:49 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Willem de Bruijn , syzbot , Jason Wang , "David S. Miller" Subject: [PATCH 4.4 73/74] flow_dissector: properly cap thoff field Date: Mon, 29 Jan 2018 13:57:18 +0100 Message-Id: <20180129123850.827330374@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123847.507563674@linuxfoundation.org> References: <20180129123847.507563674@linuxfoundation.org> User-Agent: quilt/0.65 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 d0c081b49137cd3200f2023c0875723be66e7ce5 ] syzbot reported yet another crash [1] that is caused by insufficient validation of DODGY packets. Two bugs are happening here to trigger the crash. 1) Flow dissection leaves with incorrect thoff field. 2) skb_probe_transport_header() sets transport header to this invalid thoff, even if pointing after skb valid data. 3) qdisc_pkt_len_init() reads out-of-bound data because it trusts tcp_hdrlen(skb) Possible fixes : - Full flow dissector validation before injecting bad DODGY packets in the stack. This approach was attempted here : https://patchwork.ozlabs.org/patch/ 861874/ - Have more robust functions in the core. This might be needed anyway for stable versions. This patch fixes the flow dissection issue. [1] CPU: 1 PID: 3144 Comm: syzkaller271204 Not tainted 4.15.0-rc4-mm1+ #49 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/0x257 lib/dump_stack.c:53 print_address_description+0x73/0x250 mm/kasan/report.c:256 kasan_report_error mm/kasan/report.c:355 [inline] kasan_report+0x23b/0x360 mm/kasan/report.c:413 __asan_report_load2_noabort+0x14/0x20 mm/kasan/report.c:432 __tcp_hdrlen include/linux/tcp.h:35 [inline] tcp_hdrlen include/linux/tcp.h:40 [inline] qdisc_pkt_len_init net/core/dev.c:3160 [inline] __dev_queue_xmit+0x20d3/0x2200 net/core/dev.c:3465 dev_queue_xmit+0x17/0x20 net/core/dev.c:3554 packet_snd net/packet/af_packet.c:2943 [inline] packet_sendmsg+0x3ad5/0x60a0 net/packet/af_packet.c:2968 sock_sendmsg_nosec net/socket.c:628 [inline] sock_sendmsg+0xca/0x110 net/socket.c:638 sock_write_iter+0x31a/0x5d0 net/socket.c:907 call_write_iter include/linux/fs.h:1776 [inline] new_sync_write fs/read_write.c:469 [inline] __vfs_write+0x684/0x970 fs/read_write.c:482 vfs_write+0x189/0x510 fs/read_write.c:544 SYSC_write fs/read_write.c:589 [inline] SyS_write+0xef/0x220 fs/read_write.c:581 entry_SYSCALL_64_fastpath+0x1f/0x96 Fixes: 34fad54c2537 ("net: __skb_flow_dissect() must cap its return value") Fixes: a6e544b0a88b ("flow_dissector: Jump to exit code in __skb_flow_dissect") Signed-off-by: Eric Dumazet Cc: Willem de Bruijn Reported-by: syzbot Acked-by: Jason Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/flow_dissector.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -492,8 +492,8 @@ ip_proto_again: out_good: ret = true; - key_control->thoff = (u16)nhoff; out: + key_control->thoff = min_t(u16, nhoff, skb ? skb->len : hlen); key_basic->n_proto = proto; key_basic->ip_proto = ip_proto; @@ -501,7 +501,6 @@ out: out_bad: ret = false; - key_control->thoff = min_t(u16, nhoff, skb ? skb->len : hlen); goto out; } EXPORT_SYMBOL(__skb_flow_dissect);