Re: [PATCH bpf-next v4 5/9] bpf: look into the types of the fields of a struct type recursively.

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

 



On Tue, 2024-05-07 at 23:32 -0700, Kui-Feng Lee wrote:
> The verifier has field information for specific special types, such as
> kptr, rbtree root, and list head. These types are handled
> differently. However, we did not previously examine the types of fields of
> a struct type variable. Field information records were not generated for
> the kptrs, rbtree roots, and linked_list heads that are not located at the
> outermost struct type of a variable.
> 
> For example,
> 
>   struct A {
>     struct task_struct __kptr * task;
>   };
> 
>   struct B {
>     struct A mem_a;
>   }
> 
>   struct B var_b;
> 
> It did not examine "struct A" so as not to generate field information for
> the kptr in "struct A" for "var_b".
> 
> This patch enables BPF programs to define fields of these special types in
> a struct type other than the direct type of a variable or in a struct type
> that is the type of a field in the value type of a map.
> 
> Signed-off-by: Kui-Feng Lee <thinker.li@xxxxxxxxx>
> ---

Acked-by: Eduard Zingerman <eddyz87@xxxxxxxxx>

[...]

> @@ -3555,6 +3597,17 @@ static int btf_find_field_one(const struct btf *btf,
>  
>  	field_type = btf_get_field_type(__btf_name_by_offset(btf, var_type->name_off),
>  					field_mask, seen_mask, &align, &sz);
> +	/* Look into variables of struct types */
> +	if ((field_type == BPF_KPTR_REF || !field_type) &&
> +	    __btf_type_is_struct(var_type)) {

Nit: this check looks a bit ugly, but I can't suggest a good
     refactoring for btf_get_field_type() at the moment.

> +		sz = var_type->size;
> +		if (expected_size && expected_size != sz * nelems)
> +			return 0;
> +		ret = btf_find_nested_struct(btf, var_type, off, nelems, field_mask,
> +					     &info[0], info_cnt);
> +		return ret;
> +	}
> +
>  	if (field_type == 0)
>  		return 0;
>  	if (field_type < 0)





[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