From patchwork Fri Jul 28 14:41:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 794938 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xJs4t4K7Nz9s3T for ; Sat, 29 Jul 2017 00:42:22 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752307AbdG1OmJ (ORCPT ); Fri, 28 Jul 2017 10:42:09 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:54583 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752293AbdG1OmH (ORCPT ); Fri, 28 Jul 2017 10:42:07 -0400 Received: from wuerfel.lan ([78.43.238.10]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0LqlM2-1e5Vb01P50-00eJJx; Fri, 28 Jul 2017 16:42:00 +0200 From: Arnd Bergmann To: "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI Cc: Arnd Bergmann , Eric Dumazet , Neal Cardwell , Soheil Hassas Yeganeh , Yuchung Cheng , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net] tcp: avoid bogus gcc-7 array-bounds warning Date: Fri, 28 Jul 2017 16:41:37 +0200 Message-Id: <20170728144153.2024234-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:p157YBd5d9GGu6FRtFiBEe7njzi6nKVwxZqCHnXrRKDuJ1Zyxoi n6HAKTM/aTTxEeFaUc5BTORVvbCJG/XDtmgFAsnOS2vyOt3juIOF/zdC75f89BJEchpS0F0 LvmpBjQBSPSbDCnruFJyOBjqbP+JLVmAP5WfcC8sf2vNI+xuDbfyplA1MstXJXxEx2CfQzu 5ZTbrKt2phsLx08N9Habg== X-UI-Out-Filterresults: notjunk:1; V01:K0:6ATtzHifcDs=:dPazSb9wdXm2PFFAiahZYu CmKKLf1SWjbTbd9FmYsAyzbc17hyLtJP2Xqwc1CX8mZhnlZ9728BIQgnfVhtjwXu5mHKqnLAu lRk75AJxbICqgoWjk+UUOeAGPrATxtDD5fd7RMRYsY2EelSdqLIKqS4aMn+y+/4B2sYzrs8na QVriPRlM0c3ws7B392G/Ao61DxNf7Vp7S0EfCnVyX6P0d/d/gMwhSHPO9CIpLGMlR9YFoKMiJ EG5YEgwE1BfMxG8MqgoPtLucOHUh3GpHaTDwu8cPEZs1ys0TE8D3VrkDgF0aPHQnyPEqB+Szv GfNu/zA2WrZ/gqZpVetUFHhLxvEV7DHPhOLasRhtijMX/g2irw5Rh+1YtxPTrbQG+eN2SrY5S 2nCZAqYNF3Ql7KtnCIANbe9M3Vmn8sT1tCi5B2JeyHSXez+TFwbJchSJf6Vxcs3vrAHGSl/rD D+SwPKf5ZVMZH7w+RV9J2Lx7bf36F+x6Mrv7k6mvcWuQImqeE2Qs5LxU1LuOlyMzKWd4w3aE6 MOHcsZR9gLm7On1iAVe8Amj+LXSo0us8Ngv29uefwR+mgT6xagHtozagRw9VYe3kV9iC0v26U kOP/PSZR3HV0op3R7ld5mzIE/YPDVfAruEmY2cspI+tT5sAc0G2LL4/1n1C9wwnvgQYtpEf+z 2mzV53ngLBAjf0HrIDfFzKeG/gmzfGetAFDKJDAgXaz27ykprz70Uh/Ao5rE5Kkz4EvKuvk8E sNQ87ipWfSRlDv7b1AfR8PhVkg1NcjmDxSHzuA== Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When using CONFIG_UBSAN_SANITIZE_ALL, the TCP code produces a false-positive warning: net/ipv4/tcp_output.c: In function 'tcp_connect': net/ipv4/tcp_output.c:2207:40: error: array subscript is below array bounds [-Werror=array-bounds] tp->chrono_stat[tp->chrono_type - 1] += now - tp->chrono_start; ^~ net/ipv4/tcp_output.c:2207:40: error: array subscript is below array bounds [-Werror=array-bounds] tp->chrono_stat[tp->chrono_type - 1] += now - tp->chrono_start; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ I have opened a gcc bug for this, but distros have already shipped compilers with this problem, and it's not clear yet whether there is a way for gcc to avoid the warning. As the problem is related to the bitfield access, this introduces a temporary variable to store the old enum value. I did not notice this warning earlier, since UBSAN is disabled when building with COMPILE_TEST, and that was always turned on in both allmodconfig and randconfig tests. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81601 Signed-off-by: Arnd Bergmann --- net/ipv4/tcp_output.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 886d874775df..bb901297a369 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -2202,9 +2202,10 @@ static bool tcp_small_queue_check(struct sock *sk, const struct sk_buff *skb, static void tcp_chrono_set(struct tcp_sock *tp, const enum tcp_chrono new) { const u32 now = tcp_jiffies32; + enum tcp_chrono old = tp->chrono_type; - if (tp->chrono_type > TCP_CHRONO_UNSPEC) - tp->chrono_stat[tp->chrono_type - 1] += now - tp->chrono_start; + if (old > TCP_CHRONO_UNSPEC) + tp->chrono_stat[old - 1] += now - tp->chrono_start; tp->chrono_start = now; tp->chrono_type = new; }