summaryrefslogtreecommitdiff
path: root/net/socket.c
diff options
context:
space:
mode:
authorKuniyuki Iwashima <kuniyu@amazon.com>2024-10-24 13:14:58 -0700
committerJakub Kicinski <kuba@kernel.org>2024-10-29 16:31:23 -0700
commit4bbd360a5084d8f890f814327e1d9fbb1f0f6fa1 (patch)
tree60665c3a8969efc0da533d85c37ab3a504032166 /net/socket.c
parentf75d1fbe7809bc5ed134204b920fd9e2fc5db1df (diff)
socket: Print pf->create() when it does not clear sock->sk on failure.
I suggested to put DEBUG_NET_WARN_ON_ONCE() in __sock_create() to catch possible use-after-free. But the warning itself was not useful because our interest is in the callee than the caller. Let's define DEBUG_NET_WARN_ONCE() and print the name of pf->create() and the socket identifier. While at it, we enclose DEBUG_NET_WARN_ON_ONCE() in parentheses too to avoid a checkpatch error. Note that %pf or %pF were obsoleted and will be removed later as per comment in lib/vsprintf.c. Link: https://lore.kernel.org/netdev/202410231427.633734b3-lkp@intel.com/ Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20241024201458.49412-1-kuniyu@amazon.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/socket.c')
-rw-r--r--net/socket.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/net/socket.c b/net/socket.c
index 9a8e4452b9b2..5fb3d265e492 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1578,7 +1578,9 @@ int __sock_create(struct net *net, int family, int type, int protocol,
/* ->create should release the allocated sock->sk object on error
* and make sure sock->sk is set to NULL to avoid use-after-free
*/
- DEBUG_NET_WARN_ON_ONCE(sock->sk);
+ DEBUG_NET_WARN_ONCE(sock->sk,
+ "%ps must clear sock->sk on failure, family: %d, type: %d, protocol: %d\n",
+ pf->create, family, type, protocol);
goto out_module_put;
}