Commit ca18f6ea authored by Ira Weiny's avatar Ira Weiny Committed by David Sterba

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/20201210053502.GS1563847@iweiny-DESK2.sc.intel.com/
[2] https://lore.kernel.org/lkml/20210209110931.00f00e47d9a0529fcee2ff01@linux-foundation.org/Suggested-by: default avatarMatthew Wilcox <willy@infradead.org>
Suggested-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarIra Weiny <ira.weiny@intel.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 6a0996db
...@@ -283,6 +283,7 @@ static inline void memcpy_page(struct page *dst_page, size_t dst_off, ...@@ -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 *dst = kmap_local_page(dst_page);
char *src = kmap_local_page(src_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); memcpy(dst + dst_off, src + src_off, len);
kunmap_local(src); kunmap_local(src);
kunmap_local(dst); kunmap_local(dst);
...@@ -295,6 +296,7 @@ static inline void memmove_page(struct page *dst_page, size_t dst_off, ...@@ -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 *dst = kmap_local_page(dst_page);
char *src = kmap_local_page(src_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); memmove(dst + dst_off, src + src_off, len);
kunmap_local(src); kunmap_local(src);
kunmap_local(dst); kunmap_local(dst);
...@@ -305,6 +307,7 @@ static inline void memset_page(struct page *page, size_t offset, int val, ...@@ -305,6 +307,7 @@ static inline void memset_page(struct page *page, size_t offset, int val,
{ {
char *addr = kmap_local_page(page); char *addr = kmap_local_page(page);
VM_BUG_ON(offset + len > PAGE_SIZE);
memset(addr + offset, val, len); memset(addr + offset, val, len);
kunmap_local(addr); kunmap_local(addr);
} }
...@@ -314,6 +317,7 @@ static inline void memcpy_from_page(char *to, struct page *page, ...@@ -314,6 +317,7 @@ static inline void memcpy_from_page(char *to, struct page *page,
{ {
char *from = kmap_local_page(page); char *from = kmap_local_page(page);
VM_BUG_ON(offset + len > PAGE_SIZE);
memcpy(to, from + offset, len); memcpy(to, from + offset, len);
kunmap_local(from); kunmap_local(from);
} }
...@@ -323,6 +327,7 @@ static inline void memcpy_to_page(struct page *page, size_t offset, ...@@ -323,6 +327,7 @@ static inline void memcpy_to_page(struct page *page, size_t offset,
{ {
char *to = kmap_local_page(page); char *to = kmap_local_page(page);
VM_BUG_ON(offset + len > PAGE_SIZE);
memcpy(to + offset, from, len); memcpy(to + offset, from, len);
kunmap_local(to); kunmap_local(to);
} }
......
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