All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: linux-cifs@vger.kernel.org, smfrench@gmail.com, tom@talpey.com,
	atteh.mailbox@gmail.com
Subject: Re: [PATCH] ksmbd: add max connections parameter
Date: Thu, 29 Dec 2022 11:29:06 +0900	[thread overview]
Message-ID: <Y6z7cjj+OkkVYFYR@google.com> (raw)
In-Reply-To: <20221227145954.9663-1-linkinjeon@kernel.org>

On (22/12/27 23:59), Namjae Jeon wrote:
[..]
>  	csin = KSMBD_TCP_PEER_SOCKADDR(KSMBD_TRANS(t)->conn);
>  	if (kernel_getpeername(client_sk, csin) < 0) {
> @@ -239,6 +243,17 @@ static int ksmbd_kthread_fn(void *p)
>  			continue;
>  		}
>  
> +		if (server_conf.max_connections) {
> +			if (atomic_read(&active_num_conn) >= server_conf.max_connections) {
> +				pr_info("Limit the maximum number of connections(%u)\n",
> +						atomic_read(&active_num_conn));
> +				sock_release(client_sk);
> +				continue;
> +			}
> +
> +			atomic_inc(&active_num_conn);
> +		}

This has to be one atomic op:

	if (atomic_inc_return() >= max_connections) {
		atomic_dec
		sock_release
		continue
	}

Otherwise it's racy and it's possible to have more active
connections than the limit.

I'd also note that pr_info() is risky there, it would be safer
to use rate-limited printk().

  reply	other threads:[~2022-12-29  2:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-27 14:59 [PATCH] ksmbd: add max connections parameter Namjae Jeon
2022-12-29  2:29 ` Sergey Senozhatsky [this message]
2022-12-29  9:40   ` Namjae Jeon

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=Y6z7cjj+OkkVYFYR@google.com \
    --to=senozhatsky@chromium.org \
    --cc=atteh.mailbox@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=smfrench@gmail.com \
    --cc=tom@talpey.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.