Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4359738pxj; Tue, 8 Jun 2021 12:21:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlXnqsUpiiKbxXlT68ZK6V1135VpAp1XK96+UGBAS0sTnp5JiTzMdjbk7bmOLMmkFqb82X X-Received: by 2002:a50:8751:: with SMTP id 17mr27237152edv.340.1623180119420; Tue, 08 Jun 2021 12:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623180119; cv=none; d=google.com; s=arc-20160816; b=Gom19sgvaplFHfbap/ykUEqHM6GWm1uf0aaDJAph6M5/NXoecD4is8DI/vmJhDUV4R IR5UcrpopHSaOtCFgUCCzPjtfkkun8ddHII3pR/xWWmAER2NHh68APcz5idtotZPHF+E /R4mWUcXAGBiEM6qSXhGyaNuUjFQK8V7gXpc4+mgEty9Hsodl4+AhExIoCuENr2MBv75 tQN3UyvinLKD4/iSijFKItb2jak0IubdqJQPx3d2C4Uj1Nk04qHihYA4UICNr02A/jjP RDwdjKFoDLTlsW20csJctUjA1OlS0/LzVq/HGFa5Xb3FkEcpaJL+M8Vf02ZwQLoYNEfC Rx9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rgl0xkx0hRlXCjOWY81a7PCakhb17KWxACxeMs68lYg=; b=NH53xGv/MQgp6nWLW36bHGIfK7+Gr13AdBQ4Din1KUlr3UD3K5ScxEOtKRq7deGVVF /KIagNBsfGE6WGM9dy5j1lRdh/x57dARvsZn6X3KEHM+psP0cGjFDKyXhtwXG3x8qyhW I5yZ8oR9nWvTKtn4pkY6LxhctaaJNRdUAwfxpte/nxFqMa1h9ePgRzt41EUhh4r3COfG i2bgSdWA3VTT1EAeaz4vGX2bdbEWxCv97BIr3hnM7WI4TDcdJD41hlEgPMLYum9Cpad/ MpqfdCi1Uvi7FZMB1hvoufNko0pPYo6asj2eR88vhtNQJsATrimg9kCg3IfxOJiCywUm RXxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wNQj6cSi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m7si485963edq.604.2021.06.08.12.21.36; Tue, 08 Jun 2021 12:21:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wNQj6cSi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238080AbhFHTSy (ORCPT + 99 others); Tue, 8 Jun 2021 15:18:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:55034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234617AbhFHTHf (ORCPT ); Tue, 8 Jun 2021 15:07:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EB28B613C3; Tue, 8 Jun 2021 18:47:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623178048; bh=qRgtV29vkt8l+bN+ZbQtiyJWZXFD63rBV8gf154Nykc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wNQj6cSik5DeNA1FHoZVjsiVzyiBLha7N728DRYw8gZxwOXkjEc2Su3nucV5ywrPe rKQTRljAiUKtbtFIf2GnAaNwJsZAuuwYhoJNFIJqIGvoZATDNagfFh+xM9nLmiaNPf dXyKuj8JlQ77MfqtPMTHXpeZL/zq0IkKSfb/inho= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yunjian Wang , Maxim Mikityanskiy , "David S. Miller" , Sasha Levin Subject: [PATCH 5.12 058/161] sch_htb: fix refcount leak in htb_parent_to_leaf_offload Date: Tue, 8 Jun 2021 20:26:28 +0200 Message-Id: <20210608175947.434459023@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175945.476074951@linuxfoundation.org> References: <20210608175945.476074951@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yunjian Wang [ Upstream commit 944d671d5faa0d78980a3da5c0f04960ef1ad893 ] The commit ae81feb7338c ("sch_htb: fix null pointer dereference on a null new_q") fixes a NULL pointer dereference bug, but it is not correct. Because htb_graft_helper properly handles the case when new_q is NULL, and after the previous patch by skipping this call which creates an inconsistency : dev_queue->qdisc will still point to the old qdisc, but cl->parent->leaf.q will point to the new one (which will be noop_qdisc, because new_q was NULL). The code is based on an assumption that these two pointers are the same, so it can lead to refcount leaks. The correct fix is to add a NULL pointer check to protect qdisc_refcount_inc inside htb_parent_to_leaf_offload. Fixes: ae81feb7338c ("sch_htb: fix null pointer dereference on a null new_q") Signed-off-by: Yunjian Wang Suggested-by: Maxim Mikityanskiy Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sched/sch_htb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c index 081c11d5717c..8827987ba903 100644 --- a/net/sched/sch_htb.c +++ b/net/sched/sch_htb.c @@ -1488,7 +1488,8 @@ static void htb_parent_to_leaf_offload(struct Qdisc *sch, struct Qdisc *old_q; /* One ref for cl->leaf.q, the other for dev_queue->qdisc. */ - qdisc_refcount_inc(new_q); + if (new_q) + qdisc_refcount_inc(new_q); old_q = htb_graft_helper(dev_queue, new_q); WARN_ON(!(old_q->flags & TCQ_F_BUILTIN)); } @@ -1675,10 +1676,9 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg, cl->parent->common.classid, NULL); if (q->offload) { - if (new_q) { + if (new_q) htb_set_lockdep_class_child(new_q); - htb_parent_to_leaf_offload(sch, dev_queue, new_q); - } + htb_parent_to_leaf_offload(sch, dev_queue, new_q); } } -- 2.30.2