* [PATCH] vhost: vringh: Modify the return value check
@ 2025-09-10 9:17 zhangjiao2
2025-09-15 10:59 ` Lei Yang
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: zhangjiao2 @ 2025-09-10 9:17 UTC (permalink / raw)
To: mst
Cc: jasowang, eperezma, kvm, virtualization, netdev, linux-kernel,
zhang jiao
From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
The return value of copy_from_iter and copy_to_iter can't be negative,
check whether the copied lengths are equal.
Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
---
drivers/vhost/vringh.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
index 9f27c3f6091b..0c8a17cbb22e 100644
--- a/drivers/vhost/vringh.c
+++ b/drivers/vhost/vringh.c
@@ -1115,6 +1115,7 @@ static inline int copy_from_iotlb(const struct vringh *vrh, void *dst,
struct iov_iter iter;
u64 translated;
int ret;
+ size_t size;
ret = iotlb_translate(vrh, (u64)(uintptr_t)src,
len - total_translated, &translated,
@@ -1132,9 +1133,9 @@ static inline int copy_from_iotlb(const struct vringh *vrh, void *dst,
translated);
}
- ret = copy_from_iter(dst, translated, &iter);
- if (ret < 0)
- return ret;
+ size = copy_from_iter(dst, translated, &iter);
+ if (size != translated)
+ return -EFAULT;
src += translated;
dst += translated;
--
2.33.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] vhost: vringh: Modify the return value check
2025-09-10 9:17 [PATCH] vhost: vringh: Modify the return value check zhangjiao2
@ 2025-09-15 10:59 ` Lei Yang
2025-09-21 20:59 ` Michael S. Tsirkin
2025-09-27 20:36 ` Michael S. Tsirkin
2 siblings, 0 replies; 5+ messages in thread
From: Lei Yang @ 2025-09-15 10:59 UTC (permalink / raw)
To: zhangjiao2
Cc: mst, jasowang, eperezma, kvm, virtualization, netdev,
linux-kernel
Tested this patch with virtio-net regression tests, everything works fine.
Tested-by: Lei Yang <leiyang@redhat.com>
On Wed, Sep 10, 2025 at 5:18 PM zhangjiao2
<zhangjiao2@cmss.chinamobile.com> wrote:
>
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
>
> The return value of copy_from_iter and copy_to_iter can't be negative,
> check whether the copied lengths are equal.
>
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> ---
> drivers/vhost/vringh.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
> index 9f27c3f6091b..0c8a17cbb22e 100644
> --- a/drivers/vhost/vringh.c
> +++ b/drivers/vhost/vringh.c
> @@ -1115,6 +1115,7 @@ static inline int copy_from_iotlb(const struct vringh *vrh, void *dst,
> struct iov_iter iter;
> u64 translated;
> int ret;
> + size_t size;
>
> ret = iotlb_translate(vrh, (u64)(uintptr_t)src,
> len - total_translated, &translated,
> @@ -1132,9 +1133,9 @@ static inline int copy_from_iotlb(const struct vringh *vrh, void *dst,
> translated);
> }
>
> - ret = copy_from_iter(dst, translated, &iter);
> - if (ret < 0)
> - return ret;
> + size = copy_from_iter(dst, translated, &iter);
> + if (size != translated)
> + return -EFAULT;
>
> src += translated;
> dst += translated;
> --
> 2.33.0
>
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] vhost: vringh: Modify the return value check
2025-09-10 9:17 [PATCH] vhost: vringh: Modify the return value check zhangjiao2
2025-09-15 10:59 ` Lei Yang
@ 2025-09-21 20:59 ` Michael S. Tsirkin
2025-09-21 21:41 ` Michael S. Tsirkin
2025-09-27 20:36 ` Michael S. Tsirkin
2 siblings, 1 reply; 5+ messages in thread
From: Michael S. Tsirkin @ 2025-09-21 20:59 UTC (permalink / raw)
To: zhangjiao2; +Cc: jasowang, eperezma, kvm, virtualization, netdev, linux-kernel
On Wed, Sep 10, 2025 at 05:17:38PM +0800, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
>
> The return value of copy_from_iter and copy_to_iter can't be negative,
> check whether the copied lengths are equal.
>
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
Well I don't see a fix for copy_to_iter here.
ret = copy_to_iter(src, translated, &iter);
if (ret < 0)
return ret;
> ---
> drivers/vhost/vringh.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
> index 9f27c3f6091b..0c8a17cbb22e 100644
> --- a/drivers/vhost/vringh.c
> +++ b/drivers/vhost/vringh.c
> @@ -1115,6 +1115,7 @@ static inline int copy_from_iotlb(const struct vringh *vrh, void *dst,
> struct iov_iter iter;
> u64 translated;
> int ret;
> + size_t size;
>
> ret = iotlb_translate(vrh, (u64)(uintptr_t)src,
> len - total_translated, &translated,
> @@ -1132,9 +1133,9 @@ static inline int copy_from_iotlb(const struct vringh *vrh, void *dst,
> translated);
> }
>
> - ret = copy_from_iter(dst, translated, &iter);
> - if (ret < 0)
> - return ret;
> + size = copy_from_iter(dst, translated, &iter);
> + if (size != translated)
> + return -EFAULT;
>
> src += translated;
> dst += translated;
> --
> 2.33.0
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] vhost: vringh: Modify the return value check
2025-09-21 20:59 ` Michael S. Tsirkin
@ 2025-09-21 21:41 ` Michael S. Tsirkin
0 siblings, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2025-09-21 21:41 UTC (permalink / raw)
To: zhangjiao2; +Cc: jasowang, eperezma, kvm, virtualization, netdev, linux-kernel
On Sun, Sep 21, 2025 at 04:59:36PM -0400, Michael S. Tsirkin wrote:
> On Wed, Sep 10, 2025 at 05:17:38PM +0800, zhangjiao2 wrote:
> > From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> >
> > The return value of copy_from_iter and copy_to_iter can't be negative,
> > check whether the copied lengths are equal.
> >
> > Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
>
> Well I don't see a fix for copy_to_iter here.
>
>
> ret = copy_to_iter(src, translated, &iter);
> if (ret < 0)
> return ret;
>
to clarify, pls send an additional patch to copy that one.
>
>
>
> > ---
> > drivers/vhost/vringh.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
> > index 9f27c3f6091b..0c8a17cbb22e 100644
> > --- a/drivers/vhost/vringh.c
> > +++ b/drivers/vhost/vringh.c
> > @@ -1115,6 +1115,7 @@ static inline int copy_from_iotlb(const struct vringh *vrh, void *dst,
> > struct iov_iter iter;
> > u64 translated;
> > int ret;
> > + size_t size;
> >
> > ret = iotlb_translate(vrh, (u64)(uintptr_t)src,
> > len - total_translated, &translated,
> > @@ -1132,9 +1133,9 @@ static inline int copy_from_iotlb(const struct vringh *vrh, void *dst,
> > translated);
> > }
> >
> > - ret = copy_from_iter(dst, translated, &iter);
> > - if (ret < 0)
> > - return ret;
> > + size = copy_from_iter(dst, translated, &iter);
> > + if (size != translated)
> > + return -EFAULT;
> >
> > src += translated;
> > dst += translated;
> > --
> > 2.33.0
> >
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] vhost: vringh: Modify the return value check
2025-09-10 9:17 [PATCH] vhost: vringh: Modify the return value check zhangjiao2
2025-09-15 10:59 ` Lei Yang
2025-09-21 20:59 ` Michael S. Tsirkin
@ 2025-09-27 20:36 ` Michael S. Tsirkin
2 siblings, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2025-09-27 20:36 UTC (permalink / raw)
To: zhangjiao2
Cc: jasowang, eperezma, kvm, virtualization, netdev, linux-kernel,
Simon Horman
On Wed, Sep 10, 2025 at 05:17:38PM +0800, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
>
> The return value of copy_from_iter and copy_to_iter can't be negative,
> check whether the copied lengths are equal.
>
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
Given copy_to_iter was fixed on net, how about applying
this one on net, too?
> ---
> drivers/vhost/vringh.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
> index 9f27c3f6091b..0c8a17cbb22e 100644
> --- a/drivers/vhost/vringh.c
> +++ b/drivers/vhost/vringh.c
> @@ -1115,6 +1115,7 @@ static inline int copy_from_iotlb(const struct vringh *vrh, void *dst,
> struct iov_iter iter;
> u64 translated;
> int ret;
> + size_t size;
>
> ret = iotlb_translate(vrh, (u64)(uintptr_t)src,
> len - total_translated, &translated,
> @@ -1132,9 +1133,9 @@ static inline int copy_from_iotlb(const struct vringh *vrh, void *dst,
> translated);
> }
>
> - ret = copy_from_iter(dst, translated, &iter);
> - if (ret < 0)
> - return ret;
> + size = copy_from_iter(dst, translated, &iter);
> + if (size != translated)
> + return -EFAULT;
>
> src += translated;
> dst += translated;
> --
> 2.33.0
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-09-27 20:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-10 9:17 [PATCH] vhost: vringh: Modify the return value check zhangjiao2
2025-09-15 10:59 ` Lei Yang
2025-09-21 20:59 ` Michael S. Tsirkin
2025-09-21 21:41 ` Michael S. Tsirkin
2025-09-27 20:36 ` 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;
as well as URLs for NNTP newsgroup(s).