Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Tero Kristo <t-kristo@ti.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: <davem@davemloft.net>, <linux-crypto@vger.kernel.org>,
	<linux-omap@vger.kernel.org>, Tejun Heo <tj@kernel.org>
Subject: Re: [PATCHv2 3/7] crypto: omap-crypto: fix userspace copied buffer access
Date: Tue, 26 May 2020 15:27:38 +0300	[thread overview]
Message-ID: <24092385-1348-f55d-a637-6fb2b3129f4e@ti.com> (raw)
In-Reply-To: <20200522131247.GA27255@gondor.apana.org.au>

On 22/05/2020 16:12, Herbert Xu wrote:
> On Mon, May 11, 2020 at 02:19:09PM +0300, Tero Kristo wrote:
>> In case buffers are copied from userspace, directly accessing the page
>> will most likely fail because it hasn't been mapped into the kernel
>> memory space. Fix the issue by forcing a kmap / kunmap within the
>> cleanup functionality.
>>
>> Signed-off-by: Tero Kristo <t-kristo@ti.com>
>> ---
>>   drivers/crypto/omap-crypto.c | 9 +++++++--
>>   1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/crypto/omap-crypto.c b/drivers/crypto/omap-crypto.c
>> index cc88b7362bc2..31bdb1d76d11 100644
>> --- a/drivers/crypto/omap-crypto.c
>> +++ b/drivers/crypto/omap-crypto.c
>> @@ -178,11 +178,16 @@ static void omap_crypto_copy_data(struct scatterlist *src,
>>   		amt = min(src->length - srco, dst->length - dsto);
>>   		amt = min(len, amt);
>>   
>> -		srcb = sg_virt(src) + srco;
>> -		dstb = sg_virt(dst) + dsto;
>> +		srcb = kmap_atomic(sg_page(src)) + srco + src->offset;
>> +		dstb = kmap_atomic(sg_page(dst)) + dsto + dst->offset;
>>   
>>   		memcpy(dstb, srcb, amt);
>>   
>> +		flush_dcache_page(sg_page(dst));
> 
> You need to check !PageSlab as it's illegal to call it on a kernel
> page.  Also you should be using flush_kernel_dcache_page.  scatterwalk
> uses flush_dcache_page only because when it was created the other
> function didn't exist.

Ok will fix that.

> Would it be possible to use the sg_miter interface to do the copy?
> In fact your function could possibly be added to lib/scatterlist.c
> as it seems to be quite generic.

I think it would make sense to use that, however as I am just fixing an 
existing bug here, would it be ok if I just fix your above comment and 
post v3? I can convert this later to sg_miter and take a shot at moving 
this to lib/scatterlist.c as that seems slightly bigger effort and I 
would not want to block this whole series because of that...

-Tero
--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

  reply	other threads:[~2020-05-26 12:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-11 11:19 [PATCHv2 0/7] crypto: omap: sha/aes fixes Tero Kristo
2020-05-11 11:19 ` [PATCHv2 1/7] crypto: omap-aes: avoid spamming console with self tests Tero Kristo
2020-05-11 11:19 ` [PATCHv2 2/7] crypto: omap-sham: force kernel driver usage for sha algos Tero Kristo
2020-05-11 11:19 ` [PATCHv2 3/7] crypto: omap-crypto: fix userspace copied buffer access Tero Kristo
2020-05-22 13:12   ` Herbert Xu
2020-05-26 12:27     ` Tero Kristo [this message]
2020-05-26 12:35       ` Herbert Xu
2020-05-26 12:57         ` Tero Kristo
2020-05-26 13:07           ` Herbert Xu
2020-05-26 13:11             ` Tero Kristo
2020-05-26 14:21     ` [PATCHv3 " Tero Kristo
2020-05-27  2:20       ` Herbert Xu
2020-05-11 11:19 ` [PATCHv2 4/7] crypto: omap-sham: huge buffer access fixes Tero Kristo
2020-05-11 11:19 ` [PATCHv2 5/7] crypto: omap-sham: fix very small data size handling Tero Kristo
2020-05-11 11:19 ` [PATCHv2 6/7] crypto: omap-aes: prevent unregistering algorithms twice Tero Kristo
2020-05-11 11:19 ` [PATCHv2 7/7] crypto: omap-sham: add proper load balancing support for multicore Tero Kristo

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=24092385-1348-f55d-a637-6fb2b3129f4e@ti.com \
    --to=t-kristo@ti.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=tj@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