linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: <linux-crypto@vger.kernel.org>, <davem@davemloft.net>
Subject: Re: [PATCH v1 3/3] crypto: ccp - Protect against poorly marked end of sg list
Date: Wed, 27 May 2015 09:12:02 -0500	[thread overview]
Message-ID: <5565D0B2.8070708@amd.com> (raw)
In-Reply-To: <20150527094305.GA28142@gondor.apana.org.au>

On 05/27/2015 04:43 AM, Herbert Xu wrote:
> Tom Lendacky <thomas.lendacky@amd.com> wrote:
>> Scatter gather lists can be created with more available entries than are
>> actually used (e.g. using sg_init_table() to reserve a specific number
>> of sg entries, but in actuality using something less than that based on
>> the data length).  The caller sometimes fails to mark the last entry
>> with sg_mark_end().  In these cases, sg_nents() will return the original
>> size of the sg list as opposed to the actual number of sg entries that
>> contain valid data.
>>
>> On arm64, if the sg_nents() value is used in a call to dma_map_sg() in
>> this situation, then it causes a BUG_ON in lib/swiotlb.c because an
>> "empty" sg list entry results in dma_capable() returning false and
>> swiotlb trying to create a bounce buffer of size 0. This occurred in
>> the userspace crypto interface before being fixed by
>>
>> 0f477b655a52 ("crypto: algif - Mark sgl end at the end of data")
>>
>> Protect against this in the future by counting the number of sg entries
>> needed to meet the length requirement and supplying that value to
>> dma_map_sg().
>
> Is this needed for any reason other than this bug that's already
> been fixed?
>

I added this just to protect against any other users of the API that
may do something similar in the future (or if the user should re-use
an sg list and leave leftover sg entries in it). Since software
crypto implementations walk the sg list based on length and do not use
DMA mappings it is possible for this bug to pop up again in another
location since it is likely that the testing won't be done with
hardware crypto devices.

> The reason I'm asking is because while this patch fixes your driver
> everybody else will still crash and burn should something like this
> happen again.

A number of other drivers already have similar sg-count functions in
them.

I'm ok if you decide that this patch shouldn't be applied. It's just
that this is typically an issue that won't be found until after the
release of a kernel rather than during the development stages.

Thanks,
Tom

>
> Cheers,
>

  parent reply	other threads:[~2015-05-27 14:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-26 18:06 [PATCH v1 0/3] crypto: ccp - CCP driver updates 2015-05-26 Tom Lendacky
2015-05-26 18:06 ` [PATCH v1 1/3] crypto: ccp - Remove manual check and set of dma_mask pointer Tom Lendacky
2015-05-26 18:06 ` [PATCH v1 2/3] crypto: ccp - Remove unused structure field Tom Lendacky
2015-05-26 18:06 ` [PATCH v1 3/3] crypto: ccp - Protect against poorly marked end of sg list Tom Lendacky
2015-05-27  9:43   ` Herbert Xu
2015-05-27  9:45     ` Herbert Xu
2015-05-27 14:15       ` Tom Lendacky
2015-05-27 14:12     ` Tom Lendacky [this message]
2015-05-28  0:36       ` Herbert Xu
2015-05-28 17:30         ` Tom Lendacky
2015-05-27  9:55 ` [PATCH v1 0/3] crypto: ccp - CCP driver updates 2015-05-26 Herbert Xu

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=5565D0B2.8070708@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).