public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: netdev@vger.kernel.org, kernel-janitors@vger.kernel.org,
	Anjali Kulkarni <anjali.k.kulkarni@oracle.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Kuniyuki Iwashima <kuniyu@amazon.com>,
	Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 1/4] netlink: Improve exception handling in __netlink_kernel_create()
Date: Sun, 31 Dec 2023 18:42:30 +0100	[thread overview]
Message-ID: <477e5649-87e3-44d9-8226-010b9822e649@web.de> (raw)
In-Reply-To: <90679f69-951c-47b3-b86f-75fd9fde3da3@web.de>

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(-)

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;

--
2.43.0


  reply	other threads:[~2023-12-31 17:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-31 17:40 [PATCH 0/4] netlink: Adjustments for __netlink_kernel_create() Markus Elfring
2023-12-31 17:42 ` Markus Elfring [this message]
2024-01-01 18:13   ` [PATCH 1/4] netlink: Improve exception handling in __netlink_kernel_create() Stephen Hemminger
2023-12-31 17:44 ` [PATCH 2/4] netlink: Move an assignment for the variable “sk” " Markus Elfring
2024-01-01  0:54   ` kernel test robot
2024-01-01 10:22     ` Markus Elfring
2024-01-01 18:14   ` Stephen Hemminger
2023-12-31 17:46 ` [PATCH 3/4] netlink: Delete an unnecessary variable initialisation " Markus Elfring
2024-01-01 18:42   ` Stephen Hemminger
2023-12-31 17:48 ` [PATCH 4/4] netlink: Move an assignment for the variable “cb_mutex” " Markus Elfring
2024-01-01 18:18   ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=477e5649-87e3-44d9-8226-010b9822e649@web.de \
    --to=markus.elfring@web.de \
    --cc=anjali.k.kulkarni@oracle.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@amazon.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox