Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-3-0]: src/crypto/dist/openssl Apply patch (requested by ghen in t...



details:   https://anonhg.NetBSD.org/src/rev/118776bac95b
branches:  netbsd-3-0
changeset: 579301:118776bac95b
user:      tron <tron%NetBSD.org@localhost>
date:      Fri Oct 06 11:11:57 2006 +0000

description:
Apply patch (requested by ghen in ticket #1537):
http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-2937
    OpenSSL 0.9.7 before 0.9.7l and 0.9.8 before 0.9.8d allows
    remote attackers to cause a denial of service (inifnite loop
    and memory consumption) via malformed ASN.1 structures that
    trigger an improperly handled error condition.

http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-2940
    OpenSSL 0.9.7 before 0.9.7l, 0.9.8 before 0.9.8d, and earlier
    versions allows attackers to cause a denial of service (CPU
    consumption) via certain public keys that require extra time
    to process.

http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-3738
    Buffer overflow in the SSL_get_shared_ciphers function in
    OpenSSL 0.9.7 before 0.9.7l, 0.9.8 before 0.9.8d, and earlier
    versions has unspecified impact and remote attack vectors
    involving a long list of ciphers.

http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-4343
    Unspecified vulnerability in the SSLv2 client code in OpenSSL
    0.9.7 before 0.9.7l, 0.9.8 before 0.9.8d, and earlier versions
    allows remote servers to cause a denial of service (client
    crash) via unknown vectors.

diffstat:

 crypto/dist/openssl/crypto/asn1/tasn_dec.c |   3 ++
 crypto/dist/openssl/crypto/dh/dh.h         |   5 +++
 crypto/dist/openssl/crypto/dh/dh_err.c     |   1 +
 crypto/dist/openssl/crypto/dh/dh_key.c     |   6 ++++
 crypto/dist/openssl/crypto/dsa/dsa.h       |   7 ++++
 crypto/dist/openssl/crypto/dsa/dsa_err.c   |   2 +
 crypto/dist/openssl/crypto/dsa/dsa_ossl.c  |  12 ++++++++
 crypto/dist/openssl/crypto/rsa/rsa.h       |  12 ++++++++
 crypto/dist/openssl/crypto/rsa/rsa_eay.c   |  44 ++++++++++++++++++++++++++++++
 crypto/dist/openssl/crypto/rsa/rsa_err.c   |   1 +
 crypto/dist/openssl/ssl/s2_clnt.c          |   3 +-
 crypto/dist/openssl/ssl/s3_srvr.c          |   2 +-
 crypto/dist/openssl/ssl/ssl_lib.c          |   2 +-
 13 files changed, 97 insertions(+), 3 deletions(-)

diffs (262 lines):

diff -r 46eb0ee9ba5d -r 118776bac95b crypto/dist/openssl/crypto/asn1/tasn_dec.c
--- a/crypto/dist/openssl/crypto/asn1/tasn_dec.c        Sat Sep 16 16:57:51 2006 +0000
+++ b/crypto/dist/openssl/crypto/asn1/tasn_dec.c        Fri Oct 06 11:11:57 2006 +0000
@@ -628,6 +628,9 @@
                ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
                return 0;
        } else if(ret == -1) return -1;
+
+       ret = 0;
+
        /* SEQUENCE, SET and "OTHER" are left in encoded form */
        if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
                /* Clear context cache for type OTHER because the auto clear when
diff -r 46eb0ee9ba5d -r 118776bac95b crypto/dist/openssl/crypto/dh/dh.h
--- a/crypto/dist/openssl/crypto/dh/dh.h        Sat Sep 16 16:57:51 2006 +0000
+++ b/crypto/dist/openssl/crypto/dh/dh.h        Fri Oct 06 11:11:57 2006 +0000
@@ -64,6 +64,10 @@
 #include <openssl/crypto.h>
 #include <openssl/ossl_typ.h>
        
+#ifndef OPENSSL_DH_MAX_MODULUS_BITS
+# define OPENSSL_DH_MAX_MODULUS_BITS   10000
+#endif
+
 #define DH_FLAG_CACHE_MONT_P   0x01
 
 #ifdef  __cplusplus
@@ -188,6 +192,7 @@
 /* Reason codes. */
 #define DH_R_BAD_GENERATOR                              101
 #define DH_R_NO_PRIVATE_VALUE                           100
+#define DH_R_MODULUS_TOO_LARGE                          103
 
 #ifdef  __cplusplus
 }
diff -r 46eb0ee9ba5d -r 118776bac95b crypto/dist/openssl/crypto/dh/dh_err.c
--- a/crypto/dist/openssl/crypto/dh/dh_err.c    Sat Sep 16 16:57:51 2006 +0000
+++ b/crypto/dist/openssl/crypto/dh/dh_err.c    Fri Oct 06 11:11:57 2006 +0000
@@ -78,6 +78,7 @@
 static ERR_STRING_DATA DH_str_reasons[]=
        {
 {DH_R_BAD_GENERATOR                      ,"bad generator"},
+{DH_R_MODULUS_TOO_LARGE                  ,"modulus too large"},
 {DH_R_NO_PRIVATE_VALUE                   ,"no private value"},
 {0,NULL}
        };
diff -r 46eb0ee9ba5d -r 118776bac95b crypto/dist/openssl/crypto/dh/dh_key.c
--- a/crypto/dist/openssl/crypto/dh/dh_key.c    Sat Sep 16 16:57:51 2006 +0000
+++ b/crypto/dist/openssl/crypto/dh/dh_key.c    Fri Oct 06 11:11:57 2006 +0000
@@ -162,6 +162,12 @@
        BIGNUM *tmp;
        int ret= -1;
 
+       if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS)
+               {
+               DHerr(DH_F_DH_COMPUTE_KEY,DH_R_MODULUS_TOO_LARGE);
+               return -1;
+               }
+
        ctx = BN_CTX_new();
        if (ctx == NULL) goto err;
        BN_CTX_start(ctx);
diff -r 46eb0ee9ba5d -r 118776bac95b crypto/dist/openssl/crypto/dsa/dsa.h
--- a/crypto/dist/openssl/crypto/dsa/dsa.h      Sat Sep 16 16:57:51 2006 +0000
+++ b/crypto/dist/openssl/crypto/dsa/dsa.h      Fri Oct 06 11:11:57 2006 +0000
@@ -71,6 +71,10 @@
 #include <openssl/ossl_typ.h>
 # include <openssl/dh.h>
 
+#ifndef OPENSSL_DSA_MAX_MODULUS_BITS
+# define OPENSSL_DSA_MAX_MODULUS_BITS  10000
+#endif
+
 #define DSA_FLAG_CACHE_MONT_P  0x01
 
 #ifdef  __cplusplus
@@ -227,8 +231,11 @@
 #define DSA_F_SIG_CB                                    114
 
 /* Reason codes. */
+#define DSA_R_BAD_Q_VALUE                               102
 #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE               100
 #define DSA_R_MISSING_PARAMETERS                        101
+#define DSA_R_MODULUS_TOO_LARGE                                 103
+
 
 #ifdef  __cplusplus
 }
diff -r 46eb0ee9ba5d -r 118776bac95b crypto/dist/openssl/crypto/dsa/dsa_err.c
--- a/crypto/dist/openssl/crypto/dsa/dsa_err.c  Sat Sep 16 16:57:51 2006 +0000
+++ b/crypto/dist/openssl/crypto/dsa/dsa_err.c  Fri Oct 06 11:11:57 2006 +0000
@@ -85,8 +85,10 @@
 
 static ERR_STRING_DATA DSA_str_reasons[]=
        {
+{DSA_R_BAD_Q_VALUE                       ,"bad q value"},
 {DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE       ,"data too large for key size"},
 {DSA_R_MISSING_PARAMETERS                ,"missing parameters"},
+{DSA_R_MODULUS_TOO_LARGE                 ,"modulus too large"},
 {0,NULL}
        };
 
diff -r 46eb0ee9ba5d -r 118776bac95b crypto/dist/openssl/crypto/dsa/dsa_ossl.c
--- a/crypto/dist/openssl/crypto/dsa/dsa_ossl.c Sat Sep 16 16:57:51 2006 +0000
+++ b/crypto/dist/openssl/crypto/dsa/dsa_ossl.c Fri Oct 06 11:11:57 2006 +0000
@@ -244,6 +244,18 @@
                return -1;
                }
 
+       if (BN_num_bits(dsa->q) != 160)
+               {
+               DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_BAD_Q_VALUE);
+               return -1;
+               }
+
+       if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS)
+               {
+               DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MODULUS_TOO_LARGE);
+               return -1;
+               }
+
        BN_init(&u1);
        BN_init(&u2);
        BN_init(&t1);
diff -r 46eb0ee9ba5d -r 118776bac95b crypto/dist/openssl/crypto/rsa/rsa.h
--- a/crypto/dist/openssl/crypto/rsa/rsa.h      Sat Sep 16 16:57:51 2006 +0000
+++ b/crypto/dist/openssl/crypto/rsa/rsa.h      Fri Oct 06 11:11:57 2006 +0000
@@ -144,6 +144,17 @@
        BN_BLINDING *blinding;
        };
 
+#ifndef OPENSSL_RSA_MAX_MODULUS_BITS
+# define OPENSSL_RSA_MAX_MODULUS_BITS  16400
+#endif
+
+#ifndef OPENSSL_RSA_SMALL_MODULUS_BITS
+# define OPENSSL_RSA_SMALL_MODULUS_BITS        4112
+#endif
+#ifndef OPENSSL_RSA_MAX_PUBEXP_BITS
+# define OPENSSL_RSA_MAX_PUBEXP_BITS   72 /* exponent limit enforced for "large" modulus only */
+#endif
+
 #define RSA_3  0x3L
 #define RSA_F4 0x10001L
 
@@ -333,6 +344,7 @@
 #define RSA_R_INVALID_MESSAGE_LENGTH                    131
 #define RSA_R_IQMP_NOT_INVERSE_OF_Q                     126
 #define RSA_R_KEY_SIZE_TOO_SMALL                        120
+#define RSA_R_MODULUS_TOO_LARGE                                 105
 #define RSA_R_NULL_BEFORE_BLOCK_MISSING                         113
 #define RSA_R_N_DOES_NOT_EQUAL_P_Q                      127
 #define RSA_R_OAEP_DECODING_ERROR                       121
diff -r 46eb0ee9ba5d -r 118776bac95b crypto/dist/openssl/crypto/rsa/rsa_eay.c
--- a/crypto/dist/openssl/crypto/rsa/rsa_eay.c  Sat Sep 16 16:57:51 2006 +0000
+++ b/crypto/dist/openssl/crypto/rsa/rsa_eay.c  Fri Oct 06 11:11:57 2006 +0000
@@ -104,6 +104,28 @@
        unsigned char *buf=NULL;
        BN_CTX *ctx=NULL;
 
+       if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS)
+               {
+               RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE);
+               return -1;
+               }
+
+       if (BN_ucmp(rsa->n, rsa->e) <= 0)
+               {
+               RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
+               return -1;
+               }
+
+       /* for large moduli, enforce exponent limit */
+       if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS)
+               {
+               if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS)
+                       {
+                       RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
+                       return -1;
+                       }
+               }
+
        BN_init(&f);
        BN_init(&ret);
        if ((ctx=BN_CTX_new()) == NULL) goto err;
@@ -504,6 +526,28 @@
        unsigned char *buf=NULL;
        BN_CTX *ctx=NULL;
 
+       if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS)
+               {
+               RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE);
+               return -1;
+               }
+
+       if (BN_ucmp(rsa->n, rsa->e) <= 0)
+               {
+               RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
+               return -1;
+               }
+
+       /* for large moduli, enforce exponent limit */
+       if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS)
+               {
+               if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS)
+                       {
+                       RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
+                       return -1;
+                       }
+               }
+       
        BN_init(&f);
        BN_init(&ret);
        ctx=BN_CTX_new();
diff -r 46eb0ee9ba5d -r 118776bac95b crypto/dist/openssl/crypto/rsa/rsa_err.c
--- a/crypto/dist/openssl/crypto/rsa/rsa_err.c  Sat Sep 16 16:57:51 2006 +0000
+++ b/crypto/dist/openssl/crypto/rsa/rsa_err.c  Fri Oct 06 11:11:57 2006 +0000
@@ -116,6 +116,7 @@
 {RSA_R_INVALID_MESSAGE_LENGTH            ,"invalid message length"},
 {RSA_R_IQMP_NOT_INVERSE_OF_Q             ,"iqmp not inverse of q"},
 {RSA_R_KEY_SIZE_TOO_SMALL                ,"key size too small"},
+{RSA_R_MODULUS_TOO_LARGE                 ,"modulus too large"},
 {RSA_R_NULL_BEFORE_BLOCK_MISSING         ,"null before block missing"},
 {RSA_R_N_DOES_NOT_EQUAL_P_Q              ,"n does not equal p q"},
 {RSA_R_OAEP_DECODING_ERROR               ,"oaep decoding error"},
diff -r 46eb0ee9ba5d -r 118776bac95b crypto/dist/openssl/ssl/s2_clnt.c
--- a/crypto/dist/openssl/ssl/s2_clnt.c Sat Sep 16 16:57:51 2006 +0000
+++ b/crypto/dist/openssl/ssl/s2_clnt.c Fri Oct 06 11:11:57 2006 +0000
@@ -538,7 +538,8 @@
                CRYPTO_add(&s->session->peer->references, 1, CRYPTO_LOCK_X509);
                }
 
-       if (s->session->peer != s->session->sess_cert->peer_key->x509)
+       if (s->session->sess_cert == NULL 
+         || s->session->peer != s->session->sess_cert->peer_key->x509)
                /* can't happen */
                {
                ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
diff -r 46eb0ee9ba5d -r 118776bac95b crypto/dist/openssl/ssl/s3_srvr.c
--- a/crypto/dist/openssl/ssl/s3_srvr.c Sat Sep 16 16:57:51 2006 +0000
+++ b/crypto/dist/openssl/ssl/s3_srvr.c Fri Oct 06 11:11:57 2006 +0000
@@ -1722,7 +1722,7 @@
 
                 if (kssl_ctx->client_princ)
                         {
-                        int len = strlen(kssl_ctx->client_princ);
+                        size_t len = strlen(kssl_ctx->client_princ);
                         if ( len < SSL_MAX_KRB5_PRINCIPAL_LENGTH ) 
                                 {
                                 s->session->krb5_client_princ_len = len;
diff -r 46eb0ee9ba5d -r 118776bac95b crypto/dist/openssl/ssl/ssl_lib.c
--- a/crypto/dist/openssl/ssl/ssl_lib.c Sat Sep 16 16:57:51 2006 +0000
+++ b/crypto/dist/openssl/ssl/ssl_lib.c Fri Oct 06 11:11:57 2006 +0000
@@ -1166,7 +1166,7 @@
                c=sk_SSL_CIPHER_value(sk,i);
                for (cp=c->name; *cp; )
                        {
-                       if (len-- == 0)
+                       if (len-- <= 0)
                                {
                                *p='\0';
                                return(buf);



Home | Main Index | Thread Index | Old Index