[next] nexthop: off by one in nexthop_mpath_select()
diff mbox series

Message ID 20190607135636.GB16718@mwanda
State Superseded
Delegated to: David Miller
Headers show
Series
  • [next] nexthop: off by one in nexthop_mpath_select()
Related show

Commit Message

Dan Carpenter June 7, 2019, 1:56 p.m. UTC
The nhg->nh_entries[] array is allocated in nexthop_grp_alloc() and it
has nhg->num_nh elements so this check should be >= instead of >.

Fixes: f88d8ea67fbd ("ipv6: Plumb support for nexthop object in a fib6_info")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 include/net/nexthop.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Ahern June 7, 2019, 2:54 p.m. UTC | #1
On 6/7/19 7:56 AM, Dan Carpenter wrote:
> The nhg->nh_entries[] array is allocated in nexthop_grp_alloc() and it
> has nhg->num_nh elements so this check should be >= instead of >.
> 
> Fixes: f88d8ea67fbd ("ipv6: Plumb support for nexthop object in a fib6_info")

Wrong fixes. The helper was added by 430a049190de so it should be

Fixes: 430a049190de ("nexthop: Add support for nexthop groups")

> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  include/net/nexthop.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/net/nexthop.h b/include/net/nexthop.h
> index aff7b2410057..e019ed9b3dc3 100644
> --- a/include/net/nexthop.h
> +++ b/include/net/nexthop.h
> @@ -160,7 +160,7 @@ struct nexthop *nexthop_mpath_select(const struct nexthop *nh, int nhsel)
>  	/* for_nexthops macros in fib_semantics.c grabs a pointer to
>  	 * the nexthop before checking nhsel
>  	 */
> -	if (nhsel > nhg->num_nh)
> +	if (nhsel >= nhg->num_nh)
>  		return NULL;
>  
>  	return nhg->nh_entries[nhsel].nh;
> 

Thanks for the patch.

Reviewed-by: David Ahern <dsahern@gmail.com>
Dan Carpenter June 7, 2019, 3:29 p.m. UTC | #2
On Fri, Jun 07, 2019 at 08:54:33AM -0600, David Ahern wrote:
> On 6/7/19 7:56 AM, Dan Carpenter wrote:
> > The nhg->nh_entries[] array is allocated in nexthop_grp_alloc() and it
> > has nhg->num_nh elements so this check should be >= instead of >.
> > 
> > Fixes: f88d8ea67fbd ("ipv6: Plumb support for nexthop object in a fib6_info")
> 
> Wrong fixes. The helper was added by 430a049190de so it should be
> 
> Fixes: 430a049190de ("nexthop: Add support for nexthop groups")
> 

Sorry, my eyes must have gone squiffy.  I don't even know how I got that
wrong.  Let me resend.

regards,
dan carpenter

Patch
diff mbox series

diff --git a/include/net/nexthop.h b/include/net/nexthop.h
index aff7b2410057..e019ed9b3dc3 100644
--- a/include/net/nexthop.h
+++ b/include/net/nexthop.h
@@ -160,7 +160,7 @@  struct nexthop *nexthop_mpath_select(const struct nexthop *nh, int nhsel)
 	/* for_nexthops macros in fib_semantics.c grabs a pointer to
 	 * the nexthop before checking nhsel
 	 */
-	if (nhsel > nhg->num_nh)
+	if (nhsel >= nhg->num_nh)
 		return NULL;
 
 	return nhg->nh_entries[nhsel].nh;