Skip to contentSkip to conversation

ipv4: nexthop: Fix deadcode issue by performing a proper NULL check

PATCH Applied [email protected] 3 participants 7 messages Jun 1, 2020 – Jun 7, 2020

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

PATCH 1/1 ipv4: nexthop: Fix deadcode issue by performing a proper NULL check

From: Patrick Eigensatz <[email protected]>

After allocating the spare nexthop group it should be tested for kzalloc() returning NULL, instead the already used nexthop group (which cannot be NULL at this point) had been tested so far.

Additionally, if kzalloc() fails, return ERR_PTR(-ENOMEM) instead of NULL.

Coverity-id: 1463885

---
 net/ipv4/nexthop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/nexthop.c +2 -2
index 563f71bcb2d7..cb9412cd5e4b 100644
@@ -1118,10 +1118,10 @@ 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;
+		return ERR_PTR(-ENOMEM);
 	}
 	nhg->spare->spare = nhg;
 
Signature · 1 line
2.26.2
Acked-by on v1 1/1
#1 lore raw
Quoted 23 lines · On 01/06/2020 14:12, [email protected] wrote:

From: Patrick Eigensatz <[email protected]>

After allocating the spare nexthop group it should be tested for kzalloc() returning NULL, instead the already used nexthop group (which cannot be NULL at this point) had been tested so far.

Additionally, if kzalloc() fails, return ERR_PTR(-ENOMEM) instead of NULL.

Coverity-id: 1463885

---
 net/ipv4/nexthop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/nexthop.c +0 -0
index 563f71bcb2d7..cb9412cd5e4b 100644
@@ -1118,10 +1118,10 @@ static struct nexthop *nexthop_create_group(struct net *net,
 
 	/* spare group used for removals */

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

Quoted 10 lines
net/ipv4/nexthop.c +2 -2
 	nhg->spare = nexthop_grp_alloc(num_nh);
-	if (!nhg) {
+	if (!nhg->spare) {
 		kfree(nhg);
 		kfree(nh);
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 	}
 	nhg->spare->spare = nhg;
 

As Colin's similar patch[1] was rejected recently, this one also fixes the issue. This is targeted at -net.

Fixes 90f33bffa382 ("nexthops: don't modify published nexthop groups")

Thanks!

[1] https://lkml.org/lkml/2020/5/28/909

maintainer Applied
#2 lore raw
In reply to [email protected]

From: [email protected]
Date: Mon, 1 Jun 2020 13:12:01 +0200

Quoted 11 lines

From: Patrick Eigensatz <[email protected]>

After allocating the spare nexthop group it should be tested for kzalloc() returning NULL, instead the already used nexthop group (which cannot be NULL at this point) had been tested so far.

Additionally, if kzalloc() fails, return ERR_PTR(-ENOMEM) instead of NULL.

Coverity-id: 1463885

Applied, thank you.

#3 lore raw
Quoted 9 lines · David Miller

From: [email protected]
Date: Mon, 1 Jun 2020 13:12:01 +0200

Quoted 6 lines

From: Patrick Eigensatz <[email protected]>

After allocating the spare nexthop group it should be tested for kzalloc() returning NULL, instead the already used nexthop group (which cannot be NULL at this point) had been tested so far.

Quoted 8 lines
Quoted 5 lines

Additionally, if kzalloc() fails, return ERR_PTR(-ENOMEM) instead of NULL.

Coverity-id: 1463885

Applied, thank you.

Hi Dave,
I see this patch in -net-next but it should've been in -net as I wrote in my review[1]. This patch should go along with the recent nexthop set that fixes a few bugs, since it could result in a null ptr deref if the spare group cannot be allocated.
How would you like to proceed? Should it be submitted for -net as well?

Thanks,
Nik

[1] https://lkml.org/lkml/2020/6/1/391

#4 lore raw
Quoted 16 lines · Nikolay Aleksandrov
Quoted 15 lines · David Miller

From: [email protected]
Date: Mon, 1 Jun 2020 13:12:01 +0200

Quoted 11 lines

From: Patrick Eigensatz <[email protected]>

After allocating the spare nexthop group it should be tested for kzalloc() returning NULL, instead the already used nexthop group (which cannot be NULL at this point) had been tested so far.

Additionally, if kzalloc() fails, return ERR_PTR(-ENOMEM) instead of NULL.

Coverity-id: 1463885

Quoted 8 lines
Quoted 2 lines

Applied, thank you.

Hi Dave,
I see this patch in -net-next but it should've been in -net as I wrote in my review[1]. This patch should go along with the recent nexthop set that fixes a few bugs, since it could result in a null ptr deref if the spare group cannot be allocated.

Obviously I forgot to mention in my review that it should go to -stable with the nexthop fix set.

Quoted 7 lines

How would you like to proceed? Should it be submitted for -net as well?

Thanks,
Nik

[1] https://lkml.org/lkml/2020/6/1/391

maintainer
#5 lore raw
In reply to Nikolay Aleksandrov

From: Nikolay Aleksandrov <[email protected]>
Date: Tue, 2 Jun 2020 10:23:09 +0300

Quoted 19 lines · David Miller
Quoted 9 lines

From: [email protected]
Date: Mon, 1 Jun 2020 13:12:01 +0200

Quoted 6 lines

From: Patrick Eigensatz <[email protected]>

After allocating the spare nexthop group it should be tested for kzalloc() returning NULL, instead the already used nexthop group (which cannot be NULL at this point) had been tested so far.

Quoted 8 lines
Quoted 5 lines

Additionally, if kzalloc() fails, return ERR_PTR(-ENOMEM) instead of NULL.

Coverity-id: 1463885

Applied, thank you.

Quoted 6 lines

Hi Dave,
I see this patch in -net-next but it should've been in -net as I wrote in my review[1]. This patch should go along with the recent nexthop set that fixes a few bugs, since it could result in a null ptr deref if the spare group cannot be allocated.
How would you like to proceed? Should it be submitted for -net as well?

When I'm leading up to the merge window I just toss everything into net-next and still queue things to -stable as needed.

#6 lore raw
Quoted 29 lines · David Miller

From: Nikolay Aleksandrov <[email protected]>
Date: Tue, 2 Jun 2020 10:23:09 +0300

Quoted 19 lines · David Miller
Quoted 9 lines

From: [email protected]
Date: Mon, 1 Jun 2020 13:12:01 +0200

Quoted 6 lines

From: Patrick Eigensatz <[email protected]>

After allocating the spare nexthop group it should be tested for kzalloc() returning NULL, instead the already used nexthop group (which cannot be NULL at this point) had been tested so far.

Quoted 8 lines
Quoted 5 lines

Additionally, if kzalloc() fails, return ERR_PTR(-ENOMEM) instead of NULL.

Coverity-id: 1463885

Applied, thank you.

Quoted 6 lines

Hi Dave,
I see this patch in -net-next but it should've been in -net as I wrote in my review[1]. This patch should go along with the recent nexthop set that fixes a few bugs, since it could result in a null ptr deref if the spare group cannot be allocated.
How would you like to proceed? Should it be submitted for -net as well?

Quoted 3 lines

When I'm leading up to the merge window I just toss everything into net-next and still queue things to -stable as needed.

Got it, in that case could you please queue the patch for -stable?

I checked https://patchwork.ozlabs.org/bundle/davem/stable/?state=* and
https://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git
but didn't find it.

Thanks,
Nik