* [PATCH v2] fs: Call kmap_local_page() in copy_string_kernel()
@ 2022-07-24 21:25 Fabio M. De Francesco
2022-07-27 21:13 ` Kees Cook
0 siblings, 1 reply; 2+ messages in thread
From: Fabio M. De Francesco @ 2022-07-24 21:25 UTC (permalink / raw)
To: Eric Biederman, Kees Cook, Alexander Viro, linux-mm,
linux-fsdevel, linux-kernel
Cc: Fabio M. De Francesco, Ira Weiny
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 <ira.weiny@intel.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
v1->v2: Instead of open-coding a local mapping + memcpy(), use
memcpy_to_page() (thanks to Ira Weiny for his comment on v1).
fs/exec.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/fs/exec.c b/fs/exec.c
index d20cb09476f3..eed899188333 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -630,7 +630,6 @@ int copy_string_kernel(const char *arg, struct linux_binprm *bprm)
unsigned int bytes_to_copy = min_t(unsigned int, len,
min_not_zero(offset_in_page(pos), PAGE_SIZE));
struct page *page;
- char *kaddr;
pos -= bytes_to_copy;
arg -= bytes_to_copy;
@@ -639,11 +638,8 @@ int copy_string_kernel(const char *arg, struct linux_binprm *bprm)
page = get_arg_page(bprm, pos, 1);
if (!page)
return -E2BIG;
- kaddr = kmap_atomic(page);
flush_arg_page(bprm, pos & PAGE_MASK, page);
- memcpy(kaddr + offset_in_page(pos), arg, bytes_to_copy);
- flush_dcache_page(page);
- kunmap_atomic(kaddr);
+ memcpy_to_page(page, offset_in_page(pos), arg, bytes_to_copy);
put_arg_page(page);
}
--
2.37.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] fs: Call kmap_local_page() in copy_string_kernel()
2022-07-24 21:25 [PATCH v2] fs: Call kmap_local_page() in copy_string_kernel() Fabio M. De Francesco
@ 2022-07-27 21:13 ` Kees Cook
0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2022-07-27 21:13 UTC (permalink / raw)
To: linux-mm, linux-kernel, linux-fsdevel, fmdefrancesco, ebiederm, Al Viro
Cc: Kees Cook, ira.weiny
On Sun, 24 Jul 2022 23:25:23 +0200, Fabio M. De Francesco wrote:
> 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().
>
> [...]
Applied to for-next/execve, thanks!
[1/1] fs: Call kmap_local_page() in copy_string_kernel()
https://git.kernel.org/kees/c/0ff95c390bc8
--
Kees Cook
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-07-27 21:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-24 21:25 [PATCH v2] fs: Call kmap_local_page() in copy_string_kernel() Fabio M. De Francesco
2022-07-27 21:13 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).