2015-11-06 18:46:53

by Dmitry Safonov

[permalink] [raw]
Subject: [PATCH] net: netfilter: fix GCC uninitialized warning

With x86_64_defconfig:
GCC thinks that in nfulnl_recv_config flags parameter is not inited but
it was under the same condition (nfula[NFULA_CFG_FLAGS] == true).
Suppress this warning:
net/netfilter/nfnetlink_log.c: In function ‘nfulnl_recv_config’:
net/netfilter/nfnetlink_log.c:320:14: warning: ‘flags’ may be used uninitialized in this function [-Wmaybe-uninitialized]
inst->flags = flags;
^
Signed-off-by: Dmitry Safonov <[email protected]>
---
net/netfilter/nfnetlink_log.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index 06eb48fceb42e4..d65f3b987b7f13 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -825,7 +825,7 @@ nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
struct net *net = sock_net(ctnl);
struct nfnl_log_net *log = nfnl_log_pernet(net);
int ret = 0;
- u16 flags;
+ u16 flags = 0; /* GCC uninitialized */

if (nfula[NFULA_CFG_CMD]) {
u_int8_t pf = nfmsg->nfgen_family;
--
2.6.2


2015-11-06 19:07:11

by Florian Westphal

[permalink] [raw]
Subject: Re: [netfilter-core] [PATCH] net: netfilter: fix GCC uninitialized warning

Pablo Neira Ayuso <[email protected]> wrote:
> On Fri, Nov 06, 2015 at 09:48:14PM +0300, Dmitry Safonov wrote:
> > With x86_64_defconfig:
> > GCC thinks that in nfulnl_recv_config flags parameter is not inited but
> > it was under the same condition (nfula[NFULA_CFG_FLAGS] == true).
> > Suppress this warning:
> > net/netfilter/nfnetlink_log.c: In function ‘nfulnl_recv_config’:
> > net/netfilter/nfnetlink_log.c:320:14: warning: ‘flags’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> > inst->flags = flags;
> > ^
> > Signed-off-by: Dmitry Safonov <[email protected]>
> > ---
> > net/netfilter/nfnetlink_log.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
> > index 06eb48fceb42e4..d65f3b987b7f13 100644
> > --- a/net/netfilter/nfnetlink_log.c
> > +++ b/net/netfilter/nfnetlink_log.c
> > @@ -825,7 +825,7 @@ nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
> > struct net *net = sock_net(ctnl);
> > struct nfnl_log_net *log = nfnl_log_pernet(net);
> > int ret = 0;
> > - u16 flags;
> > + u16 flags = 0; /* GCC uninitialized */
>
> u16 uninitialized_var(flags); ?

I also see warnings in nfqueue:

net/netfilter/nfnetlink_queue.c:1083:11: warning: 'nfnl_ct' may be used uninitialized in this function [-Wmaybe-uninitialized]
net/netfilter/nfnetlink_queue.c:519:19: warning: 'nfnl_ct' may be used uninitialized in this function [-Wmaybe-uninitialized]

Both are false positives, but it would be nice if we could silence
these.

2015-11-06 19:02:46

by Pablo Neira Ayuso

[permalink] [raw]
Subject: Re: [PATCH] net: netfilter: fix GCC uninitialized warning

On Fri, Nov 06, 2015 at 09:48:14PM +0300, Dmitry Safonov wrote:
> With x86_64_defconfig:
> GCC thinks that in nfulnl_recv_config flags parameter is not inited but
> it was under the same condition (nfula[NFULA_CFG_FLAGS] == true).
> Suppress this warning:
> net/netfilter/nfnetlink_log.c: In function ‘nfulnl_recv_config’:
> net/netfilter/nfnetlink_log.c:320:14: warning: ‘flags’ may be used uninitialized in this function [-Wmaybe-uninitialized]
> inst->flags = flags;
> ^
> Signed-off-by: Dmitry Safonov <[email protected]>
> ---
> net/netfilter/nfnetlink_log.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
> index 06eb48fceb42e4..d65f3b987b7f13 100644
> --- a/net/netfilter/nfnetlink_log.c
> +++ b/net/netfilter/nfnetlink_log.c
> @@ -825,7 +825,7 @@ nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
> struct net *net = sock_net(ctnl);
> struct nfnl_log_net *log = nfnl_log_pernet(net);
> int ret = 0;
> - u16 flags;
> + u16 flags = 0; /* GCC uninitialized */

u16 uninitialized_var(flags); ?

> if (nfula[NFULA_CFG_CMD]) {
> u_int8_t pf = nfmsg->nfgen_family;
> --
> 2.6.2
>

2015-11-06 19:13:38

by Dmitry Safonov

[permalink] [raw]
Subject: Re: [PATCH] net: netfilter: fix GCC uninitialized warning

I thought, it was decided to use 0/NULL/whatever, than uninitialized_var()?
Is right now?
http://thread.gmane.org/gmane.linux.kernel/1383415

2015-11-06 22:10 GMT+03:00 Pablo Neira Ayuso <[email protected]>:
> On Fri, Nov 06, 2015 at 09:48:14PM +0300, Dmitry Safonov wrote:
>> With x86_64_defconfig:
>> GCC thinks that in nfulnl_recv_config flags parameter is not inited but
>> it was under the same condition (nfula[NFULA_CFG_FLAGS] == true).
>> Suppress this warning:
>> net/netfilter/nfnetlink_log.c: In function ‘nfulnl_recv_config’:
>> net/netfilter/nfnetlink_log.c:320:14: warning: ‘flags’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>> inst->flags = flags;
>> ^
>> Signed-off-by: Dmitry Safonov <[email protected]>
>> ---
>> net/netfilter/nfnetlink_log.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
>> index 06eb48fceb42e4..d65f3b987b7f13 100644
>> --- a/net/netfilter/nfnetlink_log.c
>> +++ b/net/netfilter/nfnetlink_log.c
>> @@ -825,7 +825,7 @@ nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
>> struct net *net = sock_net(ctnl);
>> struct nfnl_log_net *log = nfnl_log_pernet(net);
>> int ret = 0;
>> - u16 flags;
>> + u16 flags = 0; /* GCC uninitialized */
>
> u16 uninitialized_var(flags); ?
>
>> if (nfula[NFULA_CFG_CMD]) {
>> u_int8_t pf = nfmsg->nfgen_family;
>> --
>> 2.6.2
>>

2015-11-06 19:35:00

by Dmitry Safonov

[permalink] [raw]
Subject: [PATCH] net: netfilter: fix false positive GCC warnings

With x86_64_defconfig:
GCC thinks that in nfulnl_recv_config flags parameter is not inited but
it was under the same condition (nfula[NFULA_CFG_FLAGS] == true).
Suppress this warning:
net/netfilter/nfnetlink_log.c: In function ‘nfulnl_recv_config’:
net/netfilter/nfnetlink_log.c:320:14: warning: ‘flags’ may be used uninitialized in this function [-Wmaybe-uninitialized]
inst->flags = flags;
^
GCC thinks that nfnl_ct wasn't inited, but it is used only under
if (ct && diff)
where ct is not NULL only when nfnl_ct is inited.

Reported-by: Florian Westphal <[email protected]>
Signed-off-by: Dmitry Safonov <[email protected]>
---
net/netfilter/nfnetlink_log.c | 2 +-
net/netfilter/nfnetlink_queue.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index 06eb48fceb42e4..23f16b99e6388a 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -825,7 +825,7 @@ nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
struct net *net = sock_net(ctnl);
struct nfnl_log_net *log = nfnl_log_pernet(net);
int ret = 0;
- u16 flags;
+ u16 uninitialized_var(flags);

if (nfula[NFULA_CFG_CMD]) {
u_int8_t pf = nfmsg->nfgen_family;
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index 7d81d280cb4ff3..66b006112921ca 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -313,7 +313,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
struct net_device *outdev;
struct nf_conn *ct = NULL;
enum ip_conntrack_info uninitialized_var(ctinfo);
- struct nfnl_ct_hook *nfnl_ct;
+ struct nfnl_ct_hook *uninitialized_var(nfnl_ct);
bool csum_verify;
char *secdata = NULL;
u32 seclen = 0;
@@ -1041,7 +1041,7 @@ nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb,
unsigned int verdict;
struct nf_queue_entry *entry;
enum ip_conntrack_info uninitialized_var(ctinfo);
- struct nfnl_ct_hook *nfnl_ct;
+ struct nfnl_ct_hook *uninitialized_var(nfnl_ct);
struct nf_conn *ct = NULL;

struct net *net = sock_net(ctnl);
--
2.6.2

2015-11-10 12:46:01

by Pablo Neira Ayuso

[permalink] [raw]
Subject: Re: [PATCH] net: netfilter: fix GCC uninitialized warning

On Fri, Nov 06, 2015 at 10:13:16PM +0300, Dmitry Safonov wrote:
> I thought, it was decided to use 0/NULL/whatever, than uninitialized_var()?
> Is right now?
> http://thread.gmane.org/gmane.linux.kernel/1383415

I overlook that one. We should stick to mainstream policies as much as
possible.

Arnd just sent a patch to address one of this by initializing the
variable: http://patchwork.ozlabs.org/patch/542259/

Please follow up with a patch to initialize the variable to avoid the
warning in other spots.

Thanks.