Skip to content

Commit 39fc22a

Browse files
committed
crypto: acomp - Fix synchronous acomp chaining fallback
The synchronous acomp fallback code path is broken because the completion code path assumes that the state object is always set but this is only done for asynchronous algorithms. First of all remove the assumption on the completion code path by passing in req0 instead of the state. However, also remove the conditional setting of the state since it's always in the request object anyway. Fixes: b67a026 ("crypto: acomp - Add request chaining and virtual addresses") Reported-by: Giovanni Cabiddu <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 8b54e6a commit 39fc22a

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

crypto/acompress.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -155,27 +155,18 @@ EXPORT_SYMBOL_GPL(crypto_alloc_acomp_node);
155155

156156
static void acomp_save_req(struct acomp_req *req, crypto_completion_t cplt)
157157
{
158-
struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
159158
struct acomp_req_chain *state = &req->chain;
160159

161-
if (!acomp_is_async(tfm))
162-
return;
163-
164160
state->compl = req->base.complete;
165161
state->data = req->base.data;
166162
req->base.complete = cplt;
167163
req->base.data = state;
168164
state->req0 = req;
169165
}
170166

171-
static void acomp_restore_req(struct acomp_req_chain *state)
167+
static void acomp_restore_req(struct acomp_req *req)
172168
{
173-
struct acomp_req *req = state->req0;
174-
struct crypto_acomp *tfm;
175-
176-
tfm = crypto_acomp_reqtfm(req);
177-
if (!acomp_is_async(tfm))
178-
return;
169+
struct acomp_req_chain *state = req->base.data;
179170

180171
req->base.complete = state->compl;
181172
req->base.data = state->data;
@@ -289,10 +280,9 @@ static int acomp_do_one_req(struct acomp_req_chain *state,
289280
return state->op(req);
290281
}
291282

292-
static int acomp_reqchain_finish(struct acomp_req_chain *state,
293-
int err, u32 mask)
283+
static int acomp_reqchain_finish(struct acomp_req *req0, int err, u32 mask)
294284
{
295-
struct acomp_req *req0 = state->req0;
285+
struct acomp_req_chain *state = req0->base.data;
296286
struct acomp_req *req = state->cur;
297287
struct acomp_req *n;
298288

@@ -323,7 +313,7 @@ static int acomp_reqchain_finish(struct acomp_req_chain *state,
323313
list_add_tail(&req->base.list, &req0->base.list);
324314
}
325315

326-
acomp_restore_req(state);
316+
acomp_restore_req(req0);
327317

328318
out:
329319
return err;
@@ -342,7 +332,8 @@ static void acomp_reqchain_done(void *data, int err)
342332
goto notify;
343333
}
344334

345-
err = acomp_reqchain_finish(state, err, CRYPTO_TFM_REQ_MAY_BACKLOG);
335+
err = acomp_reqchain_finish(state->req0, err,
336+
CRYPTO_TFM_REQ_MAY_BACKLOG);
346337
if (err == -EBUSY)
347338
return;
348339

@@ -354,17 +345,15 @@ static int acomp_do_req_chain(struct acomp_req *req,
354345
int (*op)(struct acomp_req *req))
355346
{
356347
struct crypto_acomp *tfm = crypto_acomp_reqtfm(req);
357-
struct acomp_req_chain *state = &req->chain;
348+
struct acomp_req_chain *state;
358349
int err;
359350

360351
if (crypto_acomp_req_chain(tfm) ||
361352
(!acomp_request_chained(req) && acomp_request_issg(req)))
362353
return op(req);
363354

364-
if (acomp_is_async(tfm)) {
365-
acomp_save_req(req, acomp_reqchain_done);
366-
state = req->base.data;
367-
}
355+
acomp_save_req(req, acomp_reqchain_done);
356+
state = req->base.data;
368357

369358
state->op = op;
370359
state->src = NULL;
@@ -375,7 +364,7 @@ static int acomp_do_req_chain(struct acomp_req *req,
375364
if (err == -EBUSY || err == -EINPROGRESS)
376365
return -EBUSY;
377366

378-
return acomp_reqchain_finish(state, err, ~0);
367+
return acomp_reqchain_finish(req, err, ~0);
379368
}
380369

381370
int crypto_acomp_compress(struct acomp_req *req)

0 commit comments

Comments
 (0)