syscall.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
  2. *
  3. * This program is free software; you can redistribute it and/or
  4. * modify it under the terms of version 2 of the GNU General Public
  5. * License as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful, but
  8. * WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. * General Public License for more details.
  11. */
  12. #include <linux/bpf.h>
  13. #include <linux/syscalls.h>
  14. #include <linux/slab.h>
  15. #include <linux/anon_inodes.h>
  16. #include <linux/file.h>
  17. #include <linux/license.h>
  18. #include <linux/filter.h>
  19. #include <linux/version.h>
  20. int sysctl_unprivileged_bpf_disabled __read_mostly;
  21. static LIST_HEAD(bpf_map_types);
  22. static struct bpf_map *find_and_alloc_map(union bpf_attr *attr)
  23. {
  24. struct bpf_map_type_list *tl;
  25. struct bpf_map *map;
  26. list_for_each_entry(tl, &bpf_map_types, list_node) {
  27. if (tl->type == attr->map_type) {
  28. map = tl->ops->map_alloc(attr);
  29. if (IS_ERR(map))
  30. return map;
  31. map->ops = tl->ops;
  32. map->map_type = attr->map_type;
  33. return map;
  34. }
  35. }
  36. return ERR_PTR(-EINVAL);
  37. }
  38. /* boot time registration of different map implementations */
  39. void bpf_register_map_type(struct bpf_map_type_list *tl)
  40. {
  41. list_add(&tl->list_node, &bpf_map_types);
  42. }
  43. static int bpf_map_charge_memlock(struct bpf_map *map)
  44. {
  45. struct user_struct *user = get_current_user();
  46. unsigned long memlock_limit;
  47. memlock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
  48. atomic_long_add(map->pages, &user->locked_vm);
  49. if (atomic_long_read(&user->locked_vm) > memlock_limit) {
  50. atomic_long_sub(map->pages, &user->locked_vm);
  51. free_uid(user);
  52. return -EPERM;
  53. }
  54. map->user = user;
  55. return 0;
  56. }
  57. static void bpf_map_uncharge_memlock(struct bpf_map *map)
  58. {
  59. struct user_struct *user = map->user;
  60. atomic_long_sub(map->pages, &user->locked_vm);
  61. free_uid(user);
  62. }
  63. /* called from workqueue */
  64. static void bpf_map_free_deferred(struct work_struct *work)
  65. {
  66. struct bpf_map *map = container_of(work, struct bpf_map, work);
  67. bpf_map_uncharge_memlock(map);
  68. /* implementation dependent freeing */
  69. map->ops->map_free(map);
  70. }
  71. static void bpf_map_put_uref(struct bpf_map *map)
  72. {
  73. if (atomic_dec_and_test(&map->usercnt)) {
  74. if (map->map_type == BPF_MAP_TYPE_PROG_ARRAY)
  75. bpf_fd_array_map_clear(map);
  76. }
  77. }
  78. /* decrement map refcnt and schedule it for freeing via workqueue
  79. * (unrelying map implementation ops->map_free() might sleep)
  80. */
  81. void bpf_map_put(struct bpf_map *map)
  82. {
  83. if (atomic_dec_and_test(&map->refcnt)) {
  84. INIT_WORK(&map->work, bpf_map_free_deferred);
  85. schedule_work(&map->work);
  86. }
  87. }
  88. void bpf_map_put_with_uref(struct bpf_map *map)
  89. {
  90. bpf_map_put_uref(map);
  91. bpf_map_put(map);
  92. }
  93. static int bpf_map_release(struct inode *inode, struct file *filp)
  94. {
  95. bpf_map_put_with_uref(filp->private_data);
  96. return 0;
  97. }
  98. static const struct file_operations bpf_map_fops = {
  99. .release = bpf_map_release,
  100. };
  101. int bpf_map_new_fd(struct bpf_map *map)
  102. {
  103. return anon_inode_getfd("bpf-map", &bpf_map_fops, map,
  104. O_RDWR | O_CLOEXEC);
  105. }
  106. /* helper macro to check that unused fields 'union bpf_attr' are zero */
  107. #define CHECK_ATTR(CMD) \
  108. memchr_inv((void *) &attr->CMD##_LAST_FIELD + \
  109. sizeof(attr->CMD##_LAST_FIELD), 0, \
  110. sizeof(*attr) - \
  111. offsetof(union bpf_attr, CMD##_LAST_FIELD) - \
  112. sizeof(attr->CMD##_LAST_FIELD)) != NULL
  113. #define BPF_MAP_CREATE_LAST_FIELD max_entries
  114. /* called via syscall */
  115. static int map_create(union bpf_attr *attr)
  116. {
  117. struct bpf_map *map;
  118. int err;
  119. err = CHECK_ATTR(BPF_MAP_CREATE);
  120. if (err)
  121. return -EINVAL;
  122. /* find map type and init map: hashtable vs rbtree vs bloom vs ... */
  123. map = find_and_alloc_map(attr);
  124. if (IS_ERR(map))
  125. return PTR_ERR(map);
  126. atomic_set(&map->refcnt, 1);
  127. atomic_set(&map->usercnt, 1);
  128. err = bpf_map_charge_memlock(map);
  129. if (err)
  130. goto free_map;
  131. err = bpf_map_new_fd(map);
  132. if (err < 0)
  133. /* failed to allocate fd */
  134. goto free_map;
  135. return err;
  136. free_map:
  137. map->ops->map_free(map);
  138. return err;
  139. }
  140. /* if error is returned, fd is released.
  141. * On success caller should complete fd access with matching fdput()
  142. */
  143. struct bpf_map *__bpf_map_get(struct fd f)
  144. {
  145. if (!f.file)
  146. return ERR_PTR(-EBADF);
  147. if (f.file->f_op != &bpf_map_fops) {
  148. fdput(f);
  149. return ERR_PTR(-EINVAL);
  150. }
  151. return f.file->private_data;
  152. }
  153. /* prog's and map's refcnt limit */
  154. #define BPF_MAX_REFCNT 32768
  155. struct bpf_map *bpf_map_inc(struct bpf_map *map, bool uref)
  156. {
  157. if (atomic_inc_return(&map->refcnt) > BPF_MAX_REFCNT) {
  158. atomic_dec(&map->refcnt);
  159. return ERR_PTR(-EBUSY);
  160. }
  161. if (uref)
  162. atomic_inc(&map->usercnt);
  163. return map;
  164. }
  165. struct bpf_map *bpf_map_get_with_uref(u32 ufd)
  166. {
  167. struct fd f = fdget(ufd);
  168. struct bpf_map *map;
  169. map = __bpf_map_get(f);
  170. if (IS_ERR(map))
  171. return map;
  172. map = bpf_map_inc(map, true);
  173. fdput(f);
  174. return map;
  175. }
  176. /* helper to convert user pointers passed inside __aligned_u64 fields */
  177. static void __user *u64_to_ptr(__u64 val)
  178. {
  179. return (void __user *) (unsigned long) val;
  180. }
  181. /* last field in 'union bpf_attr' used by this command */
  182. #define BPF_MAP_LOOKUP_ELEM_LAST_FIELD value
  183. static int map_lookup_elem(union bpf_attr *attr)
  184. {
  185. void __user *ukey = u64_to_ptr(attr->key);
  186. void __user *uvalue = u64_to_ptr(attr->value);
  187. int ufd = attr->map_fd;
  188. struct bpf_map *map;
  189. void *key, *value, *ptr;
  190. struct fd f;
  191. int err;
  192. if (CHECK_ATTR(BPF_MAP_LOOKUP_ELEM))
  193. return -EINVAL;
  194. f = fdget(ufd);
  195. map = __bpf_map_get(f);
  196. if (IS_ERR(map))
  197. return PTR_ERR(map);
  198. err = -ENOMEM;
  199. key = kmalloc(map->key_size, GFP_USER);
  200. if (!key)
  201. goto err_put;
  202. err = -EFAULT;
  203. if (copy_from_user(key, ukey, map->key_size) != 0)
  204. goto free_key;
  205. err = -ENOMEM;
  206. value = kmalloc(map->value_size, GFP_USER | __GFP_NOWARN);
  207. if (!value)
  208. goto free_key;
  209. rcu_read_lock();
  210. ptr = map->ops->map_lookup_elem(map, key);
  211. if (ptr)
  212. memcpy(value, ptr, map->value_size);
  213. rcu_read_unlock();
  214. err = -ENOENT;
  215. if (!ptr)
  216. goto free_value;
  217. err = -EFAULT;
  218. if (copy_to_user(uvalue, value, map->value_size) != 0)
  219. goto free_value;
  220. err = 0;
  221. free_value:
  222. kfree(value);
  223. free_key:
  224. kfree(key);
  225. err_put:
  226. fdput(f);
  227. return err;
  228. }
  229. #define BPF_MAP_UPDATE_ELEM_LAST_FIELD flags
  230. static int map_update_elem(union bpf_attr *attr)
  231. {
  232. void __user *ukey = u64_to_ptr(attr->key);
  233. void __user *uvalue = u64_to_ptr(attr->value);
  234. int ufd = attr->map_fd;
  235. struct bpf_map *map;
  236. void *key, *value;
  237. struct fd f;
  238. int err;
  239. if (CHECK_ATTR(BPF_MAP_UPDATE_ELEM))
  240. return -EINVAL;
  241. f = fdget(ufd);
  242. map = __bpf_map_get(f);
  243. if (IS_ERR(map))
  244. return PTR_ERR(map);
  245. err = -ENOMEM;
  246. key = kmalloc(map->key_size, GFP_USER);
  247. if (!key)
  248. goto err_put;
  249. err = -EFAULT;
  250. if (copy_from_user(key, ukey, map->key_size) != 0)
  251. goto free_key;
  252. err = -ENOMEM;
  253. value = kmalloc(map->value_size, GFP_USER | __GFP_NOWARN);
  254. if (!value)
  255. goto free_key;
  256. err = -EFAULT;
  257. if (copy_from_user(value, uvalue, map->value_size) != 0)
  258. goto free_value;
  259. /* eBPF program that use maps are running under rcu_read_lock(),
  260. * therefore all map accessors rely on this fact, so do the same here
  261. */
  262. rcu_read_lock();
  263. err = map->ops->map_update_elem(map, key, value, attr->flags);
  264. rcu_read_unlock();
  265. free_value:
  266. kfree(value);
  267. free_key:
  268. kfree(key);
  269. err_put:
  270. fdput(f);
  271. return err;
  272. }
  273. #define BPF_MAP_DELETE_ELEM_LAST_FIELD key
  274. static int map_delete_elem(union bpf_attr *attr)
  275. {
  276. void __user *ukey = u64_to_ptr(attr->key);
  277. int ufd = attr->map_fd;
  278. struct bpf_map *map;
  279. struct fd f;
  280. void *key;
  281. int err;
  282. if (CHECK_ATTR(BPF_MAP_DELETE_ELEM))
  283. return -EINVAL;
  284. f = fdget(ufd);
  285. map = __bpf_map_get(f);
  286. if (IS_ERR(map))
  287. return PTR_ERR(map);
  288. err = -ENOMEM;
  289. key = kmalloc(map->key_size, GFP_USER);
  290. if (!key)
  291. goto err_put;
  292. err = -EFAULT;
  293. if (copy_from_user(key, ukey, map->key_size) != 0)
  294. goto free_key;
  295. rcu_read_lock();
  296. err = map->ops->map_delete_elem(map, key);
  297. rcu_read_unlock();
  298. free_key:
  299. kfree(key);
  300. err_put:
  301. fdput(f);
  302. return err;
  303. }
  304. /* last field in 'union bpf_attr' used by this command */
  305. #define BPF_MAP_GET_NEXT_KEY_LAST_FIELD next_key
  306. static int map_get_next_key(union bpf_attr *attr)
  307. {
  308. void __user *ukey = u64_to_ptr(attr->key);
  309. void __user *unext_key = u64_to_ptr(attr->next_key);
  310. int ufd = attr->map_fd;
  311. struct bpf_map *map;
  312. void *key, *next_key;
  313. struct fd f;
  314. int err;
  315. if (CHECK_ATTR(BPF_MAP_GET_NEXT_KEY))
  316. return -EINVAL;
  317. f = fdget(ufd);
  318. map = __bpf_map_get(f);
  319. if (IS_ERR(map))
  320. return PTR_ERR(map);
  321. if (ukey) {
  322. err = -ENOMEM;
  323. key = kmalloc(map->key_size, GFP_USER);
  324. if (!key)
  325. goto err_put;
  326. err = -EFAULT;
  327. if (copy_from_user(key, ukey, map->key_size) != 0)
  328. goto free_key;
  329. } else {
  330. key = NULL;
  331. }
  332. err = -ENOMEM;
  333. next_key = kmalloc(map->key_size, GFP_USER);
  334. if (!next_key)
  335. goto free_key;
  336. rcu_read_lock();
  337. err = map->ops->map_get_next_key(map, key, next_key);
  338. rcu_read_unlock();
  339. if (err)
  340. goto free_next_key;
  341. err = -EFAULT;
  342. if (copy_to_user(unext_key, next_key, map->key_size) != 0)
  343. goto free_next_key;
  344. err = 0;
  345. free_next_key:
  346. kfree(next_key);
  347. free_key:
  348. kfree(key);
  349. err_put:
  350. fdput(f);
  351. return err;
  352. }
  353. static LIST_HEAD(bpf_prog_types);
  354. static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog)
  355. {
  356. struct bpf_prog_type_list *tl;
  357. list_for_each_entry(tl, &bpf_prog_types, list_node) {
  358. if (tl->type == type) {
  359. prog->aux->ops = tl->ops;
  360. prog->type = type;
  361. return 0;
  362. }
  363. }
  364. return -EINVAL;
  365. }
  366. void bpf_register_prog_type(struct bpf_prog_type_list *tl)
  367. {
  368. list_add(&tl->list_node, &bpf_prog_types);
  369. }
  370. /* drop refcnt on maps used by eBPF program and free auxilary data */
  371. static void free_used_maps(struct bpf_prog_aux *aux)
  372. {
  373. int i;
  374. for (i = 0; i < aux->used_map_cnt; i++)
  375. bpf_map_put(aux->used_maps[i]);
  376. kfree(aux->used_maps);
  377. }
  378. static int bpf_prog_charge_memlock(struct bpf_prog *prog)
  379. {
  380. struct user_struct *user = get_current_user();
  381. unsigned long memlock_limit;
  382. memlock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
  383. atomic_long_add(prog->pages, &user->locked_vm);
  384. if (atomic_long_read(&user->locked_vm) > memlock_limit) {
  385. atomic_long_sub(prog->pages, &user->locked_vm);
  386. free_uid(user);
  387. return -EPERM;
  388. }
  389. prog->aux->user = user;
  390. return 0;
  391. }
  392. static void bpf_prog_uncharge_memlock(struct bpf_prog *prog)
  393. {
  394. struct user_struct *user = prog->aux->user;
  395. atomic_long_sub(prog->pages, &user->locked_vm);
  396. free_uid(user);
  397. }
  398. static void __bpf_prog_put_rcu(struct rcu_head *rcu)
  399. {
  400. struct bpf_prog_aux *aux = container_of(rcu, struct bpf_prog_aux, rcu);
  401. free_used_maps(aux);
  402. bpf_prog_uncharge_memlock(aux->prog);
  403. bpf_prog_free(aux->prog);
  404. }
  405. void bpf_prog_put(struct bpf_prog *prog)
  406. {
  407. if (atomic_dec_and_test(&prog->aux->refcnt))
  408. call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu);
  409. }
  410. EXPORT_SYMBOL_GPL(bpf_prog_put);
  411. static int bpf_prog_release(struct inode *inode, struct file *filp)
  412. {
  413. struct bpf_prog *prog = filp->private_data;
  414. bpf_prog_put(prog);
  415. return 0;
  416. }
  417. static const struct file_operations bpf_prog_fops = {
  418. .release = bpf_prog_release,
  419. };
  420. int bpf_prog_new_fd(struct bpf_prog *prog)
  421. {
  422. return anon_inode_getfd("bpf-prog", &bpf_prog_fops, prog,
  423. O_RDWR | O_CLOEXEC);
  424. }
  425. static struct bpf_prog *__bpf_prog_get(struct fd f)
  426. {
  427. if (!f.file)
  428. return ERR_PTR(-EBADF);
  429. if (f.file->f_op != &bpf_prog_fops) {
  430. fdput(f);
  431. return ERR_PTR(-EINVAL);
  432. }
  433. return f.file->private_data;
  434. }
  435. struct bpf_prog *bpf_prog_inc(struct bpf_prog *prog)
  436. {
  437. if (atomic_inc_return(&prog->aux->refcnt) > BPF_MAX_REFCNT) {
  438. atomic_dec(&prog->aux->refcnt);
  439. return ERR_PTR(-EBUSY);
  440. }
  441. return prog;
  442. }
  443. /* called by sockets/tracing/seccomp before attaching program to an event
  444. * pairs with bpf_prog_put()
  445. */
  446. struct bpf_prog *bpf_prog_get(u32 ufd)
  447. {
  448. struct fd f = fdget(ufd);
  449. struct bpf_prog *prog;
  450. prog = __bpf_prog_get(f);
  451. if (IS_ERR(prog))
  452. return prog;
  453. prog = bpf_prog_inc(prog);
  454. fdput(f);
  455. return prog;
  456. }
  457. EXPORT_SYMBOL_GPL(bpf_prog_get);
  458. /* last field in 'union bpf_attr' used by this command */
  459. #define BPF_PROG_LOAD_LAST_FIELD kern_version
  460. static int bpf_prog_load(union bpf_attr *attr)
  461. {
  462. enum bpf_prog_type type = attr->prog_type;
  463. struct bpf_prog *prog;
  464. int err;
  465. char license[128];
  466. bool is_gpl;
  467. if (CHECK_ATTR(BPF_PROG_LOAD))
  468. return -EINVAL;
  469. /* copy eBPF program license from user space */
  470. if (strncpy_from_user(license, u64_to_ptr(attr->license),
  471. sizeof(license) - 1) < 0)
  472. return -EFAULT;
  473. license[sizeof(license) - 1] = 0;
  474. /* eBPF programs must be GPL compatible to use GPL-ed functions */
  475. is_gpl = license_is_gpl_compatible(license);
  476. if (attr->insn_cnt >= BPF_MAXINSNS)
  477. return -EINVAL;
  478. if (type == BPF_PROG_TYPE_KPROBE &&
  479. attr->kern_version != LINUX_VERSION_CODE)
  480. return -EINVAL;
  481. if (type != BPF_PROG_TYPE_SOCKET_FILTER && !capable(CAP_SYS_ADMIN))
  482. return -EPERM;
  483. /* plain bpf_prog allocation */
  484. prog = bpf_prog_alloc(bpf_prog_size(attr->insn_cnt), GFP_USER);
  485. if (!prog)
  486. return -ENOMEM;
  487. err = bpf_prog_charge_memlock(prog);
  488. if (err)
  489. goto free_prog_nouncharge;
  490. prog->len = attr->insn_cnt;
  491. err = -EFAULT;
  492. if (copy_from_user(prog->insns, u64_to_ptr(attr->insns),
  493. prog->len * sizeof(struct bpf_insn)) != 0)
  494. goto free_prog;
  495. prog->orig_prog = NULL;
  496. prog->jited = 0;
  497. atomic_set(&prog->aux->refcnt, 1);
  498. prog->gpl_compatible = is_gpl ? 1 : 0;
  499. /* find program type: socket_filter vs tracing_filter */
  500. err = find_prog_type(type, prog);
  501. if (err < 0)
  502. goto free_prog;
  503. /* run eBPF verifier */
  504. err = bpf_check(&prog, attr);
  505. if (err < 0)
  506. goto free_used_maps;
  507. /* eBPF program is ready to be JITed */
  508. err = bpf_prog_select_runtime(prog);
  509. if (err < 0)
  510. goto free_used_maps;
  511. err = bpf_prog_new_fd(prog);
  512. if (err < 0)
  513. /* failed to allocate fd */
  514. goto free_used_maps;
  515. return err;
  516. free_used_maps:
  517. free_used_maps(prog->aux);
  518. free_prog:
  519. bpf_prog_uncharge_memlock(prog);
  520. free_prog_nouncharge:
  521. bpf_prog_free(prog);
  522. return err;
  523. }
  524. #define BPF_OBJ_LAST_FIELD bpf_fd
  525. static int bpf_obj_pin(const union bpf_attr *attr)
  526. {
  527. if (CHECK_ATTR(BPF_OBJ))
  528. return -EINVAL;
  529. return bpf_obj_pin_user(attr->bpf_fd, u64_to_ptr(attr->pathname));
  530. }
  531. static int bpf_obj_get(const union bpf_attr *attr)
  532. {
  533. if (CHECK_ATTR(BPF_OBJ) || attr->bpf_fd != 0)
  534. return -EINVAL;
  535. return bpf_obj_get_user(u64_to_ptr(attr->pathname));
  536. }
  537. SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, size)
  538. {
  539. union bpf_attr attr = {};
  540. int err;
  541. if (sysctl_unprivileged_bpf_disabled && !capable(CAP_SYS_ADMIN))
  542. return -EPERM;
  543. if (!access_ok(VERIFY_READ, uattr, 1))
  544. return -EFAULT;
  545. if (size > PAGE_SIZE) /* silly large */
  546. return -E2BIG;
  547. /* If we're handed a bigger struct than we know of,
  548. * ensure all the unknown bits are 0 - i.e. new
  549. * user-space does not rely on any kernel feature
  550. * extensions we dont know about yet.
  551. */
  552. if (size > sizeof(attr)) {
  553. unsigned char __user *addr;
  554. unsigned char __user *end;
  555. unsigned char val;
  556. addr = (void __user *)uattr + sizeof(attr);
  557. end = (void __user *)uattr + size;
  558. for (; addr < end; addr++) {
  559. err = get_user(val, addr);
  560. if (err)
  561. return err;
  562. if (val)
  563. return -E2BIG;
  564. }
  565. size = sizeof(attr);
  566. }
  567. /* copy attributes from user space, may be less than sizeof(bpf_attr) */
  568. if (copy_from_user(&attr, uattr, size) != 0)
  569. return -EFAULT;
  570. switch (cmd) {
  571. case BPF_MAP_CREATE:
  572. err = map_create(&attr);
  573. break;
  574. case BPF_MAP_LOOKUP_ELEM:
  575. err = map_lookup_elem(&attr);
  576. break;
  577. case BPF_MAP_UPDATE_ELEM:
  578. err = map_update_elem(&attr);
  579. break;
  580. case BPF_MAP_DELETE_ELEM:
  581. err = map_delete_elem(&attr);
  582. break;
  583. case BPF_MAP_GET_NEXT_KEY:
  584. err = map_get_next_key(&attr);
  585. break;
  586. case BPF_PROG_LOAD:
  587. err = bpf_prog_load(&attr);
  588. break;
  589. case BPF_OBJ_PIN:
  590. err = bpf_obj_pin(&attr);
  591. break;
  592. case BPF_OBJ_GET:
  593. err = bpf_obj_get(&attr);
  594. break;
  595. default:
  596. err = -EINVAL;
  597. break;
  598. }
  599. return err;
  600. }