aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIra Weiny <[email protected]>2021-02-10 09:49:28 -0800
committerDavid Sterba <[email protected]>2021-02-11 19:56:15 +0100
commitca18f6ea012bf30236b76c3480ac2c97131b6f8f (patch)
treea5f9c09af903cb39b9245e03f0a96e863696580c
parent6a0996db6879cf09f989c5f44f9edd38240cb346 (diff)
mm/highmem: Add VM_BUG_ON() to mem*_page() calls
Add VM_BUG_ON bounds checks to ensure the newly lifted and created page memory operations do not result in corrupted data in neighbor pages.[1][2] [1] https://lore.kernel.org/lkml/[email protected]/ [2] https://lore.kernel.org/lkml/[email protected]/ Suggested-by: Matthew Wilcox <[email protected]> Suggested-by: Andrew Morton <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Ira Weiny <[email protected]> Signed-off-by: David Sterba <[email protected]>
-rw-r--r--include/linux/highmem.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 0b5d89621cb9..44170f312ae7 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -283,6 +283,7 @@ static inline void memcpy_page(struct page *dst_page, size_t dst_off,
char *dst = kmap_local_page(dst_page);
char *src = kmap_local_page(src_page);
+ VM_BUG_ON(dst_off + len > PAGE_SIZE || src_off + len > PAGE_SIZE);
memcpy(dst + dst_off, src + src_off, len);
kunmap_local(src);
kunmap_local(dst);
@@ -295,6 +296,7 @@ static inline void memmove_page(struct page *dst_page, size_t dst_off,
char *dst = kmap_local_page(dst_page);
char *src = kmap_local_page(src_page);
+ VM_BUG_ON(dst_off + len > PAGE_SIZE || src_off + len > PAGE_SIZE);
memmove(dst + dst_off, src + src_off, len);
kunmap_local(src);
kunmap_local(dst);
@@ -305,6 +307,7 @@ static inline void memset_page(struct page *page, size_t offset, int val,
{
char *addr = kmap_local_page(page);
+ VM_BUG_ON(offset + len > PAGE_SIZE);
memset(addr + offset, val, len);
kunmap_local(addr);
}
@@ -314,6 +317,7 @@ static inline void memcpy_from_page(char *to, struct page *page,
{
char *from = kmap_local_page(page);
+ VM_BUG_ON(offset + len > PAGE_SIZE);
memcpy(to, from + offset, len);
kunmap_local(from);
}
@@ -323,6 +327,7 @@ static inline void memcpy_to_page(struct page *page, size_t offset,
{
char *to = kmap_local_page(page);
+ VM_BUG_ON(offset + len > PAGE_SIZE);
memcpy(to + offset, from, len);
kunmap_local(to);
}