Skip to contentSkip to conversation

net: fix NULL pointer reference in cipso_v4_doi_free

PATCH Superseded 王贇 5 participants 25 messages Aug 26, 2021 – Sep 3, 2021

Subsystems (4)
lore
Share & tools
lore

王贇

author
#0 lore raw

PATCH 1/1 net: fix NULL pointer reference in cipso_v4_doi_free

In netlbl_cipsov4_add_std() when 'doi_def->map.std' alloc failed, we sometime observe panic:

  BUG: kernel NULL pointer dereference, address:
  ...
  RIP: 0010:cipso_v4_doi_free+0x3a/0x80
  ...
  Call Trace:
   netlbl_cipsov4_add_std+0xf4/0x8c0
   netlbl_cipsov4_add+0x13f/0x1b0
   genl_family_rcv_msg_doit.isra.15+0x132/0x170
   genl_rcv_msg+0x125/0x240

This is because in cipso_v4_doi_free() there is no check on 'doi_def->map.std' when 'doi_def->type' equal 1, which is possibe, since netlbl_cipsov4_add_std() haven't initialize it before alloc 'doi_def->map.std'.

This patch just add the check to prevent panic happen for similar cases.

---

 net/ipv4/cipso_ipv4.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
net/ipv4/cipso_ipv4.c +10 -8
index 099259f..7fbd0b5 100644
@@ -465,14 +465,16 @@ void cipso_v4_doi_free(struct cipso_v4_doi *doi_def)
 	if (!doi_def)
 		return;
 
-	switch (doi_def->type) {
-	case CIPSO_V4_MAP_TRANS:
-		kfree(doi_def->map.std->lvl.cipso);
-		kfree(doi_def->map.std->lvl.local);
-		kfree(doi_def->map.std->cat.cipso);
-		kfree(doi_def->map.std->cat.local);
-		kfree(doi_def->map.std);
-		break;
+	if (doi_def->map.std) {
+		switch (doi_def->type) {
+		case CIPSO_V4_MAP_TRANS:
+			kfree(doi_def->map.std->lvl.cipso);
+			kfree(doi_def->map.std->lvl.local);
+			kfree(doi_def->map.std->cat.cipso);
+			kfree(doi_def->map.std->cat.local);
+			kfree(doi_def->map.std);
+			break;
+		}
 	}
 	kfree(doi_def);
 }
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw
Quoted 21 lines · 王贇

In netlbl_cipsov4_add_std() when 'doi_def->map.std' alloc failed, we sometime observe panic:

  BUG: kernel NULL pointer dereference, address:
  ...
  RIP: 0010:cipso_v4_doi_free+0x3a/0x80
  ...
  Call Trace:
   netlbl_cipsov4_add_std+0xf4/0x8c0
   netlbl_cipsov4_add+0x13f/0x1b0
   genl_family_rcv_msg_doit.isra.15+0x132/0x170
   genl_rcv_msg+0x125/0x240

This is because in cipso_v4_doi_free() there is no check on 'doi_def->map.std' when 'doi_def->type' equal 1, which is possibe, since netlbl_cipsov4_add_std() haven't initialize it before alloc 'doi_def->map.std'.

This patch just add the check to prevent panic happen for similar cases.

Quoted 6 lines

---

 net/ipv4/cipso_ipv4.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

Thanks for the problem report. It's hard to say for certain due to the abbreviated backtrace without line number information, but it looks like the problem you are describing is happening when the allocation for doi_def->map.std fails near the top of netlbl_cipsov4_add_std() which causes the function to jump the add_std_failure target which ends up calling cipso_v4_doi_free().

  doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL);
  if (doi_def == NULL)
    return -ENOMEM;
  doi_def->map.std = kzalloc(sizeof(*doi_def->map.std), GFP_KERNEL);
  if (doi_def->map.std == NULL) {
    ret_val = -ENOMEM;
    goto add_std_failure;
  }
  ...
  add_std_failure:
    cipso_v4_doi_free(doi_def);

Since the doi_def allocation is not zero'd out, it is possible that the doi_def->type value could have a value of CIPSO_V4_MAP_TRANS when the doi_def->map.std allocation fails, causing the NULL pointer deref in cipso_v4_doi_free(). As this is the only case where we would see a problem like this, I suggest a better solution would be to change the if-block following the doi_def->map.std allocation to something like this:

  doi_def->map.std = kzalloc(sizeof(*doi_def->map.std), GFP_KERNEL);
  if (doi_def->map.std == NULL) {
    kfree(doi_def);
    return -ENOMEM;
  }
Quoted 32 lines
net/ipv4/cipso_ipv4.c +10 -9
index 099259f..7fbd0b5 100644
@@ -465,14 +465,16 @@ void cipso_v4_doi_free(struct cipso_v4_doi *doi_def)
        if (!doi_def)
                return;
 
-       switch (doi_def->type) {
-       case CIPSO_V4_MAP_TRANS:
-               kfree(doi_def->map.std->lvl.cipso);
-               kfree(doi_def->map.std->lvl.local);
-               kfree(doi_def->map.std->cat.cipso);
-               kfree(doi_def->map.std->cat.local);
-               kfree(doi_def->map.std);
-               break;
+       if (doi_def->map.std) {
+               switch (doi_def->type) {
+               case CIPSO_V4_MAP_TRANS:
+                       kfree(doi_def->map.std->lvl.cipso);
+                       kfree(doi_def->map.std->lvl.local);
+                       kfree(doi_def->map.std->cat.cipso);
+                       kfree(doi_def->map.std->cat.local);
+                       kfree(doi_def->map.std);
+                       break;
+               }
        }
        kfree(doi_def);
 }
--

1.8.3.1

Signature · 2 lines
paul moore
www.paul-moore.com
author
#2 lore raw

Hi, Paul

I'm sorry for missing this mail since my stupid filter rules...

Will send a new one soon as you suggested :-)

Regards,
Michael Wang

On 2021/8/27 上午8:09, Paul Moore wrote:
[snip]

Quoted 75 lines
Quoted 7 lines

---

 net/ipv4/cipso_ipv4.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

Thanks for the problem report. It's hard to say for certain due to the abbreviated backtrace without line number information, but it looks like the problem you are describing is happening when the allocation for doi_def->map.std fails near the top of netlbl_cipsov4_add_std() which causes the function to jump the add_std_failure target which ends up calling cipso_v4_doi_free().

  doi_def = kmalloc(sizeof(*doi_def), GFP_KERNEL);
  if (doi_def == NULL)
    return -ENOMEM;
  doi_def->map.std = kzalloc(sizeof(*doi_def->map.std), GFP_KERNEL);
  if (doi_def->map.std == NULL) {
    ret_val = -ENOMEM;
    goto add_std_failure;
  }
  ...
  add_std_failure:
    cipso_v4_doi_free(doi_def);

Since the doi_def allocation is not zero'd out, it is possible that the doi_def->type value could have a value of CIPSO_V4_MAP_TRANS when the doi_def->map.std allocation fails, causing the NULL pointer deref in cipso_v4_doi_free(). As this is the only case where we would see a problem like this, I suggest a better solution would be to change the if-block following the doi_def->map.std allocation to something like this:

  doi_def->map.std = kzalloc(sizeof(*doi_def->map.std), GFP_KERNEL);
  if (doi_def->map.std == NULL) {
    kfree(doi_def);
    return -ENOMEM;
  }
Quoted 32 lines
net/ipv4/cipso_ipv4.c +10 -9
index 099259f..7fbd0b5 100644
@@ -465,14 +465,16 @@ void cipso_v4_doi_free(struct cipso_v4_doi *doi_def)
        if (!doi_def)
                return;
 
-       switch (doi_def->type) {
-       case CIPSO_V4_MAP_TRANS:
-               kfree(doi_def->map.std->lvl.cipso);
-               kfree(doi_def->map.std->lvl.local);
-               kfree(doi_def->map.std->cat.cipso);
-               kfree(doi_def->map.std->cat.local);
-               kfree(doi_def->map.std);
-               break;
+       if (doi_def->map.std) {
+               switch (doi_def->type) {
+               case CIPSO_V4_MAP_TRANS:
+                       kfree(doi_def->map.std->lvl.cipso);
+                       kfree(doi_def->map.std->lvl.local);
+                       kfree(doi_def->map.std->cat.cipso);
+                       kfree(doi_def->map.std->cat.local);
+                       kfree(doi_def->map.std);
+                       break;
+               }
        }
        kfree(doi_def);
 }
--

1.8.3.1

author
#3 lore raw
In reply to 王贇

Just a ping... Should we fix this?

Regards,
Michael Wang

Quoted 58 lines · 王贇

In netlbl_cipsov4_add_std() when 'doi_def->map.std' alloc failed, we sometime observe panic:

  BUG: kernel NULL pointer dereference, address:
  ...
  RIP: 0010:cipso_v4_doi_free+0x3a/0x80
  ...
  Call Trace:
   netlbl_cipsov4_add_std+0xf4/0x8c0
   netlbl_cipsov4_add+0x13f/0x1b0
   genl_family_rcv_msg_doit.isra.15+0x132/0x170
   genl_rcv_msg+0x125/0x240

This is because in cipso_v4_doi_free() there is no check on 'doi_def->map.std' when 'doi_def->type' equal 1, which is possibe, since netlbl_cipsov4_add_std() haven't initialize it before alloc 'doi_def->map.std'.

This patch just add the check to prevent panic happen for similar cases.

---

 net/ipv4/cipso_ipv4.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
net/ipv4/cipso_ipv4.c +10 -8
index 099259f..7fbd0b5 100644
@@ -465,14 +465,16 @@ void cipso_v4_doi_free(struct cipso_v4_doi *doi_def)
 	if (!doi_def)
 		return;
 
-	switch (doi_def->type) {
-	case CIPSO_V4_MAP_TRANS:
-		kfree(doi_def->map.std->lvl.cipso);
-		kfree(doi_def->map.std->lvl.local);
-		kfree(doi_def->map.std->cat.cipso);
-		kfree(doi_def->map.std->cat.local);
-		kfree(doi_def->map.std);
-		break;
+	if (doi_def->map.std) {
+		switch (doi_def->type) {
+		case CIPSO_V4_MAP_TRANS:
+			kfree(doi_def->map.std->lvl.cipso);
+			kfree(doi_def->map.std->lvl.local);
+			kfree(doi_def->map.std->cat.cipso);
+			kfree(doi_def->map.std->cat.local);
+			kfree(doi_def->map.std);
+			break;
+		}
 	}
 	kfree(doi_def);
 }
author
#4 lore raw

PATCH v2 1/1 net: fix NULL pointer reference in cipso_v4_doi_free

In reply to 王贇

In netlbl_cipsov4_add_std() when 'doi_def->map.std' alloc failed, we sometime observe panic:

  BUG: kernel NULL pointer dereference, address:
  ...
  RIP: 0010:cipso_v4_doi_free+0x3a/0x80
  ...
  Call Trace:
   netlbl_cipsov4_add_std+0xf4/0x8c0
   netlbl_cipsov4_add+0x13f/0x1b0
   genl_family_rcv_msg_doit.isra.15+0x132/0x170
   genl_rcv_msg+0x125/0x240

This is because in cipso_v4_doi_free() there is no check on 'doi_def->map.std' when doi_def->type got value 1, which is possibe, since netlbl_cipsov4_add_std() haven't initialize it before alloc 'doi_def->map.std'.

This patch just add the check to prevent panic happen in similar cases.

---
 net/netlabel/netlabel_cipso_v4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netlabel/netlabel_cipso_v4.c +2 -2
index baf2357..344c228 100644
@@ -144,8 +144,8 @@ static int netlbl_cipsov4_add_std(struct genl_info *info,
 		return -ENOMEM;
 	doi_def->map.std = kzalloc(sizeof(*doi_def->map.std), GFP_KERNEL);
 	if (doi_def->map.std == NULL) {
-		ret_val = -ENOMEM;
-		goto add_std_failure;
+		kfree(doi_def);
+		return -ENOMEM;
 	}
 	doi_def->type = CIPSO_V4_MAP_TRANS;
 
Signature · 1 line
1.8.3.1
#5 lore raw
This patch was applied to netdev/net-next.git (refs/heads/master):

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

Quoted 13 lines · On Mon, 30 Aug 2021 18:28:01 +0800 you wrote:

In netlbl_cipsov4_add_std() when 'doi_def->map.std' alloc failed, we sometime observe panic:

  BUG: kernel NULL pointer dereference, address:
  ...
  RIP: 0010:cipso_v4_doi_free+0x3a/0x80
  ...
  Call Trace:
   netlbl_cipsov4_add_std+0xf4/0x8c0
   netlbl_cipsov4_add+0x13f/0x1b0
   genl_family_rcv_msg_doit.isra.15+0x132/0x170
   genl_rcv_msg+0x125/0x240
Quoted 1 line

[...]

Here is the summary with links:
- [v2] net: fix NULL pointer reference in cipso_v4_doi_free

    https://git.kernel.org/netdev/net-next/c/e842cb60e8ac

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

maintainer
#6 lore raw
In reply to 王贇
Quoted 19 lines · 王贇

In netlbl_cipsov4_add_std() when 'doi_def->map.std' alloc failed, we sometime observe panic:

  BUG: kernel NULL pointer dereference, address:
  ...
  RIP: 0010:cipso_v4_doi_free+0x3a/0x80
  ...
  Call Trace:
   netlbl_cipsov4_add_std+0xf4/0x8c0
   netlbl_cipsov4_add+0x13f/0x1b0
   genl_family_rcv_msg_doit.isra.15+0x132/0x170
   genl_rcv_msg+0x125/0x240

This is because in cipso_v4_doi_free() there is no check on 'doi_def->map.std' when doi_def->type got value 1, which is possibe, since netlbl_cipsov4_add_std() haven't initialize it before alloc 'doi_def->map.std'.

Quoted 8 lines

This patch just add the check to prevent panic happen in similar cases.

---
 net/netlabel/netlabel_cipso_v4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I see this was already merged, but it looks good to me, thanks for making those changes.

Quoted 17 lines
net/netlabel/netlabel_cipso_v4.c +2 -3
index baf2357..344c228 100644
@@ -144,8 +144,8 @@ static int netlbl_cipsov4_add_std(struct genl_info *info,
                return -ENOMEM;
        doi_def->map.std = kzalloc(sizeof(*doi_def->map.std), GFP_KERNEL);
        if (doi_def->map.std == NULL) {
-               ret_val = -ENOMEM;
-               goto add_std_failure;
+               kfree(doi_def);
+               return -ENOMEM;
        }
        doi_def->type = CIPSO_V4_MAP_TRANS;
 
--

1.8.3.1

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer
#7 lore raw
Quoted 23 lines · On Mon, 30 Aug 2021 10:17:05 -0400 Paul Moore wrote:
Quoted 22 lines · 王贇

In netlbl_cipsov4_add_std() when 'doi_def->map.std' alloc failed, we sometime observe panic:

  BUG: kernel NULL pointer dereference, address:
  ...
  RIP: 0010:cipso_v4_doi_free+0x3a/0x80
  ...
  Call Trace:
   netlbl_cipsov4_add_std+0xf4/0x8c0
   netlbl_cipsov4_add+0x13f/0x1b0
   genl_family_rcv_msg_doit.isra.15+0x132/0x170
   genl_rcv_msg+0x125/0x240

This is because in cipso_v4_doi_free() there is no check on 'doi_def->map.std' when doi_def->type got value 1, which is possibe, since netlbl_cipsov4_add_std() haven't initialize it before alloc 'doi_def->map.std'.

This patch just add the check to prevent panic happen in similar cases.

Quoted 8 lines
Quoted 5 lines
---
 net/netlabel/netlabel_cipso_v4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)  

I see this was already merged, but it looks good to me, thanks for making those changes.

FWIW it looks like v1 was also merged:

https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=733c99ee8b

maintainer
#8 lore raw
Quoted 30 lines · Jakub Kicinski
Quoted 29 lines · On Mon, 30 Aug 2021 10:17:05 -0400 Paul Moore wrote:
Quoted 27 lines · 王贇

In netlbl_cipsov4_add_std() when 'doi_def->map.std' alloc failed, we sometime observe panic:

  BUG: kernel NULL pointer dereference, address:
  ...
  RIP: 0010:cipso_v4_doi_free+0x3a/0x80
  ...
  Call Trace:
   netlbl_cipsov4_add_std+0xf4/0x8c0
   netlbl_cipsov4_add+0x13f/0x1b0
   genl_family_rcv_msg_doit.isra.15+0x132/0x170
   genl_rcv_msg+0x125/0x240

This is because in cipso_v4_doi_free() there is no check on 'doi_def->map.std' when doi_def->type got value 1, which is possibe, since netlbl_cipsov4_add_std() haven't initialize it before alloc 'doi_def->map.std'.

This patch just add the check to prevent panic happen in similar cases.

---
 net/netlabel/netlabel_cipso_v4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 6 lines
Quoted 2 lines

I see this was already merged, but it looks good to me, thanks for making those changes.

FWIW it looks like v1 was also merged:

https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=733c99ee8b

Yeah, that is unfortunate, there was a brief discussion about that over on one of the -stable patches for the v1 patch (odd that I never saw a patchbot post for the v1 patch?). Having both merged should be harmless, but we want to revert the v1 patch as soon as we can. Michael, can you take care of this?

Signature · 2 lines
paul moore
www.paul-moore.com
author
#9 lore raw

On 2021/8/31 上午12:50, Paul Moore wrote:
[SNIP]

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
---
 net/netlabel/netlabel_cipso_v4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I see this was already merged, but it looks good to me, thanks for making those changes.

FWIW it looks like v1 was also merged:

Quoted 7 lines
Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=733c99ee8b

Yeah, that is unfortunate, there was a brief discussion about that over on one of the -stable patches for the v1 patch (odd that I never saw a patchbot post for the v1 patch?). Having both merged should be harmless, but we want to revert the v1 patch as soon as we can. Michael, can you take care of this?

As v1 already merged, may be we could just goon with it?

Actually both working to fix the problem, v1 will cover all the cases, v2 take care one case since that's currently the only one, but maybe there will be more in future.

Regards,
Michael Wang

Quoted 1 line
maintainer
#10 lore raw
Quoted 21 lines · 王贇

On 2021/8/31 上午12:50, Paul Moore wrote:
[SNIP]

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
---
 net/netlabel/netlabel_cipso_v4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I see this was already merged, but it looks good to me, thanks for making those changes.

FWIW it looks like v1 was also merged:

Quoted 7 lines
Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=733c99ee8b

Yeah, that is unfortunate, there was a brief discussion about that over on one of the -stable patches for the v1 patch (odd that I never saw a patchbot post for the v1 patch?). Having both merged should be harmless, but we want to revert the v1 patch as soon as we can. Michael, can you take care of this?

Quoted 5 lines

As v1 already merged, may be we could just goon with it?

Actually both working to fix the problem, v1 will cover all the cases, v2 take care one case since that's currently the only one, but maybe there will be more in future.

No. Please revert v1 and stick with the v2 patch. The v1 patch is in my opinion a rather ugly hack that addresses the symptom of the problem and not the root cause.

It isn't your fault that both v1 and v2 were merged, but I'm asking you to help cleanup the mess. If you aren't able to do that please let us know so that others can fix this properly.

Signature · 2 lines
paul moore
www.paul-moore.com
author
#11 lore raw
Quoted 28 lines · Paul Moore
Quoted 21 lines · 王贇

On 2021/8/31 上午12:50, Paul Moore wrote:
[SNIP]

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
---
 net/netlabel/netlabel_cipso_v4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I see this was already merged, but it looks good to me, thanks for making those changes.

FWIW it looks like v1 was also merged:

Quoted 7 lines
Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=733c99ee8b

Yeah, that is unfortunate, there was a brief discussion about that over on one of the -stable patches for the v1 patch (odd that I never saw a patchbot post for the v1 patch?). Having both merged should be harmless, but we want to revert the v1 patch as soon as we can. Michael, can you take care of this?

Quoted 5 lines

As v1 already merged, may be we could just goon with it?

Actually both working to fix the problem, v1 will cover all the cases, v2 take care one case since that's currently the only one, but maybe there will be more in future.

Quoted 7 lines

No. Please revert v1 and stick with the v2 patch. The v1 patch is in my opinion a rather ugly hack that addresses the symptom of the problem and not the root cause.

It isn't your fault that both v1 and v2 were merged, but I'm asking you to help cleanup the mess. If you aren't able to do that please let us know so that others can fix this properly.

No problem I can help on that, just try to make sure it's not a meaningless work.

So would it be fine to send out a v3 which revert v1 and apply v2?

Regards,
Michael Wang

Quoted 1 line
maintainer
#12 lore raw

From: 王贇 <[email protected]>
Date: Wed, 1 Sep 2021 09:51:28 +0800

Quoted 35 lines · Paul Moore
Quoted 32 lines · 王贇
Quoted 21 lines · Paul Moore

[SNIP]

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
---
 net/netlabel/netlabel_cipso_v4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I see this was already merged, but it looks good to me, thanks for making those changes.

FWIW it looks like v1 was also merged:

Quoted 7 lines
Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=733c99ee8b

Yeah, that is unfortunate, there was a brief discussion about that over on one of the -stable patches for the v1 patch (odd that I never saw a patchbot post for the v1 patch?). Having both merged should be harmless, but we want to revert the v1 patch as soon as we can. Michael, can you take care of this?

Quoted 5 lines

As v1 already merged, may be we could just goon with it?

Actually both working to fix the problem, v1 will cover all the cases, v2 take care one case since that's currently the only one, but maybe there will be more in future.

No. Please revert v1 and stick with the v2 patch. The v1 patch is in my opinion a rather ugly hack that addresses the symptom of the problem and not the root cause.

Quoted 8 lines
Quoted 3 lines

It isn't your fault that both v1 and v2 were merged, but I'm asking you to help cleanup the mess. If you aren't able to do that please let us know so that others can fix this properly.

No problem I can help on that, just try to make sure it's not a meaningless work.

So would it be fine to send out a v3 which revert v1 and apply v2?

Please don't do things this way just send the relative change.

Thanks.

author
#13 lore raw
Quoted 42 lines · David Miller

From: 王贇 <[email protected]>
Date: Wed, 1 Sep 2021 09:51:28 +0800

Quoted 39 lines · Paul Moore
Quoted 35 lines · 王贇
Quoted 21 lines · Paul Moore

[SNIP]

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
---
 net/netlabel/netlabel_cipso_v4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I see this was already merged, but it looks good to me, thanks for making those changes.

FWIW it looks like v1 was also merged:

Quoted 7 lines
Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=733c99ee8b

Yeah, that is unfortunate, there was a brief discussion about that over on one of the -stable patches for the v1 patch (odd that I never saw a patchbot post for the v1 patch?). Having both merged should be harmless, but we want to revert the v1 patch as soon as we can. Michael, can you take care of this?

Quoted 5 lines

As v1 already merged, may be we could just goon with it?

Actually both working to fix the problem, v1 will cover all the cases, v2 take care one case since that's currently the only one, but maybe there will be more in future.

No. Please revert v1 and stick with the v2 patch. The v1 patch is in my opinion a rather ugly hack that addresses the symptom of the problem and not the root cause.

It isn't your fault that both v1 and v2 were merged, but I'm asking you to help cleanup the mess. If you aren't able to do that please let us know so that others can fix this properly.

Quoted 6 lines
Quoted 4 lines

No problem I can help on that, just try to make sure it's not a meaningless work.

So would it be fine to send out a v3 which revert v1 and apply v2?

Please don't do things this way just send the relative change.

Could you please check the patch:

Revert "net: fix NULL pointer reference in cipso_v4_doi_free"

see if that's the right way?

Regards,
Michael Wang

Quoted 3 lines

Thanks.

maintainer
#14 lore raw

From: 王贇 <[email protected]>
Date: Wed, 1 Sep 2021 17:41:00 +0800

Quoted 50 lines · David Miller
Quoted 47 lines

From: 王贇 <[email protected]>
Date: Wed, 1 Sep 2021 09:51:28 +0800

Quoted 43 lines · Paul Moore
Quoted 28 lines · 王贇
Quoted 21 lines · Paul Moore

[SNIP]

Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
---
 net/netlabel/netlabel_cipso_v4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I see this was already merged, but it looks good to me, thanks for making those changes.

FWIW it looks like v1 was also merged:

Quoted 7 lines
Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/commit/?id=733c99ee8b

Yeah, that is unfortunate, there was a brief discussion about that over on one of the -stable patches for the v1 patch (odd that I never saw a patchbot post for the v1 patch?). Having both merged should be harmless, but we want to revert the v1 patch as soon as we can. Michael, can you take care of this?

Quoted 5 lines

As v1 already merged, may be we could just goon with it?

Actually both working to fix the problem, v1 will cover all the cases, v2 take care one case since that's currently the only one, but maybe there will be more in future.

Quoted 7 lines

No. Please revert v1 and stick with the v2 patch. The v1 patch is in my opinion a rather ugly hack that addresses the symptom of the problem and not the root cause.

It isn't your fault that both v1 and v2 were merged, but I'm asking you to help cleanup the mess. If you aren't able to do that please let us know so that others can fix this properly.

No problem I can help on that, just try to make sure it's not a meaningless work.

So would it be fine to send out a v3 which revert v1 and apply v2?

Quoted 7 lines
Quoted 1 line

Please don't do things this way just send the relative change.

Could you please check the patch:

Revert "net: fix NULL pointer reference in cipso_v4_doi_free"

see if that's the right way?

It is not. Please just send a patch against the net GIT tree which relatively changes the code to match v2 of your change.

Thank you.

author
#15 lore raw

On 2021/9/1 下午6:45, David Miller wrote:
[snip]

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 9 lines
Quoted 4 lines

It isn't your fault that both v1 and v2 were merged, but I'm asking you to help cleanup the mess. If you aren't able to do that please let us know so that others can fix this properly.

No problem I can help on that, just try to make sure it's not a meaningless work.

So would it be fine to send out a v3 which revert v1 and apply v2?

Please don't do things this way just send the relative change.

Quoted 7 lines
Quoted 5 lines

Could you please check the patch:

Revert "net: fix NULL pointer reference in cipso_v4_doi_free"

see if that's the right way?

It is not. Please just send a patch against the net GIT tree which relatively changes the code to match v2 of your change.

Sorry for my horrible reading comprehension... I checked netdev/net.git master branch and saw v2's change already applied, thus I've no idea how to change it again but pretty sure I still misunderstanding the suggestion, could please kindly provide more details?

Regards,
Michael Wang

Quoted 3 lines

Thank you.

author
#16 lore raw

PATCH 1/1 Revert "net: fix NULL pointer reference in cipso_v4_doi_free"

In reply to 王贇

This reverts commit 733c99ee8be9a1410287cdbb943887365e83b2d6.

Since commit e842cb60e8ac ("net: fix NULL pointer reference in cipso_v4_doi_free") also applied to fix the root cause, we can just revert the old version now.

---
 net/ipv4/cipso_ipv4.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
net/ipv4/cipso_ipv4.c +8 -10
index 7fbd0b5..099259f 100644
@@ -465,16 +465,14 @@ void cipso_v4_doi_free(struct cipso_v4_doi *doi_def)
 	if (!doi_def)
 		return;
 
-	if (doi_def->map.std) {
-		switch (doi_def->type) {
-		case CIPSO_V4_MAP_TRANS:
-			kfree(doi_def->map.std->lvl.cipso);
-			kfree(doi_def->map.std->lvl.local);
-			kfree(doi_def->map.std->cat.cipso);
-			kfree(doi_def->map.std->cat.local);
-			kfree(doi_def->map.std);
-			break;
-		}
+	switch (doi_def->type) {
+	case CIPSO_V4_MAP_TRANS:
+		kfree(doi_def->map.std->lvl.cipso);
+		kfree(doi_def->map.std->lvl.local);
+		kfree(doi_def->map.std->cat.cipso);
+		kfree(doi_def->map.std->cat.local);
+		kfree(doi_def->map.std);
+		break;
 	}
 	kfree(doi_def);
 }
Signature · 1 line
1.8.3.1
author
#17 lore raw

Re: [PATCH] Revert "net: fix NULL pointer reference in cipso_v4_doi_free"

Hi Paul, it confused me since it's the first time I face such situation, but I just realized what you're asking is actually this revert, correct?

Regards,
Michael Wang

Quoted 42 lines · 王贇

This reverts commit 733c99ee8be9a1410287cdbb943887365e83b2d6.

Since commit e842cb60e8ac ("net: fix NULL pointer reference in cipso_v4_doi_free") also applied to fix the root cause, we can just revert the old version now.

---
 net/ipv4/cipso_ipv4.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
net/ipv4/cipso_ipv4.c +8 -10
index 7fbd0b5..099259f 100644
@@ -465,16 +465,14 @@ void cipso_v4_doi_free(struct cipso_v4_doi *doi_def)
 	if (!doi_def)
 		return;
 
-	if (doi_def->map.std) {
-		switch (doi_def->type) {
-		case CIPSO_V4_MAP_TRANS:
-			kfree(doi_def->map.std->lvl.cipso);
-			kfree(doi_def->map.std->lvl.local);
-			kfree(doi_def->map.std->cat.cipso);
-			kfree(doi_def->map.std->cat.local);
-			kfree(doi_def->map.std);
-			break;
-		}
+	switch (doi_def->type) {
+	case CIPSO_V4_MAP_TRANS:
+		kfree(doi_def->map.std->lvl.cipso);
+		kfree(doi_def->map.std->lvl.local);
+		kfree(doi_def->map.std->cat.cipso);
+		kfree(doi_def->map.std->cat.local);
+		kfree(doi_def->map.std);
+		break;
 	}
 	kfree(doi_def);
 }
maintainer
#18 lore raw

Re: [PATCH] Revert "net: fix NULL pointer reference in cipso_v4_doi_free"

Quoted 4 lines · 王贇

Hi Paul, it confused me since it's the first time I face such situation, but I just realized what you're asking is actually this revert, correct?

I believe DaveM already answered your question in the other thread, but if you are still unsure about the patch let me know.

Signature · 2 lines
paul moore
www.paul-moore.com
author
#19 lore raw

Re: [PATCH] Revert "net: fix NULL pointer reference in cipso_v4_doi_free"

Quoted 8 lines · Paul Moore
Quoted 4 lines · 王贇

Hi Paul, it confused me since it's the first time I face such situation, but I just realized what you're asking is actually this revert, correct?

I believe DaveM already answered your question in the other thread, but if you are still unsure about the patch let me know.

I do failed to get the point :-(

As I checked the:
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git

both v1 and v2 are there with the same description and both code modification are applied.

We want revert v1 but not in a revert patch style, then do you suggest send a normal patch to do the code revert?

Regards,
Michael Wang

Quoted 1 line
maintainer
#20 lore raw

Re: [PATCH] Revert "net: fix NULL pointer reference in cipso_v4_doi_free"

Quoted 12 lines · 王贇
Quoted 8 lines · Paul Moore
Quoted 4 lines · 王贇

Hi Paul, it confused me since it's the first time I face such situation, but I just realized what you're asking is actually this revert, correct?

I believe DaveM already answered your question in the other thread, but if you are still unsure about the patch let me know.

I do failed to get the point :-(

Quoted 8 lines

As I checked the:
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git

both v1 and v2 are there with the same description and both code modification are applied.

We want revert v1 but not in a revert patch style, then do you suggest send a normal patch to do the code revert?

It sounds like DaveM wants you to create a normal (not a revert) patch that removes the v1 changes while leaving the v2 changes intact. In the patch description you can mention that v1 was merged as a mistake and that v2 is the correct fix (provide commit IDs for each in your commit description using the usual 12-char hash snippet followed by the subject in parens-and-quotes).

Signature · 2 lines
paul moore
www.paul-moore.com
author
#21 lore raw

Re: [PATCH] Revert "net: fix NULL pointer reference in cipso_v4_doi_free"

On 2021/9/3 上午10:15, Paul Moore wrote:
[snip]

Quoted 6 lines
Quoted 5 lines

both v1 and v2 are there with the same description and both code modification are applied.

We want revert v1 but not in a revert patch style, then do you suggest send a normal patch to do the code revert?

Quoted 6 lines

It sounds like DaveM wants you to create a normal (not a revert) patch that removes the v1 changes while leaving the v2 changes intact. In the patch description you can mention that v1 was merged as a mistake and that v2 is the correct fix (provide commit IDs for each in your commit description using the usual 12-char hash snippet followed by the subject in parens-and-quotes).

Thanks for the kindly explain, I've sent:
[PATCH] net: remove the unnecessary check in cipso_v4_doi_free

Which actually revert the v1 and mentioned v2 fixed the root casue, Would you please take a look see if that is helpful?

Regards,
Michael Wang

Quoted 1 line
maintainer
#22 lore raw

Re: [PATCH] Revert "net: fix NULL pointer reference in cipso_v4_doi_free"

Quoted 15 lines · 王贇

On 2021/9/3 上午10:15, Paul Moore wrote:
[snip]

Quoted 6 lines
Quoted 5 lines

both v1 and v2 are there with the same description and both code modification are applied.

We want revert v1 but not in a revert patch style, then do you suggest send a normal patch to do the code revert?

Quoted 6 lines

It sounds like DaveM wants you to create a normal (not a revert) patch that removes the v1 changes while leaving the v2 changes intact. In the patch description you can mention that v1 was merged as a mistake and that v2 is the correct fix (provide commit IDs for each in your commit description using the usual 12-char hash snippet followed by the subject in parens-and-quotes).

Quoted 5 lines

Thanks for the kindly explain, I've sent:
[PATCH] net: remove the unnecessary check in cipso_v4_doi_free

Which actually revert the v1 and mentioned v2 fixed the root casue, Would you please take a look see if that is helpful?

That looks correct to me, acked. Thanks.

Signature · 2 lines
paul moore
www.paul-moore.com
author
#23 lore raw

PATCH 1/1 net: remove the unnecessary check in cipso_v4_doi_free

In reply to 王贇

The commit 733c99ee8be9 ("net: fix NULL pointer reference in cipso_v4_doi_free") was merged by a mistake, this patch try to cleanup the mess.

And we already have the commit e842cb60e8ac ("net: fix NULL pointer reference in cipso_v4_doi_free") which fixed the root cause of the issue mentioned in it's description.

---
 net/ipv4/cipso_ipv4.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
net/ipv4/cipso_ipv4.c +8 -10
index 7fbd0b5..099259f 100644
@@ -465,16 +465,14 @@ void cipso_v4_doi_free(struct cipso_v4_doi *doi_def)
 	if (!doi_def)
 		return;
 
-	if (doi_def->map.std) {
-		switch (doi_def->type) {
-		case CIPSO_V4_MAP_TRANS:
-			kfree(doi_def->map.std->lvl.cipso);
-			kfree(doi_def->map.std->lvl.local);
-			kfree(doi_def->map.std->cat.cipso);
-			kfree(doi_def->map.std->cat.local);
-			kfree(doi_def->map.std);
-			break;
-		}
+	switch (doi_def->type) {
+	case CIPSO_V4_MAP_TRANS:
+		kfree(doi_def->map.std->lvl.cipso);
+		kfree(doi_def->map.std->lvl.local);
+		kfree(doi_def->map.std->cat.cipso);
+		kfree(doi_def->map.std->cat.local);
+		kfree(doi_def->map.std);
+		break;
 	}
 	kfree(doi_def);
 }
Signature · 1 line
1.8.3.1
maintainer Acked-by on v1 1/1
#24 lore raw

Re: [PATCH] net: remove the unnecessary check in cipso_v4_doi_free

Quoted 9 lines · 王贇

The commit 733c99ee8be9 ("net: fix NULL pointer reference in cipso_v4_doi_free") was merged by a mistake, this patch try to cleanup the mess.

And we already have the commit e842cb60e8ac ("net: fix NULL pointer reference in cipso_v4_doi_free") which fixed the root cause of the issue mentioned in it's description.

Quoted 5 lines
---
 net/ipv4/cipso_ipv4.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

Verified that the v2 patch is in net/master so removing the v1 patch as this does is the right thing to do. Thanks for sending this out.

Quoted 32 lines
net/ipv4/cipso_ipv4.c +8 -11
index 7fbd0b5..099259f 100644
@@ -465,16 +465,14 @@ void cipso_v4_doi_free(struct cipso_v4_doi *doi_def)
        if (!doi_def)
                return;
 
-       if (doi_def->map.std) {
-               switch (doi_def->type) {
-               case CIPSO_V4_MAP_TRANS:
-                       kfree(doi_def->map.std->lvl.cipso);
-                       kfree(doi_def->map.std->lvl.local);
-                       kfree(doi_def->map.std->cat.cipso);
-                       kfree(doi_def->map.std->cat.local);
-                       kfree(doi_def->map.std);
-                       break;
-               }
+       switch (doi_def->type) {
+       case CIPSO_V4_MAP_TRANS:
+               kfree(doi_def->map.std->lvl.cipso);
+               kfree(doi_def->map.std->lvl.local);
+               kfree(doi_def->map.std->cat.cipso);
+               kfree(doi_def->map.std->cat.local);
+               kfree(doi_def->map.std);
+               break;
        }
        kfree(doi_def);
 }
--

1.8.3.1

Signature · 2 lines
paul moore
www.paul-moore.com