pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch for kernel impersonation+misc, 2024-04-30
Posted by Anonymous on Tue 30th Apr 2024 16:28
raw | new post

  1. From 392c0769f193a22ea6c4a8aa645055e87ab29f4b Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Tue, 30 Apr 2024 15:36:58 +0200
  4. Subject: [PATCH 1/5] daemon: SID cache should reuse entries which have the
  5.  same "win32name"
  6.  
  7. SID cache should reuse entries which have the same "win32name".
  8. This avoids cache thrashing if multile threads write the same
  9. data into the cache.
  10.  
  11. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  12. ---
  13. daemon/sid.c | 10 +++++++++-
  14.  1 file changed, 9 insertions(+), 1 deletion(-)
  15.  
  16. diff --git a/daemon/sid.c b/daemon/sid.c
  17. index 1716fd5..7e3f3d4 100644
  18. --- a/daemon/sid.c
  19. +++ b/daemon/sid.c
  20. @@ -233,7 +233,15 @@ void sidcache_add(sidcache *cache, const char* win32name, PSID value)
  21.      /* Find the oldest valid cache entry */
  22.      freeEntryIndex = -1;
  23.      for (i = 0; i < SIDCACHE_SIZE; i++) {
  24. -        if (cache->entries[i].sid == NULL) {
  25. +        if (cache->entries[i].sid) {
  26. +            /* Same name ? Then reuse this slot... */
  27. +            if (!strcmp(cache->entries[i].win32name, win32name)) {
  28. +                freeEntryIndex = i;
  29. +                break;
  30. +            }
  31. +        }
  32. +        else {
  33. +            /* (cache->entries[i].sid == NULL) --> empty slot... */
  34.              freeEntryIndex = i;
  35.              break;
  36.          }
  37. --
  38. 2.43.0
  39.  
  40. From 3ca2252f4c21205c16d13e0d7c3b5399f1ad58f1 Mon Sep 17 00:00:00 2001
  41. From: Roland Mainz <roland.mainz@nrubsig.org>
  42. Date: Tue, 30 Apr 2024 15:43:01 +0200
  43. Subject: [PATCH 2/5] sys: Use |SECURITY_STATIC_TRACKING| instead of
  44.  |SECURITY_DYNAMIC_TRACKING|
  45.  
  46. Use |SECURITY_STATIC_TRACKING| instead of |SECURITY_DYNAMIC_TRACKING|
  47. for impersonation, to handle cases where the client thread we impersonate
  48. gets destroyed before we can impersonate it.
  49.  
  50. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  51. ---
  52. sys/nfs41_driver.c | 4 ++--
  53.  1 file changed, 2 insertions(+), 2 deletions(-)
  54.  
  55. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  56. index 21d6e6d..bbce1d7 100644
  57. --- a/sys/nfs41_driver.c
  58. +++ b/sys/nfs41_driver.c
  59. @@ -1545,7 +1545,7 @@ NTSTATUS nfs41_UpcallCreate(
  60.  
  61.      if (clnt_sec_ctx == NULL) {
  62.          SeCaptureSubjectContext(&sec_ctx);
  63. -        sec_qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
  64. +        sec_qos.ContextTrackingMode = SECURITY_STATIC_TRACKING;
  65.          sec_qos.ImpersonationLevel = SecurityImpersonation;
  66.          sec_qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
  67.          sec_qos.EffectiveOnly = 0;
  68. @@ -3009,7 +3009,7 @@ NTSTATUS nfs41_GetLUID(
  69.      SECURITY_CLIENT_CONTEXT clnt_sec_ctx;
  70.  
  71.      SeCaptureSubjectContext(&sec_ctx);
  72. -    sec_qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
  73. +    sec_qos.ContextTrackingMode = SECURITY_STATIC_TRACKING;
  74.      sec_qos.ImpersonationLevel = SecurityIdentification;
  75.      sec_qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
  76.      sec_qos.EffectiveOnly = 0;
  77. --
  78. 2.43.0
  79.  
  80. From 26e7b86b963610db045ef42da237f557ed730a41 Mon Sep 17 00:00:00 2001
  81. From: Roland Mainz <roland.mainz@nrubsig.org>
  82. Date: Tue, 30 Apr 2024 16:09:52 +0200
  83. Subject: [PATCH 3/5] sys: Set |entry->psec_ctx = NULL;| after
  84.  |SeDeleteClientSecurity()|
  85.  
  86. Set |entry->psec_ctx = NULL| after |SeDeleteClientSecurity()|,
  87. to avoid use-after-free.
  88.  
  89. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  90. ---
  91. sys/nfs41_driver.c | 27 ++++++++++++++++++++-------
  92.  1 file changed, 20 insertions(+), 7 deletions(-)
  93.  
  94. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  95. index bbce1d7..3ca6ea6 100644
  96. --- a/sys/nfs41_driver.c
  97. +++ b/sys/nfs41_driver.c
  98. @@ -1549,16 +1549,17 @@ NTSTATUS nfs41_UpcallCreate(
  99.          sec_qos.ImpersonationLevel = SecurityImpersonation;
  100.          sec_qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
  101.          sec_qos.EffectiveOnly = 0;
  102. +        entry->psec_ctx = &entry->sec_ctx;
  103.          status = SeCreateClientSecurityFromSubjectContext(&sec_ctx, &sec_qos,
  104. -                    1, &entry->sec_ctx);
  105. +                    1, entry->psec_ctx);
  106.          if (status != STATUS_SUCCESS) {
  107.              print_error("nfs41_UpcallCreate: "
  108.                  "SeCreateClientSecurityFromSubjectContext failed with %x\n",
  109.                  status);
  110.              RxFreePool(entry);
  111.             entry = NULL;
  112. -        } else
  113. -            entry->psec_ctx = &entry->sec_ctx;
  114. +        }
  115. +
  116.          SeReleaseSubjectContext(&sec_ctx);
  117.      } else
  118.          entry->psec_ctx = clnt_sec_ctx;
  119. @@ -2106,7 +2107,10 @@ NTSTATUS nfs41_shutdown_daemon(
  120.      if (status) goto out;
  121.  
  122.      status = nfs41_UpcallWaitForReply(entry, UPCALL_TIMEOUT_DEFAULT);
  123. -    SeDeleteClientSecurity(&entry->sec_ctx);
  124. +    if (entry->psec_ctx == &entry->sec_ctx) {
  125. +        SeDeleteClientSecurity(entry->psec_ctx);
  126. +    }
  127. +    entry->psec_ctx = NULL;
  128.      if (status) goto out;
  129.  
  130.      RxFreePool(entry);
  131. @@ -2365,7 +2369,10 @@ NTSTATUS nfs41_unmount(
  132.  #endif
  133.      status = nfs41_UpcallCreate(NFS41_UNMOUNT, NULL, session,
  134.          INVALID_HANDLE_VALUE, version, NULL, &entry);
  135. -    SeDeleteClientSecurity(&entry->sec_ctx);
  136. +    if (entry->psec_ctx == &entry->sec_ctx) {
  137. +        SeDeleteClientSecurity(entry->psec_ctx);
  138. +    }
  139. +    entry->psec_ctx = NULL;
  140.      if (status) goto out;
  141.  
  142.      nfs41_UpcallWaitForReply(entry, timeout);
  143. @@ -2748,7 +2755,10 @@ NTSTATUS nfs41_mount(
  144.      entry->u.Mount.FsAttrs = FsAttrs;
  145.  
  146.      status = nfs41_UpcallWaitForReply(entry, config->timeout);
  147. -    SeDeleteClientSecurity(&entry->sec_ctx);
  148. +    if (entry->psec_ctx == &entry->sec_ctx) {
  149. +        SeDeleteClientSecurity(entry->psec_ctx);
  150. +    }
  151. +    entry->psec_ctx = NULL;
  152.      if (status) goto out;
  153.      *session = entry->session;
  154.      if (entry->u.Mount.lease_time > config->timeout)
  155. @@ -3937,7 +3947,10 @@ retry_on_link:
  156.  
  157.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  158.  #ifndef USE_MOUNT_SEC_CONTEXT
  159. -    SeDeleteClientSecurity(&entry->sec_ctx);
  160. +    if (entry->psec_ctx == &entry->sec_ctx) {
  161. +        SeDeleteClientSecurity(entry->psec_ctx);
  162. +    }
  163. +    entry->psec_ctx = NULL;
  164.  #endif
  165.      if (status) goto out;
  166.  
  167. --
  168. 2.43.0
  169.  
  170. From 9d85234de0be630f494f288c210c732ffd40745d Mon Sep 17 00:00:00 2001
  171. From: Roland Mainz <roland.mainz@nrubsig.org>
  172. Date: Tue, 30 Apr 2024 16:31:42 +0200
  173. Subject: [PATCH 4/5] sys: Fix kernel crash (illegal object reference count)
  174.  during unmount
  175.  
  176. Fix "illegal object reference count" kernel crash during unmount,
  177. caused by doing a |SeDeleteClientSecurity()| before doing the unmount
  178. upcall which would use this |SECURITY_CLIENT_CONTEXT|
  179.  
  180. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  181. ---
  182. sys/nfs41_driver.c | 7 ++++---
  183.  1 file changed, 4 insertions(+), 3 deletions(-)
  184.  
  185. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  186. index 3ca6ea6..cd7bb84 100644
  187. --- a/sys/nfs41_driver.c
  188. +++ b/sys/nfs41_driver.c
  189. @@ -2369,13 +2369,14 @@ NTSTATUS nfs41_unmount(
  190.  #endif
  191.      status = nfs41_UpcallCreate(NFS41_UNMOUNT, NULL, session,
  192.          INVALID_HANDLE_VALUE, version, NULL, &entry);
  193. +    if (status) goto out;
  194. +
  195. +    nfs41_UpcallWaitForReply(entry, timeout);
  196. +
  197.      if (entry->psec_ctx == &entry->sec_ctx) {
  198.          SeDeleteClientSecurity(entry->psec_ctx);
  199.      }
  200.      entry->psec_ctx = NULL;
  201. -    if (status) goto out;
  202. -
  203. -    nfs41_UpcallWaitForReply(entry, timeout);
  204.      RxFreePool(entry);
  205.  out:
  206.  #ifdef ENABLE_TIMINGS
  207. --
  208. 2.43.0
  209.  
  210. From 7f76988b1fdd9fd373f065bff517ad5e5066ac2a Mon Sep 17 00:00:00 2001
  211. From: Roland Mainz <roland.mainz@nrubsig.org>
  212. Date: Tue, 30 Apr 2024 16:54:29 +0200
  213. Subject: [PATCH 5/5] sys: Disable |STORE_MOUNT_SEC_CONTEXT|, we do not use
  214.  this data
  215.  
  216. Disable |STORE_MOUNT_SEC_CONTEXT|, we do not use this data
  217.  
  218. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  219. ---
  220. sys/nfs41_driver.c | 5 +++--
  221.  1 file changed, 3 insertions(+), 2 deletions(-)
  222.  
  223. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  224. index cd7bb84..c1ddcfd 100644
  225. --- a/sys/nfs41_driver.c
  226. +++ b/sys/nfs41_driver.c
  227. @@ -48,7 +48,8 @@
  228.   * that
  229.   */
  230.  #ifndef NFS41_DRIVER_SETGID_NEWGRP_SUPPORT
  231. -#define USE_MOUNT_SEC_CONTEXT
  232. +#define USE_MOUNT_SEC_CONTEXT 1
  233. +#define STORE_MOUNT_SEC_CONTEXT 1
  234.  #endif
  235.  
  236.  /* debugging printout defines */
  237. @@ -395,7 +396,7 @@ typedef struct _NFS41_V_NET_ROOT_EXTENSION {
  238.      BOOLEAN                 read_only;
  239.      BOOLEAN                 write_thru;
  240.      BOOLEAN                 nocache;
  241. -#define STORE_MOUNT_SEC_CONTEXT
  242. +
  243.  #ifdef STORE_MOUNT_SEC_CONTEXT
  244.      SECURITY_CLIENT_CONTEXT mount_sec_ctx;
  245.  #endif
  246. --
  247. 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