syscall.c (aaccf3c97418f169afdbb5855e9cbcbda34e90fd) syscall.c (8bad74f9840f87661f20ced3dc80c84ab4fd55a1)
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

--- 16 unchanged lines hidden (view full) ---

25#include <linux/license.h>
26#include <linux/filter.h>
27#include <linux/version.h>
28#include <linux/kernel.h>
29#include <linux/idr.h>
30#include <linux/cred.h>
31#include <linux/timekeeping.h>
32#include <linux/ctype.h>
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

--- 16 unchanged lines hidden (view full) ---

25#include <linux/license.h>
26#include <linux/filter.h>
27#include <linux/version.h>
28#include <linux/kernel.h>
29#include <linux/idr.h>
30#include <linux/cred.h>
31#include <linux/timekeeping.h>
32#include <linux/ctype.h>
33#include <linux/btf.h>
34#include <linux/nospec.h>
35
36#define IS_FD_ARRAY(map) ((map)->map_type == BPF_MAP_TYPE_PROG_ARRAY || \
37 (map)->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY || \
38 (map)->map_type == BPF_MAP_TYPE_CGROUP_ARRAY || \
39 (map)->map_type == BPF_MAP_TYPE_ARRAY_OF_MAPS)
40#define IS_FD_HASH(map) ((map)->map_type == BPF_MAP_TYPE_HASH_OF_MAPS)
41#define IS_FD_MAP(map) (IS_FD_ARRAY(map) || IS_FD_HASH(map))

--- 942 unchanged lines hidden (view full) ---

984 prog->aux->ops = &bpf_offload_prog_ops;
985 prog->type = type;
986 return 0;
987}
988
989/* drop refcnt on maps used by eBPF program and free auxilary data */
990static void free_used_maps(struct bpf_prog_aux *aux)
991{
33#include <linux/nospec.h>
34
35#define IS_FD_ARRAY(map) ((map)->map_type == BPF_MAP_TYPE_PROG_ARRAY || \
36 (map)->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY || \
37 (map)->map_type == BPF_MAP_TYPE_CGROUP_ARRAY || \
38 (map)->map_type == BPF_MAP_TYPE_ARRAY_OF_MAPS)
39#define IS_FD_HASH(map) ((map)->map_type == BPF_MAP_TYPE_HASH_OF_MAPS)
40#define IS_FD_MAP(map) (IS_FD_ARRAY(map) || IS_FD_HASH(map))

--- 942 unchanged lines hidden (view full) ---

983 prog->aux->ops = &bpf_offload_prog_ops;
984 prog->type = type;
985 return 0;
986}
987
988/* drop refcnt on maps used by eBPF program and free auxilary data */
989static void free_used_maps(struct bpf_prog_aux *aux)
990{
991 enum bpf_cgroup_storage_type stype;
992 int i;
993
992 int i;
993
994 if (aux->cgroup_storage)
995 bpf_cgroup_storage_release(aux->prog, aux->cgroup_storage);
994 for_each_cgroup_storage_type(stype) {
995 if (!aux->cgroup_storage[stype])
996 continue;
997 bpf_cgroup_storage_release(aux->prog,
998 aux->cgroup_storage[stype]);
999 }
996
997 for (i = 0; i < aux->used_map_cnt; i++)
998 bpf_map_put(aux->used_maps[i]);
999
1000 kfree(aux->used_maps);
1001}
1002
1003int __bpf_prog_charge(struct user_struct *user, u32 pages)

--- 607 unchanged lines hidden (view full) ---

1611 break;
1612 case BPF_SK_SKB_STREAM_PARSER:
1613 case BPF_SK_SKB_STREAM_VERDICT:
1614 ptype = BPF_PROG_TYPE_SK_SKB;
1615 break;
1616 case BPF_LIRC_MODE2:
1617 ptype = BPF_PROG_TYPE_LIRC_MODE2;
1618 break;
1000
1001 for (i = 0; i < aux->used_map_cnt; i++)
1002 bpf_map_put(aux->used_maps[i]);
1003
1004 kfree(aux->used_maps);
1005}
1006
1007int __bpf_prog_charge(struct user_struct *user, u32 pages)

--- 607 unchanged lines hidden (view full) ---

1615 break;
1616 case BPF_SK_SKB_STREAM_PARSER:
1617 case BPF_SK_SKB_STREAM_VERDICT:
1618 ptype = BPF_PROG_TYPE_SK_SKB;
1619 break;
1620 case BPF_LIRC_MODE2:
1621 ptype = BPF_PROG_TYPE_LIRC_MODE2;
1622 break;
1623 case BPF_FLOW_DISSECTOR:
1624 ptype = BPF_PROG_TYPE_FLOW_DISSECTOR;
1625 break;
1619 default:
1620 return -EINVAL;
1621 }
1622
1623 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype);
1624 if (IS_ERR(prog))
1625 return PTR_ERR(prog);
1626

--- 5 unchanged lines hidden (view full) ---

1632 switch (ptype) {
1633 case BPF_PROG_TYPE_SK_SKB:
1634 case BPF_PROG_TYPE_SK_MSG:
1635 ret = sockmap_get_from_fd(attr, ptype, prog);
1636 break;
1637 case BPF_PROG_TYPE_LIRC_MODE2:
1638 ret = lirc_prog_attach(attr, prog);
1639 break;
1626 default:
1627 return -EINVAL;
1628 }
1629
1630 prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype);
1631 if (IS_ERR(prog))
1632 return PTR_ERR(prog);
1633

--- 5 unchanged lines hidden (view full) ---

1639 switch (ptype) {
1640 case BPF_PROG_TYPE_SK_SKB:
1641 case BPF_PROG_TYPE_SK_MSG:
1642 ret = sockmap_get_from_fd(attr, ptype, prog);
1643 break;
1644 case BPF_PROG_TYPE_LIRC_MODE2:
1645 ret = lirc_prog_attach(attr, prog);
1646 break;
1647 case BPF_PROG_TYPE_FLOW_DISSECTOR:
1648 ret = skb_flow_dissector_bpf_prog_attach(attr, prog);
1649 break;
1640 default:
1641 ret = cgroup_bpf_prog_attach(attr, ptype, prog);
1642 }
1643
1644 if (ret)
1645 bpf_prog_put(prog);
1646 return ret;
1647}

--- 36 unchanged lines hidden (view full) ---

1684 break;
1685 case BPF_SK_MSG_VERDICT:
1686 return sockmap_get_from_fd(attr, BPF_PROG_TYPE_SK_MSG, NULL);
1687 case BPF_SK_SKB_STREAM_PARSER:
1688 case BPF_SK_SKB_STREAM_VERDICT:
1689 return sockmap_get_from_fd(attr, BPF_PROG_TYPE_SK_SKB, NULL);
1690 case BPF_LIRC_MODE2:
1691 return lirc_prog_detach(attr);
1650 default:
1651 ret = cgroup_bpf_prog_attach(attr, ptype, prog);
1652 }
1653
1654 if (ret)
1655 bpf_prog_put(prog);
1656 return ret;
1657}

--- 36 unchanged lines hidden (view full) ---

1694 break;
1695 case BPF_SK_MSG_VERDICT:
1696 return sockmap_get_from_fd(attr, BPF_PROG_TYPE_SK_MSG, NULL);
1697 case BPF_SK_SKB_STREAM_PARSER:
1698 case BPF_SK_SKB_STREAM_VERDICT:
1699 return sockmap_get_from_fd(attr, BPF_PROG_TYPE_SK_SKB, NULL);
1700 case BPF_LIRC_MODE2:
1701 return lirc_prog_detach(attr);
1702 case BPF_FLOW_DISSECTOR:
1703 return skb_flow_dissector_bpf_prog_detach(attr);
1692 default:
1693 return -EINVAL;
1694 }
1695
1696 return cgroup_bpf_prog_detach(attr, ptype);
1697}
1698
1699#define BPF_PROG_QUERY_LAST_FIELD query.prog_cnt

--- 728 unchanged lines hidden ---
1704 default:
1705 return -EINVAL;
1706 }
1707
1708 return cgroup_bpf_prog_detach(attr, ptype);
1709}
1710
1711#define BPF_PROG_QUERY_LAST_FIELD query.prog_cnt

--- 728 unchanged lines hidden ---