Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 347e223

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
SUNRPC: Fix memory corruption issue on 32-bit highmem systems
Some architectures, such as ARM-32 do not return the same base address when you call kmap_atomic() twice on the same page. This causes problems for the memmove() call in the XDR helper routine "_shift_data_right_pages()", since it defeats the detection of overlapping memory ranges, and has been seen to corrupt memory. The fix is to distinguish between the case where we're doing an inter-page copy or not. In the former case of we know that the memory ranges cannot possibly overlap, so we can additionally micro-optimise by replacing memmove() with memcpy(). Reported-by: Mark Young <[email protected]> Reported-by: Matt Craighead <[email protected]> Cc: Bruce Fields <[email protected]> Cc: [email protected] Signed-off-by: Trond Myklebust <[email protected]> Tested-by: Matt Craighead <[email protected]>
1 parent fa8218d commit 347e223

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

net/sunrpc/xdr.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,13 @@ _shift_data_right_pages(struct page **pages, size_t pgto_base,
207207
pgfrom_base -= copy;
208208

209209
vto = kmap_atomic(*pgto);
210-
vfrom = kmap_atomic(*pgfrom);
211-
memmove(vto + pgto_base, vfrom + pgfrom_base, copy);
210+
if (*pgto != *pgfrom) {
211+
vfrom = kmap_atomic(*pgfrom);
212+
memcpy(vto + pgto_base, vfrom + pgfrom_base, copy);
213+
kunmap_atomic(vfrom);
214+
} else
215+
memmove(vto + pgto_base, vto + pgfrom_base, copy);
212216
flush_dcache_page(*pgto);
213-
kunmap_atomic(vfrom);
214217
kunmap_atomic(vto);
215218

216219
} while ((len -= copy) != 0);

0 commit comments

Comments
 (0)