Skip to content

Commit c6e8e36

Browse files
xp4ns3kees
authored andcommitted
exec: Call kmap_local_page() in copy_string_kernel()
The use of kmap_atomic() is being deprecated in favor of kmap_local_page(). With kmap_local_page(), the mappings are per thread, CPU local and not globally visible. Furthermore, the mappings can be acquired from any context (including interrupts). Therefore, replace kmap_atomic() with kmap_local_page() in copy_string_kernel(). Instead of open-coding local mapping + memcpy(), use memcpy_to_page(). Delete a redundant call to flush_dcache_page(). Tested with xfstests on a QEMU/ KVM x86_32 VM, 6GB RAM, booting a kernel with HIGHMEM64GB enabled. Suggested-by: Ira Weiny <[email protected]> Signed-off-by: Fabio M. De Francesco <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5036793 commit c6e8e36

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

fs/exec.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@ int copy_string_kernel(const char *arg, struct linux_binprm *bprm)
631631
unsigned int bytes_to_copy = min_t(unsigned int, len,
632632
min_not_zero(offset_in_page(pos), PAGE_SIZE));
633633
struct page *page;
634-
char *kaddr;
635634

636635
pos -= bytes_to_copy;
637636
arg -= bytes_to_copy;
@@ -640,11 +639,8 @@ int copy_string_kernel(const char *arg, struct linux_binprm *bprm)
640639
page = get_arg_page(bprm, pos, 1);
641640
if (!page)
642641
return -E2BIG;
643-
kaddr = kmap_atomic(page);
644642
flush_arg_page(bprm, pos & PAGE_MASK, page);
645-
memcpy(kaddr + offset_in_page(pos), arg, bytes_to_copy);
646-
flush_dcache_page(page);
647-
kunmap_atomic(kaddr);
643+
memcpy_to_page(page, offset_in_page(pos), arg, bytes_to_copy);
648644
put_arg_page(page);
649645
}
650646

0 commit comments

Comments
 (0)