ipv4: Fix error return code in fib_table_insert()
authorZiyang Xuan <william.xuanziyang@huawei.com>
Sun, 20 Nov 2022 07:28:38 +0000 (15:28 +0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 23 Nov 2022 04:18:20 +0000 (20:18 -0800)
In fib_table_insert(), if the alias was already inserted, but node not
exist, the error code should be set before return from error handling path.

Fixes: a6c76c17df02 ("ipv4: Notify route after insertion to the routing table")
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
Link: https://lore.kernel.org/r/20221120072838.2167047-1-william.xuanziyang@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/fib_trie.c

index c88bf85..74d403d 100644 (file)
@@ -1381,8 +1381,10 @@ int fib_table_insert(struct net *net, struct fib_table *tb,
 
        /* The alias was already inserted, so the node must exist. */
        l = l ? l : fib_find_node(t, &tp, key);
-       if (WARN_ON_ONCE(!l))
+       if (WARN_ON_ONCE(!l)) {
+               err = -ENOENT;
                goto out_free_new_fa;
+       }
 
        if (fib_find_alias(&l->leaf, new_fa->fa_slen, 0, 0, tb->tb_id, true) ==
            new_fa) {