OSDN Git Service

crypto: dh - fix calculating encoded key size
authorEric Biggers <ebiggers@google.com>
Fri, 27 Jul 2018 22:36:10 +0000 (15:36 -0700)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 3 Aug 2018 10:06:06 +0000 (18:06 +0800)
It was forgotten to increase DH_KPP_SECRET_MIN_SIZE to include 'q_size',
causing an out-of-bounds write of 4 bytes in crypto_dh_encode_key(), and
an out-of-bounds read of 4 bytes in crypto_dh_decode_key().  Fix it, and
fix the lengths of the test vectors to match this.

Reported-by: syzbot+6d38d558c25b53b8f4ed@syzkaller.appspotmail.com
Fixes: e3fe0ae12962 ("crypto: dh - add public key verification test")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/dh_helper.c
crypto/testmgr.h

index a7de3d9..db9b2d9 100644 (file)
@@ -14,7 +14,7 @@
 #include <crypto/dh.h>
 #include <crypto/kpp.h>
 
-#define DH_KPP_SECRET_MIN_SIZE (sizeof(struct kpp_secret) + 3 * sizeof(int))
+#define DH_KPP_SECRET_MIN_SIZE (sizeof(struct kpp_secret) + 4 * sizeof(int))
 
 static inline u8 *dh_pack_data(void *dst, const void *src, size_t size)
 {
index 759462d..173111c 100644 (file)
@@ -641,14 +641,14 @@ static const struct kpp_testvec dh_tv_template[] = {
        .secret =
 #ifdef __LITTLE_ENDIAN
        "\x01\x00" /* type */
-       "\x11\x02" /* len */
+       "\x15\x02" /* len */
        "\x00\x01\x00\x00" /* key_size */
        "\x00\x01\x00\x00" /* p_size */
        "\x00\x00\x00\x00" /* q_size */
        "\x01\x00\x00\x00" /* g_size */
 #else
        "\x00\x01" /* type */
-       "\x02\x11" /* len */
+       "\x02\x15" /* len */
        "\x00\x00\x01\x00" /* key_size */
        "\x00\x00\x01\x00" /* p_size */
        "\x00\x00\x00\x00" /* q_size */
@@ -741,7 +741,7 @@ static const struct kpp_testvec dh_tv_template[] = {
        "\xd3\x34\x49\xad\x64\xa6\xb1\xc0\x59\x28\x75\x60\xa7\x8a\xb0\x11"
        "\x56\x89\x42\x74\x11\xf5\xf6\x5e\x6f\x16\x54\x6a\xb1\x76\x4d\x50"
        "\x8a\x68\xc1\x5b\x82\xb9\x0d\x00\x32\x50\xed\x88\x87\x48\x92\x17",
-       .secret_size = 529,
+       .secret_size = 533,
        .b_public_size = 256,
        .expected_a_public_size = 256,
        .expected_ss_size = 256,
@@ -750,14 +750,14 @@ static const struct kpp_testvec dh_tv_template[] = {
        .secret =
 #ifdef __LITTLE_ENDIAN
        "\x01\x00" /* type */
-       "\x11\x02" /* len */
+       "\x15\x02" /* len */
        "\x00\x01\x00\x00" /* key_size */
        "\x00\x01\x00\x00" /* p_size */
        "\x00\x00\x00\x00" /* q_size */
        "\x01\x00\x00\x00" /* g_size */
 #else
        "\x00\x01" /* type */
-       "\x02\x11" /* len */
+       "\x02\x15" /* len */
        "\x00\x00\x01\x00" /* key_size */
        "\x00\x00\x01\x00" /* p_size */
        "\x00\x00\x00\x00" /* q_size */
@@ -850,7 +850,7 @@ static const struct kpp_testvec dh_tv_template[] = {
        "\x5e\x5a\x64\xbd\xf6\x85\x04\xe8\x28\x6a\xac\xef\xce\x19\x8e\x9a"
        "\xfe\x75\xc0\x27\x69\xe3\xb3\x7b\x21\xa7\xb1\x16\xa4\x85\x23\xee"
        "\xb0\x1b\x04\x6e\xbd\xab\x16\xde\xfd\x86\x6b\xa9\x95\xd7\x0b\xfd",
-       .secret_size = 529,
+       .secret_size = 533,
        .b_public_size = 256,
        .expected_a_public_size = 256,
        .expected_ss_size = 256,