Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1494181 > unrolled thread

[PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage

Started byArnd Bergmann <arnd@arndb.de>
First post2016-09-30 18:20 +0200
Last post2016-10-03 08:00 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage Arnd Bergmann <arnd@arndb.de> - 2016-09-30 18:20 +0200
    Re: [PATCH 2/2] mlxsw: spectrum_router: avoid potential  uninitialized data usage Ido Schimmel <idosch@idosch.org> - 2016-09-30 20:10 +0200
      Re: [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage Arnd Bergmann <arnd@arndb.de> - 2016-10-01 05:50 +0200
    Re: [PATCH 2/2] mlxsw: spectrum_router: avoid potential  uninitialized data usage David Miller <davem@davemloft.net> - 2016-10-03 08:00 +0200

#1494181 — [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage

FromArnd Bergmann <arnd@arndb.de>
Date2016-09-30 18:20 +0200
Subject[PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage
Message-ID<sn8Hv-4bK-1@gated-at.bofh.it>
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 <arnd@arndb.de>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

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;
-- 
2.9.0

[toc] | [next] | [standalone]


#1494228 — Re: [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage

FromIdo Schimmel <idosch@idosch.org>
Date2016-09-30 20:10 +0200
SubjectRe: [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage
Message-ID<snapX-5oq-15@gated-at.bofh.it>
In reply to#1494181
On Fri, Sep 30, 2016 at 06:17:10PM +0200, Arnd Bergmann wrote:
> 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 <arnd@arndb.de>

For net-next:
Acked-by: Ido Schimmel <idosch@mellanox.com>

BTW, which flags did you pass to generate this error? I can only
reproduce this with EXTRA_CFLAGS="-Wmaybe-uninitialized -Werror", but
for some reason EXTRA_CFLAGS="-Wall -Werror" is silent. Any idea why? I
would like to add this to my git hooks and avoid these errors in the
future :)

Thanks!

[toc] | [prev] | [next] | [standalone]


#1494346

FromArnd Bergmann <arnd@arndb.de>
Date2016-10-01 05:50 +0200
Message-ID<snjtf-2OO-5@gated-at.bofh.it>
In reply to#1494228
On Friday 30 September 2016, Ido Schimmel wrote:
> BTW, which flags did you pass to generate this error? I can only
> reproduce this with EXTRA_CFLAGS="-Wmaybe-uninitialized -Werror", but
> for some reason EXTRA_CFLAGS="-Wall -Werror" is silent. Any idea why? I
> would like to add this to my git hooks and avoid these errors in the
> future :)

Linus disabled the warning for v4.8. I've just talked to him today about this
warning in particular, and hope that we can find a way to enable it by
default again in the future, as a lot of possible bugs get introduced,
but certain compiler versions also produce a lot of false positives.

	Arnd

[toc] | [prev] | [next] | [standalone]


#1494708 — Re: [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage

FromDavid Miller <davem@davemloft.net>
Date2016-10-03 08:00 +0200
SubjectRe: [PATCH 2/2] mlxsw: spectrum_router: avoid potential uninitialized data usage
Message-ID<so4sa-8tW-9@gated-at.bofh.it>
In reply to#1494181
From: Arnd Bergmann <arnd@arndb.de>
Date: Fri, 30 Sep 2016 18:17:10 +0200

> 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 <arnd@arndb.de>

Applied.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web