netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v2] ipvs:set sock send/receive buffer correctly
       [not found] <7d0dbb46-09aa-0163-bfd9-169594489584@huawei.com>
@ 2019-04-21 18:48 ` Julian Anastasov
  2019-04-28  3:03   ` linmiaohe
  0 siblings, 1 reply; 2+ messages in thread
From: Julian Anastasov @ 2019-04-21 18:48 UTC (permalink / raw)
  To: linmiaohe
  Cc: wensong, horms, pablo, kadlec, fw, davem, netdev, lvs-devel,
	netfilter-devel, coreteam, linux-kernel, eric.dumazet,
	Mingfangsen, liujie165


	Hello,

On Thu, 18 Apr 2019, linmiaohe wrote:

> From: Jie Liu <liujie165@huawei.com>
> 
> If we set sysctl_wmem_max or sysctl_rmem_max larger than INT_MAX, the
> send/receive buffer of sock will be an negative value. Same as when
> the val is larger than INT_MAX/2.
> 
> Fixes: 1c003b1580e2 ("ipvs: wakeup master thread")
> Reported-by: Qiang Ning <ningqiang1@huawei.com>
> Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
> Signed-off-by: Jie Liu <liujie165@huawei.com>

	Looks good to me, thanks!

Acked-by: Julian Anastasov <ja@ssi.bg>

> ---
>  net/netfilter/ipvs/ip_vs_sync.c | 20 ++++++++++++++------
>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
> index 2526be6b3d90..760f3364d4a2 100644
> --- a/net/netfilter/ipvs/ip_vs_sync.c
> +++ b/net/netfilter/ipvs/ip_vs_sync.c
> @@ -1278,14 +1278,22 @@ static void set_sock_size(struct sock *sk, int mode, int val)
>  	/* setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)); */
>  	lock_sock(sk);
>  	if (mode) {
> -		val = clamp_t(int, val, (SOCK_MIN_SNDBUF + 1) / 2,
> -			      sysctl_wmem_max);
> -		sk->sk_sndbuf = val * 2;
> +		val = min_t(u32, val, sysctl_wmem_max);
> +
> +		/* Ensure val * 2 fits into an int, to prevent max_t()
> +		 * from treating it as a negative value.
> +		 */
> +		val = min_t(int, val, INT_MAX / 2);
> +		sk->sk_sndbuf = max_t(int, val * 2, SOCK_MIN_SNDBUF);
>  		sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
>  	} else {
> -		val = clamp_t(int, val, (SOCK_MIN_RCVBUF + 1) / 2,
> -			      sysctl_rmem_max);
> -		sk->sk_rcvbuf = val * 2;
> +		val = min_t(u32, val, sysctl_rmem_max);
> +
> +		/* Ensure val * 2 fits into an int, to prevent max_t()
> +		 * from treating it as a negative value.
> +		 */
> +		val = min_t(int, val, INT_MAX / 2);
> +		sk->sk_rcvbuf = max_t(int, val * 2, SOCK_MIN_RCVBUF);
>  		sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
>  	}
>  	release_sock(sk);
> -- 

Regards

--
Julian Anastasov <ja@ssi.bg>

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

* Re: [PATCH v2] ipvs:set sock send/receive buffer correctly
  2019-04-21 18:48 ` [PATCH v2] ipvs:set sock send/receive buffer correctly Julian Anastasov
@ 2019-04-28  3:03   ` linmiaohe
  0 siblings, 0 replies; 2+ messages in thread
From: linmiaohe @ 2019-04-28  3:03 UTC (permalink / raw)
  To: Julian Anastasov
  Cc: wensong, horms, pablo, kadlec, fw, davem, netdev, lvs-devel,
	netfilter-devel, coreteam, linux-kernel, eric.dumazet,
	Mingfangsen, liujie165



On 2019/4/22 2:48, Julian Anastasov wrote:
> 
> 	Hello,
> 
> On Thu, 18 Apr 2019, linmiaohe wrote:
> 
>> From: Jie Liu <liujie165@huawei.com>
>>
>> If we set sysctl_wmem_max or sysctl_rmem_max larger than INT_MAX, the
>> send/receive buffer of sock will be an negative value. Same as when
>> the val is larger than INT_MAX/2.
>>
>> Fixes: 1c003b1580e2 ("ipvs: wakeup master thread")
>> Reported-by: Qiang Ning <ningqiang1@huawei.com>
>> Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
>> Signed-off-by: Jie Liu <liujie165@huawei.com>
> 
> 	Looks good to me, thanks!
> 
> Acked-by: Julian Anastasov <ja@ssi.bg>
> 
>> ---
>>  net/netfilter/ipvs/ip_vs_sync.c | 20 ++++++++++++++------
>>  1 file changed, 14 insertions(+), 6 deletions(-)
>>
>> diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
>> index 2526be6b3d90..760f3364d4a2 100644
>> --- a/net/netfilter/ipvs/ip_vs_sync.c
>> +++ b/net/netfilter/ipvs/ip_vs_sync.c
>> @@ -1278,14 +1278,22 @@ static void set_sock_size(struct sock *sk, int mode, int val)
>>  	/* setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)); */
>>  	lock_sock(sk);
>>  	if (mode) {
>> -		val = clamp_t(int, val, (SOCK_MIN_SNDBUF + 1) / 2,
>> -			      sysctl_wmem_max);
>> -		sk->sk_sndbuf = val * 2;
>> +		val = min_t(u32, val, sysctl_wmem_max);
>> +
>> +		/* Ensure val * 2 fits into an int, to prevent max_t()
>> +		 * from treating it as a negative value.
>> +		 */
>> +		val = min_t(int, val, INT_MAX / 2);
>> +		sk->sk_sndbuf = max_t(int, val * 2, SOCK_MIN_SNDBUF);
>>  		sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
>>  	} else {
>> -		val = clamp_t(int, val, (SOCK_MIN_RCVBUF + 1) / 2,
>> -			      sysctl_rmem_max);
>> -		sk->sk_rcvbuf = val * 2;
>> +		val = min_t(u32, val, sysctl_rmem_max);
>> +
>> +		/* Ensure val * 2 fits into an int, to prevent max_t()
>> +		 * from treating it as a negative value.
>> +		 */
>> +		val = min_t(int, val, INT_MAX / 2);
>> +		sk->sk_rcvbuf = max_t(int, val * 2, SOCK_MIN_RCVBUF);
>>  		sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
>>  	}
>>  	release_sock(sk);
>> -- 
> 
> Regards
> 
> --
> Julian Anastasov <ja@ssi.bg>
> 
> .
> 

Hi all,
    Could you please tell me if there is still any problem?
Many thanks.


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

end of thread, other threads:[~2019-04-28  3:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <7d0dbb46-09aa-0163-bfd9-169594489584@huawei.com>
2019-04-21 18:48 ` [PATCH v2] ipvs:set sock send/receive buffer correctly Julian Anastasov
2019-04-28  3:03   ` linmiaohe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).