From patchwork Thu Aug 23 06:50:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Pundir X-Patchwork-Id: 144883 Delivered-To: patch@linaro.org Received: by 2002:a2e:164a:0:0:0:0:0 with SMTP id 10-v6csp756899ljw; Wed, 22 Aug 2018 23:50:53 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyJrQhI8poWjBpFbwJYOLer+qReYzWjqnvLjmsE+Vwo0Gkhjy9xjXtnkgMLqxErB4t4rdwr X-Received: by 2002:a17:902:2f43:: with SMTP id s61-v6mr55999377plb.176.1535007053484; Wed, 22 Aug 2018 23:50:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535007053; cv=none; d=google.com; s=arc-20160816; b=oZLQ4y5lOVHMGGYkqcEpaHsEBW8iZm0IdnhDGfyIQd79ptChQd92gMmIiAtAtYqNuG qDE29azsaZrbIV36mtqBTH7r/hlyfkxrFMtIvJDG9VHZmRPLA/AyapQhABz4dem5HUvi 824IjYN2pdL9enqiRmNmPzjhwZSMmsnv6fWmWHlYwI0iJJElS9KIdK1yvnQYB19eM1sd 3efwFRzuImFTDz9JEoT/Xasg52jdUQBbnZQfXD/LQxF4G9gXTJ4nMLjahNUnBwRbrXwM pQjsv+SqZVvZgMcQGGkZTKpB9SzWJ010cHe5ke7GUdYFfXImJ1zCfKDtY6Qh+kEDfn45 8Iig== 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=YPPTZBcirSnBHY2ji2HESr2mIS3fo0qH3/RyHn4RCcc=; b=s5wlmK4iceVV5GnAbucVp3JfpyeWhVs6pRuym4cfUhKkESebfLuoSO2jPAL0vHqAuD efvvfsdLOReZdW5EyZ6uNXCotMZj6BwxmGZ7QIlGu0zTOKA7Li65Jqm6VgbBtyELvD0w 7aXxFyiAGR1JhE4LCUH4ukY5WMUkIcEmkFNMcA/uCexPsCsB4KM9Xw8c2iE0RvzBoPB8 KwpEjwe5wmgJburHu/lYaToGrd083jkByVIASX5Dc/hHVWrDTjDBO5u8PcZOFFt9b3ae LPqbeuDMt2u+yOZgR2Rw36/m6ye26DGDaxoG00iT6uU7HaNsWYFktZEm8O4kl63+OnNj +Big== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L5sWzgT4; 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.53; Wed, 22 Aug 2018 23:50:53 -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=L5sWzgT4; 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 S1726145AbeHWKTB (ORCPT + 13 others); Thu, 23 Aug 2018 06:19:01 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:35474 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbeHWKTB (ORCPT ); Thu, 23 Aug 2018 06:19:01 -0400 Received: by mail-pl0-f68.google.com with SMTP id d9-v6so1787966plr.2 for ; Wed, 22 Aug 2018 23:50:52 -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=YPPTZBcirSnBHY2ji2HESr2mIS3fo0qH3/RyHn4RCcc=; b=L5sWzgT4RFu+XnTNQPuPg6qINJomEulMzN0Kk81lHJ1Nwzo27LBCiNLP1aao0Odrw8 tAFTSK1wA8/AiRJPygZCQSAlbWp3oAvQyzvbP5PwiaV7w3r26veabAD3ud/g6/z/o0u6 liUPNipyEvX9+gpDW9W6ZgODoAQByuzM2HVlc= 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=YPPTZBcirSnBHY2ji2HESr2mIS3fo0qH3/RyHn4RCcc=; b=VgkbcMdmdBz0AOx6MYUE36ECRhKcmEBt0wV1cI5+3ASL+fBxfWKfE4if3/vvTyNrJ0 BLLAHnvurg9HxGmIYHg4rfDkXKviIttRUdnfr6aQTYR5KpM7Ptl0A4zo7WbLclh3K+wt loZl+EwABIGNu/7quNh3bf5HgQF4hbAokINuFridrPfe8DLvdXXQdz4/Ei3QU2m8njsU YUlX4XkwRn4IrlPNXTzVbGt5XbQz7bF9jaNtFl+uzpbEaQBdMHguX5eNAV2H1nY7czz2 SwVLk8+dIUgoO8twhZPqc/lzaURDaGa+DAyGS6cCduIXM4KcO3hae2gRWobnVlzks6Q8 pvPA== X-Gm-Message-State: AOUpUlGe2WfnEayxfMjKta1kJiHhjg4qoFRV30dDY21RgT1MHU3Qkhex sLPu3ArnRhmO+Bf3Y6KbY8Iyqg== X-Received: by 2002:a17:902:6f16:: with SMTP id w22-v6mr38503734plk.127.1535007051976; Wed, 22 Aug 2018 23:50:51 -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.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Aug 2018 23:50:50 -0700 (PDT) From: Amit Pundir To: Greg KH , Nikolay Aleksandrov Cc: "David S . Miller" , Stable Subject: [PATCH v2 for-4.9.y 2/5] sch_multiq: fix double free on init failure Date: Thu, 23 Aug 2018 12:20:38 +0530 Message-Id: <1535007041-31605-3-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 e89d469e3be3ed3d7124a803211a463ff83d0964 upstream. The below commit added a call to ->destroy() on init failure, but multiq still frees ->queues on error in init, but ->queues is also freed by ->destroy() thus we get double free and corrupted memory. Very easy to reproduce (eth0 not multiqueue): $ tc qdisc add dev eth0 root multiq RTNETLINK answers: Operation not supported $ ip l add dumdum type dummy (crash) Trace log: [ 3929.467747] general protection fault: 0000 [#1] SMP [ 3929.468083] Modules linked in: [ 3929.468302] CPU: 3 PID: 967 Comm: ip Not tainted 4.13.0-rc6+ #56 [ 3929.468625] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.7.5-20140531_083030-gandalf 04/01/2014 [ 3929.469124] task: ffff88003716a700 task.stack: ffff88005872c000 [ 3929.469449] RIP: 0010:__kmalloc_track_caller+0x117/0x1be [ 3929.469746] RSP: 0018:ffff88005872f6a0 EFLAGS: 00010246 [ 3929.470042] RAX: 00000000000002de RBX: 0000000058a59000 RCX: 00000000000002df [ 3929.470406] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffff821f7020 [ 3929.470770] RBP: ffff88005872f6e8 R08: 000000000001f010 R09: 0000000000000000 [ 3929.471133] R10: ffff88005872f730 R11: 0000000000008cdd R12: ff006d75646d7564 [ 3929.471496] R13: 00000000014000c0 R14: ffff88005b403c00 R15: ffff88005b403c00 [ 3929.471869] FS: 00007f0b70480740(0000) GS:ffff88005d980000(0000) knlGS:0000000000000000 [ 3929.472286] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 3929.472677] CR2: 00007ffcee4f3000 CR3: 0000000059d45000 CR4: 00000000000406e0 [ 3929.473209] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 3929.474109] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 3929.474873] Call Trace: [ 3929.475337] ? kstrdup_const+0x23/0x25 [ 3929.475863] kstrdup+0x2e/0x4b [ 3929.476338] kstrdup_const+0x23/0x25 [ 3929.478084] __kernfs_new_node+0x28/0xbc [ 3929.478478] kernfs_new_node+0x35/0x55 [ 3929.478929] kernfs_create_link+0x23/0x76 [ 3929.479478] sysfs_do_create_link_sd.isra.2+0x85/0xd7 [ 3929.480096] sysfs_create_link+0x33/0x35 [ 3929.480649] device_add+0x200/0x589 [ 3929.481184] netdev_register_kobject+0x7c/0x12f [ 3929.481711] register_netdevice+0x373/0x471 [ 3929.482174] rtnl_newlink+0x614/0x729 [ 3929.482610] ? rtnl_newlink+0x17f/0x729 [ 3929.483080] rtnetlink_rcv_msg+0x188/0x197 [ 3929.483533] ? rcu_read_unlock+0x3e/0x5f [ 3929.483984] ? rtnl_newlink+0x729/0x729 [ 3929.484420] netlink_rcv_skb+0x6c/0xce [ 3929.484858] rtnetlink_rcv+0x23/0x2a [ 3929.485291] netlink_unicast+0x103/0x181 [ 3929.485735] netlink_sendmsg+0x326/0x337 [ 3929.486181] sock_sendmsg_nosec+0x14/0x3f [ 3929.486614] sock_sendmsg+0x29/0x2e [ 3929.486973] ___sys_sendmsg+0x209/0x28b [ 3929.487340] ? do_raw_spin_unlock+0xcd/0xf8 [ 3929.487719] ? _raw_spin_unlock+0x27/0x31 [ 3929.488092] ? __handle_mm_fault+0x651/0xdb1 [ 3929.488471] ? check_chain_key+0xb0/0xfd [ 3929.488847] __sys_sendmsg+0x45/0x63 [ 3929.489206] ? __sys_sendmsg+0x45/0x63 [ 3929.489576] SyS_sendmsg+0x19/0x1b [ 3929.489901] entry_SYSCALL_64_fastpath+0x23/0xc2 [ 3929.490172] RIP: 0033:0x7f0b6fb93690 [ 3929.490423] RSP: 002b:00007ffcee4ed588 EFLAGS: 00000246 ORIG_RAX: 000000000000002e [ 3929.490881] RAX: ffffffffffffffda RBX: ffffffff810d278c RCX: 00007f0b6fb93690 [ 3929.491198] RDX: 0000000000000000 RSI: 00007ffcee4ed5d0 RDI: 0000000000000003 [ 3929.491521] RBP: ffff88005872ff98 R08: 0000000000000001 R09: 0000000000000000 [ 3929.491801] R10: 00007ffcee4ed350 R11: 0000000000000246 R12: 0000000000000002 [ 3929.492075] R13: 000000000066f1a0 R14: 00007ffcee4f5680 R15: 0000000000000000 [ 3929.492352] ? trace_hardirqs_off_caller+0xa7/0xcf [ 3929.492590] Code: 8b 45 c0 48 8b 45 b8 74 17 48 8b 4d c8 83 ca ff 44 89 ee 4c 89 f7 e8 83 ca ff ff 49 89 c4 eb 49 49 63 56 20 48 8d 48 01 4d 8b 06 <49> 8b 1c 14 48 89 c2 4c 89 e0 65 49 0f c7 08 0f 94 c0 83 f0 01 [ 3929.493335] RIP: __kmalloc_track_caller+0x117/0x1be RSP: ffff88005872f6a0 Fixes: 87b60cfacf9f ("net_sched: fix error recovery at qdisc creation") Fixes: f07d1501292b ("multiq: Further multiqueue cleanup") Signed-off-by: Nikolay Aleksandrov Signed-off-by: David S. Miller [AmitP: Removed unused variable 'err' in multiq_init()] Signed-off-by: Amit Pundir --- net/sched/sch_multiq.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) -- 2.7.4 diff --git a/net/sched/sch_multiq.c b/net/sched/sch_multiq.c index 9ffbb025b37e..66b6e807b4ec 100644 --- a/net/sched/sch_multiq.c +++ b/net/sched/sch_multiq.c @@ -234,7 +234,7 @@ static int multiq_tune(struct Qdisc *sch, struct nlattr *opt) static int multiq_init(struct Qdisc *sch, struct nlattr *opt) { struct multiq_sched_data *q = qdisc_priv(sch); - int i, err; + int i; q->queues = NULL; @@ -249,12 +249,7 @@ static int multiq_init(struct Qdisc *sch, struct nlattr *opt) for (i = 0; i < q->max_bands; i++) q->queues[i] = &noop_qdisc; - err = multiq_tune(sch, opt); - - if (err) - kfree(q->queues); - - return err; + return multiq_tune(sch, opt); } static int multiq_dump(struct Qdisc *sch, struct sk_buff *skb)