Skip to contentSkip to conversation

vduse: return compat ioctl results directly

PATCH In review Linfeng Sun 3 participants 4 messages Sep 8 virtio core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vduse: return compat ioctl results directly

The compat handler handles VDUSE_IOTLB_GET_FD and VDUSE_VQ_GET_INFO, but then calls the native handler. Their different command sizes make native dispatch return -ENOIOCTLCMD.

For GET_FD, this overwrites receive_fd()'s return value after the descriptor is installed, leaking one fd per call. Return handled compat results directly and use native dispatch only for other commands.

Fixes 455a2a1af926 ("vduse: fix compat handling for VDUSE_IOTLB_GET_FD/VDUSE_VQ_GET_INFO")
---
 drivers/vdpa/vdpa_user/vduse_dev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/vdpa/vdpa_user/vduse_dev.c +3 -3
index 4dea4d6a3855..49a231bdf948 100644
@@ -1882,11 +1882,11 @@ static long vduse_dev_compat_ioctl(struct file *file, unsigned int cmd,
 		break;
 	}
 	default:
-		ret = -ENOIOCTLCMD;
-		break;
+		return vduse_dev_ioctl(file, cmd,
+				       (unsigned long)compat_ptr(arg));
 	}
 
-	return vduse_dev_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
+	return ret;
 }
 #else
 #define vduse_dev_compat_ioctl compat_ptr_ioctl

---
base-commit: d7808b37da0a619cf1fa541c2384e783fecc2480

Best regards,

Signature · 1 line
Linfeng Sun <[email protected]>
#1 lore raw
Quoted 10 lines · Linfeng Sun

The compat handler handles VDUSE_IOTLB_GET_FD and VDUSE_VQ_GET_INFO, but then calls the native handler. Their different command sizes make native dispatch return -ENOIOCTLCMD.

For GET_FD, this overwrites receive_fd()'s return value after the descriptor is installed, leaking one fd per call. Return handled compat results directly and use native dispatch only for other commands.

Fixes 455a2a1af926 ("vduse: fix compat handling for VDUSE_IOTLB_GET_FD/VDUSE_VQ_GET_INFO")

indeed, I will apply.

Cc Arnd.

But ... how was the original patch working then? Arnd, what gives?

Quoted 30 lines
---
 drivers/vdpa/vdpa_user/vduse_dev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/vdpa/vdpa_user/vduse_dev.c +3 -4
index 4dea4d6a3855..49a231bdf948 100644
@@ -1882,11 +1882,11 @@ static long vduse_dev_compat_ioctl(struct file *file, unsigned int cmd,
 		break;
 	}
 	default:
-		ret = -ENOIOCTLCMD;
-		break;
+		return vduse_dev_ioctl(file, cmd,
+				       (unsigned long)compat_ptr(arg));
 	}
 
-	return vduse_dev_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
+	return ret;
 }
 #else
 #define vduse_dev_compat_ioctl compat_ptr_ioctl
 
---

base-commit: d7808b37da0a619cf1fa541c2384e783fecc2480

Best regards,

Signature · 1 line
Linfeng Sun <[email protected]>
#2 lore raw
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Linfeng Sun

The compat handler handles VDUSE_IOTLB_GET_FD and VDUSE_VQ_GET_INFO, but then calls the native handler. Their different command sizes make native dispatch return -ENOIOCTLCMD.

Quoted 8 lines
Quoted 6 lines

For GET_FD, this overwrites receive_fd()'s return value after the descriptor is installed, leaking one fd per call. Return handled compat results directly and use native dispatch only for other commands.

Fixes 455a2a1af926 ("vduse: fix compat handling for VDUSE_IOTLB_GET_FD/VDUSE_VQ_GET_INFO")

indeed, I will apply.

The fix looks correct to me, thanks!

Quoted 1 line

But ... how was the original patch working then? Arnd, what gives?

It looks I either broke it during refactoring from two functions into one, or I just didn't do it right in the first place.

I did write in the extra patch text

| The code is directly copied from the native ioctl handler, but I
| did not test this with actual x86-32 userspace, so please review
| carefully.

but obviously should have caught this one myself since it is a much less subtle bug than the one I was trying to fix in the first place.

Arnd

#3 lore raw
Quoted 24 lines · Arnd Bergmann
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Linfeng Sun

The compat handler handles VDUSE_IOTLB_GET_FD and VDUSE_VQ_GET_INFO, but then calls the native handler. Their different command sizes make native dispatch return -ENOIOCTLCMD.

Quoted 8 lines
Quoted 6 lines

For GET_FD, this overwrites receive_fd()'s return value after the descriptor is installed, leaking one fd per call. Return handled compat results directly and use native dispatch only for other commands.

Fixes 455a2a1af926 ("vduse: fix compat handling for VDUSE_IOTLB_GET_FD/VDUSE_VQ_GET_INFO")

indeed, I will apply.

The fix looks correct to me, thanks!

Quoted 1 line

But ... how was the original patch working then? Arnd, what gives?

It looks I either broke it during refactoring from two functions into one, or I just didn't do it right in the first place.

I did write in the extra patch text

Quoted 8 lines
| The code is directly copied from the native ioctl handler, but I
| did not test this with actual x86-32 userspace, so please review
| carefully.

but obviously should have caught this one myself since it is a much less subtle bug than the one I was trying to fix in the first place.

Arnd

Should teach me not to apply untested code. No amount of careful review replaces testing)

Signature · 1 line
MST