Skip to contentSkip to conversation

virtio: nsm: fix raw ioctl copy error path

PATCH In review Yousef Alhouseen 3 participants 4 messages Jun 24 – Jul 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio: nsm: fix raw ioctl copy error path

nsm_dev_ioctl() uses a common exit path which unlocks nsm->lock.

A failed copy_from_user() reaches that path before the mutex is locked.

Return -EFAULT directly for that pre-lock failure.

---
 drivers/misc/nsm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/nsm.c +1 -2
index ef7b32742..e39ff0071 100644
@@ -365,9 +365,8 @@ static long nsm_dev_ioctl(struct file *file, unsigned int cmd,
 		return -EINVAL;
 
 	/* Copy user argument struct to kernel argument struct */
-	r = -EFAULT;
 	if (copy_from_user(&raw, argp, _IOC_SIZE(cmd)))
-		goto out;
+		return -EFAULT;
 
 	mutex_lock(&nsm->lock);
 
Signature · 1 line
2.54.0
#2 lore raw
In reply to Yousef Alhouseen
Quoted 10 lines · Yousef Alhouseen

nsm_dev_ioctl() uses a common exit path which unlocks nsm->lock.

A failed copy_from_user() reaches that path before the mutex is locked.

Return -EFAULT directly for that pre-lock failure.

---
 drivers/misc/nsm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

The subject says "virtio" yet that is not what this driver is :(

Can you fix that up and resend?

thanks,

greg k-h

#3 lore raw

Yes, sorry about that. The prefix should be "virt: nsm", not "virtio:
nsm". I'll fix the subject and resend it as v2.

Thanks,
Yousef

Quoted 19 lines · Greg Kroah-Hartman
Quoted 10 lines · Yousef Alhouseen

nsm_dev_ioctl() uses a common exit path which unlocks nsm->lock.

A failed copy_from_user() reaches that path before the mutex is locked.

Return -EFAULT directly for that pre-lock failure.

---
drivers/misc/nsm.c | 3 +--

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

The subject says "virtio" yet that is not what this driver is :(

Can you fix that up and resend?

thanks,

greg k-h