From: netdev-bot+sashiko@kernel.org
To: enachman@marvell.com
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, yevhen.orlov@plvision.eu,
taras.chornyi@plvision.eu, oleksandr.mazur@plvision.eu,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
error27@gmail.com
Subject: Re: [PATCH] net: prestera: return error on hash table init failure
Date: Wed, 16 Sep 2026 01:35:31 +0000 [thread overview]
Message-ID: <178952253180.22033.10137454952622538480@kernel.org> (raw)
In-Reply-To: <20260914112026.2822222-1-enachman@marvell.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider:
Critical: 1 · High: 0 · Medium: 0 · Low: 0
- [Critical] Double destroy / double free of rhashtable bucket tables on
the prestera router teardown path.
--
net: prestera: return error on hash table init failure
prestera_router_hw_init() ran its rhashtable cleanup labels but returned 0,
so a failing rhashtable_init() was reported to prestera_router_init() as
success. The patch changes the final return in the error path from 0 to err.
Link: https://lore.kernel.org/kernel-janitors/aqT9h61WBcslE0gJ@stanley.mountain
> diff --git a/drivers/net/ethernet/marvell/prestera/prestera_router_hw.c b/drivers/net/ethernet/marvell/prestera/prestera_router_hw.c
> index ccf6cf98920f2..4785fcb62735d 100644
> --- a/drivers/net/ethernet/marvell/prestera/prestera_router_hw.c
> +++ b/drivers/net/ethernet/marvell/prestera/prestera_router_hw.c
> @@ -93,7 +93,7 @@ int prestera_router_hw_init(struct prestera_switch *sw)
> err_nexthop_grp_ht_init:
> rhashtable_destroy(&sw->router->nh_neigh_ht);
> err_nh_neigh_ht_init:
> - return 0;
> + return err;
> }
>
> void prestera_router_hw_fini(struct prestera_switch *sw)
[Severity: Critical]
The commit message describes the bug being fixed as "dereferencing of freed
memory 'sw->router->nexthop_group_ht.tbl'". Is a very similar dereference
still left in prestera_router_hw_fini() itself, on every teardown rather
than only on the init error path?
drivers/net/ethernet/marvell/prestera/prestera_router_hw.c:
void prestera_router_hw_fini(struct prestera_switch *sw)
{
rhashtable_free_and_destroy(&sw->router->fib_ht,
prestera_fib_node_destroy_ht_cb, sw);
WARN_ON(!list_empty(&sw->router->vr_list));
WARN_ON(!list_empty(&sw->router->rif_entry_list));
rhashtable_destroy(&sw->router->fib_ht);
rhashtable_destroy(&sw->router->nexthop_group_ht);
rhashtable_destroy(&sw->router->nh_neigh_ht);
}
fib_ht is destroyed twice here, and rhashtable_destroy() is only a wrapper
around the same function that already ran:
lib/rhashtable.c:
void rhashtable_destroy(struct rhashtable *ht)
{
return rhashtable_free_and_destroy(ht, NULL, NULL);
}
rhashtable_free_and_destroy() does not clear ht->tbl after freeing the
bucket table:
lib/rhashtable.c:rhashtable_free_and_destroy() {
tbl = rcu_dereference_raw(ht->tbl);
restart:
...
next_tbl = rcu_dereference_raw(tbl->future_tbl);
bucket_table_free(tbl);
if (next_tbl) {
tbl = next_tbl;
goto restart;
}
}
and the free is synchronous, with another dereference of the table inside
it:
lib/rhashtable.c:
static void bucket_table_free(const struct bucket_table *tbl)
{
if (tbl->nest)
nested_bucket_table_free(tbl);
kvfree(tbl);
}
So does the second rhashtable_destroy(&sw->router->fib_ht) read tbl->nest
and tbl->future_tbl out of an already kvfree()d allocation and then kvfree()
it a second time? If the object has been recycled by then, could the
garbage value read from tbl->future_tbl send the restart loop into freeing
an unrelated pointer?
The destroys of nexthop_group_ht and nh_neigh_ht look fine, since those two
tables were only rhashtable_init()'ed and never passed to
rhashtable_free_and_destroy().
The same duplication appears one level up for kern_fib_cache_ht:
drivers/net/ethernet/marvell/prestera/prestera_router.c:prestera_k_arb_abort() {
rhashtable_free_and_destroy(&sw->router->kern_fib_cache_ht,
__prestera_k_arb_abort_fib_ht_cb,
sw);
...
}
drivers/net/ethernet/marvell/prestera/prestera_router.c:prestera_router_fini() {
...
prestera_k_arb_abort(sw);
kfree(sw->router->nhgrp_hw_state_cache);
rhashtable_destroy(&sw->router->kern_fib_cache_ht);
prestera_router_hw_fini(sw);
...
}
Both of these run unconditionally on device unbind and module removal, and
prestera_router_hw_fini() is also reached from the init error label:
err_kern_fib_cache_ht_init:
prestera_router_hw_fini(sw);
which is the very path this patch makes reachable with a non-zero return.
Should the redundant rhashtable_destroy() calls for fib_ht and
kern_fib_cache_ht be dropped as part of this fix?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260914112026.2822222-1-enachman%40marvell.com
prev parent reply other threads:[~2026-09-16 1:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 11:20 Elad Nachman
2026-09-15 23:55 ` Jacob Keller
2026-09-16 1:35 ` netdev-bot+sashiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=178952253180.22033.10137454952622538480@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=enachman@marvell.com \
--cc=error27@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oleksandr.mazur@plvision.eu \
--cc=pabeni@redhat.com \
--cc=taras.chornyi@plvision.eu \
--cc=yevhen.orlov@plvision.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®