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

Bart Van Assche posted 62 patches 1 month ago
Only 30 patches received!
[PATCH 26/62] misc: nsm: Fix a locking bug in an error path
Posted by Bart Van Assche 1 month ago
From: Bart Van Assche <bvanassche@acm.org>

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@linaro.org>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Alexander Graf <graf@amazon.com>
Cc: The AWS Nitro Enclaves Team <aws-nitro-enclaves-devel@amazon.com>
Cc: linux-kernel@vger.kernel.org
Fixes: b9873755a6c8 ("misc: Add Nitro Secure Module driver")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 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);
Re: [PATCH 26/62] misc: nsm: Fix a locking bug in an error path
Posted by Alexander Graf 1 month ago
On 23.02.26 23:00, Bart Van Assche wrote:
> From: Bart Van Assche <bvanassche@acm.org>
>
> 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@linaro.org>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Alexander Graf <graf@amazon.com>
> Cc: The AWS Nitro Enclaves Team <aws-nitro-enclaves-devel@amazon.com>
> Cc: linux-kernel@vger.kernel.org
> Fixes: b9873755a6c8 ("misc: Add Nitro Secure Module driver")
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>


Thanks for catching this!

Reviewed-by: Alexander Graf <graf@amazon.com>


Alex





Amazon Web Services Development Center Germany GmbH
Tamara-Danz-Str. 13
10243 Berlin
Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger
Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597