From patchwork Tue Aug 15 13:43:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Craig Gallek X-Patchwork-Id: 801599 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=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xWtwy50lNz9t32 for ; Tue, 15 Aug 2017 23:43:46 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752133AbdHONno (ORCPT ); Tue, 15 Aug 2017 09:43:44 -0400 Received: from mail-qt0-f169.google.com ([209.85.216.169]:37879 "EHLO mail-qt0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752038AbdHONnn (ORCPT ); Tue, 15 Aug 2017 09:43:43 -0400 Received: by mail-qt0-f169.google.com with SMTP id 16so4446990qtz.4 for ; Tue, 15 Aug 2017 06:43:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=X/4PcNAu3BmAuy/DRTINabTCJs1rYO58A5Dol1f8bNo=; b=AK7zJ7xH+a066C5WvbZH/q4LJzR4cnQEnXyrAzRS+n8QyowUDICvVLSwxVZE3z3oxY UJyycybtjdSFdjW7t8MDUNw10a2Iz+B7/f4TVWmJS4pVHX+surLM072pTDjObGjV187/ f4AGQuvYFnly+7Fg3zLY9xShV/I8z+MmhuttLGXm/HO0LX9421N591yQbL5dg9l3wsA4 tDTl0yy8U7VlhPT1QLpQWHNXZtjpYR1zM+Ahhn9P28dvC1OSFKPnxugF0qAuSnJDAFmp s6iibNFFCZQElnH9yTvi5mpPLT9l2oWgHSdOMjIDgg5rmrg1M8HlzAezinqPSmeAOOD+ jcTg== X-Gm-Message-State: AHYfb5icOkgLdcp/y8vt04eB7csHlfDnoBVGdG3mp1uZD0hqPjennNG3 P6COp8TOpCi8IGXq X-Received: by 10.237.53.83 with SMTP id b19mr35696841qte.312.1502804622519; Tue, 15 Aug 2017 06:43:42 -0700 (PDT) Received: from monkey.nyc.corp.google.com ([100.101.213.79]) by smtp.gmail.com with ESMTPSA id h32sm6703591qtk.27.2017.08.15.06.43.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Aug 2017 06:43:42 -0700 (PDT) From: Craig Gallek To: John Crispin , Andrew Lunn , "David S . Miller" Cc: Dmitry Vyukov , netdev@vger.kernel.org Subject: [PATCH net-next] dsa: fix flow disector null pointer Date: Tue, 15 Aug 2017 09:43:40 -0400 Message-Id: <20170815134340.169914-1-kraigatgoog@gmail.com> X-Mailer: git-send-email 2.14.0.434.g98096fd7a8-goog Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Craig Gallek A recent change to fix up DSA device behavior made the assumption that all skbs passing through the flow disector will be associated with a device. This does not appear to be a safe assumption. Syzkaller found the crash below by attaching a BPF socket filter that tries to find the payload offset of a packet passing between two unix sockets. kasan: GPF could be caused by NULL-ptr deref or user memory access general protection fault: 0000 [#1] SMP KASAN Dumping ftrace buffer: (ftrace buffer empty) Modules linked in: CPU: 0 PID: 2940 Comm: syzkaller872007 Not tainted 4.13.0-rc4-next-20170811 #1 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 task: ffff8801d1b425c0 task.stack: ffff8801d0bc0000 RIP: 0010:__skb_flow_dissect+0xdcd/0x3ae0 net/core/flow_dissector.c:445 RSP: 0018:ffff8801d0bc7340 EFLAGS: 00010206 RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000 RDX: 0000000000000060 RSI: ffffffff856dc080 RDI: 0000000000000300 RBP: ffff8801d0bc7870 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000008 R11: ffffed003a178f1e R12: 0000000000000000 R13: 0000000000000000 R14: ffffffff856dc080 R15: ffff8801ce223140 FS: 00000000016ed880(0000) GS:ffff8801dc000000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000020008000 CR3: 00000001ce22d000 CR4: 00000000001406f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: skb_flow_dissect_flow_keys include/linux/skbuff.h:1176 [inline] skb_get_poff+0x9a/0x1a0 net/core/flow_dissector.c:1079 ______skb_get_pay_offset net/core/filter.c:114 [inline] __skb_get_pay_offset+0x15/0x20 net/core/filter.c:112 Code: 80 3c 02 00 44 89 6d 10 0f 85 44 2b 00 00 4d 8b 67 20 48 b8 00 00 00 00 00 fc ff df 49 8d bc 24 00 03 00 00 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 13 2b 00 00 4d 8b a4 24 00 03 00 00 4d 85 e4 RIP: __skb_flow_dissect+0xdcd/0x3ae0 net/core/flow_dissector.c:445 RSP: ffff8801d0bc7340 Fixes: 43e665287f93 ("net-next: dsa: fix flow dissection") Reported-by: Dmitry Vyukov Signed-off-by: Craig Gallek Reviewed-by: Andrew Lunn --- net/core/flow_dissector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index 79b9c06c83ad..e2eaa1ff948d 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -442,7 +442,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, nhoff = skb_network_offset(skb); hlen = skb_headlen(skb); #if IS_ENABLED(CONFIG_NET_DSA) - if (unlikely(netdev_uses_dsa(skb->dev))) { + if (unlikely(skb->dev && netdev_uses_dsa(skb->dev))) { const struct dsa_device_ops *ops; int offset;