mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
bpf: Drop redundant BTF pointer helper write rejection
check_reg_type() rejects a trusted PTR_TO_BTF_ID admitted by
mem_types unless the argument carries MEM_RDONLY. This duplicates
argument-specific memory access validation and is too conservative for
map keys and input map values, whose read direction is not represented
by MEM_RDONLY.
Since commit fa75b7c85b ("bpf: Enforce write checks for BTF pointer
helper access"), check_helper_mem_access() forwards the requested access
type to check_ptr_to_btf_access(). Map keys always request read access.
Map values request write access only when tagged with MEM_WRITE.
ARG_PTR_TO_MEM prototypes must carry either MEM_RDONLY or MEM_WRITE,
and size arguments use the direction of their associated memory
argument. check_ptr_to_btf_access() therefore checks the effective access
direction in every case.
Drop the early rejection and keep check_reg_type() limited to register
admission.
Signed-off-by: Amery Hung <ameryhung@gmail.com>
Link: https://lore.kernel.org/r/20260911220415.1396439-17-ameryhung@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
750f377080
commit
a583d56e8d
|
|
@ -8515,16 +8515,8 @@ static int check_reg_type(struct bpf_verifier_env *env, struct bpf_reg_state *re
|
|||
if (base_type(reg->type) != PTR_TO_BTF_ID)
|
||||
return 0;
|
||||
|
||||
if (compatible == &mem_types) {
|
||||
if (!(arg_type & MEM_RDONLY)) {
|
||||
verbose(env,
|
||||
"%s() may write into memory pointed by %s type=%s\n",
|
||||
meta->func_name,
|
||||
reg_arg_name(env, argno), reg_type_str(env, reg->type));
|
||||
return -EACCES;
|
||||
}
|
||||
if (compatible == &mem_types)
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch ((int)reg->type) {
|
||||
case PTR_TO_BTF_ID:
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ int BPF_PROG(task_access_comm2, struct task_struct *task, u64 clone_flags)
|
|||
}
|
||||
|
||||
SEC("tp_btf/task_newtask")
|
||||
__failure __msg("write into memory")
|
||||
__failure __msg("only read is supported")
|
||||
int BPF_PROG(task_access_comm3, struct task_struct *task, u64 clone_flags)
|
||||
{
|
||||
bpf_probe_read_kernel(task->comm, 16, task->comm);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user