Skip to content

Commit 2f660a3

Browse files
committed
linuxkm/linuxkm_wc_port.h: in my_memmove(), early-return when n == 0 to avoid size_t underflow
The backward-copy branches compute (n - 1) as size_t, which wraps to SIZE_MAX for n == 0 and, with src below dest, drives the loop backward through kernel memory until it oopses; matches glibc / musl / kernel memmove(). Signed-off-by: Sameeh Jubran <sameeh@wolfssl.com>
1 parent 7ca42d1 commit 2f660a3

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

linuxkm/linuxkm_wc_port.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@
450450
#define memset my_memset
451451

452452
static inline void *my_memmove(void *dest, const void *src, size_t n) {
453+
if (n == 0)
454+
return dest;
453455
if (! (((uintptr_t)dest | (uintptr_t)src | (uintptr_t)n)
454456
& (uintptr_t)(sizeof(uintptr_t) - 1)))
455457
{

0 commit comments

Comments
 (0)