pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches for handling write-only open requests, fix pagelock+mem leaks+misc, 2024-12-19
Posted by Anonymous on Thu 19th Dec 2024 12:44
raw | new post

  1. From 4c321e5efeffd1273fae6961e544b59c78754bf3 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Thu, 19 Dec 2024 11:56:24 +0100
  4. Subject: [PATCH 1/3] sys: Add |PagedPool| support to our version of the
  5.  |RxAllocatePoolWithTag()| macro
  6.  
  7. Add |PagedPool| support to our |ExAllocatePool2()|-based version of the
  8. |RxAllocatePoolWithTag()| macro.
  9.  
  10. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  11. ---
  12. sys/nfs41sys_driver.h | 6 ++++--
  13.  1 file changed, 4 insertions(+), 2 deletions(-)
  14.  
  15. diff --git a/sys/nfs41sys_driver.h b/sys/nfs41sys_driver.h
  16. index 1c39ab6..0e0107c 100644
  17. --- a/sys/nfs41sys_driver.h
  18. +++ b/sys/nfs41sys_driver.h
  19. @@ -48,8 +48,10 @@
  20.      (POOL_FLAG_UNINITIALIZED|POOL_FLAG_CACHE_ALIGNED)
  21.  
  22.  #define RxAllocatePoolWithTag(rxallocpool, numbytes, tag) \
  23. -    ExAllocatePool2(((((rxallocpool) == NonPagedPoolNx)? \
  24. -            POOL_FLAG_NON_PAGED:POOL_FLAG_NON_PAGED_EXECUTE) | \
  25. +    ExAllocatePool2((( \
  26. +            ((rxallocpool) == PagedPool)?POOL_FLAG_PAGED: \
  27. +                (((rxallocpool) == NonPagedPoolNx)? \
  28. +                    POOL_FLAG_NON_PAGED:POOL_FLAG_NON_PAGED_EXECUTE)) | \
  29.              RXALLOCATEPOOL_DEFAULT_ALLOCATEPOOL2FLAGS), \
  30.          (numbytes), (tag))
  31.  #endif /* EXALLOCATEPOOLWITHTAG_DEPRECATED */
  32. --
  33. 2.45.1
  34.  
  35. From e583e149fb36ced6d8ee83f7a60c79a092ffe252 Mon Sep 17 00:00:00 2001
  36. From: Roland Mainz <roland.mainz@nrubsig.org>
  37. Date: Thu, 19 Dec 2024 12:19:41 +0100
  38. Subject: [PATCH 2/3] sys,tests: File open with write-only desired access
  39.  should turn-off write caching
  40.  
  41. File open with write-only desired access should turn-off write caching,
  42. otherwise we might end-up with blocks of zero-bytes in the file instead
  43. of valid data.
  44.  
  45. This fixes issues with tools like Win10 /cygdrive/c/Windows/system32/tar,
  46. which uses write-only handles and had $'\0'-bytes in plain text files
  47. when unpacking files.
  48.  
  49. Testing:
  50. If we do not turn off write caching in this case "wintartest_seq001.bash"
  51. will fail like this (might require a few hundred cycles, and only fails
  52. on a freshly booted machine, e.g. this bug includes a race-condition!):
  53. -------- snip --------
  54. x 1seq.txt
  55. x 100seq.txt
  56. x 1040seq.txt
  57. x 5000seq.txt
  58. x 10000seq.txt
  59. x 12000seq.txt
  60. x 1seq.txt
  61. x 100seq.txt
  62. x 1040seq.txt
  63. x 5000seq.txt
  64. x 10000seq.txt
  65. x 12000seq.txt
  66. ---- snip ----
  67. 000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  68. 000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  69. 000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  70. 000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  71. 000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  72. ---- snip ----
  73. -------- snip --------
  74.  
  75. Thanks to Hermes Belusca-Maito <hermes.belusca-maito@reactos.org>
  76. for helping a lot to hunt this bug down.
  77.  
  78. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  79. ---
  80. sys/nfs41sys_openclose.c | 22 ++++++++++++++++++++++
  81.  tests/manual_testing.txt | 34 +++++++++++++++++++++++++++++++++-
  82.  2 files changed, 55 insertions(+), 1 deletion(-)
  83.  
  84. diff --git a/sys/nfs41sys_openclose.c b/sys/nfs41sys_openclose.c
  85. index 86473e5..794aeee 100644
  86. --- a/sys/nfs41sys_openclose.c
  87. +++ b/sys/nfs41sys_openclose.c
  88. @@ -333,6 +333,15 @@ static BOOLEAN isOpen2Create(
  89.      return FALSE;
  90.  }
  91.  
  92. +static BOOLEAN isWriteOnlyDesiredAccess(PNT_CREATE_PARAMETERS params)
  93. +{
  94. +    if (((params->DesiredAccess & (FILE_EXECUTE|FILE_READ_DATA)) == 0) &&
  95. +        ((params->DesiredAccess & (FILE_WRITE_DATA|FILE_APPEND_DATA)) != 0)) {
  96. +        return TRUE;
  97. +    }
  98. +    return FALSE;
  99. +}
  100. +
  101.  static BOOLEAN areOpenParamsValid(NT_CREATE_PARAMETERS *params)
  102.  {
  103.      /* from ms-fsa page 52 */
  104. @@ -851,6 +860,19 @@ retry_on_link:
  105.  #ifdef DEBUG_OPEN
  106.          DbgP("nfs41_Create: received delegation %d\n", entry->u.Open.deleg_type);
  107.  #endif
  108. +
  109. +        /*
  110. +         * We cannot have a file cached on a write-only handle,
  111. +         * so we have to set |SRVOPEN_FLAG_DONTUSE_WRITE_CACHING|
  112. +         * in this case.
  113. +         */
  114. +        if (isWriteOnlyDesiredAccess(params)) {
  115. +            SrvOpen->Flags |= SRVOPEN_FLAG_DONTUSE_WRITE_CACHING;
  116. +            DbgP("nfs41_Create: write-only handle for file '%wZ', "
  117. +                "setting SRVOPEN_FLAG_DONTUSE_WRITE_CACHING\n",
  118. +                SrvOpen->pAlreadyPrefixedName);
  119. +        }
  120. +
  121.          if (!(params->CreateOptions & FILE_WRITE_THROUGH) &&
  122.                  !pVNetRootContext->write_thru &&
  123.                  (entry->u.Open.deleg_type == 2 ||
  124. diff --git a/tests/manual_testing.txt b/tests/manual_testing.txt
  125. index 48614f2..6ee7186 100644
  126. --- a/tests/manual_testing.txt
  127. +++ b/tests/manual_testing.txt
  128. @@ -1,5 +1,5 @@
  129.  #
  130. -# ms-nfs41-client manual testing sequence, 2024-07-04
  131. +# ms-nfs41-client manual testing sequence, 2024-12-19
  132.  #
  133.  # Draft version, needs to be turned into automated tests
  134.  # if possible
  135. @@ -456,6 +456,38 @@ drmemory -batch -check_uninit_all -strict_bitops -logdir "$(cygpath -w "$PWD")"
  136.  # Run Windows tar (/cygdrive/c/Windows/system32/tar) tests
  137.  # on NFSv4.1 filesystem
  138.  #
  139. +# Notes:
  140. +# - Win10 /cygdrive/c/Windows/system32/tar uses write-only handles
  141. +#   which should turn-off write caching. If we do not turn off
  142. +#   write caching in this case "wintartest_seq001.bash" will fail
  143. +#   like this (might require a few hundred cycles, and only fails
  144. +#   on a freshly booted machine):
  145. +#   -------- snip --------
  146. +#   #### Test cycle 11 (usingbzip=true,tarfileonlocaldisk=true):
  147. +#   x 1seq.txt
  148. +#   x 100seq.txt
  149. +#   x 1040seq.txt
  150. +#   x 5000seq.txt
  151. +#   x 10000seq.txt
  152. +#   x 12000seq.txt
  153. +#   #### Test cycle 12 (usingbzip=true,tarfileonlocaldisk=true):
  154. +#   x 1seq.txt
  155. +#   x 100seq.txt
  156. +#   x 1040seq.txt
  157. +#   x 5000seq.txt
  158. +#   x 10000seq.txt
  159. +#   x 12000seq.txt
  160. +#   ## ERROR: Zero byte in plain /usr/bin/seq output 10000seq.txt found:
  161. +#   ---- snip ----
  162. +#   000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  163. +#   000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  164. +#   000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  165. +#   000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  166. +#   000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  167. +#   ---- snip ----
  168. +#   -------- snip --------
  169. +#
  170. +#
  171.  
  172.  cd /cygdrive/n/xxx/
  173.  bash /usr/share/msnfs41client/tests/misc/wintartests/wintartest_seq001.bash
  174. --
  175. 2.45.1
  176.  
  177. From 8be4753af5e39b365584c71dbaa1820ee520cbc3 Mon Sep 17 00:00:00 2001
  178. From: Roland Mainz <roland.mainz@nrubsig.org>
  179. Date: Thu, 19 Dec 2024 12:50:39 +0100
  180. Subject: [PATCH 3/3] sys: Fix locked page+memory "leaks" in
  181.  |nfs41_QueryDirectory()|+|nfs41_Create()| error codepaths
  182.  
  183. Fix locked page+memory "leaks" in |nfs41_QueryDirectory()| and
  184. |nfs41_Create()| error codepaths.
  185.  
  186. Reported-by: Hermes Belusca-Maito <hermes.belusca-maito@reactos.org>
  187. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  188. ---
  189. sys/nfs41sys_dir.c       | 4 +++-
  190.  sys/nfs41sys_openclose.c | 4 +++-
  191.  2 files changed, 6 insertions(+), 2 deletions(-)
  192.  
  193. diff --git a/sys/nfs41sys_dir.c b/sys/nfs41sys_dir.c
  194. index 815904a..fee2847 100644
  195. --- a/sys/nfs41sys_dir.c
  196. +++ b/sys/nfs41sys_dir.c
  197. @@ -288,9 +288,11 @@ NTSTATUS nfs41_QueryDirectory(
  198.      entry->u.QueryFile.return_single = RxContext->QueryDirectory.ReturnSingleEntry;
  199.  
  200.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  201. -    if (status) goto out;
  202. +
  203.      MmUnlockPages(entry->u.QueryFile.mdl);
  204.  
  205. +    if (status) goto out;
  206. +
  207.      if (entry->status == STATUS_BUFFER_TOO_SMALL) {
  208.          DbgP("nfs41_QueryDirectory: buffer too small provided %d need %lu\n",
  209.              RxContext->Info.LengthRemaining, entry->buf_len);
  210. diff --git a/sys/nfs41sys_openclose.c b/sys/nfs41sys_openclose.c
  211. index 794aeee..d2624e7 100644
  212. --- a/sys/nfs41sys_openclose.c
  213. +++ b/sys/nfs41sys_openclose.c
  214. @@ -690,17 +690,19 @@ retry_on_link:
  215.      }
  216.  
  217.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  218. +
  219.      if (entry->psec_ctx == &entry->sec_ctx) {
  220.          SeDeleteClientSecurity(entry->psec_ctx);
  221.      }
  222.      entry->psec_ctx = NULL;
  223. -    if (status) goto out;
  224.  
  225.      if (entry->u.Open.EaMdl) {
  226.          MmUnlockPages(entry->u.Open.EaMdl);
  227.          IoFreeMdl(entry->u.Open.EaMdl);
  228.      }
  229.  
  230. +    if (status) goto out;
  231. +
  232.      if (entry->status == NO_ERROR && entry->errno == ERROR_REPARSE) {
  233.          /* symbolic link handling. when attempting to open a symlink when the
  234.           * FILE_OPEN_REPARSE_POINT flag is not set, replace the filename with
  235. --
  236. 2.45.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