Skip to contentSkip to conversation

cls_cgroup: read classid atomically in classifier

PATCH In review Paul Menage 3 participants 3 messages May 21, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cls_cgroup: read classid atomically in classifier

cls_cgroup: read classid atomically in classifier

Avoid reading the unsynchronized value cs->classid multiple times, since it could change concurrently from non-zero to zero; this would result in the classifier returning a positive result with a bogus (zero) classid.

---

Resending to cc [email protected] as requested by DaveM

 net/sched/cls_cgroup.c |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)
net/sched/cls_cgroup.c +11 -11
index 1ab4542..4ece6e0 100644
@@ -98,8 +98,7 @@ static int cls_cgroup_classify(struct sk_buff *skb, struct tcf_proto *tp,
 			       struct tcf_result *res)
 {
 	struct cls_cgroup_head *head = tp->root;
-	struct cgroup_cls_state *cs;
-	int ret = 0;
+        u32 classid;
 
 	/*
 	 * Due to the nature of the classifier it is required to ignore all
@@ -115,17 +114,18 @@ static int cls_cgroup_classify(struct sk_buff *skb, struct tcf_proto *tp,
 		return -1;
 
 	rcu_read_lock();
-	cs = task_cls_state(current);
-	if (cs->classid && tcf_em_tree_match(skb, &head->ematches, NULL)) {
-		res->classid = cs->classid;
-		res->class = 0;
-		ret = tcf_exts_exec(skb, &head->exts, res);
-	} else
-		ret = -1;
-
+	classid = task_cls_state(current)->classid;
 	rcu_read_unlock();
 
-	return ret;
+	if (!classid)
+		return -1;
+
+	if (!tcf_em_tree_match(skb, &head->ematches, NULL))
+		return -1;
+
+	res->classid = classid;
+	res->class = 0;
+	return tcf_exts_exec(skb, &head->exts, res);
 }
 
 static unsigned long cls_cgroup_get(struct tcf_proto *tp, u32 handle)
#1 lore raw
Quoted 22 lines · Thu, May 21, 2009 at 08:31:26PM CEST, [email protected] wrote:

cls_cgroup: read classid atomically in classifier

Avoid reading the unsynchronized value cs->classid multiple times, since it could change concurrently from non-zero to zero; this would result in the classifier returning a positive result with a bogus (zero) classid.

---

Resending to cc [email protected] as requested by DaveM

net/sched/cls_cgroup.c | 22 +++++++++++-----------

1 files changed, 11 insertions(+), 11 deletions(-)
net/sched/cls_cgroup.c +0 -0
index 1ab4542..4ece6e0 100644

net/sched/cls_cgroup.c static int cls_cgroup_classify(struct sk_buff *skb, struct tcf_proto *tp, · line 101

Quoted 6 lines
net/sched/cls_cgroup.c +1 -2
@@ -98,8 +98,7 @@ static int cls_cgroup_classify(struct sk_buff *skb, struct tcf_proto *tp,
 			       struct tcf_result *res)
 {
 	struct cls_cgroup_head *head = tp->root;
-	struct cgroup_cls_state *cs;
-	int ret = 0;
+        u32 classid;

^^^^^^^^ How about using TAB instead?

Quoted 36 lines
net/sched/cls_cgroup.c +10 -10
 	/*
 	 * Due to the nature of the classifier it is required to ignore all
@@ -115,17 +114,18 @@ static int cls_cgroup_classify(struct sk_buff *skb, struct tcf_proto *tp,
 		return -1;
 
 	rcu_read_lock();
-	cs = task_cls_state(current);
-	if (cs->classid && tcf_em_tree_match(skb, &head->ematches, NULL)) {
-		res->classid = cs->classid;
-		res->class = 0;
-		ret = tcf_exts_exec(skb, &head->exts, res);
-	} else
-		ret = -1;
-
+	classid = task_cls_state(current)->classid;
 	rcu_read_unlock();
 
-	return ret;
+	if (!classid)
+		return -1;
+
+	if (!tcf_em_tree_match(skb, &head->ematches, NULL))
+		return -1;
+
+	res->classid = classid;
+	res->class = 0;
+	return tcf_exts_exec(skb, &head->exts, res);
 }
 
 static unsigned long cls_cgroup_get(struct tcf_proto *tp, u32 handle)
 
--

To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#2 lore raw

From: Jiri Pirko <[email protected]>
Date: Thu, 21 May 2009 21:44:48 +0200

Quoted 18 lines
Quoted 17 lines · Thu, May 21, 2009 at 08:31:26PM CEST, [email protected] wrote:

cls_cgroup: read classid atomically in classifier

Avoid reading the unsynchronized value cs->classid multiple times, since it could change concurrently from non-zero to zero; this would result in the classifier returning a positive result with a bogus (zero) classid.

---

Resending to cc [email protected] as requested by DaveM

net/sched/cls_cgroup.c | 22 +++++++++++-----------

1 files changed, 11 insertions(+), 11 deletions(-)
Quoted 12 lines

net/sched/cls_cgroup.c static int cls_cgroup_classify(struct sk_buff *skb, struct tcf_proto *tp, · line 101

Quoted 11 lines
net/sched/cls_cgroup.c +1 -2
index 1ab4542..4ece6e0 100644
@@ -98,8 +98,7 @@ static int cls_cgroup_classify(struct sk_buff *skb, struct tcf_proto *tp,
 			       struct tcf_result *res)
 {
 	struct cls_cgroup_head *head = tp->root;
-	struct cgroup_cls_state *cs;
-	int ret = 0;
+        u32 classid;

^^^^^^^^ How about using TAB instead?

Agreed, please use proper formatting.