Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941220AbcJXPfu (ORCPT ); Mon, 24 Oct 2016 11:35:50 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:53271 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S938862AbcJXPfm (ORCPT ); Mon, 24 Oct 2016 11:35:42 -0400 From: Arnd Bergmann To: Wensong Zhang , Simon Horman , Julian Anastasov Cc: Arnd Bergmann , Pablo Neira Ayuso , Patrick McHardy , Jozsef Kadlecsik , "David S. Miller" , Quentin Armitage , netdev@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-kernel@vger.kernel.org Subject: [PATCH] netfilter: ip_vs_sync: fix bogus maybe-uninitialized warning Date: Mon, 24 Oct 2016 17:34:32 +0200 Message-Id: <20161024153454.2766113-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:chT7W5IJAYAM6H4BH0Psf8UkFQSadkllF+pNEIFmHtSBf/X+5KT iTb5+BEJUuIfuZuoUUnslQkyF1GFGiqgs54P5d5VnzBlEeJqcKbymZdLzKMNb4FIeQeARqF jEylyCzbvxy+J1T9NOuw7AugSG2wOHbDTySR+SA8mC5FwSvDZNJwX5LmrEsp0YtMAtGI9Oo BvBzz/NfeExTRnTcZfxZQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:QcS3OLPjG+Y=:cBbgfMOzLVJbjGq7PS/EWb +DYhRN1CnwYBPgor8cMdOa2StZ0kwuSvlMPp0L5UT1A2WsF8d+wH2xO52TKeEKyjz1uUMusK7 29j0PyyFsvcKqAQVxQ1HKX6R/AniS5bK+Nt+z7q9ioTWgz5WgbMR3kuof9jyCX8956MAnHuy8 eK8mxGs/xDfy0ETbLPzufk2X4IJWamljZDkrqRvu2l2xTp1+dz20nigssBrlTp/dRzdX0gVt5 YgeMwrcN6e6DK5Lg6shxPOvPZLzcXp4Ts/XcWL4iVh9wtkadWNemKFkCHomjwDzQ2CQPEPGaS NjUzfBb3xAHTydq106vV/hALver7p9vCBnYb7spB0v4TvgccEbY9OO7VljF+mYByGB4XEgGxo NMnXoGx6r2xePoM9l0GfOa4QnOmwr/52SXszFmW6qZIXNle/Kn0Y0+f6+Jav0DBC8GIxpwmxV HIWjZ4hqYpixU0FAVwRz4EDiNRnx3wVVvWtmjB9Ksrrtm92FXchbooo3FKOsPGOWiYNdcCAZU q6aninPKFkStAy9eCw5kE626P646nH5qOCov9e04ISjaTi0K6URv3ILyicXbejA3x6IcQRQVB 7GNdyJ5Zu8jlLqM0NAM0+XCaUykLxrjoCEopYtoG6Gqh8tWdRjSY+EAQfy0TRJwyowdE4t2oE 4HXfH4p6PEUJWdzViXAWS/YpHebCepL1n7IkqlfJwSyOXiVcvPjeuw5c+NUf30xuOPIP3arWD 86opJtL2sOSZl4k2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3217 Lines: 64 Building the ip_vs_sync code with CONFIG_OPTIMIZE_INLINING on x86 confuses the compiler to the point where it produces a rather dubious warning message: net/netfilter/ipvs/ip_vs_sync.c:1073:33: error: ‘opt.init_seq’ may be used uninitialized in this function [-Werror=maybe-uninitialized] struct ip_vs_sync_conn_options opt; ^~~ net/netfilter/ipvs/ip_vs_sync.c:1073:33: error: ‘opt.delta’ may be used uninitialized in this function [-Werror=maybe-uninitialized] net/netfilter/ipvs/ip_vs_sync.c:1073:33: error: ‘opt.previous_delta’ may be used uninitialized in this function [-Werror=maybe-uninitialized] net/netfilter/ipvs/ip_vs_sync.c:1073:33: error: ‘*((void *)&opt+12).init_seq’ may be used uninitialized in this function [-Werror=maybe-uninitialized] net/netfilter/ipvs/ip_vs_sync.c:1073:33: error: ‘*((void *)&opt+12).delta’ may be used uninitialized in this function [-Werror=maybe-uninitialized] net/netfilter/ipvs/ip_vs_sync.c:1073:33: error: ‘*((void *)&opt+12).previous_delta’ may be used uninitialized in this function [-Werror=maybe-uninitialized] The problem appears to be a combination of a number of factors, including the __builtin_bswap32 compiler builtin being slightly odd, having a large amount of code inlined into a single function, and the way that some functions only get partially inlined here. I've spent way too much time trying to work out a way to improve the code, but the best I've come up with is to add an explicit memset right before the ip_vs_seq structure is first initialized here. When the compiler works correctly, this has absolutely no effect, but in the case that produces the warning, the warning disappears. In the process of analysing this warning, I also noticed that we use memcpy to copy the larger ip_vs_sync_conn_options structure over two members of the ip_vs_conn structure. This works because the layout is identical, but seems error-prone, so I'm changing this in the process to directly copy the two members. This change seemed to have no effect on the object code or the warning, but it deals with the same data, so I kept the two changes together. Signed-off-by: Arnd Bergmann --- net/netfilter/ipvs/ip_vs_sync.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c index 1b07578bedf3..9350530c16c1 100644 --- a/net/netfilter/ipvs/ip_vs_sync.c +++ b/net/netfilter/ipvs/ip_vs_sync.c @@ -283,6 +283,7 @@ struct ip_vs_sync_buff { */ static void ntoh_seq(struct ip_vs_seq *no, struct ip_vs_seq *ho) { + memset(ho, 0, sizeof(*ho)); ho->init_seq = get_unaligned_be32(&no->init_seq); ho->delta = get_unaligned_be32(&no->delta); ho->previous_delta = get_unaligned_be32(&no->previous_delta); @@ -917,8 +918,10 @@ static void ip_vs_proc_conn(struct netns_ipvs *ipvs, struct ip_vs_conn_param *pa kfree(param->pe_data); } - if (opt) - memcpy(&cp->in_seq, opt, sizeof(*opt)); + if (opt) { + cp->in_seq = opt->in_seq; + cp->out_seq = opt->out_seq; + } atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs)); cp->state = state; cp->old_state = cp->state; -- 2.9.0