From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C710BC4332F for ; Sun, 8 Sep 2019 12:57:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A14D92081B for ; Sun, 8 Sep 2019 12:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567947477; bh=A9IErmwm/sY8MQkwbPXh+/Q0dPv8y4x2fUnBeVQcIVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=UVgdON5d3Zs9EqI4VHij4BvF/7JazEbVk/Bt9bj3PCO+U0i71x/X8NTodRspTLbxI BJnw39wKl2N1htdpvAbYakp+7w3Pmyu61wEUiKi1liXIfOZykbpewXuNqYp3M94nDT M3sdDI/HNuFRXyFIMxCF1BhCr8hKD2Lxz9YJRZaw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730794AbfIHMrt (ORCPT ); Sun, 8 Sep 2019 08:47:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:36462 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730787AbfIHMrt (ORCPT ); Sun, 8 Sep 2019 08:47:49 -0400 Received: from localhost (unknown [62.28.240.114]) (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 BC0FD21927; Sun, 8 Sep 2019 12:47:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567946868; bh=A9IErmwm/sY8MQkwbPXh+/Q0dPv8y4x2fUnBeVQcIVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1dcIke9dyjf43vYcuqd/+0HT94JQSkvCgswlVFJqxfJKT8ZYd5B+YTWmJdct5V6DF yKVq1N8qXJ0Pua1eOMf5dFz2gVoW9RHj2Xk+Uy4rQlN3YhUwp72RlO5zrQBGC7q3fT YKKSVDxggQRDljH47B5BXEEaXAjPPV/2w3QGf/7w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vlad Buslov , "David S. Miller" Subject: [PATCH 4.19 03/57] net: sched: act_sample: fix psample group handling on overwrite Date: Sun, 8 Sep 2019 13:41:27 +0100 Message-Id: <20190908121127.301930233@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190908121125.608195329@linuxfoundation.org> References: <20190908121125.608195329@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Vlad Buslov [ Upstream commit dbf47a2a094edf58983265e323ca4bdcdb58b5ee ] Action sample doesn't properly handle psample_group pointer in overwrite case. Following issues need to be fixed: - In tcf_sample_init() function RCU_INIT_POINTER() is used to set s->psample_group, even though we neither setting the pointer to NULL, nor preventing concurrent readers from accessing the pointer in some way. Use rcu_swap_protected() instead to safely reset the pointer. - Old value of s->psample_group is not released or deallocated in any way, which results resource leak. Use psample_group_put() on non-NULL value obtained with rcu_swap_protected(). - The function psample_group_put() that released reference to struct psample_group pointed by rcu-pointer s->psample_group doesn't respect rcu grace period when deallocating it. Extend struct psample_group with rcu head and use kfree_rcu when freeing it. Fixes: 5c5670fae430 ("net/sched: Introduce sample tc action") Signed-off-by: Vlad Buslov Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/net/psample.h | 1 + net/psample/psample.c | 2 +- net/sched/act_sample.c | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) --- a/include/net/psample.h +++ b/include/net/psample.h @@ -12,6 +12,7 @@ struct psample_group { u32 group_num; u32 refcount; u32 seq; + struct rcu_head rcu; }; struct psample_group *psample_group_get(struct net *net, u32 group_num); --- a/net/psample/psample.c +++ b/net/psample/psample.c @@ -156,7 +156,7 @@ static void psample_group_destroy(struct { psample_group_notify(group, PSAMPLE_CMD_DEL_GROUP); list_del(&group->list); - kfree(group); + kfree_rcu(group, rcu); } static struct psample_group * --- a/net/sched/act_sample.c +++ b/net/sched/act_sample.c @@ -99,7 +99,8 @@ static int tcf_sample_init(struct net *n s->tcf_action = parm->action; s->rate = rate; s->psample_group_num = psample_group_num; - RCU_INIT_POINTER(s->psample_group, psample_group); + rcu_swap_protected(s->psample_group, psample_group, + lockdep_is_held(&s->tcf_lock)); if (tb[TCA_SAMPLE_TRUNC_SIZE]) { s->truncate = true; @@ -107,6 +108,8 @@ static int tcf_sample_init(struct net *n } spin_unlock_bh(&s->tcf_lock); + if (psample_group) + psample_group_put(psample_group); if (ret == ACT_P_CREATED) tcf_idr_insert(tn, *a); return ret;