回复: [PATCH -next 2/5] bpf: Remove map_push_elem callbacks with -EOPNOTSUPP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
Although when the BPF program invokes the bpf_map_peek_elem helper, the verifier intercepts it and ensures that this helper is only available for specific map types through check_map_func_compatibility(), there is no such verifier interception when this function is called from the syscall side.

Therefore, it is necessary to include appropriate checks in the syscall implementation to handle cases where map->ops->map_peek_elem may not be supported by certain map types. Without these checks, calling bpf_map_peek_elem through syscalls could lead to undefined behavior or errors if the map does not support this operation.

-----邮件原件-----
发件人: Hou Tao <houtao@xxxxxxxxxxxxxxx> 
发送时间: 2025年2月17日 10:28
收件人: zhangxiaomeng (A) <zhangxiaomeng13@xxxxxxxxxx>; bpf@xxxxxxxxxxxxxxx
抄送: Alexei Starovoitov <ast@xxxxxxxxxx>; Daniel Borkmann <daniel@xxxxxxxxxxxxx>; Andrii Nakryiko <andrii@xxxxxxxxxx>; Martin KaFai Lau <martin.lau@xxxxxxxxx>; Eduard Zingerman <eddyz87@xxxxxxxxx>; Song Liu <song@xxxxxxxxxx>; Yonghong Song <yonghong.song@xxxxxxxxx>; John Fastabend <john.fastabend@xxxxxxxxx>; KP Singh <kpsingh@xxxxxxxxxx>; Stanislav Fomichev <sdf@xxxxxxxxxxx>; Hao Luo <haoluo@xxxxxxxxxx>; Jiri Olsa <jolsa@xxxxxxxxxx>
主题: Re: [PATCH -next 2/5] bpf: Remove map_push_elem callbacks with -EOPNOTSUPP



On 2/17/2025 9:41 AM, Xiaomeng Zhang wrote:
> Remove redundant map_push_elem callbacks with return -EOPNOTSUPP. We 
> can directly return -EOPNOTSUPP when calling the unimplemented callbacks.
>
>
>  BPF_CALL_3(bpf_map_push_elem, struct bpf_map *, map, void *, value, 
> u64, flags)  {
> -	return map->ops->map_push_elem(map, value, flags);
> +	if (map->ops->map_push_elem)
> +		return map->ops->map_push_elem(map, value, flags);
> +	else
> +		return -EOPNOTSUPP;
>  }

Similar with the previous patch, the modifications in both
bpf_map_push_elem() and bpf_map_update_valu() are unnecessary.
>  
>  const struct bpf_func_proto bpf_map_push_elem_proto = { diff --git 
> a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 
> e6e859f71c5d..79a118ea9270 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -281,7 +281,10 @@ static int bpf_map_update_value(struct bpf_map *map, struct file *map_file,
>  	} else if (map->map_type == BPF_MAP_TYPE_QUEUE ||
>  		   map->map_type == BPF_MAP_TYPE_STACK ||
>  		   map->map_type == BPF_MAP_TYPE_BLOOM_FILTER) {
> -		err = map->ops->map_push_elem(map, value, flags);
> +		if (map->ops->map_push_elem)
> +			err = map->ops->map_push_elem(map, value, flags);
> +		else
> +			err = -EOPNOTSUPP;
>  	} else {
>  		err = bpf_obj_pin_uptrs(map->record, value);
>  		if (!err) {





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux