net/mlx5e: Handle FIB events to update tunnel endpoint device
Subsystems (3)
Hello Vlad Buslov,
The patch 8914add2c9e5: "net/mlx5e: Handle FIB events to update tunnel endpoint device" from Jan 25, 2021, leads to the following static checker warning:
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:1639 mlx5e_tc_tun_init() error: passing non negative 1 to ERR_PTR
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
1622 struct mlx5e_tc_tun_encap *mlx5e_tc_tun_init(struct mlx5e_priv *priv) 1623 {
1624 struct mlx5e_tc_tun_encap *encap;
1625 int err;
1626
1627 encap = kvzalloc(sizeof(*encap), GFP_KERNEL);
1628 if (!encap)
1629 return ERR_PTR(-ENOMEM);
1630
1631 encap->priv = priv; 1632 encap->fib_nb.notifier_call = mlx5e_tc_tun_fib_event; 1633 spin_lock_init(&encap->route_lock); 1634 hash_init(encap->route_tbl); 1635 err = register_fib_notifier(dev_net(priv->netdev), &encap->fib_nb,
1636 NULL, NULL);
register_fib_notifier() calls fib_net_dump() which eventually calls fib6_walk_continue() which can return 1 if "walk is incomplete (i.e. suspended)".
1637 if (err) {
1638 kvfree(encap);
1639 return ERR_PTR(err);If this returns 1 it will eventually lead to an Oops.
1640 }
1641
1642 return encap;
1643 }
regards,
dan carpenter
Quoted 30 lines · Dan Carpenter
Hello Vlad Buslov,
The patch
8914add2c9e5: "net/mlx5e: Handle FIB events to update tunnel endpoint device" from Jan 25, 2021, leads to the following static checker warning:drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:1639 mlx5e_tc_tun_init() error: passing non negative 1 to ERR_PTR
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
1622 structmlx5e_tc_tun_encap*mlx5e_tc_tun_init(structmlx5e_priv*priv) 1623 {
1624 structmlx5e_tc_tun_encap*encap;
1625 int err;
1626
1627 encap =kvzalloc(sizeof(*encap), GFP_KERNEL);
1628 if (!encap)
1629 returnERR_PTR(-ENOMEM);
16301631 encap->priv = priv; 1632 encap->fib_nb.notifier_call = mlx5e_tc_tun_fib_event; 1633 spin_lock_init(&encap->route_lock); 1634 hash_init(encap->route_tbl); 1635 err = register_fib_notifier(dev_net(priv->netdev), &encap->fib_nb,1636 NULL, NULL);
register_fib_notifier()callsfib_net_dump()which eventually callsfib6_walk_continue()which can return 1 if "walk is incomplete (i.e. suspended)".
Quoted 5 lines
1637 if (err) { 1638 kvfree(encap); 1639 return ERR_PTR(err);If this returns 1 it will eventually lead to an Oops.
Hi Dan,
Thanks for the bug report!
This looks a bit strange to me because none of the other users of this API handle positive error code in any special way (including reference netdevsim implementation). Maybe API itself should be fixed? Jiri, Ido, what do you think?
Regards,
Vlad
Quoted 8 lines
1640 }
1641
1642 return encap;
1643 }regards,
dan carpenter
Quoted 37 lines · Vlad Buslov
Quoted 30 lines · Dan Carpenter
Hello Vlad Buslov,
The patch
8914add2c9e5: "net/mlx5e: Handle FIB events to update tunnel endpoint device" from Jan 25, 2021, leads to the following static checker warning:drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:1639 mlx5e_tc_tun_init() error: passing non negative 1 to ERR_PTR
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
1622 structmlx5e_tc_tun_encap*mlx5e_tc_tun_init(structmlx5e_priv*priv) 1623 {
1624 structmlx5e_tc_tun_encap*encap;
1625 int err;
1626
1627 encap =kvzalloc(sizeof(*encap), GFP_KERNEL);
1628 if (!encap)
1629 returnERR_PTR(-ENOMEM);
16301631 encap->priv = priv; 1632 encap->fib_nb.notifier_call = mlx5e_tc_tun_fib_event; 1633 spin_lock_init(&encap->route_lock); 1634 hash_init(encap->route_tbl); 1635 err = register_fib_notifier(dev_net(priv->netdev), &encap->fib_nb,1636 NULL, NULL);
register_fib_notifier()callsfib_net_dump()which eventually callsfib6_walk_continue()which can return 1 if "walk is incomplete (i.e. suspended)".Quoted 5 lines
1637 if (err) { 1638 kvfree(encap); 1639 return ERR_PTR(err);If this returns 1 it will eventually lead to an Oops.
Quoted 8 lines
Hi Dan,
Thanks for the bug report!
This looks a bit strange to me because none of the other users of this API handle positive error code in any special way (including reference netdevsim implementation). Maybe API itself should be fixed? Jiri, Ido, what do you think?
The other functions that call register_fib_notifier() return an int, but mlx5e_tc_tun_init() returns a pointer. I think that's why it was
flagged: "error: passing non negative 1 to ERR_PTR".
fib6_walk_continue() cannot return a positive value when called from register_fib_notifier(), but ignoring it means that you will keep getting the same static analysis error. What about:
net/ipv6/ip6_fib.c +3 -2
@@ -499,7 +499,7 @@ int fib6_tables_dump(struct net *net, struct notifier_block *nb,hlist_for_each_entry_rcu (tb, head, tb6_hlist) { err =fib6_table_dump (net, tb, w); -if (err <0 ) +if (err) goto out; } }
@@ -507,7 +507,8 @@ int fib6_tables_dump(struct net *net, struct notifier_block *nb, out:kfree (w); -return err; +/* The tree traversal function should never return a positive value. */ +return err >0 ? -EINVAL : err; }static int fib6_dump_node (struct fib6_walker *w)
Quoted 13 lines
Regards,
VladQuoted 8 lines
1640 }
1641
1642 return encap;
1643 }regards,
dan carpenter
Quoted 42 lines · Ido Schimmel
Quoted 41 lines · Vlad Buslov
Quoted 30 lines · Dan Carpenter
Hello Vlad Buslov,
The patch
8914add2c9e5: "net/mlx5e: Handle FIB events to update tunnel endpoint device" from Jan 25, 2021, leads to the following static checker warning:drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:1639 mlx5e_tc_tun_init() error: passing non negative 1 to ERR_PTR
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
1622 structmlx5e_tc_tun_encap*mlx5e_tc_tun_init(structmlx5e_priv*priv) 1623 {
1624 structmlx5e_tc_tun_encap*encap;
1625 int err;
1626
1627 encap =kvzalloc(sizeof(*encap), GFP_KERNEL);
1628 if (!encap)
1629 returnERR_PTR(-ENOMEM);
16301631 encap->priv = priv; 1632 encap->fib_nb.notifier_call = mlx5e_tc_tun_fib_event; 1633 spin_lock_init(&encap->route_lock); 1634 hash_init(encap->route_tbl); 1635 err = register_fib_notifier(dev_net(priv->netdev), &encap->fib_nb,1636 NULL, NULL);
register_fib_notifier()callsfib_net_dump()which eventually callsfib6_walk_continue()which can return 1 if "walk is incomplete (i.e. suspended)".Quoted 5 lines
1637 if (err) { 1638 kvfree(encap); 1639 return ERR_PTR(err);If this returns 1 it will eventually lead to an Oops.
Hi Dan,
Thanks for the bug report!
Quoted 8 lines
Quoted 4 lines
This looks a bit strange to me because none of the other users of this API handle positive error code in any special way (including reference netdevsim implementation). Maybe API itself should be fixed? Jiri, Ido, what do you think?
The other functions that call
register_fib_notifier()return an int, butmlx5e_tc_tun_init()returns a pointer. I think that's why it was
flagged: "error: passing non negative 1 toERR_PTR".
Actually, some of them do. I mentioned netdevsim specifically because nsim_fib_create() returns pointer and also casts return value of register_fib_notifier() with ERR_PTR.
Quoted 20 lines
fib6_walk_continue()cannot return a positive value when called fromregister_fib_notifier(), but ignoring it means that you will keep getting the same static analysis error. What about:net/ipv6/ip6_fib.c +1
-1@@ -499,7 +499,7 @@ int fib6_tables_dump(struct net *net, struct notifier_block *nb,hlist_for_each_entry_rcu (tb, head, tb6_hlist) { err =fib6_table_dump (net, tb, w); -if (err <0 ) +if (err) goto out; } }
net/ipv6/ip6_fib.c int fib6_tables_dump(struct net *net, struct notifier_block *nb, · line 514
Quoted 9 lines
net/ipv6/ip6_fib.c +2
-1@@ -507,7 +507,8 @@ int fib6_tables_dump(struct net *net, struct notifier_block *nb, out:kfree (w); -return err; +/* The tree traversal function should never return a positive value. */ +return err >0 ? -EINVAL : err; }static int fib6_dump_node (struct fib6_walker *w)
Makes sense. You want me to send the fix or you will do it?
Quoted 13 lines
Quoted 13 lines
Regards,
VladQuoted 8 lines
1640 }
1641
1642 return encap;
1643 }regards,
dan carpenter
Quoted 84 lines · Vlad Buslov
Quoted 42 lines · Ido Schimmel
Quoted 41 lines · Vlad Buslov
Quoted 30 lines · Dan Carpenter
Hello Vlad Buslov,
The patch
8914add2c9e5: "net/mlx5e: Handle FIB events to update tunnel endpoint device" from Jan 25, 2021, leads to the following static checker warning:drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:1639 mlx5e_tc_tun_init() error: passing non negative 1 to ERR_PTR
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
1622 structmlx5e_tc_tun_encap*mlx5e_tc_tun_init(structmlx5e_priv*priv) 1623 {
1624 structmlx5e_tc_tun_encap*encap;
1625 int err;
1626
1627 encap =kvzalloc(sizeof(*encap), GFP_KERNEL);
1628 if (!encap)
1629 returnERR_PTR(-ENOMEM);
16301631 encap->priv = priv; 1632 encap->fib_nb.notifier_call = mlx5e_tc_tun_fib_event; 1633 spin_lock_init(&encap->route_lock); 1634 hash_init(encap->route_tbl); 1635 err = register_fib_notifier(dev_net(priv->netdev), &encap->fib_nb,1636 NULL, NULL);
register_fib_notifier()callsfib_net_dump()which eventually callsfib6_walk_continue()which can return 1 if "walk is incomplete (i.e. suspended)".Quoted 5 lines
1637 if (err) { 1638 kvfree(encap); 1639 return ERR_PTR(err);If this returns 1 it will eventually lead to an Oops.
Hi Dan,
Thanks for the bug report!
Quoted 8 lines
Quoted 4 lines
This looks a bit strange to me because none of the other users of this API handle positive error code in any special way (including reference netdevsim implementation). Maybe API itself should be fixed? Jiri, Ido, what do you think?
The other functions that call
register_fib_notifier()return an int, butmlx5e_tc_tun_init()returns a pointer. I think that's why it was
flagged: "error: passing non negative 1 toERR_PTR".Actually, some of them do. I mentioned netdevsim specifically because
nsim_fib_create()returns pointer and also casts return value ofregister_fib_notifier()withERR_PTR.Quoted 27 lines
fib6_walk_continue()cannot return a positive value when called fromregister_fib_notifier(), but ignoring it means that you will keep getting the same static analysis error. What about:net/ipv6/ip6_fib.c +3
-2@@ -499,7 +499,7 @@ int fib6_tables_dump(struct net *net, struct notifier_block *nb,hlist_for_each_entry_rcu (tb, head, tb6_hlist) { err =fib6_table_dump (net, tb, w); -if (err <0 ) +if (err) goto out; } }@@ -507,7 +507,8 @@ int fib6_tables_dump(struct net *net, struct notifier_block *nb, out:kfree (w); -return err; +/* The tree traversal function should never return a positive value. */ +return err >0 ? -EINVAL : err; }
Quoted 4 lines
net/ipv6/ip6_fib.c int fib6_tables_dump(struct net *net, struct notifier_block *nb, · line 514
Quoted 2 lines
net/ipv6/ip6_fib.c +0
-0static int fib6_dump_node (struct fib6_walker *w)Makes sense. You want me to send the fix or you will do it?
Can you send to linux-internal and then I will apply it to our regression and let you know tomorrow morning?
Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
Regards,
VladQuoted 8 lines
1640 }
1641
1642 return encap;
1643 }regards,
dan carpenter
Quoted 49 lines · Vlad Buslov
Quoted 47 lines · Ido Schimmel
Quoted 45 lines · Vlad Buslov
Quoted 30 lines · Dan Carpenter
Hello Vlad Buslov,
The patch
8914add2c9e5: "net/mlx5e: Handle FIB events to update tunnel endpoint device" from Jan 25, 2021, leads to the following static checker warning:drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:1639 mlx5e_tc_tun_init() error: passing non negative 1 to ERR_PTR
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
1622 structmlx5e_tc_tun_encap*mlx5e_tc_tun_init(structmlx5e_priv*priv) 1623 {
1624 structmlx5e_tc_tun_encap*encap;
1625 int err;
1626
1627 encap =kvzalloc(sizeof(*encap), GFP_KERNEL);
1628 if (!encap)
1629 returnERR_PTR(-ENOMEM);
16301631 encap->priv = priv; 1632 encap->fib_nb.notifier_call = mlx5e_tc_tun_fib_event; 1633 spin_lock_init(&encap->route_lock); 1634 hash_init(encap->route_tbl); 1635 err = register_fib_notifier(dev_net(priv->netdev), &encap->fib_nb,1636 NULL, NULL);
register_fib_notifier()callsfib_net_dump()which eventually callsfib6_walk_continue()which can return 1 if "walk is incomplete (i.e. suspended)".Quoted 5 lines
1637 if (err) { 1638 kvfree(encap); 1639 return ERR_PTR(err);If this returns 1 it will eventually lead to an Oops.
Hi Dan,
Thanks for the bug report!
This looks a bit strange to me because none of the other users of this API handle positive error code in any special way (including reference netdevsim implementation). Maybe API itself should be fixed? Jiri, Ido, what do you think?
Quoted 8 lines
Quoted 3 lines
The other functions that call
register_fib_notifier()return an int, butmlx5e_tc_tun_init()returns a pointer. I think that's why it was
flagged: "error: passing non negative 1 toERR_PTR".Actually, some of them do. I mentioned netdevsim specifically because
nsim_fib_create()returns pointer and also casts return value ofregister_fib_notifier()withERR_PTR.
Huh. Smatch prints a warning for nsim_fib_create() but I never forwarded the warning to anyone apparently.
regards,
dan carpenter
Quoted 47 lines · Ido Schimmel
Quoted 37 lines · Vlad Buslov
Quoted 30 lines · Dan Carpenter
Hello Vlad Buslov,
The patch
8914add2c9e5: "net/mlx5e: Handle FIB events to update tunnel endpoint device" from Jan 25, 2021, leads to the following static checker warning:drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:1639 mlx5e_tc_tun_init() error: passing non negative 1 to ERR_PTR
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
1622 structmlx5e_tc_tun_encap*mlx5e_tc_tun_init(structmlx5e_priv*priv) 1623 {
1624 structmlx5e_tc_tun_encap*encap;
1625 int err;
1626
1627 encap =kvzalloc(sizeof(*encap), GFP_KERNEL);
1628 if (!encap)
1629 returnERR_PTR(-ENOMEM);
16301631 encap->priv = priv; 1632 encap->fib_nb.notifier_call = mlx5e_tc_tun_fib_event; 1633 spin_lock_init(&encap->route_lock); 1634 hash_init(encap->route_tbl); 1635 err = register_fib_notifier(dev_net(priv->netdev), &encap->fib_nb,1636 NULL, NULL);
register_fib_notifier()callsfib_net_dump()which eventually callsfib6_walk_continue()which can return 1 if "walk is incomplete (i.e. suspended)".Quoted 5 lines
1637 if (err) { 1638 kvfree(encap); 1639 return ERR_PTR(err);If this returns 1 it will eventually lead to an Oops.
Quoted 8 lines
Hi Dan,
Thanks for the bug report!
This looks a bit strange to me because none of the other users of this API handle positive error code in any special way (including reference netdevsim implementation). Maybe API itself should be fixed? Jiri, Ido, what do you think?
Quoted 6 lines
The other functions that call
register_fib_notifier()return an int, butmlx5e_tc_tun_init()returns a pointer. I think that's why it was
flagged: "error: passing non negative 1 toERR_PTR".
fib6_walk_continue()cannot return a positive value when called fromregister_fib_notifier()
Ideally Smatch would be able to figure out this rule automatically.
I see now that fib6_tables_dump() can't return positive because it returns either zero or the return from the "w->func = fib6_node_dump;" and fib6_node_dump() doesn't return positive.
Handling it properly is something I've thought about but I haven't figured out how. What I will do is hard code this into Smatch by adding a line into the smatch_data/db/fixup_kernel.sh file:
delete from return_states where function = 'fib6_tables_dump' and return = '1';
regards,
dan carpenter