From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <cosiekvfj@o2.pl>
Cc: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
<pabeni@redhat.com>, <kuniyu@amazon.com>
Subject: Re: [PATCH] net/socket: clamp negative backlog value to 0 in listen()
Date: Fri, 28 Jun 2024 14:58:48 -0700 [thread overview]
Message-ID: <20240628215848.99285-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20240628172836.19213-1-cosiekvfj@o2.pl>
From Kacper Piwiński <cosiekvfj@o2.pl>
Date: Fri, 28 Jun 2024 19:28:36 +0200
> 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.
This breaks many applications that assume listen(fd, -1) configures
the backlog with the max value allowed in the netns.
The behaviour is useful especially in a container-like env where app
does not have access to procfs.
The man page should be updated instead.
>
> 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)
> --
prev parent reply other threads:[~2024-06-28 21:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-28 17:28 Kacper Piwiński
2024-06-28 21:58 ` Kuniyuki Iwashima [this message]
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=20240628215848.99285-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=cosiekvfj@o2.pl \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--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
all inboxes | Powered by JetHome®