Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2006681imm; Thu, 24 May 2018 04:24:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrouzZkcS8J/dqM0TgWm5bggbjGuG07tKyu9bNH+KlxHGQZuf09ApBEZPd7fWOVadK/I3MT X-Received: by 2002:a17:902:bf0a:: with SMTP id bi10-v6mr6817392plb.235.1527161074301; Thu, 24 May 2018 04:24:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527161074; cv=none; d=google.com; s=arc-20160816; b=zk0kmnpcEr5HvgZHhw6+9WaEek1RBzxg/RXugEA/KMeTAg042SrWQwmE0HZbzQGY7c rJmdhK4B3jKkhkjh6Ypj8JiMywV2c+nUTncfYKeJSEHGtyWXwvFlKrRZOb+PwFdHhbJ5 iLKHJN30BDPU2Qanf5X3bayB+3LVsvkDhkUrvNbk7pJ6D9PeV8GsX+t5QFZlhu2RplRS j0h5D7ThUK+k41d680dlK9zXU0a3m5JuwrkqW3o4G0FBVHk0VjSu2fLPQhA06oJfSus4 ao95wo+jRbwaPZsVzkmRpxjBtEkYg1lpL8+PXAGxcvJCbnO6oHfP1eLyDGMBXlO2OjIm BhXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=7JWJ5h0Tt0a3NZMxCHUJ1u4qW3gul1+L3iXvrTLYkb4=; b=LNpFHb3oPkc/KJmigkb+XqohgVwTNHTDBr3H+RkVe011Mbh5vpzhA/LBMLr66S8Mns iSmScNWWS6+FZoOaY9Du+VQdEIpQh5ESps6hC8W7M+3VfJIq2HQxr4oa/bFVZ6Rk/5WF 3eH2y6J1BTab9tNZcVkmI/S4KuBcy2hwCdF2F5/Eu3C0Bqkzd2M1DMJrRMWy4u9VvsES XXC7vxG5qLb8KT6/jBAt1xLdZLl9oGeUNnkINxUl2ZlkfmEFzKFQtiDiLXiZANqI4H3u 4PmTMDsZA4UnVnU57WiG47oIwz9gl6KhExD0GfRNf5QXHSYyWfvPLXJgc0W3/9YbeaiP 335g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=leWAWcCW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10-v6si1907654plz.190.2018.05.24.04.24.19; Thu, 24 May 2018 04:24:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@kernel.org header.s=default header.b=leWAWcCW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967915AbeEXLXD (ORCPT + 99 others); Thu, 24 May 2018 07:23:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:49854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967806AbeEXJwI (ORCPT ); Thu, 24 May 2018 05:52:08 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 87B79208AE; Thu, 24 May 2018 09:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155528; bh=RMh7lxDFEw9M3I9D3ZhvSNoAqnOp22I9E8H2KrTgTWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=leWAWcCWD5HSYs27gJqGO9E0hsYnmb/MIw0s4W8DnmO3amkppqFUiaHmh4i+L8zw4 rRE48aZ6oyB45+Clsy1Yr4aappQTU06HRCQEWt0gBd/VRnO1+SaX198wWDJV7kp0Vr GWnyhEIlEAiUYpuVFUoIVIuAMe+8PKZIq2DqHcXI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hangbin Liu , Paolo Abeni , Jiri Kosina , "David S. Miller" Subject: [PATCH 4.14 004/165] net: sched: red: avoid hashing NULL child Date: Thu, 24 May 2018 11:36:50 +0200 Message-Id: <20180524093622.150403466@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093621.979359379@linuxfoundation.org> References: <20180524093621.979359379@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Abeni [ Upstream commit 44a63b137f7b6e4c7bd6c9cc21615941cb36509d ] Hangbin reported an Oops triggered by the syzkaller qdisc rules: kasan: GPF could be caused by NULL-ptr deref or user memory access general protection fault: 0000 [#1] SMP KASAN PTI Modules linked in: sch_red CPU: 0 PID: 28699 Comm: syz-executor5 Not tainted 4.17.0-rc4.kcov #1 Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011 RIP: 0010:qdisc_hash_add+0x26/0xa0 RSP: 0018:ffff8800589cf470 EFLAGS: 00010203 RAX: dffffc0000000000 RBX: 0000000000000000 RCX: ffffffff824ad971 RDX: 0000000000000007 RSI: ffffc9000ce9f000 RDI: 000000000000003c RBP: 0000000000000001 R08: ffffed000b139ea2 R09: ffff8800589cf4f0 R10: ffff8800589cf50f R11: ffffed000b139ea2 R12: ffff880054019fc0 R13: ffff880054019fb4 R14: ffff88005c0af600 R15: ffff880054019fb0 FS: 00007fa6edcb1700(0000) GS:ffff88005ce00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000020000740 CR3: 000000000fc16000 CR4: 00000000000006f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: red_change+0x2d2/0xed0 [sch_red] qdisc_create+0x57e/0xef0 tc_modify_qdisc+0x47f/0x14e0 rtnetlink_rcv_msg+0x6a8/0x920 netlink_rcv_skb+0x2a2/0x3c0 netlink_unicast+0x511/0x740 netlink_sendmsg+0x825/0xc30 sock_sendmsg+0xc5/0x100 ___sys_sendmsg+0x778/0x8e0 __sys_sendmsg+0xf5/0x1b0 do_syscall_64+0xbd/0x3b0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x450869 RSP: 002b:00007fa6edcb0c48 EFLAGS: 00000246 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 00007fa6edcb16b4 RCX: 0000000000450869 RDX: 0000000000000000 RSI: 00000000200000c0 RDI: 0000000000000013 RBP: 000000000072bea0 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff R13: 0000000000008778 R14: 0000000000702838 R15: 00007fa6edcb1700 Code: e9 0b fe ff ff 0f 1f 44 00 00 55 53 48 89 fb 89 f5 e8 3f 07 f3 fe 48 8d 7b 3c 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 14 02 48 89 f8 83 e0 07 83 c0 03 38 d0 7c 04 84 d2 75 51 RIP: qdisc_hash_add+0x26/0xa0 RSP: ffff8800589cf470 When a red qdisc is updated with a 0 limit, the child qdisc is left unmodified, no additional scheduler is created in red_change(), the 'child' local variable is rightfully NULL and must not add it to the hash table. This change addresses the above issue moving qdisc_hash_add() right after the child qdisc creation. It additionally removes unneeded checks for noop_qdisc. Reported-by: Hangbin Liu Fixes: 49b499718fa1 ("net: sched: make default fifo qdiscs appear in the dump") Signed-off-by: Paolo Abeni Acked-by: Jiri Kosina Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sched/sch_red.c | 5 +++-- net/sched/sch_tbf.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) --- a/net/sched/sch_red.c +++ b/net/sched/sch_red.c @@ -191,10 +191,11 @@ static int red_change(struct Qdisc *sch, child = fifo_create_dflt(sch, &bfifo_qdisc_ops, ctl->limit); if (IS_ERR(child)) return PTR_ERR(child); - } - if (child != &noop_qdisc) + /* child is fifo, no need to check for noop_qdisc */ qdisc_hash_add(child, true); + } + sch_tree_lock(sch); q->flags = ctl->flags; q->limit = ctl->limit; --- a/net/sched/sch_tbf.c +++ b/net/sched/sch_tbf.c @@ -388,6 +388,9 @@ static int tbf_change(struct Qdisc *sch, err = PTR_ERR(child); goto done; } + + /* child is fifo, no need to check for noop_qdisc */ + qdisc_hash_add(child, true); } sch_tree_lock(sch); @@ -396,8 +399,6 @@ static int tbf_change(struct Qdisc *sch, q->qdisc->qstats.backlog); qdisc_destroy(q->qdisc); q->qdisc = child; - if (child != &noop_qdisc) - qdisc_hash_add(child, true); } q->limit = qopt->limit; if (tb[TCA_TBF_PBURST])