Skip to content

Commit c8d46f1

Browse files
hfreudeVasily Gorbik
authored andcommitted
s390/zcrypt: Fix memory leak with CCA cards used as accelerator
Tests showed that there is a memory leak if CCA cards are used as accelerator for clear key RSA requests (ME and CRT). With the last rework for the memory allocation the AP messages are allocated by ap_init_apmsg() but for some reason on two places (ME and CRT) the older allocation was still in place. So the first allocation simple was never freed. Fixes: 57db62a ("s390/ap/zcrypt: Rework AP message buffer allocation") Reported-by: Yi Zhang <yi.zhang@redhat.com> Closes: https://lore.kernel.org/linux-s390/CAHj4cs9H67Uz0iVaRQv447p7JFPRPy3TKAT4=Y6_e=wSHCZM5w@mail.gmail.com/ Reported-by: Nadja Hariz <Nadia.Hariz@ibm.com> Cc: stable@vger.kernel.org Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com> Reviewed-by: Holger Dengler <dengler@linux.ibm.com> Acked-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Harald Freudenberger <freude@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent 57ad0d4 commit c8d46f1

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

drivers/s390/crypto/zcrypt_msgtype6.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,10 @@ static atomic_t zcrypt_step = ATOMIC_INIT(0);
953953
/*
954954
* The request distributor calls this function if it picked the CEXxC
955955
* device to handle a modexpo request.
956+
* This function assumes that ap_msg has been initialized with
957+
* ap_init_apmsg() and thus a valid buffer with the size of
958+
* ap_msg->bufsize is available within ap_msg. Also the caller has
959+
* to make sure ap_release_apmsg() is always called even on failure.
956960
* @zq: pointer to zcrypt_queue structure that identifies the
957961
* CEXxC device to the request distributor
958962
* @mex: pointer to the modexpo request buffer
@@ -964,21 +968,17 @@ static long zcrypt_msgtype6_modexpo(struct zcrypt_queue *zq,
964968
struct ap_response_type *resp_type = &ap_msg->response;
965969
int rc;
966970

967-
ap_msg->msg = (void *)get_zeroed_page(GFP_KERNEL);
968-
if (!ap_msg->msg)
969-
return -ENOMEM;
970-
ap_msg->bufsize = PAGE_SIZE;
971971
ap_msg->receive = zcrypt_msgtype6_receive;
972972
ap_msg->psmid = (((unsigned long)current->pid) << 32) +
973973
atomic_inc_return(&zcrypt_step);
974974
rc = icamex_msg_to_type6mex_msgx(zq, ap_msg, mex);
975975
if (rc)
976-
goto out_free;
976+
goto out;
977977
resp_type->type = CEXXC_RESPONSE_TYPE_ICA;
978978
init_completion(&resp_type->work);
979979
rc = ap_queue_message(zq->queue, ap_msg);
980980
if (rc)
981-
goto out_free;
981+
goto out;
982982
rc = wait_for_completion_interruptible(&resp_type->work);
983983
if (rc == 0) {
984984
rc = ap_msg->rc;
@@ -991,15 +991,17 @@ static long zcrypt_msgtype6_modexpo(struct zcrypt_queue *zq,
991991
ap_cancel_message(zq->queue, ap_msg);
992992
}
993993

994-
out_free:
995-
free_page((unsigned long)ap_msg->msg);
996-
ap_msg->msg = NULL;
994+
out:
997995
return rc;
998996
}
999997

1000998
/*
1001999
* The request distributor calls this function if it picked the CEXxC
10021000
* device to handle a modexpo_crt request.
1001+
* This function assumes that ap_msg has been initialized with
1002+
* ap_init_apmsg() and thus a valid buffer with the size of
1003+
* ap_msg->bufsize is available within ap_msg. Also the caller has
1004+
* to make sure ap_release_apmsg() is always called even on failure.
10031005
* @zq: pointer to zcrypt_queue structure that identifies the
10041006
* CEXxC device to the request distributor
10051007
* @crt: pointer to the modexpoc_crt request buffer
@@ -1011,21 +1013,17 @@ static long zcrypt_msgtype6_modexpo_crt(struct zcrypt_queue *zq,
10111013
struct ap_response_type *resp_type = &ap_msg->response;
10121014
int rc;
10131015

1014-
ap_msg->msg = (void *)get_zeroed_page(GFP_KERNEL);
1015-
if (!ap_msg->msg)
1016-
return -ENOMEM;
1017-
ap_msg->bufsize = PAGE_SIZE;
10181016
ap_msg->receive = zcrypt_msgtype6_receive;
10191017
ap_msg->psmid = (((unsigned long)current->pid) << 32) +
10201018
atomic_inc_return(&zcrypt_step);
10211019
rc = icacrt_msg_to_type6crt_msgx(zq, ap_msg, crt);
10221020
if (rc)
1023-
goto out_free;
1021+
goto out;
10241022
resp_type->type = CEXXC_RESPONSE_TYPE_ICA;
10251023
init_completion(&resp_type->work);
10261024
rc = ap_queue_message(zq->queue, ap_msg);
10271025
if (rc)
1028-
goto out_free;
1026+
goto out;
10291027
rc = wait_for_completion_interruptible(&resp_type->work);
10301028
if (rc == 0) {
10311029
rc = ap_msg->rc;
@@ -1038,9 +1036,7 @@ static long zcrypt_msgtype6_modexpo_crt(struct zcrypt_queue *zq,
10381036
ap_cancel_message(zq->queue, ap_msg);
10391037
}
10401038

1041-
out_free:
1042-
free_page((unsigned long)ap_msg->msg);
1043-
ap_msg->msg = NULL;
1039+
out:
10441040
return rc;
10451041
}
10461042

0 commit comments

Comments
 (0)