From 3739d280101f7e8dae6af3df5e1d37981f33d0fc Mon Sep 17 00:00:00 2001 From: Weili Qian Date: Fri, 26 May 2023 18:04:37 +0800 Subject: [PATCH 1/2] crypto: hisilicon/trng - use %u to print u32 variables driver inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I79JTN CVE: NA ---------------------------------------------------------------------- The 'dlen' is u32 type, use %u instead of %d to print u32 values. Signed-off-by: Weili Qian Signed-off-by: JiangShui Yang (cherry picked from commit ac0a046ea41c82cf67b7d16702e1d7316f81f8ea) --- drivers/crypto/hisilicon/trng/trng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/hisilicon/trng/trng.c b/drivers/crypto/hisilicon/trng/trng.c index 97e500db0a82..35907f29cee6 100644 --- a/drivers/crypto/hisilicon/trng/trng.c +++ b/drivers/crypto/hisilicon/trng/trng.c @@ -121,7 +121,7 @@ static int hisi_trng_generate(struct crypto_rng *tfm, const u8 *src, u32 i; if (dlen > SW_DRBG_BLOCKS_NUM * SW_DRBG_BYTES || dlen == 0) { - pr_err("dlen(%d) exceeds limit(%d)!\n", dlen, + pr_err("dlen(%u) exceeds limit(%d)!\n", dlen, SW_DRBG_BLOCKS_NUM * SW_DRBG_BYTES); return -EINVAL; } -- Gitee From ad4f5877b02bd93d1ad416c707aee0f4df7774d1 Mon Sep 17 00:00:00 2001 From: Weili Qian Date: Fri, 26 May 2023 18:04:38 +0800 Subject: [PATCH 2/2] crypto/trng: Remove the automatic loading of the hisi_trng driver driver inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I79JTN CVE: NA ---------------------------------------------------------------------- On the current openEuler OS, when the OS is automatically started, the hisi_trng_v2 device driver will be loaded because the algorithm self-test needs to use random numbers. However, the trng framework of community crypto requires that the first loaded and used trng resource handle cannot be released, which will cause hisi_trng_v2 to fail to unload the driver in subsequent hisi trng module function processing. The patch is modified by reducing the algorithm priority of the hardware device driver. Not enabled in autotest and load. Only reload this device driver for stand-alone use. Signed-off-by: liulongfang Signed-off-by: JiangShui Yang (cherry picked from commit fafc2e9530bad47c8cf87a06a30e550eb8c96d2d) --- drivers/crypto/hisilicon/trng/trng.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/crypto/hisilicon/trng/trng.c b/drivers/crypto/hisilicon/trng/trng.c index 35907f29cee6..440cc28b2e35 100644 --- a/drivers/crypto/hisilicon/trng/trng.c +++ b/drivers/crypto/hisilicon/trng/trng.c @@ -27,6 +27,7 @@ #define SW_DRBG_SEED(n) (SW_DRBG_KEY_BASE - ((n) << SW_DRBG_NUM_SHIFT)) #define SW_DRBG_SEED_REGS_NUM 12 #define SW_DRBG_SEED_SIZE 48 +#define SW_DRBG_CRYPTO_ALG_PRI 100 #define SW_DRBG_BLOCKS 0x0830 #define SW_DRBG_INIT 0x0834 #define SW_DRBG_GEN 0x083c @@ -218,7 +219,7 @@ static struct rng_alg hisi_trng_alg = { .base = { .cra_name = "stdrng", .cra_driver_name = "hisi_stdrng", - .cra_priority = 300, + .cra_priority = SW_DRBG_CRYPTO_ALG_PRI, .cra_ctxsize = sizeof(struct hisi_trng_ctx), .cra_module = THIS_MODULE, .cra_init = hisi_trng_init, -- Gitee