bpf: Protect probed address based on kptr_restrict setting

The probed address can be accessed by userspace through querying the task
file descriptor (fd). However, it is crucial to adhere to the kptr_restrict
setting and refrain from exposing the address if it is not permitted.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20230709025630.3735-5-laoar.shao@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Yafang Shao 2023-07-09 02:56:24 +00:00 committed by Alexei Starovoitov
parent edd7f49bb8
commit f1a414537e
1 changed files with 4 additions and 1 deletions

View File

@ -1551,7 +1551,10 @@ int bpf_get_kprobe_info(const struct perf_event *event, u32 *fd_type,
} else {
*symbol = NULL;
*probe_offset = 0;
*probe_addr = (unsigned long)tk->rp.kp.addr;
if (kallsyms_show_value(current_cred()))
*probe_addr = (unsigned long)tk->rp.kp.addr;
else
*probe_addr = 0;
}
return 0;
}