ipv6: make sure dev is not NULL before call ip6_frag_reasm
Subsystems (3)
PATCH 1/1 ipv6: make sure dev is not NULL before call ip6_frag_reasm
Since ip6_frag_reasm() will call __in6_dev_get(dev), which will access dev->ip6_ptr. We need to make sure dev is not NULL.
--- net/ipv6/reassembly.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/reassembly.c +1 -1
@@ -348,7 +348,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, fq->q.flags |=INET_FRAG_FIRST_IN ; } -if (fq->q.flags == (INET_FRAG_FIRST_IN |INET_FRAG_LAST_IN ) && +if (dev && fq->q.flags == (INET_FRAG_FIRST_IN |INET_FRAG_LAST_IN ) && fq->q.meat == fq->q.len) {int res;unsigned long orefdst = skb->_skb_refdst;
Signature · 1 line
2.5.5
Quoted 13 lines · Hangbin Liu
Since
ip6_frag_reasm()will call__in6_dev_get(dev), which will accessdev->ip6_ptr. We need to make sure dev is not NULL.Signed-off-by Hangbin Liu <[email protected]>--- net/ipv6/reassembly.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv6/reassembly.c +0
-0
net/ipv6/reassembly.c static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, · line 354
Quoted 8 lines
net/ipv6/reassembly.c +1
-1@@ -348,7 +348,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, fq->q.flags |=INET_FRAG_FIRST_IN ; } -if (fq->q.flags == (INET_FRAG_FIRST_IN |INET_FRAG_LAST_IN ) && +if (dev && fq->q.flags == (INET_FRAG_FIRST_IN |INET_FRAG_LAST_IN ) && fq->q.meat == fq->q.len) {int res;unsigned long orefdst = skb->_skb_refdst;
How dev could be possibly NULL here ?
Quoted 17 lines · Eric Dumazet
Quoted 16 lines · Hangbin Liu
Since
ip6_frag_reasm()will call__in6_dev_get(dev), which will accessdev->ip6_ptr. We need to make sure dev is not NULL.Signed-off-by Hangbin Liu <[email protected]>--- net/ipv6/reassembly.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv6/reassembly.c +0
-0@@ -348,7 +348,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, fq->q.flags |=INET_FRAG_FIRST_IN ; }
Quoted 8 lines
net/ipv6/reassembly.c static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, · line 354
Quoted 5 lines
net/ipv6/reassembly.c +1
-1-if (fq->q.flags == (INET_FRAG_FIRST_IN |INET_FRAG_LAST_IN ) && +if (dev && fq->q.flags == (INET_FRAG_FIRST_IN |INET_FRAG_LAST_IN ) && fq->q.meat == fq->q.len) {int res;unsigned long orefdst = skb->_skb_refdst;How dev could be possibly NULL here ?
I saw we checked the dev in this function
dev = skb->dev;
if (dev) {
fq->iif = dev->ifindex;
skb->dev = NULL;
}and upper caller ipv6_frag_rcv()
fq = fq_find(net, fhdr->identification, &hdr->saddr, &hdr->daddr, skb->dev ? skb->dev->ifindex : 0, ip6_frag_ecn(hdr));
Apologise that I did not do enough research to make sure whether skb->dev could be NULL or not. I will do the check recently and reply when got a confirmation.
Regards
Hangbin
Quoted 11 lines · Hangbin Liu
I saw we checked the dev in this function
dev = skb->dev; if (dev) { fq->iif = dev->ifindex; skb->dev = NULL; }and upper caller
ipv6_frag_rcv()
Quoted 7 lines
fq = fq_find(net, fhdr->identification, &hdr->saddr, &hdr->daddr, skb->dev ? skb->dev->ifindex : 0, ip6_frag_ecn(hdr));Apologise that I did not do enough research to make sure whether
skb->devcould be NULL or not. I will do the check recently and reply when got a confirmation.
If really having a NULL dev is possible, I would rather change things this way, as your fix has side effects.
net/ipv6/reassembly.c +8 -12
@@ -77,7 +77,7 @@ static u8 ip6_frag_ecn(const struct ipv6hdr *ipv6h)static struct inet_frags ip6_frags;static int ip6_frag_reasm (struct frag_queue *fq,struct sk_buff *prev, -struct net_device *dev); +struct net_device *dev,struct inet6_dev *idev);/* * callers should be careful not to use the hash value outside the ipfrag_lock
@@ -209,6 +209,7 @@ fq_find(struct net *net, __be32 id, const struct in6_addr *src,static int ip6_frag_queue (struct frag_queue *fq,struct sk_buff *skb,struct frag_hdr *fhdr,int nhoff) { +struct inet6_dev *idev =ip6_dst_idev (skb_dst (skb));struct sk_buff *prev, *next;struct net_device *dev;int offset, end, fragsize;
@@ -223,8 +224,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, ((u8 *)(fhdr + 1) - (u8 *)(ipv6_hdr(skb) + 1)));if ((unsigned int )end >IPV6_MAXPLEN ) { -__IP6_INC_STATS (net,ip6_dst_idev (skb_dst (skb)), -IPSTATS_MIB_INHDRERRORS ); +__IP6_INC_STATS (net, idev,IPSTATS_MIB_INHDRERRORS );icmpv6_param_prob (skb,ICMPV6_HDR_FIELD , ((u8 *)&fhdr->frag_off -skb_network_header (skb)));
@@ -258,8 +258,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,/* RFC2460 says always send parameter problem in * this case. -DaveM */ -__IP6_INC_STATS (net,ip6_dst_idev (skb_dst (skb)), -IPSTATS_MIB_INHDRERRORS ); +__IP6_INC_STATS (net, idev,IPSTATS_MIB_INHDRERRORS );icmpv6_param_prob (skb,ICMPV6_HDR_FIELD , offsetof(struct ipv6hdr , payload_len));return -1 ;
@@ -354,7 +353,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,unsigned long orefdst = skb->_skb_refdst; skb->_skb_refdst =0UL ; - res =ip6_frag_reasm (fq, prev, dev); + res =ip6_frag_reasm (fq, prev, dev, idev); skb->_skb_refdst = orefdst;return res; }
@@ -365,8 +364,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb, discard_fq:inet_frag_kill (&fq->q, &ip6_frags); err: -__IP6_INC_STATS (net,ip6_dst_idev (skb_dst (skb)), -IPSTATS_MIB_REASMFAILS ); +__IP6_INC_STATS (net, idev,IPSTATS_MIB_REASMFAILS );kfree_skb (skb);return -1 ; }
@@ -381,7 +379,7 @@ static int ip6_frag_queue(struct frag_queue *fq, struct sk_buff *skb,* the last and the first frames arrived and all the bits are here. */ static int ip6_frag_reasm (struct frag_queue *fq,struct sk_buff *prev, -struct net_device *dev) +struct net_device *dev,struct inet6_dev *idev) { struct net *net = container_of(fq->q.net, struct net, ipv6.frags);struct sk_buff *fp, *head = fq->q.fragments;
@@ -505,9 +503,7 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,skb_postpush_rcsum (head,skb_network_header (head),skb_network_header_len (head)); -rcu_read_lock (); -__IP6_INC_STATS (net,__in6_dev_get (dev),IPSTATS_MIB_REASMOKS ); -rcu_read_unlock (); +__IP6_INC_STATS (net, idev,IPSTATS_MIB_REASMOKS ); fq->q.fragments =NULL ; fq->q.fragments_tail =NULL ;return 1 ;