lkml.org 
[lkml]   [2020]   [May]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 13/20] maccess: always use strict semantics for probe_kernel_read
On Tue, May 19, 2020 at 6:45 AM Christoph Hellwig <hch@lst.de> wrote:
>
> +
> + if (IS_ENABLED(CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE) &&
> + compat && (unsigned long)unsafe_ptr < TASK_SIZE)
> + ret = probe_user_read(dst, user_ptr, size);
> + else
> + ret = probe_kernel_read(dst, unsafe_ptr, size);
...
> - ret = probe_kernel_read(&c, (u8 *)addr + len, 1);
> + if (IS_ENABLED(CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE) &&
> + (unsigned long)addr < TASK_SIZE) {
> + ret = probe_user_read(&c,
> + (__force u8 __user *)addr + len, 1);
> + } else {
> + ret = probe_kernel_read(&c, (u8 *)addr + len, 1);
> + }
...
> + if (IS_ENABLED(CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE) &&
> + (unsigned long)src < TASK_SIZE) {
> + return probe_user_read(dest, (__force const void __user *)src,
> + size);

If you can't make the conditional legible and fit on a single line and
make it obvious _why_ you have that conditional, just use a helper
function.

Either for just the conditional itself, or for the whole operation.
And at least for the bpf case, since you want the whole operation for
that error handling and clearing of the result buffer anyway, I
suspect it would be cleaner to have that kind of
"bpf_copy_legacy_nofault()" function or whatever.

(And see previous email why I dislike that "compat" naming in the bpf case)

Linus

\
 
 \ /
  Last update: 2020-05-19 18:34    [W:0.234 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site