pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch for ro-fs-return codes, clean pointes are RxFreePooled(), daemon with high prio etc., 2023-11-22
Posted by Anonymous on Wed 22nd Nov 2023 17:13
raw | new post

  1. From 1e1475d1a8cd14cabee68f38c990118390d43866 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Tue, 21 Nov 2023 23:36:19 +0100
  4. Subject: [PATCH 1/4] sys/nfs41_driver: Return STATUS_MEDIA_WRITE_PROTECTED for
  5.  "ro" mounts
  6.  
  7. Return STATUS_MEDIA_WRITE_PROTECTED for read-only mounts (instead of
  8. STATUS_ACCESS_DENIED), as other filesystems do and the Microsoft specs
  9. mandate.
  10.  
  11. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  12. ---
  13.  sys/nfs41_driver.c | 10 +++++-----
  14.  1 file changed, 5 insertions(+), 5 deletions(-)
  15.  
  16. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  17. index 0a04a6e..4e6b483 100644
  18. --- a/sys/nfs41_driver.c
  19. +++ b/sys/nfs41_driver.c
  20. @@ -3549,7 +3549,7 @@ NTSTATUS check_nfs41_create_args(
  21.  
  22.      if (pVNetRootContext->read_only &&
  23.              (params->DesiredAccess & (FILE_WRITE_DATA | FILE_APPEND_DATA))) {
  24. -        status = STATUS_NETWORK_ACCESS_DENIED;
  25. +        status = STATUS_MEDIA_WRITE_PROTECTED;
  26.          goto out;
  27.      }
  28.  
  29. @@ -4649,7 +4649,7 @@ NTSTATUS check_nfs41_setea_args(
  30.      }
  31.      if (pVNetRootContext->read_only) {
  32.          print_error("check_nfs41_setattr_args: Read-only mount\n");
  33. -        status = STATUS_ACCESS_DENIED;
  34. +        status = STATUS_MEDIA_WRITE_PROTECTED;
  35.          goto out;
  36.      }
  37.  out:
  38. @@ -5174,7 +5174,7 @@ NTSTATUS check_nfs41_setacl_args(
  39.  
  40.      if (pVNetRootContext->read_only) {
  41.          print_error("check_nfs41_setacl_args: Read-only mount\n");
  42. -        status = STATUS_ACCESS_DENIED;
  43. +        status = STATUS_MEDIA_WRITE_PROTECTED;
  44.          goto out;
  45.      }
  46.      /* we don't support sacls */
  47. @@ -5488,7 +5488,7 @@ NTSTATUS check_nfs41_setattr_args(
  48.  
  49.      if (pVNetRootContext->read_only) {
  50.          print_error("check_nfs41_setattr_args: Read-only mount\n");
  51. -        status = STATUS_ACCESS_DENIED;
  52. +        status = STATUS_MEDIA_WRITE_PROTECTED;
  53.          goto out;
  54.      }
  55.  
  56. @@ -5984,7 +5984,7 @@ NTSTATUS check_nfs41_write_args(
  57.  
  58.      if (pVNetRootContext->read_only) {
  59.          print_error("check_nfs41_write_args: Read-only mount\n");
  60. -        status = STATUS_ACCESS_DENIED;
  61. +        status = STATUS_MEDIA_WRITE_PROTECTED;
  62.          goto out;
  63.      }
  64.  out:
  65. --
  66. 2.42.1
  67.  
  68. From 473516870d1a6a9a977713918eaa20d5f143df6a Mon Sep 17 00:00:00 2001
  69. From: Roland Mainz <roland.mainz@nrubsig.org>
  70. Date: Wed, 22 Nov 2023 00:19:29 +0100
  71. Subject: [PATCH 2/4] sys/nfs41_driver: Set ptrs to NULL after passing them to
  72.  |RxFreePool()|
  73.  
  74. Set pointers passed to |RxFreePool()| to NULL afterwards, e.g.
  75. replace |RxFreePool(ptr);| by |RxFreePool(ptr); ptr = NULL;|.
  76. This fixes some potential use-after-free risks.
  77.  
  78. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  79. ---
  80.  sys/nfs41_driver.c | 8 +++++++-
  81.  1 file changed, 7 insertions(+), 1 deletion(-)
  82.  
  83. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  84. index 4e6b483..d9ae5a1 100644
  85. --- a/sys/nfs41_driver.c
  86. +++ b/sys/nfs41_driver.c
  87. @@ -1452,6 +1452,7 @@ NTSTATUS nfs41_UpcallCreate(
  88.                  "SeCreateClientSecurityFromSubjectContext failed with %x\n",
  89.                  status);
  90.              RxFreePool(entry);
  91. +           entry = NULL;
  92.          } else
  93.              entry->psec_ctx = &entry->sec_ctx;
  94.          SeReleaseSubjectContext(&sec_ctx);
  95. @@ -3303,6 +3304,7 @@ NTSTATUS nfs41_FinalizeNetRoot(
  96.          }
  97.          nfs41_RemoveEntry(pNetRootContext->mountLock, mount_tmp);
  98.          RxFreePool(mount_tmp);
  99. +        mount_tmp = NULL;
  100.      } while (1);
  101.      /* ignore any errors from unmount */
  102.      status = STATUS_SUCCESS;
  103. @@ -3758,6 +3760,7 @@ retry_on_link:
  104.          RtlCopyMemory(buf, entry->u.Open.symlink.Buffer,
  105.              entry->u.Open.symlink.Length);
  106.          RxFreePool(entry->u.Open.symlink.Buffer);
  107. +        entry->u.Open.symlink.Buffer = NULL;
  108.          buf += entry->u.Open.symlink.Length;
  109.          *(PWCHAR)buf = UNICODE_NULL;
  110.  
  111. @@ -4152,8 +4155,10 @@ NTSTATUS nfs41_DeallocateForFobx(
  112.      IN OUT PMRX_FOBX pFobx)
  113.  {
  114.      __notnull PNFS41_FOBX nfs41_fobx = NFS41GetFobxExtension(pFobx);
  115. -    if (nfs41_fobx->acl)
  116. +    if (nfs41_fobx->acl) {
  117.          RxFreePool(nfs41_fobx->acl);
  118. +        nfs41_fobx->acl = NULL;
  119. +    }
  120.      return STATUS_SUCCESS;
  121.  }
  122.  
  123. @@ -5135,6 +5140,7 @@ NTSTATUS nfs41_QuerySecurityInformation(
  124.          InterlockedAdd64(&getacl.size, entry->u.Acl.buf_len);
  125.  #endif
  126.          RxFreePool(entry->buf);
  127. +        entry->buf = NULL;
  128.          nfs41_fobx->acl = NULL;
  129.          nfs41_fobx->acl_len = 0;
  130.          RxContext->IoStatusBlock.Information = RxContext->InformationToReturn =
  131. --
  132. 2.42.1
  133.  
  134. From 81642a9e0427e2fdaf9ae0c2042049a5dbd63311 Mon Sep 17 00:00:00 2001
  135. From: Roland Mainz <roland.mainz@nrubsig.org>
  136. Date: Wed, 22 Nov 2023 00:30:50 +0100
  137. Subject: [PATCH 3/4] tests/manual_testing.txt: Update gcc procedures to catch
  138.  all configs
  139.  
  140. Update gcc manual testing procedure to catch&modify all ./configure
  141. and Makefile.in files.
  142.  
  143. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  144. ---
  145.  tests/manual_testing.txt | 8 ++++++--
  146.  1 file changed, 6 insertions(+), 2 deletions(-)
  147.  
  148. diff --git a/tests/manual_testing.txt b/tests/manual_testing.txt
  149. index 5f4b74a..3058c0b 100644
  150. --- a/tests/manual_testing.txt
  151. +++ b/tests/manual_testing.txt
  152. @@ -60,13 +60,17 @@ MSBuild.exe build.vc19/nfs41-client.sln -t:Build  -p:Configuration=Release -p:Pl
  153.  #
  154.  # gcc
  155.  #
  156. +
  157. +
  158.  git clone -b 'releases/gcc-13.2.0' git://gcc.gnu.org/git/gcc.git
  159.  cd gcc/
  160.  # Cygwin: workaround for configure using cp -p where ln -s should be used
  161. -sed -i "s/as_ln_s='cp -pR'/as_ln_s='ln -s'/g" configure
  162. +# (this is an automake/autoconf issue, they should trust Cygwin and not use
  163. +# ancient workarounds for issues which no longer exists)
  164. +(set -o xtrace ; sed -i "s/as_ln_s='cp -pR'/as_ln_s='ln -s'/g" $(find . -name configure) )
  165.  ./configure
  166.  # workaround for $ cp -p # failing with "Function not implemented"
  167. -(set -o xtrace ; sed -i -r 's/(cp.*)([[:space:]]+-p[[:space:]]+)/\1\2--no-preserve=ownership /g' $(find . -name Makefile) )
  168. +(set -o xtrace ; sed -i -r 's/(cp.*)([[:space:]]+-p[[:space:]]+)/\1\2--no-preserve=ownership /g' $(find . -name Makefile -o -name Makefile.in) )
  169.  # repeat:
  170.  make -j4 clean
  171.  (yes | make -j32 all)
  172. --
  173. 2.42.1
  174.  
  175. From 2ac6f86294da08490302e9469c47aa550319e146 Mon Sep 17 00:00:00 2001
  176. From: Roland Mainz <roland.mainz@nrubsig.org>
  177. Date: Wed, 22 Nov 2023 01:47:01 +0100
  178. Subject: [PATCH 4/4] daemon: Daemon should run with "high priority" to avoid
  179.  prio-inversion
  180.  
  181. The nfsd daemon should run with HIGH_PRIORITY_CLASS priority
  182. to avoid priority inversion issues if a high-priority process
  183. using the NFSv4 filesystem steals CPU time from the NFSv4 filesystem
  184. daemon on very busy systems.
  185.  
  186. Fixes build time issues with Cygwin/gcc parallel builds.
  187.  
  188. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  189. ---
  190.  daemon/nfs41_daemon.c | 12 ++++++++++++
  191.  1 file changed, 12 insertions(+)
  192.  
  193. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  194. index 4ab96d9..5e40a83 100644
  195. --- a/daemon/nfs41_daemon.c
  196. +++ b/daemon/nfs41_daemon.c
  197. @@ -428,6 +428,18 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  198.          exit(1);
  199.      }
  200.  
  201. +    /*
  202. +     * Set high priority class to avoid that the daemon gets stomped
  203. +     * by other processes, which might lead to some kind of priority
  204. +     * inversion
  205. +     */
  206. +    if(SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS)) {
  207. +        dprintf(0, "Running as HIGH_PRIORITY_CLASS\n");
  208. +    }
  209. +    else {
  210. +        eprintf("Failed to enter HIGH_PRIORITY_CLASS mode\n");
  211. +    }
  212. +
  213.  #ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  214.      /* force enable for cygwin getent passwd/group testing */
  215.      cmd_args.ldap_enable = TRUE;
  216. --
  217. 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