From: sashiko-bot@kernel.org
To: "Depei Yang" <yangdepei@hygon.cn>, linux-crypto@vger.kernel.org
Cc: "Tom Lendacky" <thomas.lendacky@amd.com>,
"Herbert Xu" <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
"Gary R Hook" <gary.hook@amd.com>,
"Shan Chen" <chenshan@hygon.cn>,
"Yongwei Xu" <xuyongwei@hygon.cn>,
"Xiaochen Shen" <shenxiaochen@hygon.cn>
Subject: Re: [PATCH 10/11] crypto: ccp - add SM4 engine and skcipher algorithms
Date: Wed, 25 Nov 2026 08:11:17 +0000 [thread overview]
Message-ID: <sashiko-outbox-232868@kernel.org> (raw)
In-Reply-To: <197a8174e8f0e39b92585c4fa24f228d5e4486d1.1795588986.git.yangdepei@hygon.cn>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] crypto: ccp - missing chunksize for ctr(sm4) in
ccp_register_sm4_alg()
- [Medium] crypto: ccp - 64-bit counter size in ccp_sm4_crypt() breaks
128-bit ctr(sm4)
- [Low] crypto: ccp - missing noinline_for_stack on SM4 ccp_run_*_cmd()
handlers
--
commit dd1e070e32af2e2910159d7e8f6ecb0aabde8163
Author: Depei Yang <yangdepei@hygon.cn>
crypto: ccp - add SM4 engine and skcipher algorithms
This commit adds v5 descriptor builders, request handling, and skcipher
registrations for ecb(sm4), cbc(sm4), and ctr(sm4) on CCP devices.
> diff --git a/drivers/crypto/ccp/ccp-crypto-sm4.c b/drivers/crypto/ccp/ccp-crypto-sm4.c
> new file mode 100644
> index 0000000000000..fbdba8cd0da04
> --- /dev/null
> +++ b/drivers/crypto/ccp/ccp-crypto-sm4.c
[ ... ]
> + if (mode == CCP_SM4_ALG_MODE_CTR) {
> + cmd->engine = CCP_ENGINE_SM4_CTR;
> + cmd->u.sm4_ctr.action = action;
> + cmd->u.sm4_ctr.size = 63;
> + cmd->u.sm4_ctr.step = 1;
[Severity: Medium]
Does setting cmd->u.sm4_ctr.size to 63 restrict the counter increment to
the lower 64 bits of the 16-byte IV?
The crypto API ctr(sm4) algorithm treats the counter block as a 128-bit
big-endian integer (crypto_inc(ctrblk, 16)), and CCP AES-CTR sets its
7-bit size field to AES_BLOCK_SIZE * BITS_PER_BYTE - 1 (127). With size =
63, requests whose counter wraps the lower 64 bits will not propagate the
carry into the upper 64 bits of the counter stream or the returned
req->iv, causing self-test failures against the generic implementation
under CONFIG_CRYPTO_MANAGER_EXTRA_TESTS.
If the SM4-CTR engine supports a 128-bit counter width via its 7-bit size
field, this should be SM4_BLOCK_SIZE * BITS_PER_BYTE - 1; if the hardware
is limited to 64 bits, requests crossing a 64-bit counter boundary need a
software fallback.
[ ... ]
> +static const struct skcipher_alg ccp_sm4_defaults = {
> + .setkey = ccp_sm4_setkey,
> + .encrypt = ccp_sm4_encrypt,
> + .decrypt = ccp_sm4_decrypt,
> + .min_keysize = SM4_KEY_SIZE,
> + .max_keysize = SM4_KEY_SIZE,
> + .init = ccp_sm4_init_tfm,
> +
> + .base.cra_flags = CRYPTO_ALG_ASYNC |
> + CRYPTO_ALG_ALLOCATES_MEMORY |
> + CRYPTO_ALG_KERN_DRIVER_ONLY |
> + CRYPTO_ALG_NEED_FALLBACK,
> + .base.cra_blocksize = SM4_BLOCK_SIZE,
> + .base.cra_ctxsize = sizeof(struct ccp_ctx) + CRYPTO_DMA_PADDING,
> + .base.cra_priority = CCP_CRA_PRIORITY,
> + .base.cra_module = THIS_MODULE,
> +};
[ ... ]
> +/* SM4-CTR is a separate engine on the CCP */
> +static const struct ccp_sm4_def sm4_ctr_alg = {
> + .mode = CCP_SM4_ALG_MODE_CTR,
> + .name = "ctr(sm4)",
> + .driver_name = "ctr-sm4-ccp",
> + .blocksize = 1,
> + .ivsize = SM4_BLOCK_SIZE,
> + .alg_defaults = &ccp_sm4_defaults,
> +};
> +
> +static int ccp_register_sm4_alg(struct list_head *head,
> + const struct ccp_sm4_def *def)
> +{
> + struct ccp_crypto_skcipher_alg *ccp_alg;
> + struct skcipher_alg *alg;
> + int ret;
> +
> + ccp_alg = kzalloc_obj(*ccp_alg);
> + if (!ccp_alg)
> + return -ENOMEM;
> +
> + INIT_LIST_HEAD(&ccp_alg->entry);
> +
> + ccp_alg->mode = def->mode;
> +
> + /* copy the defaults and override as necessary */
> + alg = &ccp_alg->alg;
> + *alg = *def->alg_defaults;
> + strscpy(alg->base.cra_name, def->name);
> + strscpy(alg->base.cra_driver_name, def->driver_name);
> + alg->base.cra_blocksize = def->blocksize;
> + alg->ivsize = def->ivsize;
> +
> + ret = crypto_register_skcipher(alg);
[Severity: Medium]
Should ccp_sm4_defaults set .chunksize = SM4_BLOCK_SIZE?
For ctr(sm4), ccp_register_sm4_alg() sets alg->base.cra_blocksize to 1
while alg->chunksize remains 0, so skcipher_prepare_alg_common() defaults
chunksize to 1 instead of SM4_BLOCK_SIZE. Streaming callers such as
AF_ALG _skcipher_recvmsg() use crypto_skcipher_chunksize() to align
non-final MSG_MORE chunks to a block boundary; with chunksize == 1, a
partial block submitted in a non-final call advances the 16-byte hardware
counter IV to the next block and discards the remaining keystream bytes of
that block, corrupting subsequent output.
> diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
> index f35803c37ab4b..7c8464b1db6b7 100644
> --- a/drivers/crypto/ccp/ccp-ops.c
> +++ b/drivers/crypto/ccp/ccp-ops.c
[ ... ]
> +static int ccp_run_sm4_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
> +{
> + struct ccp_sm4_engine *sm4 = &cmd->u.sm4;
> + struct ccp_dm_workarea iv_key;
> + struct ccp_data src, dst;
> + struct ccp_op op;
[ ... ]
> +static int ccp_run_sm4_ctr_cmd(struct ccp_cmd_queue *cmd_q,
> + struct ccp_cmd *cmd)
> +{
> + struct ccp_sm4_ctr_engine *sm4_ctr = &cmd->u.sm4_ctr;
> + struct ccp_dm_workarea iv_key;
> + struct ccp_data src, dst;
> + struct ccp_op op;
[Severity: Low]
Should ccp_run_sm4_cmd() and ccp_run_sm4_ctr_cmd() be marked
noinline_for_stack like the other per-engine handlers in this file?
Each function allocates roughly 400 bytes of local structures on the stack
and has a single call site in ccp_run_cmd(); 72c8117adfce ("crypto: ccp -
Reduce maximum stack usage") marked the other ccp_run_*_cmd() handlers
noinline_for_stack to prevent the compiler from combining their stack
frames in ccp_run_cmd() and tripping -Wframe-larger-than.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795588986.git.yangdepei@hygon.cn?part=10
next prev parent reply other threads:[~2026-11-25 8:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 7:45 [PATCH 00/11] crypto: ccp - add Hygon SM3/SM4 support Depei Yang
2026-11-25 7:45 ` [PATCH 01/11] crypto: ccp - fix LSB region mask calculation Depei Yang
2026-11-25 7:46 ` [PATCH 02/11] crypto: ccp - acknowledge queue interrupt before waking waiter Depei Yang
2026-11-25 7:46 ` [PATCH 03/11] crypto: ccp - add engine capability and version information Depei Yang
2026-11-25 7:55 ` sashiko-bot
2026-11-25 7:46 ` [PATCH 04/11] crypto: ccp - register algorithms only for supported engines Depei Yang
2026-11-25 7:46 ` [PATCH 05/11] crypto: ccp - split v5 command submission from queue run Depei Yang
2026-11-25 7:46 ` [PATCH 06/11] crypto: ccp - add SM3/SM4 command definitions Depei Yang
2026-11-25 7:46 ` [PATCH 07/11] crypto: ccp - add Hygon CCP device IDs and vdata Depei Yang
2026-11-25 7:46 ` [PATCH 08/11] crypto: ccp - handle only supported interrupts in v5 irq bh Depei Yang
2026-11-25 7:46 ` [PATCH 09/11] crypto: ccp - detect the Hygon CCP engines from the version register Depei Yang
2026-11-25 7:46 ` [PATCH 10/11] crypto: ccp - add SM4 engine and skcipher algorithms Depei Yang
2026-11-25 8:11 ` sashiko-bot [this message]
2026-11-25 7:46 ` [PATCH 11/11] crypto: ccp - add SM3 engine and ahash algorithms Depei Yang
2026-11-25 8:10 ` sashiko-bot
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=sashiko-outbox-232868@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=chenshan@hygon.cn \
--cc=davem@davemloft.net \
--cc=gary.hook@amd.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shenxiaochen@hygon.cn \
--cc=thomas.lendacky@amd.com \
--cc=xuyongwei@hygon.cn \
--cc=yangdepei@hygon.cn \
/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