pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


experiment: include TOKEN_ORIGIN data into NFS session hash
Posted by Anonymous on Thu 18th Apr 2024 18:19
raw | new post

  1. # experiment: include TOKEN_ORIGIN data into NFS session hash
  2. diff --git a/daemon/nfs41_client.c b/daemon/nfs41_client.c
  3. index d0306a0..97713bf 100644
  4. --- a/daemon/nfs41_client.c
  5. +++ b/daemon/nfs41_client.c
  6. @@ -3,6 +3,7 @@
  7.   *
  8.   * Olga Kornievskaia <aglo@umich.edu>
  9.   * Casey Bodley <cbodley@umich.edu>
  10. + * Roland Mainz <roland.mainz@nrubsig.org>
  11.   *
  12.   * This library is free software; you can redistribute it and/or modify it
  13.   * under the terms of the GNU Lesser General Public License as published by
  14. @@ -26,6 +27,7 @@
  15.  #include <iphlpapi.h> /* for GetAdaptersAddresses() */
  16.  #include <wincrypt.h> /* for Crypt*() functions */
  17.  #include <winsock2.h> /* for hostent struct */
  18. +#include <processthreadsapi.h>
  19.  
  20.  #include "tree.h"
  21.  #include "delegation.h"
  22. @@ -370,13 +372,44 @@ int nfs41_client_owner(
  23.      int status;
  24.      char username[UNLEN + 1];
  25.      DWORD len = UNLEN + 1;
  26. +    LUID originatinglogonsession = { 0 };
  27.  
  28.      if (!GetUserNameA(username, &len)) {
  29.          status = GetLastError();
  30. -        eprintf("GetUserName() failed with %d\n", status);
  31. +        eprintf("nfs41_client_owner: "
  32. +            "GetUserName() failed with %d\n", status);
  33.          goto out;
  34.      }
  35.  
  36. +#if 0
  37. +    /*
  38. +     * Just using the Windows username is not sufficient - DOS
  39. +     * devices are virtualized based off of the LSA logon
  40. +     * session ID a token has associated with it (otherwise
  41. +     * known as an authentication ID; this value is actually
  42. +     * a bit more granular than the Terminal Server session ID),
  43. +     * which means an user can have multiple logons (e.g. GUI and ssh,
  44. +     * and/or user logons with and without Admin rights etc) with
  45. +     * separate DOS namespaces.
  46. +     *
  47. +     * So we need to add the LSA logon session ID from the
  48. +     * "effective thread token" (thread token when impersonating
  49. +     * an user, or process token if not)
  50. +     */
  51. +    if (!gettokenoriginatinglogonsession(GetCurrentThreadToken()/*GetCurrentThreadEffectiveToken()*/,
  52. +        &originatinglogonsession)) {
  53. +        eprintf("nfs41_client_owner: "
  54. +            "gettokenoriginatinglogonsession() failed\n");
  55. +        //goto out;
  56. +    }
  57. +#endif
  58. +
  59. +    DPRINTF(0, ("nfs41_client_owner: username='%s' "
  60. +        "originatinglogonsession={ 0x%lx, 0x%lx }\n",
  61. +        username,
  62. +        (long)originatinglogonsession.LowPart,
  63. +        (long)originatinglogonsession.HighPart));
  64. +
  65.      /* owner.verifier = "time created" */
  66.      memcpy(owner->co_verifier, &time_created, sizeof(time_created));
  67.  
  68. @@ -405,6 +438,25 @@ int nfs41_client_owner(
  69.          goto out_hash;
  70.      }
  71.  
  72. +    /*
  73. +     * |originatinglogonsession| is a |struct _LUID| which can contain
  74. +     * padding bytes with random values, so we need to hash each
  75. +     * member separately
  76. +     */
  77. +    if (!CryptHashData(hash, (const BYTE*)&originatinglogonsession.LowPart,
  78. +        sizeof(originatinglogonsession.LowPart), 0)) {
  79. +        status = GetLastError();
  80. +        eprintf("CryptHashData() failed with %d\n", status);
  81. +        goto out_hash;
  82. +    }
  83. +
  84. +    if (!CryptHashData(hash, (const BYTE*)&originatinglogonsession.HighPart,
  85. +        sizeof(originatinglogonsession.HighPart), 0)) {
  86. +        status = GetLastError();
  87. +        eprintf("CryptHashData() failed with %d\n", status);
  88. +        goto out_hash;
  89. +    }
  90. +
  91.      if (!CryptHashData(hash, (const BYTE*)name, (DWORD)strlen(name), 0)) {
  92.          status = GetLastError();
  93.          eprintf("CryptHashData() failed with %d\n", status);
  94. diff --git a/daemon/nfs41_session.c b/daemon/nfs41_session.c
  95. index 6f4654d..98a2ccb 100644
  96. --- a/daemon/nfs41_session.c
  97. +++ b/daemon/nfs41_session.c
  98. @@ -409,10 +409,10 @@ int nfs41_session_set_lease(
  99.  
  100.      session->lease_time = lease_time;
  101.      session->renew.cancel_event = CreateEventA(NULL, TRUE, FALSE,
  102. -        "renew.cancel_event");
  103. +        NULL);
  104.      if (!valid_handle(session->renew.cancel_event)) {
  105.          status = GetLastError();
  106. -        eprintf("nfs41_session_set_lease: CreateEventA() failed %d\n",
  107. +        eprintf("nfs41_session_set_lease: CreateEventA() failed, status=%d\n",
  108.              status);
  109.          goto out;
  110.      }
  111. diff --git a/daemon/util.c b/daemon/util.c
  112. index 741a653..8bed743 100644
  113. --- a/daemon/util.c
  114. +++ b/daemon/util.c
  115. @@ -717,3 +717,21 @@ bool getwinntversionnnumbers(
  116.  
  117.      return true;
  118.  }
  119. +
  120. +bool gettokenoriginatinglogonsession(HANDLE tok, LUID *pluid)
  121. +{
  122. +    DWORD returnedLength;
  123. +    TOKEN_ORIGIN torigin;
  124. +
  125. +    if (!GetTokenInformation(tok, TokenOrigin, &torigin,
  126. +        sizeof(torigin), &returnedLength)) {
  127. +        eprintf("gettokenoriginatinglogonsession: "
  128. +            "GetTokenInformation(tok=0x%p) failed, status=%d\n",
  129. +            (void *)tok, (int)GetLastError());
  130. +        return false;
  131. +    }
  132. +
  133. +    (void)memcpy(pluid, &torigin.OriginatingLogonSession, sizeof(LUID));
  134. +
  135. +    return true;
  136. +}
  137. diff --git a/daemon/util.h b/daemon/util.h
  138. index b1bdc8a..710728f 100644
  139. --- a/daemon/util.h
  140. +++ b/daemon/util.h
  141. @@ -284,4 +284,6 @@ bool_t waitcriticalsection(LPCRITICAL_SECTION cs);
  142.  
  143.  bool getwinntversionnnumbers(DWORD *MajorVersionPtr, DWORD *MinorVersionPtr, DWORD *BuildNumberPtr);
  144.  
  145. +bool gettokenoriginatinglogonsession(HANDLE tok, LUID *pluid);
  146. +
  147.  #endif /* !__NFS41_DAEMON_UTIL_H__ */

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