pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: libtirpc locking patches+misc, 2024-04-15
Posted by Anonymous on Mon 15th Apr 2024 15:00
raw | new post

  1. From ffa2f9440cccae29fb82039513bb4cecd31e0cfa Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Mon, 15 Apr 2024 14:21:40 +0200
  4. Subject: [PATCH 1/3] libtirpc: |authnone_marshal()| over-unlocks mutex
  5.  
  6. |authnone_marshal()| over-unlocks mutex, as detected with the
  7. Windows application (see
  8. https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/application-verifier)
  9. verifier.
  10.  
  11. Stack trace of the over-unlock event:
  12. ---- snip ----
  13. vrfcore!VerifierStopMessageEx+0x7f7
  14. vfbasics!VerifierStopMessage+0x1ad
  15. vfbasics!AVrfpVerifyCriticalSectionOwner+0x14a
  16. vfbasics!AVrfpRtlLeaveCriticalSection+0x91
  17. libtirpc!authnone_marshal(struct __auth * client = 0x000001ca`22ec2980, struct __rpc_xdr * xdrs = 0x000001ca`22ee9ca0, unsigned int * seq = 0x0000009f`794f8354)+0xa8 [C:\cygwin64\home\roland_mainz\work\msnfs41_uidmapping\ms-nfs41-client\libtirpc\src\auth_none.c @ 149]
  18. libtirpc!clnt_vc_call(struct __rpc_client * cl = 0x000001ca`22efc3f0, unsigned int proc = 0, <function> * xdr_args = 0x00007ff7`3093e8f2, void * args_ptr = 0x00000000`00000000, <function> * xdr_results = 0x00007ff7`3093e8f2, void * results_ptr = 0x00000000`00000000, struct timeval timeout = struct timeval)+0x1f0 [C:\cygwin64\home\roland_mainz\work\msnfs41_uidmapping\ms-nfs41-client\libtirpc\src\clnt_vc.c @ 575]
  19. nfsd!send_null(struct __rpc_client * client = 0x000001ca`22efc3f0)+0x64 [C:\cygwin64\home\roland_mainz\work\msnfs41_uidmapping\ms-nfs41-client\daemon\nfs41_rpc.c @ 40]
  20. nfsd!nfs41_rpc_clnt_create(struct __multi_addr4 * addrs = 0x0000009f`794fa130, unsigned int wsize = 0x10042c, unsigned int rsize = 0x100200, unsigned int uid = 0x303e8, unsigned int gid = 0x30201, unsigned int sec_flavor = 0, struct __nfs41_rpc_clnt ** rpc_out = 0x0000009f`794f8ed0)+0x15f [C:\cygwin64\home\roland_mainz\work\msnfs41_uidmapping\ms-nfs41-client\daemon\nfs41_rpc.c @ 185]
  21. nfsd!nfs41_root_mount_addrs(struct __nfs41_root * root = 0x000001ca`22ea3a00, struct __multi_addr4 * addrs = 0x0000009f`794fa130, int is_data = 0n0, unsigned int lease_time = 0, struct __nfs41_client ** client_out = 0x0000009f`794fa238)+0x117 [C:\cygwin64\home\roland_mainz\work\msnfs41_uidmapping\ms-nfs41-client\daemon\namespace.c @ 361]
  22. nfsd!handle_mount(void * daemon_context = 0x00007ff7`309b4010, struct __nfs41_upcall * upcall = 0x0000009f`794fe600)+0x2bc [C:\cygwin64\home\roland_mainz\work\msnfs41_uidmapping\ms-nfs41-client\daemon\mount.c @ 127]
  23. nfsd!upcall_handle(void * daemon_context = 0x00007ff7`309b4010, struct __nfs41_upcall * upcall = 0x0000009f`794fe600)+0x82 [C:\cygwin64\home\roland_mainz\work\msnfs41_uidmapping\ms-nfs41-client\daemon\upcall.c @ 190]
  24. nfsd!nfsd_worker_thread_main(void * args = 0x00007ff7`309b4010)+0x18b [C:\cygwin64\home\roland_mainz\work\msnfs41_uidmapping\ms-nfs41-client\daemon\nfs41_daemon.c @ 142]
  25. nfsd!nfsd_thread_main(void * args = 0x00007ff7`309b4010)+0x2b [C:\cygwin64\home\roland_mainz\work\msnfs41_uidmapping\ms-nfs41-client\daemon\nfs41_daemon.c @ 172]
  26. ucrtbased!thread_start<unsigned int (void * parameter = 0x000001ca`22ea9a30)+0xb0 [minkernel\crts\ucrt\src\appcrt\startup\thread.cpp @ 97]
  27. vfbasics!AVrfpStandardThreadFunction+0x4e
  28. KERNEL32!BaseThreadInitThunk+0x14
  29. ntdll!RtlUserThreadStart+0x21
  30. ---- snip ----
  31.  
  32. Reported-by: Dan Shelton <dan.f.shelton@gmail.com>
  33. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  34. ---
  35. libtirpc/src/auth_none.c | 4 ++++
  36.  1 file changed, 4 insertions(+)
  37.  
  38. diff --git a/libtirpc/src/auth_none.c b/libtirpc/src/auth_none.c
  39. index e2793c6..5e78ea4 100644
  40. --- a/libtirpc/src/auth_none.c
  41. +++ b/libtirpc/src/auth_none.c
  42. @@ -140,12 +140,16 @@ authnone_marshal(AUTH *client, XDR *xdrs, u_int *seq)
  43.  
  44.         ap = authnone_private;
  45.         if (ap == NULL) {
  46. +#if 0 /* gisburn: Disabled, causes mutex over-unlock */
  47.                 mutex_unlock(&authnone_lock);
  48. +#endif
  49.                 return (FALSE);
  50.         }
  51.         dummy = (*xdrs->x_ops->x_putbytes)(xdrs,
  52.             ap->marshalled_client, ap->mcnt);
  53. +#if 0 /* gisburn: Disabled, causes mutex over-unlock */
  54.         mutex_unlock(&authnone_lock);
  55. +#endif
  56.         return (dummy);
  57.  }
  58.  
  59. --
  60. 2.43.0
  61.  
  62. From 3964df57a2f3e17e3c667e1d82abe0b485983e8f Mon Sep 17 00:00:00 2001
  63. From: Roland Mainz <roland.mainz@nrubsig.org>
  64. Date: Mon, 15 Apr 2024 14:36:17 +0200
  65. Subject: [PATCH 2/3] libtirpc: Use |SRWLOCK| instead of |CRITICAL_SECTION| for
  66.  mutex locks
  67.  
  68. Use |SRWLOCK| instead of |CRITICAL_SECTION| for mutex locks, as
  69. it might be better suited how we use mutex-style locking in
  70. the libtirpc codebase.
  71.  
  72. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  73. ---
  74. libtirpc/src/mt_misc.c     | 44 +++++++++++++++++++-------------------
  75.  libtirpc/tirpc/reentrant.h | 33 +++++++++++++++++++++++++---
  76.  2 files changed, 52 insertions(+), 25 deletions(-)
  77.  
  78. diff --git a/libtirpc/src/mt_misc.c b/libtirpc/src/mt_misc.c
  79. index 58d8522..815b590 100644
  80. --- a/libtirpc/src/mt_misc.c
  81. +++ b/libtirpc/src/mt_misc.c
  82. @@ -104,31 +104,31 @@ mutex_t nc_lock;
  83.  
  84.  #ifdef _WIN32
  85.  /*
  86. - * Initialize all the mutexes (CriticalSections)
  87. + * Initialize all the mutexes (CriticalSections or SRWLOCK)
  88.   */
  89.  void multithread_init(void)
  90.  {
  91. -       InitializeCriticalSection(&authdes_lock);
  92. -       InitializeCriticalSection(&authdes_ops_lock);
  93. -       InitializeCriticalSection(&svcauthdesstats_lock);
  94. -       InitializeCriticalSection(&authnone_lock);
  95. -       InitializeCriticalSection(&authsvc_lock);
  96. -       InitializeCriticalSection(&clnt_fd_lock);
  97. -       InitializeCriticalSection(&clntraw_lock);
  98. -       InitializeCriticalSection(&dname_lock);
  99. -       InitializeCriticalSection(&dupreq_lock);
  100. -       InitializeCriticalSection(&keyserv_lock);
  101. -       InitializeCriticalSection(&libnsl_trace_lock);
  102. -       InitializeCriticalSection(&loopnconf_lock);
  103. -       InitializeCriticalSection(&ops_lock);
  104. -       InitializeCriticalSection(&portnum_lock);
  105. -       InitializeCriticalSection(&proglst_lock);
  106. -       InitializeCriticalSection(&rpcsoc_lock);
  107. -       InitializeCriticalSection(&svcraw_lock);
  108. -       InitializeCriticalSection(&tsd_lock);
  109. -       InitializeCriticalSection(&xprtlist_lock);
  110. -       InitializeCriticalSection(&serialize_pkey);
  111. -       InitializeCriticalSection(&nc_lock);
  112. +       mutex_init(&authdes_lock, 0);
  113. +       mutex_init(&authdes_ops_lock, 0);
  114. +       mutex_init(&svcauthdesstats_lock, 0);
  115. +       mutex_init(&authnone_lock, 0);
  116. +       mutex_init(&authsvc_lock, 0);
  117. +       mutex_init(&clnt_fd_lock, 0);
  118. +       mutex_init(&clntraw_lock, 0);
  119. +       mutex_init(&dname_lock, 0);
  120. +       mutex_init(&dupreq_lock, 0);
  121. +       mutex_init(&keyserv_lock, 0);
  122. +       mutex_init(&libnsl_trace_lock, 0);
  123. +       mutex_init(&loopnconf_lock, 0);
  124. +       mutex_init(&ops_lock, 0);
  125. +       mutex_init(&portnum_lock, 0);
  126. +       mutex_init(&proglst_lock, 0);
  127. +       mutex_init(&rpcsoc_lock, 0);
  128. +       mutex_init(&svcraw_lock, 0);
  129. +       mutex_init(&tsd_lock, 0);
  130. +       mutex_init(&xprtlist_lock, 0);
  131. +       mutex_init(&serialize_pkey, 0);
  132. +       mutex_init(&nc_lock, 0);
  133.  }
  134.  #endif
  135.  
  136. diff --git a/libtirpc/tirpc/reentrant.h b/libtirpc/tirpc/reentrant.h
  137. index c81d1a0..a3632d2 100644
  138. --- a/libtirpc/tirpc/reentrant.h
  139. +++ b/libtirpc/tirpc/reentrant.h
  140. @@ -92,6 +92,7 @@
  141.   *
  142.   * Olga Kornievskaia <aglo@umich.edu>
  143.   * Casey Bodley <cbodley@umich.edu>
  144. + * Roland Mainz <roland.mainz@nrubsig.org>
  145.   *
  146.   * This library is free software; you can redistribute it and/or modify it
  147.   * under the terms of the GNU Lesser General Public License as published by
  148. @@ -115,25 +116,51 @@
  149.  
  150.  #include <stdlib.h>
  151.  
  152. +/*
  153. + * |USE_SRWLOCK_FOR_MUTEX| - Use SRWLOCK for |mutex_t| instead of a
  154. + * |CRITICAL_SECTION|
  155. + */
  156. +#define USE_SRWLOCK_FOR_MUTEX 1
  157.  
  158. +#ifdef USE_SRWLOCK_FOR_MUTEX
  159. +#define mutex_t                                SRWLOCK
  160. +#else
  161.  #define mutex_t                                CRITICAL_SECTION
  162. +#endif /* USE_SRWLOCK_FOR_MUTEX */
  163.  #define cond_t                         CONDITION_VARIABLE
  164.  #define rwlock_t                       SRWLOCK
  165.  
  166.  
  167.  #define thread_key_t           DWORD
  168. +#ifdef USE_SRWLOCK_FOR_MUTEX
  169. +#define MUTEX_INITIALIZER      SRWLOCK_INIT
  170. +#else
  171.  #define MUTEX_INITIALIZER      -1 /*THIS_NEEDS_HELP*/
  172. -#define RWLOCK_INITIALIZER     -1 /*THIS_NEEDS_HELP*/
  173. +#endif /* USE_SRWLOCK_FOR_MUTEX */
  174. +#define RWLOCK_INITIALIZER     SRWLOCK_INIT
  175. +
  176. +#ifdef USE_SRWLOCK_FOR_MUTEX
  177. +#define mutex_init(m, a)       InitializeSRWLock(m)
  178. +#define mutex_lock(m)          AcquireSRWLockExclusive(m)
  179. +#define mutex_unlock(m)                ReleaseSRWLockExclusive(m)
  180. +#define mutex_trylock(m)       TryAcquireSRWLockExclusive(m)
  181. +#else
  182.  #define mutex_init(m, a)       InitializeCriticalSection(m)
  183.  #define mutex_lock(m)          EnterCriticalSection(m)
  184.  #define mutex_unlock(m)                LeaveCriticalSection(m)
  185.  #define mutex_trylock(m)       TryEnterCriticalSection(m)
  186. +#endif /* USE_SRWLOCK_FOR_MUTEX */
  187.  
  188.  #define cond_init(c, a, p)             InitializeConditionVariable(c)
  189.  #define cond_signal(m)                 WakeConditionVariable(m)
  190.  #define cond_broadcast(m)              WakeAllConditionVariable(m)
  191. -#define cond_wait(c, m)                        SleepConditionVariableCS(c, m, INFINITE)
  192. -#define cond_wait_timed(c, m, t) SleepConditionVariableCS(c, m, t)
  193. +#ifdef USE_SRWLOCK_FOR_MUTEX
  194. +#define cond_wait(c, m)                        SleepConditionVariableSRW((c), (m), INFINITE, 0)
  195. +#define cond_wait_timed(c, m, t)       SleepConditionVariableSRW((c), (m), (t), 0)
  196. +#else
  197. +#define cond_wait(c, m)                        SleepConditionVariableCS((c), (m), INFINITE)
  198. +#define cond_wait_timed(c, m, t)       SleepConditionVariableCS((c), (m), (t))
  199. +#endif /* USE_SRWLOCK_FOR_MUTEX */
  200.  
  201.  #define rwlock_init(l, a)              InitializeSRWLock(l)
  202.  #define rwlock_rdlock(l)               AcquireSRWLockShared(l)
  203. --
  204. 2.43.0
  205.  
  206. From 7e319663050b8bdf8a104e0ef88602dff8cbb652 Mon Sep 17 00:00:00 2001
  207. From: Roland Mainz <roland.mainz@nrubsig.org>
  208. Date: Mon, 15 Apr 2024 15:11:28 +0200
  209. Subject: [PATCH 3/3] cygwin: bintarball readme: Update required Cygwin version
  210.  from "3.5.1" to "3.5.3"
  211.  
  212. Update required Cygwin version in cygwin/README.bintarball.txt from
  213. "3.5.1" to "3.5.3".
  214.  
  215. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  216. ---
  217. cygwin/README.bintarball.txt | 2 +-
  218.  1 file changed, 1 insertion(+), 1 deletion(-)
  219.  
  220. diff --git a/cygwin/README.bintarball.txt b/cygwin/README.bintarball.txt
  221. index bc0209d..c0c2bf3 100644
  222. --- a/cygwin/README.bintarball.txt
  223. +++ b/cygwin/README.bintarball.txt
  224. @@ -68,7 +68,7 @@ NFSv4.1 client and filesystem driver for Windows 10/11
  225.  # 3. Requirements:
  226.  #
  227.  - Windows 10 or Windows 11
  228. -- Cygwin 3.5.1 (or 3.6.x-devel)
  229. +- Cygwin 3.5.3 (or 3.6.x-devel)
  230.      - Packages (required):
  231.          cygwin
  232.          cygwin-devel
  233. --
  234. 2.43.0

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