Re: [PATCH] crypto: ccp: Initialize DBC ioctl mutex before registering device

From: Tom Lendacky

Date: Sat Aug 29 2026 - 11:08:26 EST


On 8/29/26 08:34, Runyu Xiao wrote:
> dbc_dev_init() registers the DBC misc device before initializing
> ioctl_mutex. Once misc_register() publishes the device, userspace can
> open it and invoke dbc_ioctl() while the mutex is still uninitialized.
>
> Initialize ioctl_mutex before calling misc_register() so the published
> ioctl callback always sees an initialized mutex.
>
> Fixes: c04cf9e14f10 ("crypto: ccp - Add support for fetching a nonce for dynamic boost control")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Runyu Xiao <runyu.xiao@xxxxxxxxxx>
> Assisted-by: Codex:GPT-5
> ---
> drivers/crypto/ccp/dbc.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/crypto/ccp/dbc.c b/drivers/crypto/ccp/dbc.c
> index 410084a90..00c864413 100644
> --- a/drivers/crypto/ccp/dbc.c
> +++ b/drivers/crypto/ccp/dbc.c
> @@ -240,12 +240,12 @@ int dbc_dev_init(struct psp_device *psp)
> dbc_dev->char_dev.name = "dbc";
> dbc_dev->char_dev.fops = &dbc_fops;
> dbc_dev->char_dev.mode = 0600;
> + mutex_init(&dbc_dev->ioctl_mutex);

This mixes it in with the misc_register() settings and the call, move it
to just before all the settings.

Thanks,
Tom

> +
> ret = misc_register(&dbc_dev->char_dev);
> if (ret)
> goto cleanup_mbox;
>
> - mutex_init(&dbc_dev->ioctl_mutex);
> -
> return 0;
>
> cleanup_mbox: