Skip to contentSkip to conversation

nexthop: off by one in nexthop_mpath_select()

PATCH Superseded Dan Carpenter 3 participants 5 messages Jun 7, 2019 – Jun 9, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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 >.

Fixes f88d8ea67fbd ("ipv6: Plumb support for nexthop object in a fib6_info")
---
 include/net/nexthop.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/nexthop.h +1 -1
index aff7b2410057..e019ed9b3dc3 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Dan Carpenter

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")
Quoted 11 lines
---
 include/net/nexthop.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/nexthop.h +0 -0
index aff7b2410057..e019ed9b3dc3 100644

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.

#2 lore raw
Quoted 10 lines · David Ahern
Quoted 4 lines · Dan Carpenter

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

#3 lore raw

PATCH v2 1/1 nexthop: off by one in nexthop_mpath_select()

In reply to David Ahern

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 430a049190de ("nexthop: Add support for nexthop groups")

---
v2: Use the correct Fixes tag

 include/net/nexthop.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/nexthop.h +1 -1
index aff7b2410057..e019ed9b3dc3 100644
@@ -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
maintainer Applied
#4 lore raw

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 has nhg->num_nh elements so this check should be >= instead of >.

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

---
v2: Use the correct Fixes tag

Applied, thanks Dan.