[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <67597a1e.5d0a0220.9b04.2bef@mx.google.com>
Date: Wed, 11 Dec 2024 12:40:09 +0100
From: Christian Marangi <ansuelsmth@...il.com>
To: Herbert Xu <herbert@...dor.apana.org.au>
Cc: "David S. Miller" <davem@...emloft.net>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>,
Antoine Tenart <atenart@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>, Will Deacon <will@...nel.org>,
Waiman Long <longman@...hat.com>, Boqun Feng <boqun.feng@...il.com>,
Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Bill Wendling <morbo@...gle.com>,
Justin Stitt <justinstitt@...gle.com>, linux-crypto@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
llvm@...ts.linux.dev, upstream@...oha.com,
Richard van Schagen <vschagen@...oud.com>
Subject: Re: [PATCH v8 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto
engine support
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?
--
Ansuel
Powered by blists - more mailing lists