Commit Graph
100 Commits
Author SHA1 Message Date
Herbert Xu cb3e9864cd ipv6: raw: Deduct extension header length in rawv6_push_pending_frames
The total cork length created by ip6_append_data includes extension
headers, so we must exclude them when comparing them against the
IPV6_CHECKSUM offset which does not include extension headers.

Reported-by: Kyle Zeng <[email protected]>
Fixes: 357b40a18b ("[IPV6]: IPV6_CHECKSUM socket option can corrupt kernel memory")
Signed-off-by: Herbert Xu <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
2023-01-11 12:49:13 +00:00
Herbert Xu 18daae5b0c crypto: qce - Set DMA alignment explicitly
This driver has been implicitly relying on kmalloc alignment
to be sufficient for DMA.  This may no longer be the case with
upcoming arm64 changes.

This patch changes it to explicitly request DMA alignment from
the Crypto API.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-09 18:45:00 +08:00
Herbert Xu d887dec105 crypto: octeontx2 - Set DMA alignment explicitly
This driver has been implicitly relying on kmalloc alignment
to be sufficient for DMA.  This may no longer be the case with
upcoming arm64 changes.

This patch changes it to explicitly request DMA alignment from
the Crypto API.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-09 18:45:00 +08:00
Herbert Xu 0a55f4e385 crypto: octeontx - Set DMA alignment explicitly
This driver has been implicitly relying on kmalloc alignment
to be sufficient for DMA.  This may no longer be the case with
upcoming arm64 changes.

This patch changes it to explicitly request DMA alignment from
the Crypto API.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-09 18:45:00 +08:00
Herbert Xu be75969c81 crypto: keembay - Set DMA alignment explicitly
This driver has been implicitly relying on kmalloc alignment
to be sufficient for DMA.  This may no longer be the case with
upcoming arm64 changes.

This patch changes it to explicitly request DMA alignment from
the Crypto API.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-09 18:45:00 +08:00
Herbert Xu b2e2e2da7b crypto: safexcel - Set DMA alignment explicitly
This driver has been implicitly relying on kmalloc alignment
to be sufficient for DMA.  This may no longer be the case with
upcoming arm64 changes.

This patch changes it to explicitly request DMA alignment from
the Crypto API.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-09 18:45:00 +08:00
Herbert Xu 80b61baca4 crypto: hisilicon/hpre - Set DMA alignment explicitly
This driver has been implicitly relying on kmalloc alignment
to be sufficient for DMA.  This may no longer be the case with
upcoming arm64 changes.

This patch changes it to explicitly request DMA alignment from
the Crypto API.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-09 18:45:00 +08:00
Herbert Xu e055bffaa3 crypto: chelsio - Set DMA alignment explicitly
This driver has been implicitly relying on kmalloc alignment
to be sufficient for DMA.  This may no longer be the case with
upcoming arm64 changes.

This patch changes it to explicitly request DMA alignment from
the Crypto API.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-09 18:45:00 +08:00
Herbert Xu 07547fa73e crypto: ccree - Set DMA alignment explicitly
This driver has been implicitly relying on kmalloc alignment
to be sufficient for DMA.  This may no longer be the case with
upcoming arm64 changes.

This patch changes it to explicitly request DMA alignment from
the Crypto API.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-09 18:45:00 +08:00
Herbert Xu 99c6b20edf crypto: ccp - Set DMA alignment explicitly
This driver has been implicitly relying on kmalloc alignment
to be sufficient for DMA.  This may no longer be the case with
upcoming arm64 changes.

This patch changes it to explicitly request DMA alignment from
the Crypto API.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-09 18:45:00 +08:00
Herbert Xu 1c64a7e1f9 crypto: cavium - Set DMA alignment explicitly
This driver has been implicitly relying on kmalloc alignment
to be sufficient for DMA.  This may no longer be the case with
upcoming arm64 changes.

This patch changes it to explicitly request DMA alignment from
the Crypto API.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-09 18:45:00 +08:00
Herbert Xu 3564f5a214 crypto: chelsio - Fix flexible struct array warning
This patch fixes the sparse warning about arrays of flexible
structures by removing an unnecessary use of them in struct
__crypto_ctx.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-09 18:45:00 +08:00
Herbert Xu eaade84a63 crypto: api - Use linux/cache.h instead of asm/cache.h
Directly including asm/cache.h leads to build failures on powerpc
so replace it with linux/cache.h instead.

Fixes: e634ac4a8a ("crypto: api - Add crypto_tfm_ctx_dma")
Reported-by: Stephen Rothwell <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-12-05 16:39:18 +08:00
Herbert Xu 4cb4f7c11d crypto: caam - Set DMA alignment explicitly
This driver has been implicitly relying on kmalloc alignment
to be sufficient for DMA.  This may no longer be the case with
upcoming arm64 changes.

This patch changes it to explicitly request DMA alignment from
the Crypto API.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:41 +08:00
Herbert Xu a5a49249ef crypto: kpp - Add ctx helpers with DMA alignment
This patch adds helpers to access the kpp context structure and
request context structure with an added alignment for DMA access.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:40 +08:00
Herbert Xu 4ac3377645 crypto: akcipher - Add ctx helpers with DMA alignment
This patch adds helpers to access the akcipher context structure and
request context structure with an added alignment for DMA access.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:40 +08:00
Herbert Xu 1c79957197 crypto: api - Increase MAX_ALGAPI_ALIGNMASK to 127
Previously we limited the maximum alignment mask to 63.  This
is mostly due to stack usage for shash.  This patch introduces
a separate limit for shash algorithms and increases the general
limit to 127 which is the value that we need for DMA allocations
on arm64.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:40 +08:00
Herbert Xu 12658ac5e6 crypto: skcipher - Add ctx helpers with DMA alignment
This patch adds helpers to access the skcipher context structure and
request context structure with an added alignment for DMA access.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:40 +08:00
Herbert Xu b5f755fbd5 crypto: hash - Add ctx helpers with DMA alignment
This patch adds helpers to access the ahash context structure and
request context structure with an added alignment for DMA access.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:40 +08:00
Herbert Xu f8e4d1d0ac crypto: aead - Add ctx helpers with DMA alignment
This patch adds helpers to access the aead context structure and
request context structure with an added alignment for DMA access.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:40 +08:00
Herbert Xu e634ac4a8a crypto: api - Add crypto_tfm_ctx_dma
This patch adds the helpers crypto_tfm_ctx_aligned and
crypto_tfm_ctx_dma.  The first aligns the tfm context to the
value cra_alignmask.  The second sets the alignment according
to dma_cache_get_alignment();

This patch also moves crypto_tfm_ctx into algapi.h.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:40 +08:00
Herbert Xu 14386d4713 crypto: Prepare to move crypto_tfm_ctx
The helper crypto_tfm_ctx is only used by the Crypto API algorithm
code and should really be in algapi.h.  However, for historical
reasons many files relied on it to be in crypto.h.  This patch
changes those files to use algapi.h instead in prepartion for a
move.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:40 +08:00
Herbert Xu 4d2b225a67 crypto: kpp - Move reqsize into tfm
The value of reqsize cannot be determined in case of fallbacks.
Therefore it must be stored in the tfm and not the alg object.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:40 +08:00
Herbert Xu cb99fc0dd1 crypto: dh - Use helper to set reqsize
The value of reqsize must only be changed through the helper.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:40 +08:00
Herbert Xu 3e71e5b0ef crypto: akcipher - Move reqsize into tfm
The value of reqsize cannot be determined in case of fallbacks.
Therefore it must be stored in the tfm and not the alg object.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:39 +08:00
Herbert Xu 93c446cd36 crypto: virtio - Use helper to set reqsize
The value of reqsize must only be changed through the helper.

Signed-off-by: Herbert Xu <[email protected]>
Acked-by: Gonglei <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:39 +08:00
Herbert Xu 908d383b6c crypto: caam - Use helper to set reqsize
The value of reqsize must only be changed through the helper.

Signed-off-by: Herbert Xu <[email protected]>
Reviewed-by: Gaurav Jain <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:39 +08:00
Herbert Xu 80e62ad58d crypto: qat - Use helper to set reqsize
The value of reqsize must only be changed through the helper.

Signed-off-by: Herbert Xu <[email protected]>
Reviewed-by: Giovanni Cabiddu <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:39 +08:00
Herbert Xu 5ba7837356 crypto: hisilicon/hpre - Use helper to set reqsize
The value of reqsize must only be changed through the helper.

Signed-off-by: Herbert Xu <[email protected]>
Reviewed-by: Longfang Liu <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:39 +08:00
Herbert Xu 56861cbde1 crypto: kpp - Add helper to set reqsize
The value of reqsize should only be changed through a helper.
To do so we need to first add a helper for this.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:39 +08:00
Herbert Xu 5b11d1a360 crypto: rsa-pkcs1pad - Use helper to set reqsize
The value of reqsize must only be changed through the helper.

Signed-off-by: Herbert Xu <[email protected]>
2022-12-02 18:12:39 +08:00
Herbert Xu 719c547c65 Merge branch 'i2c/client_device_id_helper-immutable' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Merge i2c tree to pick up i2c_client_get_device_id helper.
2022-11-25 17:05:15 +08:00
Herbert Xu e6cb02bd0a crypto: skcipher - Allow sync algorithms with large request contexts
Some sync algorithms may require a large amount of temporary
space during its operations.  There is no reason why they should
be limited just because some legacy users want to place all
temporary data on the stack.

Such algorithms can now set a flag to indicate that they need
extra request context, which will cause them to be invisible
to users that go through the sync_skcipher interface.

Signed-off-by: Herbert Xu <[email protected]>
2022-11-18 16:59:34 +08:00
Herbert Xu 3a58c23117 crypto: cryptd - Use request context instead of stack for sub-request
cryptd is buggy as it tries to use sync_skcipher without going
through the proper sync_skcipher interface.  In fact it doesn't
even need sync_skcipher since it's already a proper skcipher and
can easily access the request context instead of using something
off the stack.

Fixes: 36b3875a97 ("crypto: cryptd - Remove VLA usage of skcipher")
Signed-off-by: Herbert Xu <[email protected]>
2022-11-18 16:59:34 +08:00
Herbert Xu 7f57f8165c af_key: Fix send_acquire race with pfkey_register
The function pfkey_send_acquire may race with pfkey_register
(which could even be in a different name space).  This may result
in a buffer overrun.

Allocating the maximum amount of memory that could be used prevents
this.

Reported-by: [email protected]
Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
Signed-off-by: Herbert Xu <[email protected]>
Reviewed-by: Sabrina Dubroca <[email protected]>
Reviewed-by: Eric Dumazet <[email protected]>
Signed-off-by: Steffen Klassert <[email protected]>
2022-10-27 16:35:12 +02:00
Herbert Xu 46beeade05 crypto: ixp4xx - Fix sparse warnings
This fixes a number of trivial sparse warnings in ixp4xx.

Signed-off-by: Herbert Xu <[email protected]>
Acked-by: Corentin Labbe <[email protected]>
Tested-by: Corentin Labbe <[email protected]>
Acked-by: Linus Walleij <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-10-21 19:15:35 +08:00
Herbert Xu 4532f1cf9c crypto: artpec6 - Fix printk warning on size_t/%d
Switch to %zu instead of %d for printing size_t.

Signed-off-by: Herbert Xu <[email protected]>
Acked-by: Jesper Nilsson <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-09-24 16:14:43 +08:00
Herbert Xu efc96d43ec crypto: aspeed - Fix sparse warnings
This patch fixes a bunch of bit endianness warnings and two missing
static modifiers.

Signed-off-by: Herbert Xu <[email protected]>
Reviewed-by: Neal Liu <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-09-07 14:11:04 +08:00
Herbert Xu 31b39755e3 crypto: aspeed - Enable compile testing
This driver compile tests just fine.

Signed-off-by: Herbert Xu <[email protected]>
Reviewed-by: Neal Liu <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-09-02 18:38:06 +08:00
Herbert Xu 2ad548ebb8 Revert "crypto: allwinner - Fix dma_map_sg error check"
This reverts commit 2b02187bdb.

The original code was correct and arguably more robust than the
patched version.

Signed-off-by: Herbert Xu <[email protected]>
2022-09-02 18:19:27 +08:00
Herbert Xu fb1e1257b0 Revert "crypto: gemini - Fix error check for dma_map_sg"
This reverts commit 545665ad1e.

The original code was correct and arguably more robust than the
patched version.

Signed-off-by: Herbert Xu <[email protected]>
2022-09-02 18:15:53 +08:00
Herbert Xu 5010077074 Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Merge crypto tree to pick up backport of XOR_BLOCKS Kconfig fix.
2022-08-26 18:45:27 +08:00
Herbert Xu 882aa6525c crypto: qcom-rng - Fix qcom_rng_of_match unused warning
Module device tables need to be declared as maybe_unused because
they will be unused when built-in and the corresponding option is
also disabled.

This patch adds the maybe_unused attributes to OF and ACPI.  This
also allows us to remove the ifdef around the ACPI data structure.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
Reviewed-by: Vinod Koul <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-08-19 18:39:35 +08:00
Herbert Xu ba953a9d89 af_key: Do not call xfrm_probe_algs in parallel
When namespace support was added to xfrm/afkey, it caused the
previously single-threaded call to xfrm_probe_algs to become
multi-threaded.  This is buggy and needs to be fixed with a mutex.

Reported-by: Abhishek Shah <[email protected]>
Fixes: 283bc9f35b ("xfrm: Namespacify xfrm state/policy locks")
Signed-off-by: Herbert Xu <[email protected]>
Signed-off-by: Steffen Klassert <[email protected]>
2022-08-05 10:22:14 +02:00
Herbert Xu cc8166bfc8 crypto: vmx - Fix warning on p8_ghash_alg
The compiler complains that p8_ghash_alg isn't declared which is
because the header file aesp8-ppc.h isn't included in ghash.c.
This patch fixes the warning.

Signed-off-by: Herbert Xu <[email protected]>
Acked-by: Breno Leitao <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-07-08 15:21:15 +08:00
Herbert Xu 25dfae6840 hwrng: cn10k - Enable compile testing
This patch enables COMPILE_TEST for cn10k.

Signed-off-by: Herbert Xu <[email protected]>
2022-05-06 18:16:55 +08:00
Herbert Xu c6d3ffae0d Revert "hwrng: mpfs - Enable COMPILE_TEST"
This reverts commit 6a71277ce9.

The underlying option POLARFIRE_SOC_SYS_CTRL already supports
COMPILE_TEST so there is no need for this.  What's more, if
we force this option on without the underlying option it fails
to build.

Reported-by: kernel test robot <[email protected]>
Reported-by: Randy Dunlap <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-04-26 17:42:36 +08:00
Herbert Xu 6a71277ce9 hwrng: mpfs - Enable COMPILE_TEST
The dependency on HW_RANDOM is redundant so this patch removes it.
As this driver seems to cross-compile just fine we could also enable
COMPILE_TEST.

Signed-off-by: Herbert Xu <[email protected]>
Reviewed-by: Conor Dooley <[email protected]
Reviewed-by: Conor Dooley <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-04-21 17:53:55 +08:00
Herbert Xu c8bd296cca crypto: arm/aes-neonbs-cbc - Select generic cbc and aes
The algorithm __cbc-aes-neonbs requires a fallback so we need
to select the config options for them or otherwise it will fail
to register on boot-up.

Fixes: 00b99ad2ba ("crypto: arm/aes-neonbs - Use generic cbc...")
Signed-off-by: Herbert Xu <[email protected]>
2022-03-25 16:21:05 +12:00
Herbert Xu 30d024b505 cacheflush.h: Add forward declaration for struct folio
The struct folio is not declared in cacheflush.h so we need to provide
a forward declaration as otherwise users of this header file may get
warnings.

Reported-by: Guenter Roeck <[email protected]>
Fixes: 522a0032af ("Add linux/cacheflush.h")
Signed-off-by: Herbert Xu <[email protected]>
Reviewed-by: Matthew Wilcox (Oracle) <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
2022-03-23 10:11:03 -07:00
Herbert Xu 0e03b8fd29 crypto: xilinx - Turn SHA into a tristate and allow COMPILE_TEST
This patch turns the new SHA driver into a tristate and also allows
compile testing.

Signed-off-by: Herbert Xu <[email protected]>
2022-03-14 14:45:45 +12:00
Herbert Xu f60bbbbe80 crypto: lrw - Add dependency on ecb
The lrw template relies on ecb to work.  So we need to declare
a Kconfig dependency as well as a module softdep on it.

Signed-off-by: Herbert Xu <[email protected]>
2022-02-18 16:21:08 +11:00
Herbert Xu dfe085d8dc crypto: xts - Add softdep on ecb
The xts module needs ecb to be present as it's meant to work
on top of ecb.  This patch adds a softdep so ecb can be included
automatically into the initramfs.

Reported-by: rftc <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-02-18 16:21:08 +11:00
Herbert Xu c6ce9c5831 crypto: api - Move cryptomgr soft dependency into algapi
The soft dependency on cryptomgr is only needed in algapi because
if algapi isn't present then no algorithms can be loaded.  This
also fixes the case where api is built-in but algapi is built as
a module as the soft dependency would otherwise get lost.

Fixes: 8ab23d547f ("crypto: api - Add softdep on cryptomgr")
Reported-by: Jan Beulich <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
Tested-by: Jan Beulich <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-02-05 15:10:07 +11:00
Herbert Xu 66eae85033 crypto: authenc - Fix sleep in atomic context in decrypt_tail
The function crypto_authenc_decrypt_tail discards its flags
argument and always relies on the flags from the original request
when starting its sub-request.

This is clearly wrong as it may cause the SLEEPABLE flag to be
set when it shouldn't.

Fixes: 92d95ba917 ("crypto: authenc - Convert to new AEAD interface")
Reported-by: Corentin Labbe <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
Tested-by: Corentin Labbe <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-01-31 11:21:44 +11:00
Herbert Xu a88592cc27 crypto: kdf - Select hmac in addition to sha256
In addition to sha256 we must also enable hmac for the kdf self-test
to work.

Reported-by: kernel test robot <[email protected]>
Fixes: 304b4acee2 ("crypto: kdf - select SHA-256 required...")
Fixes: 026a733e66 ("crypto: kdf - add SP800-108 counter key...")
Signed-off-by: Herbert Xu <[email protected]>
2022-01-31 11:21:43 +11:00
Herbert Xu 8fc5f2ad89 crypto: testmgr - Move crypto_simd_disabled_for_test out
As testmgr is part of cryptomgr which was designed to be unloadable
as a module, it shouldn't export any symbols for other crypto
modules to use as that would prevent it from being unloaded.  All
its functionality is meant to be accessed through notifiers.

The symbol crypto_simd_disabled_for_test was added to testmgr
which caused it to be pinned as a module if its users were also
loaded.  This patch moves it out of testmgr and into crypto/algapi.c
so cryptomgr can again be unloaded and replaced on demand.

Signed-off-by: Herbert Xu <[email protected]>
Reviewed-by: Eric Biggers <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2022-01-31 11:21:42 +11:00
Herbert Xu 3d6b661330 crypto: stm32 - Revert broken pm_runtime_resume_and_get changes
We should not call pm_runtime_resume_and_get where the reference
count is expected to be incremented unconditionally.  This patch
reverts these calls to the original unconditional get_sync call.

Reported-by: Heiner Kallweit <[email protected]>
Fixes: 747bf30fd9 ("crypto: stm32/cryp - Fix PM reference leak...")
Fixes: 1cb3ad7019 ("crypto: stm32/hash - Fix PM reference leak...")
Signed-off-by: Herbert Xu <[email protected]>
Acked-by: Rafael J. Wysocki <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2021-12-11 16:49:17 +11:00
Herbert Xu beaaaa37c6 crypto: api - Fix boot-up crash when crypto manager is disabled
When the crypto manager is disabled, we need to explicitly set
the crypto algorithms' tested status so that they can be used.

Fixes: cad439fc04 ("crypto: api - Do not create test larvals if...")
Reported-by: Geert Uytterhoeven <[email protected]>
Reported-by: Ido Schimmel <[email protected]>
Reported-by: Guenter Roeck <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
Tested-by: Ido Schimmel <[email protected]>
Tested-by: Geert Uytterhoeven <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2021-11-09 13:45:48 +08:00
Herbert Xu cad439fc04 crypto: api - Do not create test larvals if manager is disabled
The delayed boot-time testing patch created a dependency loop
between api.c and algapi.c because it added a crypto_alg_tested
call to the former when the crypto manager is disabled.

We could instead avoid creating the test larvals if the crypto
manager is disabled.  This avoids the dependency loop as well
as saving some unnecessary work, albeit in a very unlikely case.

Reported-by: Nathan Chancellor <[email protected]>
Reported-by: Naresh Kamboju <[email protected]>
Reported-by: kernel test robot <[email protected]>
Fixes: adad556efc ("crypto: api - Fix built-in testing dependency failures")
Signed-off-by: Herbert Xu <[email protected]>
2021-10-29 21:04:02 +08:00
Herbert Xu e42dff467e crypto: api - Export crypto_boot_test_finished
We need to export crypto_boot_test_finished in case api.c is
built-in while algapi.c is built as a module.

Fixes: adad556efc ("crypto: api - Fix built-in testing dependency failures")
Reported-by: Stephen Rothwell <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
Tested-by: Stephen Rothwell <[email protected]> # ppc32 build
Signed-off-by: Herbert Xu <[email protected]>
2021-10-01 14:41:23 +08:00
Herbert Xu adad556efc crypto: api - Fix built-in testing dependency failures
When complex algorithms that depend on other algorithms are built
into the kernel, the order of registration must be done such that
the underlying algorithms are ready before the ones on top are
registered.  As otherwise they would fail during the self-test
which is required during registration.

In the past we have used subsystem initialisation ordering to
guarantee this.  The number of such precedence levels are limited
and they may cause ripple effects in other subsystems.

This patch solves this problem by delaying all self-tests during
boot-up for built-in algorithms.  They will be tested either when
something else in the kernel requests for them, or when we have
finished registering all built-in algorithms, whichever comes
earlier.

Reported-by: Vladis Dronov <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2021-09-24 16:03:05 +08:00
Herbert Xu cbbb5f07ab crypto: hisilicon - Fix sscanf format signedness
The function qm_qos_value_init expects an unsigned integer but
is incorrectly supplying a signed format to sscanf.  This patch
fixes it.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2021-09-17 11:05:11 +08:00
Herbert Xu 6ee55a6f50 crypto: omap - Drop obsolete PageSlab check
As it is now legal to call flush_dcache_page on slab pages we
no longer need to do the check in the omap driver.  This patch
also uses flush_dcache_page instead of flush_kernel_dcache_page
because the page we're writing to could be anything.

Reported-by: Ira Weiny <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2021-06-28 11:28:08 +08:00
Herbert Xu b0d2193ba6 crypto: scatterwalk - Remove obsolete PageSlab check
As it is now legal to call flush_dcache_page on slab pages we
no longer need to do the check in the Crypto API.

Reported-by: Ira Weiny <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2021-06-28 11:28:08 +08:00
Herbert Xu b20d9a73a3 crypto: nx - Fix numerous sparse byte-order warnings
The nx driver started out its life as a BE-only driver.  However,
somewhere along the way LE support was partially added.  This never
seems to have been extended all the way but it does trigger numerous
warnings during build.

This patch fixes all those warnings, but it doesn't mean that the
driver will work on LE.

Signed-off-by: Herbert Xu <[email protected]>
2021-06-24 14:51:35 +08:00
Herbert Xu 2a96726bd0 crypto: nx - Fix RCU warning in nx842_OF_upd_status
The function nx842_OF_upd_status triggers a sparse RCU warning when
it directly dereferences the RCU-protected devdata.  This appears
to be an accident as there was another variable of the same name
that was passed in from the caller.

After it was removed (because the main purpose of using it, to
update the status member was itself removed) the global variable
unintenionally stood in as its replacement.

This patch restores the devdata parameter.

Fixes: 90fd73f912 ("crypto: nx - remove pSeries NX 'status' field")
Signed-off-by: Herbert Xu <[email protected]>
2021-06-24 14:51:35 +08:00
Herbert Xu 5163ab505e crypto: api - Move crypto attr definitions out of crypto.h
The definitions for crypto_attr-related types and enums are not
needed by most Crypto API users.  This patch moves them out of
crypto.h and into algapi.h/internal.h depending on the extent of
their use.

Signed-off-by: Herbert Xu <[email protected]>
2021-06-24 14:51:35 +08:00
Herbert Xu d886d55f4c crypto: sa2ul - Remove unused auth_len variable
This patch removes the unused auth_len variable from
sa_aead_dma_in_callback.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2021-06-24 14:51:34 +08:00
Herbert Xu 3877869d13 Merge branch 'ecc'
This pulls in the NIST P384/256/192 x509 changes.
2021-03-26 19:55:55 +11:00
Herbert Xu 0914999744 crypto: aegis128 - Move simd prototypes into aegis.h
This patch fixes missing prototype warnings in crypto/aegis128-neon.c.

Fixes: a4397635af ("crypto: aegis128 - provide a SIMD...")
Reported-by: kernel test robot <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
Acked-by: Ard Biesheuvel <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2021-03-19 21:59:45 +11:00
Herbert Xu 4ab6093ba4 crypto: serpent - Fix sparse byte order warnings
This patch fixes the byte order markings in serpent.

Signed-off-by: Herbert Xu <[email protected]>
Tested-by: Ard Biesheuvel <[email protected]> # arm64 big-endian
Signed-off-by: Herbert Xu <[email protected]>
2021-03-07 15:13:15 +11:00
Herbert Xu dc9ab9c69c Merge git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux for-next/crypto
Pull change from arm64 tree that's needed for crypto arm changes.
2021-02-10 17:20:35 +11:00
Herbert Xu b4ea2220b8 crypto: octeontx2 - Add dependency on NET_VENDOR_MARVELL
The crypto octeontx2 driver depends on the mbox code in the network
tree.  It tries to select the MBOX Kconfig option but that option
itself depends on many other options which are not selected, e.g.,
CONFIG_NET_VENDOR_MARVELL.  It would be inappropriate to select them
all as randomly prompting the user for network options which would
oterhwise be disabled just because a crypto driver has been enabled
makes no sense.

This patch fixes this by adding a dependency on NET_VENDOR_MARVELL.
This makes the crypto driver invisible if the network option is off.

If the crypto driver must be visible even without the network stack
then the shared mbox code should be moved out of drivers/net.

Reported-by: Randy Dunlap <[email protected]>
Reported-by: kernel test robot <[email protected]>
Fixes: 5e8ce83347 ("crypto: marvell - add Marvell OcteonTX2 CPT...")
Signed-off-by: Herbert Xu <[email protected]>
Acked-by: Randy Dunlap <[email protected]> # build-tested
Signed-off-by: Herbert Xu <[email protected]>
2021-02-05 14:32:05 +11:00
Herbert Xu c114cf7f86 crypto: marvell/cesa - Fix use of sg_pcopy on iomem pointer
The cesa driver mixes use of iomem pointers and normal kernel
pointers.  Sometimes it uses memcpy_toio/memcpy_fromio on both
while other times it would use straight memcpy on both, through
the sg_pcopy_* helpers.

This patch fixes this by adding a new field sram_pool to the engine
for the normal pointer case which then allows us to use the right
interface depending on the value of engine->pool.

Signed-off-by: Herbert Xu <[email protected]>
2021-01-29 16:07:03 +11:00
Herbert Xu 5a17eae414 crypto: bcm - Fix sparse warnings
This patch fixes a number of sparse warnings in the bcm driver.

Signed-off-by: Herbert Xu <[email protected]>
2021-01-22 14:58:01 +11:00
Herbert Xu 4f6543f28b crypto: marvel/cesa - Fix tdma descriptor on 64-bit
The patch that added src_dma/dst_dma to struct mv_cesa_tdma_desc
is broken on 64-bit systems as the size of the descriptor has been
changed.  This patch fixes it by using u32 instead of dma_addr_t.

Fixes: e62291c1d9 ("crypto: marvell/cesa - Fix sparse warnings")
Cc: <[email protected]>
Reported-by: Sven Auhagen <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2021-01-22 14:57:31 +11:00
Herbert Xu 81064c96d8 crypto: stm32 - Fix last sparse warning in stm32_cryp_check_ctr_counter
This patch changes the cast in stm32_cryp_check_ctr_counter from
u32 to __be32 to match the prototype of stm32_cryp_hw_write_iv
correctly.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2021-01-14 17:10:25 +11:00
Herbert Xu 622aae879c crypto: vmx - Move extern declarations into header file
This patch moves the extern algorithm declarations into a header
file so that a number of compiler warnings are silenced.

Signed-off-by: Herbert Xu <[email protected]>
2021-01-08 15:39:47 +11:00
Herbert Xu f2d4576a9d crypto: cpt - Fix sparse warnings in cptpf
This patch fixes a few sparse warnings that were missed in the
last round.

Signed-off-by: Herbert Xu <[email protected]>
2020-12-04 18:13:15 +11:00
Herbert Xu a1315dcb7b hwrng: ks-sa - Add dependency on IOMEM and OF
This patch adds a dependency for KEYSTONE on HAS_IOMEM and OF to
prevent COMPILE_TEST build failures.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2020-12-04 18:13:14 +11:00
Herbert Xu ce0d5d63e8 crypto: lib/blake2s - Move selftest prototype into header file
This patch fixes a missing prototype warning on blake2s_selftest.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2020-12-04 18:13:14 +11:00
Herbert Xu 6cf1a144d3 crypto: sparc - Fix sparse endianness warnings
This patch fixes a coulpe of sparse endianness warnings.

Signed-off-by: Herbert Xu <[email protected]>
2020-11-27 17:13:42 +11:00
Herbert Xu e547655238 crypto: powerpc/sha256-spe - Fix sparse endianness warning
This patch fixes a sparse endianness warning in sha256-spe.

Signed-off-by: Herbert Xu <[email protected]>
2020-11-27 17:13:41 +11:00
Herbert Xu 7c2f5537ca crypto: mips/octeon - Fix sparse endianness warnings
This patch fixes a number of endianness warnings in the mips/octeon
code.

Signed-off-by: Herbert Xu <[email protected]>
2020-11-27 17:13:41 +11:00
Herbert Xu 1201581c57 crypto: lib/curve25519 - Move selftest prototype into header file
This patch moves the curve25519_selftest into curve25519.h so
we don't get a warning from gcc complaining about a missing
prototype.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2020-11-20 14:45:33 +11:00
Herbert Xu cd078cb6a0 crypto: cavium/nitrox - Fix sparse warnings
This patch fixes all the sparse warnings in cavium/nitrox:

- Fix endianness warnings by adding the correct markers to unions.
- Add missing header inclusions for prototypes.
- Move nitrox_sriov_configure prototype into the isr header file.

Signed-off-by: Herbert Xu <[email protected]>
2020-11-13 20:38:45 +11:00
Herbert Xu ad0bb4e4d2 crypto: sa2ul - Reduce stack usage
This patch reduces the stack usage in sa2ul:

1. Move the exported sha state into sa_prepare_iopads so that it
can occupy the same space as the k_pad buffer.

2. Use one buffer for ipad/opad in sa_prepare_iopads.

3. Remove ipad/opad buffer from sa_set_sc_auth.

4. Use async skcipher fallback and remove on-stack request from
sa_cipher_run.

Reported-by: kernel test robot <[email protected]>
Fixes: d2c8ac187f ("crypto: sa2ul - Add AEAD algorithm support")
Signed-off-by: Herbert Xu <[email protected]>
2020-10-30 17:35:02 +11:00
Herbert Xu d722869432 lib/mpi: Remove unused scalar_copied
The scalar_copied variable is not as the scalar is never copied
in that block.  This patch removes it.

Fixes: d58bb7e55a ("lib/mpi: Introduce ec implementation to...")
Reported-by: Gustavo A. R. Silva <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2020-10-30 17:34:45 +11:00
Herbert Xu 3093e7c16e X.509: Fix modular build of public_key_sm2
The sm2 code was split out of public_key.c in a way that breaks
modular builds.  This patch moves the code back into the same file
as the original motivation was to minimise ifdefs and that has
nothing to do with splitting the code out.

Fixes: 2155256396 ("X.509: support OSCCA SM2-with-SM3...")
Reported-by: kernel test robot <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2020-10-08 16:39:14 +11:00
Herbert Xu 10a2f0b311 crypto: bcm - Verify GCM/CCM key length in setkey
The setkey function for GCM/CCM algorithms didn't verify the key
length before copying the key and subtracting the salt length.

This patch delays the copying of the key til after the verification
has been done.  It also adds checks on the key length to ensure
that it's at least as long as the salt.

Fixes: 9d12ba86f8 ("crypto: brcm - Add Broadcom SPU driver")
Cc: <[email protected]>
Reported-by: kiyin(尹亮) <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2020-10-08 16:38:06 +11:00
Herbert Xu ae6ee6ae2b lib/mpi: Fix unused variable warnings
This patch removes a number of unused variables and marks others
as unused in order to silence compiler warnings about them.

Fixes: a8ea8bdd9d ("lib/mpi: Extend the MPI library")
Signed-off-by: Herbert Xu <[email protected]>
Tested-by: Tianjia Zhang <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2020-10-02 18:02:13 +10:00
Herbert Xu 4a0c1de64b crypto: x86/poly1305 - Remove assignments with no effect
This patch removes a few ineffectual assignments from the function
crypto_poly1305_setdctxkey.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2020-10-02 18:02:13 +10:00
Herbert Xu e94ee17134 xfrm: Use correct address family in xfrm_state_find
The struct flowi must never be interpreted by itself as its size
depends on the address family.  Therefore it must always be grouped
with its original family value.

In this particular instance, the original family value is lost in
the function xfrm_state_find.  Therefore we get a bogus read when
it's coupled with the wrong family which would occur with inter-
family xfrm states.

This patch fixes it by keeping the original family value.

Note that the same bug could potentially occur in LSM through
the xfrm_state_pol_flow_match hook.  I checked the current code
there and it seems to be safe for now as only secid is used which
is part of struct flowi_common.  But that API should be changed
so that so that we don't get new bugs in the future.  We could
do that by replacing fl with just secid or adding a family field.

Reported-by: [email protected]
Fixes: 48b8d78315 ("[XFRM]: State selection update to use inner...")
Signed-off-by: Herbert Xu <[email protected]>
Signed-off-by: Steffen Klassert <[email protected]>
2020-09-25 09:59:51 +02:00
Herbert Xu 255f6c2e74 crypto: lib/chacha20poly1305 - Set SG_MITER_ATOMIC unconditionally
There is no reason for the chacha20poly1305 SG miter code to use
kmap instead of kmap_atomic as the critical section doesn't sleep
anyway.  So we can simply get rid of the preemptible check and
set SG_MITER_ATOMIC unconditionally.

Even if we need to reenable preemption to lower latency we should
be doing that by interrupting the SG miter walk rather than using
kmap.

Reported-by: Linus Torvalds <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2020-09-25 17:48:13 +10:00
Herbert Xu 63cdd870ab crypto: inside-secure - Reuse code in safexcel_hmac_alg_setkey
The code in the current implementation of safexcel_hmac_alg_setkey
can be reused by safexcel_cipher.  This patch does just that by
renaming the previous safexcel_hmac_setkey to __safexcel_hmac_setkey.
The now-shared safexcel_hmac_alg_setkey becomes safexcel_hmac_setkey
and a new safexcel_hmac_alg_setkey has been added for use by ahash
transforms.

As a result safexcel_aead_setkey's stack frame has been reduced by
about half in size, or about 512 bytes.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2020-09-25 17:48:13 +10:00
Herbert Xu 78cf1c8bfc crypto: inside-secure - Move ipad/opad into safexcel_context
As both safexcel_ahash_ctx and safexcel_cipher_ctx contain ipad
and opad buffers this patch moves them into the common struct
safexcel_context.  It also adds a union so that they can be accessed
in the appropriate endian without crazy casts.

Signed-off-by: Herbert Xu <[email protected]>
2020-09-25 17:48:13 +10:00
Herbert Xu 18e5189535 crypto: inside-secure - Move priv pointer into safexcel_context
This patch moves the priv pointer into struct safexcel_context
because both structs that extend safexcel_context have that pointer
as well.

Signed-off-by: Herbert Xu <[email protected]>
2020-09-25 17:48:12 +10:00
Herbert Xu 6d77282faf crypto: n2 - Fix sparse endianness warning
This patch fixes sparse endianness warnings by changing the type
of hash_init to u8 from u32.  There should be no difference in the
generated code.

Signed-off-by: Herbert Xu <[email protected]>
2020-09-18 17:20:12 +10:00
Herbert Xu 9b20cbf8eb crypto: sun4i-ss - Fix sparse endianness markers
This patch also fixes the incorrect endianness markings in the
sun4i-ss driver.  It should have no effect in the genereated code.

Instead of using cpu_to_Xe32 followed by a memcpy, this patch
converts the final hash write to use put_unaligned_X instead.

Reported-by: kernel test robot <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
Tested-by: Corentin Labbe <[email protected]>
Acked-by: Corentin Labbe <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
2020-09-18 17:20:10 +10:00