From: LABBE Corentin <clabbe@baylibre.com>
To: Ben Dooks <ben.dooks@codethink.co.uk>
Cc: herbert@gondor.apana.org.au, hch@lst.de, heiko@sntech.de,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-riscv@lists.infradead.org, linux-sunxi@lists.linux.dev
Subject: Re: [RFC PATCH] crypto: flush poison data
Date: Tue, 5 Jul 2022 10:21:13 +0200 [thread overview]
Message-ID: <YsP0eekTthD4jWGV@Red> (raw)
In-Reply-To: <4570f6d8-251f-2cdb-1ea6-c3a8d6bb9fcf@codethink.co.uk>
Le Fri, Jul 01, 2022 at 02:35:41PM +0100, Ben Dooks a écrit :
> On 01/07/2022 14:27, Corentin Labbe wrote:
> > On my Allwinner D1 nezha, the sun8i-ce fail self-tests due to:
> > alg: skcipher: cbc-des3-sun8i-ce encryption overran dst buffer on test vector 0
> >
> > In fact the buffer is not overran by device but by the dma_map_single() operation.
> >
> > To prevent any corruption of the poisoned data, simply flush them before
> > giving the buffer to the tested driver.
> >
> > Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
> > ---
> >
> > Hello
> >
> > I put this patch as RFC, since this behavour happen only on non yet merged RISCV code.
> > (Mostly riscv: implement Zicbom-based CMO instructions + the t-head variant)
> >
> > Regards
> >
> > crypto/testmgr.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/crypto/testmgr.c b/crypto/testmgr.c
> > index c59bd9e07978..187163e2e593 100644
> > --- a/crypto/testmgr.c
> > +++ b/crypto/testmgr.c
> > @@ -19,6 +19,7 @@
> > #include <crypto/aead.h>
> > #include <crypto/hash.h>
> > #include <crypto/skcipher.h>
> > +#include <linux/cacheflush.h>
> > #include <linux/err.h>
> > #include <linux/fips.h>
> > #include <linux/module.h>
> > @@ -205,6 +206,8 @@ static void testmgr_free_buf(char *buf[XBUFSIZE])
> > static inline void testmgr_poison(void *addr, size_t len)
> > {
> > memset(addr, TESTMGR_POISON_BYTE, len);
> > + /* Be sure data is written to prevent corruption from some DMA sync */
> > + flush_icache_range((unsigned long)addr, (unsigned long)addr + len);
> > }
> >
> > /* Is the memory region still fully poisoned? */
>
> why are you flushing the instruction cache and not the data-cache?
>
I just copied what did drivers/crypto/xilinx/zynqmp-sha.c.
I tried to do flush_dcache_range() but it seems to not be implemented on riscV.
And flush_dcache_page(virt_to_page(addr), len) produce a kernel panic.
Any advice on how to go further ?
WARNING: multiple messages have this Message-ID (diff)
From: LABBE Corentin <clabbe@baylibre.com>
To: Ben Dooks <ben.dooks@codethink.co.uk>
Cc: herbert@gondor.apana.org.au, hch@lst.de, heiko@sntech.de,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-riscv@lists.infradead.org, linux-sunxi@lists.linux.dev
Subject: Re: [RFC PATCH] crypto: flush poison data
Date: Tue, 5 Jul 2022 10:21:13 +0200 [thread overview]
Message-ID: <YsP0eekTthD4jWGV@Red> (raw)
In-Reply-To: <4570f6d8-251f-2cdb-1ea6-c3a8d6bb9fcf@codethink.co.uk>
Le Fri, Jul 01, 2022 at 02:35:41PM +0100, Ben Dooks a écrit :
> On 01/07/2022 14:27, Corentin Labbe wrote:
> > On my Allwinner D1 nezha, the sun8i-ce fail self-tests due to:
> > alg: skcipher: cbc-des3-sun8i-ce encryption overran dst buffer on test vector 0
> >
> > In fact the buffer is not overran by device but by the dma_map_single() operation.
> >
> > To prevent any corruption of the poisoned data, simply flush them before
> > giving the buffer to the tested driver.
> >
> > Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
> > ---
> >
> > Hello
> >
> > I put this patch as RFC, since this behavour happen only on non yet merged RISCV code.
> > (Mostly riscv: implement Zicbom-based CMO instructions + the t-head variant)
> >
> > Regards
> >
> > crypto/testmgr.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/crypto/testmgr.c b/crypto/testmgr.c
> > index c59bd9e07978..187163e2e593 100644
> > --- a/crypto/testmgr.c
> > +++ b/crypto/testmgr.c
> > @@ -19,6 +19,7 @@
> > #include <crypto/aead.h>
> > #include <crypto/hash.h>
> > #include <crypto/skcipher.h>
> > +#include <linux/cacheflush.h>
> > #include <linux/err.h>
> > #include <linux/fips.h>
> > #include <linux/module.h>
> > @@ -205,6 +206,8 @@ static void testmgr_free_buf(char *buf[XBUFSIZE])
> > static inline void testmgr_poison(void *addr, size_t len)
> > {
> > memset(addr, TESTMGR_POISON_BYTE, len);
> > + /* Be sure data is written to prevent corruption from some DMA sync */
> > + flush_icache_range((unsigned long)addr, (unsigned long)addr + len);
> > }
> >
> > /* Is the memory region still fully poisoned? */
>
> why are you flushing the instruction cache and not the data-cache?
>
I just copied what did drivers/crypto/xilinx/zynqmp-sha.c.
I tried to do flush_dcache_range() but it seems to not be implemented on riscV.
And flush_dcache_page(virt_to_page(addr), len) produce a kernel panic.
Any advice on how to go further ?
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2022-07-05 8:21 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-01 13:27 [RFC PATCH] crypto: flush poison data Corentin Labbe
2022-07-01 13:27 ` Corentin Labbe
2022-07-01 13:35 ` Ben Dooks
2022-07-01 13:35 ` Ben Dooks
2022-07-05 8:21 ` LABBE Corentin [this message]
2022-07-05 8:21 ` LABBE Corentin
2022-07-05 16:42 ` Christoph Hellwig
2022-07-05 16:42 ` Christoph Hellwig
2022-07-05 17:56 ` LABBE Corentin
2022-07-05 17:56 ` LABBE Corentin
2022-07-05 17:58 ` Christoph Hellwig
2022-07-05 17:58 ` Christoph Hellwig
2022-07-06 7:25 ` LABBE Corentin
2022-07-06 7:25 ` LABBE Corentin
2022-07-06 9:47 ` Ben Dooks
2022-07-06 9:47 ` Ben Dooks
2022-07-06 11:58 ` Christoph Hellwig
2022-07-06 11:58 ` Christoph Hellwig
2022-07-06 12:23 ` LABBE Corentin
2022-07-06 12:23 ` LABBE Corentin
2022-07-01 14:36 ` Andre Przywara
2022-07-01 14:36 ` Andre Przywara
2022-07-01 14:55 ` LABBE Corentin
2022-07-01 14:55 ` LABBE Corentin
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=YsP0eekTthD4jWGV@Red \
--to=clabbe@baylibre.com \
--cc=ben.dooks@codethink.co.uk \
--cc=hch@lst.de \
--cc=heiko@sntech.de \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-sunxi@lists.linux.dev \
/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.