From patchwork Tue Jul 31 18:40: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: 143208 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp5668374ljj; Tue, 31 Jul 2018 11:40:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfI/gCeEOopCXmUM9dL2amCx0U3HeCzeRHNjffLZxWTuSFCprho+pZT+FCJUBmOPLm+AEN2 X-Received: by 2002:aa7:800f:: with SMTP id j15-v6mr23297989pfi.174.1533062426602; Tue, 31 Jul 2018 11:40:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533062426; cv=none; d=google.com; s=arc-20160816; b=wE5NZ9W2Ek90zHyCL6glivL5lM76oF6Ue/eeLpZbBKiD3AKTnD+F6RYMN+Cw5oHe8d rtXJG8niDdiHnYEllhFOYOaVdbktvFIbCg523g/4iR3ZJAwvRpPX7TI1ANoEEh9KW6gD gRiJ8YEQP40F7p5K+eo5oe/LIxF/9YJCf7ex4Tros9sKE1NtTYiDh1odG75QQB6BuFRh sOdlL+R4CKRsCAPpsPNjcJRd7daU39k8FJAOWjHT7znvFIxDw/m88QsJxDSjTOF3vbz+ ak55A1jEmzjHGPx6/NF1OwQr312K1mKtjLwk+s6F2l/d8+yVJ6qky4IHGEiMgHp0QFSZ Cjrg== 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=pPCSTeC84yOQxgyM8e/R+qVuuNtbJ5jVzPqymIzroPU=; b=Yx6BfLI6WjjxzM6E+tQRjkwai9jGy9RNexx7SXWJOyaRcnFbvK5S+RZzlFfPpb+9AI r/23oUHnxW+MjYMNQavPzpNHXsQCIsy/XJsYD6bK3Jdvn+pndGtY5aluRe4s76d7TjN1 7t0fO93vd919CS0S96cijChcq/deFWcwaHKdPRnXEux4Cz3sC8ihZDrySBcmC5JdedGS jp/aHfGdjs8FUPugwHPDI3ziC2BTs0y9Jhj0RSzHGOWp9PeVGFkqraSHEvRdTGApYosW vOxshjgXX7/oQbKu3bneTVo+vZJBe9U0KEv3shdRKzuBdNayxgCud/iye8Mn+r54Qb9x umVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="V/yw68DJ"; 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.26; Tue, 31 Jul 2018 11:40:26 -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="V/yw68DJ"; 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 S1729790AbeGaUWB (ORCPT + 13 others); Tue, 31 Jul 2018 16:22:01 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:46095 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729645AbeGaUWA (ORCPT ); Tue, 31 Jul 2018 16:22:00 -0400 Received: by mail-pf1-f193.google.com with SMTP id u24-v6so6519583pfn.13 for ; Tue, 31 Jul 2018 11:40:25 -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=pPCSTeC84yOQxgyM8e/R+qVuuNtbJ5jVzPqymIzroPU=; b=V/yw68DJ7a8B6j591LczghKiUi//JArZ/nluuLvY/8hwgqjTQNfvXadTv8ywTcdsur R7zY1jYEvDbDLBaVsYUX0ag+/46bPjGFPbwfbB/0y4bcJWX9j0COiFP12lqCJ2OmJWuV f/FKupEHbEbGVBNGkea+WyIetuSVRJECsGbeE= 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=pPCSTeC84yOQxgyM8e/R+qVuuNtbJ5jVzPqymIzroPU=; b=kh4t9H0R4P+Hl9ckJe0+XyLO1DFiHUEdAfPB7olLPKY0xTajIVxX3oxJPEm8mgbgHs /Y95GJU/OrWbrumNNaGkWpZ4UQdnhVd/KQmWSklenSAtxKtw9/LJ0i5wFnUBAJjM68k9 irWfKqT0vqBzn0hPXNBaylhLkgS6EWpc8QkmMI/ymi3+2IPnZF0ZgJvYMIyjkKsiq44q DLzB9RL5g/3RaTsmZUZxHAuLNaQDRGQ2uUmrc6EU/49tq2ga/M3P81Q5P6vVlv/w7pjz haJaAtseiFmtm8Vg80uXozLTuN8SuGgrzem2V1s6ACEcQtYEmeoLw64Oio+ej9Jftb/W rpdw== X-Gm-Message-State: AOUpUlGh7YhJ1hMWGV3IJw05b1YQGbuzEOm3Vz6xeRaSN/A24DNl5dcp ap0Tqms5EsTUMCUoOb2eFo9Zfw== X-Received: by 2002:a63:b349:: with SMTP id x9-v6mr21554534pgt.337.1533062424693; Tue, 31 Jul 2018 11:40:24 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Jul 2018 11:40:23 -0700 (PDT) From: Amit Pundir To: Greg KH , Nikolay Aleksandrov Cc: "David S . Miller" , Stable Subject: [PATCH for-4.9.y 5/5] sch_tbf: fix two null pointer dereferences on init failure Date: Wed, 1 Aug 2018 00:10:05 +0530 Message-Id: <1533062405-32524-6-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 c2d6511e6a4f1f3673d711569c00c3849549e9b0 upstream. sch_tbf calls qdisc_watchdog_cancel() in both its ->reset and ->destroy callbacks but it may fail before the timer is initialized due to missing options (either not supplied by user-space or set as a default qdisc), also q->qdisc is used by ->reset and ->destroy so we need it initialized. Reproduce: $ sysctl net.core.default_qdisc=tbf $ ip l set ethX up Crash log: [ 959.160172] BUG: unable to handle kernel NULL pointer dereference at 0000000000000018 [ 959.160323] IP: qdisc_reset+0xa/0x5c [ 959.160400] PGD 59cdb067 [ 959.160401] P4D 59cdb067 [ 959.160466] PUD 59ccb067 [ 959.160532] PMD 0 [ 959.160597] [ 959.160706] Oops: 0000 [#1] SMP [ 959.160778] Modules linked in: sch_tbf sch_sfb sch_prio sch_netem [ 959.160891] CPU: 2 PID: 1562 Comm: ip Not tainted 4.13.0-rc6+ #62 [ 959.160998] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.7.5-20140531_083030-gandalf 04/01/2014 [ 959.161157] task: ffff880059c9a700 task.stack: ffff8800376d0000 [ 959.161263] RIP: 0010:qdisc_reset+0xa/0x5c [ 959.161347] RSP: 0018:ffff8800376d3610 EFLAGS: 00010286 [ 959.161531] RAX: ffffffffa001b1dd RBX: ffff8800373a2800 RCX: 0000000000000000 [ 959.161733] RDX: ffffffff8215f160 RSI: ffffffff8215f160 RDI: 0000000000000000 [ 959.161939] RBP: ffff8800376d3618 R08: 00000000014080c0 R09: 00000000ffffffff [ 959.162141] R10: ffff8800376d3578 R11: 0000000000000020 R12: ffffffffa001d2c0 [ 959.162343] R13: ffff880037538000 R14: 00000000ffffffff R15: 0000000000000001 [ 959.162546] FS: 00007fcc5126b740(0000) GS:ffff88005d900000(0000) knlGS:0000000000000000 [ 959.162844] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 959.163030] CR2: 0000000000000018 CR3: 000000005abc4000 CR4: 00000000000406e0 [ 959.163233] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 959.163436] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 959.163638] Call Trace: [ 959.163788] tbf_reset+0x19/0x64 [sch_tbf] [ 959.163957] qdisc_destroy+0x8b/0xe5 [ 959.164119] qdisc_create_dflt+0x86/0x94 [ 959.164284] ? dev_activate+0x129/0x129 [ 959.164449] attach_one_default_qdisc+0x36/0x63 [ 959.164623] netdev_for_each_tx_queue+0x3d/0x48 [ 959.164795] dev_activate+0x4b/0x129 [ 959.164957] __dev_open+0xe7/0x104 [ 959.165118] __dev_change_flags+0xc6/0x15c [ 959.165287] dev_change_flags+0x25/0x59 [ 959.165451] do_setlink+0x30c/0xb3f [ 959.165613] ? check_chain_key+0xb0/0xfd [ 959.165782] rtnl_newlink+0x3a4/0x729 [ 959.165947] ? rtnl_newlink+0x117/0x729 [ 959.166121] ? ns_capable_common+0xd/0xb1 [ 959.166288] ? ns_capable+0x13/0x15 [ 959.166450] rtnetlink_rcv_msg+0x188/0x197 [ 959.166617] ? rcu_read_unlock+0x3e/0x5f [ 959.166783] ? rtnl_newlink+0x729/0x729 [ 959.166948] netlink_rcv_skb+0x6c/0xce [ 959.167113] rtnetlink_rcv+0x23/0x2a [ 959.167273] netlink_unicast+0x103/0x181 [ 959.167439] netlink_sendmsg+0x326/0x337 [ 959.167607] sock_sendmsg_nosec+0x14/0x3f [ 959.167772] sock_sendmsg+0x29/0x2e [ 959.167932] ___sys_sendmsg+0x209/0x28b [ 959.168098] ? do_raw_spin_unlock+0xcd/0xf8 [ 959.168267] ? _raw_spin_unlock+0x27/0x31 [ 959.168432] ? __handle_mm_fault+0x651/0xdb1 [ 959.168602] ? check_chain_key+0xb0/0xfd [ 959.168773] __sys_sendmsg+0x45/0x63 [ 959.168934] ? __sys_sendmsg+0x45/0x63 [ 959.169100] SyS_sendmsg+0x19/0x1b [ 959.169260] entry_SYSCALL_64_fastpath+0x23/0xc2 [ 959.169432] RIP: 0033:0x7fcc5097e690 [ 959.169592] RSP: 002b:00007ffd0d5c7b48 EFLAGS: 00000246 ORIG_RAX: 000000000000002e [ 959.169887] RAX: ffffffffffffffda RBX: ffffffff810d278c RCX: 00007fcc5097e690 [ 959.170089] RDX: 0000000000000000 RSI: 00007ffd0d5c7b90 RDI: 0000000000000003 [ 959.170292] RBP: ffff8800376d3f98 R08: 0000000000000001 R09: 0000000000000003 [ 959.170494] R10: 00007ffd0d5c7910 R11: 0000000000000246 R12: 0000000000000006 [ 959.170697] R13: 000000000066f1a0 R14: 00007ffd0d5cfc40 R15: 0000000000000000 [ 959.170900] ? trace_hardirqs_off_caller+0xa7/0xcf [ 959.171076] Code: 00 41 c7 84 24 14 01 00 00 00 00 00 00 41 c7 84 24 98 00 00 00 00 00 00 00 41 5c 41 5d 41 5e 5d c3 66 66 66 66 90 55 48 89 e5 53 <48> 8b 47 18 48 89 fb 48 8b 40 48 48 85 c0 74 02 ff d0 48 8b bb [ 959.171637] RIP: qdisc_reset+0xa/0x5c RSP: ffff8800376d3610 [ 959.171821] CR2: 0000000000000018 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_tbf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/net/sched/sch_tbf.c b/net/sched/sch_tbf.c index 303355c449ab..b3f7980b0f27 100644 --- a/net/sched/sch_tbf.c +++ b/net/sched/sch_tbf.c @@ -423,12 +423,13 @@ static int tbf_init(struct Qdisc *sch, struct nlattr *opt) { struct tbf_sched_data *q = qdisc_priv(sch); + qdisc_watchdog_init(&q->watchdog, sch); + q->qdisc = &noop_qdisc; + if (opt == NULL) return -EINVAL; q->t_c = ktime_get_ns(); - qdisc_watchdog_init(&q->watchdog, sch); - q->qdisc = &noop_qdisc; return tbf_change(sch, opt); }