* [nf PATCH] ipset: core: Hold module reference while requesting a module
@ 2024-11-29 15:30 Phil Sutter
2024-11-30 21:16 ` Jozsef Kadlecsik
2024-12-04 14:40 ` Pablo Neira Ayuso
0 siblings, 2 replies; 3+ messages in thread
From: Phil Sutter @ 2024-11-29 15:30 UTC (permalink / raw)
To: Jozsef Kadlecsik; +Cc: Pablo Neira Ayuso, netfilter-devel
User space may unload ip_set.ko while it is itself requesting a set type
backend module, leading to a kernel crash. The race condition may be
provoked by inserting an mdelay() right after the nfnl_unlock() call.
Fixes: a7b4f989a629 ("netfilter: ipset: IP set core support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
net/netfilter/ipset/ip_set_core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
index 61431690cbd5..cc20e6d56807 100644
--- a/net/netfilter/ipset/ip_set_core.c
+++ b/net/netfilter/ipset/ip_set_core.c
@@ -104,14 +104,19 @@ find_set_type(const char *name, u8 family, u8 revision)
static bool
load_settype(const char *name)
{
+ if (!try_module_get(THIS_MODULE))
+ return false;
+
nfnl_unlock(NFNL_SUBSYS_IPSET);
pr_debug("try to load ip_set_%s\n", name);
if (request_module("ip_set_%s", name) < 0) {
pr_warn("Can't find ip_set type %s\n", name);
nfnl_lock(NFNL_SUBSYS_IPSET);
+ module_put(THIS_MODULE);
return false;
}
nfnl_lock(NFNL_SUBSYS_IPSET);
+ module_put(THIS_MODULE);
return true;
}
--
2.47.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [nf PATCH] ipset: core: Hold module reference while requesting a module
2024-11-29 15:30 [nf PATCH] ipset: core: Hold module reference while requesting a module Phil Sutter
@ 2024-11-30 21:16 ` Jozsef Kadlecsik
2024-12-04 14:40 ` Pablo Neira Ayuso
1 sibling, 0 replies; 3+ messages in thread
From: Jozsef Kadlecsik @ 2024-11-30 21:16 UTC (permalink / raw)
To: Phil Sutter; +Cc: Pablo Neira Ayuso, netfilter-devel
Hi Phil,
On Fri, 29 Nov 2024, Phil Sutter wrote:
> User space may unload ip_set.ko while it is itself requesting a set type
> backend module, leading to a kernel crash. The race condition may be
> provoked by inserting an mdelay() right after the nfnl_unlock() call.
>
> Fixes: a7b4f989a629 ("netfilter: ipset: IP set core support")
> Signed-off-by: Phil Sutter <phil@nwl.cc>
Good catch! It's an unlocked area, so the module reference is indeed
required.
Acked-by: Jozsef Kadlecsik <kadlec@netfilter.org>
Best regards,
Jozsef
> ---
> net/netfilter/ipset/ip_set_core.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
> index 61431690cbd5..cc20e6d56807 100644
> --- a/net/netfilter/ipset/ip_set_core.c
> +++ b/net/netfilter/ipset/ip_set_core.c
> @@ -104,14 +104,19 @@ find_set_type(const char *name, u8 family, u8 revision)
> static bool
> load_settype(const char *name)
> {
> + if (!try_module_get(THIS_MODULE))
> + return false;
> +
> nfnl_unlock(NFNL_SUBSYS_IPSET);
> pr_debug("try to load ip_set_%s\n", name);
> if (request_module("ip_set_%s", name) < 0) {
> pr_warn("Can't find ip_set type %s\n", name);
> nfnl_lock(NFNL_SUBSYS_IPSET);
> + module_put(THIS_MODULE);
> return false;
> }
> nfnl_lock(NFNL_SUBSYS_IPSET);
> + module_put(THIS_MODULE);
> return true;
> }
>
> --
> 2.47.0
>
>
--
E-mail : kadlec@netfilter.org, kadlec@blackhole.kfki.hu, kadlecsik.jozsef@wigner.hu
Address: Wigner Research Centre for Physics
H-1525 Budapest 114, POB. 49, Hungary
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [nf PATCH] ipset: core: Hold module reference while requesting a module
2024-11-29 15:30 [nf PATCH] ipset: core: Hold module reference while requesting a module Phil Sutter
2024-11-30 21:16 ` Jozsef Kadlecsik
@ 2024-12-04 14:40 ` Pablo Neira Ayuso
1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2024-12-04 14:40 UTC (permalink / raw)
To: Phil Sutter; +Cc: Jozsef Kadlecsik, netfilter-devel
On Fri, Nov 29, 2024 at 04:30:38PM +0100, Phil Sutter wrote:
> User space may unload ip_set.ko while it is itself requesting a set type
> backend module, leading to a kernel crash. The race condition may be
> provoked by inserting an mdelay() right after the nfnl_unlock()
> call.
Applied, thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-12-04 14:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-29 15:30 [nf PATCH] ipset: core: Hold module reference while requesting a module Phil Sutter
2024-11-30 21:16 ` Jozsef Kadlecsik
2024-12-04 14:40 ` Pablo Neira Ayuso
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.