[PATCH 26/62] misc: nsm: Fix a locking bug in an error path

From: Bart Van Assche

Date: Mon Feb 23 2026 - 17:17:03 EST


From: Bart Van Assche <bvanassche@xxxxxxx>

If nsm->lock has not been locked, do not unlock it from any error path.
This bug has been detected by the Clang thread-safety analyzer.

Cc: Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxx>
Cc: Michael S. Tsirkin <mst@xxxxxxxxxx>
Cc: Alexander Graf <graf@xxxxxxxxxx>
Cc: The AWS Nitro Enclaves Team <aws-nitro-enclaves-devel@xxxxxxxxxx>
Cc: linux-kernel@xxxxxxxxxxxxxxx
Fixes: b9873755a6c8 ("misc: Add Nitro Secure Module driver")
Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
---
drivers/misc/nsm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/nsm.c b/drivers/misc/nsm.c
index ef7b32742340..185900cdad4a 100644
--- a/drivers/misc/nsm.c
+++ b/drivers/misc/nsm.c
@@ -367,7 +367,7 @@ static long nsm_dev_ioctl(struct file *file, unsigned int cmd,
/* Copy user argument struct to kernel argument struct */
r = -EFAULT;
if (copy_from_user(&raw, argp, _IOC_SIZE(cmd)))
- goto out;
+ return r;

mutex_lock(&nsm->lock);