Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3673452pxv; Mon, 26 Jul 2021 09:08:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzP4+moGNGzFtc5GRPNWDpWB4qbLxTybckBcR2oH0jy1jnGD7iwL8+H1Vs6tBuun0ir00tL X-Received: by 2002:a05:6602:59d:: with SMTP id v29mr15447147iox.132.1627315734501; Mon, 26 Jul 2021 09:08:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627315734; cv=none; d=google.com; s=arc-20160816; b=FJXDwVgJ+zQerqok6L+ZblgunN44zsAcrwhPkcCrowYD+qwsbEBKKmtutxWKIXoYP4 W/h3CueR95f21/axkokSYW0+Lpx6GP72OIY9N4hRlZaA5VbQNhUH47Xc0wGdOsXVhz6v ZYebBuTt/8UeQkc67aPHzqXg5Cq5/RE50l0IedC7vd9RfXQr59bOP7arqnzAJhXnCneY Qp5pyrjGPVtAdqNPsLSNDCz3zYvi1ijjV7CFE2Vh4zHWnPn3xVFRs+9BZmsG/JPS1bRp Wg1GGUbO1kbEn2QcV7moQ6vRjntq2IW4aUqa5C7wS5OoS1jPhbw6gtTeuK6vJ4r9Tfnx fGKQ== 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=5p18z+O5E0Ji45E7jKJFTzEpLhBmfnGxc9+dLF4lpic=; b=uXWDj8hLHZZKWFmFBplIC8p1+FqsTb6RGduQZ040mG8tTu2zM9V3NKKhvuyHmJtCmB dg+uQV2e4kqzdnkR7CG6qkAbZstvSGqV9K6XhDDiPdj+4KxDkXf9VSqsNI3grsfue+a2 LexLF3ni7gcnaAZMc87GrKGHq2YjvRwi1NiMwYuOgI4vy0i1YlMWwTDPf099SSid3fL3 rOtcU7AJz7spx24VT4n70tTYCeRvRRBfhFAIDBvppZ0W3/ksu4Cgyxc3W43elrAHkiDJ DITwaPFblJXdtHFR/UqeMovSwDJDrgnQyB44ATji3XX2Jw2HdvRECx4j2NooOIFoziF7 mRhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=A4HNKYTM; 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 d24si332211iob.3.2021.07.26.09.08.41; Mon, 26 Jul 2021 09:08:54 -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=A4HNKYTM; 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 S237980AbhGZPY3 (ORCPT + 99 others); Mon, 26 Jul 2021 11:24:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:55652 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237573AbhGZPQG (ORCPT ); Mon, 26 Jul 2021 11:16:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 308F360F02; Mon, 26 Jul 2021 15:56:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627314994; bh=eZZBQ0hQLixfIx0ngE++QqALKOgwIbU6lo/WcK+LRA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A4HNKYTMqyCF0goRdKtPCNnE55blj0JacBeTz9DxMc4ZZ+dpOOFN+/YZvp03fOo4X F4IxS1SD24SsT/87WSOb2yqJ7zxo79XfpqKmToXRxpuLU5idfHHsD59aM4wM+R4XzG ey4Wg2xPz0T3GYLTnh/BGQSxXOVhFboihQXRn9aY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Skripkin , "David S. Miller" , Sasha Levin , syzbot+f0bbb2287b8993d4fa74@syzkaller.appspotmail.com Subject: [PATCH 5.4 046/108] net: sched: fix memory leak in tcindex_partial_destroy_work Date: Mon, 26 Jul 2021 17:38:47 +0200 Message-Id: <20210726153833.165007842@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153831.696295003@linuxfoundation.org> References: <20210726153831.696295003@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: Pavel Skripkin [ Upstream commit f5051bcece50140abd1a11a2d36dc3ec5484fc32 ] Syzbot reported memory leak in tcindex_set_parms(). The problem was in non-freed perfect hash in tcindex_partial_destroy_work(). In tcindex_set_parms() new tcindex_data is allocated and some fields from old one are copied to new one, but not the perfect hash. Since tcindex_partial_destroy_work() is the destroy function for old tcindex_data, we need to free perfect hash to avoid memory leak. Reported-and-tested-by: syzbot+f0bbb2287b8993d4fa74@syzkaller.appspotmail.com Fixes: 331b72922c5f ("net: sched: RCU cls_tcindex") Signed-off-by: Pavel Skripkin Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sched/cls_tcindex.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/sched/cls_tcindex.c b/net/sched/cls_tcindex.c index 3e81f87d0c89..684187a1fdb9 100644 --- a/net/sched/cls_tcindex.c +++ b/net/sched/cls_tcindex.c @@ -278,6 +278,8 @@ static int tcindex_filter_result_init(struct tcindex_filter_result *r, TCA_TCINDEX_POLICE); } +static void tcindex_free_perfect_hash(struct tcindex_data *cp); + static void tcindex_partial_destroy_work(struct work_struct *work) { struct tcindex_data *p = container_of(to_rcu_work(work), @@ -285,7 +287,8 @@ static void tcindex_partial_destroy_work(struct work_struct *work) rwork); rtnl_lock(); - kfree(p->perfect); + if (p->perfect) + tcindex_free_perfect_hash(p); kfree(p); rtnl_unlock(); } -- 2.30.2