Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4049232ybe; Mon, 9 Sep 2019 03:25:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9EB9YSV+f1ijN9VYFOzqX+SOLRAFjmER4l30Xd/gfQGMkCJBYM/ypgVnNZAvuNBG5gSst X-Received: by 2002:a50:b19c:: with SMTP id m28mr23186948edd.189.1568024717908; Mon, 09 Sep 2019 03:25:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568024717; cv=none; d=google.com; s=arc-20160816; b=P0uENIU8/RofKVBS4OT04kK4sy6Kdii40798UZwD37IQzpEL6tzM/6Sj1EJIjSyHTP TdUz0XJjRJpFuQ7gxHBnHzVul8c+D7pkVkA5ZyaysgAqVYwuWo7mu1PO2vW30iFeI31W GGvCpjOrf3q22J3zugLj/xi0qbB9jrSWyxCO2rIEZHRU2yJFizoiaAlkGZCdd5gadgnA vlrVleir9HnA+mjngkpRm8DqcZKnHtdSpxeumQTpJfHmcJFHkv7mH7j2VjqektxhLOKe db/GyFmTHQZdJkl9EJbtV4MEQTe7cbh0syKm7Yoj82JtGw6XmCltZRkY5c5tWmgaTh4i eQdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=C49YjgEmlMw/FVGMAZJN6zjEt0qxVXIEnP6/l+MigSE=; b=oe0+v6a8/5Ca3AGf+MWtIuan1WayaVyNyw8UYxmT4915yUJa5Rbz82U/lVkubkXvWT itO1XP3Nw2/fGXVMCSLCLD/K2ynAW5YgnUI54h2WtTpB2cm1Y8CCjM+6kPgYz4J48q/P 1/wqsVyoARzPapbMMcXzigNADQlNrVAVEtIQY4+M4tJn6xiSj/QYb3wb0jyDUraKOxt9 2VqCnf7Sq+dBiXJmDy4e+vET4ueL5DTTgp/9bElY0z8UcS4BGSd0MMagbyv9i/GHCG5H 5YqP6v87RD9n0dRiWQitNq3n3mtYc8dnejI8r/gYgu+B/PROwcowgKV2gMDuR3LWh9+t H8Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="h1/eR6f0"; 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 b22si8581725eda.194.2019.09.09.03.24.54; Mon, 09 Sep 2019 03:25:17 -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="h1/eR6f0"; 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 S1731504AbfIHMt3 (ORCPT + 99 others); Sun, 8 Sep 2019 08:49:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:39420 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731431AbfIHMt1 (ORCPT ); Sun, 8 Sep 2019 08:49:27 -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 A3CD1218AF; Sun, 8 Sep 2019 12:49:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567946967; bh=bJ0k3ILoIt5GOaVgDgkaBUsemy5WapQCN3Gaw5S1tgs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h1/eR6f0mA0VdqhLAJJsOSuGUhEPlZ2wuMYXCHiY3ijkF7nVaKTf80CLaxuTTECTs M6Nnxm4lGoeLbj5J/4sOHKoqh2sIIxeemcB/3nexl1bnQw0f4m+6RTwTU9kloywsbW 1s/9beeTpvI1RVt+hzwgnJugeeR6vT7dtwLawqvQ= 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 5.2 03/94] net: sched: act_sample: fix psample group handling on overwrite Date: Sun, 8 Sep 2019 13:40:59 +0100 Message-Id: <20190908121150.529366497@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190908121150.420989666@linuxfoundation.org> References: <20190908121150.420989666@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) --- a/include/net/psample.h +++ b/include/net/psample.h @@ -11,6 +11,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 @@ -154,7 +154,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 @@ -102,13 +102,17 @@ static int tcf_sample_init(struct net *n goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch); 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; s->trunc_size = nla_get_u32(tb[TCA_SAMPLE_TRUNC_SIZE]); } spin_unlock_bh(&s->tcf_lock); + + if (psample_group) + psample_group_put(psample_group); if (goto_ch) tcf_chain_put_by_act(goto_ch);