diff mbox series

[net-next,v4,1/4] usbnet: ipheth: fix risk of NULL pointer deallocation

Message ID 20230607135702.32679-1-forst@pen.gy (mailing list archive)
State Accepted
Commit 2203718c2f59ffdd6c78d54e5add594aebb4461e
Headers show
Series [net-next,v4,1/4] usbnet: ipheth: fix risk of NULL pointer deallocation | expand

Commit Message

Foster Snowhill June 7, 2023, 1:56 p.m. UTC
From: Georgi Valkov <gvalkov@gmail.com>

The cleanup precedure in ipheth_probe will attempt to free a
NULL pointer in dev->ctrl_buf if the memory allocation for
this buffer is not successful. While kfree ignores NULL pointers,
and the existing code is safe, it is a better design to rearrange
the goto labels and avoid this.

Signed-off-by: Georgi Valkov <gvalkov@gmail.com>
Signed-off-by: Foster Snowhill <forst@pen.gy>
---
v4:
  No change
v3: https://lore.kernel.org/netdev/20230527130309.34090-1-forst@pen.gy/
  - Reword commit msg to indicate design improvement rather than bugfix
  - Add missing signoff for Foster Snowhill
  No code changes
v2: https://lore.kernel.org/netdev/20230525194255.4516-1-forst@pen.gy/
  - Factor out goto label change from v1 into this separate patch
v1: n/a
  Part of https://lore.kernel.org/netdev/20230516210127.35841-1-forst@pen.gy/
---
 drivers/net/usb/ipheth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

patchwork-bot+netdevbpf@kernel.org June 9, 2023, 9:30 a.m. UTC | #1
Hello:

This series was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Wed,  7 Jun 2023 15:56:59 +0200 you wrote:
> From: Georgi Valkov <gvalkov@gmail.com>
> 
> The cleanup precedure in ipheth_probe will attempt to free a
> NULL pointer in dev->ctrl_buf if the memory allocation for
> this buffer is not successful. While kfree ignores NULL pointers,
> and the existing code is safe, it is a better design to rearrange
> the goto labels and avoid this.
> 
> [...]

Here is the summary with links:
  - [net-next,v4,1/4] usbnet: ipheth: fix risk of NULL pointer deallocation
    https://git.kernel.org/netdev/net-next/c/2203718c2f59
  - [net-next,v4,2/4] usbnet: ipheth: transmit URBs without trailing padding
    https://git.kernel.org/netdev/net-next/c/3e65efcca87a
  - [net-next,v4,3/4] usbnet: ipheth: add CDC NCM support
    https://git.kernel.org/netdev/net-next/c/a2d274c62e44
  - [net-next,v4,4/4] usbnet: ipheth: update Kconfig description
    https://git.kernel.org/netdev/net-next/c/0c6e9d32ef0c

You are awesome, thank you!
George Valkov June 9, 2023, 10:42 a.m. UTC | #2
Thank you David!

Can you please also backport the patch-series to Linux kernel 5.15, which is in use by the OpenWRT project! The patches apply cleanly.

Cheers!

Georgi Valkov
httpstorm.com
nano RTOS



> On 9 Jun 2023, at 12:30 PM, patchwork-bot+netdevbpf@kernel.org wrote:
> 
> Hello:
> 
> This series was applied to netdev/net-next.git (main)
> by David S. Miller <davem@davemloft.net>:
> 
> On Wed,  7 Jun 2023 15:56:59 +0200 you wrote:
>> From: Georgi Valkov <gvalkov@gmail.com>
>> 
>> The cleanup precedure in ipheth_probe will attempt to free a
>> NULL pointer in dev->ctrl_buf if the memory allocation for
>> this buffer is not successful. While kfree ignores NULL pointers,
>> and the existing code is safe, it is a better design to rearrange
>> the goto labels and avoid this.
>> 
>> [...]
> 
> Here is the summary with links:
>  - [net-next,v4,1/4] usbnet: ipheth: fix risk of NULL pointer deallocation
>    https://git.kernel.org/netdev/net-next/c/2203718c2f59
>  - [net-next,v4,2/4] usbnet: ipheth: transmit URBs without trailing padding
>    https://git.kernel.org/netdev/net-next/c/3e65efcca87a
>  - [net-next,v4,3/4] usbnet: ipheth: add CDC NCM support
>    https://git.kernel.org/netdev/net-next/c/a2d274c62e44
>  - [net-next,v4,4/4] usbnet: ipheth: update Kconfig description
>    https://git.kernel.org/netdev/net-next/c/0c6e9d32ef0c
> 
> You are awesome, thank you!
> -- 
> Deet-doot-dot, I am a bot.
> https://korg.docs.kernel.org/patchwork/pwbot.html
> 
>
Greg KH June 9, 2023, 11:09 a.m. UTC | #3
On Fri, Jun 09, 2023 at 01:42:09PM +0300, George Valkov wrote:
> Thank you David!
> 
> Can you please also backport the patch-series to Linux kernel 5.15, which is in use by the OpenWRT project! The patches apply cleanly.

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>
diff mbox series

Patch

diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c
index 6a769df0b..8875a3d0e 100644
--- a/drivers/net/usb/ipheth.c
+++ b/drivers/net/usb/ipheth.c
@@ -510,8 +510,8 @@  static int ipheth_probe(struct usb_interface *intf,
 	ipheth_free_urbs(dev);
 err_alloc_urbs:
 err_get_macaddr:
-err_alloc_ctrl_buf:
 	kfree(dev->ctrl_buf);
+err_alloc_ctrl_buf:
 err_endpoints:
 	free_netdev(netdev);
 	return retval;