mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-07 15:18:15 +00:00
bpf: factor out a bpf_trace_copy_string helper
Split out a helper to do the fault free access to the string pointer to get it out of a crazy indentation level. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20200521152301.2587579-12-hch@lst.de Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
eab0c6089b
commit
d7b2977b81
1 changed files with 24 additions and 18 deletions
|
@ -324,6 +324,28 @@ static const struct bpf_func_proto *bpf_get_probe_write_proto(void)
|
||||||
return &bpf_probe_write_user_proto;
|
return &bpf_probe_write_user_proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bpf_trace_copy_string(char *buf, void *unsafe_ptr, char fmt_ptype,
|
||||||
|
size_t bufsz)
|
||||||
|
{
|
||||||
|
void __user *user_ptr = (__force void __user *)unsafe_ptr;
|
||||||
|
|
||||||
|
buf[0] = 0;
|
||||||
|
|
||||||
|
switch (fmt_ptype) {
|
||||||
|
case 's':
|
||||||
|
#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
|
||||||
|
strncpy_from_unsafe(buf, unsafe_ptr, bufsz);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
case 'k':
|
||||||
|
strncpy_from_kernel_nofault(buf, unsafe_ptr, bufsz);
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
strncpy_from_user_nofault(buf, user_ptr, bufsz);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Only limited trace_printk() conversion specifiers allowed:
|
* Only limited trace_printk() conversion specifiers allowed:
|
||||||
* %d %i %u %x %ld %li %lu %lx %lld %lli %llu %llx %p %pks %pus %s
|
* %d %i %u %x %ld %li %lu %lx %lld %lli %llu %llx %p %pks %pus %s
|
||||||
|
@ -406,24 +428,8 @@ fmt_str:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[0] = 0;
|
bpf_trace_copy_string(buf, unsafe_ptr, fmt_ptype,
|
||||||
switch (fmt_ptype) {
|
|
||||||
case 's':
|
|
||||||
#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
|
|
||||||
strncpy_from_unsafe(buf, unsafe_ptr,
|
|
||||||
sizeof(buf));
|
sizeof(buf));
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
case 'k':
|
|
||||||
strncpy_from_kernel_nofault(buf, unsafe_ptr,
|
|
||||||
sizeof(buf));
|
|
||||||
break;
|
|
||||||
case 'u':
|
|
||||||
strncpy_from_user_nofault(buf,
|
|
||||||
(__force void __user *)unsafe_ptr,
|
|
||||||
sizeof(buf));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
goto fmt_next;
|
goto fmt_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue