* [PATCH] fib:fix BUG_ON in fib_nl_newrule when add new fib rule
@ 2011-09-10 17:19 Wanlong Gao
2011-09-11 7:12 ` Eric Dumazet
2011-09-12 1:36 ` [PATCH resend] " Wanlong Gao
0 siblings, 2 replies; 4+ messages in thread
From: Wanlong Gao @ 2011-09-10 17:19 UTC (permalink / raw)
To: linux-kernel, netdev; +Cc: davem, eric.dumazet, omarapazanadi, Gao feng
From: Gao feng <gaofeng@cn.fujitsu.com>
add new fib rule can cause BUG_ON
the reproduce shell is
#ip rule add pref 38
#ip rule add pref 38
#ip rule add to 192.168.3.0/24 goto 38
#ip rule del pref 38
#ip rule add to 192.168.3.0/24 goto 38
#ip rule add pref 38
then the BUG_ON will happen
add a var unresolved in struct fib_rule
and use it to identify whether this rule is unresolved
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
---
include/net/fib_rules.h | 1 +
net/core/fib_rules.c | 5 ++++-
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/include/net/fib_rules.h b/include/net/fib_rules.h
index 075f1e3..e4bae01 100644
--- a/include/net/fib_rules.h
+++ b/include/net/fib_rules.h
@@ -19,6 +19,7 @@ struct fib_rule {
u32 flags;
u32 table;
u8 action;
+ u8 unresolved;
u32 target;
struct fib_rule __rcu *ctarget;
char iifname[IFNAMSIZ];
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index e7ab0c0..aa20560 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -384,9 +384,11 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
*/
list_for_each_entry(r, &ops->rules_list, list) {
if (r->action == FR_ACT_GOTO &&
- r->target == rule->pref) {
+ r->target == rule->pref &&
+ r->unresolved) {
BUG_ON(rtnl_dereference(r->ctarget) != NULL);
rcu_assign_pointer(r->ctarget, rule);
+ r->unresolved = 0;
if (--ops->unresolved_rules == 0)
break;
}
@@ -488,6 +490,7 @@ static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
list_for_each_entry(tmp, &ops->rules_list, list) {
if (rtnl_dereference(tmp->ctarget) == rule) {
rcu_assign_pointer(tmp->ctarget, NULL);
+ tmp->unresolved = 1;
ops->unresolved_rules++;
}
}
--
1.7.6
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] fib:fix BUG_ON in fib_nl_newrule when add new fib rule
2011-09-10 17:19 [PATCH] fib:fix BUG_ON in fib_nl_newrule when add new fib rule Wanlong Gao
@ 2011-09-11 7:12 ` Eric Dumazet
2011-09-12 1:36 ` [PATCH resend] " Wanlong Gao
1 sibling, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2011-09-11 7:12 UTC (permalink / raw)
To: Wanlong Gao; +Cc: linux-kernel, netdev, davem, omarapazanadi, Gao feng
Le dimanche 11 septembre 2011 à 01:19 +0800, Wanlong Gao a écrit :
> From: Gao feng <gaofeng@cn.fujitsu.com>
>
> add new fib rule can cause BUG_ON
> the reproduce shell is
>
> #ip rule add pref 38
> #ip rule add pref 38
> #ip rule add to 192.168.3.0/24 goto 38
> #ip rule del pref 38
> #ip rule add to 192.168.3.0/24 goto 38
> #ip rule add pref 38
>
> then the BUG_ON will happen
> add a var unresolved in struct fib_rule
> and use it to identify whether this rule is unresolved
>
> Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
> ---
> include/net/fib_rules.h | 1 +
> net/core/fib_rules.c | 5 ++++-
> 2 files changed, 5 insertions(+), 1 deletions(-)
>
> diff --git a/include/net/fib_rules.h b/include/net/fib_rules.h
> index 075f1e3..e4bae01 100644
> --- a/include/net/fib_rules.h
> +++ b/include/net/fib_rules.h
> @@ -19,6 +19,7 @@ struct fib_rule {
> u32 flags;
> u32 table;
> u8 action;
> + u8 unresolved;
> u32 target;
> struct fib_rule __rcu *ctarget;
> char iifname[IFNAMSIZ];
> diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
> index e7ab0c0..aa20560 100644
> --- a/net/core/fib_rules.c
> +++ b/net/core/fib_rules.c
> @@ -384,9 +384,11 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
> */
> list_for_each_entry(r, &ops->rules_list, list) {
> if (r->action == FR_ACT_GOTO &&
> - r->target == rule->pref) {
> + r->target == rule->pref &&
> + r->unresolved) {
> BUG_ON(rtnl_dereference(r->ctarget) != NULL);
> rcu_assign_pointer(r->ctarget, rule);
> + r->unresolved = 0;
> if (--ops->unresolved_rules == 0)
> break;
> }
> @@ -488,6 +490,7 @@ static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
> list_for_each_entry(tmp, &ops->rules_list, list) {
> if (rtnl_dereference(tmp->ctarget) == rule) {
> rcu_assign_pointer(tmp->ctarget, NULL);
> + tmp->unresolved = 1;
> ops->unresolved_rules++;
> }
> }
Hmm, good catch, but you add 'unresolved' field but dont init it
correctly to 1 in all cases.
Following will break :
ip rule add pref 100
ip rule add to 192.168.3.0/24 goto 200
ip rule add pref 200
Normally, we should have
unresolved = (ctarget == NULL);
What about following patch instead ?
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index e7ab0c0..3231b46 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -384,8 +384,8 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
*/
list_for_each_entry(r, &ops->rules_list, list) {
if (r->action == FR_ACT_GOTO &&
- r->target == rule->pref) {
- BUG_ON(rtnl_dereference(r->ctarget) != NULL);
+ r->target == rule->pref &&
+ rtnl_dereference(r->ctarget) == NULL) {
rcu_assign_pointer(r->ctarget, rule);
if (--ops->unresolved_rules == 0)
break;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH resend] fib:fix BUG_ON in fib_nl_newrule when add new fib rule
2011-09-10 17:19 [PATCH] fib:fix BUG_ON in fib_nl_newrule when add new fib rule Wanlong Gao
2011-09-11 7:12 ` Eric Dumazet
@ 2011-09-12 1:36 ` Wanlong Gao
2011-09-21 19:17 ` David Miller
1 sibling, 1 reply; 4+ messages in thread
From: Wanlong Gao @ 2011-09-12 1:36 UTC (permalink / raw)
To: linux-kernel, netdev; +Cc: davem, Gao feng, Gao feng, Eric Dumazet
From: Gao feng <gaofeng@cn.fujitsu.com>
add new fib rule can cause BUG_ON happen
the reproduce shell is
ip rule add pref 38
ip rule add pref 38
ip rule add to 192.168.3.0/24 goto 38
ip rule del pref 38
ip rule add to 192.168.3.0/24 goto 38
ip rule add pref 38
then the BUG_ON will happen
del BUG_ON and use (ctarget == NULL) identify whether this rule is unresolved
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
net/core/fib_rules.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index e7ab0c0..3231b46 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -384,8 +384,8 @@ static int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
*/
list_for_each_entry(r, &ops->rules_list, list) {
if (r->action == FR_ACT_GOTO &&
- r->target == rule->pref) {
- BUG_ON(rtnl_dereference(r->ctarget) != NULL);
+ r->target == rule->pref &&
+ rtnl_dereference(r->ctarget) == NULL) {
rcu_assign_pointer(r->ctarget, rule);
if (--ops->unresolved_rules == 0)
break;
--
1.7.6
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH resend] fib:fix BUG_ON in fib_nl_newrule when add new fib rule
2011-09-12 1:36 ` [PATCH resend] " Wanlong Gao
@ 2011-09-21 19:17 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2011-09-21 19:17 UTC (permalink / raw)
To: wanlong.gao; +Cc: linux-kernel, netdev, omarapazanadi, gaofeng, eric.dumazet
From: Wanlong Gao <wanlong.gao@gmail.com>
Date: Mon, 12 Sep 2011 09:36:05 +0800
> From: Gao feng <gaofeng@cn.fujitsu.com>
>
> add new fib rule can cause BUG_ON happen
> the reproduce shell is
> ip rule add pref 38
> ip rule add pref 38
> ip rule add to 192.168.3.0/24 goto 38
> ip rule del pref 38
> ip rule add to 192.168.3.0/24 goto 38
> ip rule add pref 38
>
> then the BUG_ON will happen
> del BUG_ON and use (ctarget == NULL) identify whether this rule is unresolved
>
> Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Applied, thanks a lot.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-09-21 19:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-10 17:19 [PATCH] fib:fix BUG_ON in fib_nl_newrule when add new fib rule Wanlong Gao
2011-09-11 7:12 ` Eric Dumazet
2011-09-12 1:36 ` [PATCH resend] " Wanlong Gao
2011-09-21 19:17 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).