From patchwork Thu Aug 23 06:50:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 144885 Delivered-To: patch@linaro.org Received: by 2002:a2e:164a:0:0:0:0:0 with SMTP id 10-v6csp756951ljw; Wed, 22 Aug 2018 23:50:59 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwiW0WFYFST2rfcb0cQJ7bGHuhHC/Qft+zIZU9nqdY9RLjBepyJNmo51Hg+nv26JAXkGdE0 X-Received: by 2002:a63:5e45:: with SMTP id s66-v6mr54569771pgb.151.1535007059373; Wed, 22 Aug 2018 23:50:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535007059; cv=none; d=google.com; s=arc-20160816; b=QZ3n1E8md+froP9WUlL1MMAZ41C94IfTUt+ph8/IzoFFJ4El4lJcC41fo0XLEx6wtT U/neiC4lSf9ZfeD3+FkNJAhits2zo82RwfIn4sDTQ8lVMXR7Ov0umWro9uzg8TKDT2F7 nJCvaFLLRA++zmFCS2rPp0eH6WOLpYfetju9cagbWV7gpgnfDzibQb2Tf/wRm21hhUER 0/Hk9vSPFUD3vQdflcZ7iQ/ETP2fQtwI8B9psPUXI8juBcf/vnPYLRJBT1bdYEPRdlWV hkhJ22n5tb1uyjs73HI4RHETY7WYKjxue4Q/9wZZI0xJBWbqGTt0HlhJI/JLUMa3n8M+ Chkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=f/C+senbndULJWNdGhdDtynwSqspcIgbzLuXwF13ouQ=; b=PJ0PRGh82Tycc/XTmKVI+9oHKwJKo2pdWo60rvKkWY7hMVN5rN9YGlldg3RHz7X2/2 ZVaGmUbIvA8TJjnGV99j5IwSyR8+yxd9A4yd7st6cXKnbs58DDJRdrUR+8I2GTW2Zbrp AXMA1eM9K66E7IOPGkqEOGAQZxLqGquG8sowEYSAO9acKVURvfjnGNuGvyHUUsQigKt7 rUQwIWOUGgeahmq//ErOHlugHkMTzc4uPtVzYETqhC683AVEcI47c29jGmGJ5gZ9AG5S mpKIpZfdq7Ooz6+7/qrNYC3Ee+lD5Hd1co4mSFYhno3LraYHswxifNkh2/J99XGxMToc 0ESw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F6EaWKmI; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cf13-v6si3685258plb.334.2018.08.22.23.50.59; Wed, 22 Aug 2018 23:50:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F6EaWKmI; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726182AbeHWKTH (ORCPT + 13 others); Thu, 23 Aug 2018 06:19:07 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:40273 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbeHWKTH (ORCPT ); Thu, 23 Aug 2018 06:19:07 -0400 Received: by mail-pg1-f196.google.com with SMTP id z25-v6so2092367pgu.7 for ; Wed, 22 Aug 2018 23:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=f/C+senbndULJWNdGhdDtynwSqspcIgbzLuXwF13ouQ=; b=F6EaWKmIw7GtFSUjeoOjpcdVFyHnU211KWisIKQEgNkShovUHW8q4vJP8xrYBeFJ9t Slb0GLKbvpJ2uz2N3TsChevNY2qtwHWG/sv5GhoEzcO+kz11z7TMDxLJ13k5JJNkwY6s a8PRauuybCkJC+Fxi36lrXCTPLvZnJCN+QNNA= 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:in-reply-to :references; bh=f/C+senbndULJWNdGhdDtynwSqspcIgbzLuXwF13ouQ=; b=DfBABhBO3GFX8INPxd89KGdxphQizjAWRtwoKvvPz8CqEJmUZoNUEAXpuw7l8a0MSA 6R4pe2+yOG23ofxNSCaYHUSOe0lumz6UrFihSbpC9y/O5PjdqYcSTK2q0AGwqa9+D9qB x0HzNEWvStYPvOL3RxS6ag687Aplezh8nj4jDKb1WDWUtP1E7uQuUf9PMG3NEDRM+eyY xfszEo5cIua3S5xNzh5Ezw1xQ1QKukLZ8Igepi/QDmd60/9L15P48iqMLv9oi620ggXb qjPwqvjdXOurOl8XK3Eqpp1rOXiNwCI7SY3R++pKYk9sUR3RgLCFXlwW3Ikm7v2mf/lf P6cg== X-Gm-Message-State: AOUpUlEabk4XeQxfypEJLrpH/SLvxV5v/e0SYEAbiaTZMPJCIKdqsnkf dRaIdULVuhmh+BkBDxOHtjAZzQ== X-Received: by 2002:a63:24c:: with SMTP id 73-v6mr55906516pgc.252.1535007057611; Wed, 22 Aug 2018 23:50:57 -0700 (PDT) Received: from localhost.localdomain ([49.207.48.21]) by smtp.gmail.com with ESMTPSA id l85-v6sm6274501pfk.34.2018.08.22.23.50.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Aug 2018 23:50:56 -0700 (PDT) From: Amit Pundir To: Greg KH , Nikolay Aleksandrov Cc: "David S . Miller" , Stable Subject: [PATCH v2 for-4.9.y 4/5] sch_netem: avoid null pointer deref on init failure Date: Thu, 23 Aug 2018 12:20:40 +0530 Message-Id: <1535007041-31605-5-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1535007041-31605-1-git-send-email-amit.pundir@linaro.org> References: <1535007041-31605-1-git-send-email-amit.pundir@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Nikolay Aleksandrov commit 634576a1844dba15bc5e6fc61d72f37e13a21615 upstream. netem can fail in ->init due to missing options (either not supplied by user-space or used as a default qdisc) causing a timer->base null pointer deref in its ->destroy() and ->reset() callbacks. Reproduce: $ sysctl net.core.default_qdisc=netem $ ip l set ethX up Crash log: [ 1814.846943] BUG: unable to handle kernel NULL pointer dereference at (null) [ 1814.847181] IP: hrtimer_active+0x17/0x8a [ 1814.847270] PGD 59c34067 [ 1814.847271] P4D 59c34067 [ 1814.847337] PUD 37374067 [ 1814.847403] PMD 0 [ 1814.847468] [ 1814.847582] Oops: 0000 [#1] SMP [ 1814.847655] Modules linked in: sch_netem(O) sch_fq_codel(O) [ 1814.847761] CPU: 3 PID: 1573 Comm: ip Tainted: G O 4.13.0-rc6+ #62 [ 1814.847884] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.7.5-20140531_083030-gandalf 04/01/2014 [ 1814.848043] task: ffff88003723a700 task.stack: ffff88005adc8000 [ 1814.848235] RIP: 0010:hrtimer_active+0x17/0x8a [ 1814.848407] RSP: 0018:ffff88005adcb590 EFLAGS: 00010246 [ 1814.848590] RAX: 0000000000000000 RBX: ffff880058e359d8 RCX: 0000000000000000 [ 1814.848793] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff880058e359d8 [ 1814.848998] RBP: ffff88005adcb5b0 R08: 00000000014080c0 R09: 00000000ffffffff [ 1814.849204] R10: ffff88005adcb660 R11: 0000000000000020 R12: 0000000000000000 [ 1814.849410] R13: ffff880058e359d8 R14: 00000000ffffffff R15: 0000000000000001 [ 1814.849616] FS: 00007f733bbca740(0000) GS:ffff88005d980000(0000) knlGS:0000000000000000 [ 1814.849919] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 1814.850107] CR2: 0000000000000000 CR3: 0000000059f0d000 CR4: 00000000000406e0 [ 1814.850313] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 1814.850518] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 1814.850723] Call Trace: [ 1814.850875] hrtimer_try_to_cancel+0x1a/0x93 [ 1814.851047] hrtimer_cancel+0x15/0x20 [ 1814.851211] qdisc_watchdog_cancel+0x12/0x14 [ 1814.851383] netem_reset+0xe6/0xed [sch_netem] [ 1814.851561] qdisc_destroy+0x8b/0xe5 [ 1814.851723] qdisc_create_dflt+0x86/0x94 [ 1814.851890] ? dev_activate+0x129/0x129 [ 1814.852057] attach_one_default_qdisc+0x36/0x63 [ 1814.852232] netdev_for_each_tx_queue+0x3d/0x48 [ 1814.852406] dev_activate+0x4b/0x129 [ 1814.852569] __dev_open+0xe7/0x104 [ 1814.852730] __dev_change_flags+0xc6/0x15c [ 1814.852899] dev_change_flags+0x25/0x59 [ 1814.853064] do_setlink+0x30c/0xb3f [ 1814.853228] ? check_chain_key+0xb0/0xfd [ 1814.853396] ? check_chain_key+0xb0/0xfd [ 1814.853565] rtnl_newlink+0x3a4/0x729 [ 1814.853728] ? rtnl_newlink+0x117/0x729 [ 1814.853905] ? ns_capable_common+0xd/0xb1 [ 1814.854072] ? ns_capable+0x13/0x15 [ 1814.854234] rtnetlink_rcv_msg+0x188/0x197 [ 1814.854404] ? rcu_read_unlock+0x3e/0x5f [ 1814.854572] ? rtnl_newlink+0x729/0x729 [ 1814.854737] netlink_rcv_skb+0x6c/0xce [ 1814.854902] rtnetlink_rcv+0x23/0x2a [ 1814.855064] netlink_unicast+0x103/0x181 [ 1814.855230] netlink_sendmsg+0x326/0x337 [ 1814.855398] sock_sendmsg_nosec+0x14/0x3f [ 1814.855584] sock_sendmsg+0x29/0x2e [ 1814.855747] ___sys_sendmsg+0x209/0x28b [ 1814.855912] ? do_raw_spin_unlock+0xcd/0xf8 [ 1814.856082] ? _raw_spin_unlock+0x27/0x31 [ 1814.856251] ? __handle_mm_fault+0x651/0xdb1 [ 1814.856421] ? check_chain_key+0xb0/0xfd [ 1814.856592] __sys_sendmsg+0x45/0x63 [ 1814.856755] ? __sys_sendmsg+0x45/0x63 [ 1814.856923] SyS_sendmsg+0x19/0x1b [ 1814.857083] entry_SYSCALL_64_fastpath+0x23/0xc2 [ 1814.857256] RIP: 0033:0x7f733b2dd690 [ 1814.857419] RSP: 002b:00007ffe1d3387d8 EFLAGS: 00000246 ORIG_RAX: 000000000000002e [ 1814.858238] RAX: ffffffffffffffda RBX: ffffffff810d278c RCX: 00007f733b2dd690 [ 1814.858445] RDX: 0000000000000000 RSI: 00007ffe1d338820 RDI: 0000000000000003 [ 1814.858651] RBP: ffff88005adcbf98 R08: 0000000000000001 R09: 0000000000000003 [ 1814.858856] R10: 00007ffe1d3385a0 R11: 0000000000000246 R12: 0000000000000002 [ 1814.859060] R13: 000000000066f1a0 R14: 00007ffe1d3408d0 R15: 0000000000000000 [ 1814.859267] ? trace_hardirqs_off_caller+0xa7/0xcf [ 1814.859446] Code: 10 55 48 89 c7 48 89 e5 e8 45 a1 fb ff 31 c0 5d c3 31 c0 c3 66 66 66 66 90 55 48 89 e5 41 56 41 55 41 54 53 49 89 fd 49 8b 45 30 <4c> 8b 20 41 8b 5c 24 38 31 c9 31 d2 48 c7 c7 50 8e 1d 82 41 89 [ 1814.860022] RIP: hrtimer_active+0x17/0x8a RSP: ffff88005adcb590 [ 1814.860214] CR2: 0000000000000000 Fixes: 87b60cfacf9f ("net_sched: fix error recovery at qdisc creation") Fixes: 0fbbeb1ba43b ("[PKT_SCHED]: Fix missing qdisc_destroy() in qdisc_create_dflt()") Signed-off-by: Nikolay Aleksandrov Signed-off-by: David S. Miller Signed-off-by: Amit Pundir --- net/sched/sch_netem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c index e899d9eb76cb..3f87ddb1777d 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -937,11 +937,11 @@ static int netem_init(struct Qdisc *sch, struct nlattr *opt) struct netem_sched_data *q = qdisc_priv(sch); int ret; + qdisc_watchdog_init(&q->watchdog, sch); + if (!opt) return -EINVAL; - qdisc_watchdog_init(&q->watchdog, sch); - q->loss_model = CLG_RANDOM; ret = netem_change(sch, opt); if (ret)