From patchwork Tue Jul 31 18:43:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 143213 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp5670749ljj; Tue, 31 Jul 2018 11:43:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeQOH51WJ7p/mAdE7/+s71beEsdQBID7boL1MTXvCiU0eQ9tGDlEZT+mO/rlb6IdeG9m6Qo X-Received: by 2002:a63:d401:: with SMTP id a1-v6mr21391079pgh.414.1533062604407; Tue, 31 Jul 2018 11:43:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533062604; cv=none; d=google.com; s=arc-20160816; b=JoAMSry+n1ifV6ayUxsx+b92rVxsh+CB+X0v0bzgloGsYAw6abdx+L5f96NOv70O5V +vJIXlXHXMCtxPFd+4m6MFbByP45FWTCPBE/aYUKXyimePh6JuDS4cVo+k0Dv/xq/obz aQbyiSdyms49OivbfPYVrAkPaceYoLY4QAm0g9XSQ5rghekBTulJ1ezNbJVuroyIILhd XJ+IQbQ29yuZwutrnkuUCxPCdfAhskaNyxYPhURza+TZsi1uR1DqkaxzK+Vyfk8KA0R4 g9Hxr+Re0WT4vtyvu9JBxedSeNFVkA91Y++Lqi2KOHU0mmC8Wx5JgVQxVKLicWSp5v5y m75g== 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=FO1OiUvUGFGRcngUcmdFC97SkgP7sAxZmmtjGPihLPA=; b=FgDLJlXNN36ZxYohLT8aZMufWMBzzECYsXclcOJ3vR3VyRxIxckHxxXwWnOSUXIS5G blzIXNnWGkjVNdt++3HAJMD4Q7bTQCZ5KpfJAiudNOiPJ5O8Q+LITIy4BRZIvarAm0Fm QvitOb66VGbHgTUhgkJyQ/n3EL79z0rFJNR4Zr4JjGg8i4/ZU4lQQe6jKupeJ22gLCnZ grM/s/uAqNcKfPZbhmWoHCByLUDJkSvsC2Ob1esR8QP7vtwRGuDDcaxwUyw+XmikdB05 SCNJZJpd99NVQiRkTQRHKFDo8r1NQNdmg1hLkbZ4891i5SaE3nC3FqP2XwodZjB4poex 72FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BdKfcO0h; 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 t71-v6si13085197pgd.271.2018.07.31.11.43.24; Tue, 31 Jul 2018 11:43: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=BdKfcO0h; 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 S1729645AbeGaUY7 (ORCPT + 13 others); Tue, 31 Jul 2018 16:24:59 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:39918 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729772AbeGaUY7 (ORCPT ); Tue, 31 Jul 2018 16:24:59 -0400 Received: by mail-pg1-f194.google.com with SMTP id a11-v6so9519554pgw.6 for ; Tue, 31 Jul 2018 11:43: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=FO1OiUvUGFGRcngUcmdFC97SkgP7sAxZmmtjGPihLPA=; b=BdKfcO0hUU2y65b3NROPwGe13Aon9F+fQm52nz4tXOhaxJIyZknFnEwm5obkYo8R81 zQba2w89DLsccY4mcdEQeyvh7A7plBQu5wEf+I12WiBswru9ipl3lk129NFmNU1ZLClV 21HvEgVcrCn8XVMWE7R7vaRm4ZNCT0j6t6u60= 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=FO1OiUvUGFGRcngUcmdFC97SkgP7sAxZmmtjGPihLPA=; b=BQhimUPs6nfiufLm7no/IXufcJ43GDotIVY40YE1sedjypB5y6Jc6sVe4/B7MfLq8c t3aqTsS/1Y4VEv8gNbiKHLfBJN5YYb3Pgu4vDib2TBHfBIVNeJHJsnWo7KtKFY1mOlPC vVGTy6DThAKX1v3Xzh+UcdFn+vY/DfZfMzjTybi7ruTRZImKVuiSug/qtbe53/8R/NmR 6ebZfjXjPjTDXpUTlv3y3Ne0kPkn9kE3KARBbShSUqS9putBTLtEnv29E8cWpOtjQvVE 99DXXqhfq4zXOZU/46d3cpctZdiR61gb4HUycM8NmQYidlwe1uAU90timmTh1BQa8JCB wRdQ== X-Gm-Message-State: AOUpUlEl7IU/vTBGujPYMHFV4Jp1+YZUjETxkR81dxBQcwaBnOLXGYI0 MsfULOrfyRZ2k0Jot8aM2qdqZQ== X-Received: by 2002:a65:608b:: with SMTP id t11-v6mr21632031pgu.259.1533062601998; Tue, 31 Jul 2018 11:43:21 -0700 (PDT) Received: from localhost.localdomain ([106.51.18.123]) by smtp.gmail.com with ESMTPSA id v22-v6sm38486956pfi.60.2018.07.31.11.43.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Jul 2018 11:43:20 -0700 (PDT) From: Amit Pundir To: Greg KH , Nikolay Aleksandrov Cc: "David S . Miller" , Stable Subject: [PATCH for-4.4.y 4/5] sch_netem: avoid null pointer deref on init failure Date: Wed, 1 Aug 2018 00:13:05 +0530 Message-Id: <1533062586-804-5-git-send-email-amit.pundir@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533062586-804-1-git-send-email-amit.pundir@linaro.org> References: <1533062586-804-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 b7c29d5b6f04..743ff23885da 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -943,11 +943,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)