path: root/mm
diff options
authorIsaac J. Manjarres <>2019-08-13 15:37:37 -0700
committerLinus Torvalds <>2019-08-13 16:06:52 -0700
commit951531691c4bcaa59f56a316e018bc2ff1ddf855 (patch)
treea26a939586580ccb3c570a558a58f138c55c19af /mm
parentfcf3a5b62f431ce9feeac73afbe128b7b6395dbc (diff)
mm/usercopy: use memory range to be accessed for wraparound check
Currently, when checking to see if accessing n bytes starting at address "ptr" will cause a wraparound in the memory addresses, the check in check_bogus_address() adds an extra byte, which is incorrect, as the range of addresses that will be accessed is [ptr, ptr + (n - 1)]. This can lead to incorrectly detecting a wraparound in the memory address, when trying to read 4 KB from memory that is mapped to the the last possible page in the virtual address space, when in fact, accessing that range of memory would not cause a wraparound to occur. Use the memory range that will actually be accessed when considering if accessing a certain amount of bytes will cause the memory address to wrap around. Link: Fixes: f5509cc18daa ("mm: Hardened usercopy") Signed-off-by: Prasad Sodagudi <> Signed-off-by: Isaac J. Manjarres <> Co-developed-by: Prasad Sodagudi <> Reviewed-by: William Kucharski <> Acked-by: Kees Cook <> Cc: Greg Kroah-Hartman <> Cc: Trilok Soni <> Cc: <> Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <>
Diffstat (limited to 'mm')
1 files changed, 1 insertions, 1 deletions
diff --git a/mm/usercopy.c b/mm/usercopy.c
index 2a09796edef8..98e924864554 100644
--- a/mm/usercopy.c
+++ b/mm/usercopy.c
@@ -147,7 +147,7 @@ static inline void check_bogus_address(const unsigned long ptr, unsigned long n,
bool to_user)
/* Reject if object wraps past end of memory. */
- if (ptr + n < ptr)
+ if (ptr + (n - 1) < ptr)
usercopy_abort("wrapped address", NULL, to_user, 0, ptr + n);
/* Reject if NULL or ZERO-allocation. */