pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches for UNC crashes+mem allocator debug options, 2023-12-18
Posted by Anonymous on Mon 18th Dec 2023 15:29
raw | new post

  1. From b850ea10692f8eb7c39b7015b42009c22d4868e1 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Fri, 15 Dec 2023 12:39:30 +0100
  4. Subject: [PATCH 1/8] mount,sys/nfs41_driver: Unaligned mount data can lead to
  5.  mount failure
  6.  
  7. Make sure |FILE_FULL_EA_INFORMATION| data is properly longword-aligned,
  8. (as mandated by
  9. https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_file_full_ea_information)
  10.  
  11. Previously the alignment was only 32bit (|ULONG| for 32bit platform)
  12. aligned, which lead to random mount failures on 64bit platforms
  13. (where |ULONG| is a 64bit datatype).
  14.  
  15. The patch also adds |IoCheckEaBufferValidity()| to
  16. |nfs41_MountConfig_ParseOptions()|, to make sure we validate the
  17. mount data and get a proper error code if they are not valid.
  18.  
  19. Reported-by: Cedric Blancher <cedric.blancher@gmail.com>
  20. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  21. ---
  22. mount/options.c    |  2 +-
  23.  sys/nfs41_driver.c | 17 +++++++++++++++++
  24.  2 files changed, 18 insertions(+), 1 deletion(-)
  25.  
  26. diff --git a/mount/options.c b/mount/options.c
  27. index 73649cc..f254d6d 100644
  28. --- a/mount/options.c
  29. +++ b/mount/options.c
  30. @@ -86,7 +86,7 @@ static FORCEINLINE ULONG EaBufferSize(
  31.          + NameSize + ValueSize + sizeof(TCHAR);
  32.      /* extended attributes require ULONG alignment;
  33.       * see documentation for IoCheckEaBufferValidity() */
  34. -    return ( (Size + 3) / sizeof(ULONG) ) * sizeof(ULONG);
  35. +    return ( (Size + (sizeof(ULONG)-1)) / sizeof(ULONG) ) * sizeof(ULONG);
  36.  }
  37.  
  38.  static FORCEINLINE ULONG EaBufferNextOffset(
  39. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  40. index e2919b9..457ce03 100644
  41. --- a/sys/nfs41_driver.c
  42. +++ b/sys/nfs41_driver.c
  43. @@ -2760,6 +2760,17 @@ NTSTATUS nfs41_MountConfig_ParseOptions(
  44.      LPWSTR Name;
  45.      size_t NameLen;
  46.      UNICODE_STRING  usValue;
  47. +    ULONG error_offset;
  48. +
  49. +    status = IoCheckEaBufferValidity(EaBuffer, EaLength, &error_offset);
  50. +    if (status) {
  51. +        DbgP("status(=%d)=IoCheckEaBufferValidity"
  52. +            "(eainfo=%p, buflen=%lu, &(error_offset=%d)) failed\n",
  53. +            (int)status, (void *)EaBuffer, EaLength,
  54. +            (int)error_offset);
  55. +        goto out;
  56. +    }
  57. +
  58.      Option = EaBuffer;
  59.      while (status == STATUS_SUCCESS) {
  60.          DbgP("Option=%p\n", (void *)Option);
  61. @@ -2857,6 +2868,7 @@ NTSTATUS nfs41_MountConfig_ParseOptions(
  62.              ((PBYTE)Option + Option->NextEntryOffset);
  63.      }
  64.  
  65. +out:
  66.      DbgP("<-- nfs41_MountConfig_ParseOptions, status=%ld\n", (long)status);
  67.      return status;
  68.  }
  69. @@ -4797,6 +4809,11 @@ NTSTATUS nfs41_SetEaInformation(
  70.          entry->u.SetEa.mode = 0;
  71.          status = IoCheckEaBufferValidity(eainfo, buflen, &error_offset);
  72.          if (status) {
  73. +            DbgP("nfs41_SetEaInformation: "
  74. +                "status(=%d)=IoCheckEaBufferValidity"
  75. +                "(eainfo=%p, buflen=%lu, &(error_offset=%d))\n",
  76. +                (int)status, (void *)eainfo, buflen,
  77. +                (int)error_offset);
  78.              RxFreePool(entry);
  79.              goto out;
  80.          }
  81. --
  82. 2.42.1
  83.  
  84. From 20f3533e33104728406a7bca517c6d672c1be9f2 Mon Sep 17 00:00:00 2001
  85. From: Roland Mainz <roland.mainz@nrubsig.org>
  86. Date: Mon, 18 Dec 2023 10:59:10 +0100
  87. Subject: [PATCH 2/8] sys/nfs41_driver: Fix crash when NFS fs is accessed via
  88.  UNC path before mount
  89.  
  90. Fix kernel crash due to an uninitalised mutex when a NFSv4 filesystem
  91. is accessed via UNC path without being mounted first via
  92. nfs_mount.exe (UNC paths to a NFSv4 filesystem require that the
  93. filesystem is mounted via nfs_mount.exe first, so the kernel has
  94. proper mount options).
  95.  
  96. Stack trace from MEMORY.DMP:
  97. ---- snip ----
  98. nt!KeBugCheckEx
  99. nt!KiBugCheckDispatch+0x69
  100. nt!KiPageFault+0x463
  101. nt!KeWaitForSingleObject+0x1e1
  102. nt!ExpAcquireFastMutexContended+0x7a
  103. nt!ExAcquireFastMutex+0x162
  104. nfs41_driver!nfs41_CreateVNetRoot+0x356 [C:\cygwin64\home\roland_mainz\work\msnfs41_uidmapping\ms-nfs41-client\sys\nfs41_driver.c @ 3080]
  105. nfs41_driver!RxConstructNetRoot+0xdd [base\fs\rdr2\rxce\rxconnct.c @ 1101]
  106. nfs41_driver!RxFindOrCreateConnections+0x657 [base\fs\rdr2\rxce\rxconnct.c @ 500]
  107. nfs41_driver!RxConstructVirtualNetRoot+0x72 [base\fs\rdr2\rxce\rxconnct.c @ 1197]
  108. nfs41_driver!RxFindOrConstructVirtualNetRoot+0x30e [base\fs\rdr2\rxce\rxconnct.c @ 1731]
  109. nfs41_driver!RxPrefixClaim+0x197 [base\fs\rdr2\rdbss\create.c @ 3037]
  110. nfs41_driver!RxCommonDevFCBIoCtl+0x92 [base\fs\rdr2\rdbss\ntdevfcb.c @ 498]
  111. nfs41_driver!RxFinishSrvCallConstruction+0x18f [base\fs\rdr2\rxce\rxconnct.c @ 723]
  112. nfs41_driver!RxFinishSrvCallConstructionDispatcher+0x84 [base\fs\rdr2\rxce\rxconnct.c @ 805]
  113. nfs41_driver!RxWorkItemDispatcher+0x13 [base\fs\rdr2\rxce\rxworkq.c @ 1653]
  114. nfs41_driver!RxpWorkerThreadDispatcher+0xbb [base\fs\rdr2\rxce\rxworkq.c @ 1343]
  115. nfs41_driver!RxBootstrapWorkerThreadDispatcher+0xb [base\fs\rdr2\rxce\rxworkq.c @ 1469]
  116. nt!PspSystemThreadStartup+0x55
  117. nt!KiStartSystemThread+0x28
  118. ---- snip ----
  119.  
  120. This also adds |STATUS_NFS_SHARE_NOT_MOUNTED| (mapped to
  121. |STATUS_BAD_NETWORK_PATH|) so we always use the same error code for
  122. this case.
  123.  
  124. Reported-by: Martin Wege <martin.l.wege@gmail.com>
  125. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  126. ---
  127. sys/nfs41_driver.c | 22 ++++++++++++++++++++--
  128.  1 file changed, 20 insertions(+), 2 deletions(-)
  129.  
  130. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  131. index 457ce03..83aca0b 100644
  132. --- a/sys/nfs41_driver.c
  133. +++ b/sys/nfs41_driver.c
  134. @@ -3052,6 +3052,23 @@ NTSTATUS nfs41_CreateVNetRoot(
  135.          /* Codepath for \\server@port\nfs4\path */
  136.          DbgP("Codepath for \\\\server@port\\nfs4\\path\n");
  137.  
  138. +        /*
  139. +         * STATUS_NFS_SHARE_NOT_MOUNTED - status code for the case
  140. +         * when a NFS filesystem is accessed via UNC path, but no
  141. +         * nfs_mount.exe was done for that filesystem
  142. +         */
  143. +#define STATUS_NFS_SHARE_NOT_MOUNTED STATUS_BAD_NETWORK_PATH
  144. +        if (!pNetRootContext->mounts_init) {
  145. +            /*
  146. +             * We can only support UNC paths when we got valid
  147. +             * mount options via nfs_mount.exe before this point.
  148. +             */
  149. +            DbgP("pNetRootContext(=%p) not initalised yet\n",
  150. +                pNetRootContext);
  151. +            status = STATUS_NFS_SHARE_NOT_MOUNTED;
  152. +            goto out_free;
  153. +        }
  154. +
  155.          /*
  156.           * gisburn: Fixme: Originally the code was using the
  157.           * SRV_CALL name (without leading \) as the hostname
  158. @@ -3074,7 +3091,7 @@ NTSTATUS nfs41_CreateVNetRoot(
  159.  
  160.          PLIST_ENTRY pEntry;
  161.  
  162. -        status = STATUS_OBJECT_NAME_NOT_FOUND;
  163. +        status = STATUS_NFS_SHARE_NOT_MOUNTED;
  164.  
  165.          ExAcquireFastMutex(&pNetRootContext->mountLock);
  166.          pEntry = &pNetRootContext->mounts.head;
  167. @@ -3098,7 +3115,8 @@ NTSTATUS nfs41_CreateVNetRoot(
  168.          ExReleaseFastMutex(&pNetRootContext->mountLock);
  169.  
  170.          if (status != STATUS_SUCCESS) {
  171. -            DbgP("No existing mount found\n");
  172. +            DbgP("No existing mount found, "
  173. +                "status==STATUS_NFS_SHARE_NOT_MOUNTED\n");
  174.              goto out_free;
  175.          }
  176.  
  177. --
  178. 2.42.1
  179.  
  180. From be737a2627aa659a1b342c5a02578921b167393a Mon Sep 17 00:00:00 2001
  181. From: Roland Mainz <roland.mainz@nrubsig.org>
  182. Date: Mon, 18 Dec 2023 11:28:49 +0100
  183. Subject: [PATCH 3/8] mount: nfs_mount.exe should always use debug allocator
  184.  
  185. nfs_mount.exe should always use the debug allocator - it is not
  186. performance sensitive, and it is more important to see leads and
  187. other memory issues there.
  188.  
  189. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  190. ---
  191. mount/mount.c   | 13 +++++++++++++
  192.  mount/options.c |  3 +++
  193.  2 files changed, 16 insertions(+)
  194.  
  195. diff --git a/mount/mount.c b/mount/mount.c
  196. index 0d48ec2..b06cac1 100644
  197. --- a/mount/mount.c
  198. +++ b/mount/mount.c
  199. @@ -20,6 +20,9 @@
  200.   * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  201.   */
  202.  
  203. +#define _DEBUG 1
  204. +
  205. +#include <crtdbg.h>
  206.  #include <Windows.h>
  207.  #include <tchar.h>
  208.  #include <strsafe.h>
  209. @@ -96,6 +99,16 @@ DWORD __cdecl _tmain(DWORD argc, LPTSTR argv[])
  210.      BOOL    bPersistent = FALSE;
  211.      MOUNT_OPTION_LIST Options;
  212.  
  213. +    int crtsetdbgflags = 0;
  214. +    crtsetdbgflags |= _CRTDBG_ALLOC_MEM_DF;  /* use debug heap */
  215. +    crtsetdbgflags |= _CRTDBG_LEAK_CHECK_DF; /* report leaks on exit */
  216. +    crtsetdbgflags |= _CRTDBG_DELAY_FREE_MEM_DF;
  217. +    (void)_CrtSetDbgFlag(crtsetdbgflags);
  218. +    (void)_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
  219. +    (void)_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
  220. +    (void)_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
  221. +
  222. +
  223.      if (argc == 1) {
  224.          /* list open nfs shares */
  225.          result = EnumMounts(NULL);
  226. diff --git a/mount/options.c b/mount/options.c
  227. index f254d6d..53d0e37 100644
  228. --- a/mount/options.c
  229. +++ b/mount/options.c
  230. @@ -19,6 +19,9 @@
  231.   * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  232.   */
  233.  
  234. +#define _DEBUG 1
  235. +
  236. +#include <crtdbg.h>
  237.  #include <Windows.h>
  238.  #include <tchar.h>
  239.  #include <strsafe.h>
  240. --
  241. 2.42.1
  242.  
  243. From 38af108c0b47f66bd65d309cf60c46216eb3ab57 Mon Sep 17 00:00:00 2001
  244. From: Roland Mainz <roland.mainz@nrubsig.org>
  245. Date: Mon, 18 Dec 2023 11:34:48 +0100
  246. Subject: [PATCH 4/8] daemon: nfs_debug should not open interactive dialogs for
  247.  _CRT_(ERROR|ASSERT)
  248.  
  249. nfs_debug.exe should not open interactive Windows dialogs for
  250. _CRT_ERROR and _CRT_ASSERT issues. Instead they should just be logged
  251. to the error log.
  252.  
  253. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  254. ---
  255. daemon/nfs41_daemon.c | 4 +++-
  256.  1 file changed, 3 insertions(+), 1 deletion(-)
  257.  
  258. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  259. index 99eb468..0097d2e 100644
  260. --- a/daemon/nfs41_daemon.c
  261. +++ b/daemon/nfs41_daemon.c
  262. @@ -433,7 +433,9 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  263.      crtsetdbgflags |= _CRTDBG_DELAY_FREE_MEM_DF;
  264.  #endif
  265.      (void)_CrtSetDbgFlag(crtsetdbgflags);
  266. -    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
  267. +    (void)_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
  268. +    (void)_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
  269. +    (void)_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
  270.  
  271.      /*
  272.       * Do not fill memory with 0xFE for functions like |strcpy_s()|
  273. --
  274. 2.42.1
  275.  
  276. From 3a684459fefee5272d6ca0abc5faf37a15ac07f6 Mon Sep 17 00:00:00 2001
  277. From: Roland Mainz <roland.mainz@nrubsig.org>
  278. Date: Mon, 18 Dec 2023 14:16:03 +0100
  279. Subject: [PATCH 5/8] daemon: Add --crtdbgmem option to set CRTDBG handling
  280.  
  281. Add cmd line option --crtdbgmem to nfsd which accepts the values
  282. 'allocmem'|'leakcheck'|'delayfree' (OR'ed), or "all" (set all flags),
  283. 'none' (disable crtdbgmem) or 'default' (use defaults used when
  284. --crtdbgmem is not set).
  285.  
  286. See https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/crtsetdbgflag?view=msvc-170
  287. for a description of the flags.
  288.  
  289. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  290. ---
  291. daemon/nfs41_daemon.c | 141 +++++++++++++++++++++++++++++++-----------
  292.  daemon/nfs41_daemon.h |   3 +
  293.  2 files changed, 109 insertions(+), 35 deletions(-)
  294.  
  295. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  296. index 0097d2e..1b07301 100644
  297. --- a/daemon/nfs41_daemon.c
  298. +++ b/daemon/nfs41_daemon.c
  299. @@ -50,6 +50,7 @@ nfs41_daemon_globals nfs41_dg = {
  300.      .default_uid = NFS_USER_NOBODY_UID,
  301.      .default_gid = NFS_GROUP_NOGROUP_GID,
  302.      .num_worker_threads = DEFAULT_NUM_THREADS,
  303. +    .crtdbgmem_flags = NFS41D_GLOBALS_CRTDBGMEM_FLAGS_NOT_SET,
  304.  };
  305.  
  306.  
  307. @@ -192,6 +193,10 @@ static void PrintUsage()
  308.          "--uid <non-zero value> "
  309.          "--gid <non-zero value> "
  310.          "--numworkerthreads <value-between 16 and %d> "
  311. +#ifdef _DEBUG
  312. +        "--crtdbgmem <'allocmem'|'leakcheck'|'delayfree', "
  313. +            "'all', 'none' or 'default'> "
  314. +#endif /* _DEBUG */
  315.          "\n", MAX_NUM_THREADS);
  316.  }
  317.  static bool_t parse_cmdlineargs(int argc, TCHAR *argv[], nfsd_args *out)
  318. @@ -218,6 +223,43 @@ static bool_t parse_cmdlineargs(int argc, TCHAR *argv[], nfsd_args *out)
  319.                  }
  320.                  out->debug_level = _ttoi(argv[i]);
  321.              }
  322. +#ifdef _DEBUG
  323. +            else if (_tcscmp(argv[i], TEXT("--crtdbgmem")) == 0) {
  324. +                ++i;
  325. +                const TCHAR *memdbgoptions = argv[i];
  326. +                if (i >= argc) {
  327. +                    fprintf(stderr, "Missing options\n");
  328. +                    PrintUsage();
  329. +                    return FALSE;
  330. +                }
  331. +
  332. +                if (nfs41_dg.crtdbgmem_flags ==
  333. +                    NFS41D_GLOBALS_CRTDBGMEM_FLAGS_NOT_SET)
  334. +                    nfs41_dg.crtdbgmem_flags = 0;
  335. +
  336. +                nfs41_dg.crtdbgmem_flags |=
  337. +                    (_tcsstr(memdbgoptions, TEXT("allocmem")) != NULL)?
  338. +                    _CRTDBG_ALLOC_MEM_DF:0;
  339. +                nfs41_dg.crtdbgmem_flags |=
  340. +                    (_tcsstr(memdbgoptions, TEXT("leakcheck")) != NULL)?
  341. +                    _CRTDBG_LEAK_CHECK_DF:0;
  342. +                nfs41_dg.crtdbgmem_flags |=
  343. +                    (_tcsstr(memdbgoptions, TEXT("delayfree")) != NULL)?
  344. +                    _CRTDBG_DELAY_FREE_MEM_DF:0;
  345. +                nfs41_dg.crtdbgmem_flags |=
  346. +                    (_tcsstr(memdbgoptions, TEXT("all")) != NULL)?
  347. +                    (_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF|_CRTDBG_DELAY_FREE_MEM_DF):0;
  348. +
  349. +                if (_tcsstr(memdbgoptions, TEXT("none")) != NULL) {
  350. +                    nfs41_dg.crtdbgmem_flags = 0;
  351. +                }
  352. +
  353. +                if (_tcsstr(memdbgoptions, TEXT("default")) != NULL) {
  354. +                    nfs41_dg.crtdbgmem_flags =
  355. +                        NFS41D_GLOBALS_CRTDBGMEM_FLAGS_NOT_SET;
  356. +                }
  357. +            }
  358. +#endif /* _DEBUG */
  359.              else if (_tcscmp(argv[i], TEXT("--noldap")) == 0) { /* no LDAP */
  360.                  out->ldap_enable = FALSE;
  361.              }
  362. @@ -393,6 +435,69 @@ out:
  363.      return status;
  364.  }
  365.  
  366. +
  367. +static
  368. +void nfsd_crt_debug_init(void)
  369. +{
  370. +#ifdef _DEBUG
  371. +    /* dump memory leaks to stderr on exit; this requires the debug heap,
  372. +    /* available only when built in debug mode under visual studio -cbodley */
  373. +
  374. +    int crtsetdbgflags = nfs41_dg.crtdbgmem_flags;
  375. +
  376. +    if (crtsetdbgflags == NFS41D_GLOBALS_CRTDBGMEM_FLAGS_NOT_SET) {
  377. +        dprintf(0, "crtsetdbgflags not set, using defaults\n");
  378. +        crtsetdbgflags = 0;
  379. +
  380. +        crtsetdbgflags |= _CRTDBG_ALLOC_MEM_DF;
  381. +        crtsetdbgflags |= _CRTDBG_LEAK_CHECK_DF;
  382. +        /*
  383. +         * _CRTDBG_DELAY_FREE_MEM_DF - Delay freeing of memory, but
  384. +         * fill memory blocks passed to |free()| with 0xdd. We rely
  385. +         * on that to see 0xdddddddddddddddd-pointers for
  386. +         * use-after-free and catch them in stress testing instead
  387. +         * of having to deal with a core dump.
  388. +         *
  389. +         * This is off by default, as it can lead to memory
  390. +         * exhaustion (e.g. 5GB for $ git clone -b
  391. +         * 'releases/gcc-13.2.0' git://gcc.gnu.org/git/gcc.git on a
  392. +         * NFS filesystem)
  393. +         * ---- snip ----
  394. +         * crtsetdbgflags |= _CRTDBG_DELAY_FREE_MEM_DF;
  395. +         * ---- snip ----
  396. +         */
  397. +    }
  398. +
  399. +    dprintf(0, "memory debug flags _CRTDBG_(=0x%x)"
  400. +        "{ ALLOC_MEM_DF=%d, LEAK_CHECK_DF=%d, DELAY_FREE_MEM_DF=%d }\n",
  401. +        crtsetdbgflags,
  402. +        ((crtsetdbgflags & _CRTDBG_ALLOC_MEM_DF)?1:0),
  403. +        ((crtsetdbgflags & _CRTDBG_LEAK_CHECK_DF)?1:0),
  404. +        ((crtsetdbgflags & _CRTDBG_DELAY_FREE_MEM_DF)?1:0));
  405. +
  406. +    (void)_CrtSetDbgFlag(crtsetdbgflags);
  407. +
  408. +    /*
  409. +     * Do not fill memory with 0xFE for functions like |strcpy_s()|
  410. +     * etc, as it causes bad performance. We have drmemory to find
  411. +     * issues like that instead
  412. +     */
  413. +    (void)_CrtSetDebugFillThreshold(0);
  414. +
  415. +    (void)_CrtSetReportMode(_CRT_WARN,      _CRTDBG_MODE_FILE);
  416. +    (void)_CrtSetReportMode(_CRT_ERROR,     _CRTDBG_MODE_FILE);
  417. +    (void)_CrtSetReportMode(_CRT_ASSERT,    _CRTDBG_MODE_FILE);
  418. +
  419. +    (void)_CrtSetReportFile(_CRT_WARN,    _CRTDBG_FILE_STDERR);
  420. +    (void)_CrtSetReportFile(_CRT_ERROR,   _CRTDBG_FILE_STDERR);
  421. +    (void)_CrtSetReportFile(_CRT_ASSERT,  _CRTDBG_FILE_STDERR);
  422. +
  423. +    if (crtsetdbgflags & _CRTDBG_LEAK_CHECK_DF) {
  424. +        dprintf(1, "debug mode. dumping memory leaks to stderr on exit.\n");
  425. +    }
  426. +#endif /* _DEBUG */
  427. +}
  428. +
  429.  #ifdef STANDALONE_NFSD
  430.  void __cdecl _tmain(int argc, TCHAR *argv[])
  431.  #else
  432. @@ -412,43 +517,9 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  433.          exit(1);
  434.      set_debug_level(cmd_args.debug_level);
  435.      open_log_files();
  436. +    nfsd_crt_debug_init();
  437.      sidcache_init();
  438.  
  439. -#ifdef _DEBUG
  440. -    /* dump memory leaks to stderr on exit; this requires the debug heap,
  441. -    /* available only when built in debug mode under visual studio -cbodley */
  442. -
  443. -    int crtsetdbgflags = 0;
  444. -    crtsetdbgflags |= _CRTDBG_ALLOC_MEM_DF;  /* use debug heap */
  445. -    crtsetdbgflags |= _CRTDBG_LEAK_CHECK_DF; /* report leaks on exit */
  446. -/* Disabled for now, git clone ... gcc.git does not work with it */
  447. -#ifdef DISABLED_FOR_NOW
  448. -    /*
  449. -     * _CRTDBG_DELAY_FREE_MEM_DF - Delay freeing of memory, but fill
  450. -     * memory blocks passed to |free()| with 0xdd. We rely on that to
  451. -     * see 0xdddddddddddddddd-pointers for use-after-free and catch
  452. -     * them in stress testing instead of having to deal with a core
  453. -     * dump
  454. -     */
  455. -    crtsetdbgflags |= _CRTDBG_DELAY_FREE_MEM_DF;
  456. -#endif
  457. -    (void)_CrtSetDbgFlag(crtsetdbgflags);
  458. -    (void)_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
  459. -    (void)_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
  460. -    (void)_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
  461. -
  462. -    /*
  463. -     * Do not fill memory with 0xFE for functions like |strcpy_s()|
  464. -     * etc, as it causes bad performance. We have drmemory to find
  465. -     * issues like that instead
  466. -     */
  467. -    (void)_CrtSetDebugFillThreshold(0);
  468. -#pragma warning (push)
  469. -#pragma warning (disable : 4306) /* conversion from 'int' to '_HFILE' of greater size */
  470. -    _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
  471. -#pragma warning (pop)
  472. -    dprintf(1, "debug mode. dumping memory leaks to stderr on exit.\n");
  473. -#endif
  474.      /* acquire and store in global memory current dns domain name.
  475.       * needed for acls */
  476.      if (getdomainname()) {
  477. diff --git a/daemon/nfs41_daemon.h b/daemon/nfs41_daemon.h
  478. index 2023fdc..f89b281 100644
  479. --- a/daemon/nfs41_daemon.h
  480. +++ b/daemon/nfs41_daemon.h
  481. @@ -35,6 +35,9 @@ typedef struct __nfs41_daemon_globals {
  482.      int default_uid;
  483.      int default_gid;
  484.      ssize_t num_worker_threads;
  485. +    int crtdbgmem_flags;
  486.  } nfs41_daemon_globals;
  487.  
  488. +#define NFS41D_GLOBALS_CRTDBGMEM_FLAGS_NOT_SET (-1)
  489. +
  490.  #endif /* !__NFS41_DAEMON_H_ */
  491. --
  492. 2.42.1
  493.  
  494. From f27a0117921770d2ebbe2928360aae7d19a1944f Mon Sep 17 00:00:00 2001
  495. From: Roland Mainz <roland.mainz@nrubsig.org>
  496. Date: Mon, 18 Dec 2023 14:30:23 +0100
  497. Subject: [PATCH 6/8] cygwin/devel/msnfs41client.bash: Use --crtdbgmem none for
  498.  drmemory
  499.  
  500. Use nfsd_debug option --crtdbgmem none for drmemory debug mode.
  501.  
  502. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  503. ---
  504. cygwin/devel/msnfs41client.bash | 2 ++
  505.  1 file changed, 2 insertions(+)
  506.  
  507. diff --git a/cygwin/devel/msnfs41client.bash b/cygwin/devel/msnfs41client.bash
  508. index 130b508..0b4c703 100644
  509. --- a/cygwin/devel/msnfs41client.bash
  510. +++ b/cygwin/devel/msnfs41client.bash
  511. @@ -191,6 +191,7 @@ function nfsclient_rundeamon
  512.                                 '-preload_symbols'
  513.                                 '--'
  514.                                 "${nfsd_args[@]}"
  515. +                               '--crtdbgmem' 'none'
  516.                         )
  517.                 "${nfsd_args[@]}"
  518.         else
  519. @@ -271,6 +272,7 @@ function nfsclient_system_rundeamon
  520.                                 '-preload_symbols'
  521.                                 '--'
  522.                                 "${nfsd_args[@]}"
  523. +                               '--crtdbgmem' 'none'
  524.                         )
  525.                 "${nfsd_args[@]}"
  526.         else
  527. --
  528. 2.42.1
  529.  
  530. From 324df5036106de017e644cb8bd78666657babb5b Mon Sep 17 00:00:00 2001
  531. From: Roland Mainz <roland.mainz@nrubsig.org>
  532. Date: Mon, 18 Dec 2023 14:39:12 +0100
  533. Subject: [PATCH 7/8] mount,Cygwin/Makefile: Fix "Release" build failure+enable
  534.  Release build
  535.  
  536. Fix build failure in "Release" build caused by commit for
  537. "mount: nfs_mount.exe should always use debug allocator",
  538. and enable the "Release" build by default to avoid future issues
  539. like this.
  540.  
  541. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  542. ---
  543. cygwin/Makefile | 2 +-
  544.  mount/mount.c   | 1 -
  545.  mount/options.c | 2 --
  546.  3 files changed, 1 insertion(+), 4 deletions(-)
  547.  
  548. diff --git a/cygwin/Makefile b/cygwin/Makefile
  549. index 8eb25fa..e9207f6 100644
  550. --- a/cygwin/Makefile
  551. +++ b/cygwin/Makefile
  552. @@ -29,8 +29,8 @@ $(VS_BUILD_DIR)/nfsd.exe \
  553.  build:
  554.         @printf '#\n# PATH is %q\n#\n' '$(PATH)'
  555.         which MSBuild.exe
  556. +       MSBuild.exe '$(shell cygpath -w "$(PROJECT_BASEDIR_DIR)/build.vc19/nfs41-client.sln")' -t:Build  -p:Configuration=Release -p:Platform=x64
  557.         MSBuild.exe '$(shell cygpath -w "$(PROJECT_BASEDIR_DIR)/build.vc19/nfs41-client.sln")' -t:Build  -p:Configuration=Debug -p:Platform=x64
  558. -       #MSBuild.exe $(PROJECT_BASEDIR_DIR)/build.vc19/nfs41-client.sln -t:Build  -p:Configuration=Debug -p:Platform=x64
  559.         (cd tests/winfsinfo1 && make all)
  560.  
  561.  #
  562. diff --git a/mount/mount.c b/mount/mount.c
  563. index b06cac1..f8372e6 100644
  564. --- a/mount/mount.c
  565. +++ b/mount/mount.c
  566. @@ -20,7 +20,6 @@
  567.   * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  568.   */
  569.  
  570. -#define _DEBUG 1
  571.  
  572.  #include <crtdbg.h>
  573.  #include <Windows.h>
  574. diff --git a/mount/options.c b/mount/options.c
  575. index 53d0e37..53be68c 100644
  576. --- a/mount/options.c
  577. +++ b/mount/options.c
  578. @@ -19,8 +19,6 @@
  579.   * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  580.   */
  581.  
  582. -#define _DEBUG 1
  583. -
  584.  #include <crtdbg.h>
  585.  #include <Windows.h>
  586.  #include <tchar.h>
  587. --
  588. 2.42.1
  589.  
  590. From 51c7447599ff4d89667ffea1d87068ce8b940887 Mon Sep 17 00:00:00 2001
  591. From: Roland Mainz <roland.mainz@nrubsig.org>
  592. Date: Mon, 18 Dec 2023 16:16:50 +0100
  593. Subject: [PATCH 8/8] cygwin/devel/msnfs41client.bash: Enable "SegmentHeap"
  594.  allocator
  595.  
  596. Enable "SegmentHeap" allocator in registry for nfs_mount.exe,
  597. nfsd.exe and nfsd_debug.exe for testing.
  598.  
  599. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  600. ---
  601. cygwin/devel/msnfs41client.bash | 8 ++++++++
  602.  1 file changed, 8 insertions(+)
  603.  
  604. diff --git a/cygwin/devel/msnfs41client.bash b/cygwin/devel/msnfs41client.bash
  605. index 0b4c703..def9735 100644
  606. --- a/cygwin/devel/msnfs41client.bash
  607. +++ b/cygwin/devel/msnfs41client.bash
  608. @@ -93,6 +93,14 @@ function nfsclient_install
  609.         # (see https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation)
  610.         regtool -i set '/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/FileSystem/LongPathsEnabled' 1
  611.  
  612. +       # use the Win10 "SegmentHeap" (see https://www.blackhat.com/docs/us-16/materials/us-16-Yason-Windows-10-Segment-Heap-Internals.pdf)
  613. +       regtool add '/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Image File Execution Options/nfs_mount.exe'
  614. +       regtool -i set '/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Image File Execution Options/nfsd_debug.exe/FrontEndHeapDebugOptions' 0x08
  615. +       regtool add '/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Image File Execution Options/nfsd.exe'
  616. +       regtool -i set '/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Image File Execution Options/nfsd.exe/FrontEndHeapDebugOptions' 0x08
  617. +       regtool add '/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Image File Execution Options/nfs_mount.exe'
  618. +       regtool -i set '/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Image File Execution Options/nfs_mount.exe/FrontEndHeapDebugOptions' 0x08
  619. +
  620.         # make sure we can load the kernel driver
  621.         # (does not work with SecureBoot)
  622.         bcdedit /set testsigning on
  623. --
  624. 2.42.1

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at