curve25519pad.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. Hi,
  2. So I screwed up when writing the support for the curve25519 KEX method
  3. that doesn't depend on OpenSSL's BIGNUM type - a bug in my code left
  4. leading zero bytes where they should have been skipped. The impact of
  5. this is that OpenSSH 6.5 and 6.6 will fail during key exchange with a
  6. peer that implements curve25519-sha256@libssh.org properly about 0.2%
  7. of the time (one in every 512ish connections).
  8. We've fixed this for OpenSSH 6.7 by avoiding the curve25519-sha256
  9. key exchange for previous versions, but I'd recommend distributors
  10. of OpenSSH apply this patch so the affected code doesn't become
  11. too entrenched in LTS releases.
  12. The patch fixes the bug and makes OpenSSH identify itself as 6.6.1 so as
  13. to distinguish itself from the incorrect versions so the compatibility
  14. code to disable the affected KEX isn't activated.
  15. I've committed this on the 6.6 branch too.
  16. Apologies for the hassle.
  17. -d
  18. Index: version.h
  19. ===================================================================
  20. RCS file: /var/cvs/openssh/version.h,v
  21. retrieving revision 1.82
  22. diff -u -p -r1.82 version.h
  23. --- version.h 27 Feb 2014 23:01:54 -0000 1.82
  24. +++ version.h 20 Apr 2014 03:35:15 -0000
  25. @@ -1,6 +1,6 @@
  26. /* $OpenBSD: version.h,v 1.70 2014/02/27 22:57:40 djm Exp $ */
  27. -#define SSH_VERSION "OpenSSH_6.6"
  28. +#define SSH_VERSION "OpenSSH_6.6.1"
  29. #define SSH_PORTABLE "p1"
  30. #define SSH_RELEASE SSH_VERSION SSH_PORTABLE
  31. Index: compat.c
  32. ===================================================================
  33. RCS file: /var/cvs/openssh/compat.c,v
  34. retrieving revision 1.82
  35. retrieving revision 1.85
  36. diff -u -p -r1.82 -r1.85
  37. --- compat.c 31 Dec 2013 01:25:41 -0000 1.82
  38. +++ compat.c 20 Apr 2014 03:33:59 -0000 1.85
  39. @@ -95,6 +95,9 @@ compat_datafellows(const char *version)
  40. { "Sun_SSH_1.0*", SSH_BUG_NOREKEY|SSH_BUG_EXTEOF},
  41. { "OpenSSH_4*", 0 },
  42. { "OpenSSH_5*", SSH_NEW_OPENSSH|SSH_BUG_DYNAMIC_RPORT},
  43. + { "OpenSSH_6.6.1*", SSH_NEW_OPENSSH},
  44. + { "OpenSSH_6.5*,"
  45. + "OpenSSH_6.6*", SSH_NEW_OPENSSH|SSH_BUG_CURVE25519PAD},
  46. { "OpenSSH*", SSH_NEW_OPENSSH },
  47. { "*MindTerm*", 0 },
  48. { "2.1.0*", SSH_BUG_SIGBLOB|SSH_BUG_HMAC|
  49. @@ -251,7 +254,6 @@ compat_cipher_proposal(char *cipher_prop
  50. return cipher_prop;
  51. }
  52. -
  53. char *
  54. compat_pkalg_proposal(char *pkalg_prop)
  55. {
  56. @@ -263,5 +265,18 @@ compat_pkalg_proposal(char *pkalg_prop)
  57. if (*pkalg_prop == '\0')
  58. fatal("No supported PK algorithms found");
  59. return pkalg_prop;
  60. +}
  61. +
  62. +char *
  63. +compat_kex_proposal(char *kex_prop)
  64. +{
  65. + if (!(datafellows & SSH_BUG_CURVE25519PAD))
  66. + return kex_prop;
  67. + debug2("%s: original KEX proposal: %s", __func__, kex_prop);
  68. + kex_prop = filter_proposal(kex_prop, "curve25519-sha256@libssh.org");
  69. + debug2("%s: compat KEX proposal: %s", __func__, kex_prop);
  70. + if (*kex_prop == '\0')
  71. + fatal("No supported key exchange algorithms found");
  72. + return kex_prop;
  73. }
  74. Index: compat.h
  75. ===================================================================
  76. RCS file: /var/cvs/openssh/compat.h,v
  77. retrieving revision 1.42
  78. retrieving revision 1.43
  79. diff -u -p -r1.42 -r1.43
  80. --- compat.h 31 Dec 2013 01:25:41 -0000 1.42
  81. +++ compat.h 20 Apr 2014 03:25:31 -0000 1.43
  82. @@ -59,6 +59,7 @@
  83. #define SSH_BUG_RFWD_ADDR 0x02000000
  84. #define SSH_NEW_OPENSSH 0x04000000
  85. #define SSH_BUG_DYNAMIC_RPORT 0x08000000
  86. +#define SSH_BUG_CURVE25519PAD 0x10000000
  87. void enable_compat13(void);
  88. void enable_compat20(void);
  89. @@ -66,6 +67,7 @@ void compat_datafellows(const char *
  90. int proto_spec(const char *);
  91. char *compat_cipher_proposal(char *);
  92. char *compat_pkalg_proposal(char *);
  93. +char *compat_kex_proposal(char *);
  94. extern int compat13;
  95. extern int compat20;
  96. Index: sshd.c
  97. ===================================================================
  98. RCS file: /var/cvs/openssh/sshd.c,v
  99. retrieving revision 1.448
  100. retrieving revision 1.453
  101. diff -u -p -r1.448 -r1.453
  102. --- sshd.c 26 Feb 2014 23:20:08 -0000 1.448
  103. +++ sshd.c 20 Apr 2014 03:28:41 -0000 1.453
  104. @@ -2462,6 +2438,9 @@ do_ssh2_kex(void)
  105. if (options.kex_algorithms != NULL)
  106. myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
  107. + myproposal[PROPOSAL_KEX_ALGS] = compat_kex_proposal(
  108. + myproposal[PROPOSAL_KEX_ALGS]);
  109. +
  110. if (options.rekey_limit || options.rekey_interval)
  111. packet_set_rekey_limits((u_int32_t)options.rekey_limit,
  112. (time_t)options.rekey_interval);
  113. Index: sshconnect2.c
  114. ===================================================================
  115. RCS file: /var/cvs/openssh/sshconnect2.c,v
  116. retrieving revision 1.197
  117. retrieving revision 1.199
  118. diff -u -p -r1.197 -r1.199
  119. --- sshconnect2.c 4 Feb 2014 00:20:16 -0000 1.197
  120. +++ sshconnect2.c 20 Apr 2014 03:25:31 -0000 1.199
  121. @@ -195,6 +196,8 @@ ssh_kex2(char *host, struct sockaddr *ho
  122. }
  123. if (options.kex_algorithms != NULL)
  124. myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
  125. + myproposal[PROPOSAL_KEX_ALGS] = compat_kex_proposal(
  126. + myproposal[PROPOSAL_KEX_ALGS]);
  127. if (options.rekey_limit || options.rekey_interval)
  128. packet_set_rekey_limits((u_int32_t)options.rekey_limit,
  129. Index: bufaux.c
  130. ===================================================================
  131. RCS file: /var/cvs/openssh/bufaux.c,v
  132. retrieving revision 1.62
  133. retrieving revision 1.63
  134. diff -u -p -r1.62 -r1.63
  135. --- bufaux.c 4 Feb 2014 00:20:15 -0000 1.62
  136. +++ bufaux.c 20 Apr 2014 03:24:50 -0000 1.63
  137. @@ -1,4 +1,4 @@
  138. -/* $OpenBSD: bufaux.c,v 1.56 2014/02/02 03:44:31 djm Exp $ */
  139. +/* $OpenBSD: bufaux.c,v 1.57 2014/04/16 23:22:45 djm Exp $ */
  140. /*
  141. * Author: Tatu Ylonen <ylo@cs.hut.fi>
  142. * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  143. @@ -372,6 +372,9 @@ buffer_put_bignum2_from_string(Buffer *b
  144. if (l > 8 * 1024)
  145. fatal("%s: length %u too long", __func__, l);
  146. + /* Skip leading zero bytes */
  147. + for (; l > 0 && *s == 0; l--, s++)
  148. + ;
  149. p = buf = xmalloc(l + 1);
  150. /*
  151. * If most significant bit is set then prepend a zero byte to
  152. _______________________________________________
  153. openssh-unix-dev mailing list
  154. openssh-unix-dev@mindrot.org
  155. https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev