s390/zcrypt: Explicitly check input data length.
authorHarald Freudenberger <freude@linux.vnet.ibm.com>
Tue, 12 Sep 2017 05:04:26 +0000 (07:04 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Thu, 28 Sep 2017 05:29:43 +0000 (07:29 +0200)
The function to prepare MEX type 50 ap messages did
not explicitly check for the data length in case of
data > 512 bytes. Instead the function assumes the
boundary check done in the ioctl function will always
reject requests with invalid data length values.
However, screening just the function code may give the
illusion, that there may be a gap which could be
exploited by userspace for buffer overwrite attacks.

Signed-off-by: Harald Freudenberger <freude@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
drivers/s390/crypto/zcrypt_msgtype50.c

index 6dd5d7c..db5bde4 100644 (file)
@@ -240,8 +240,7 @@ static int ICAMEX_msg_to_type50MEX_msg(struct zcrypt_queue *zq,
                mod = meb2->modulus + sizeof(meb2->modulus) - mod_len;
                exp = meb2->exponent + sizeof(meb2->exponent) - mod_len;
                inp = meb2->message + sizeof(meb2->message) - mod_len;
-       } else {
-               /* mod_len > 256 = 4096 bit RSA Key */
+       } else if (mod_len <= 512) {
                struct type50_meb3_msg *meb3 = ap_msg->message;
                memset(meb3, 0, sizeof(*meb3));
                ap_msg->length = sizeof(*meb3);
@@ -251,7 +250,8 @@ static int ICAMEX_msg_to_type50MEX_msg(struct zcrypt_queue *zq,
                mod = meb3->modulus + sizeof(meb3->modulus) - mod_len;
                exp = meb3->exponent + sizeof(meb3->exponent) - mod_len;
                inp = meb3->message + sizeof(meb3->message) - mod_len;
-       }
+       } else
+               return -EINVAL;
 
        if (copy_from_user(mod, mex->n_modulus, mod_len) ||
            copy_from_user(exp, mex->b_key, mod_len) ||