diff mbox series

[1/4] netlink: Improve exception handling in __netlink_kernel_create()

Message ID 477e5649-87e3-44d9-8226-010b9822e649@web.de (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series netlink: Adjustments for __netlink_kernel_create() | expand

Checks

Context Check Description
netdev/series_format warning Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1118 this patch: 1118
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 1141 this patch: 1141
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1145 this patch: 1145
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 15 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Markus Elfring Dec. 31, 2023, 5:42 p.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 31 Dec 2023 17:26:41 +0100

The kfree() function was called in one case by
the __netlink_kernel_create() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

Thus use another label.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 net/netlink/af_netlink.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--
2.43.0

Comments

Stephen Hemminger Jan. 1, 2024, 6:13 p.m. UTC | #1
On Sun, 31 Dec 2023 18:42:30 +0100
Markus Elfring <Markus.Elfring@web.de> wrote:

> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 31 Dec 2023 17:26:41 +0100
> 
> The kfree() function was called in one case by
> the __netlink_kernel_create() function during error handling
> even if the passed variable contained a null pointer.
> This issue was detected by using the Coccinelle software.
> 
> Thus use another label.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>


NAK
Please look at something else, calling kfree(NULL) is correct
and the preferred solution.
diff mbox series

Patch

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 4ed8ffd58ff3..c3f88015cacf 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2042,7 +2042,7 @@  __netlink_kernel_create(struct net *net, int unit, struct module *module,

 	listeners = kzalloc(sizeof(*listeners) + NLGRPSZ(groups), GFP_KERNEL);
 	if (!listeners)
-		goto out_sock_release;
+		goto out_netlink_release_sock;

 	sk->sk_data_ready = netlink_data_ready;
 	if (cfg && cfg->input)
@@ -2076,6 +2076,7 @@  __netlink_kernel_create(struct net *net, int unit, struct module *module,

 out_sock_release:
 	kfree(listeners);
+out_netlink_release_sock:
 	netlink_kernel_release(sk);
 	return NULL;