Readonly and readwrite buffer register states are introduced. Totally four states, PTR_TO_RDONLY_BUF[_OR_NULL] and PTR_TO_RDWR_BUF[_OR_NULL] are supported. As suggested by their respective names, PTR_TO_RDONLY_BUF[_OR_NULL] are for readonly buffers and PTR_TO_RDWR_BUF[_OR_NULL] for read/write buffers. These new register states will be used by later bpf map element iterator. New register states share some similarity to PTR_TO_TP_BUFFER as it will calculate accessed buffer size during verification time. The accessed buffer size will be later compared to other metrics during later attach/link_create time. Similar to reg_state PTR_TO_BTF_ID_OR_NULL in bpf iterator programs, PTR_TO_RDONLY_BUF_OR_NULL or PTR_TO_RDWR_BUF_OR_NULL reg_types can be set at prog->aux->bpf_ctx_arg_aux, and bpf verifier will retrieve the values during btf_ctx_access(). Later bpf map element iterator implementation will show how such information will be assigned during target registeration time. The verifier is also enhanced such that PTR_TO_RDONLY_BUF can be passed to ARG_PTR_TO_MEM[_OR_NULL] helper argument, and PTR_TO_RDWR_BUF can be passed to ARG_PTR_TO_MEM[_OR_NULL] or ARG_PTR_TO_UNINIT_MEM.
Showing the changes to include/linux (1 of 3 files). Show all
Unified · Split
| @@ -353,6 +353,10 @@ enum bpf_reg_type { · 352 unmodified lines | ||
| 353 | 353 | PTR_TO_BTF_ID_OR_NULL, /* reg points to kernel struct or NULL */ |
| 354 | 354 | PTR_TO_MEM, /* reg points to valid memory region */ |
| 355 | 355 | PTR_TO_MEM_OR_NULL, /* reg points to valid memory region or NULL */ |
| 356 | + PTR_TO_RDONLY_BUF, /* reg points to a readonly buffer */ | |
| 357 | + PTR_TO_RDONLY_BUF_OR_NULL, /* reg points to a readonly buffer or NULL */ | |
| 358 | + PTR_TO_RDWR_BUF, /* reg points to a read/write buffer */ | |
| 359 | + PTR_TO_RDWR_BUF_OR_NULL, /* reg points to a read/write buffer or NULL */ | |
| 356 | 360 | }; |
| 357 | 361 | |
| 358 | 362 | /* The information passed from prog-specific *_is_valid_access |
| @@ -694,6 +698,8 @@ struct bpf_prog_aux { · 335 unmodified lines | ||
| 694 | 698 | u32 func_idx; /* 0 for non-func prog, the index in func array for func prog */ |
| 695 | 699 | u32 attach_btf_id; /* in-kernel BTF type id to attach to */ |
| 696 | 700 | u32 ctx_arg_info_size; |
| 701 | + u32 max_rdonly_access; | |
| 702 | + u32 max_rdwr_access; | |
| 697 | 703 | const struct bpf_ctx_arg_aux *ctx_arg_info; |
| 698 | 704 | struct bpf_prog *linked_prog; |
| 699 | 705 | bool verifier_zext; /* Zero extensions has been inserted by verifier. */ |