Skip to contentSkip to conversation

net_sched: fix struct tc_u_hnode layout in u32

PATCH In review Cong Wang 3 participants 3 messages Mar 10, 2015

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 net_sched: fix struct tc_u_hnode layout in u32

We dynamically allocate divisor+1 entries for ->ht[] in tc_u_hnode:

  ht = kzalloc(sizeof(*ht) + divisor*sizeof(void *), GFP_KERNEL);

So ->ht is supposed to be the last field of this struct, however this is broken, since an rcu head is appended after it.

Fixes 1ce87720d456 ("net: sched: make cls_u32 lockless")
Cc Jamal Hadi Salim <[email protected]>
Cc John Fastabend <[email protected]>
---
 net/sched/cls_u32.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/sched/cls_u32.c +4 -1
index 09487af..95fdf4e 100644
@@ -78,8 +78,11 @@ struct tc_u_hnode {
 	struct tc_u_common	*tp_c;
 	int			refcnt;
 	unsigned int		divisor;
-	struct tc_u_knode __rcu	*ht[1];
 	struct rcu_head		rcu;
+	/* The 'ht' field MUST be the last field in structure to allow for
+	 * more entries allocated at end of structure.
+	 */
+	struct tc_u_knode __rcu	*ht[1];
 };
 
 struct tc_u_common {
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#1 lore raw
Quoted 20 lines · Cong Wang

We dynamically allocate divisor+1 entries for ->ht[] in tc_u_hnode:

  ht = kzalloc(sizeof(*ht) + divisor*sizeof(void *), GFP_KERNEL);

So ->ht is supposed to be the last field of this struct, however this is broken, since an rcu head is appended after it.

Fixes 1ce87720d456 ("net: sched: make cls_u32 lockless")
Cc Jamal Hadi Salim <[email protected]>
Cc John Fastabend <[email protected]>
---
 net/sched/cls_u32.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/sched/cls_u32.c +0 -0
index 09487af..95fdf4e 100644

net/sched/cls_u32.c struct tc_u_hnode { · line 86

Quoted 10 lines
net/sched/cls_u32.c +4 -1
@@ -78,8 +78,11 @@ struct tc_u_hnode {
 	struct tc_u_common	*tp_c;
 	int			refcnt;
 	unsigned int		divisor;
-	struct tc_u_knode __rcu	*ht[1];
 	struct rcu_head		rcu;
+	/* The 'ht' field MUST be the last field in structure to allow for
+	 * more entries allocated at end of structure.
+	 */
+	struct tc_u_knode __rcu	*ht[1];
 };

Good catch.

Definitely a call to make this a flexible array in net-next (ht[]), so that compiler would have catch the bug.

maintainer
#2 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Mon, 9 Mar 2015 17:03:40 -0700

Quoted 11 lines

We dynamically allocate divisor+1 entries for ->ht[] in tc_u_hnode:

  ht = kzalloc(sizeof(*ht) + divisor*sizeof(void *), GFP_KERNEL);

So ->ht is supposed to be the last field of this struct, however this is broken, since an rcu head is appended after it.

Fixes 1ce87720d456 ("net: sched: make cls_u32 lockless")
Cc Jamal Hadi Salim <[email protected]>
Cc John Fastabend <[email protected]>

Applied and queued up for -stable, thanks.