pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


nfs41_UpcallDestroy() crash fixes - does not work
Posted by Anonymous on Sat 10th May 2025 13:16
raw | new post

  1. diff --git a/sys/nfs41sys_dir.c b/sys/nfs41sys_dir.c
  2. index 1e9f581..20a7574 100644
  3. --- a/sys/nfs41sys_dir.c
  4. +++ b/sys/nfs41sys_dir.c
  5. @@ -155,6 +155,7 @@ NTSTATUS unmarshal_nfs41_dirquery(
  6.          code = GetExceptionCode();
  7.          print_error("MmUnmapLockedPages thrown exception=0x%lx\n",
  8.              (long)code);
  9. +        cur->u.QueryFile.mdl_buf = NULL;
  10.          status = STATUS_ACCESS_VIOLATION;
  11.      }
  12.      if (buf_len > cur->buf_len)
  13. diff --git a/sys/nfs41sys_fsctl.c b/sys/nfs41sys_fsctl.c
  14. index d90eb6d..53d1a89 100644
  15. --- a/sys/nfs41sys_fsctl.c
  16. +++ b/sys/nfs41sys_fsctl.c
  17. @@ -322,6 +322,7 @@ NTSTATUS unmarshal_nfs41_queryallocatedranges(
  18.          print_error("unmarshal_nfs41_queryallocatedranges: "
  19.              "MmUnmapLockedPages thrown exception=0x%lx\n",
  20.              (long)GetExceptionCode());
  21. +            cur->u.QueryAllocatedRanges.Buffer = NULL;
  22.          status = cur->status = STATUS_ACCESS_VIOLATION;
  23.          goto out;
  24.      }
  25. diff --git a/sys/nfs41sys_openclose.c b/sys/nfs41sys_openclose.c
  26. index a5b5284..8884e91 100644
  27. --- a/sys/nfs41sys_openclose.c
  28. +++ b/sys/nfs41sys_openclose.c
  29. @@ -259,6 +259,7 @@ NTSTATUS unmarshal_nfs41_open(
  30.      } __except(EXCEPTION_EXECUTE_HANDLER) {
  31.          print_error("MmUnmapLockedPages thrown exception=0x%lx\n",
  32.              (long)GetExceptionCode());
  33. +        cur->u.Open.EaBuffer = NULL;
  34.          status = cur->status = STATUS_ACCESS_VIOLATION;
  35.          goto out;
  36.      }
  37. diff --git a/sys/nfs41sys_readwrite.c b/sys/nfs41sys_readwrite.c
  38. index cc718df..8531a5f 100644
  39. --- a/sys/nfs41sys_readwrite.c
  40. +++ b/sys/nfs41sys_readwrite.c
  41. @@ -188,6 +188,7 @@ NTSTATUS unmarshal_nfs41_rw(
  42.          code = GetExceptionCode();
  43.          print_error("unmarshal_nfs41_rw: Call to MmUnmapLockedPages() "
  44.              "failed due to exception 0x%0x\n", (long)code);
  45. +        cur->buf = NULL;
  46.          status = STATUS_ACCESS_VIOLATION;
  47.      }
  48.  #endif
  49. diff --git a/sys/nfs41sys_updowncall.c b/sys/nfs41sys_updowncall.c
  50. index 75801be..b69d34c 100644
  51. --- a/sys/nfs41sys_updowncall.c
  52. +++ b/sys/nfs41sys_updowncall.c
  53. @@ -408,6 +408,7 @@ NTSTATUS nfs41_UpcallCreate(
  54.              case NFS41_SYSOP_WRITE:
  55.              case NFS41_SYSOP_READ:
  56.                  entry->buf = NULL;
  57. +                entry->u.ReadWrite.MdlAddress = NULL;
  58.                  break;
  59.              case NFS41_SYSOP_DIR_QUERY:
  60.                  entry->u.QueryFile.mdl_buf = NULL;
  61. @@ -434,13 +435,22 @@ void nfs41_UpcallDestroy(nfs41_updowncall_entry *entry)
  62.      if (!entry)
  63.          return;
  64.  
  65. -#if defined(_DEBUG)
  66. +#if 1 /*defined(_DEBUG)*/
  67.      switch(entry->opcode) {
  68.          case NFS41_SYSOP_WRITE:
  69.          case NFS41_SYSOP_READ:
  70. -            if (entry->buf) {
  71. +            if (entry->u.ReadWrite.MdlAddress && entry->buf) {
  72.                  DbgP("nfs41_UpcallDestroy: NFS41_SYSOP_RW mapping leak\n");
  73. -                MmUnmapLockedPages(entry->buf, entry->u.ReadWrite.MdlAddress);
  74. +                __try {
  75. +                    MmUnmapLockedPages(entry->buf, entry->u.ReadWrite.MdlAddress);
  76. +                } __except(EXCEPTION_EXECUTE_HANDLER) {
  77. +                    NTSTATUS code;
  78. +                    code = GetExceptionCode();
  79. +                    print_error("nfs41_UpcallDestroy: "
  80. +                        "Call to MmUnmapLockedPages() "
  81. +                        "failed due to exception 0x%0x\n", (long)code);
  82. +                }
  83. +
  84.                  entry->buf = NULL;
  85.              }
  86.              break;
  87. @@ -448,20 +458,42 @@ void nfs41_UpcallDestroy(nfs41_updowncall_entry *entry)
  88.              if (entry->u.QueryFile.mdl) {
  89.                  DbgP("nfs41_UpcallDestroy: "
  90.                      "NFS41_SYSOP_DIR_QUERY mapping leak\n");
  91. -                MmUnmapLockedPages(entry->u.QueryFile.mdl_buf,
  92. -                    entry->u.QueryFile.mdl);
  93. +                if (entry->u.QueryFile.mdl_buf) {
  94. +                    __try {
  95. +                        MmUnmapLockedPages(entry->u.QueryFile.mdl_buf,
  96. +                            entry->u.QueryFile.mdl);
  97. +                    } __except(EXCEPTION_EXECUTE_HANDLER) {
  98. +                        NTSTATUS code;
  99. +                        code = GetExceptionCode();
  100. +                        print_error("nfs41_UpcallDestroy: "
  101. +                            "Call to MmUnmapLockedPages() "
  102. +                            "failed due to exception 0x%0x\n", (long)code);
  103. +                    }
  104. +
  105. +                    entry->u.QueryFile.mdl_buf = NULL;
  106. +                }
  107.                  IoFreeMdl(entry->u.QueryFile.mdl);
  108. -                entry->u.QueryFile.mdl_buf = NULL;
  109.                  entry->u.QueryFile.mdl = NULL;
  110.              }
  111.              break;
  112.          case NFS41_SYSOP_OPEN:
  113.              if (entry->u.Open.EaMdl) {
  114.                  DbgP("nfs41_UpcallDestroy: NFS41_SYSOP_OPEN mapping leak\n");
  115. -                MmUnmapLockedPages(entry->u.Open.EaBuffer,
  116. -                    entry->u.Open.EaMdl);
  117. +                if (entry->u.Open.EaBuffer) {
  118. +                    __try {
  119. +                        MmUnmapLockedPages(entry->u.Open.EaBuffer,
  120. +                            entry->u.Open.EaMdl);
  121. +                    } __except(EXCEPTION_EXECUTE_HANDLER) {
  122. +                        NTSTATUS code;
  123. +                        code = GetExceptionCode();
  124. +                        print_error("nfs41_UpcallDestroy: "
  125. +                            "Call to MmUnmapLockedPages() "
  126. +                            "failed due to exception 0x%0x\n", (long)code);
  127. +                    }
  128. +
  129. +                    entry->u.Open.EaBuffer = NULL;
  130. +                }
  131.                  IoFreeMdl(entry->u.Open.EaMdl);
  132. -                entry->u.Open.EaBuffer = NULL;
  133.                  entry->u.Open.EaMdl = NULL;
  134.              }
  135.              break;
  136. @@ -469,11 +501,21 @@ void nfs41_UpcallDestroy(nfs41_updowncall_entry *entry)
  137.              if (entry->u.QueryAllocatedRanges.BufferMdl) {
  138.                  DbgP("nfs41_UpcallDestroy: "
  139.                      "NFS41_SYSOP_FSCTL_QUERYALLOCATEDRANGES mapping leak\n");
  140. -                MmUnmapLockedPages(
  141. -                    entry->u.QueryAllocatedRanges.Buffer,
  142. -                    entry->u.QueryAllocatedRanges.BufferMdl);
  143. +                if (entry->u.QueryAllocatedRanges.Buffer) {
  144. +                    __try {
  145. +                        MmUnmapLockedPages(
  146. +                            entry->u.QueryAllocatedRanges.Buffer,
  147. +                            entry->u.QueryAllocatedRanges.BufferMdl);
  148. +                        } __except(EXCEPTION_EXECUTE_HANDLER) {
  149. +                            NTSTATUS code;
  150. +                            code = GetExceptionCode();
  151. +                            print_error("nfs41_UpcallDestroy: Call to MmUnmapLockedPages() "
  152. +                                "failed due to exception 0x%0x\n", (long)code);
  153. +                        }
  154. +
  155. +                        entry->u.QueryAllocatedRanges.Buffer = NULL;
  156. +                }
  157.                  IoFreeMdl(entry->u.QueryAllocatedRanges.BufferMdl);
  158. -                entry->u.QueryAllocatedRanges.Buffer = NULL;
  159.                  entry->u.QueryAllocatedRanges.BufferMdl = NULL;
  160.              }
  161.              break;

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