Skip to contentSkip to conversation

nexthop: fix incorrect allocation failure on nhg->spare

PATCH In review Colin King 4 participants 8 messages May 28, 2020 – May 30, 2020

Subsystems (4)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 nexthop: fix incorrect allocation failure on nhg->spare

From: Colin Ian King <[email protected]>

The allocation failure check for nhg->spare is currently checking the pointer nhg rather than nhg->spare which is never false. Fix this by checking nhg->spare instead.

Addresses-Coverity: ("Logically dead code")

Fixes 430a049190de ("nexthop: Add support for nexthop groups")
---
 net/ipv4/nexthop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/nexthop.c +1 -1
index ebafa5ed91ac..97423d6f2de9 100644
@@ -1185,7 +1185,7 @@ static struct nexthop *nexthop_create_group(struct net *net,
 
 	/* spare group used for removals */
 	nhg->spare = nexthop_grp_alloc(num_nh);
-	if (!nhg) {
+	if (!nhg->spare) {
 		kfree(nhg);
 		kfree(nh);
 		return NULL;
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 19 lines · Colin King

From: Colin Ian King <[email protected]>

The allocation failure check for nhg->spare is currently checking the pointer nhg rather than nhg->spare which is never false. Fix this by checking nhg->spare instead.

Addresses-Coverity: ("Logically dead code")

Fixes 430a049190de ("nexthop: Add support for nexthop groups")
---
 net/ipv4/nexthop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/nexthop.c +0 -0
index ebafa5ed91ac..97423d6f2de9 100644

net/ipv4/nexthop.c static struct nexthop *nexthop_create_group(struct net *net, · line 1191

Quoted 8 lines
net/ipv4/nexthop.c +1 -1
@@ -1185,7 +1185,7 @@ static struct nexthop *nexthop_create_group(struct net *net,
 
 	/* spare group used for removals */
 	nhg->spare = nexthop_grp_alloc(num_nh);
-	if (!nhg) {
+	if (!nhg->spare) {
 		kfree(nhg);
 		kfree(nh);
 		return NULL;

Good catch, embarrassing copy paste error :-/

Reviewed-by
#2 lore raw
Quoted 30 lines · Nikolay Aleksandrov
Quoted 19 lines · Colin King

From: Colin Ian King <[email protected]>

The allocation failure check for nhg->spare is currently checking the pointer nhg rather than nhg->spare which is never false. Fix this by checking nhg->spare instead.

Addresses-Coverity: ("Logically dead code")

Fixes 430a049190de ("nexthop: Add support for nexthop groups")
---
 net/ipv4/nexthop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/nexthop.c +0 -0
index ebafa5ed91ac..97423d6f2de9 100644

net/ipv4/nexthop.c static struct nexthop *nexthop_create_group(struct net *net, · line 1191

Quoted 8 lines
net/ipv4/nexthop.c +1 -1
@@ -1185,7 +1185,7 @@ static struct nexthop *nexthop_create_group(struct net *net,
 
 	/* spare group used for removals */
 	nhg->spare = nexthop_grp_alloc(num_nh);
-	if (!nhg) {
+	if (!nhg->spare) {
 		kfree(nhg);
 		kfree(nh);
 		return NULL;

Good catch, embarrassing copy paste error :-/

Quoted 2 lines

I missed that as well.

Patch needs to go to -net

#3 lore raw
In reply to Nikolay Aleksandrov
Quoted 30 lines · Nikolay Aleksandrov
Quoted 19 lines · Colin King

From: Colin Ian King <[email protected]>

The allocation failure check for nhg->spare is currently checking the pointer nhg rather than nhg->spare which is never false. Fix this by checking nhg->spare instead.

Addresses-Coverity: ("Logically dead code")

Fixes 430a049190de ("nexthop: Add support for nexthop groups")
---
 net/ipv4/nexthop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/nexthop.c +0 -0
index ebafa5ed91ac..97423d6f2de9 100644

net/ipv4/nexthop.c static struct nexthop *nexthop_create_group(struct net *net, · line 1191

Quoted 8 lines
net/ipv4/nexthop.c +1 -1
@@ -1185,7 +1185,7 @@ static struct nexthop *nexthop_create_group(struct net *net,
 
 	/* spare group used for removals */
 	nhg->spare = nexthop_grp_alloc(num_nh);
-	if (!nhg) {
+	if (!nhg->spare) {
 		kfree(nhg);
 		kfree(nh);
 		return NULL;

Good catch, embarrassing copy paste error :-/

Quoted 2 lines

Wait - that should be targeted at -net, that's where the fixes went. And the fixes tag is wrong, nhg->spare was very recently added by:
commit 90f33bffa382

Author: Nikolay Aleksandrov <[email protected]>
Date:   Tue May 26 12:56:15 2020 -0600

nexthops: don't modify published nexthop groups

#4 lore raw
Quoted 34 lines · Nikolay Aleksandrov
Quoted 30 lines · Nikolay Aleksandrov
Quoted 19 lines · Colin King

From: Colin Ian King <[email protected]>

The allocation failure check for nhg->spare is currently checking the pointer nhg rather than nhg->spare which is never false. Fix this by checking nhg->spare instead.

Addresses-Coverity: ("Logically dead code")

Fixes 430a049190de ("nexthop: Add support for nexthop groups")
---
 net/ipv4/nexthop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/nexthop.c +0 -0
index ebafa5ed91ac..97423d6f2de9 100644

net/ipv4/nexthop.c static struct nexthop *nexthop_create_group(struct net *net, · line 1191

Quoted 8 lines
net/ipv4/nexthop.c +1 -1
@@ -1185,7 +1185,7 @@ static struct nexthop *nexthop_create_group(struct net *net,
 
 	/* spare group used for removals */
 	nhg->spare = nexthop_grp_alloc(num_nh);
-	if (!nhg) {
+	if (!nhg->spare) {
 		kfree(nhg);
 		kfree(nh);
 		return NULL;

Good catch, embarrassing copy paste error :-/

Quoted 2 lines
Quoted 8 lines

Wait - that should be targeted at -net, that's where the fixes went. And the fixes tag is wrong, nhg->spare was very recently added by:
commit 90f33bffa382

Author: Nikolay Aleksandrov <[email protected]>
Date:   Tue May 26 12:56:15 2020 -0600

nexthops: don't modify published nexthop groups

Do you require me to fix this up and re-send?

Colin

#5 lore raw
Quoted 41 lines · Colin Ian King
Quoted 40 lines · Nikolay Aleksandrov
Quoted 30 lines · Nikolay Aleksandrov
Quoted 19 lines · Colin King

From: Colin Ian King <[email protected]>

The allocation failure check for nhg->spare is currently checking the pointer nhg rather than nhg->spare which is never false. Fix this by checking nhg->spare instead.

Addresses-Coverity: ("Logically dead code")

Fixes 430a049190de ("nexthop: Add support for nexthop groups")
---
 net/ipv4/nexthop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/nexthop.c +0 -0
index ebafa5ed91ac..97423d6f2de9 100644

net/ipv4/nexthop.c static struct nexthop *nexthop_create_group(struct net *net, · line 1191

Quoted 8 lines
net/ipv4/nexthop.c +1 -1
@@ -1185,7 +1185,7 @@ static struct nexthop *nexthop_create_group(struct net *net,
 
 	/* spare group used for removals */
 	nhg->spare = nexthop_grp_alloc(num_nh);
-	if (!nhg) {
+	if (!nhg->spare) {
 		kfree(nhg);
 		kfree(nh);
 		return NULL;

Good catch, embarrassing copy paste error :-/

Quoted 2 lines

Wait - that should be targeted at -net, that's where the fixes went. And the fixes tag is wrong, nhg->spare was very recently added by:
commit 90f33bffa382

Author: Nikolay Aleksandrov <[email protected]>
Date:   Tue May 26 12:56:15 2020 -0600
Quoted 7 lines
Quoted 2 lines

nexthops: don't modify published nexthop groups

Do you require me to fix this up and re-send?

Colin

Up to you, it will go to the same stable releases as that fix used the same Fixes tag, so it's really not an issue.

#6 lore raw
Quoted 45 lines · Nikolay Aleksandrov
Quoted 44 lines · Colin Ian King
Quoted 42 lines · Nikolay Aleksandrov
Quoted 30 lines · Nikolay Aleksandrov
Quoted 19 lines · Colin King

From: Colin Ian King <[email protected]>

The allocation failure check for nhg->spare is currently checking the pointer nhg rather than nhg->spare which is never false. Fix this by checking nhg->spare instead.

Addresses-Coverity: ("Logically dead code")

Fixes 430a049190de ("nexthop: Add support for nexthop groups")
---
 net/ipv4/nexthop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/nexthop.c +0 -0
index ebafa5ed91ac..97423d6f2de9 100644

net/ipv4/nexthop.c static struct nexthop *nexthop_create_group(struct net *net, · line 1191

Quoted 8 lines
net/ipv4/nexthop.c +1 -1
@@ -1185,7 +1185,7 @@ static struct nexthop *nexthop_create_group(struct net *net,
 
 	/* spare group used for removals */
 	nhg->spare = nexthop_grp_alloc(num_nh);
-	if (!nhg) {
+	if (!nhg->spare) {
 		kfree(nhg);
 		kfree(nh);
 		return NULL;

Good catch, embarrassing copy paste error :-/

Quoted 2 lines

Wait - that should be targeted at -net, that's where the fixes went. And the fixes tag is wrong, nhg->spare was very recently added by:
commit 90f33bffa382

Author: Nikolay Aleksandrov <[email protected]>
Date:   Tue May 26 12:56:15 2020 -0600

nexthops: don't modify published nexthop groups

Quoted 8 lines
Quoted 4 lines

Do you require me to fix this up and re-send?

Colin

Up to you, it will go to the same stable releases as that fix used the same Fixes tag, so it's really not an issue.

OK, I'll let it slip and won't send a V2. Thanks

maintainer
#7 lore raw
In reply to Colin King

From: Colin King <[email protected]>
Date: Thu, 28 May 2020 15:51:14 +0100

net/ipv4/nexthop.c static struct nexthop *nexthop_create_group(struct net *net, · line 1187

Quoted 4 lines
net/ipv4/nexthop.c +0 -0
@@ -1185,7 +1185,7 @@ static struct nexthop *nexthop_create_group(struct net *net,
 
 	/* spare group used for removals */
 	nhg->spare = nexthop_grp_alloc(num_nh);

I don't even see this line in the current net-next tree nor any references to ->spare.

What am I missing?