From patchwork Fri Sep 30 16:17:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 101722 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp379028qgf; Fri, 30 Sep 2016 09:18:15 -0700 (PDT) X-Received: by 10.98.41.131 with SMTP id p125mr13284395pfp.108.1475252295308; Fri, 30 Sep 2016 09:18:15 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8si20661357paz.216.2016.09.30.09.18.15; Fri, 30 Sep 2016 09:18:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934174AbcI3QSF (ORCPT + 4 others); Fri, 30 Sep 2016 12:18:05 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:56240 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933082AbcI3QSA (ORCPT ); Fri, 30 Sep 2016 12:18:00 -0400 Received: from wuerfel.lan. ([78.43.20.153]) by mrelayeu.kundenserver.de (mreue102) with ESMTPA (Nemesis) id 0MZUYX-1bVSzF1Yz7-00LHUL; Fri, 30 Sep 2016 18:17:52 +0200 From: Arnd Bergmann To: Jiri Pirko , Ido Schimmel Cc: Arnd Bergmann , "David S. Miller" , Yotam Gigi , Nogah Frankel , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage Date: Fri, 30 Sep 2016 18:17:10 +0200 Message-Id: <20160930161734.70928-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160930161734.70928-1-arnd@arndb.de> References: <20160930161734.70928-1-arnd@arndb.de> X-Provags-ID: V03:K0:fsg1HtqsQxpqRN8nXjTawOxa5rJrOLgeeyJuvE1NH0mj5gWHtb+ ONVmwNwATuY3CQfi8prE5Pfa6prmTvL/SStlcibMIxmfCf1tGVTIPo1dBJ3G6YYB3kLUpY/ 01g8sM9Dt2mJ4VmA+A3RvVN5n6l7TdpVe0QPnYbFQ/N3xrdU9m83N2ihwya0UwZhWa3flec gfNu4egqP5UcUqkGmW6BQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:hsvL8TpVDLo=:4KT7CPKJUah7WGIZhRqPaA t6SXw44kfPgEEfFO7NbhIysd4CFvmvjiIvFsHyQBnokNZMj058lknrucGOR6r+3KoKidlnZQc YjIWSOWfydCUeXNV1g00aTDoDBc4CPHwJXP1/DZYqmdp+/cDYhR9421OVVlUSM09L2PAbSf6d S1aFhX0YaiaA1T3xVvOou4wDMSe5ydR9wQCdZKV+Q05Cxor+1DvrUQd4WvGZw3xwECOzDR6Xj 0ALyN4k/kfvsUB9pwq1WEs3w4DaVk4RqqISnKIsVpowNCSZpzWHW6DFvPBO3atkJStQNIGktU XDMpcFeMbouXddenvkkHZQbbSz2ND3KrLOLGhfQWRxrJqFomdSH/aPGiQDjYJUjBXdVjafMc/ sBk75dFWfxUIpcQnlXmq2q8+wc9tPwUaUji+N65bYI1Euv/s69S1IsLvMwF5bOLp7ObTdj5pw 5L0PPVCivEUI/to35ZuJ4Nu0nixCytSeXlcjSG365x/m2YZ4jZJ6xmWHsG594rEe9UrxrRJfD mWgDnBPZB1nnIXrkGrdTTv+YEG2Dt+gZFQXS55j0uind1TdLNu08nRCJDkGzNP6H0IZdCM3Nf OeQrgQpCjl8BEarZLau8Xf6CKMWuumOOI176X4Ig3XZEH0XT5Yt8c3Ab1J6muUpfviHBslD8P 4WjFsAHfgaRwEsjQPkd9C7i0UcyOjC9bpvti4JrucKqZQpbCjofeEp1JCI1CHOJ+aY8c= Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If fi->fib_nhs is zero, the router interface pointer is uninitialized, as shown by this warning: drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c: In function 'mlxsw_sp_router_fib_event': drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:1674:21: error: 'r' may be used uninitialized in this function [-Werror=maybe-uninitialized] drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:1643:23: note: 'r' was declared here This changes the loop so we handle the case the same way as finding no router interface pointer attached to one of the nexthops to ensure we always trap here instead of using uninitialized data. Fixes: b45f64d16d45 ("mlxsw: spectrum_router: Use FIB notifications instead of switchdev calls") Signed-off-by: Arnd Bergmann --- drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) -- 2.9.0 diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index 48d50efec5e2..78fc557d6dd7 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -1640,7 +1640,7 @@ mlxsw_sp_router_fib4_entry_init(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fib_entry *fib_entry) { struct fib_info *fi = fen_info->fi; - struct mlxsw_sp_rif *r; + struct mlxsw_sp_rif *r = NULL; int nhsel; int err; @@ -1664,11 +1664,15 @@ mlxsw_sp_router_fib4_entry_init(struct mlxsw_sp *mlxsw_sp, * to us. Set trap and pass the packets for * this prefix to kernel. */ - fib_entry->type = MLXSW_SP_FIB_ENTRY_TYPE_TRAP; - return 0; + break; } } + if (!r) { + fib_entry->type = MLXSW_SP_FIB_ENTRY_TYPE_TRAP; + return 0; + } + if (fi->fib_scope != RT_SCOPE_UNIVERSE) { fib_entry->type = MLXSW_SP_FIB_ENTRY_TYPE_LOCAL; fib_entry->rif = r->rif;