nexthop: off by one in nexthop_mpath_select()
Subsystems (4)
PATCH 1/1 nexthop: off by one in nexthop_mpath_select()
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 >.
--- include/net/nexthop.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/nexthop.h +1 -1
@@ -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;
Signature · 1 line
2.20.1
Quoted 4 lines · Dan Carpenter
The nhg->nh_entries[] array is allocated in
nexthop_grp_alloc()and it hasnhg->num_nhelements 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
Quoted 11 lines
Signed-off-by Dan Carpenter <[email protected]>--- include/net/nexthop.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/net/nexthop.h +0
-0
include/net/nexthop.h struct nexthop *nexthop_mpath_select(const struct nexthop *nh, int nhsel) · line 166
Quoted 8 lines
include/net/nexthop.h +1
-1@@ -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.
Quoted 10 lines · David Ahern
Quoted 4 lines · Dan Carpenter
The nhg->nh_entries[] array is allocated in
nexthop_grp_alloc()and it hasnhg->num_nhelements 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
430a049190deso it should beFixes 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 v2 1/1 nexthop: off by one in nexthop_mpath_select()
In reply to David AhernThe nhg->nh_entries[] array is allocated in nexthop_grp_alloc() and it has nhg->num_nh elements so this check should be >= instead of >.
---
v2: Use the correct Fixes tag
include/net/nexthop.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/nexthop.h +1 -1
@@ -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;
Signature · 1 line
2.20.1
From: Dan Carpenter <[email protected]>
Date: Fri, 7 Jun 2019 18:31:07 +0300
Quoted 8 lines
The nhg->nh_entries[] array is allocated in
nexthop_grp_alloc()and it hasnhg->num_nhelements so this check should be >= instead of >.Fixes 430a049190de ("nexthop: Add support for nexthop groups")Signed-off-by Dan Carpenter <[email protected]>Reviewed-by David Ahern <[email protected]>---
v2: Use the correct Fixes tag
Applied, thanks Dan.