]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mm/highmem: VM_BUG_ON() if offset + len > PAGE_SIZE
authorFabio M. De Francesco <fmdefrancesco@gmail.com>
Tue, 10 May 2022 01:20:51 +0000 (18:20 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 13 May 2022 14:20:06 +0000 (07:20 -0700)
Add VM_BUG_ON() bounds checking to make sure that, if "offset + len>
PAGE_SIZE", memset() does not corrupt data in adjacent pages.

Mainly to match all the similar functions in highmem.h.

Link: https://lkml.kernel.org/r/20220426193020.8710-1-fmdefrancesco@gmail.com
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Peter Collingbourne <pcc@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/highmem.h

index 39bb9b47fa9cd4c633366f2097d5239a4323871e..67720bfd6adea67027d527088c07237900d314cc 100644 (file)
@@ -358,6 +358,8 @@ static inline void memcpy_to_page(struct page *page, size_t offset,
 static inline void memzero_page(struct page *page, size_t offset, size_t len)
 {
        char *addr = kmap_local_page(page);
+
+       VM_BUG_ON(offset + len > PAGE_SIZE);
        memset(addr + offset, 0, len);
        flush_dcache_page(page);
        kunmap_local(addr);