netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] genl: Fix descriptor leak in get_genl_kind()
@ 2024-02-07 20:08 Maks Mishin
  2024-02-08 13:22 ` Donald Hunter
  0 siblings, 1 reply; 2+ messages in thread
From: Maks Mishin @ 2024-02-07 20:08 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Maks Mishin, netdev

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
---
 genl/genl.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/genl/genl.c b/genl/genl.c
index 85cc73bb..74100dad 100644
--- a/genl/genl.c
+++ b/genl/genl.c
@@ -71,6 +71,9 @@ static struct genl_util *get_genl_kind(const char *str)
 	snprintf(buf, sizeof(buf), "%s_genl_util", str);
 
 	f = dlsym(dlh, buf);
+	if (dlh != NULL)
+		dlclose(dlh);
+
 	if (f == NULL)
 		goto noexist;
 reg:
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] genl: Fix descriptor leak in get_genl_kind()
  2024-02-07 20:08 [PATCH] genl: Fix descriptor leak in get_genl_kind() Maks Mishin
@ 2024-02-08 13:22 ` Donald Hunter
  0 siblings, 0 replies; 2+ messages in thread
From: Donald Hunter @ 2024-02-08 13:22 UTC (permalink / raw)
  To: Maks Mishin; +Cc: Stephen Hemminger, netdev

Maks Mishin <maks.mishinfz@gmail.com> writes:

> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>

The subject should say [PATCH iproute2] or [PATCH iproute2-next] since
it targets that project.

> ---
>  genl/genl.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/genl/genl.c b/genl/genl.c
> index 85cc73bb..74100dad 100644
> --- a/genl/genl.c
> +++ b/genl/genl.c
> @@ -71,6 +71,9 @@ static struct genl_util *get_genl_kind(const char *str)
>  	snprintf(buf, sizeof(buf), "%s_genl_util", str);
>  
>  	f = dlsym(dlh, buf);
> +	if (dlh != NULL)
> +		dlclose(dlh);

This is broken. If the earlier dlopen() actually loaded a .so then this
dlclose() will close it again, before f gets used. When f gets
dereferenced later, the program will crash. If this works at all, it is
because dlopen(NULL, ...) returns a handle to the main program, so
dlclose() doesn't unload it.

My assumption is that the author is leaving resources to be released at
program exit. It is a short-lived command line utility after all.

> +
>  	if (f == NULL)
>  		goto noexist;
>  reg:

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-08 13:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-07 20:08 [PATCH] genl: Fix descriptor leak in get_genl_kind() Maks Mishin
2024-02-08 13:22 ` Donald Hunter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).