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] [day] [month] [year] [list]
Date:   Fri, 29 Jun 2018 18:37:54 -0700
From:   Andrew Morton <akpm@...ux-foundation.org>
To:     Andrey Ryabinin <aryabinin@...tuozzo.com>
Cc:     icytxw@...il.com, Alexander Potapenko <glider@...gle.com>,
        Dmitry Vyukov <dvyukov@...gle.com>, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] mm/fadvise: Fix signed overflow UBSAN complaint

On Fri, 29 Jun 2018 21:44:53 +0300 Andrey Ryabinin <aryabinin@...tuozzo.com> wrote:

> Signed integer overflow is undefined according to the C standard.
> The overflow in ksys_fadvise64_64() is deliberate, but since it is signed
> overflow, UBSAN complains:
> 	UBSAN: Undefined behaviour in mm/fadvise.c:76:10
> 	signed integer overflow:
> 	4 + 9223372036854775805 cannot be represented in type 'long long int'
> 
> Use unsigned types to do math. Unsigned overflow is defined so UBSAN
> will not complain about it. This patch doesn't change generated code.
> 
> ...
>
> --- a/mm/fadvise.c
> +++ b/mm/fadvise.c
> @@ -73,7 +73,7 @@ int ksys_fadvise64_64(int fd, loff_t offset, loff_t len, int advice)
>  	}
>  
>  	/* Careful about overflows. Len == 0 means "as much as possible" */
> -	endbyte = offset + len;
> +	endbyte = (u64)offset + (u64)len;
>  	if (!len || endbyte < len)
>  		endbyte = -1;
>  	else

Readers of this code will wonder "what the heck are those casts for". 
Therefore:

--- a/mm/fadvise.c~mm-fadvise-fix-signed-overflow-ubsan-complaint-fix
+++ a/mm/fadvise.c
@@ -72,7 +72,11 @@ int ksys_fadvise64_64(int fd, loff_t off
 		goto out;
 	}
 
-	/* Careful about overflows. Len == 0 means "as much as possible" */
+	/*
+	 * Careful about overflows. Len == 0 means "as much as possible".  Use
+	 * unsigned math because signed overflows are undefined and UBSan
+	 * complains.
+	 */
 	endbyte = (u64)offset + (u64)len;
 	if (!len || endbyte < len)
 		endbyte = -1;
_

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ