Commit c7590efa authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Greg Kroah-Hartman

crypto: cpt - don't sleep of CRYPTO_TFM_REQ_MAY_SLEEP was not specified

commit 9e27c991 upstream.

There is this call chain:
cvm_encrypt -> cvm_enc_dec -> cptvf_do_request -> process_request -> kzalloc
where we call sleeping allocator function even if CRYPTO_TFM_REQ_MAY_SLEEP
was not specified.
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org	# v4.11+
Fixes: c694b233 ("crypto: cavium - Add the Virtual Function driver for CPT")
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent aabc11c1
...@@ -205,6 +205,7 @@ static inline int cvm_enc_dec(struct ablkcipher_request *req, u32 enc) ...@@ -205,6 +205,7 @@ static inline int cvm_enc_dec(struct ablkcipher_request *req, u32 enc)
int status; int status;
memset(req_info, 0, sizeof(struct cpt_request_info)); memset(req_info, 0, sizeof(struct cpt_request_info));
req_info->may_sleep = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) != 0;
memset(fctx, 0, sizeof(struct fc_context)); memset(fctx, 0, sizeof(struct fc_context));
create_input_list(req, enc, enc_iv_len); create_input_list(req, enc, enc_iv_len);
create_output_list(req, enc_iv_len); create_output_list(req, enc_iv_len);
......
...@@ -136,7 +136,7 @@ static inline int setup_sgio_list(struct cpt_vf *cptvf, ...@@ -136,7 +136,7 @@ static inline int setup_sgio_list(struct cpt_vf *cptvf,
/* Setup gather (input) components */ /* Setup gather (input) components */
g_sz_bytes = ((req->incnt + 3) / 4) * sizeof(struct sglist_component); g_sz_bytes = ((req->incnt + 3) / 4) * sizeof(struct sglist_component);
info->gather_components = kzalloc(g_sz_bytes, GFP_KERNEL); info->gather_components = kzalloc(g_sz_bytes, req->may_sleep ? GFP_KERNEL : GFP_ATOMIC);
if (!info->gather_components) { if (!info->gather_components) {
ret = -ENOMEM; ret = -ENOMEM;
goto scatter_gather_clean; goto scatter_gather_clean;
...@@ -153,7 +153,7 @@ static inline int setup_sgio_list(struct cpt_vf *cptvf, ...@@ -153,7 +153,7 @@ static inline int setup_sgio_list(struct cpt_vf *cptvf,
/* Setup scatter (output) components */ /* Setup scatter (output) components */
s_sz_bytes = ((req->outcnt + 3) / 4) * sizeof(struct sglist_component); s_sz_bytes = ((req->outcnt + 3) / 4) * sizeof(struct sglist_component);
info->scatter_components = kzalloc(s_sz_bytes, GFP_KERNEL); info->scatter_components = kzalloc(s_sz_bytes, req->may_sleep ? GFP_KERNEL : GFP_ATOMIC);
if (!info->scatter_components) { if (!info->scatter_components) {
ret = -ENOMEM; ret = -ENOMEM;
goto scatter_gather_clean; goto scatter_gather_clean;
...@@ -170,7 +170,7 @@ static inline int setup_sgio_list(struct cpt_vf *cptvf, ...@@ -170,7 +170,7 @@ static inline int setup_sgio_list(struct cpt_vf *cptvf,
/* Create and initialize DPTR */ /* Create and initialize DPTR */
info->dlen = g_sz_bytes + s_sz_bytes + SG_LIST_HDR_SIZE; info->dlen = g_sz_bytes + s_sz_bytes + SG_LIST_HDR_SIZE;
info->in_buffer = kzalloc(info->dlen, GFP_KERNEL); info->in_buffer = kzalloc(info->dlen, req->may_sleep ? GFP_KERNEL : GFP_ATOMIC);
if (!info->in_buffer) { if (!info->in_buffer) {
ret = -ENOMEM; ret = -ENOMEM;
goto scatter_gather_clean; goto scatter_gather_clean;
...@@ -198,7 +198,7 @@ static inline int setup_sgio_list(struct cpt_vf *cptvf, ...@@ -198,7 +198,7 @@ static inline int setup_sgio_list(struct cpt_vf *cptvf,
} }
/* Create and initialize RPTR */ /* Create and initialize RPTR */
info->out_buffer = kzalloc(COMPLETION_CODE_SIZE, GFP_KERNEL); info->out_buffer = kzalloc(COMPLETION_CODE_SIZE, req->may_sleep ? GFP_KERNEL : GFP_ATOMIC);
if (!info->out_buffer) { if (!info->out_buffer) {
ret = -ENOMEM; ret = -ENOMEM;
goto scatter_gather_clean; goto scatter_gather_clean;
...@@ -434,7 +434,7 @@ int process_request(struct cpt_vf *cptvf, struct cpt_request_info *req) ...@@ -434,7 +434,7 @@ int process_request(struct cpt_vf *cptvf, struct cpt_request_info *req)
struct cpt_vq_command vq_cmd; struct cpt_vq_command vq_cmd;
union cpt_inst_s cptinst; union cpt_inst_s cptinst;
info = kzalloc(sizeof(*info), GFP_KERNEL); info = kzalloc(sizeof(*info), req->may_sleep ? GFP_KERNEL : GFP_ATOMIC);
if (unlikely(!info)) { if (unlikely(!info)) {
dev_err(&pdev->dev, "Unable to allocate memory for info_buffer\n"); dev_err(&pdev->dev, "Unable to allocate memory for info_buffer\n");
return -ENOMEM; return -ENOMEM;
...@@ -456,7 +456,7 @@ int process_request(struct cpt_vf *cptvf, struct cpt_request_info *req) ...@@ -456,7 +456,7 @@ int process_request(struct cpt_vf *cptvf, struct cpt_request_info *req)
* Get buffer for union cpt_res_s response * Get buffer for union cpt_res_s response
* structure and its physical address * structure and its physical address
*/ */
info->completion_addr = kzalloc(sizeof(union cpt_res_s), GFP_KERNEL); info->completion_addr = kzalloc(sizeof(union cpt_res_s), req->may_sleep ? GFP_KERNEL : GFP_ATOMIC);
if (unlikely(!info->completion_addr)) { if (unlikely(!info->completion_addr)) {
dev_err(&pdev->dev, "Unable to allocate memory for completion_addr\n"); dev_err(&pdev->dev, "Unable to allocate memory for completion_addr\n");
ret = -ENOMEM; ret = -ENOMEM;
......
...@@ -65,6 +65,8 @@ struct cpt_request_info { ...@@ -65,6 +65,8 @@ struct cpt_request_info {
union ctrl_info ctrl; /* User control information */ union ctrl_info ctrl; /* User control information */
struct cptvf_request req; /* Request Information (Core specific) */ struct cptvf_request req; /* Request Information (Core specific) */
bool may_sleep;
struct buf_ptr in[MAX_BUF_CNT]; struct buf_ptr in[MAX_BUF_CNT];
struct buf_ptr out[MAX_BUF_CNT]; struct buf_ptr out[MAX_BUF_CNT];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment