Message ID | 20241210204853.18765-1-ansuelsmth@gmail.com |
---|---|
Headers | show |
Series | crypto: Add EIP-93 crypto engine support | expand |
On Tue, Dec 10, 2024 at 09:48:33PM +0100, Christian Marangi wrote: > > +static int eip93_hash_export(struct ahash_request *req, void *out) > +{ > + struct eip93_hash_reqctx *rctx = ahash_request_ctx(req); > + struct eip93_hash_export_state *state = out; > + > + /* Save the first block in state data */ > + if (rctx->len) { > + struct mkt_hash_block *block; > + > + block = list_first_entry(&rctx->blocks, > + struct mkt_hash_block, > + list); > + > + memcpy(state->data, block->data, > + SHA256_BLOCK_SIZE - rctx->left_last); > + } > + > + eip93_hash_export_sa_state(req, state); > + > + eip93_hash_free_data_blocks(req); > + eip93_hash_free_sa_state(req); > + eip93_hash_free_sa_record(req); The export function should be idempotent so it shouldn't be freeing anything. In fact this indicates a bigger problem with how DMA is being used in the driver. You shouldn't be leaving DMA memory mapped after the init (or update) function completes. It is perfectly legal for a user to call init and then abandon the request by freeing it directly without ever calling final. In that case you will be leaking the DMA mappings. So make sure that DMA is mapped only when needed, and freed before you call the user callback. The import/export functions should only be touching kernel memory, not DMA. Cheers,
On Wed, Dec 11, 2024 at 05:39:27PM +0800, Herbert Xu wrote: > On Tue, Dec 10, 2024 at 09:48:33PM +0100, Christian Marangi wrote: > > > > +static int eip93_hash_export(struct ahash_request *req, void *out) > > +{ > > + struct eip93_hash_reqctx *rctx = ahash_request_ctx(req); > > + struct eip93_hash_export_state *state = out; > > + > > + /* Save the first block in state data */ > > + if (rctx->len) { > > + struct mkt_hash_block *block; > > + > > + block = list_first_entry(&rctx->blocks, > > + struct mkt_hash_block, > > + list); > > + > > + memcpy(state->data, block->data, > > + SHA256_BLOCK_SIZE - rctx->left_last); > > + } > > + > > + eip93_hash_export_sa_state(req, state); > > + > > + eip93_hash_free_data_blocks(req); > > + eip93_hash_free_sa_state(req); > > + eip93_hash_free_sa_record(req); > > The export function should be idempotent so it shouldn't be freeing > anything. > > In fact this indicates a bigger problem with how DMA is being used > in the driver. You shouldn't be leaving DMA memory mapped after > the init (or update) function completes. It is perfectly legal > for a user to call init and then abandon the request by freeing it > directly without ever calling final. In that case you will be > leaking the DMA mappings. > > So make sure that DMA is mapped only when needed, and freed before > you call the user callback. > > The import/export functions should only be touching kernel memory, > not DMA. > Just to make sure, this is only limited to DMA or it's also problematic to the block list? Aka NO FREE should be done in export or NO DMA FREE should be done in export?