All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kamil Konieczny <k.konieczny@partner.samsung.com>
To: Antoine Tenart <antoine.tenart@free-electrons.com>,
	Herbert Xu <herbert@gondor.apana.org.au>
Cc: davem@davemloft.net, thomas.petazzoni@free-electrons.com,
	gregory.clement@free-electrons.com,
	miquel.raynal@free-electrons.com, oferh@marvell.com,
	igall@marvell.com, nadavh@marvell.com,
	linux-crypto@vger.kernel.org
Subject: Re: [PATCH v2 3/4] crypto: inside-secure - only update the result buffer when provided
Date: Fri, 01 Dec 2017 11:18:30 +0100	[thread overview]
Message-ID: <8c42f4a1-ac1d-3817-3380-da4cee73168e@partner.samsung.com> (raw)
In-Reply-To: <20171201081157.GA2535@kwain>

Hi All,

On 01.12.2017 09:11, Antoine Tenart wrote:
> Hi Herbert,
> 
> On Fri, Dec 01, 2017 at 11:31:09AM +1100, Herbert Xu wrote:
>> On Thu, Nov 30, 2017 at 10:19:26AM +0100, Kamil Konieczny wrote:
>>>
>>> can the driver get request for final/finup/digest with null req->result ?
>>> If yes (?), such checks can be done before any hardware processing, saving time,
>>> for example:
>>
>> This should not be possible through any user-space facing API.
>>
>> If a kernel API user did this then they're just shooting themselves
>> in the foot.
>>
>> So unless there is a valida call path that leads to this then I
>> would say that there is nothing to fix.
> 
> I agree this should not be the case.
> 
> But:
> - Other drivers are doing this check (grep "if (!req->result)" or
>   "if (req->result)" to see some of them).
> - I see at least one commit fixing the exact same issue I'm facing here,
>   393897c5156a415533ff85aa381458840417b032:
> 
>     crypto: ccp - Check for caller result area before using it
> 
>     For a hash operation, the caller doesn't have to supply a result
>     area on every call so don't use it / update it if it hasn't
>     been supplied.

Herbert, is it possible for every init/update that areq->result can be NULL,
and only for final/update/digit user set it to actual memory ?
testmgr.c can check if hash update writes into areq->result and if yes, 
then test fails ?

As I understand this, when crypto api user allocates ahash_request, 
crypto allocates memory for itself _plus_ for driver's context. This allocated
ahash_request is "handle" for all subsequent updates/export/import, 
and for last final/finup, so I do not need to copy hash state into areq->result,
but keep it whole time in context, in your code in sreq:

struct safexcel_ahash_req *sreq = ahash_request_ctx(areq);

so here sreq is async hash request context.

Do you set last_req true for digest/finup/final ? If yes,
then you need to copy result only when it is true,

	if (sreq->last_req) {
		result_sz = crypto_ahash_digestsize(ahash);
		memcpy(sreq->state, areq->result, result_sz);
	}

I do not read all your code though, so I can be wrong here.
 
> I'm not entirely sure what was the code path that leads to this, I'll
> reproduce the issue and try to understand what is going on (I clearly
> recall having this crash though).
> 
> The crypto API does not enforce this somehow, and this should probably
> be fixed. That might break some users. But it was seen as a valid use
> for some, so we should probably fix this in previous versions of the
> driver anyway.

-- 
Best regards,
Kamil Konieczny
Samsung R&D Institute Poland

  reply	other threads:[~2017-12-01 10:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-28 15:42 [PATCH v2 0/4] crypto: inside-secure - set of fixes Antoine Tenart
2017-11-28 15:42 ` [PATCH v2 1/4] crypto: inside-secure - per request invalidation Antoine Tenart
2017-11-28 15:42 ` [PATCH v2 2/4] crypto: inside-secure - free requests even if their handling failed Antoine Tenart
2017-11-28 15:42 ` [PATCH v2 3/4] crypto: inside-secure - only update the result buffer when provided Antoine Tenart
2017-11-30  9:19   ` Kamil Konieczny
2017-11-30  9:29     ` Antoine Tenart
2017-11-30 11:52       ` Kamil Konieczny
2017-11-30 12:41         ` Antoine Tenart
2017-11-30 14:10           ` Kamil Konieczny
2017-11-30 14:30             ` Antoine Tenart
2017-12-01  0:31     ` Herbert Xu
2017-12-01  8:11       ` Antoine Tenart
2017-12-01 10:18         ` Kamil Konieczny [this message]
2017-12-01 10:24           ` Antoine Tenart
2017-12-01 10:43             ` Kamil Konieczny
2017-12-01 10:55               ` Antoine Tenart
2017-12-01 10:36           ` Herbert Xu
2017-12-01 11:24             ` Kamil Konieczny
2017-12-01 10:35         ` Herbert Xu
2017-12-01 10:52           ` Antoine Tenart
2017-11-28 15:42 ` [PATCH v2 4/4] crypto: inside-secure - fix request allocations in invalidation path Antoine Tenart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8c42f4a1-ac1d-3817-3380-da4cee73168e@partner.samsung.com \
    --to=k.konieczny@partner.samsung.com \
    --cc=antoine.tenart@free-electrons.com \
    --cc=davem@davemloft.net \
    --cc=gregory.clement@free-electrons.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=igall@marvell.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=miquel.raynal@free-electrons.com \
    --cc=nadavh@marvell.com \
    --cc=oferh@marvell.com \
    --cc=thomas.petazzoni@free-electrons.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.