lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 14 Dec 2018 07:48:10 +0000
From:   Pavel Tikhomirov <ptikhomirov@...tuozzo.com>
To:     "Michael S. Tsirkin" <mst@...hat.com>
CC:     Jason Wang <jasowang@...hat.com>,
        "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
        "virtualization@...ts.linux-foundation.org" 
        <virtualization@...ts.linux-foundation.org>,
        "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        Konstantin Khorenko <khorenko@...tuozzo.com>
Subject: Re: [PATCH] vhost: return EINVAL if iovecs size does not match the
 message size

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@...tuozzo.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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ