All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vhost: return EINVAL if iovecs size does not match the message size
@ 2018-12-13 14:53 Pavel Tikhomirov
  2018-12-13 19:55 ` Michael S. Tsirkin
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Pavel Tikhomirov @ 2018-12-13 14:53 UTC (permalink / raw)
  To: Michael S . Tsirkin
  Cc: Jason Wang, kvm, virtualization, netdev, linux-kernel,
	Konstantin Khorenko, Pavel Tikhomirov

We've failed to copy and process vhost_iotlb_msg so let userspace at
least know about it. For instance before these patch the code below runs
without any error:

int main()
{
  struct vhost_msg msg;
  struct iovec iov;
  int fd;

  fd = open("/dev/vhost-net", O_RDWR);
  if (fd == -1) {
    perror("open");
    return 1;
  }

  iov.iov_base = &msg;
  iov.iov_len = sizeof(msg)-4;

  if (writev(fd, &iov,1) == -1) {
    perror("writev");
    return 1;
  }

  return 0;
}

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
 drivers/vhost/vhost.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 3a5f81a66d34..03014224ef13 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1024,8 +1024,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
 	int type, ret;
 
 	ret = copy_from_iter(&type, sizeof(type), from);
-	if (ret != sizeof(type))
+	if (ret != sizeof(type)) {
+		ret = -EINVAL;
 		goto done;
+	}
 
 	switch (type) {
 	case VHOST_IOTLB_MSG:
@@ -1044,8 +1046,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
 
 	iov_iter_advance(from, offset);
 	ret = copy_from_iter(&msg, sizeof(msg), from);
-	if (ret != sizeof(msg))
+	if (ret != sizeof(msg)) {
+		ret = -EINVAL;
 		goto done;
+	}
 	if (vhost_process_iotlb_msg(dev, &msg)) {
 		ret = -EFAULT;
 		goto done;
-- 
2.17.1


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

* Re: [PATCH] vhost: return EINVAL if iovecs size does not match the message size
  2018-12-13 14:53 [PATCH] vhost: return EINVAL if iovecs size does not match the message size Pavel Tikhomirov
@ 2018-12-13 19:55 ` Michael S. Tsirkin
  2018-12-14  7:48     ` Pavel Tikhomirov
  2018-12-13 19:55 ` Michael S. Tsirkin
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Michael S. Tsirkin @ 2018-12-13 19:55 UTC (permalink / raw)
  To: Pavel Tikhomirov
  Cc: Jason Wang, kvm, virtualization, netdev, linux-kernel,
	Konstantin Khorenko

On Thu, Dec 13, 2018 at 05:53:50PM +0300, Pavel Tikhomirov wrote:
> We've failed to copy and process vhost_iotlb_msg so let userspace at
> least know about it. For instance before these patch the code below runs
> without any error:
> 
> int main()
> {
>   struct vhost_msg msg;
>   struct iovec iov;
>   int fd;
> 
>   fd = open("/dev/vhost-net", O_RDWR);
>   if (fd == -1) {
>     perror("open");
>     return 1;
>   }
> 
>   iov.iov_base = &msg;
>   iov.iov_len = sizeof(msg)-4;
> 
>   if (writev(fd, &iov,1) == -1) {
>     perror("writev");
>     return 1;
>   }
> 
>   return 0;
> }
> 
> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

Thanks for the patch!

> ---
>  drivers/vhost/vhost.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 3a5f81a66d34..03014224ef13 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -1024,8 +1024,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
>  	int type, ret;
>  
>  	ret = copy_from_iter(&type, sizeof(type), from);
> -	if (ret != sizeof(type))
> +	if (ret != sizeof(type)) {
> +		ret = -EINVAL;
>  		goto done;
> +	}
>  
>  	switch (type) {
>  	case VHOST_IOTLB_MSG:

should this be EFAULT rather?

> @@ -1044,8 +1046,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
>  
>  	iov_iter_advance(from, offset);
>  	ret = copy_from_iter(&msg, sizeof(msg), from);
> -	if (ret != sizeof(msg))
> +	if (ret != sizeof(msg)) {
> +		ret = -EINVAL;
>  		goto done;
> +	}
>  	if (vhost_process_iotlb_msg(dev, &msg)) {
>  		ret = -EFAULT;
>  		goto done;

This too?

> -- 
> 2.17.1

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

* Re: [PATCH] vhost: return EINVAL if iovecs size does not match the message size
  2018-12-13 14:53 [PATCH] vhost: return EINVAL if iovecs size does not match the message size Pavel Tikhomirov
  2018-12-13 19:55 ` Michael S. Tsirkin
@ 2018-12-13 19:55 ` Michael S. Tsirkin
  2018-12-15 19:46 ` David Miller
  2018-12-15 19:46 ` David Miller
  3 siblings, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2018-12-13 19:55 UTC (permalink / raw)
  To: Pavel Tikhomirov
  Cc: kvm, netdev, linux-kernel, virtualization, Konstantin Khorenko

On Thu, Dec 13, 2018 at 05:53:50PM +0300, Pavel Tikhomirov wrote:
> We've failed to copy and process vhost_iotlb_msg so let userspace at
> least know about it. For instance before these patch the code below runs
> without any error:
> 
> int main()
> {
>   struct vhost_msg msg;
>   struct iovec iov;
>   int fd;
> 
>   fd = open("/dev/vhost-net", O_RDWR);
>   if (fd == -1) {
>     perror("open");
>     return 1;
>   }
> 
>   iov.iov_base = &msg;
>   iov.iov_len = sizeof(msg)-4;
> 
>   if (writev(fd, &iov,1) == -1) {
>     perror("writev");
>     return 1;
>   }
> 
>   return 0;
> }
> 
> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

Thanks for the patch!

> ---
>  drivers/vhost/vhost.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 3a5f81a66d34..03014224ef13 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -1024,8 +1024,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
>  	int type, ret;
>  
>  	ret = copy_from_iter(&type, sizeof(type), from);
> -	if (ret != sizeof(type))
> +	if (ret != sizeof(type)) {
> +		ret = -EINVAL;
>  		goto done;
> +	}
>  
>  	switch (type) {
>  	case VHOST_IOTLB_MSG:

should this be EFAULT rather?

> @@ -1044,8 +1046,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
>  
>  	iov_iter_advance(from, offset);
>  	ret = copy_from_iter(&msg, sizeof(msg), from);
> -	if (ret != sizeof(msg))
> +	if (ret != sizeof(msg)) {
> +		ret = -EINVAL;
>  		goto done;
> +	}
>  	if (vhost_process_iotlb_msg(dev, &msg)) {
>  		ret = -EFAULT;
>  		goto done;

This too?

> -- 
> 2.17.1

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

* Re: [PATCH] vhost: return EINVAL if iovecs size does not match the message size
  2018-12-13 19:55 ` Michael S. Tsirkin
@ 2018-12-14  7:48     ` Pavel Tikhomirov
  0 siblings, 0 replies; 9+ messages in thread
From: Pavel Tikhomirov @ 2018-12-14  7:48 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Jason Wang, kvm, virtualization, netdev, linux-kernel,
	Konstantin Khorenko

On 12/13/2018 10:55 PM, Michael S. Tsirkin wrote:
> On Thu, Dec 13, 2018 at 05:53:50PM +0300, Pavel Tikhomirov wrote:
>> We've failed to copy and process vhost_iotlb_msg so let userspace at
>> least know about it. For instance before these patch the code below runs
>> without any error:
>>
>> int main()
>> {
>>    struct vhost_msg msg;
>>    struct iovec iov;
>>    int fd;
>>
>>    fd = open("/dev/vhost-net", O_RDWR);
>>    if (fd == -1) {
>>      perror("open");
>>      return 1;
>>    }
>>
>>    iov.iov_base = &msg;
>>    iov.iov_len = sizeof(msg)-4;
>>
>>    if (writev(fd, &iov,1) == -1) {
>>      perror("writev");
>>      return 1;
>>    }
>>
>>    return 0;
>> }
>>
>> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
> 
> Thanks for the patch!
> 
>> ---
>>   drivers/vhost/vhost.c | 8 ++++++--
>>   1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
>> index 3a5f81a66d34..03014224ef13 100644
>> --- a/drivers/vhost/vhost.c
>> +++ b/drivers/vhost/vhost.c
>> @@ -1024,8 +1024,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
>>   	int type, ret;
>>   
>>   	ret = copy_from_iter(&type, sizeof(type), from);
>> -	if (ret != sizeof(type))
>> +	if (ret != sizeof(type)) {
>> +		ret = -EINVAL;
>>   		goto done;
>> +	}
>>   
>>   	switch (type) {
>>   	case VHOST_IOTLB_MSG:
> 
> should this be EFAULT rather?

We already have "Invalid argument" returned when wrong type of vhost_msg 
received, I though it would be fine to return same thing if we have 
wrong size of vhost_msg.

When we return "Bad address" because of vhost_process_iotlb_msg fail, it 
is because our vhost_dev has no ->iotlb so our problem is not connected 
to the data passed from userspace but with the state of vhost_dev.

So I like EINVAL more in these two cases.

> 
>> @@ -1044,8 +1046,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
>>   
>>   	iov_iter_advance(from, offset);
>>   	ret = copy_from_iter(&msg, sizeof(msg), from);
>> -	if (ret != sizeof(msg))
>> +	if (ret != sizeof(msg)) {
>> +		ret = -EINVAL;
>>   		goto done;
>> +	}
>>   	if (vhost_process_iotlb_msg(dev, &msg)) {
>>   		ret = -EFAULT;
>>   		goto done;
> 
> This too?
> 
>> -- 
>> 2.17.1

-- 
Best regards, Tikhomirov Pavel
Software Developer, Virtuozzo.

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

* Re: [PATCH] vhost: return EINVAL if iovecs size does not match the message size
@ 2018-12-14  7:48     ` Pavel Tikhomirov
  0 siblings, 0 replies; 9+ messages in thread
From: Pavel Tikhomirov @ 2018-12-14  7:48 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Jason Wang, kvm, virtualization, netdev, linux-kernel,
	Konstantin Khorenko

On 12/13/2018 10:55 PM, Michael S. Tsirkin wrote:
> On Thu, Dec 13, 2018 at 05:53:50PM +0300, Pavel Tikhomirov wrote:
>> We've failed to copy and process vhost_iotlb_msg so let userspace at
>> least know about it. For instance before these patch the code below runs
>> without any error:
>>
>> int main()
>> {
>>    struct vhost_msg msg;
>>    struct iovec iov;
>>    int fd;
>>
>>    fd = open("/dev/vhost-net", O_RDWR);
>>    if (fd == -1) {
>>      perror("open");
>>      return 1;
>>    }
>>
>>    iov.iov_base = &msg;
>>    iov.iov_len = sizeof(msg)-4;
>>
>>    if (writev(fd, &iov,1) == -1) {
>>      perror("writev");
>>      return 1;
>>    }
>>
>>    return 0;
>> }
>>
>> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
> 
> Thanks for the patch!
> 
>> ---
>>   drivers/vhost/vhost.c | 8 ++++++--
>>   1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
>> index 3a5f81a66d34..03014224ef13 100644
>> --- a/drivers/vhost/vhost.c
>> +++ b/drivers/vhost/vhost.c
>> @@ -1024,8 +1024,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
>>   	int type, ret;
>>   
>>   	ret = copy_from_iter(&type, sizeof(type), from);
>> -	if (ret != sizeof(type))
>> +	if (ret != sizeof(type)) {
>> +		ret = -EINVAL;
>>   		goto done;
>> +	}
>>   
>>   	switch (type) {
>>   	case VHOST_IOTLB_MSG:
> 
> should this be EFAULT rather?

We already have "Invalid argument" returned when wrong type of vhost_msg 
received, I though it would be fine to return same thing if we have 
wrong size of vhost_msg.

When we return "Bad address" because of vhost_process_iotlb_msg fail, it 
is because our vhost_dev has no ->iotlb so our problem is not connected 
to the data passed from userspace but with the state of vhost_dev.

So I like EINVAL more in these two cases.

> 
>> @@ -1044,8 +1046,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
>>   
>>   	iov_iter_advance(from, offset);
>>   	ret = copy_from_iter(&msg, sizeof(msg), from);
>> -	if (ret != sizeof(msg))
>> +	if (ret != sizeof(msg)) {
>> +		ret = -EINVAL;
>>   		goto done;
>> +	}
>>   	if (vhost_process_iotlb_msg(dev, &msg)) {
>>   		ret = -EFAULT;
>>   		goto done;
> 
> This too?
> 
>> -- 
>> 2.17.1

-- 
Best regards, Tikhomirov Pavel
Software Developer, Virtuozzo.

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

* Re: [PATCH] vhost: return EINVAL if iovecs size does not match the message size
  2018-12-13 14:53 [PATCH] vhost: return EINVAL if iovecs size does not match the message size Pavel Tikhomirov
  2018-12-13 19:55 ` Michael S. Tsirkin
  2018-12-13 19:55 ` Michael S. Tsirkin
@ 2018-12-15 19:46 ` David Miller
  2018-12-16 19:41   ` Michael S. Tsirkin
  2018-12-16 19:41   ` Michael S. Tsirkin
  2018-12-15 19:46 ` David Miller
  3 siblings, 2 replies; 9+ messages in thread
From: David Miller @ 2018-12-15 19:46 UTC (permalink / raw)
  To: ptikhomirov
  Cc: mst, jasowang, kvm, virtualization, netdev, linux-kernel, khorenko

From: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Date: Thu, 13 Dec 2018 17:53:50 +0300

> We've failed to copy and process vhost_iotlb_msg so let userspace at
> least know about it. For instance before these patch the code below runs
> without any error:
 ...
> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

Michael, will you be taking this in via your tree?

Thanks.

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

* Re: [PATCH] vhost: return EINVAL if iovecs size does not match the message size
  2018-12-13 14:53 [PATCH] vhost: return EINVAL if iovecs size does not match the message size Pavel Tikhomirov
                   ` (2 preceding siblings ...)
  2018-12-15 19:46 ` David Miller
@ 2018-12-15 19:46 ` David Miller
  3 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2018-12-15 19:46 UTC (permalink / raw)
  To: ptikhomirov; +Cc: kvm, mst, netdev, linux-kernel, virtualization, khorenko

From: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Date: Thu, 13 Dec 2018 17:53:50 +0300

> We've failed to copy and process vhost_iotlb_msg so let userspace at
> least know about it. For instance before these patch the code below runs
> without any error:
 ...
> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

Michael, will you be taking this in via your tree?

Thanks.

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

* Re: [PATCH] vhost: return EINVAL if iovecs size does not match the message size
  2018-12-15 19:46 ` David Miller
@ 2018-12-16 19:41   ` Michael S. Tsirkin
  2018-12-16 19:41   ` Michael S. Tsirkin
  1 sibling, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2018-12-16 19:41 UTC (permalink / raw)
  To: David Miller
  Cc: ptikhomirov, jasowang, kvm, virtualization, netdev, linux-kernel,
	khorenko

On Sat, Dec 15, 2018 at 11:46:11AM -0800, David Miller wrote:
> From: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
> Date: Thu, 13 Dec 2018 17:53:50 +0300
> 
> > We've failed to copy and process vhost_iotlb_msg so let userspace at
> > least know about it. For instance before these patch the code below runs
> > without any error:
>  ...
> > Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
> 
> Michael, will you be taking this in via your tree?
> 
> Thanks.

Will do, thanks!


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

* Re: [PATCH] vhost: return EINVAL if iovecs size does not match the message size
  2018-12-15 19:46 ` David Miller
  2018-12-16 19:41   ` Michael S. Tsirkin
@ 2018-12-16 19:41   ` Michael S. Tsirkin
  1 sibling, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2018-12-16 19:41 UTC (permalink / raw)
  To: David Miller
  Cc: kvm, netdev, linux-kernel, virtualization, khorenko, ptikhomirov

On Sat, Dec 15, 2018 at 11:46:11AM -0800, David Miller wrote:
> From: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
> Date: Thu, 13 Dec 2018 17:53:50 +0300
> 
> > We've failed to copy and process vhost_iotlb_msg so let userspace at
> > least know about it. For instance before these patch the code below runs
> > without any error:
>  ...
> > Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
> 
> Michael, will you be taking this in via your tree?
> 
> Thanks.

Will do, thanks!

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

end of thread, other threads:[~2018-12-16 19:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-13 14:53 [PATCH] vhost: return EINVAL if iovecs size does not match the message size Pavel Tikhomirov
2018-12-13 19:55 ` Michael S. Tsirkin
2018-12-14  7:48   ` Pavel Tikhomirov
2018-12-14  7:48     ` Pavel Tikhomirov
2018-12-13 19:55 ` Michael S. Tsirkin
2018-12-15 19:46 ` David Miller
2018-12-16 19:41   ` Michael S. Tsirkin
2018-12-16 19:41   ` Michael S. Tsirkin
2018-12-15 19:46 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.