{"id":807234,"url":"http://patchwork.ozlabs.org/api/1.2/patches/807234/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/1504033335-19098-1-git-send-email-nikolay@cumulusnetworks.com/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/1.2/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1504033335-19098-1-git-send-email-nikolay@cumulusnetworks.com>","list_archive_url":null,"date":"2017-08-29T19:02:15","name":"[net] sch_hhf: fix null pointer dereference on init failure","commit_ref":null,"pull_url":null,"state":"superseded","archived":true,"hash":"96ded3079d0cb0c6fb6612786dbb9f90af022b6b","submitter":{"id":66448,"url":"http://patchwork.ozlabs.org/api/1.2/people/66448/?format=json","name":"Nikolay Aleksandrov","email":"nikolay@cumulusnetworks.com"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/1.2/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/1504033335-19098-1-git-send-email-nikolay@cumulusnetworks.com/mbox/","series":[{"id":441,"url":"http://patchwork.ozlabs.org/api/1.2/series/441/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=441","date":"2017-08-29T19:02:15","name":"[net] sch_hhf: fix null pointer dereference on init failure","version":1,"mbox":"http://patchwork.ozlabs.org/series/441/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/807234/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/807234/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=cumulusnetworks.com\n\theader.i=@cumulusnetworks.com header.b=\"GsIjI8t9\"; \n\tdkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xhdLG2Pb9z9s7m\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 30 Aug 2017 05:02:30 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751455AbdH2TC1 (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tTue, 29 Aug 2017 15:02:27 -0400","from mail-wm0-f51.google.com ([74.125.82.51]:35233 \"EHLO\n\tmail-wm0-f51.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1751415AbdH2TCW (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Tue, 29 Aug 2017 15:02:22 -0400","by mail-wm0-f51.google.com with SMTP id a80so3016113wma.0\n\tfor <netdev@vger.kernel.org>; Tue, 29 Aug 2017 12:02:22 -0700 (PDT)","from debil.mediahub-bg.com (46-10-142-144.ip.btc-net.bg.\n\t[46.10.142.144]) by smtp.gmail.com with ESMTPSA id\n\tt8sm3178849wrg.21.2017.08.29.12.02.19\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tTue, 29 Aug 2017 12:02:19 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=cumulusnetworks.com; s=google;\n\th=from:to:cc:subject:date:message-id;\n\tbh=G9uaTRFHwLa+Uf5fje/leA71I4KMjT4JT/tTUoM5Zz8=;\n\tb=GsIjI8t9EQxXohPuij5GIi/yaz+FgcdkBaC3LFXR+zQGFvcICRhOfbxKlw6klFeUv5\n\tbsN6Nq+UG5fNNxf+2N5RDtYS+l59TyPddyzLcXZlozaOXOTQexm1FohRA94mIZxGvkKw\n\tR0tTxeAG6xvXRHSYnaRRZ0sKnBs11iSIu0D60=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id;\n\tbh=G9uaTRFHwLa+Uf5fje/leA71I4KMjT4JT/tTUoM5Zz8=;\n\tb=VtWn0Qo2LWk/KGbVbyRe7JDrKrE7TcyISbZcZNxvfnoXdjKLyhgR36LP0SRrNjpCH5\n\tvFkTihGiSpJf9FJzLht7OsMqfH91uaRSrfoYS5snbQlBDPc8qGRA5zzWd+KbJE2Du5pw\n\tkiC82486JwD3kmfdhaOlWlevEjYz4gom4SQoRq35hTwEpoMUsSpklihQOcnKA8uC8vvL\n\tZXsNABBToN1SDTAysuO62hckaSAWET1vx95Svm9N5S1LEwKOGsQ+H/v3QZn2st4L2QUy\n\tpZ47RpLwD5PAkHT+Q+trJBDhcx0tTKP0yBB/5g3FPqfKnAPkCPcwJLNPN8FQDZs0rn36\n\t9Dzw==","X-Gm-Message-State":"AHYfb5gjdzZ/Vykwrq3c9/hdD42qu/FwlsbPhWctZ4bKfQmaK/fP2wMR\n\tIlzkUI3b4aUuEtG2AI0=","X-Received":"by 10.28.181.143 with SMTP id e137mr343188wmf.68.1504033341111; \n\tTue, 29 Aug 2017 12:02:21 -0700 (PDT)","From":"Nikolay Aleksandrov <nikolay@cumulusnetworks.com>","To":"netdev@vger.kernel.org","Cc":"edumazet@google.com, jhs@mojatatu.com, xiyou.wangcong@gmail.com,\n\tjiri@resnulli.us, roopa@cumulusnetworks.com,\n\tNikolay Aleksandrov <nikolay@cumulusnetworks.com>","Subject":"[PATCH net] sch_hhf: fix null pointer dereference on init failure","Date":"Tue, 29 Aug 2017 22:02:15 +0300","Message-Id":"<1504033335-19098-1-git-send-email-nikolay@cumulusnetworks.com>","X-Mailer":"git-send-email 2.1.4","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"If sch_hhf fails in its ->init() function (either due to wrong\nuser-space arguments as below or memory alloc failure of hh_flows) it\nwill do a null pointer deref of q->hh_flows in its ->destroy() function.\n\nTo reproduce the crash:\n$ tc qdisc add dev eth0 root hhf quantum 2000000 non_hh_weight 10000000\n\nCrash log:\n[  690.654882] BUG: unable to handle kernel NULL pointer dereference at (null)\n[  690.655565] IP: hhf_destroy+0x48/0xbc\n[  690.655944] PGD 37345067\n[  690.655948] P4D 37345067\n[  690.656252] PUD 58402067\n[  690.656554] PMD 0\n[  690.656857]\n[  690.657362] Oops: 0000 [#1] SMP\n[  690.657696] Modules linked in:\n[  690.658032] CPU: 3 PID: 920 Comm: tc Not tainted 4.13.0-rc6+ #57\n[  690.658525] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.7.5-20140531_083030-gandalf 04/01/2014\n[  690.659255] task: ffff880058578000 task.stack: ffff88005acbc000\n[  690.659747] RIP: 0010:hhf_destroy+0x48/0xbc\n[  690.660146] RSP: 0018:ffff88005acbf9e0 EFLAGS: 00010246\n[  690.660601] RAX: 0000000000000000 RBX: 0000000000000020 RCX: 0000000000000000\n[  690.661155] RDX: 0000000000000000 RSI: 0000000000000001 RDI: ffffffff821f63f0\n[  690.661710] RBP: ffff88005acbfa08 R08: ffffffff81b10a90 R09: 0000000000000000\n[  690.662267] R10: 00000000f42b7019 R11: ffff880058578000 R12: 00000000ffffffea\n[  690.662820] R13: ffff8800372f6400 R14: 0000000000000000 R15: 0000000000000000\n[  690.663769] FS:  00007f8ae5e8b740(0000) GS:ffff88005d980000(0000) knlGS:0000000000000000\n[  690.667069] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033\n[  690.667965] CR2: 0000000000000000 CR3: 0000000058523000 CR4: 00000000000406e0\n[  690.668918] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000\n[  690.669945] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400\n[  690.671003] Call Trace:\n[  690.671743]  qdisc_create+0x377/0x3fd\n[  690.672534]  tc_modify_qdisc+0x4d2/0x4fd\n[  690.673324]  rtnetlink_rcv_msg+0x188/0x197\n[  690.674204]  ? rcu_read_unlock+0x3e/0x5f\n[  690.675091]  ? rtnl_newlink+0x729/0x729\n[  690.675877]  netlink_rcv_skb+0x6c/0xce\n[  690.676648]  rtnetlink_rcv+0x23/0x2a\n[  690.677405]  netlink_unicast+0x103/0x181\n[  690.678179]  netlink_sendmsg+0x326/0x337\n[  690.678958]  sock_sendmsg_nosec+0x14/0x3f\n[  690.679743]  sock_sendmsg+0x29/0x2e\n[  690.680506]  ___sys_sendmsg+0x209/0x28b\n[  690.681283]  ? __handle_mm_fault+0xc7d/0xdb1\n[  690.681915]  ? check_chain_key+0xb0/0xfd\n[  690.682449]  __sys_sendmsg+0x45/0x63\n[  690.682954]  ? __sys_sendmsg+0x45/0x63\n[  690.683471]  SyS_sendmsg+0x19/0x1b\n[  690.683974]  entry_SYSCALL_64_fastpath+0x23/0xc2\n[  690.684516] RIP: 0033:0x7f8ae529d690\n[  690.685016] RSP: 002b:00007fff26d2d6b8 EFLAGS: 00000246 ORIG_RAX: 000000000000002e\n[  690.685931] RAX: ffffffffffffffda RBX: ffffffff810d278c RCX: 00007f8ae529d690\n[  690.686573] RDX: 0000000000000000 RSI: 00007fff26d2d700 RDI: 0000000000000003\n[  690.687047] RBP: ffff88005acbff98 R08: 0000000000000001 R09: 0000000000000000\n[  690.687519] R10: 00007fff26d2d480 R11: 0000000000000246 R12: 0000000000000002\n[  690.687996] R13: 0000000001258070 R14: 0000000000000001 R15: 0000000000000000\n[  690.688475]  ? trace_hardirqs_off_caller+0xa7/0xcf\n[  690.688887] Code: 00 00 e8 2a 02 ae ff 49 8b bc 1d 60 02 00 00 48 83\nc3 08 e8 19 02 ae ff 48 83 fb 20 75 dc 45 31 f6 4d 89 f7 4d 03 bd 20 02\n00 00 <49> 8b 07 49 39 c7 75 24 49 83 c6 10 49 81 fe 00 40 00 00 75 e1\n[  690.690200] RIP: hhf_destroy+0x48/0xbc RSP: ffff88005acbf9e0\n[  690.690636] CR2: 0000000000000000\n\nFixes: 87b60cfacf9f (\"net_sched: fix error recovery at qdisc creation\")\nSigned-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>\n---\nFirst I did it with the check in the for () conditional, but this is more\nvisible and explicit. Let me know if you'd like the shorter version. :-)\n\n net/sched/sch_hhf.c | 20 +++++++++++---------\n 1 file changed, 11 insertions(+), 9 deletions(-)","diff":"diff --git a/net/sched/sch_hhf.c b/net/sched/sch_hhf.c\nindex 51d3ba682af9..931c6cc23ac2 100644\n--- a/net/sched/sch_hhf.c\n+++ b/net/sched/sch_hhf.c\n@@ -477,15 +477,17 @@ static void hhf_destroy(struct Qdisc *sch)\n \t\tkvfree(q->hhf_valid_bits[i]);\n \t}\n \n-\tfor (i = 0; i < HH_FLOWS_CNT; i++) {\n-\t\tstruct hh_flow_state *flow, *next;\n-\t\tstruct list_head *head = &q->hh_flows[i];\n-\n-\t\tif (list_empty(head))\n-\t\t\tcontinue;\n-\t\tlist_for_each_entry_safe(flow, next, head, flowchain) {\n-\t\t\tlist_del(&flow->flowchain);\n-\t\t\tkfree(flow);\n+\tif (q->hh_flows) {\n+\t\tfor (i = 0; i < HH_FLOWS_CNT; i++) {\n+\t\t\tstruct hh_flow_state *flow, *next;\n+\t\t\tstruct list_head *head = &q->hh_flows[i];\n+\n+\t\t\tif (list_empty(head))\n+\t\t\t\tcontinue;\n+\t\t\tlist_for_each_entry_safe(flow, next, head, flowchain) {\n+\t\t\t\tlist_del(&flow->flowchain);\n+\t\t\t\tkfree(flow);\n+\t\t\t}\n \t\t}\n \t}\n \tkvfree(q->hh_flows);\n","prefixes":["net"]}