Re: [PATCH net-next] ipvs: properly dereference pe in ip_vs_add_service

Julian Anastasov <[email protected]>
Newsgroups org.kernel.vger.lvs-devel,org.kernel.vger.netdev,org.kernel.vger.netfilter-devel
Message-ID <[email protected]>
	Hello,

On Wed, 26 Jun 2024, Chen Hanxiao wrote:

> Use rcu_dereference_protected to resolve sparse warning:
> 
>   net/netfilter/ipvs/ip_vs_ctl.c:1471:27: warning: dereference of noderef expression
> 
> Fixes: 39b972231536 ("ipvs: handle connections started by real-servers")
> Signed-off-by: Chen Hanxiao <[email protected]>
> ---
>  net/netfilter/ipvs/ip_vs_ctl.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
> index b6d0dcf3a5c3..925e2143ba15 100644
> --- a/net/netfilter/ipvs/ip_vs_ctl.c
> +++ b/net/netfilter/ipvs/ip_vs_ctl.c
> @@ -1369,7 +1369,7 @@ ip_vs_add_service(struct netns_ipvs *ipvs, struct ip_vs_service_user_kern *u,
>  {
>  	int ret = 0;
>  	struct ip_vs_scheduler *sched = NULL;
> -	struct ip_vs_pe *pe = NULL;
> +	struct ip_vs_pe *pe = NULL, *tmp_pe = NULL;

	NULL init is not needed

>  	struct ip_vs_service *svc = NULL;
>  	int ret_hooks = -1;
>  
> @@ -1468,7 +1468,8 @@ ip_vs_add_service(struct netns_ipvs *ipvs, struct ip_vs_service_user_kern *u,
>  		atomic_inc(&ipvs->ftpsvc_counter);
>  	else if (svc->port == 0)
>  		atomic_inc(&ipvs->nullsvc_counter);
> -	if (svc->pe && svc->pe->conn_out)
> +	tmp_pe = rcu_dereference_protected(svc->pe, 1);
> +	if (tmp_pe && tmp_pe->conn_out)
>  		atomic_inc(&ipvs->conn_out_counter);

	Alternative option would be to use 'pe' above and to move
the RCU_INIT_POINTER and pe = NULL with their comment here.
It is up to you to decide which option is better...

Regards

--
Julian Anastasov <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.