Add helpers to work with new value being written to sysctl by user space. bpf_sysctl_get_new_value() copies value being written to sysctl into provided buffer. bpf_sysctl_set_new_value() overrides new value being written by user space with a one from provided buffer. Buffer should contain string representation of the value, similar to what can be seen in /proc/sys/. Both helpers can be used only on sysctl write. File position matters and can be managed by an interface that will be introduced separately. E.g. if user space calls sys_write to a file in /proc/sys/ at file position = X, where X > 0, then the value set by bpf_sysctl_set_new_value() will be written starting from X. If program wants to override whole value with specified buffer, file position has to be set to zero. Documentation for the new helpers is provided in bpf.h UAPI.
Showing the changes to include/linux (2 of 5 files). Show all
Unified · Split
| @@ -113,7 +113,8 @@ int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor, · 112 unmodified lines | ||
| 113 | 113 | |
| 114 | 114 | int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head, |
| 115 | 115 | struct ctl_table *table, int write, |
| 116 | − enum bpf_attach_type type); | |
| 116 | + void __user *buf, size_t *pcount, | |
| 117 | + void **new_buf, enum bpf_attach_type type); | |
| 117 | 118 | |
| 118 | 119 | static inline enum bpf_cgroup_storage_type cgroup_storage_type( |
| 119 | 120 | struct bpf_map *map) |
| @@ -261,11 +262,12 @@ int bpf_percpu_cgroup_storage_update(struct bpf_map *map, void *key, · 141 unmodified lines | ||
| 261 | 262 | }) |
| 262 | 263 | |
| 263 | 264 | |
| 264 | −#define BPF_CGROUP_RUN_PROG_SYSCTL(head, table, write) \ | |
| 265 | +#define BPF_CGROUP_RUN_PROG_SYSCTL(head, table, write, buf, count, nbuf) \ | |
| 265 | 266 | ({ \ |
| 266 | 267 | int __ret = 0; \ |
| 267 | 268 | if (cgroup_bpf_enabled) \ |
| 268 | 269 | __ret = __cgroup_bpf_run_filter_sysctl(head, table, write, \ |
| 270 | + buf, count, nbuf, \ | |
| 269 | 271 | BPF_CGROUP_SYSCTL); \ |
| 270 | 272 | __ret; \ |
| 271 | 273 | }) |
| @@ -338,7 +340,7 @@ static inline int bpf_percpu_cgroup_storage_update(struct bpf_map *map, · 66 unmodified lines | ||
| 338 | 340 | #define BPF_CGROUP_RUN_PROG_UDP6_SENDMSG_LOCK(sk, uaddr, t_ctx) ({ 0; }) |
| 339 | 341 | #define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; }) |
| 340 | 342 | #define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(type,major,minor,access) ({ 0; }) |
| 341 | −#define BPF_CGROUP_RUN_PROG_SYSCTL(head, table, write) ({ 0; }) | |
| 343 | +#define BPF_CGROUP_RUN_PROG_SYSCTL(head,table,write,buf,count,nbuf) ({ 0; }) | |
| 342 | 344 | |
| 343 | 345 | #define for_each_cgroup_storage_type(stype) for (; false; ) |
| 344 | 346 | |
| @@ -1184,6 +1184,9 @@ struct bpf_sysctl_kern { · 1183 unmodified lines | ||
| 1184 | 1184 | struct ctl_table *table; |
| 1185 | 1185 | void *cur_val; |
| 1186 | 1186 | size_t cur_len; |
| 1187 | + void *new_val; | |
| 1188 | + size_t new_len; | |
| 1189 | + int new_updated; | |
| 1187 | 1190 | int write; |
| 1188 | 1191 | }; |
| 1189 | 1192 | |