pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Fix for secctx leak, 32bit build+misc, 2024-05-11
Posted by Anonymous on Sat 11th May 2024 14:25
raw | new post

  1. From 381122b4802589e8878be80126ee6257c6fd7ff7 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Sat, 11 May 2024 13:33:54 +0200
  4. Subject: [PATCH 1/4] tests: Add support for |FileNormalizedNameInfo| to
  5.  tests/winfsinfo1
  6.  
  7. Add support for |FileNormalizedNameInfo| to tests/winfsinfo1
  8.  
  9. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  10. ---
  11. tests/winfsinfo1/winfsinfo.c | 74 +++++++++++++++++++++++++++++++++++-
  12.  1 file changed, 73 insertions(+), 1 deletion(-)
  13.  
  14. diff --git a/tests/winfsinfo1/winfsinfo.c b/tests/winfsinfo1/winfsinfo.c
  15. index 3c5a2bb..d0cf0c9 100644
  16. --- a/tests/winfsinfo1/winfsinfo.c
  17. +++ b/tests/winfsinfo1/winfsinfo.c
  18. @@ -267,10 +267,79 @@ done:
  19.      return res;
  20.  }
  21.  
  22. +/*
  23. + * |FILE_NAME_INFORMATION| variation with 4096 bytes, matching
  24. + * Linux |PATH_MAX| value of 4096
  25. + */
  26. +typedef struct _FILE_NAME_INFORMATION4096 {
  27. +  ULONG FileNameLength;
  28. +  WCHAR FileName[4096];
  29. +} FILE_NAME_INFORMATION4096, *PFILE_NAME_INFORMATION4096;
  30. +
  31. +
  32. +static
  33. +bool get_filenormalizednameinfo(const char *progname, const char *filename)
  34. +{
  35. +    int res = EXIT_FAILURE;
  36. +    bool ok;
  37. +    FILE_NAME_INFORMATION4096 finfo = { 0 };
  38. +
  39. +    HANDLE fileHandle = CreateFileA(filename,
  40. +        GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
  41. +        FILE_FLAG_BACKUP_SEMANTICS, NULL);
  42. +    if (fileHandle == INVALID_HANDLE_VALUE) {
  43. +        (void)fprintf(stderr,
  44. +            "%s: Error opening file '%s'. Last error was %d.\n",
  45. +            progname,
  46. +            filename,
  47. +            GetLastError());
  48. +        return EXIT_FAILURE;
  49. +    }
  50. +
  51. +    /*
  52. +     * |FileNormalizedNameInfo| value:
  53. +     * Per
  54. +     * https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ne-minwinbase-file_info_by_handle_class
  55. +     * |FileNormalizedNameInfo| should be |24|, but on Cygwin 3.6 we
  56. +     * get the value |48|. Since |24| works and |48| returns an
  57. +     * "Invalid Parameter" error we assume this is a Cygwin bug.
  58. +     */
  59. +    ok = GetFileInformationByHandleEx(fileHandle,
  60. +        24/*FileNormalizedNameInfo*/,
  61. +        &finfo, sizeof(finfo));
  62. +
  63. +    if (!ok) {
  64. +        (void)fprintf(stderr, "%s: GetFileInformationByHandleEx() "
  65. +            "error. GetLastError()==%d.\n",
  66. +            progname,
  67. +            GetLastError());
  68. +        res = EXIT_FAILURE;
  69. +        goto done;
  70. +    }
  71. +
  72. +    (void)printf("(\n");
  73. +    (void)printf("\tfilename='%s'\n", filename);
  74. +
  75. +    (void)printf("\tFileNameLength=%ld\n",
  76. +        (long)finfo.FileNameLength);
  77. +    (void)printf("\tFileName='%S'\n",   finfo.FileName);
  78. +    (void)printf(")\n");
  79. +    res = EXIT_SUCCESS;
  80. +
  81. +done:
  82. +    CloseHandle(fileHandle);
  83. +    return res;
  84. +}
  85. +
  86.  static
  87.  void usage(void)
  88.  {
  89. -    (void)fprintf(stderr, "winfsinfo <getvolumeinfo|filebasicinfo|filestandardinfo> path\n");
  90. +    (void)fprintf(stderr, "winfsinfo <"
  91. +        "getvolumeinfo|"
  92. +        "filebasicinfo|"
  93. +        "filestandardinfo|"
  94. +        "filenormalizednameinfo"
  95. +        "> path\n");
  96.  }
  97.  
  98.  int main(int ac, char *av[])
  99. @@ -293,6 +362,9 @@ int main(int ac, char *av[])
  100.      else if (!strcmp(subcmd, "filestandardinfo")) {
  101.          return get_file_standard_info(av[0], av[2]);
  102.      }
  103. +    else if (!strcmp(subcmd, "filenormalizednameinfo")) {
  104. +        return get_filenormalizednameinfo(av[0], av[2]);
  105. +    }
  106.      else {
  107.          (void)fprintf(stderr, "%s: Unknown subcmd '%s'\n", av[0], subcmd);
  108.          return EXIT_FAILURE;
  109. --
  110. 2.43.0
  111.  
  112. From 7a52aa24d3cb5f0b91b8879d452c3d4145c0e9c1 Mon Sep 17 00:00:00 2001
  113. From: Roland Mainz <roland.mainz@nrubsig.org>
  114. Date: Sat, 11 May 2024 14:25:27 +0200
  115. Subject: [PATCH 2/4] sys: Fix |nfs41_fobx->sec_ctx| leak
  116.  
  117. Fix leaking |nfs41_fobx->sec_ctx|, caused by |nfs41_get_sec_ctx()|
  118. overwriting an existing |nfs41_fobx->sec_ctx|.
  119.  
  120. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  121. ---
  122. sys/nfs41_driver.c | 28 ++++++++++++++++++++--------
  123.  1 file changed, 20 insertions(+), 8 deletions(-)
  124.  
  125. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  126. index 60f65ca..7d4f37e 100644
  127. --- a/sys/nfs41_driver.c
  128. +++ b/sys/nfs41_driver.c
  129. @@ -4078,9 +4078,11 @@ retry_on_link:
  130.      nfs41_fobx = (PNFS41_FOBX)(RxContext->pFobx)->Context;
  131.      nfs41_fobx->nfs41_open_state = entry->open_state;
  132.  #ifndef USE_MOUNT_SEC_CONTEXT
  133. -    status = nfs41_get_sec_ctx(SecurityImpersonation, &nfs41_fobx->sec_ctx);
  134. -    if (status)
  135. -        goto out_free;
  136. +    if (nfs41_fobx->sec_ctx.ClientToken == NULL) {
  137. +        status = nfs41_get_sec_ctx(SecurityImpersonation, &nfs41_fobx->sec_ctx);
  138. +        if (status)
  139. +            goto out_free;
  140. +    }
  141.  #else
  142.      RtlCopyMemory(&nfs41_fobx->sec_ctx, &pVNetRootContext->mount_sec_ctx,
  143.          sizeof(nfs41_fobx->sec_ctx));
  144. @@ -4384,9 +4386,6 @@ NTSTATUS nfs41_CloseSrvOpen(
  145.          entry->u.Close.renamed = nfs41_fcb->Renamed;
  146.  
  147.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  148. -#ifndef USE_MOUNT_SEC_CONTEXT
  149. -    SeDeleteClientSecurity(&nfs41_fobx->sec_ctx);
  150. -#endif
  151.      if (status) goto out;
  152.  
  153.      /* map windows ERRORs to NTSTATUS */
  154. @@ -4428,6 +4427,12 @@ NTSTATUS nfs41_DeallocateForFobx(
  155.          RxFreePool(nfs41_fobx->acl);
  156.          nfs41_fobx->acl = NULL;
  157.      }
  158. +
  159. +    if (nfs41_fobx->sec_ctx.ClientToken) {
  160. +        SeDeleteClientSecurity(&nfs41_fobx->sec_ctx);
  161. +        nfs41_fobx->sec_ctx.ClientToken = NULL;
  162. +    }
  163. +
  164.      return STATUS_SUCCESS;
  165.  }
  166.  
  167. @@ -7167,7 +7172,7 @@ VOID fcbopen_main(PVOID ctx)
  168.          pEntry = openlist.head.Flink;
  169.          while (!IsListEmpty(&openlist.head)) {
  170.              PNFS41_NETROOT_EXTENSION pNetRootContext;
  171. -            nfs41_updowncall_entry *entry;
  172. +            nfs41_updowncall_entry *entry = NULL;
  173.              FILE_BASIC_INFORMATION binfo;
  174.              PNFS41_FCB nfs41_fcb;
  175.              cur = (nfs41_fcb_list_entry *)CONTAINING_RECORD(pEntry,
  176. @@ -7179,6 +7184,12 @@ VOID fcbopen_main(PVOID ctx)
  177.                  cur->ChangeTime, cur->skip);
  178.  #endif
  179.              if (cur->skip) goto out;
  180. +
  181. +#ifdef NFS41_DRIVER_STABILITY_HACKS
  182. +            /* FIXME: Why ? */
  183. +            if (!cur->nfs41_fobx->sec_ctx.ClientToken)
  184. +                goto out;
  185. +#endif /* NFS41_DRIVER_STABILITY_HACKS */
  186.              pNetRootContext =
  187.                  NFS41GetNetRootExtension(cur->fcb->pNetRoot);
  188.              /* place an upcall for this srv_open */
  189. @@ -7232,8 +7243,9 @@ VOID fcbopen_main(PVOID ctx)
  190.              }
  191.              nfs41_fcb = (PNFS41_FCB)cur->fcb->Context;
  192.              nfs41_fcb->changeattr = entry->ChangeTime;
  193. -            nfs41_UpcallDestroy(entry);
  194.  out:
  195. +            nfs41_UpcallDestroy(entry);
  196. +            entry = NULL;
  197.              if (pEntry->Flink == &openlist.head) {
  198.  #ifdef DEBUG_TIME_BASED_COHERENCY
  199.                  DbgP("fcbopen_main: reached end of the fcb list\n");
  200. --
  201. 2.43.0
  202.  
  203. From 14d7fabc1721ca2e2606b806a92c722f4d912d1c Mon Sep 17 00:00:00 2001
  204. From: Roland Mainz <roland.mainz@nrubsig.org>
  205. Date: Sat, 11 May 2024 14:39:35 +0200
  206. Subject: [PATCH 3/4] sys: Remove
  207.  |USE_MOUNT_SEC_CONTEXT|+|STORE_MOUNT_SEC_CONTEXT|
  208.  
  209. Remove |USE_MOUNT_SEC_CONTEXT| and |STORE_MOUNT_SEC_CONTEXT|
  210. codepaths, as they are not working with newgrp(1)/|setgid()|
  211. support.
  212.  
  213. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  214. ---
  215. sys/nfs41_driver.c | 39 ---------------------------------------
  216.  1 file changed, 39 deletions(-)
  217.  
  218. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  219. index 7d4f37e..1950917 100644
  220. --- a/sys/nfs41_driver.c
  221. +++ b/sys/nfs41_driver.c
  222. @@ -41,17 +41,6 @@
  223.  #include "nfs41_build_features.h"
  224.  
  225.  
  226. -/*
  227. - * FIXME: NFS41_DRIVER_SETGID_NEWGRP_SUPPORT - we need the correct
  228. - * |TOKEN_PRIMARY_GROUP| for |setgid()|/newgrp(1)
  229. - * support, and |#define USE_MOUNT_SEC_CONTEXT| currently breaks
  230. - * that
  231. - */
  232. -#ifndef NFS41_DRIVER_SETGID_NEWGRP_SUPPORT
  233. -#define USE_MOUNT_SEC_CONTEXT 1
  234. -#define STORE_MOUNT_SEC_CONTEXT 1
  235. -#endif
  236. -
  237.  /* debugging printout defines */
  238.  #define DEBUG_MARSHAL_HEADER
  239.  #define DEBUG_MARSHAL_DETAIL
  240. @@ -402,10 +391,6 @@ typedef struct _NFS41_V_NET_ROOT_EXTENSION {
  241.      BOOLEAN                 read_only;
  242.      BOOLEAN                 write_thru;
  243.      BOOLEAN                 nocache;
  244. -
  245. -#ifdef STORE_MOUNT_SEC_CONTEXT
  246. -    SECURITY_CLIENT_CONTEXT mount_sec_ctx;
  247. -#endif
  248.  } NFS41_V_NET_ROOT_EXTENSION, *PNFS41_V_NET_ROOT_EXTENSION;
  249.  #define NFS41GetVNetRootExtension(pVNetRoot)      \
  250.          (((pVNetRoot) == NULL) ? NULL :           \
  251. @@ -3407,10 +3392,6 @@ NTSTATUS nfs41_CreateVNetRoot(
  252.  #ifdef DEBUG_MOUNT
  253.      DbgP("Saving new session 0x%x\n", pVNetRootContext->session);
  254.  #endif
  255. -#ifdef STORE_MOUNT_SEC_CONTEXT
  256. -    status = nfs41_get_sec_ctx(SecurityImpersonation,
  257. -        &pVNetRootContext->mount_sec_ctx);
  258. -#endif
  259.  
  260.  out_free:
  261.      RxFreePool(Config);
  262. @@ -3609,15 +3590,6 @@ NTSTATUS nfs41_FinalizeVNetRoot(
  263.      if (pVNetRoot->pNetRoot->Type != NET_ROOT_DISK &&
  264.              pVNetRoot->pNetRoot->Type != NET_ROOT_WILD)
  265.          status = STATUS_NOT_SUPPORTED;
  266. -#ifdef STORE_MOUNT_SEC_CONTEXT
  267. -    else if (pVNetRootContext->session != INVALID_HANDLE_VALUE) {
  268. -#ifdef DEBUG_MOUNT
  269. -        DbgP("nfs41_FinalizeVNetRoot: deleting security context: %p\n",
  270. -            pVNetRootContext->mount_sec_ctx.ClientToken);
  271. -#endif
  272. -        SeDeleteClientSecurity(&pVNetRootContext->mount_sec_ctx);
  273. -    }
  274. -#endif
  275.  #ifdef DEBUG_MOUNT
  276.      DbgEx();
  277.  #endif
  278. @@ -3913,11 +3885,7 @@ NTSTATUS nfs41_Create(
  279.      status = check_nfs41_create_args(RxContext);
  280.      if (status) goto out;
  281.  
  282. -#if defined(STORE_MOUNT_SEC_CONTEXT) && defined (USE_MOUNT_SEC_CONTEXT)
  283. -    status = nfs41_UpcallCreate(NFS41_OPEN, &pVNetRootContext->mount_sec_ctx,
  284. -#else
  285.      status = nfs41_UpcallCreate(NFS41_OPEN, NULL,
  286. -#endif
  287.          pVNetRootContext->session, INVALID_HANDLE_VALUE,
  288.          pNetRootContext->nfs41d_version,
  289.          SrvOpen->pAlreadyPrefixedName, &entry);
  290. @@ -3980,12 +3948,10 @@ retry_on_link:
  291.      }
  292.  
  293.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  294. -#ifndef USE_MOUNT_SEC_CONTEXT
  295.      if (entry->psec_ctx == &entry->sec_ctx) {
  296.          SeDeleteClientSecurity(entry->psec_ctx);
  297.      }
  298.      entry->psec_ctx = NULL;
  299. -#endif
  300.      if (status) goto out;
  301.  
  302.      if (entry->u.Open.EaMdl) {
  303. @@ -4077,16 +4043,11 @@ retry_on_link:
  304.  #endif
  305.      nfs41_fobx = (PNFS41_FOBX)(RxContext->pFobx)->Context;
  306.      nfs41_fobx->nfs41_open_state = entry->open_state;
  307. -#ifndef USE_MOUNT_SEC_CONTEXT
  308.      if (nfs41_fobx->sec_ctx.ClientToken == NULL) {
  309.          status = nfs41_get_sec_ctx(SecurityImpersonation, &nfs41_fobx->sec_ctx);
  310.          if (status)
  311.              goto out_free;
  312.      }
  313. -#else
  314. -    RtlCopyMemory(&nfs41_fobx->sec_ctx, &pVNetRootContext->mount_sec_ctx,
  315. -        sizeof(nfs41_fobx->sec_ctx));
  316. -#endif
  317.  
  318.      // we get attributes only for data access and file (not directories)
  319.      if (Fcb->OpenCount == 0 ||
  320. --
  321. 2.43.0
  322.  
  323. From 2c69570c0731b9ee6d6d45a2ac63236d68d6f748 Mon Sep 17 00:00:00 2001
  324. From: Roland Mainz <roland.mainz@nrubsig.org>
  325. Date: Sat, 11 May 2024 15:17:29 +0200
  326. Subject: [PATCH 4/4] sys: 32bit build failure due to missing
  327.  |FSCTL_ENABLE_PER_IO_FLAGS|
  328.  
  329. Fix 32bit build, |FSCTL_ENABLE_PER_IO_FLAGS| is not available on
  330. 32bit platforms.
  331.  
  332. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  333. ---
  334. sys/nfs41_debug.c | 2 ++
  335.  1 file changed, 2 insertions(+)
  336.  
  337. diff --git a/sys/nfs41_debug.c b/sys/nfs41_debug.c
  338. index 80da014..3c3accb 100644
  339. --- a/sys/nfs41_debug.c
  340. +++ b/sys/nfs41_debug.c
  341. @@ -771,7 +771,9 @@ const char *fsctl2string(ULONG fscontrolcode)
  342.          CASE_SYM2STR_RET(FSCTL_DISMOUNT_VOLUME)
  343.          CASE_SYM2STR_RET(FSCTL_DUPLICATE_EXTENTS_TO_FILE)
  344.          CASE_SYM2STR_RET(FSCTL_DUPLICATE_EXTENTS_TO_FILE_EX)
  345. +#ifdef FSCTL_ENABLE_PER_IO_FLAGS
  346.          CASE_SYM2STR_RET(FSCTL_ENABLE_PER_IO_FLAGS)
  347. +#endif /* FSCTL_ENABLE_PER_IO_FLAGS */
  348.          CASE_SYM2STR_RET(FSCTL_ENABLE_UPGRADE)
  349.          CASE_SYM2STR_RET(FSCTL_ENCRYPTION_FSCTL_IO)
  350.          CASE_SYM2STR_RET(FSCTL_ENCRYPTION_KEY_CONTROL)
  351. --
  352. 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