mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] vduse: return compat ioctl results directly
@ 2026-09-08  7:31 Linfeng Sun
  2026-09-08  7:57 ` Michael S. Tsirkin
  0 siblings, 1 reply; 4+ messages in thread
From: Linfeng Sun @ 2026-09-08  7:31 UTC (permalink / raw)
  To: Michael S. Tsirkin, Jason Wang, Eugenio Pérez
  Cc: virtualization, linux-kernel, 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")
Signed-off-by: Linfeng Sun <linfeng.sun.dev@gmail.com>
---
 drivers/vdpa/vdpa_user/vduse_dev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index 4dea4d6a3855..49a231bdf948 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -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,
-- 
Linfeng Sun <linfeng.sun.dev@gmail.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] vduse: return compat ioctl results directly
  2026-09-08  7:31 [PATCH] vduse: return compat ioctl results directly Linfeng Sun
@ 2026-09-08  7:57 ` Michael S. Tsirkin
  2026-09-08  8:08   ` Arnd Bergmann
  0 siblings, 1 reply; 4+ messages in thread
From: Michael S. Tsirkin @ 2026-09-08  7:57 UTC (permalink / raw)
  To: Linfeng Sun
  Cc: Jason Wang, Eugenio Pérez, virtualization, linux-kernel,
	Arnd Bergmann

On Tue, Sep 08, 2026 at 03:31:51PM +0800, Linfeng Sun wrote:
> 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")
> Signed-off-by: Linfeng Sun <linfeng.sun.dev@gmail.com>

indeed, I will apply.

Cc Arnd.

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

> ---
>  drivers/vdpa/vdpa_user/vduse_dev.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> index 4dea4d6a3855..49a231bdf948 100644
> --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> @@ -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,
> -- 
> Linfeng Sun <linfeng.sun.dev@gmail.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] vduse: return compat ioctl results directly
  2026-09-08  7:57 ` Michael S. Tsirkin
@ 2026-09-08  8:08   ` Arnd Bergmann
  2026-09-08  8:32     ` Michael S. Tsirkin
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2026-09-08  8:08 UTC (permalink / raw)
  To: Michael S. Tsirkin, Linfeng Sun
  Cc: Jason Wang, Eugenio Pérez, virtualization, linux-kernel

On Tue, Sep 8, 2026, at 09:57, Michael S. Tsirkin wrote:
> On Tue, Sep 08, 2026 at 03:31:51PM +0800, Linfeng Sun wrote:
>> 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")
>> Signed-off-by: Linfeng Sun <linfeng.sun.dev@gmail.com>
>
> indeed, I will apply.

The fix looks correct to me, thanks!

> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] vduse: return compat ioctl results directly
  2026-09-08  8:08   ` Arnd Bergmann
@ 2026-09-08  8:32     ` Michael S. Tsirkin
  0 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2026-09-08  8:32 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Linfeng Sun, Jason Wang, Eugenio Pérez, virtualization,
	linux-kernel

On Tue, Sep 08, 2026 at 10:08:46AM +0200, Arnd Bergmann wrote:
> On Tue, Sep 8, 2026, at 09:57, Michael S. Tsirkin wrote:
> > On Tue, Sep 08, 2026 at 03:31:51PM +0800, Linfeng Sun wrote:
> >> 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")
> >> Signed-off-by: Linfeng Sun <linfeng.sun.dev@gmail.com>
> >
> > indeed, I will apply.
> 
> The fix looks correct to me, thanks!
> 
> > 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

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

-- 
MST


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-08  8:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-08  7:31 [PATCH] vduse: return compat ioctl results directly Linfeng Sun
2026-09-08  7:57 ` Michael S. Tsirkin
2026-09-08  8:08   ` Arnd Bergmann
2026-09-08  8:32     ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®