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
113113
114114 int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head,
115115 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);
117118
118119 static inline enum bpf_cgroup_storage_type cgroup_storage_type(
119120 struct bpf_map *map)
@@ -261,11 +262,12 @@ int bpf_percpu_cgroup_storage_update(struct bpf_map *map, void *key, · 141 unmodified lines
261262 })
262263
263264
264−#define BPF_CGROUP_RUN_PROG_SYSCTL(head, table, write) \
265+#define BPF_CGROUP_RUN_PROG_SYSCTL(head, table, write, buf, count, nbuf) \
265266 ({ \
266267 int __ret = 0; \
267268 if (cgroup_bpf_enabled) \
268269 __ret = __cgroup_bpf_run_filter_sysctl(head, table, write, \
270+ buf, count, nbuf, \
269271 BPF_CGROUP_SYSCTL); \
270272 __ret; \
271273 })
@@ -338,7 +340,7 @@ static inline int bpf_percpu_cgroup_storage_update(struct bpf_map *map, · 66 unmodified lines
338340 #define BPF_CGROUP_RUN_PROG_UDP6_SENDMSG_LOCK(sk, uaddr, t_ctx) ({ 0; })
339341 #define BPF_CGROUP_RUN_PROG_SOCK_OPS(sock_ops) ({ 0; })
340342 #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; })
342344
343345 #define for_each_cgroup_storage_type(stype) for (; false; )
344346
include/linux/filter.h+3−0
@@ -1184,6 +1184,9 @@ struct bpf_sysctl_kern { · 1183 unmodified lines
11841184 struct ctl_table *table;
11851185 void *cur_val;
11861186 size_t cur_len;
1187+ void *new_val;
1188+ size_t new_len;
1189+ int new_updated;
11871190 int write;
11881191 };
11891192

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