From patchwork Tue Jul 31 18:40:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 143207 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp5668344ljj; Tue, 31 Jul 2018 11:40:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcuLOjBEaVF0Zpj8aSok3QVewViKv+iv0juBj3lXj+NlNJHLU1WnyQfgXdOT102kaRXsNDM X-Received: by 2002:a17:902:d68f:: with SMTP id v15-v6mr13377145ply.278.1533062424517; Tue, 31 Jul 2018 11:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533062424; cv=none; d=google.com; s=arc-20160816; b=gCEy+0DQJme0RnSa7BqIx1qS9dQNx5oq2sfOcjtcxI1S7uybcszIX9oqvw+Gf6Bfbj CXOa62pJBMHYiTgugvNwg6QAFDtOxtoTNbI09KFn29RoeYV8E9ylD/RAR7hpN5qIZubZ XxUWA+pqRFu+FLtzt6O+GorAbfiEqgNAzU9ipMGfKYmNM28kpHV9/PtSdX3q+LMIPVCw 6Rn6s0MvQ+ZcNirvRHqo/wzM9xntEFYI4j7wd+Nop9QmwH+sINXoRyVswLvHUAeINBzm sdfT++cwWc3Q/pG2N8qIX1/5unnrmMMSieyimYD780DFv/5GajOgzL9+vrMEpCed1Qf6 55WA== 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=shaJ1GdIh25T8mDW1izEG2iSrG0xfPM31bZS/h49KfV0wdhlgzwDOjJc0SXeFcjPuQ h+z6Km4Zd7VBg+mDm3rRz7VpY2zqhDhiCfY1W6wlZVTCC297jXtsgFGqtBFWk+loGW6+ R/Em2l3A7IowxzLZLNYjYvw0NlLa1RULDNCXEkL66/HDVke1VtlmaXoiMewr/kG9qOyX oCKGezDcHARQLOvYHNZL0VrivezKnC7KxaSDSLU5HtP1TnlzEpInqoGIN1TKZoF4q1iR zgKrB4RDzU1HqNkGx2quKgSsx9Dy3L/CKnB8nGIBIC53LJSGAuuaFwE+O65BEQ5uAb4k KsZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R7P71SF9; 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 x3-v6si13746391pgo.542.2018.07.31.11.40.23; Tue, 31 Jul 2018 11:40:24 -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=R7P71SF9; 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 S1729785AbeGaUV6 (ORCPT + 13 others); Tue, 31 Jul 2018 16:21:58 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35252 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729645AbeGaUV6 (ORCPT ); Tue, 31 Jul 2018 16:21:58 -0400 Received: by mail-pf1-f194.google.com with SMTP id p12-v6so1427466pfh.2 for ; Tue, 31 Jul 2018 11:40:22 -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=R7P71SF9wfBgZhlB4aRQ6TatleVcGH3k4mRqDGsSAi/OSBWMS5ixD4QPOMgJInvOPv /NiuEfRu7trP6NfG+0cijcXues+1zWUuDtAn0bT/eMEQECKWsDb3QiDJXbqQikCmNSfR ym5Y2QvKgefWcjXrx4mdKKMsA8mzU20atWMaU= 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=hkKKpmnFo4DQ7Ze61j2ipKyOo4tLV9Vu7Xi6Rila1ggNl8QgQ5lt6COljaI1iSTvJi 3m7OLOQA57VCjQIxgKVBtdsny4IYFzvbWJRpOsVLcy75xBe/sGjuGtytQGPOttf8ZeNK SczqAW3RwW1oLVc+qPsQasBfk7+BwcoEccYrMGL/I5T465wTocW0wECu5ho0STvpDRdL VxoUzLrqyoF6IDQezDQirK2SQ5ukMa3s1HCfP5JLF1+64iAHFLkJMKi22K6vpfDriPSb wASNKbZLavIA+XsXBizfpq1eEEsSJvf6erRJeowHpr6LSpmbY7q8Z4izikwJ2+gvmjwl 3uhg== X-Gm-Message-State: AOUpUlH3LZ6EGppzfGAP5LnKzIrraoAlAbuVm+O8cyFDUxMvUUXti+fB asFxKiW5bet67y4DreLGkGlr0Q== X-Received: by 2002:a63:fd06:: with SMTP id d6-v6mr21710066pgh.348.1533062421943; Tue, 31 Jul 2018 11:40:21 -0700 (PDT) Received: from localhost.localdomain ([106.51.18.123]) by smtp.gmail.com with ESMTPSA id d191-v6sm15467977pfg.172.2018.07.31.11.40.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Jul 2018 11:40:20 -0700 (PDT) From: Amit Pundir To: Greg KH , Nikolay Aleksandrov Cc: "David S . Miller" , Stable Subject: [PATCH for-4.9.y 4/5] sch_netem: avoid null pointer deref on init failure Date: Wed, 1 Aug 2018 00:10:04 +0530 Message-Id: <1533062405-32524-5-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533062405-32524-1-git-send-email-amit.pundir@linaro.org> References: <1533062405-32524-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)