All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH ipsec] xfrm: Ignore socket policies when rebuilding hash tables
@ 2016-07-29  7:57 Tobias Brunner
  2016-07-29  8:19 ` Herbert Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Tobias Brunner @ 2016-07-29  7:57 UTC (permalink / raw)
  To: Steffen Klassert, David S. Miller; +Cc: netdev, Herbert Xu, Christophe Gouault

Whenever thresholds are changed the hash tables are rebuilt.  This is
done by enumerating all policies and hashing and inserting them into
the right table according to the thresholds and direction.

Because socket policies are also contained in net->xfrm.policy_all but
no hash tables are defined for their direction (dir + XFRM_POLICY_MAX)
this causes a NULL or invalid pointer dereference after returning from
policy_hash_bysel() if the rebuild is done while any socket policies
are installed.

Since the rebuild after changing thresholds is scheduled this crash
could even occur if the userland sets thresholds seemingly before
installing any socket policies.

Fixes: 53c2e285f970 ("xfrm: Do not hash socket policies")
Signed-off-by: Tobias Brunner <tobias@strongswan.org>
---
 net/xfrm/xfrm_policy.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index b5e665b3cfb0..45f9cf97ea25 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -626,6 +626,10 @@ static void xfrm_hash_rebuild(struct work_struct *work)
 
 	/* re-insert all policies by order of creation */
 	list_for_each_entry_reverse(policy, &net->xfrm.policy_all, walk.all) {
+		if (xfrm_policy_id2dir(policy->index) >= XFRM_POLICY_MAX) {
+			/* skip socket policies */
+			continue;
+		}
 		newpos = NULL;
 		chain = policy_hash_bysel(net, &policy->selector,
 					  policy->family,
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH ipsec] xfrm: Ignore socket policies when rebuilding hash tables
  2016-07-29  7:57 [PATCH ipsec] xfrm: Ignore socket policies when rebuilding hash tables Tobias Brunner
@ 2016-07-29  8:19 ` Herbert Xu
  2016-07-29 10:40   ` Steffen Klassert
  0 siblings, 1 reply; 3+ messages in thread
From: Herbert Xu @ 2016-07-29  8:19 UTC (permalink / raw)
  To: Tobias Brunner
  Cc: Steffen Klassert, David S. Miller, netdev, Christophe Gouault

On Fri, Jul 29, 2016 at 09:57:32AM +0200, Tobias Brunner wrote:
> Whenever thresholds are changed the hash tables are rebuilt.  This is
> done by enumerating all policies and hashing and inserting them into
> the right table according to the thresholds and direction.
> 
> Because socket policies are also contained in net->xfrm.policy_all but
> no hash tables are defined for their direction (dir + XFRM_POLICY_MAX)
> this causes a NULL or invalid pointer dereference after returning from
> policy_hash_bysel() if the rebuild is done while any socket policies
> are installed.
> 
> Since the rebuild after changing thresholds is scheduled this crash
> could even occur if the userland sets thresholds seemingly before
> installing any socket policies.
> 
> Fixes: 53c2e285f970 ("xfrm: Do not hash socket policies")
> Signed-off-by: Tobias Brunner <tobias@strongswan.org>

Acked-by: Herbert Xu <herbert@gondor.apana.org.au>

Good catch, thanks!
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH ipsec] xfrm: Ignore socket policies when rebuilding hash tables
  2016-07-29  8:19 ` Herbert Xu
@ 2016-07-29 10:40   ` Steffen Klassert
  0 siblings, 0 replies; 3+ messages in thread
From: Steffen Klassert @ 2016-07-29 10:40 UTC (permalink / raw)
  To: Herbert Xu; +Cc: Tobias Brunner, David S. Miller, netdev, Christophe Gouault

On Fri, Jul 29, 2016 at 04:19:11PM +0800, Herbert Xu wrote:
> On Fri, Jul 29, 2016 at 09:57:32AM +0200, Tobias Brunner wrote:
> > Whenever thresholds are changed the hash tables are rebuilt.  This is
> > done by enumerating all policies and hashing and inserting them into
> > the right table according to the thresholds and direction.
> > 
> > Because socket policies are also contained in net->xfrm.policy_all but
> > no hash tables are defined for their direction (dir + XFRM_POLICY_MAX)
> > this causes a NULL or invalid pointer dereference after returning from
> > policy_hash_bysel() if the rebuild is done while any socket policies
> > are installed.
> > 
> > Since the rebuild after changing thresholds is scheduled this crash
> > could even occur if the userland sets thresholds seemingly before
> > installing any socket policies.
> > 
> > Fixes: 53c2e285f970 ("xfrm: Do not hash socket policies")
> > Signed-off-by: Tobias Brunner <tobias@strongswan.org>
> 
> Acked-by: Herbert Xu <herbert@gondor.apana.org.au>

Applied to the ipsec tree, thanks a lot Tobias!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-29 10:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-29  7:57 [PATCH ipsec] xfrm: Ignore socket policies when rebuilding hash tables Tobias Brunner
2016-07-29  8:19 ` Herbert Xu
2016-07-29 10:40   ` Steffen Klassert

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.