Commit 7be8ef2c authored by Dmytro Linkin's avatar Dmytro Linkin Committed by David S. Miller
Browse files

net: sched: use temporary variable for actions indexes



Currently init call of all actions (except ipt) init their 'parm'
structure as a direct pointer to nla data in skb. This leads to race
condition when some of the filter actions were initialized successfully
(and were assigned with idr action index that was written directly
into nla data), but then were deleted and retried (due to following
action module missing or classifier-initiated retry), in which case
action init code tries to insert action to idr with index that was
assigned on previous iteration. During retry the index can be reused
by another action that was inserted concurrently, which causes
unintended action sharing between filters.
To fix described race condition, save action idr index to temporary
stack-allocated variable instead on nla data.

Fixes: 0190c1d4 ("net: sched: atomically check-allocate action")
Signed-off-by: default avatarDmytro Linkin <dmitrolin@mellanox.com>
Signed-off-by: default avatarVlad Buslov <vladbu@mellanox.com>
Acked-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7fb5a711
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -285,6 +285,7 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla,
	struct tcf_bpf *prog;
	bool is_bpf, is_ebpf;
	int ret, res = 0;
	u32 index;

	if (!nla)
		return -EINVAL;
@@ -298,13 +299,13 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla,
		return -EINVAL;

	parm = nla_data(tb[TCA_ACT_BPF_PARMS]);

	ret = tcf_idr_check_alloc(tn, &parm->index, act, bind);
	index = parm->index;
	ret = tcf_idr_check_alloc(tn, &index, act, bind);
	if (!ret) {
		ret = tcf_idr_create(tn, parm->index, est, act,
		ret = tcf_idr_create(tn, index, est, act,
				     &act_bpf_ops, bind, true);
		if (ret < 0) {
			tcf_idr_cleanup(tn, parm->index);
			tcf_idr_cleanup(tn, index);
			return ret;
		}

+5 −4
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ static int tcf_connmark_init(struct net *net, struct nlattr *nla,
	struct tcf_connmark_info *ci;
	struct tc_connmark *parm;
	int ret = 0, err;
	u32 index;

	if (!nla)
		return -EINVAL;
@@ -116,13 +117,13 @@ static int tcf_connmark_init(struct net *net, struct nlattr *nla,
		return -EINVAL;

	parm = nla_data(tb[TCA_CONNMARK_PARMS]);

	ret = tcf_idr_check_alloc(tn, &parm->index, a, bind);
	index = parm->index;
	ret = tcf_idr_check_alloc(tn, &index, a, bind);
	if (!ret) {
		ret = tcf_idr_create(tn, parm->index, est, a,
		ret = tcf_idr_create(tn, index, est, a,
				     &act_connmark_ops, bind, false);
		if (ret) {
			tcf_idr_cleanup(tn, parm->index);
			tcf_idr_cleanup(tn, index);
			return ret;
		}

+5 −4
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ static int tcf_csum_init(struct net *net, struct nlattr *nla,
	struct tc_csum *parm;
	struct tcf_csum *p;
	int ret = 0, err;
	u32 index;

	if (nla == NULL)
		return -EINVAL;
@@ -64,13 +65,13 @@ static int tcf_csum_init(struct net *net, struct nlattr *nla,
	if (tb[TCA_CSUM_PARMS] == NULL)
		return -EINVAL;
	parm = nla_data(tb[TCA_CSUM_PARMS]);

	err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
	index = parm->index;
	err = tcf_idr_check_alloc(tn, &index, a, bind);
	if (!err) {
		ret = tcf_idr_create(tn, parm->index, est, a,
		ret = tcf_idr_create(tn, index, est, a,
				     &act_csum_ops, bind, true);
		if (ret) {
			tcf_idr_cleanup(tn, parm->index);
			tcf_idr_cleanup(tn, index);
			return ret;
		}
		ret = ACT_P_CREATED;
+5 −4
Original line number Diff line number Diff line
@@ -666,6 +666,7 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,
	struct tc_ct *parm;
	struct tcf_ct *c;
	int err, res = 0;
	u32 index;

	if (!nla) {
		NL_SET_ERR_MSG_MOD(extack, "Ct requires attributes to be passed");
@@ -681,16 +682,16 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,
		return -EINVAL;
	}
	parm = nla_data(tb[TCA_CT_PARMS]);

	err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
	index = parm->index;
	err = tcf_idr_check_alloc(tn, &index, a, bind);
	if (err < 0)
		return err;

	if (!err) {
		err = tcf_idr_create(tn, parm->index, est, a,
		err = tcf_idr_create(tn, index, est, a,
				     &act_ct_ops, bind, true);
		if (err) {
			tcf_idr_cleanup(tn, parm->index);
			tcf_idr_cleanup(tn, index);
			return err;
		}
		res = ACT_P_CREATED;
+5 −4
Original line number Diff line number Diff line
@@ -157,10 +157,10 @@ static int tcf_ctinfo_init(struct net *net, struct nlattr *nla,
			   struct netlink_ext_ack *extack)
{
	struct tc_action_net *tn = net_generic(net, ctinfo_net_id);
	u32 dscpmask = 0, dscpstatemask, index;
	struct nlattr *tb[TCA_CTINFO_MAX + 1];
	struct tcf_ctinfo_params *cp_new;
	struct tcf_chain *goto_ch = NULL;
	u32 dscpmask = 0, dscpstatemask;
	struct tc_ctinfo *actparm;
	struct tcf_ctinfo *ci;
	u8 dscpmaskshift;
@@ -206,12 +206,13 @@ static int tcf_ctinfo_init(struct net *net, struct nlattr *nla,
	}

	/* done the validation:now to the actual action allocation */
	err = tcf_idr_check_alloc(tn, &actparm->index, a, bind);
	index = actparm->index;
	err = tcf_idr_check_alloc(tn, &index, a, bind);
	if (!err) {
		ret = tcf_idr_create(tn, actparm->index, est, a,
		ret = tcf_idr_create(tn, index, est, a,
				     &act_ctinfo_ops, bind, false);
		if (ret) {
			tcf_idr_cleanup(tn, actparm->index);
			tcf_idr_cleanup(tn, index);
			return ret;
		}
		ret = ACT_P_CREATED;
Loading