linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] drivers/vhost/vhost: fix overflow checks in vhost_overflow
@ 2022-12-07 13:46 Daniil Tatianin
  2022-12-07 15:01 ` Michael S. Tsirkin
  0 siblings, 1 reply; 3+ messages in thread
From: Daniil Tatianin @ 2022-12-07 13:46 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Daniil Tatianin, Jason Wang, kvm, virtualization, netdev, linux-kernel

The if statement would erroneously check for > ULONG_MAX, which could
never evaluate to true. Check for equality instead.

Found by Linux Verification Center (linuxtesting.org) with the SVACE
static analysis tool.

Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
---
 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 40097826cff0..8df706e7bc6c 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -730,7 +730,7 @@ static bool log_access_ok(void __user *log_base, u64 addr, unsigned long sz)
 /* Make sure 64 bit math will not overflow. */
 static bool vhost_overflow(u64 uaddr, u64 size)
 {
-	if (uaddr > ULONG_MAX || size > ULONG_MAX)
+	if (uaddr == ULONG_MAX || size == ULONG_MAX)
 		return true;
 
 	if (!size)
-- 
2.25.1


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

* Re: [PATCH v1] drivers/vhost/vhost: fix overflow checks in vhost_overflow
  2022-12-07 13:46 [PATCH v1] drivers/vhost/vhost: fix overflow checks in vhost_overflow Daniil Tatianin
@ 2022-12-07 15:01 ` Michael S. Tsirkin
  2022-12-08  7:21   ` Daniil Tatianin
  0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Tsirkin @ 2022-12-07 15:01 UTC (permalink / raw)
  To: Daniil Tatianin; +Cc: Jason Wang, kvm, virtualization, netdev, linux-kernel

On Wed, Dec 07, 2022 at 04:46:31PM +0300, Daniil Tatianin wrote:
> The if statement would erroneously check for > ULONG_MAX, which could
> never evaluate to true. Check for equality instead.
> 
> Found by Linux Verification Center (linuxtesting.org) with the SVACE
> static analysis tool.
> 
> Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>

It can trigger on a 32 bit system. I'd also expect more analysis
of the code flow than "this can not trigger switch to a condition
that can" to accompany a patch.

> ---
>  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 40097826cff0..8df706e7bc6c 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -730,7 +730,7 @@ static bool log_access_ok(void __user *log_base, u64 addr, unsigned long sz)
>  /* Make sure 64 bit math will not overflow. */
>  static bool vhost_overflow(u64 uaddr, u64 size)
>  {
> -	if (uaddr > ULONG_MAX || size > ULONG_MAX)
> +	if (uaddr == ULONG_MAX || size == ULONG_MAX)
>  		return true;
>  
>  	if (!size)
> -- 
> 2.25.1


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

* Re: [PATCH v1] drivers/vhost/vhost: fix overflow checks in vhost_overflow
  2022-12-07 15:01 ` Michael S. Tsirkin
@ 2022-12-08  7:21   ` Daniil Tatianin
  0 siblings, 0 replies; 3+ messages in thread
From: Daniil Tatianin @ 2022-12-08  7:21 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Jason Wang, kvm, virtualization, netdev, linux-kernel

On 12/7/22 6:01 PM, Michael S. Tsirkin wrote:
> On Wed, Dec 07, 2022 at 04:46:31PM +0300, Daniil Tatianin wrote:
>> The if statement would erroneously check for > ULONG_MAX, which could
>> never evaluate to true. Check for equality instead.
>>
>> Found by Linux Verification Center (linuxtesting.org) with the SVACE
>> static analysis tool.
>>
>> Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
> 
> It can trigger on a 32 bit system. I'd also expect more analysis
> of the code flow than "this can not trigger switch to a condition
> that can" to accompany a patch.

Oops, my bad. It can trigger on 32 bit indeed. Sorry, completely 
overlooked that.

Thanks

>> ---
>>   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 40097826cff0..8df706e7bc6c 100644
>> --- a/drivers/vhost/vhost.c
>> +++ b/drivers/vhost/vhost.c
>> @@ -730,7 +730,7 @@ static bool log_access_ok(void __user *log_base, u64 addr, unsigned long sz)
>>   /* Make sure 64 bit math will not overflow. */
>>   static bool vhost_overflow(u64 uaddr, u64 size)
>>   {
>> -	if (uaddr > ULONG_MAX || size > ULONG_MAX)
>> +	if (uaddr == ULONG_MAX || size == ULONG_MAX)
>>   		return true;
>>   
>>   	if (!size)
>> -- 
>> 2.25.1
> 

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

end of thread, other threads:[~2022-12-08  7:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07 13:46 [PATCH v1] drivers/vhost/vhost: fix overflow checks in vhost_overflow Daniil Tatianin
2022-12-07 15:01 ` Michael S. Tsirkin
2022-12-08  7:21   ` Daniil Tatianin

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).