Guest User

krb5_patch_Oktober_28_2015

a guest
Nov 13th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.88 KB | None | 0 0
  1.  
  2. From b51b33f2bc5d1497ddf5bd107f791c101695000d Mon Sep 17 00:00:00 2001
  3. From: Nicolas Williams <[email protected]>
  4. Date: Mon, 14 Sep 2015 12:27:52 -0400
  5. Subject: [PATCH] Fix SPNEGO context aliasing bugs [CVE-2015-2695]
  6.  
  7. The SPNEGO mechanism currently replaces its context handle with the
  8. mechanism context handle upon establishment, under the assumption that
  9. most GSS functions are only called after context establishment. This
  10. assumption is incorrect, and can lead to aliasing violations for some
  11. programs. Maintain the SPNEGO context structure after context
  12. establishment and refer to it in all GSS methods. Add initiate and
  13. opened flags to the SPNEGO context structure for use in
  14. gss_inquire_context() prior to context establishment.
  15.  
  16. CVE-2015-2695:
  17.  
  18. In MIT krb5 1.5 and later, applications which call
  19. gss_inquire_context() on a partially-established SPNEGO context can
  20. cause the GSS-API library to read from a pointer using the wrong type,
  21. generally causing a process crash. This bug may go unnoticed, because
  22. the most common SPNEGO authentication scenario establishes the context
  23. after just one call to gss_accept_sec_context(). Java server
  24. applications using the native JGSS provider are vulnerable to this
  25. bug. A carefully crafted SPNEGO packet might allow the
  26. gss_inquire_context() call to succeed with attacker-determined
  27. results, but applications should not make access control decisions
  28. based on gss_inquire_context() results prior to context establishment.
  29.  
  30. CVSSv2 Vector: AV:N/AC:M/Au:N/C:N/I:N/A:C/E:POC/RL:OF/RC:C
  31.  
  32. [[email protected]: several bugfixes, style changes, and edge-case
  33. behavior changes; commit message and CVE description]
  34.  
  35. ticket: 8244
  36. target_version: 1.14
  37. tags: pullup
  38.  
  39. Patch content is adjusted by Howard Guo <[email protected]> to work with
  40. this older version of Kerberos.
  41.  
  42. diff -rupN krb5-1.6.3/src/lib/gssapi/spnego/gssapiP_spnego.h krb5-1.6.3-patched/src/lib/gssapi/spnego/gssapiP_spnego.h
  43. --- krb5-1.6.3/src/lib/gssapi/spnego/gssapiP_spnego.h 2015-10-28 11:16:05.520166617 +0100
  44. +++ krb5-1.6.3-patched/src/lib/gssapi/spnego/gssapiP_spnego.h 2015-10-28 11:54:29.719199162 +0100
  45. @@ -95,6 +95,8 @@ typedef struct {
  46. int firstpass;
  47. int mech_complete;
  48. int nego_done;
  49. + int initiate;
  50. + int opened;
  51. OM_uint32 ctx_flags;
  52. gss_name_t internal_name;
  53. gss_OID actual_mech;
  54. diff -rupN krb5-1.6.3/src/lib/gssapi/spnego/spnego_mech.c krb5-1.6.3-patched/src/lib/gssapi/spnego/spnego_mech.c
  55. --- krb5-1.6.3/src/lib/gssapi/spnego/spnego_mech.c 2015-10-28 11:16:05.520166617 +0100
  56. +++ krb5-1.6.3-patched/src/lib/gssapi/spnego/spnego_mech.c 2015-10-28 13:06:16.223968028 +0100
  57. @@ -76,7 +76,7 @@ static OM_uint32 get_available_mechs(OM_
  58. gss_cred_usage_t, gss_cred_id_t *, gss_OID_set *);
  59. static void release_spnego_ctx(spnego_gss_ctx_id_t *);
  60. static void check_spnego_options(spnego_gss_ctx_id_t);
  61. -static spnego_gss_ctx_id_t create_spnego_ctx(void);
  62. +static spnego_gss_ctx_id_t create_spnego_ctx(int);
  63. static int put_req_flags(unsigned char **, OM_uint32, unsigned int);
  64. static int put_mech_set(gss_OID_set mechSet, gss_buffer_t buf);
  65. static int put_input_token(unsigned char **, gss_buffer_t, unsigned int);
  66. @@ -291,7 +291,7 @@ check_spnego_options(spnego_gss_ctx_id_t
  67. }
  68.  
  69. static spnego_gss_ctx_id_t
  70. -create_spnego_ctx(void)
  71. +create_spnego_ctx(int initiate)
  72. {
  73. spnego_gss_ctx_id_t spnego_ctx = NULL;
  74. spnego_ctx = (spnego_gss_ctx_id_t)
  75. @@ -313,6 +313,8 @@ create_spnego_ctx(void)
  76. spnego_ctx->mic_rcvd = 0;
  77. spnego_ctx->mech_complete = 0;
  78. spnego_ctx->nego_done = 0;
  79. + spnego_ctx->opened = 0;
  80. + spnego_ctx->initiate = initiate;
  81. spnego_ctx->internal_name = GSS_C_NO_NAME;
  82. spnego_ctx->actual_mech = GSS_C_NO_OID;
  83.  
  84. @@ -462,7 +464,7 @@ init_ctx_new(OM_uint32 *minor_status,
  85. if (ret != GSS_S_COMPLETE)
  86. return ret;
  87.  
  88. - sc = create_spnego_ctx();
  89. + sc = create_spnego_ctx(1);
  90. if (sc == NULL)
  91. return GSS_S_FAILURE;
  92.  
  93. @@ -480,10 +482,7 @@ init_ctx_new(OM_uint32 *minor_status,
  94. ret = GSS_S_FAILURE;
  95. goto cleanup;
  96. }
  97. - /*
  98. - * The actual context is not yet determined, set the output
  99. - * context handle to refer to the spnego context itself.
  100. - */
  101. +
  102. sc->ctx_handle = GSS_C_NO_CONTEXT;
  103. *ctx = (gss_ctx_id_t)sc;
  104. *tokflag = INIT_TOKEN_SEND;
  105. @@ -837,14 +836,9 @@ cleanup:
  106. }
  107. gss_release_buffer(&tmpmin, &mechtok_out);
  108. if (ret == GSS_S_COMPLETE) {
  109. - /*
  110. - * Now, switch the output context to refer to the
  111. - * negotiated mechanism's context.
  112. - */
  113. - *context_handle = (gss_ctx_id_t)spnego_ctx->ctx_handle;
  114. + spnego_ctx->opened = 1;
  115. if (actual_mech != NULL)
  116. *actual_mech = spnego_ctx->actual_mech;
  117. - release_spnego_ctx(&spnego_ctx);
  118. } else if (ret != GSS_S_CONTINUE_NEEDED) {
  119. if (spnego_ctx != NULL) {
  120. gss_delete_sec_context(&tmpmin,
  121. @@ -938,7 +932,7 @@ acc_ctx_new(OM_uint32 *minor_status,
  122. ret = GSS_S_BAD_MECH;
  123. goto cleanup;
  124. }
  125. - sc = create_spnego_ctx();
  126. + sc = create_spnego_ctx(0);
  127. if (sc == NULL) {
  128. ret = GSS_S_FAILURE;
  129. *return_token = NO_TOKEN_SEND;
  130. @@ -1259,12 +1253,12 @@ cleanup:
  131. }
  132. }
  133. if (ret == GSS_S_COMPLETE) {
  134. + sc->opened = 1;
  135. *context_handle = (gss_ctx_id_t)sc->ctx_handle;
  136. if (sc->internal_name != GSS_C_NO_NAME &&
  137. src_name != NULL) {
  138. *src_name = sc->internal_name;
  139. }
  140. - release_spnego_ctx(&sc);
  141. }
  142. gss_release_buffer(&tmpmin, &mechtok_out);
  143. if (mechtok_in != GSS_C_NO_BUFFER) {
  144. @@ -1473,8 +1467,14 @@ spnego_gss_process_context_token(void *c
  145. const gss_buffer_t token_buffer)
  146. {
  147. OM_uint32 ret;
  148. + spnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;
  149. +
  150. + /* SPNEGO doesn't have its own context tokens. */
  151. + if (!sc->opened)
  152. + return (GSS_S_DEFECTIVE_TOKEN);
  153. +
  154. ret = gss_process_context_token(minor_status,
  155. - context_handle,
  156. + sc->ctx_handle,
  157. token_buffer);
  158.  
  159. return (ret);
  160. @@ -1493,17 +1493,9 @@ spnego_gss_delete_sec_context(void *cont
  161. if (context_handle == NULL)
  162. return (GSS_S_FAILURE);
  163.  
  164. - /*
  165. - * If this is still an SPNEGO mech, release it locally.
  166. - */
  167. - if (*ctx != NULL &&
  168. - (*ctx)->magic_num == SPNEGO_MAGIC_ID) {
  169. - (void) release_spnego_ctx(ctx);
  170. - } else {
  171. - ret = gss_delete_sec_context(minor_status,
  172. - context_handle,
  173. - output_token);
  174. - }
  175. + (void) gss_delete_sec_context(minor_status, &(*ctx)->ctx_handle,
  176. + output_token);
  177. + (void) release_spnego_ctx(ctx);
  178.  
  179. return (ret);
  180. }
  181. @@ -1515,8 +1507,13 @@ spnego_gss_context_time(void *context,
  182. OM_uint32 *time_rec)
  183. {
  184. OM_uint32 ret;
  185. + spnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;
  186. +
  187. + if (sc->ctx_handle == GSS_C_NO_CONTEXT)
  188. + return (GSS_S_NO_CONTEXT);
  189. +
  190. ret = gss_context_time(minor_status,
  191. - context_handle,
  192. + sc->ctx_handle,
  193. time_rec);
  194. return (ret);
  195. }
  196. @@ -1528,9 +1525,20 @@ spnego_gss_export_sec_context(void *cont
  197. gss_buffer_t interprocess_token)
  198. {
  199. OM_uint32 ret;
  200. + spnego_gss_ctx_id_t sc = *(spnego_gss_ctx_id_t *)context_handle;
  201. +
  202. + /* We don't currently support exporting partially established
  203. + * contexts. */
  204. + if (!sc->opened)
  205. + return GSS_S_UNAVAILABLE;
  206. +
  207. ret = gss_export_sec_context(minor_status,
  208. - context_handle,
  209. + &sc->ctx_handle,
  210. interprocess_token);
  211. + if (sc->ctx_handle == GSS_C_NO_CONTEXT) {
  212. + release_spnego_ctx(&sc);
  213. + *context_handle = GSS_C_NO_CONTEXT;
  214. + }
  215. return (ret);
  216. }
  217.  
  218. @@ -1540,11 +1548,12 @@ spnego_gss_import_sec_context(void *cont
  219. const gss_buffer_t interprocess_token,
  220. gss_ctx_id_t *context_handle)
  221. {
  222. - OM_uint32 ret;
  223. - ret = gss_import_sec_context(minor_status,
  224. - interprocess_token,
  225. - context_handle);
  226. - return (ret);
  227. + /*
  228. + * Until we implement partial context exports, there are no SPNEGO
  229. + * exported context tokens, only tokens for underlying mechs. So just
  230. + * return an error for now.
  231. + */
  232. + return GSS_S_UNAVAILABLE;
  233. }
  234.  
  235. OM_uint32
  236. @@ -1557,19 +1566,51 @@ spnego_gss_inquire_context(void *context
  237. gss_OID *mech_type,
  238. OM_uint32 *ctx_flags,
  239. int *locally_initiated,
  240. - int *open)
  241. + int *opened)
  242. {
  243. OM_uint32 ret = GSS_S_COMPLETE;
  244. + spnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;
  245.  
  246. - ret = gss_inquire_context(minor_status,
  247. - context_handle,
  248. - src_name,
  249. - targ_name,
  250. - lifetime_rec,
  251. - mech_type,
  252. - ctx_flags,
  253. - locally_initiated,
  254. - open);
  255. + if (src_name != NULL)
  256. + *src_name = GSS_C_NO_NAME;
  257. + if (targ_name != NULL)
  258. + *targ_name = GSS_C_NO_NAME;
  259. + if (lifetime_rec != NULL)
  260. + *lifetime_rec = 0;
  261. + if (mech_type != NULL)
  262. + *mech_type = (gss_OID)gss_mech_spnego;
  263. + if (ctx_flags != NULL)
  264. + *ctx_flags = 0;
  265. + if (locally_initiated != NULL)
  266. + *locally_initiated = sc->initiate;
  267. + if (opened != NULL)
  268. + *opened = sc->opened;
  269. +
  270. + if (sc->ctx_handle != GSS_C_NO_CONTEXT) {
  271. + ret = gss_inquire_context(minor_status, sc->ctx_handle,
  272. + src_name, targ_name, lifetime_rec,
  273. + mech_type, ctx_flags, NULL, NULL);
  274. + }
  275. +
  276. + if (!sc->opened) {
  277. + /*
  278. + * We are still doing SPNEGO negotiation, so report SPNEGO as
  279. + * the OID. After negotiation is complete we will report the
  280. + * underlying mechanism OID.
  281. + */
  282. + if (mech_type != NULL)
  283. + *mech_type = (gss_OID)gss_mech_spnego;
  284. +
  285. + /*
  286. + * Remove flags we don't support with partially-established
  287. + * contexts. (Change this to keep GSS_C_TRANS_FLAG if we add
  288. + * support for exporting partial SPNEGO contexts.)
  289. + */
  290. + if (ctx_flags != NULL) {
  291. + *ctx_flags &= ~GSS_C_PROT_READY_FLAG;
  292. + *ctx_flags &= ~GSS_C_TRANS_FLAG;
  293. + }
  294. + }
  295.  
  296. return (ret);
  297. }
  298. @@ -1584,8 +1625,13 @@ spnego_gss_wrap_size_limit(void *context
  299. OM_uint32 *max_input_size)
  300. {
  301. OM_uint32 ret;
  302. + spnego_gss_ctx_id_t sc = (spnego_gss_ctx_id_t)context_handle;
  303. +
  304. + if (sc->ctx_handle == GSS_C_NO_CONTEXT)
  305. + return (GSS_S_NO_CONTEXT);
  306. +
  307. ret = gss_wrap_size_limit(minor_status,
  308. - context_handle,
  309. + sc->ctx_handle,
  310. conf_req_flag,
  311. qop_req,
  312. req_output_size,
Advertisement
Add Comment
Please, Sign In to add comment