mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-07 19:30:30 +09:00
libnvdimm/pmem: fix a possible OOB access when read and write pmem
[ Upstream commit9dc6488e84] If offset is not zero and length is bigger than PAGE_SIZE, this will cause to out of boundary access to a page memory Fixes:98cc093cba("block, THP: make block_device_operations.rw_page support THP") Co-developed-by: Liang ZhiCheng <liangzhicheng@baidu.com> Signed-off-by: Liang ZhiCheng <liangzhicheng@baidu.com> Signed-off-by: Li RongQing <lirongqing@baidu.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Jeff Moyer <jmoyer@redhat.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
f2565d0e52
commit
4c8c9d5149
@@ -113,13 +113,13 @@ static void write_pmem(void *pmem_addr, struct page *page,
|
||||
|
||||
while (len) {
|
||||
mem = kmap_atomic(page);
|
||||
chunk = min_t(unsigned int, len, PAGE_SIZE);
|
||||
chunk = min_t(unsigned int, len, PAGE_SIZE - off);
|
||||
memcpy_flushcache(pmem_addr, mem + off, chunk);
|
||||
kunmap_atomic(mem);
|
||||
len -= chunk;
|
||||
off = 0;
|
||||
page++;
|
||||
pmem_addr += PAGE_SIZE;
|
||||
pmem_addr += chunk;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ static blk_status_t read_pmem(struct page *page, unsigned int off,
|
||||
|
||||
while (len) {
|
||||
mem = kmap_atomic(page);
|
||||
chunk = min_t(unsigned int, len, PAGE_SIZE);
|
||||
chunk = min_t(unsigned int, len, PAGE_SIZE - off);
|
||||
rem = memcpy_mcsafe(mem + off, pmem_addr, chunk);
|
||||
kunmap_atomic(mem);
|
||||
if (rem)
|
||||
@@ -140,7 +140,7 @@ static blk_status_t read_pmem(struct page *page, unsigned int off,
|
||||
len -= chunk;
|
||||
off = 0;
|
||||
page++;
|
||||
pmem_addr += PAGE_SIZE;
|
||||
pmem_addr += chunk;
|
||||
}
|
||||
return BLK_STS_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user