Skip to contentSkip to conversation

xfrm: Delete hold_timer when destroy policy

PATCH In review Fan Du 2 participants 4 messages Aug 1, 2013 – Aug 6, 2013

Subsystems (3)
lore
Share & tools
lore

Fan Du

author
#0 lore raw

PATCH 1/1 xfrm: Delete hold_timer when destroy policy

Both policy timer and hold_timer need to be deleted when destroy policy Bad mood today, maybe I'm wrong about this...

---
 net/xfrm/xfrm_policy.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/xfrm/xfrm_policy.c +1 -1
index d8da6b8..f7078eb 100644
@@ -308,7 +308,7 @@ void xfrm_policy_destroy(struct xfrm_policy *policy)
 {
 	BUG_ON(!policy->walk.dead);
 
-	if (del_timer(&policy->timer))
+	if (del_timer(&policy->timer) || del_timer(&policy->polq.hold_timer))
 		BUG();
 
 	security_xfrm_policy_free(policy->security);
Signature · 1 line
1.7.1
maintainer
#1 lore raw
Quoted 13 lines · Fan Du

Both policy timer and hold_timer need to be deleted when destroy policy Bad mood today, maybe I'm wrong about this...

---
 net/xfrm/xfrm_policy.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/xfrm/xfrm_policy.c +0 -0
index d8da6b8..f7078eb 100644

net/xfrm/xfrm_policy.c void xfrm_policy_destroy(struct xfrm_policy *policy) · line 313

Quoted 7 lines
net/xfrm/xfrm_policy.c +1 -1
@@ -308,7 +308,7 @@ void xfrm_policy_destroy(struct xfrm_policy *policy)
 {
 	BUG_ON(!policy->walk.dead);
 
-	if (del_timer(&policy->timer))
+	if (del_timer(&policy->timer) || del_timer(&policy->polq.hold_timer))
 		BUG();
 

The timers should be already deleted when xfrm_policy_destroy() is called. This is just to check if that really happened and to catch this bug if not. So it's not a bug fix, it just helps to catch a potential bug. I'll consider to take this into ipsec-next after some testing.

author
#2 lore raw
Quoted 17 lines · Steffen Klassert
Quoted 16 lines · Fan Du

Both policy timer and hold_timer need to be deleted when destroy policy Bad mood today, maybe I'm wrong about this...

---
  net/xfrm/xfrm_policy.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
net/xfrm/xfrm_policy.c +0 -0
index d8da6b8..f7078eb 100644
@@ -308,7 +308,7 @@ void xfrm_policy_destroy(struct xfrm_policy *policy)
  {
  	BUG_ON(!policy->walk.dead);
 
Quoted 11 lines

net/xfrm/xfrm_policy.c void xfrm_policy_destroy(struct xfrm_policy *policy) · line 313

Quoted 4 lines
net/xfrm/xfrm_policy.c +1 -1
-	if (del_timer(&policy->timer))
+	if (del_timer(&policy->timer) || del_timer(&policy->polq.hold_timer))
  		BUG();
 

The timers should be already deleted when xfrm_policy_destroy() is called. This is just to check if that really happened and to catch this bug if not. So it's not a bug fix, it just helps to catch a potential bug. I'll consider to take this into ipsec-next after some testing.

On the contrary, please take a look at callers of xfrm_policy_destroy. Code flow is as below:

xfrm_policy_alloc() /* setup timer/hold_timer here */ (1)

/* do something with this policy, insert or something else */

goto err; /* bail out if bad things happens */

return ok

err:
xfrm_policy_destroy() /*So both timers in (1) need to be deleted */

Signature · 3 lines
浮沉随浪只记今朝笑

--fan
maintainer
#3 lore raw
Quoted 37 lines · Fan Du
Quoted 17 lines · Steffen Klassert
Quoted 16 lines · Fan Du

Both policy timer and hold_timer need to be deleted when destroy policy Bad mood today, maybe I'm wrong about this...

---
 net/xfrm/xfrm_policy.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/xfrm/xfrm_policy.c +0 -0
index d8da6b8..f7078eb 100644
@@ -308,7 +308,7 @@ void xfrm_policy_destroy(struct xfrm_policy *policy)
 {
 	BUG_ON(!policy->walk.dead);
 
Quoted 11 lines

net/xfrm/xfrm_policy.c void xfrm_policy_destroy(struct xfrm_policy *policy) · line 313

Quoted 4 lines
net/xfrm/xfrm_policy.c +1 -1
-	if (del_timer(&policy->timer))
+	if (del_timer(&policy->timer) || del_timer(&policy->polq.hold_timer))
 		BUG();
 

The timers should be already deleted when xfrm_policy_destroy() is called. This is just to check if that really happened and to catch this bug if not. So it's not a bug fix, it just helps to catch a potential bug. I'll consider to take this into ipsec-next after some testing.

On the contrary, please take a look at callers of xfrm_policy_destroy. Code flow is as below:

xfrm_policy_alloc() /* setup timer/hold_timer here */ (1)

Quoted 9 lines

/* do something with this policy, insert or something else */

goto err; /* bail out if bad things happens */

return ok

err:
xfrm_policy_destroy() /*So both timers in (1) need to be deleted */

setup_timer() does not arm the timer, it just initializes the timer. So the timer is not pending when xfrm_policy_destroy() is called on error. The del_timer() in xfrm_policy_destroy() is really just to catch a bug. That's also the reason why we call BUG() if we delete a pending timer.

Anyway, applied to ipsec-next.

Thanks!