NetBSD Problem Report #57983

From jarle@festningen.kontor.norid.no  Sat Mar  2 12:50:59 2024
Return-Path: <jarle@festningen.kontor.norid.no>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 986C41A923A
	for <gnats-bugs@gnats.NetBSD.org>; Sat,  2 Mar 2024 12:50:59 +0000 (UTC)
Message-Id: <20240302125046.2C7FA170270E@festningen.kontor.norid.no>
Date: Sat,  2 Mar 2024 13:50:46 +0100 (CET)
From: jarle.greipsland@norid.no
To: gnats-bugs@NetBSD.org
Subject: open-vm-tools file descriptor leak
X-Send-Pr-Version: 3.95

>Number:         57983
>Category:       pkg
>Synopsis:       open-vm-tools file descriptor leak
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    agc
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 02 12:55:00 +0000 2024
>Closed-Date:    Sat Mar 02 13:53:34 +0000 2024
>Last-Modified:  Sat Mar 02 13:55:01 +0000 2024
>Originator:     Jarle Fredrik Greipsland
>Release:        NetBSD 10.0_RC4
>Organization:
Vennlig hilsen
Jarle Fredrik Greipsland
>Environment:


System: NetBSD aaa.bbb.ccc.ddd 10.0_RC4 NetBSD 10.0_RC4 (GENERIC) #3: Thu Feb 22 17:41:47 CET 2024  jarle@aaa.bbb.ccc.ddd:/build/netbsd-10/amd64/obj/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:

On a newly created VM on a VMware hypervisor, I compiled, installed
and started vmtoolsd from pkgsrc' sysutils/open-vm-tools package.
Some hours later the vmtoolsd process had reached its limit with
regards to the permitted number of open file descriptors.

In its default configuration vmtoolsd will try and retrieve
information from /etc/resolv.conf or similar every 30 seconds.  In a
Unix-like environment it does this by calling res_ninit, and then
extricate various pieces of information from the data stored in the
struct __res_state variable.  When done, it does a res_nclose on the
variable.

Unfortunately, in NetBSD, the res_ninit function has the (unusual, but
documented) side effect that it will keep an open file descriptor for
the /etc/resolv.conf file, and even allocate a kevent descriptor as
well, in order to catch updates to the file.  res_nclose does not free
these resources.  So the process will leak 2 descriptors every 30
seconds.

>How-To-Repeat:
Install and run vmtoolsd on a VMware hosted VM.

>Fix:
For NetBSD, when done with the resolver object, use res_ndestroy
instead of res_nclose to release any allocated resources.  Patch
below.

diff -u lib/nicInfo/nicInfoPosix.c.orig lib/nicInfo/nicInfoPosix.c
--- lib/nicInfo/nicInfoPosix.c.orig     2024-03-01 17:37:32.813014060 +0100
+++ lib/nicInfo/nicInfoPosix.c  2024-03-01 17:38:38.906276921 +0100
@@ -898,14 +898,22 @@
     */
    nicInfo->dnsConfigInfo = dnsConfigInfo;

+#if defined(__NetBSD__)
+   res_ndestroy(&res);
+#else
    res_nclose(&res);
+#endif

    return TRUE;

 fail:
    VMX_XDR_FREE(xdr_DnsConfigInfo, dnsConfigInfo);
    free(dnsConfigInfo);
+#if defined(__NetBSD__)
+   res_ndestroy(&res);
+#else
    res_nclose(&res);
+#endif

    return FALSE;
 }


>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: pkg-manager->agc
Responsible-Changed-By: wiz@NetBSD.org
Responsible-Changed-When: Sat, 02 Mar 2024 13:53:34 +0000
Responsible-Changed-Why:
Info for MAINTAINER


State-Changed-From-To: open->closed
State-Changed-By: wiz@NetBSD.org
State-Changed-When: Sat, 02 Mar 2024 13:53:34 +0000
State-Changed-Why:
I've applied the patch to pkgsrc.
Thank you for the detailed analysis!

Can you please send the patch upstream too? Thanks.


From: "Thomas Klausner" <wiz@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57983 CVS commit: pkgsrc/sysutils/open-vm-tools
Date: Sat, 2 Mar 2024 13:52:43 +0000

 Module Name:	pkgsrc
 Committed By:	wiz
 Date:		Sat Mar  2 13:52:43 UTC 2024

 Modified Files:
 	pkgsrc/sysutils/open-vm-tools: Makefile distinfo
 Added Files:
 	pkgsrc/sysutils/open-vm-tools/patches: patch-lib_nicInfo_nicInfoPosix.c

 Log Message:
 open-vm-tools: add patch from PR 57983 by Jarle Fredrik Greipsland

 Fixes a resource leak.

 Bump PKGREVISION.


 To generate a diff of this commit:
 cvs rdiff -u -r1.123 -r1.124 pkgsrc/sysutils/open-vm-tools/Makefile
 cvs rdiff -u -r1.39 -r1.40 pkgsrc/sysutils/open-vm-tools/distinfo
 cvs rdiff -u -r0 -r1.3 \
     pkgsrc/sysutils/open-vm-tools/patches/patch-lib_nicInfo_nicInfoPosix.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.