History

bpf: Introduce bpf_sysctl_{get,set}_new_value helpers

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.

Andrey Ignatov committed 7 years ago

Commit 4e63acd1 parent 1d11b305 files · +142 −10Browse files

Showing the changes to include/linux (2 of 5 files). Show all

Unified · Split

2 files
  1. include/linux/bpf-cgroup.h +5 −3
  2. include/linux/filter.h +3 −0
include/linux/bpf-cgroup.h+5−3
@@ -113,7 +113,8 @@ int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor, · 112 unmodified lines
113 113
114int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head,114int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head,
115 struct ctl_table *table, int write,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
118static inline enum bpf_cgroup_storage_type cgroup_storage_type(119static inline enum bpf_cgroup_storage_type cgroup_storage_type(
119 struct bpf_map *map)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 int __ret = 0; \267 int __ret = 0; \
267 if (cgroup_bpf_enabled) \268 if (cgroup_bpf_enabled) \
268 __ret = __cgroup_bpf_run_filter_sysctl(head, table, write, \269 __ret = __cgroup_bpf_run_filter_sysctl(head, table, write, \
270 buf, count, nbuf, \
269 BPF_CGROUP_SYSCTL); \271 BPF_CGROUP_SYSCTL); \
270 __ret; \272 __ret; \
271})273})
@@ -338,7 +340,7 @@ static inline int bpf_percpu_cgroup_storage_update(struct bpf_map *map, · 66 unmodified lines
338#define BPF_CGROUP_RUN_PROG_UDP6_SENDMSG_LOCK(sk, uaddr, t_ctx) ({ 0; })340#define BPF_CGROUP_RUN_PROG_UDP6_SENDMSG_LOCK(sk, uaddr, t_ctx) ({ 0; })
339#define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; })341#define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; })
340#define BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(type,major,minor,access) ({ 0; })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#define for_each_cgroup_storage_type(stype) for (; false; )345#define for_each_cgroup_storage_type(stype) for (; false; )
344 346
include/linux/filter.h+3−0
@@ -1184,6 +1184,9 @@ struct bpf_sysctl_kern { · 1183 unmodified lines
1184 struct ctl_table *table;1184 struct ctl_table *table;
1185 void *cur_val;1185 void *cur_val;
1186 size_t cur_len;1186 size_t cur_len;
1187 void *new_val;
1188 size_t new_len;
1189 int new_updated;
1187 int write;1190 int write;
1188};1191};
1189 1192

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t