netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] packet: Improve exception handling in fanout_add()
@ 2023-12-31 15:39 Markus Elfring
  2023-12-31 21:45 ` Willem de Bruijn
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Markus Elfring @ 2023-12-31 15:39 UTC (permalink / raw)
  To: netdev, kernel-janitors, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn
  Cc: LKML

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 31 Dec 2023 16:30:51 +0100

The kfree() function was called in some cases by the fanout_add() function
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/packet/af_packet.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 5f1757a32842..0681d4f1ed85 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1712,14 +1712,14 @@ static int fanout_add(struct sock *sk, struct fanout_args *args)

 	err = -EALREADY;
 	if (po->fanout)
-		goto out;
+		goto unlock_mutex;

 	if (type == PACKET_FANOUT_ROLLOVER ||
 	    (type_flags & PACKET_FANOUT_FLAG_ROLLOVER)) {
 		err = -ENOMEM;
 		rollover = kzalloc(sizeof(*rollover), GFP_KERNEL);
 		if (!rollover)
-			goto out;
+			goto unlock_mutex;
 		atomic_long_set(&rollover->num, 0);
 		atomic_long_set(&rollover->num_huge, 0);
 		atomic_long_set(&rollover->num_failed, 0);
@@ -1812,6 +1812,7 @@ static int fanout_add(struct sock *sk, struct fanout_args *args)

 out:
 	kfree(rollover);
+unlock_mutex:
 	mutex_unlock(&fanout_mutex);
 	return err;
 }
--
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-01-02 16:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-31 15:39 [PATCH] packet: Improve exception handling in fanout_add() Markus Elfring
2023-12-31 21:45 ` Willem de Bruijn
2024-01-01  9:46   ` Markus Elfring
2024-01-01 15:29     ` Willem de Bruijn
2024-01-01 16:33       ` David Laight
2024-01-01 18:12     ` Stephen Hemminger
2024-01-02  7:32       ` Markus Elfring
2023-12-31 22:44 ` [PATCH] " Stephen Hemminger
2024-01-02 16:30 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).