All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ipvs: initialize 'ret' variable in do_ip_vs_set_ctl()
@ 2022-12-02  3:25 Li Qiong
  2022-12-02 10:02 ` Simon Horman
  2022-12-02 10:07 ` Dan Carpenter
  0 siblings, 2 replies; 10+ messages in thread
From: Li Qiong @ 2022-12-02  3:25 UTC (permalink / raw)
  To: Simon Horman, Julian Anastasov, Pablo Neira Ayuso,
	Jozsef Kadlecsik, Florian Westphal, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, lvs-devel, netfilter-devel,
	kernel-janitors, coreteam, Yu Zhe, Li Qiong

The 'ret' should need to be initialized to 0, in case
return a uninitialized value because no default process
for "switch (cmd)".

Signed-off-by: Li Qiong <liqiong@nfschina.com>
---
 net/netfilter/ipvs/ip_vs_ctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index 988222fff9f0..4b20db86077c 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -2456,7 +2456,7 @@ static int
 do_ip_vs_set_ctl(struct sock *sk, int cmd, sockptr_t ptr, unsigned int len)
 {
 	struct net *net = sock_net(sk);
-	int ret;
+	int ret = 0;
 	unsigned char arg[MAX_SET_ARGLEN];
 	struct ip_vs_service_user *usvc_compat;
 	struct ip_vs_service_user_kern usvc;
-- 
2.11.0


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

* Re: [PATCH] ipvs: initialize 'ret' variable in do_ip_vs_set_ctl()
  2022-12-02  3:25 [PATCH] ipvs: initialize 'ret' variable in do_ip_vs_set_ctl() Li Qiong
@ 2022-12-02 10:02 ` Simon Horman
  2022-12-02 10:07 ` Dan Carpenter
  1 sibling, 0 replies; 10+ messages in thread
From: Simon Horman @ 2022-12-02 10:02 UTC (permalink / raw)
  To: Li Qiong
  Cc: Julian Anastasov, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel, lvs-devel, netfilter-devel,
	kernel-janitors, coreteam, Yu Zhe

On Fri, Dec 02, 2022 at 11:25:11AM +0800, Li Qiong wrote:
> The 'ret' should need to be initialized to 0, in case
> return a uninitialized value because no default process
> for "switch (cmd)".
> 
> Signed-off-by: Li Qiong <liqiong@nfschina.com>

Thanks,

I agree there seems to be a problem here.  But perhaps it's nicer to solve
it by adding a default case to the switch statement?

Also, if we update the declaration of ret, perhaps we could also move it to
the bottom of the declaration of local variables, to move more towards
reverse xmas tree order.

But to be honest, I don't feel strongly about either of these issues.

So if someone wants to take this patch as-is then feel free to add.

Reviewed-by: Simon Horman <horms@verge.net.au>

> ---
>  net/netfilter/ipvs/ip_vs_ctl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
> index 988222fff9f0..4b20db86077c 100644
> --- a/net/netfilter/ipvs/ip_vs_ctl.c
> +++ b/net/netfilter/ipvs/ip_vs_ctl.c
> @@ -2456,7 +2456,7 @@ static int
>  do_ip_vs_set_ctl(struct sock *sk, int cmd, sockptr_t ptr, unsigned int len)
>  {
>  	struct net *net = sock_net(sk);
> -	int ret;
> +	int ret = 0;
>  	unsigned char arg[MAX_SET_ARGLEN];
>  	struct ip_vs_service_user *usvc_compat;
>  	struct ip_vs_service_user_kern usvc;
> -- 
> 2.11.0
> 

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

* Re: [PATCH] ipvs: initialize 'ret' variable in do_ip_vs_set_ctl()
  2022-12-02  3:25 [PATCH] ipvs: initialize 'ret' variable in do_ip_vs_set_ctl() Li Qiong
  2022-12-02 10:02 ` Simon Horman
@ 2022-12-02 10:07 ` Dan Carpenter
  2022-12-02 10:18   ` liqiong
  1 sibling, 1 reply; 10+ messages in thread
From: Dan Carpenter @ 2022-12-02 10:07 UTC (permalink / raw)
  To: Li Qiong, Peilin Ye
  Cc: Simon Horman, Julian Anastasov, Pablo Neira Ayuso,
	Jozsef Kadlecsik, Florian Westphal, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	lvs-devel, netfilter-devel, kernel-janitors, coreteam, Yu Zhe

On Fri, Dec 02, 2022 at 11:25:11AM +0800, Li Qiong wrote:
> The 'ret' should need to be initialized to 0, in case
> return a uninitialized value because no default process
> for "switch (cmd)".
> 
> Signed-off-by: Li Qiong <liqiong@nfschina.com>

If this is a real bug, then it needs a fixes tag.  The fixes tag helps
us know whether to back port or not and it also helps in reviewing the
patch.  Also get_maintainer.pl will CC the person who introduced the
bug so they can review it.  They are normally the best person to review
their own code.

Here it would be:
Fixes: c5a8a8498eed ("ipvs: Fix uninit-value in do_ip_vs_set_ctl()")

Which is strange...  Also it suggest that the correct value is -EINVAL
and not 0.

The thing about uninitialized variable bugs is that Smatch and Clang
both warn about them so they tend to get reported pretty quick.
Apparently neither Nathan nor I sent forwarded this static checker
warning.  :/

regards,
dan carpenter

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

* Re: [PATCH] ipvs: initialize 'ret' variable in do_ip_vs_set_ctl()
  2022-12-02 10:07 ` Dan Carpenter
@ 2022-12-02 10:18   ` liqiong
  2022-12-02 10:26     ` Dan Carpenter
  0 siblings, 1 reply; 10+ messages in thread
From: liqiong @ 2022-12-02 10:18 UTC (permalink / raw)
  To: Dan Carpenter, Peilin Ye
  Cc: Simon Horman, Julian Anastasov, Pablo Neira Ayuso,
	Jozsef Kadlecsik, Florian Westphal, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	lvs-devel, netfilter-devel, kernel-janitors, coreteam, Yu Zhe



在 2022年12月02日 18:07, Dan Carpenter 写道:
> On Fri, Dec 02, 2022 at 11:25:11AM +0800, Li Qiong wrote:
>> The 'ret' should need to be initialized to 0, in case
>> return a uninitialized value because no default process
>> for "switch (cmd)".
>>
>> Signed-off-by: Li Qiong <liqiong@nfschina.com>
> If this is a real bug, then it needs a fixes tag.  The fixes tag helps
> us know whether to back port or not and it also helps in reviewing the
> patch.  Also get_maintainer.pl will CC the person who introduced the
> bug so they can review it.  They are normally the best person to review
> their own code.
>
> Here it would be:
> Fixes: c5a8a8498eed ("ipvs: Fix uninit-value in do_ip_vs_set_ctl()")
>
> Which is strange...  Also it suggest that the correct value is -EINVAL
> and not 0.
>
> The thing about uninitialized variable bugs is that Smatch and Clang
> both warn about them so they tend to get reported pretty quick.
> Apparently neither Nathan nor I sent forwarded this static checker
> warning.  :/
>
> regards,
> dan carpenter

It is not a real bug,   I  use tool (eg: smatch, sparse) to audit the code,  got this warning and check it,
found may be a real problem.

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

* Re: [PATCH] ipvs: initialize 'ret' variable in do_ip_vs_set_ctl()
  2022-12-02 10:18   ` liqiong
@ 2022-12-02 10:26     ` Dan Carpenter
  2022-12-02 11:26       ` Julian Anastasov
  0 siblings, 1 reply; 10+ messages in thread
From: Dan Carpenter @ 2022-12-02 10:26 UTC (permalink / raw)
  To: liqiong
  Cc: Peilin Ye, Simon Horman, Julian Anastasov, Pablo Neira Ayuso,
	Jozsef Kadlecsik, Florian Westphal, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	lvs-devel, netfilter-devel, kernel-janitors, coreteam, Yu Zhe

On Fri, Dec 02, 2022 at 06:18:37PM +0800, liqiong wrote:
> 
> 
> 在 2022年12月02日 18:07, Dan Carpenter 写道:
> > On Fri, Dec 02, 2022 at 11:25:11AM +0800, Li Qiong wrote:
> >> The 'ret' should need to be initialized to 0, in case
> >> return a uninitialized value because no default process
> >> for "switch (cmd)".
> >>
> >> Signed-off-by: Li Qiong <liqiong@nfschina.com>
> > If this is a real bug, then it needs a fixes tag.  The fixes tag helps
> > us know whether to back port or not and it also helps in reviewing the
> > patch.  Also get_maintainer.pl will CC the person who introduced the
> > bug so they can review it.  They are normally the best person to review
> > their own code.
> >
> > Here it would be:
> > Fixes: c5a8a8498eed ("ipvs: Fix uninit-value in do_ip_vs_set_ctl()")
> >
> > Which is strange...  Also it suggest that the correct value is -EINVAL
> > and not 0.
> >
> > The thing about uninitialized variable bugs is that Smatch and Clang
> > both warn about them so they tend to get reported pretty quick.
> > Apparently neither Nathan nor I sent forwarded this static checker
> > warning.  :/
> >
> > regards,
> > dan carpenter
> 
> It is not a real bug,   I  use tool (eg: smatch, sparse) to audit the
> code,  got this warning and check it, found may be a real problem.

Yeah.  If it is a false positive just ignore it, do not bother to
silence wrong static checker warnings.

The code in question here is:

	if (len != set_arglen[CMDID(cmd)]) {

The only time that condition can be true is for the cases in the switch
statement.  So Peilin's patch is correct.

Smatch is bad at understanding arrays so Smatch cannot parse the if
statement above as a human reader can.

regards,
dan carpenter


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

* Re: [PATCH] ipvs: initialize 'ret' variable in do_ip_vs_set_ctl()
  2022-12-02 10:26     ` Dan Carpenter
@ 2022-12-02 11:26       ` Julian Anastasov
  2022-12-12  7:05         ` liqiong
  0 siblings, 1 reply; 10+ messages in thread
From: Julian Anastasov @ 2022-12-02 11:26 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: liqiong, Peilin Ye, Simon Horman, Pablo Neira Ayuso, netdev,
	linux-kernel, lvs-devel, netfilter-devel, kernel-janitors,
	Yu Zhe

[-- Attachment #1: Type: text/plain, Size: 2125 bytes --]


	Hello,

On Fri, 2 Dec 2022, Dan Carpenter wrote:

> On Fri, Dec 02, 2022 at 06:18:37PM +0800, liqiong wrote:
> > 
> > 
> > 在 2022年12月02日 18:07, Dan Carpenter 写道:
> > > On Fri, Dec 02, 2022 at 11:25:11AM +0800, Li Qiong wrote:
> > >> The 'ret' should need to be initialized to 0, in case
> > >> return a uninitialized value because no default process
> > >> for "switch (cmd)".
> > >>
> > >> Signed-off-by: Li Qiong <liqiong@nfschina.com>
> > > If this is a real bug, then it needs a fixes tag.  The fixes tag helps
> > > us know whether to back port or not and it also helps in reviewing the
> > > patch.  Also get_maintainer.pl will CC the person who introduced the
> > > bug so they can review it.  They are normally the best person to review
> > > their own code.
> > >
> > > Here it would be:
> > > Fixes: c5a8a8498eed ("ipvs: Fix uninit-value in do_ip_vs_set_ctl()")
> > >
> > > Which is strange...  Also it suggest that the correct value is -EINVAL
> > > and not 0.
> > >
> > > The thing about uninitialized variable bugs is that Smatch and Clang
> > > both warn about them so they tend to get reported pretty quick.
> > > Apparently neither Nathan nor I sent forwarded this static checker
> > > warning.  :/
> > >
> > > regards,
> > > dan carpenter
> > 
> > It is not a real bug,   I  use tool (eg: smatch, sparse) to audit the
> > code,  got this warning and check it, found may be a real problem.
> 
> Yeah.  If it is a false positive just ignore it, do not bother to
> silence wrong static checker warnings.
> 
> The code in question here is:
> 
> 	if (len != set_arglen[CMDID(cmd)]) {
> 
> The only time that condition can be true is for the cases in the switch
> statement.  So Peilin's patch is correct.
> 
> Smatch is bad at understanding arrays so Smatch cannot parse the if
> statement above as a human reader can.

	Yes, no bug in current code. But it is better to return the 
default switch case with -EINVAL (not 0), in case new commands are added.
Such patch should target net-next, it is just for compilers/tools
that do not look into set_arglen[].

Regards

--
Julian Anastasov <ja@ssi.bg>

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

* Re: [PATCH] ipvs: initialize 'ret' variable in do_ip_vs_set_ctl()
  2022-12-02 11:26       ` Julian Anastasov
@ 2022-12-12  7:05         ` liqiong
  2022-12-12  7:43           ` [PATCH v2] ipvs: add a 'default' case " Li Qiong
  0 siblings, 1 reply; 10+ messages in thread
From: liqiong @ 2022-12-12  7:05 UTC (permalink / raw)
  To: Julian Anastasov
  Cc: Dan Carpenter, Peilin Ye, Simon Horman, Pablo Neira Ayuso,
	netdev, linux-kernel, lvs-devel, netfilter-devel,
	kernel-janitors, Yu Zhe



在 2022年12月02日 19:26, Julian Anastasov 写道:
> 	Hello,
>
> On Fri, 2 Dec 2022, Dan Carpenter wrote:
>
>> On Fri, Dec 02, 2022 at 06:18:37PM +0800, liqiong wrote:
>>>
>>> 在 2022年12月02日 18:07, Dan Carpenter 写道:
>>>> On Fri, Dec 02, 2022 at 11:25:11AM +0800, Li Qiong wrote:
>>>>> The 'ret' should need to be initialized to 0, in case
>>>>> return a uninitialized value because no default process
>>>>> for "switch (cmd)".
>>>>>
>>>>> Signed-off-by: Li Qiong <liqiong@nfschina.com>
>>>> If this is a real bug, then it needs a fixes tag.  The fixes tag helps
>>>> us know whether to back port or not and it also helps in reviewing the
>>>> patch.  Also get_maintainer.pl will CC the person who introduced the
>>>> bug so they can review it.  They are normally the best person to review
>>>> their own code.
>>>>
>>>> Here it would be:
>>>> Fixes: c5a8a8498eed ("ipvs: Fix uninit-value in do_ip_vs_set_ctl()")
>>>>
>>>> Which is strange...  Also it suggest that the correct value is -EINVAL
>>>> and not 0.
>>>>
>>>> The thing about uninitialized variable bugs is that Smatch and Clang
>>>> both warn about them so they tend to get reported pretty quick.
>>>> Apparently neither Nathan nor I sent forwarded this static checker
>>>> warning.  :/
>>>>
>>>> regards,
>>>> dan carpenter
>>> It is not a real bug,   I  use tool (eg: smatch, sparse) to audit the
>>> code,  got this warning and check it, found may be a real problem.
>> Yeah.  If it is a false positive just ignore it, do not bother to
>> silence wrong static checker warnings.
>>
>> The code in question here is:
>>
>> 	if (len != set_arglen[CMDID(cmd)]) {
>>
>> The only time that condition can be true is for the cases in the switch
>> statement.  So Peilin's patch is correct.
>>
>> Smatch is bad at understanding arrays so Smatch cannot parse the if
>> statement above as a human reader can.
> 	Yes, no bug in current code. But it is better to return the 
> default switch case with -EINVAL (not 0), in case new commands are added.
> Such patch should target net-next, it is just for compilers/tools
> that do not look into set_arglen[].
>
> Regards
>
> --
> Julian Anastasov <ja@ssi.bg>
Thanks, I will send a v2 patch.


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

* [PATCH v2] ipvs: add a 'default' case in do_ip_vs_set_ctl()
  2022-12-12  7:05         ` liqiong
@ 2022-12-12  7:43           ` Li Qiong
  2022-12-12 14:20             ` Julian Anastasov
  0 siblings, 1 reply; 10+ messages in thread
From: Li Qiong @ 2022-12-12  7:43 UTC (permalink / raw)
  To: Simon Horman, Julian Anastasov, Pablo Neira Ayuso,
	Jozsef Kadlecsik, Florian Westphal, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, lvs-devel, netfilter-devel,
	kernel-janitors, coreteam, Yu Zhe, Li Qiong

It is better to return the default switch case with
'-EINVAL', in case new commands are added. otherwise,
return a uninitialized value of ret.

Signed-off-by: Li Qiong <liqiong@nfschina.com>
Reviewed-by: Simon Horman <horms@verge.net.au>
---
v2: Add 'default' case instead of initializing 'ret'.
---
 net/netfilter/ipvs/ip_vs_ctl.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index 988222fff9f0..97f6a1c8933a 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -2590,6 +2590,11 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, sockptr_t ptr, unsigned int len)
 		break;
 	case IP_VS_SO_SET_DELDEST:
 		ret = ip_vs_del_dest(svc, &udest);
+		break;
+	default:
+		WARN_ON_ONCE(1);
+		ret = -EINVAL;
+		break;
 	}
 
   out_unlock:
-- 
2.11.0


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

* Re: [PATCH v2] ipvs: add a 'default' case in do_ip_vs_set_ctl()
  2022-12-12  7:43           ` [PATCH v2] ipvs: add a 'default' case " Li Qiong
@ 2022-12-12 14:20             ` Julian Anastasov
  2022-12-13 11:28               ` Pablo Neira Ayuso
  0 siblings, 1 reply; 10+ messages in thread
From: Julian Anastasov @ 2022-12-12 14:20 UTC (permalink / raw)
  To: Li Qiong
  Cc: Simon Horman, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, netdev, linux-kernel, lvs-devel,
	netfilter-devel, kernel-janitors, coreteam, Yu Zhe


	Hello,

On Mon, 12 Dec 2022, Li Qiong wrote:

> It is better to return the default switch case with
> '-EINVAL', in case new commands are added. otherwise,
> return a uninitialized value of ret.
> 
> Signed-off-by: Li Qiong <liqiong@nfschina.com>
> Reviewed-by: Simon Horman <horms@verge.net.au>

	Change looks correct to me for -next, thanks!

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

	Still, the comment can explain that this code
is currently unreachable and that some parsers need
the default case to avoid report for uninitialized 'ret'.

> ---
> v2: Add 'default' case instead of initializing 'ret'.
> ---
>  net/netfilter/ipvs/ip_vs_ctl.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
> index 988222fff9f0..97f6a1c8933a 100644
> --- a/net/netfilter/ipvs/ip_vs_ctl.c
> +++ b/net/netfilter/ipvs/ip_vs_ctl.c
> @@ -2590,6 +2590,11 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, sockptr_t ptr, unsigned int len)
>  		break;
>  	case IP_VS_SO_SET_DELDEST:
>  		ret = ip_vs_del_dest(svc, &udest);
> +		break;
> +	default:
> +		WARN_ON_ONCE(1);
> +		ret = -EINVAL;
> +		break;
>  	}
>  
>    out_unlock:
> -- 
> 2.11.0

Regards

--
Julian Anastasov <ja@ssi.bg>


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

* Re: [PATCH v2] ipvs: add a 'default' case in do_ip_vs_set_ctl()
  2022-12-12 14:20             ` Julian Anastasov
@ 2022-12-13 11:28               ` Pablo Neira Ayuso
  0 siblings, 0 replies; 10+ messages in thread
From: Pablo Neira Ayuso @ 2022-12-13 11:28 UTC (permalink / raw)
  To: Julian Anastasov
  Cc: Li Qiong, Simon Horman, Jozsef Kadlecsik, Florian Westphal,
	netdev, linux-kernel, lvs-devel, netfilter-devel,
	kernel-janitors, coreteam, Yu Zhe

On Mon, Dec 12, 2022 at 04:20:41PM +0200, Julian Anastasov wrote:
> 
> 	Hello,
> 
> On Mon, 12 Dec 2022, Li Qiong wrote:
> 
> > It is better to return the default switch case with
> > '-EINVAL', in case new commands are added. otherwise,
> > return a uninitialized value of ret.
> > 
> > Signed-off-by: Li Qiong <liqiong@nfschina.com>
> > Reviewed-by: Simon Horman <horms@verge.net.au>
> 
> 	Change looks correct to me for -next, thanks!
> 
> Acked-by: Julian Anastasov <ja@ssi.bg>

Applied, thanks.

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

end of thread, other threads:[~2022-12-13 11:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-02  3:25 [PATCH] ipvs: initialize 'ret' variable in do_ip_vs_set_ctl() Li Qiong
2022-12-02 10:02 ` Simon Horman
2022-12-02 10:07 ` Dan Carpenter
2022-12-02 10:18   ` liqiong
2022-12-02 10:26     ` Dan Carpenter
2022-12-02 11:26       ` Julian Anastasov
2022-12-12  7:05         ` liqiong
2022-12-12  7:43           ` [PATCH v2] ipvs: add a 'default' case " Li Qiong
2022-12-12 14:20             ` Julian Anastasov
2022-12-13 11:28               ` Pablo Neira Ayuso

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.