Skip to contentSkip to conversation

crypto: ccp: Initialize DBC ioctl mutex before registering device

PATCH Superseded Runyu Xiao 4 participants 7 messages Aug 29 – Sep 11

Subsystems (4)
lore
Share & tools
lore

Runyu Xiao

author
#0 lore raw

PATCH 1/1 crypto: ccp: Initialize DBC ioctl mutex before registering device

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")
Assisted-by Codex:GPT-5
---
 drivers/crypto/ccp/dbc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/ccp/dbc.c +2 -2
index 410084a90..00c864413 100644
@@ -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);
+
 	ret = misc_register(&dbc_dev->char_dev);
 	if (ret)
 		goto cleanup_mbox;
 
-	mutex_init(&dbc_dev->ioctl_mutex);
-
 	return 0;
 
 cleanup_mbox:
maintainer
#1 lore raw
Quoted 20 lines · Runyu Xiao

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")
Assisted-by Codex:GPT-5
---
 drivers/crypto/ccp/dbc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/ccp/dbc.c +0 -0
index 410084a90..00c864413 100644

drivers/crypto/ccp/dbc.c int dbc_dev_init(struct psp_device *psp) · line 243

Quoted 4 lines
drivers/crypto/ccp/dbc.c +1 -0
@@ -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

Quoted 10 lines
drivers/crypto/ccp/dbc.c +1 -2
+
 	ret = misc_register(&dbc_dev->char_dev);
 	if (ret)
 		goto cleanup_mbox;
 
-	mutex_init(&dbc_dev->ioctl_mutex);
-
 	return 0;
 
 cleanup_mbox:
author
#2 lore raw

PATCH v2 1/1 crypto: ccp: Initialize DBC ioctl mutex before registering device

In reply to Runyu Xiao

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")
Assisted-by Codex:GPT-5

---
v2:
- Move mutex initialization before setting up the misc device, as suggested by Tom Lendacky.

 drivers/crypto/ccp/dbc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/ccp/dbc.c +2 -2
index 410084a9039c..4db49a14550c 100644
@@ -235,6 +235,8 @@ int dbc_dev_init(struct psp_device *psp)
 		goto cleanup_mbox;
 	}
 
+	mutex_init(&dbc_dev->ioctl_mutex);
+
 	dbc_dev->char_dev.minor = MISC_DYNAMIC_MINOR;
 	dbc_dev->char_dev.name = "dbc";
 	dbc_dev->char_dev.fops = &dbc_fops;
@@ -243,8 +245,6 @@ int dbc_dev_init(struct psp_device *psp)
 	if (ret)
 		goto cleanup_mbox;
 
-	mutex_init(&dbc_dev->ioctl_mutex);
-
 	return 0;
 
 cleanup_mbox:
maintainer Reviewed-by on v2 1/1
#3 lore raw
Quoted 4 lines · Runyu Xiao

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.

Quoted 8 lines

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")
Assisted-by Codex:GPT-5
Quoted 30 lines

---
v2:
- Move mutex initialization before setting up the misc device, as suggested by Tom Lendacky.

 drivers/crypto/ccp/dbc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/ccp/dbc.c +2 -2
index 410084a9039c..4db49a14550c 100644
@@ -235,6 +235,8 @@ int dbc_dev_init(struct psp_device *psp)
 		goto cleanup_mbox;
 	}
 
+	mutex_init(&dbc_dev->ioctl_mutex);
+
 	dbc_dev->char_dev.minor = MISC_DYNAMIC_MINOR;
 	dbc_dev->char_dev.name = "dbc";
 	dbc_dev->char_dev.fops = &dbc_fops;
@@ -243,8 +245,6 @@ int dbc_dev_init(struct psp_device *psp)
 	if (ret)
 		goto cleanup_mbox;
 
-	mutex_init(&dbc_dev->ioctl_mutex);
-
 	return 0;
 
 cleanup_mbox:
Reviewed-by on v2 1/1
#4 lore raw
In reply to Runyu Xiao
Quoted 4 lines · Runyu Xiao

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.

Quoted 8 lines

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")
Assisted-by Codex:GPT-5

I mean my tag to come here, I didn't realize this was threaded with V1 and V2 together.

Quoted 29 lines

v2:
- Move mutex initialization before setting up the misc device, as suggested by Tom Lendacky.

  drivers/crypto/ccp/dbc.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/ccp/dbc.c +2 -2
index 410084a9039c..4db49a14550c 100644
@@ -235,6 +235,8 @@ int dbc_dev_init(struct psp_device *psp)
  		goto cleanup_mbox;
  	}
 
+	mutex_init(&dbc_dev->ioctl_mutex);
+
  	dbc_dev->char_dev.minor = MISC_DYNAMIC_MINOR;
  	dbc_dev->char_dev.name = "dbc";
  	dbc_dev->char_dev.fops = &dbc_fops;
@@ -243,8 +245,6 @@ int dbc_dev_init(struct psp_device *psp)
  	if (ret)
  		goto cleanup_mbox;
 
-	mutex_init(&dbc_dev->ioctl_mutex);
-
  	return 0;
 
  cleanup_mbox:
maintainer
#5 lore raw
In reply to Runyu Xiao
Quoted 12 lines · Runyu Xiao

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")
Assisted-by Codex:GPT-5
Quoted 7 lines

---
v2:
- Move mutex initialization before setting up the misc device, as suggested by Tom Lendacky.

drivers/crypto/ccp/dbc.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Reviewed-by on v1 1/1
#6 lore raw
In reply to Runyu Xiao
Quoted 11 lines · Runyu Xiao

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")
Assisted-by Codex:GPT-5
Quoted 22 lines
  drivers/crypto/ccp/dbc.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/ccp/dbc.c +2 -2
index 410084a90..00c864413 100644
@@ -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);
+
  	ret = misc_register(&dbc_dev->char_dev);
  	if (ret)
  		goto cleanup_mbox;
 
-	mutex_init(&dbc_dev->ioctl_mutex);
-
  	return 0;
 
  cleanup_mbox: