mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net/socket: clamp negative backlog value to 0 in listen()
@ 2024-06-28 17:28 Kacper Piwiński
  2024-06-28 21:58 ` Kuniyuki Iwashima
  0 siblings, 1 reply; 2+ messages in thread
From: Kacper Piwiński @ 2024-06-28 17:28 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, netdev, linux-kernel; +Cc: Kacper Piwiński

According to manual: https://man7.org/linux/man-pages/man3/listen.3p.html
If listen() is called with a backlog argument value that is less
than 0, the function behaves as if it had been called with a
backlog argument value of 0.

Signed-off-by: Kacper Piwiński <cosiekvfj@o2.pl>
---
 net/socket.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/socket.c b/net/socket.c
index e416920e9..9567223d7 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1873,8 +1873,7 @@ int __sys_listen(int fd, int backlog)
 	sock = sockfd_lookup_light(fd, &err, &fput_needed);
 	if (sock) {
 		somaxconn = READ_ONCE(sock_net(sock->sk)->core.sysctl_somaxconn);
-		if ((unsigned int)backlog > somaxconn)
-			backlog = somaxconn;
+		backlog = clamp(backlog, 0, somaxconn);
 
 		err = security_socket_listen(sock, backlog);
 		if (!err)
-- 
2.34.1


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

end of thread, other threads:[~2024-06-28 21:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-28 17:28 [PATCH] net/socket: clamp negative backlog value to 0 in listen() Kacper Piwiński
2024-06-28 21:58 ` Kuniyuki Iwashima

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®