Commit b9f9fc38 authored by Andrey Ryabinin's avatar Andrey Ryabinin Committed by Greg Kroah-Hartman

mm/fadvise.c: fix signed overflow UBSAN complaint

[ Upstream commit a718e28f ]

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.

[ add comment explaining the casts]
Link: default avatarAndrey Ryabinin <>
Reported-by: <>
Reviewed-by: default avatarAndrew Morton <>
Cc: Alexander Potapenko <>
Cc: Dmitry Vyukov <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
Signed-off-by: default avatarSasha Levin <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent dfb5ad65
......@@ -72,8 +72,12 @@ int ksys_fadvise64_64(int fd, loff_t offset, loff_t len, int advice)
goto out;
/* Careful about overflows. Len == 0 means "as much as possible" */
endbyte = offset + len;
* 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;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment