Re: [PATCH] ksmbd: add max connections parameter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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().



[Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux