fib:fix BUG_ON in fib_nl_newrule when add new fib rule
Subsystems (3)
PATCH 1/1 fib:fix BUG_ON in fib_nl_newrule when add new fib rule
From: Gao feng <[email protected]>
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
--- include/net/fib_rules.h | 1 + net/core/fib_rules.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletions(-)
include/net/fib_rules.h +1 -0
@@ -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 ];
net/core/fib_rules.c +4 -1
@@ -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++; } }
Signature · 1 line
1.7.6
Quoted 52 lines · Wanlong Gao
From: Gao feng <[email protected]>
add new fib rule can cause
BUG_ONthe 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 38then the
BUG_ONwill happen
add a var unresolved in structfib_rule
and use it to identify whether this rule is unresolvedSigned-off-by Gao feng <[email protected]>--- include/net/fib_rules.h | 1 + net/core/fib_rules.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletions(-)include/net/fib_rules.h +1
-0@@ -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 ];net/core/fib_rules.c +3
-1@@ -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 ; }
net/core/fib_rules.c static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) · line 496
Quoted 7 lines
net/core/fib_rules.c +1
-0@@ -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 ?
net/core/fib_rules.c +2 -2
@@ -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 ;
PATCH RESEND 1/1 fib:fix BUG_ON in fib_nl_newrule when add new fib rule
In reply to Wanlong GaoFrom: Gao feng <[email protected]>
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
--- net/core/fib_rules.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
net/core/fib_rules.c +2 -2
@@ -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 ;
Signature · 1 line
1.7.6
From: Wanlong Gao <[email protected]>
Date: Mon, 12 Sep 2011 09:36:05 +0800
Quoted 11 lines
From: Gao feng <[email protected]>
add new fib rule can cause
BUG_ONhappen
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
Quoted 5 lines
then the
BUG_ONwill happen
delBUG_ONand use (ctarget == NULL) identify whether this rule is unresolvedSigned-off-by Gao feng <[email protected]>Signed-off-by Eric Dumazet <[email protected]>
Applied, thanks a lot.