Skip to content

Commit 9dc6488

Browse files
lrq-maxdjbw
authored andcommitted
libnvdimm/pmem: fix a possible OOB access when read and write pmem
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: 98cc093 ("block, THP: make block_device_operations.rw_page support THP") Co-developed-by: Liang ZhiCheng <[email protected]> Signed-off-by: Liang ZhiCheng <[email protected]> Signed-off-by: Li RongQing <[email protected]> Reviewed-by: Ira Weiny <[email protected]> Reviewed-by: Jeff Moyer <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent d2e5b64 commit 9dc6488

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/nvdimm/pmem.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ static void write_pmem(void *pmem_addr, struct page *page,
113113

114114
while (len) {
115115
mem = kmap_atomic(page);
116-
chunk = min_t(unsigned int, len, PAGE_SIZE);
116+
chunk = min_t(unsigned int, len, PAGE_SIZE - off);
117117
memcpy_flushcache(pmem_addr, mem + off, chunk);
118118
kunmap_atomic(mem);
119119
len -= chunk;
120120
off = 0;
121121
page++;
122-
pmem_addr += PAGE_SIZE;
122+
pmem_addr += chunk;
123123
}
124124
}
125125

@@ -132,15 +132,15 @@ static blk_status_t read_pmem(struct page *page, unsigned int off,
132132

133133
while (len) {
134134
mem = kmap_atomic(page);
135-
chunk = min_t(unsigned int, len, PAGE_SIZE);
135+
chunk = min_t(unsigned int, len, PAGE_SIZE - off);
136136
rem = memcpy_mcsafe(mem + off, pmem_addr, chunk);
137137
kunmap_atomic(mem);
138138
if (rem)
139139
return BLK_STS_IOERR;
140140
len -= chunk;
141141
off = 0;
142142
page++;
143-
pmem_addr += PAGE_SIZE;
143+
pmem_addr += chunk;
144144
}
145145
return BLK_STS_OK;
146146
}

0 commit comments

Comments
 (0)