pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Fix some potential kernel leaks, 2025-05-07
Posted by Anonymous on Wed 7th May 2025 16:00
raw | new post

  1. From fe203d8a9c60660dd167e44bb98b6e105549aaaa Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Wed, 7 May 2025 12:24:20 +0200
  4. Subject: [PATCH 1/3] sys: Make sure Mdl mappings and locked memory pages are
  5.  only released/freed once
  6.  
  7. Make sure Mdl mappings and locked memory pages are only released/freed
  8. once.
  9.  
  10. Reported-by: Dan Shelton <dan.f.shelton@gmail.com>
  11. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  12. ---
  13. sys/nfs41sys_dir.c        |  4 +-
  14.  sys/nfs41sys_fsctl.c      |  4 +-
  15.  sys/nfs41sys_openclose.c  |  5 ++-
  16.  sys/nfs41sys_readwrite.c  |  5 ++-
  17.  sys/nfs41sys_updowncall.c | 86 +++++++++++++++++++++++++++++++++++++--
  18.  5 files changed, 96 insertions(+), 8 deletions(-)
  19.  
  20. diff --git a/sys/nfs41sys_dir.c b/sys/nfs41sys_dir.c
  21. index 4d0681d..fc71eef 100644
  22. --- a/sys/nfs41sys_dir.c
  23. +++ b/sys/nfs41sys_dir.c
  24. @@ -1,6 +1,6 @@
  25.  /* NFSv4.1 client for Windows
  26.   * Copyright (C) 2012 The Regents of the University of Michigan
  27. - * Copyright (C) 2023-2024 Roland Mainz <roland.mainz@nrubsig.org>
  28. + * Copyright (C) 2023-2025 Roland Mainz <roland.mainz@nrubsig.org>
  29.   *
  30.   * Olga Kornievskaia <aglo@umich.edu>
  31.   * Casey Bodley <cbodley@umich.edu>
  32. @@ -149,6 +149,7 @@ NTSTATUS unmarshal_nfs41_dirquery(
  33.      *buf += sizeof(ULONG);
  34.      __try {
  35.          MmUnmapLockedPages(cur->u.QueryFile.mdl_buf, cur->u.QueryFile.mdl);
  36. +        cur->u.QueryFile.mdl_buf = NULL;
  37.      } __except(EXCEPTION_EXECUTE_HANDLER) {
  38.          NTSTATUS code;
  39.          code = GetExceptionCode();
  40. @@ -317,6 +318,7 @@ NTSTATUS nfs41_QueryDirectory(
  41.          status = map_querydir_errors(entry->status);
  42.      }
  43.      IoFreeMdl(entry->u.QueryFile.mdl);
  44. +    entry->u.QueryFile.mdl = NULL;
  45.      nfs41_UpcallDestroy(entry);
  46.  out:
  47.  #ifdef ENABLE_TIMINGS
  48. diff --git a/sys/nfs41sys_fsctl.c b/sys/nfs41sys_fsctl.c
  49. index 3f401ec..bc7ea2b 100644
  50. --- a/sys/nfs41sys_fsctl.c
  51. +++ b/sys/nfs41sys_fsctl.c
  52. @@ -317,10 +317,12 @@ NTSTATUS unmarshal_nfs41_queryallocatedranges(
  53.      NTSTATUS status = STATUS_SUCCESS;
  54.  
  55.      __try {
  56. -        if (cur->u.QueryAllocatedRanges.Buffer)
  57. +        if (cur->u.QueryAllocatedRanges.Buffer) {
  58.              MmUnmapLockedPages(
  59.                  cur->u.QueryAllocatedRanges.Buffer,
  60.                  cur->u.QueryAllocatedRanges.BufferMdl);
  61. +            cur->u.QueryAllocatedRanges.Buffer = NULL;
  62. +        }
  63.      } __except(EXCEPTION_EXECUTE_HANDLER) {
  64.          print_error("unmarshal_nfs41_queryallocatedranges: "
  65.              "MmUnmapLockedPages thrown exception=0x%lx\n",
  66. diff --git a/sys/nfs41sys_openclose.c b/sys/nfs41sys_openclose.c
  67. index 9334701..50cdc15 100644
  68. --- a/sys/nfs41sys_openclose.c
  69. +++ b/sys/nfs41sys_openclose.c
  70. @@ -252,8 +252,10 @@ NTSTATUS unmarshal_nfs41_open(
  71.      NTSTATUS status = STATUS_SUCCESS;
  72.  
  73.      __try {
  74. -        if (cur->u.Open.EaBuffer)
  75. +        if (cur->u.Open.EaBuffer) {
  76.              MmUnmapLockedPages(cur->u.Open.EaBuffer, cur->u.Open.EaMdl);
  77. +            cur->u.Open.EaBuffer = NULL;
  78. +        }
  79.      } __except(EXCEPTION_EXECUTE_HANDLER) {
  80.          print_error("MmUnmapLockedPages thrown exception=0x%lx\n",
  81.              (long)GetExceptionCode());
  82. @@ -726,6 +728,7 @@ retry_on_link:
  83.      if (entry->u.Open.EaMdl) {
  84.          MmUnlockPages(entry->u.Open.EaMdl);
  85.          IoFreeMdl(entry->u.Open.EaMdl);
  86. +        entry->u.Open.EaMdl = NULL;
  87.      }
  88.  
  89.      if (status) goto out;
  90. diff --git a/sys/nfs41sys_readwrite.c b/sys/nfs41sys_readwrite.c
  91. index ba6f3db..6f5c8fb 100644
  92. --- a/sys/nfs41sys_readwrite.c
  93. +++ b/sys/nfs41sys_readwrite.c
  94. @@ -179,7 +179,10 @@ NTSTATUS unmarshal_nfs41_rw(
  95.          * is already locked.
  96.          */
  97.      __try {
  98. -        MmUnmapLockedPages(cur->buf, cur->u.ReadWrite.MdlAddress);
  99. +        if (cur->buf) {
  100. +            MmUnmapLockedPages(cur->buf, cur->u.ReadWrite.MdlAddress);
  101. +            cur->buf = NULL;
  102. +        }
  103.      } __except(EXCEPTION_EXECUTE_HANDLER) {
  104.          NTSTATUS code;
  105.          code = GetExceptionCode();
  106. diff --git a/sys/nfs41sys_updowncall.c b/sys/nfs41sys_updowncall.c
  107. index 5e2edee..ca130cf 100644
  108. --- a/sys/nfs41sys_updowncall.c
  109. +++ b/sys/nfs41sys_updowncall.c
  110. @@ -402,6 +402,28 @@ NTSTATUS nfs41_UpcallCreate(
  111.          ObReferenceObject(entry->psec_ctx_clienttoken);
  112.      }
  113.  
  114. +    if (entry) {
  115. +        /* Clear fields used for memory mappings */
  116. +        switch(entry->opcode) {
  117. +            case NFS41_SYSOP_WRITE:
  118. +            case NFS41_SYSOP_READ:
  119. +                entry->buf = NULL;
  120. +                break;
  121. +            case NFS41_SYSOP_DIR_QUERY:
  122. +                entry->u.QueryFile.mdl_buf = NULL;
  123. +                entry->u.QueryFile.mdl = NULL;
  124. +                break;
  125. +            case NFS41_SYSOP_OPEN:
  126. +                entry->u.Open.EaBuffer = NULL;
  127. +                entry->u.Open.EaMdl = NULL;
  128. +                break;
  129. +            case NFS41_SYSOP_FSCTL_QUERYALLOCATEDRANGES:
  130. +                entry->u.QueryAllocatedRanges.Buffer = NULL;
  131. +                entry->u.QueryAllocatedRanges.BufferMdl = NULL;
  132. +                break;
  133. +        }
  134. +    }
  135. +
  136.      *entry_out = entry;
  137.  out:
  138.      return status;
  139. @@ -412,6 +434,52 @@ void nfs41_UpcallDestroy(nfs41_updowncall_entry *entry)
  140.      if (!entry)
  141.          return;
  142.  
  143. +#if defined(_DEBUG)
  144. +    switch(entry->opcode) {
  145. +        case NFS41_SYSOP_WRITE:
  146. +        case NFS41_SYSOP_READ:
  147. +            if (entry->buf) {
  148. +                DbgP("nfs41_UpcallDestroy: NFS41_SYSOP_RW mapping leak\n");
  149. +                MmUnmapLockedPages(entry->buf, entry->u.ReadWrite.MdlAddress);
  150. +                entry->buf = NULL;
  151. +            }
  152. +            break;
  153. +        case NFS41_SYSOP_DIR_QUERY:
  154. +            if (entry->u.QueryFile.mdl) {
  155. +                DbgP("nfs41_UpcallDestroy: "
  156. +                    "NFS41_SYSOP_DIR_QUERY mapping leak\n");
  157. +                MmUnmapLockedPages(entry->u.QueryFile.mdl_buf,
  158. +                    entry->u.QueryFile.mdl);
  159. +                IoFreeMdl(entry->u.QueryFile.mdl);
  160. +                entry->u.QueryFile.mdl_buf = NULL;
  161. +                entry->u.QueryFile.mdl = NULL;
  162. +            }
  163. +            break;
  164. +        case NFS41_SYSOP_OPEN:
  165. +            if (entry->u.Open.EaMdl) {
  166. +                DbgP("nfs41_UpcallDestroy: NFS41_SYSOP_OPEN mapping leak\n");
  167. +                MmUnmapLockedPages(entry->u.Open.EaBuffer,
  168. +                    entry->u.Open.EaMdl);
  169. +                IoFreeMdl(entry->u.Open.EaMdl);
  170. +                entry->u.Open.EaBuffer = NULL;
  171. +                entry->u.Open.EaMdl = NULL;
  172. +            }
  173. +            break;
  174. +        case NFS41_SYSOP_FSCTL_QUERYALLOCATEDRANGES:
  175. +            if (entry->u.QueryAllocatedRanges.BufferMdl) {
  176. +                DbgP("nfs41_UpcallDestroy: "
  177. +                    "NFS41_SYSOP_FSCTL_QUERYALLOCATEDRANGES mapping leak\n");
  178. +                MmUnmapLockedPages(
  179. +                    entry->u.QueryAllocatedRanges.Buffer,
  180. +                    entry->u.QueryAllocatedRanges.BufferMdl);
  181. +                IoFreeMdl(entry->u.QueryAllocatedRanges.BufferMdl);
  182. +                entry->u.QueryAllocatedRanges.Buffer = NULL;
  183. +                entry->u.QueryAllocatedRanges.BufferMdl = NULL;
  184. +            }
  185. +            break;
  186. +    }
  187. +#endif /* _DEBUG */
  188. +
  189.      if (entry->psec_ctx_clienttoken) {
  190.          ObDereferenceObject(entry->psec_ctx_clienttoken);
  191.      }
  192. @@ -596,18 +664,27 @@ NTSTATUS nfs41_downcall(
  193.          switch(cur->opcode) {
  194.          case NFS41_SYSOP_WRITE:
  195.          case NFS41_SYSOP_READ:
  196. -            MmUnmapLockedPages(cur->buf, cur->u.ReadWrite.MdlAddress);
  197. +            if (cur->buf) {
  198. +                MmUnmapLockedPages(cur->buf, cur->u.ReadWrite.MdlAddress);
  199. +                cur->buf = NULL;
  200. +            }
  201.              break;
  202.          case NFS41_SYSOP_DIR_QUERY:
  203. -            MmUnmapLockedPages(cur->u.QueryFile.mdl_buf,
  204. +            if (cur->u.QueryFile.mdl) {
  205. +                MmUnmapLockedPages(cur->u.QueryFile.mdl_buf,
  206.                      cur->u.QueryFile.mdl);
  207. -            IoFreeMdl(cur->u.QueryFile.mdl);
  208. +                IoFreeMdl(cur->u.QueryFile.mdl);
  209. +                cur->u.QueryFile.mdl_buf = NULL;
  210. +                cur->u.QueryFile.mdl = NULL;
  211. +            }
  212.              break;
  213.          case NFS41_SYSOP_OPEN:
  214.              if (cur->u.Open.EaMdl) {
  215.                  MmUnmapLockedPages(cur->u.Open.EaBuffer,
  216. -                        cur->u.Open.EaMdl);
  217. +                    cur->u.Open.EaMdl);
  218.                  IoFreeMdl(cur->u.Open.EaMdl);
  219. +                cur->u.Open.EaBuffer = NULL;
  220. +                cur->u.Open.EaMdl = NULL;
  221.              }
  222.              break;
  223.          case NFS41_SYSOP_FSCTL_QUERYALLOCATEDRANGES:
  224. @@ -616,6 +693,7 @@ NTSTATUS nfs41_downcall(
  225.                      cur->u.QueryAllocatedRanges.Buffer,
  226.                      cur->u.QueryAllocatedRanges.BufferMdl);
  227.                  IoFreeMdl(cur->u.QueryAllocatedRanges.BufferMdl);
  228. +                cur->u.QueryAllocatedRanges.Buffer = NULL;
  229.                  cur->u.QueryAllocatedRanges.BufferMdl = NULL;
  230.              }
  231.              break;
  232. --
  233. 2.45.1
  234.  
  235. From 2b9c0476d623e848ffdabf42caa39a2e38fc2541 Mon Sep 17 00:00:00 2001
  236. From: Roland Mainz <roland.mainz@nrubsig.org>
  237. Date: Wed, 7 May 2025 13:29:05 +0200
  238. Subject: [PATCH 2/3] sys: Make sure we do not free an |nfs41_updowncall_entry|
  239.  which got a timeout
  240.  
  241. Make sure we do not free an |nfs41_updowncall_entry| which got a
  242. timeout, otherwise we would crash later when the userland daemon
  243. does the downcall.
  244.  
  245. Reported-by: Dan Shelton <dan.f.shelton@gmail.com>
  246. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  247. ---
  248. sys/nfs41sys_acl.c       | 12 ++++++++++--
  249.  sys/nfs41sys_dir.c       |  6 +++++-
  250.  sys/nfs41sys_driver.c    |  6 +++++-
  251.  sys/nfs41sys_ea.c        | 18 +++++++++++++++---
  252.  sys/nfs41sys_fileinfo.c  | 10 +++++++---
  253.  sys/nfs41sys_fsctl.c     |  4 +++-
  254.  sys/nfs41sys_lock.c      | 12 ++++++++++--
  255.  sys/nfs41sys_mount.c     |  6 +++++-
  256.  sys/nfs41sys_openclose.c | 12 ++++++++++--
  257.  sys/nfs41sys_readwrite.c | 12 ++++++++++--
  258.  sys/nfs41sys_symlink.c   | 12 ++++++++++--
  259.  sys/nfs41sys_volinfo.c   |  6 +++++-
  260.  12 files changed, 95 insertions(+), 21 deletions(-)
  261.  
  262. diff --git a/sys/nfs41sys_acl.c b/sys/nfs41sys_acl.c
  263. index 1d64293..2758fbf 100644
  264. --- a/sys/nfs41sys_acl.c
  265. +++ b/sys/nfs41sys_acl.c
  266. @@ -266,7 +266,11 @@ NTSTATUS nfs41_QuerySecurityInformation(
  267.      entry->buf_len = RxContext->CurrentIrpSp->Parameters.QuerySecurity.Length;
  268.  
  269.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  270. -    if (status) goto out;
  271. +    if (status) {
  272. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  273. +        entry = NULL;
  274. +        goto out;
  275. +    }
  276.  
  277.      if (entry->status == STATUS_BUFFER_TOO_SMALL) {
  278.  #ifdef DEBUG_ACL_QUERY
  279. @@ -406,7 +410,11 @@ NTSTATUS nfs41_SetSecurityInformation(
  280.  #endif
  281.  
  282.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  283. -    if (status) goto out;
  284. +    if (status) {
  285. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  286. +        entry = NULL;
  287. +        goto out;
  288. +    }
  289.  
  290.      status = map_query_acl_error(entry->status);
  291.      if (!status) {
  292. diff --git a/sys/nfs41sys_dir.c b/sys/nfs41sys_dir.c
  293. index fc71eef..4faedef 100644
  294. --- a/sys/nfs41sys_dir.c
  295. +++ b/sys/nfs41sys_dir.c
  296. @@ -294,7 +294,11 @@ NTSTATUS nfs41_QueryDirectory(
  297.  
  298.      MmUnlockPages(entry->u.QueryFile.mdl);
  299.  
  300. -    if (status) goto out;
  301. +    if (status) {
  302. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  303. +        entry = NULL;
  304. +        goto out;
  305. +    }
  306.  
  307.      if (entry->status == STATUS_BUFFER_TOO_SMALL) {
  308.          DbgP("nfs41_QueryDirectory: buffer too small provided %d need %lu\n",
  309. diff --git a/sys/nfs41sys_driver.c b/sys/nfs41sys_driver.c
  310. index 43f0706..50f37a1 100644
  311. --- a/sys/nfs41sys_driver.c
  312. +++ b/sys/nfs41sys_driver.c
  313. @@ -321,7 +321,11 @@ NTSTATUS nfs41_shutdown_daemon(
  314.          SeDeleteClientSecurity(entry->psec_ctx);
  315.      }
  316.      entry->psec_ctx = NULL;
  317. -    if (status) goto out;
  318. +    if (status) {
  319. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  320. +        entry = NULL;
  321. +        goto out;
  322. +    }
  323.  
  324.      nfs41_UpcallDestroy(entry);
  325.  out:
  326. diff --git a/sys/nfs41sys_ea.c b/sys/nfs41sys_ea.c
  327. index b5f12c3..719c41e 100644
  328. --- a/sys/nfs41sys_ea.c
  329. +++ b/sys/nfs41sys_ea.c
  330. @@ -380,7 +380,11 @@ NTSTATUS nfs41_SetEaInformation(
  331.      entry->buf_len = buflen;
  332.  
  333.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  334. -    if (status) goto out;
  335. +    if (status) {
  336. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  337. +        entry = NULL;
  338. +        goto out;
  339. +    }
  340.  #ifdef ENABLE_TIMINGS
  341.      if (entry->status == STATUS_SUCCESS) {
  342.          InterlockedIncrement(&setexattr.sops);
  343. @@ -483,7 +487,11 @@ NTSTATUS QueryCygwinSymlink(
  344.      entry->u.Symlink.target = &TargetName;
  345.  
  346.      status = nfs41_UpcallWaitForReply(entry, VNetRootContext->timeout);
  347. -    if (status) goto out;
  348. +    if (status) {
  349. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  350. +        entry = NULL;
  351. +        goto out;
  352. +    }
  353.  
  354.      status = map_setea_error(entry->status);
  355.      if (status == STATUS_SUCCESS) {
  356. @@ -639,7 +647,11 @@ NTSTATUS nfs41_QueryEaInformation(
  357.      entry->u.QueryEa.ReturnSingleEntry = RxContext->QueryEa.ReturnSingleEntry;
  358.  
  359.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  360. -    if (status) goto out;
  361. +    if (status) {
  362. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  363. +        entry = NULL;
  364. +        goto out;
  365. +    }
  366.  
  367.      if (entry->status == STATUS_SUCCESS) {
  368.          switch (entry->u.QueryEa.Overflow) {
  369. diff --git a/sys/nfs41sys_fileinfo.c b/sys/nfs41sys_fileinfo.c
  370. index e5bd1a0..905096e 100644
  371. --- a/sys/nfs41sys_fileinfo.c
  372. +++ b/sys/nfs41sys_fileinfo.c
  373. @@ -401,8 +401,8 @@ NTSTATUS nfs41_QueryFileInformation(
  374.  
  375.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  376.      if (status) {
  377. -        print_error("nfs41_UpcallWaitForReply() failed, status=0x%lx\n",
  378. -            (long)status);
  379. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  380. +        entry = NULL;
  381.          goto out;
  382.      }
  383.  
  384. @@ -743,7 +743,11 @@ NTSTATUS nfs41_SetFileInformation(
  385.  #endif
  386.  
  387.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  388. -    if (status) goto out;
  389. +    if (status) {
  390. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  391. +        entry = NULL;
  392. +        goto out;
  393. +    }
  394.  
  395.      status = map_setfile_error(entry->status);
  396.      if (!status) {
  397. diff --git a/sys/nfs41sys_fsctl.c b/sys/nfs41sys_fsctl.c
  398. index bc7ea2b..0803229 100644
  399. --- a/sys/nfs41sys_fsctl.c
  400. +++ b/sys/nfs41sys_fsctl.c
  401. @@ -193,6 +193,7 @@ NTSTATUS nfs41_QueryAllocatedRanges(
  402.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  403.      if (status) {
  404.          /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  405. +        entry = NULL;
  406.          goto out;
  407.      }
  408.  
  409. @@ -512,6 +513,7 @@ NTSTATUS nfs41_SetZeroData(
  410.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  411.      if (status) {
  412.          /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  413. +        entry = NULL;
  414.          goto out;
  415.      }
  416.  
  417. @@ -740,9 +742,9 @@ NTSTATUS nfs41_DuplicateData(
  418.          duplicatedatabuffer->ByteCount.QuadPart;
  419.  
  420.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  421. -
  422.      if (status) {
  423.          /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  424. +        entry = NULL;
  425.          goto out;
  426.      }
  427.  
  428. diff --git a/sys/nfs41sys_lock.c b/sys/nfs41sys_lock.c
  429. index e6a2016..4f71120 100644
  430. --- a/sys/nfs41sys_lock.c
  431. +++ b/sys/nfs41sys_lock.c
  432. @@ -311,7 +311,11 @@ NTSTATUS nfs41_Lock(
  433.  
  434.  retry_upcall:
  435.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  436. -    if (status) goto out;
  437. +    if (status) {
  438. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  439. +        entry = NULL;
  440. +        goto out;
  441. +    }
  442.  
  443.      /* blocking locks keep trying until it succeeds */
  444.      if (entry->status == ERROR_LOCK_FAILED && entry->u.Lock.blocking) {
  445. @@ -436,7 +440,11 @@ NTSTATUS nfs41_Unlock(
  446.      }
  447.  
  448.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  449. -    if (status) goto out;
  450. +    if (status) {
  451. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  452. +        entry = NULL;
  453. +        goto out;
  454. +    }
  455.  
  456.      status = map_lock_errors(entry->status);
  457.      RxContext->CurrentIrp->IoStatus.Status = status;
  458. diff --git a/sys/nfs41sys_mount.c b/sys/nfs41sys_mount.c
  459. index 5a78eb8..8f4fa40 100644
  460. --- a/sys/nfs41sys_mount.c
  461. +++ b/sys/nfs41sys_mount.c
  462. @@ -277,7 +277,11 @@ NTSTATUS nfs41_mount(
  463.          SeDeleteClientSecurity(entry->psec_ctx);
  464.      }
  465.      entry->psec_ctx = NULL;
  466. -    if (status) goto out;
  467. +    if (status) {
  468. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  469. +        entry = NULL;
  470. +        goto out;
  471. +    }
  472.      *session = entry->session;
  473.      if (entry->u.Mount.lease_time > config->timeout)
  474.          config->timeout = entry->u.Mount.lease_time;
  475. diff --git a/sys/nfs41sys_openclose.c b/sys/nfs41sys_openclose.c
  476. index 50cdc15..972a2c7 100644
  477. --- a/sys/nfs41sys_openclose.c
  478. +++ b/sys/nfs41sys_openclose.c
  479. @@ -731,7 +731,11 @@ retry_on_link:
  480.          entry->u.Open.EaMdl = NULL;
  481.      }
  482.  
  483. -    if (status) goto out;
  484. +    if (status) {
  485. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  486. +        entry = NULL;
  487. +        goto out;
  488. +    }
  489.  
  490.      if (entry->status == NO_ERROR && entry->errno == ERROR_REPARSE) {
  491.          /* symbolic link handling. when attempting to open a symlink when the
  492. @@ -1164,7 +1168,11 @@ NTSTATUS nfs41_CloseSrvOpen(
  493.          entry->u.Close.renamed = nfs41_fcb->Renamed;
  494.  
  495.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  496. -    if (status) goto out;
  497. +    if (status) {
  498. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  499. +        entry = NULL;
  500. +        goto out;
  501. +    }
  502.  
  503.      /* map windows ERRORs to NTSTATUS */
  504.      status = map_close_errors(entry->status);
  505. diff --git a/sys/nfs41sys_readwrite.c b/sys/nfs41sys_readwrite.c
  506. index 6f5c8fb..2cfcf7c 100644
  507. --- a/sys/nfs41sys_readwrite.c
  508. +++ b/sys/nfs41sys_readwrite.c
  509. @@ -271,7 +271,11 @@ NTSTATUS nfs41_Read(
  510.      io_delay = pVNetRootContext->timeout +
  511.          EXTRA_TIMEOUT_PER_BYTE(entry->buf_len);
  512.      status = nfs41_UpcallWaitForReply(entry, io_delay);
  513. -    if (status) goto out;
  514. +    if (status) {
  515. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  516. +        entry = NULL;
  517. +        goto out;
  518. +    }
  519.  
  520.      if (async) {
  521.  #ifdef DEBUG_READ
  522. @@ -389,7 +393,11 @@ NTSTATUS nfs41_Write(
  523.      io_delay = pVNetRootContext->timeout +
  524.          EXTRA_TIMEOUT_PER_BYTE(entry->buf_len);
  525.      status = nfs41_UpcallWaitForReply(entry, io_delay);
  526. -    if (status) goto out;
  527. +    if (status) {
  528. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  529. +        entry = NULL;
  530. +        goto out;
  531. +    }
  532.  
  533.      if (async) {
  534.  #ifdef DEBUG_WRITE
  535. diff --git a/sys/nfs41sys_symlink.c b/sys/nfs41sys_symlink.c
  536. index fffcde7..d92281a 100644
  537. --- a/sys/nfs41sys_symlink.c
  538. +++ b/sys/nfs41sys_symlink.c
  539. @@ -409,7 +409,11 @@ NTSTATUS nfs41_SetSymlinkReparsePoint(
  540.      entry->u.Symlink.target = &TargetName;
  541.  
  542.      status = nfs41_UpcallWaitForReply(entry, VNetRootContext->timeout);
  543. -    if (status) goto out;
  544. +    if (status) {
  545. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  546. +        entry = NULL;
  547. +        goto out;
  548. +    }
  549.  
  550.      status = map_symlink_errors(entry->status);
  551.  out:
  552. @@ -588,7 +592,11 @@ NTSTATUS nfs41_GetSymlinkReparsePoint(
  553.      entry->u.Symlink.target = &TargetName;
  554.  
  555.      status = nfs41_UpcallWaitForReply(entry, VNetRootContext->timeout);
  556. -    if (status) goto out;
  557. +    if (status) {
  558. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  559. +        entry = NULL;
  560. +        goto out;
  561. +    }
  562.  
  563.      status = map_symlink_errors(entry->status);
  564.      if (status == STATUS_SUCCESS) {
  565. diff --git a/sys/nfs41sys_volinfo.c b/sys/nfs41sys_volinfo.c
  566. index d4a0eeb..7d58020 100644
  567. --- a/sys/nfs41sys_volinfo.c
  568. +++ b/sys/nfs41sys_volinfo.c
  569. @@ -249,7 +249,11 @@ NTSTATUS nfs41_QueryVolumeInformation(
  570.      entry->buf_len = RxContext->Info.LengthRemaining;
  571.  
  572.      status = nfs41_UpcallWaitForReply(entry, pVNetRootContext->timeout);
  573. -    if (status) goto out;
  574. +    if (status) {
  575. +        /* Timeout - |nfs41_downcall()| will free |entry|+contents */
  576. +        entry = NULL;
  577. +        goto out;
  578. +    }
  579.  
  580.      if (entry->status == STATUS_BUFFER_TOO_SMALL) {
  581.          RxContext->InformationToReturn = entry->buf_len;
  582. --
  583. 2.45.1
  584.  
  585. From 9b45c9d9c198201594b5dd067bdb67eeea9f2efa Mon Sep 17 00:00:00 2001
  586. From: Roland Mainz <roland.mainz@nrubsig.org>
  587. Date: Wed, 7 May 2025 16:13:24 +0200
  588. Subject: [PATCH 3/3] sys: Make sure we do not leak |nfs41_updowncall_entry|
  589.  
  590. Make sure we do not leak |nfs41_updowncall_entry|.
  591.  
  592. Reported-by: Dan Shelton <dan.f.shelton@gmail.com>
  593. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  594. ---
  595. sys/nfs41sys_acl.c       | 14 +++++++++-----
  596.  sys/nfs41sys_dir.c       |  7 ++++---
  597.  sys/nfs41sys_ea.c        | 20 ++++++++++++--------
  598.  sys/nfs41sys_fileinfo.c  | 12 ++++++++----
  599.  sys/nfs41sys_fsctl.c     |  9 ++++-----
  600.  sys/nfs41sys_lock.c      | 12 ++++++++----
  601.  sys/nfs41sys_mount.c     | 12 ++++++++----
  602.  sys/nfs41sys_openclose.c | 29 +++++++++++++++--------------
  603.  sys/nfs41sys_readwrite.c | 14 ++++++++++----
  604.  sys/nfs41sys_symlink.c   |  6 ++++--
  605.  sys/nfs41sys_volinfo.c   |  8 +++++---
  606.  11 files changed, 87 insertions(+), 56 deletions(-)
  607.  
  608. diff --git a/sys/nfs41sys_acl.c b/sys/nfs41sys_acl.c
  609. index 2758fbf..c468433 100644
  610. --- a/sys/nfs41sys_acl.c
  611. +++ b/sys/nfs41sys_acl.c
  612. @@ -1,6 +1,6 @@
  613.  /* NFSv4.1 client for Windows
  614.   * Copyright (C) 2012 The Regents of the University of Michigan
  615. - * Copyright (C) 2023-2024 Roland Mainz <roland.mainz@nrubsig.org>
  616. + * Copyright (C) 2023-2025 Roland Mainz <roland.mainz@nrubsig.org>
  617.   *
  618.   * Olga Kornievskaia <aglo@umich.edu>
  619.   * Casey Bodley <cbodley@umich.edu>
  620. @@ -204,7 +204,7 @@ NTSTATUS nfs41_QuerySecurityInformation(
  621.      IN OUT PRX_CONTEXT RxContext)
  622.  {
  623.      NTSTATUS status = STATUS_NOT_SUPPORTED;
  624. -    nfs41_updowncall_entry *entry;
  625. +    nfs41_updowncall_entry *entry = NULL;
  626.      __notnull PNFS41_FOBX nfs41_fobx = NFS41GetFobxExtension(RxContext->pFobx);
  627.      __notnull PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  628.      __notnull PNFS41_V_NET_ROOT_EXTENSION pVNetRootContext =
  629. @@ -304,8 +304,10 @@ NTSTATUS nfs41_QuerySecurityInformation(
  630.      } else {
  631.          status = map_query_acl_error(entry->status);
  632.      }
  633. -    nfs41_UpcallDestroy(entry);
  634.  out:
  635. +    if (entry) {
  636. +        nfs41_UpcallDestroy(entry);
  637. +    }
  638.  #ifdef ENABLE_TIMINGS
  639.      t2 = KeQueryPerformanceCounter(NULL);
  640.      /* only count getacl that we made an upcall for */
  641. @@ -353,7 +355,7 @@ NTSTATUS nfs41_SetSecurityInformation(
  642.      IN OUT PRX_CONTEXT RxContext)
  643.  {
  644.      NTSTATUS status = STATUS_NOT_SUPPORTED;
  645. -    nfs41_updowncall_entry *entry;
  646. +    nfs41_updowncall_entry *entry = NULL;
  647.      __notnull PNFS41_FOBX nfs41_fobx = NFS41GetFobxExtension(RxContext->pFobx);
  648.      __notnull PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  649.      __notnull PNFS41_V_NET_ROOT_EXTENSION pVNetRootContext =
  650. @@ -424,8 +426,10 @@ NTSTATUS nfs41_SetSecurityInformation(
  651.              nfs41_update_fcb_list(RxContext->pFcb, entry->ChangeTime);
  652.          nfs41_fcb->changeattr = entry->ChangeTime;
  653.      }
  654. -    nfs41_UpcallDestroy(entry);
  655.  out:
  656. +    if (entry) {
  657. +        nfs41_UpcallDestroy(entry);
  658. +    }
  659.  #ifdef ENABLE_TIMINGS
  660.      t2 = KeQueryPerformanceCounter(NULL);
  661.      InterlockedIncrement(&setacl.tops);
  662. diff --git a/sys/nfs41sys_dir.c b/sys/nfs41sys_dir.c
  663. index 4faedef..1e9f581 100644
  664. --- a/sys/nfs41sys_dir.c
  665. +++ b/sys/nfs41sys_dir.c
  666. @@ -220,7 +220,7 @@ NTSTATUS nfs41_QueryDirectory(
  667.      IN OUT PRX_CONTEXT RxContext)
  668.  {
  669.      NTSTATUS status = STATUS_INVALID_PARAMETER;
  670. -    nfs41_updowncall_entry *entry;
  671. +    nfs41_updowncall_entry *entry = NULL;
  672.      FILE_INFORMATION_CLASS InfoClass = RxContext->Info.FileInformationClass;
  673.      PUNICODE_STRING Filter = &RxContext->pFobx->UnicodeQueryTemplate;
  674.      __notnull PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  675. @@ -271,7 +271,6 @@ NTSTATUS nfs41_QueryDirectory(
  676.          RxContext->Info.LengthRemaining, FALSE, FALSE, NULL);
  677.      if (entry->u.QueryFile.mdl == NULL) {
  678.          status = STATUS_INTERNAL_ERROR;
  679. -        nfs41_UpcallDestroy(entry);
  680.          goto out;
  681.      }
  682.  #pragma warning( push )
  683. @@ -323,8 +322,10 @@ NTSTATUS nfs41_QueryDirectory(
  684.      }
  685.      IoFreeMdl(entry->u.QueryFile.mdl);
  686.      entry->u.QueryFile.mdl = NULL;
  687. -    nfs41_UpcallDestroy(entry);
  688.  out:
  689. +    if (entry) {
  690. +        nfs41_UpcallDestroy(entry);
  691. +    }
  692.  #ifdef ENABLE_TIMINGS
  693.      t2 = KeQueryPerformanceCounter(NULL);
  694.      InterlockedIncrement(&readdir.tops);
  695. diff --git a/sys/nfs41sys_ea.c b/sys/nfs41sys_ea.c
  696. index 719c41e..f8eac28 100644
  697. --- a/sys/nfs41sys_ea.c
  698. +++ b/sys/nfs41sys_ea.c
  699. @@ -324,7 +324,7 @@ NTSTATUS nfs41_SetEaInformation(
  700.      IN OUT PRX_CONTEXT RxContext)
  701.  {
  702.      NTSTATUS status = STATUS_EAS_NOT_SUPPORTED;
  703. -    nfs41_updowncall_entry *entry;
  704. +    nfs41_updowncall_entry *entry = NULL;
  705.      __notnull PFILE_FULL_EA_INFORMATION eainfo =
  706.          (PFILE_FULL_EA_INFORMATION)RxContext->Info.Buffer;
  707.      nfs3_attrs *attrs = NULL;
  708. @@ -371,8 +371,6 @@ NTSTATUS nfs41_SetEaInformation(
  709.                  "(eainfo=0x%p, buflen=%lu, &(error_offset=%d))\n",
  710.                  (long)status, (void *)eainfo, buflen,
  711.                  (int)error_offset);
  712. -            nfs41_UpcallDestroy(entry);
  713. -            entry = NULL;
  714.              goto out;
  715.          }
  716.      }
  717. @@ -400,8 +398,10 @@ NTSTATUS nfs41_SetEaInformation(
  718.          nfs41_fcb->changeattr = entry->ChangeTime;
  719.          nfs41_fcb->mode = entry->u.SetEa.mode;
  720.      }
  721. -    nfs41_UpcallDestroy(entry);
  722.  out:
  723. +    if (entry) {
  724. +        nfs41_UpcallDestroy(entry);
  725. +    }
  726.  #ifdef ENABLE_TIMINGS
  727.      t2 = KeQueryPerformanceCounter(NULL);
  728.      InterlockedIncrement(&setexattr.tops);
  729. @@ -463,7 +463,7 @@ NTSTATUS QueryCygwinSymlink(
  730.      __notnull PNFS41_NETROOT_EXTENSION NetRootContext =
  731.              NFS41GetNetRootExtension(SrvOpen->pVNetRoot->pNetRoot);
  732.      __notnull PNFS41_FOBX Fobx = NFS41GetFobxExtension(RxContext->pFobx);
  733. -    nfs41_updowncall_entry *entry;
  734. +    nfs41_updowncall_entry *entry = NULL;
  735.      UNICODE_STRING TargetName;
  736.      const USHORT HeaderLen = FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName) +
  737.          query->EaNameLength + 1;
  738. @@ -506,8 +506,10 @@ NTSTATUS QueryCygwinSymlink(
  739.          RxContext->InformationToReturn = (ULONG_PTR)HeaderLen +
  740.              entry->u.Symlink.target->Length;
  741.      }
  742. -    nfs41_UpcallDestroy(entry);
  743.  out:
  744. +    if (entry) {
  745. +        nfs41_UpcallDestroy(entry);
  746. +    }
  747.      return status;
  748.  }
  749.  
  750. @@ -602,7 +604,7 @@ NTSTATUS nfs41_QueryEaInformation(
  751.      IN OUT PRX_CONTEXT RxContext)
  752.  {
  753.      NTSTATUS status = STATUS_EAS_NOT_SUPPORTED;
  754. -    nfs41_updowncall_entry *entry;
  755. +    nfs41_updowncall_entry *entry = NULL;
  756.      PFILE_GET_EA_INFORMATION query = (PFILE_GET_EA_INFORMATION)
  757.              RxContext->CurrentIrpSp->Parameters.QueryEa.EaList;
  758.      ULONG buflen = RxContext->CurrentIrpSp->Parameters.QueryEa.Length;
  759. @@ -673,8 +675,10 @@ NTSTATUS nfs41_QueryEaInformation(
  760.      } else {
  761.          status = map_setea_error(entry->status);
  762.      }
  763. -    nfs41_UpcallDestroy(entry);
  764.  out:
  765. +    if (entry) {
  766. +        nfs41_UpcallDestroy(entry);
  767. +    }
  768.  #ifdef ENABLE_TIMINGS
  769.      t2 = KeQueryPerformanceCounter(NULL);
  770.      InterlockedIncrement(&getexattr.tops);
  771. diff --git a/sys/nfs41sys_fileinfo.c b/sys/nfs41sys_fileinfo.c
  772. index 905096e..36407f6 100644
  773. --- a/sys/nfs41sys_fileinfo.c
  774. +++ b/sys/nfs41sys_fileinfo.c
  775. @@ -186,7 +186,7 @@ NTSTATUS nfs41_QueryFileInformation(
  776.  {
  777.      NTSTATUS status = STATUS_OBJECT_NAME_NOT_FOUND;
  778.      FILE_INFORMATION_CLASS InfoClass = RxContext->Info.FileInformationClass;
  779. -    nfs41_updowncall_entry *entry;
  780. +    nfs41_updowncall_entry *entry = NULL;
  781.      __notnull PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  782.      __notnull PNFS41_V_NET_ROOT_EXTENSION pVNetRootContext =
  783.          NFS41GetVNetRootExtension(SrvOpen->pVNetRoot);
  784. @@ -487,8 +487,10 @@ NTSTATUS nfs41_QueryFileInformation(
  785.          print_error("status(0x%lx) = map_queryfile_error(entry->status(0x%lx));\n",
  786.              (long)status, (long)entry->status);
  787.      }
  788. -    nfs41_UpcallDestroy(entry);
  789.  out:
  790. +    if (entry) {
  791. +        nfs41_UpcallDestroy(entry);
  792. +    }
  793.  #ifdef ENABLE_TIMINGS
  794.      t2 = KeQueryPerformanceCounter(NULL);
  795.      InterlockedIncrement(&getattr.tops);
  796. @@ -634,7 +636,7 @@ NTSTATUS nfs41_SetFileInformation(
  797.      IN OUT PRX_CONTEXT RxContext)
  798.  {
  799.      NTSTATUS status = STATUS_INVALID_PARAMETER;
  800. -    nfs41_updowncall_entry *entry;
  801. +    nfs41_updowncall_entry *entry = NULL;
  802.      FILE_INFORMATION_CLASS InfoClass = RxContext->Info.FileInformationClass;
  803.      FILE_RENAME_INFORMATION rinfo;
  804.      __notnull PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  805. @@ -757,8 +759,10 @@ NTSTATUS nfs41_SetFileInformation(
  806.              nfs41_update_fcb_list(RxContext->pFcb, entry->ChangeTime);
  807.          nfs41_fcb->changeattr = entry->ChangeTime;
  808.      }
  809. -    nfs41_UpcallDestroy(entry);
  810.  out:
  811. +    if (entry) {
  812. +        nfs41_UpcallDestroy(entry);
  813. +    }
  814.  #ifdef ENABLE_TIMINGS
  815.      t2 = KeQueryPerformanceCounter(NULL);
  816.      InterlockedIncrement(&setattr.tops);
  817. diff --git a/sys/nfs41sys_fsctl.c b/sys/nfs41sys_fsctl.c
  818. index 0803229..fd84e79 100644
  819. --- a/sys/nfs41sys_fsctl.c
  820. +++ b/sys/nfs41sys_fsctl.c
  821. @@ -174,7 +174,7 @@ NTSTATUS nfs41_QueryAllocatedRanges(
  822.      if (entry->u.QueryAllocatedRanges.BufferMdl == NULL) {
  823.          status = STATUS_INTERNAL_ERROR;
  824.          DbgP("nfs41_QueryAllocatedRanges: IoAllocateMdl() failed\n");
  825. -        goto out_free;
  826. +        goto out;
  827.      }
  828.  
  829.  #pragma warning( push )
  830. @@ -231,7 +231,7 @@ NTSTATUS nfs41_QueryAllocatedRanges(
  831.          RxContext->IoStatusBlock.Information = 0;
  832.      }
  833.  
  834. -out_free:
  835. +out:
  836.      if (entry) {
  837.          if (entry->u.QueryAllocatedRanges.BufferMdl) {
  838.              MmUnlockPages(entry->u.QueryAllocatedRanges.BufferMdl);
  839. @@ -242,7 +242,6 @@ out_free:
  840.          nfs41_UpcallDestroy(entry);
  841.      }
  842.  
  843. -out:
  844.      DbgEx();
  845.      return status;
  846.  }
  847. @@ -535,11 +534,11 @@ NTSTATUS nfs41_SetZeroData(
  848.          RxContext->IoStatusBlock.Information = 0;
  849.      }
  850.  
  851. +out:
  852.      if (entry) {
  853.          nfs41_UpcallDestroy(entry);
  854.      }
  855.  
  856. -out:
  857.      DbgEx();
  858.      return status;
  859.  }
  860. @@ -766,11 +765,11 @@ NTSTATUS nfs41_DuplicateData(
  861.          RxContext->IoStatusBlock.Information = 0;
  862.      }
  863.  
  864. +out:
  865.      if (entry) {
  866.          nfs41_UpcallDestroy(entry);
  867.      }
  868.  
  869. -out:
  870.      if (srcfo) {
  871.          ObDereferenceObject(srcfo);
  872.      }
  873. diff --git a/sys/nfs41sys_lock.c b/sys/nfs41sys_lock.c
  874. index 4f71120..803c4c1 100644
  875. --- a/sys/nfs41sys_lock.c
  876. +++ b/sys/nfs41sys_lock.c
  877. @@ -261,7 +261,7 @@ NTSTATUS nfs41_Lock(
  878.      IN OUT PRX_CONTEXT RxContext)
  879.  {
  880.      NTSTATUS status = STATUS_SUCCESS;
  881. -    nfs41_updowncall_entry *entry;
  882. +    nfs41_updowncall_entry *entry = NULL;
  883.      PLOWIO_CONTEXT LowIoContext = &RxContext->LowIoContext;
  884.      __notnull PNFS41_FOBX nfs41_fobx = NFS41GetFobxExtension(RxContext->pFobx);
  885.      __notnull PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  886. @@ -330,8 +330,10 @@ retry_upcall:
  887.      status = map_lock_errors(entry->status);
  888.      RxContext->CurrentIrp->IoStatus.Status = status;
  889.  
  890. -    nfs41_UpcallDestroy(entry);
  891.  out:
  892. +    if (entry) {
  893. +        nfs41_UpcallDestroy(entry);
  894. +    }
  895.  #ifdef ENABLE_TIMINGS
  896.      t2 = KeQueryPerformanceCounter(NULL);
  897.      InterlockedIncrement(&lock.tops);
  898. @@ -382,7 +384,7 @@ NTSTATUS nfs41_Unlock(
  899.      IN OUT PRX_CONTEXT RxContext)
  900.  {
  901.      NTSTATUS status = STATUS_SUCCESS;
  902. -    nfs41_updowncall_entry *entry;
  903. +    nfs41_updowncall_entry *entry = NULL;
  904.      PLOWIO_CONTEXT LowIoContext  = &RxContext->LowIoContext;
  905.      __notnull PNFS41_FOBX nfs41_fobx = NFS41GetFobxExtension(RxContext->pFobx);
  906.      __notnull PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  907. @@ -448,8 +450,10 @@ NTSTATUS nfs41_Unlock(
  908.  
  909.      status = map_lock_errors(entry->status);
  910.      RxContext->CurrentIrp->IoStatus.Status = status;
  911. -    nfs41_UpcallDestroy(entry);
  912.  out:
  913. +    if (entry) {
  914. +        nfs41_UpcallDestroy(entry);
  915. +    }
  916.  #ifdef ENABLE_TIMINGS
  917.      t2 = KeQueryPerformanceCounter(NULL);
  918.      InterlockedIncrement(&unlock.tops);
  919. diff --git a/sys/nfs41sys_mount.c b/sys/nfs41sys_mount.c
  920. index 8f4fa40..5c92f99 100644
  921. --- a/sys/nfs41sys_mount.c
  922. +++ b/sys/nfs41sys_mount.c
  923. @@ -182,7 +182,7 @@ NTSTATUS nfs41_unmount(
  924.      DWORD timeout)
  925.  {
  926.      NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES;
  927. -    nfs41_updowncall_entry *entry;
  928. +    nfs41_updowncall_entry *entry = NULL;
  929.  
  930.  #ifdef DEBUG_MOUNT
  931.      DbgEn();
  932. @@ -197,8 +197,10 @@ NTSTATUS nfs41_unmount(
  933.          SeDeleteClientSecurity(entry->psec_ctx);
  934.      }
  935.      entry->psec_ctx = NULL;
  936. -    nfs41_UpcallDestroy(entry);
  937.  out:
  938. +    if (entry) {
  939. +        nfs41_UpcallDestroy(entry);
  940. +    }
  941.  #ifdef ENABLE_TIMINGS
  942.      print_op_stat("lookup", &lookup, 1);
  943.      print_op_stat("open", &open, 1);
  944. @@ -252,7 +254,7 @@ NTSTATUS nfs41_mount(
  945.      PFILE_FS_ATTRIBUTE_INFORMATION FsAttrs)
  946.  {
  947.      NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES;
  948. -    nfs41_updowncall_entry *entry;
  949. +    nfs41_updowncall_entry *entry = NULL;
  950.  
  951.  #ifdef DEBUG_MOUNT
  952.      DbgEn();
  953. @@ -290,8 +292,10 @@ NTSTATUS nfs41_mount(
  954.      status = map_mount_errors(entry->status);
  955.      if (status == STATUS_SUCCESS)
  956.          *version = entry->version;
  957. -    nfs41_UpcallDestroy(entry);
  958.  out:
  959. +    if (entry) {
  960. +        nfs41_UpcallDestroy(entry);
  961. +    }
  962.  #ifdef DEBUG_MOUNT
  963.      DbgEx();
  964.  #endif
  965. diff --git a/sys/nfs41sys_openclose.c b/sys/nfs41sys_openclose.c
  966. index 972a2c7..6b030b0 100644
  967. --- a/sys/nfs41sys_openclose.c
  968. +++ b/sys/nfs41sys_openclose.c
  969. @@ -703,8 +703,6 @@ retry_on_link:
  970.              FALSE, FALSE, NULL);
  971.          if (entry->u.Open.EaMdl == NULL) {
  972.              status = STATUS_INTERNAL_ERROR;
  973. -            nfs41_UpcallDestroy(entry);
  974. -            entry = NULL;
  975.              goto out;
  976.          }
  977.  #pragma warning( push )
  978. @@ -771,7 +769,7 @@ retry_on_link:
  979.              DbgP("nfs41_Create: Unknown symlinktarget_type=%d\n",
  980.                  (int)entry->u.Open.symlinktarget_type);
  981.              status = STATUS_INVALID_PARAMETER;
  982. -            goto out_free;
  983. +            goto out;
  984.          }
  985.          AbsPath.Length += entry->u.Open.symlink.Length;
  986.          AbsPath.MaximumLength = AbsPath.Length + sizeof(UNICODE_NULL);
  987. @@ -779,7 +777,7 @@ retry_on_link:
  988.              AbsPath.MaximumLength, NFS41_MM_POOLTAG);
  989.          if (AbsPath.Buffer == NULL) {
  990.              status = STATUS_INSUFFICIENT_RESOURCES;
  991. -            goto out_free;
  992. +            goto out;
  993.          }
  994.  
  995.          buf = (PCHAR)AbsPath.Buffer;
  996. @@ -825,7 +823,7 @@ retry_on_link:
  997.              }
  998.              status = STATUS_REPARSE;
  999.          }
  1000. -        goto out_free;
  1001. +        goto out;
  1002.      }
  1003.  
  1004.      status = map_open_errors(entry->status,
  1005. @@ -834,7 +832,7 @@ retry_on_link:
  1006.  #ifdef DEBUG_OPEN
  1007.          print_open_error(1, status);
  1008.  #endif
  1009. -        goto out_free;
  1010. +        goto out;
  1011.      }
  1012.  
  1013.      if (!RxIsFcbAcquiredExclusive(Fcb)) {
  1014. @@ -845,7 +843,7 @@ retry_on_link:
  1015.      RxContext->pFobx = RxCreateNetFobx(RxContext, SrvOpen);
  1016.      if (RxContext->pFobx == NULL) {
  1017.          status = STATUS_INSUFFICIENT_RESOURCES;
  1018. -        goto out_free;
  1019. +        goto out;
  1020.      }
  1021.  #ifdef DEBUG_OPEN
  1022.      DbgP("nfs41_Create: created FOBX 0x%p\n", RxContext->pFobx);
  1023. @@ -855,7 +853,7 @@ retry_on_link:
  1024.      if (nfs41_fobx->sec_ctx.ClientToken == NULL) {
  1025.          status = nfs41_get_sec_ctx(SecurityImpersonation, &nfs41_fobx->sec_ctx);
  1026.          if (status)
  1027. -            goto out_free;
  1028. +            goto out;
  1029.      }
  1030.  
  1031.      // we get attributes only for data access and file (not directories)
  1032. @@ -1033,7 +1031,7 @@ retry_on_link:
  1033.              oentry = nfs41_allocate_nfs41_fcb_list_entry();
  1034.              if (oentry == NULL) {
  1035.                  status = STATUS_INSUFFICIENT_RESOURCES;
  1036. -                goto out_free;
  1037. +                goto out;
  1038.              }
  1039.              oentry->fcb = RxContext->pFcb;
  1040.              oentry->nfs41_fobx = nfs41_fobx;
  1041. @@ -1056,10 +1054,11 @@ retry_on_link:
  1042.          RxContext->Create.ReturnedCreateInformation;
  1043.      status = RxContext->CurrentIrp->IoStatus.Status = STATUS_SUCCESS;
  1044.  
  1045. -out_free:
  1046. -    if (entry)
  1047. -        nfs41_UpcallDestroy(entry);
  1048.  out:
  1049. +    if (entry) {
  1050. +        nfs41_UpcallDestroy(entry);
  1051. +    }
  1052. +
  1053.  #ifdef ENABLE_TIMINGS
  1054.      t2 = KeQueryPerformanceCounter(NULL);
  1055.      if ((params->DesiredAccess & FILE_READ_DATA) ||
  1056. @@ -1129,7 +1128,7 @@ NTSTATUS nfs41_CloseSrvOpen(
  1057.      IN OUT PRX_CONTEXT RxContext)
  1058.  {
  1059.      NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES;
  1060. -    nfs41_updowncall_entry *entry;
  1061. +    nfs41_updowncall_entry *entry = NULL;
  1062.      __notnull PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  1063.      __notnull PNFS41_V_NET_ROOT_EXTENSION pVNetRootContext =
  1064.          NFS41GetVNetRootExtension(SrvOpen->pVNetRoot);
  1065. @@ -1176,8 +1175,10 @@ NTSTATUS nfs41_CloseSrvOpen(
  1066.  
  1067.      /* map windows ERRORs to NTSTATUS */
  1068.      status = map_close_errors(entry->status);
  1069. -    nfs41_UpcallDestroy(entry);
  1070.  out:
  1071. +    if (entry) {
  1072. +        nfs41_UpcallDestroy(entry);
  1073. +    }
  1074.  #ifdef ENABLE_TIMINGS
  1075.      t2 = KeQueryPerformanceCounter(NULL);
  1076.      InterlockedIncrement(&close.tops);
  1077. diff --git a/sys/nfs41sys_readwrite.c b/sys/nfs41sys_readwrite.c
  1078. index 2cfcf7c..cc718df 100644
  1079. --- a/sys/nfs41sys_readwrite.c
  1080. +++ b/sys/nfs41sys_readwrite.c
  1081. @@ -230,7 +230,7 @@ NTSTATUS nfs41_Read(
  1082.      IN OUT PRX_CONTEXT RxContext)
  1083.  {
  1084.      NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES;
  1085. -    nfs41_updowncall_entry *entry;
  1086. +    nfs41_updowncall_entry *entry = NULL;
  1087.      BOOLEAN async = FALSE;
  1088.      PLOWIO_CONTEXT LowIoContext  = &RxContext->LowIoContext;
  1089.      __notnull PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  1090. @@ -282,6 +282,7 @@ NTSTATUS nfs41_Read(
  1091.          DbgP("This is asynchronous read, returning control back to the user\n");
  1092.  #endif
  1093.          status = STATUS_PENDING;
  1094. +        entry = NULL; /* |entry| will be freed once async call is done */
  1095.          goto out;
  1096.      }
  1097.  
  1098. @@ -308,8 +309,10 @@ NTSTATUS nfs41_Read(
  1099.          RxContext->CurrentIrp->IoStatus.Status = status;
  1100.          RxContext->IoStatusBlock.Information = 0;
  1101.      }
  1102. -    nfs41_UpcallDestroy(entry);
  1103.  out:
  1104. +    if (entry) {
  1105. +        nfs41_UpcallDestroy(entry);
  1106. +    }
  1107.  #ifdef ENABLE_TIMINGS
  1108.      t2 = KeQueryPerformanceCounter(NULL);
  1109.      InterlockedIncrement(&read.tops);
  1110. @@ -350,7 +353,7 @@ NTSTATUS nfs41_Write(
  1111.      IN OUT PRX_CONTEXT RxContext)
  1112.  {
  1113.      NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES;
  1114. -    nfs41_updowncall_entry *entry;
  1115. +    nfs41_updowncall_entry *entry = NULL;
  1116.      BOOLEAN async = FALSE;
  1117.      PLOWIO_CONTEXT LowIoContext  = &RxContext->LowIoContext;
  1118.      __notnull PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  1119. @@ -404,6 +407,7 @@ NTSTATUS nfs41_Write(
  1120.          DbgP("This is asynchronous write, returning control back to the user\n");
  1121.  #endif
  1122.          status = STATUS_PENDING;
  1123. +        entry = NULL; /* |entry| will be freed once async call is done */
  1124.          goto out;
  1125.      }
  1126.  
  1127. @@ -437,8 +441,10 @@ NTSTATUS nfs41_Write(
  1128.          RxContext->CurrentIrp->IoStatus.Status = status;
  1129.          RxContext->IoStatusBlock.Information = 0;
  1130.      }
  1131. -    nfs41_UpcallDestroy(entry);
  1132.  out:
  1133. +    if (entry) {
  1134. +        nfs41_UpcallDestroy(entry);
  1135. +    }
  1136.  #ifdef ENABLE_TIMINGS
  1137.      t2 = KeQueryPerformanceCounter(NULL);
  1138.      InterlockedIncrement(&write.tops);
  1139. diff --git a/sys/nfs41sys_symlink.c b/sys/nfs41sys_symlink.c
  1140. index d92281a..6db82de 100644
  1141. --- a/sys/nfs41sys_symlink.c
  1142. +++ b/sys/nfs41sys_symlink.c
  1143. @@ -417,8 +417,9 @@ NTSTATUS nfs41_SetSymlinkReparsePoint(
  1144.  
  1145.      status = map_symlink_errors(entry->status);
  1146.  out:
  1147. -    if (entry)
  1148. +    if (entry) {
  1149.          nfs41_UpcallDestroy(entry);
  1150. +    }
  1151.      if (prefixed_targetname)
  1152.          RxFreePool(prefixed_targetname);
  1153.  
  1154. @@ -896,8 +897,9 @@ NTSTATUS nfs41_GetSymlinkReparsePoint(
  1155.      }
  1156.  
  1157.  out:
  1158. -    if (entry)
  1159. +    if (entry) {
  1160.          nfs41_UpcallDestroy(entry);
  1161. +    }
  1162.      if (targetname_buffer)
  1163.          RxFreePool(targetname_buffer);
  1164.  
  1165. diff --git a/sys/nfs41sys_volinfo.c b/sys/nfs41sys_volinfo.c
  1166. index 7d58020..af1cfa3 100644
  1167. --- a/sys/nfs41sys_volinfo.c
  1168. +++ b/sys/nfs41sys_volinfo.c
  1169. @@ -1,6 +1,6 @@
  1170.  /* NFSv4.1 client for Windows
  1171.   * Copyright (C) 2012 The Regents of the University of Michigan
  1172. - * Copyright (C) 2023-2024 Roland Mainz <roland.mainz@nrubsig.org>
  1173. + * Copyright (C) 2023-2025 Roland Mainz <roland.mainz@nrubsig.org>
  1174.   *
  1175.   * Olga Kornievskaia <aglo@umich.edu>
  1176.   * Casey Bodley <cbodley@umich.edu>
  1177. @@ -144,7 +144,7 @@ NTSTATUS nfs41_QueryVolumeInformation(
  1178.      IN OUT PRX_CONTEXT RxContext)
  1179.  {
  1180.      NTSTATUS status = STATUS_INVALID_PARAMETER;
  1181. -    nfs41_updowncall_entry *entry;
  1182. +    nfs41_updowncall_entry *entry = NULL;
  1183.      ULONG RemainingLength = RxContext->Info.LengthRemaining, SizeUsed;
  1184.      FS_INFORMATION_CLASS InfoClass = RxContext->Info.FsInformationClass;
  1185.      __notnull PMRX_SRV_OPEN SrvOpen = RxContext->pRelevantSrvOpen;
  1186. @@ -280,8 +280,10 @@ NTSTATUS nfs41_QueryVolumeInformation(
  1187.      } else {
  1188.          status = map_volume_errors(entry->status);
  1189.      }
  1190. -    nfs41_UpcallDestroy(entry);
  1191.  out:
  1192. +    if (entry) {
  1193. +        nfs41_UpcallDestroy(entry);
  1194. +    }
  1195.  #ifdef ENABLE_TIMINGS
  1196.      t2 = KeQueryPerformanceCounter(NULL);
  1197.      InterlockedIncrement(&volume.tops);
  1198. --
  1199. 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