2019-02-15 15:34:41

by Jason Wang

[permalink] [raw]
Subject: [PATCH net] vhost: correctly check the return value of translate_desc() in log_used()

When fail, translate_desc() returns negative value, otherwise the
number of iovs. So we should fail when the return value is negative
instead of a blindly check against zero.

Reported-by: Stephen Hemminger <[email protected]>
Fixes: cc5e71075947 ("vhost: log dirty page correctly")
Signed-off-by: Jason Wang <[email protected]>
---
drivers/vhost/vhost.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 24a129fcdd61..a2e5dc7716e2 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1788,7 +1788,7 @@ static int log_used(struct vhost_virtqueue *vq, u64 used_offset, u64 len)

ret = translate_desc(vq, (uintptr_t)vq->used + used_offset,
len, iov, 64, VHOST_ACCESS_WO);
- if (ret)
+ if (ret < 0)
return ret;

for (i = 0; i < ret; i++) {
--
2.17.1



2019-02-15 17:04:36

by Stephen Hemminger

[permalink] [raw]
Subject: Re: [PATCH net] vhost: correctly check the return value of translate_desc() in log_used()

On Fri, 15 Feb 2019 15:53:24 +0800
Jason Wang <[email protected]> wrote:

> When fail, translate_desc() returns negative value, otherwise the
> number of iovs. So we should fail when the return value is negative
> instead of a blindly check against zero.
>
> Reported-by: Stephen Hemminger <[email protected]>
> Fixes: cc5e71075947 ("vhost: log dirty page correctly")
> Signed-off-by: Jason Wang <[email protected]>

Looks good. It is best to put the Addresses-Coverity-Id tag on these kind
of bug fixes so that the automated tools see it.

2019-02-16 05:00:29

by David Miller

[permalink] [raw]
Subject: Re: [PATCH net] vhost: correctly check the return value of translate_desc() in log_used()

From: Jason Wang <[email protected]>
Date: Fri, 15 Feb 2019 15:53:24 +0800

> When fail, translate_desc() returns negative value, otherwise the
> number of iovs. So we should fail when the return value is negative
> instead of a blindly check against zero.
>
> Reported-by: Stephen Hemminger <[email protected]>
> Fixes: cc5e71075947 ("vhost: log dirty page correctly")
> Signed-off-by: Jason Wang <[email protected]>

Jason, please put the Fixes tag first.

Thank you.

2019-02-16 08:19:09

by Michael S. Tsirkin

[permalink] [raw]
Subject: Re: [PATCH net] vhost: correctly check the return value of translate_desc() in log_used()

On Fri, Feb 15, 2019 at 03:53:24PM +0800, Jason Wang wrote:
> When fail, translate_desc() returns negative value, otherwise the
> number of iovs. So we should fail when the return value is negative
> instead of a blindly check against zero.
>
> Reported-by: Stephen Hemminger <[email protected]>
> Fixes: cc5e71075947 ("vhost: log dirty page correctly")
> Signed-off-by: Jason Wang <[email protected]>

Acked-by: Michael S. Tsirkin <[email protected]>

and I guess the log was backported to stable so we want
this backported too.

> ---
> drivers/vhost/vhost.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 24a129fcdd61..a2e5dc7716e2 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -1788,7 +1788,7 @@ static int log_used(struct vhost_virtqueue *vq, u64 used_offset, u64 len)
>
> ret = translate_desc(vq, (uintptr_t)vq->used + used_offset,
> len, iov, 64, VHOST_ACCESS_WO);
> - if (ret)
> + if (ret < 0)
> return ret;
>
> for (i = 0; i < ret; i++) {
> --
> 2.17.1

2019-02-19 06:51:35

by Jason Wang

[permalink] [raw]
Subject: Re: [PATCH net] vhost: correctly check the return value of translate_desc() in log_used()


On 2019/2/16 上午2:03, David Miller wrote:
> From: Jason Wang<[email protected]>
> Date: Fri, 15 Feb 2019 15:53:24 +0800
>
>> When fail, translate_desc() returns negative value, otherwise the
>> number of iovs. So we should fail when the return value is negative
>> instead of a blindly check against zero.
>>
>> Reported-by: Stephen Hemminger<[email protected]>
>> Fixes: cc5e71075947 ("vhost: log dirty page correctly")
>> Signed-off-by: Jason Wang<[email protected]>
> Jason, please put the Fixes tag first.
>
> Thank you.


Ok. Will post V2.

Thanks


2019-02-19 06:53:55

by Jason Wang

[permalink] [raw]
Subject: Re: [PATCH net] vhost: correctly check the return value of translate_desc() in log_used()


On 2019/2/16 上午12:45, Stephen Hemminger wrote:
> On Fri, 15 Feb 2019 15:53:24 +0800
> Jason Wang <[email protected]> wrote:
>
>> When fail, translate_desc() returns negative value, otherwise the
>> number of iovs. So we should fail when the return value is negative
>> instead of a blindly check against zero.
>>
>> Reported-by: Stephen Hemminger <[email protected]>
>> Fixes: cc5e71075947 ("vhost: log dirty page correctly")
>> Signed-off-by: Jason Wang <[email protected]>
> Looks good. It is best to put the Addresses-Coverity-Id tag on these kind
> of bug fixes so that the automated tools see it.


Ok. Will do this in V2.

Thanks