Patchwork [net-next,1/3] net: fix race bug in fragmentation create code

login
register
mail settings
Submitter Jesper Dangaard Brouer
Date April 18, 2013, 9:37 p.m.
Message ID <20130418213715.14296.43912.stgit@dragon>
Download mbox | patch
Permalink /patch/237745/
State Superseded
Delegated to: David Miller
Headers show

Comments

Jesper Dangaard Brouer - April 18, 2013, 9:37 p.m.
During creation of a new inet_frag_queue, the lru_list pointer is
updated after releasing the hash bucket lock, which can lead to a
race condition (and panic), if the inet_frag_queue is deleted
(very quickly) before the lru_list is valid.

This race condition is should not be able to occur with current
LRU based evictor.  For the planned direct hash based
evictor/clean strategy, this race condition is more likely to
occur.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---

 net/ipv4/inet_fragment.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hannes Frederic Sowa - April 19, 2013, 1 a.m.
On Thu, Apr 18, 2013 at 11:37:27PM +0200, Jesper Dangaard Brouer wrote:
> During creation of a new inet_frag_queue, the lru_list pointer is
> updated after releasing the hash bucket lock, which can lead to a
> race condition (and panic), if the inet_frag_queue is deleted
> (very quickly) before the lru_list is valid.
> 
> This race condition is should not be able to occur with current
> LRU based evictor.  For the planned direct hash based
> evictor/clean strategy, this race condition is more likely to
> occur.
> 
> Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
> ---
> 
>  net/ipv4/inet_fragment.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
> index e97d66a..beec05b 100644
> --- a/net/ipv4/inet_fragment.c
> +++ b/net/ipv4/inet_fragment.c
> @@ -283,9 +283,9 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
>  
>  	atomic_inc(&qp->refcnt);
>  	hlist_add_head(&qp->list, &hb->chain);
> +	inet_frag_lru_add(nf, qp);
>  	spin_unlock(&hb->chain_lock);
>  	read_unlock(&f->lock);
> -	inet_frag_lru_add(nf, qp);
>  	return qp;
>  }

If I checked correctly, the current code does not have the race
condition? I think this change is ok but maybe we can defer it until
the direct hash cleanup patches land?

Thanks,

  Hannes
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jesper Dangaard Brouer - April 19, 2013, 8:09 a.m.
On Fri, 2013-04-19 at 03:00 +0200, Hannes Frederic Sowa wrote:
> On Thu, Apr 18, 2013 at 11:37:27PM +0200, Jesper Dangaard Brouer wrote:
> > During creation of a new inet_frag_queue, the lru_list pointer is
> > updated after releasing the hash bucket lock, which can lead to a
> > race condition (and panic), if the inet_frag_queue is deleted
> > (very quickly) before the lru_list is valid.
> > 
> > This race condition is should not be able to occur with current
> > LRU based evictor.  For the planned direct hash based
> > evictor/clean strategy, this race condition is more likely to
> > occur.
> > 
> > Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
> > ---
> > 
> >  net/ipv4/inet_fragment.c |    2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> > 
> > diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
> > index e97d66a..beec05b 100644
> > --- a/net/ipv4/inet_fragment.c
> > +++ b/net/ipv4/inet_fragment.c
> > @@ -283,9 +283,9 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
> >  
> >  	atomic_inc(&qp->refcnt);
> >  	hlist_add_head(&qp->list, &hb->chain);
> > +	inet_frag_lru_add(nf, qp);
> >  	spin_unlock(&hb->chain_lock);
> >  	read_unlock(&f->lock);
> > -	inet_frag_lru_add(nf, qp);
> >  	return qp;
> >  }
> 
> If I checked correctly, the current code does not have the race
> condition? I think this change is ok but maybe we can defer it until
> the direct hash cleanup patches land?

Lets hear what others think of collapsing it into the next patch?
(I don't have a problem with doing so)

--Jesper


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
index e97d66a..beec05b 100644
--- a/net/ipv4/inet_fragment.c
+++ b/net/ipv4/inet_fragment.c
@@ -283,9 +283,9 @@  static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
 
 	atomic_inc(&qp->refcnt);
 	hlist_add_head(&qp->list, &hb->chain);
+	inet_frag_lru_add(nf, qp);
 	spin_unlock(&hb->chain_lock);
 	read_unlock(&f->lock);
-	inet_frag_lru_add(nf, qp);
 	return qp;
 }