netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][net-next] ipv6: fix dereference of rt6_ex before null check error
@ 2017-10-10 17:01 Colin King
  2017-10-10 17:26 ` Eric Dumazet
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Colin King @ 2017-10-10 17:01 UTC (permalink / raw)
  To: David S . Miller, Alexey Kuznetsov, Hideaki YOSHIFUJI, netdev
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently rt6_ex is being dereferenced before it is null checked
hence there is a possible null dereference bug. Fix this by only
dereferencing rt6_ex after it has been null checked.

Detected by CoverityScan, CID#1457749 ("Dereference before null check")

Fixes: 81eb8447daae ("ipv6: take care of rt6_stats")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 net/ipv6/route.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 606e80325b21..6db1541eaa7b 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1152,10 +1152,12 @@ static DEFINE_SPINLOCK(rt6_exception_lock);
 static void rt6_remove_exception(struct rt6_exception_bucket *bucket,
 				 struct rt6_exception *rt6_ex)
 {
-	struct net *net = dev_net(rt6_ex->rt6i->dst.dev);
+	struct net *net;
 
 	if (!bucket || !rt6_ex)
 		return;
+
+	net = dev_net(rt6_ex->rt6i->dst.dev);
 	rt6_ex->rt6i->rt6i_node = NULL;
 	hlist_del_rcu(&rt6_ex->hlist);
 	rt6_release(rt6_ex->rt6i);
-- 
2.14.1

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

* Re: [PATCH][net-next] ipv6: fix dereference of rt6_ex before null check error
  2017-10-10 17:01 [PATCH][net-next] ipv6: fix dereference of rt6_ex before null check error Colin King
@ 2017-10-10 17:26 ` Eric Dumazet
  2017-10-10 17:40 ` Martin KaFai Lau
  2017-10-10 17:54 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2017-10-10 17:26 UTC (permalink / raw)
  To: Colin King
  Cc: David S . Miller, Alexey Kuznetsov, Hideaki YOSHIFUJI, netdev,
	kernel-janitors, linux-kernel

On Tue, 2017-10-10 at 18:01 +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently rt6_ex is being dereferenced before it is null checked
> hence there is a possible null dereference bug. Fix this by only
> dereferencing rt6_ex after it has been null checked.
> 
> Detected by CoverityScan, CID#1457749 ("Dereference before null check")
> 
> Fixes: 81eb8447daae ("ipv6: take care of rt6_stats")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---

Reviewed-by: Eric Dumazet <edumazet@google.com>

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

* Re: [PATCH][net-next] ipv6: fix dereference of rt6_ex before null check error
  2017-10-10 17:01 [PATCH][net-next] ipv6: fix dereference of rt6_ex before null check error Colin King
  2017-10-10 17:26 ` Eric Dumazet
@ 2017-10-10 17:40 ` Martin KaFai Lau
  2017-10-10 17:54 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Martin KaFai Lau @ 2017-10-10 17:40 UTC (permalink / raw)
  To: Colin King
  Cc: David S . Miller, Alexey Kuznetsov, Hideaki YOSHIFUJI, netdev,
	kernel-janitors, linux-kernel

On Tue, Oct 10, 2017 at 05:01:16PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently rt6_ex is being dereferenced before it is null checked
> hence there is a possible null dereference bug. Fix this by only
> dereferencing rt6_ex after it has been null checked.
> 
> Detected by CoverityScan, CID#1457749 ("Dereference before null check")
> 
> Fixes: 81eb8447daae ("ipv6: take care of rt6_stats")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>

> ---
>  net/ipv6/route.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 606e80325b21..6db1541eaa7b 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -1152,10 +1152,12 @@ static DEFINE_SPINLOCK(rt6_exception_lock);
>  static void rt6_remove_exception(struct rt6_exception_bucket *bucket,
>  				 struct rt6_exception *rt6_ex)
>  {
> -	struct net *net = dev_net(rt6_ex->rt6i->dst.dev);
> +	struct net *net;
>  
>  	if (!bucket || !rt6_ex)
>  		return;
> +
> +	net = dev_net(rt6_ex->rt6i->dst.dev);
>  	rt6_ex->rt6i->rt6i_node = NULL;
>  	hlist_del_rcu(&rt6_ex->hlist);
>  	rt6_release(rt6_ex->rt6i);
> -- 
> 2.14.1
> 

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

* Re: [PATCH][net-next] ipv6: fix dereference of rt6_ex before null check error
  2017-10-10 17:01 [PATCH][net-next] ipv6: fix dereference of rt6_ex before null check error Colin King
  2017-10-10 17:26 ` Eric Dumazet
  2017-10-10 17:40 ` Martin KaFai Lau
@ 2017-10-10 17:54 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2017-10-10 17:54 UTC (permalink / raw)
  To: colin.king; +Cc: kuznet, yoshfuji, netdev, kernel-janitors, linux-kernel

From: Colin King <colin.king@canonical.com>
Date: Tue, 10 Oct 2017 18:01:16 +0100

> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently rt6_ex is being dereferenced before it is null checked
> hence there is a possible null dereference bug. Fix this by only
> dereferencing rt6_ex after it has been null checked.
> 
> Detected by CoverityScan, CID#1457749 ("Dereference before null check")
> 
> Fixes: 81eb8447daae ("ipv6: take care of rt6_stats")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Applied, thanks Colin.

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

end of thread, other threads:[~2017-10-10 17:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-10 17:01 [PATCH][net-next] ipv6: fix dereference of rt6_ex before null check error Colin King
2017-10-10 17:26 ` Eric Dumazet
2017-10-10 17:40 ` Martin KaFai Lau
2017-10-10 17:54 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).