syscall.c (3bec5b6aae830355e786e204b20a7cea38c3a8ed) syscall.c (8ea636848aca35b9f97c5b5dee30225cf2dd0fe6)
1// SPDX-License-Identifier: GPL-2.0-only
2/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
3 */
4#include <linux/bpf.h>
5#include <linux/bpf_trace.h>
6#include <linux/bpf_lirc.h>
7#include <linux/btf.h>
8#include <linux/syscalls.h>

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

152 void *value, __u64 flags)
153{
154 int err;
155
156 /* Need to create a kthread, thus must support schedule */
157 if (bpf_map_is_dev_bound(map)) {
158 return bpf_map_offload_update_elem(map, key, value, flags);
159 } else if (map->map_type == BPF_MAP_TYPE_CPUMAP ||
1// SPDX-License-Identifier: GPL-2.0-only
2/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
3 */
4#include <linux/bpf.h>
5#include <linux/bpf_trace.h>
6#include <linux/bpf_lirc.h>
7#include <linux/btf.h>
8#include <linux/syscalls.h>

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

152 void *value, __u64 flags)
153{
154 int err;
155
156 /* Need to create a kthread, thus must support schedule */
157 if (bpf_map_is_dev_bound(map)) {
158 return bpf_map_offload_update_elem(map, key, value, flags);
159 } else if (map->map_type == BPF_MAP_TYPE_CPUMAP ||
160 map->map_type == BPF_MAP_TYPE_SOCKHASH ||
161 map->map_type == BPF_MAP_TYPE_SOCKMAP ||
162 map->map_type == BPF_MAP_TYPE_STRUCT_OPS) {
163 return map->ops->map_update_elem(map, key, value, flags);
160 map->map_type == BPF_MAP_TYPE_STRUCT_OPS) {
161 return map->ops->map_update_elem(map, key, value, flags);
162 } else if (map->map_type == BPF_MAP_TYPE_SOCKHASH ||
163 map->map_type == BPF_MAP_TYPE_SOCKMAP) {
164 return sock_map_update_elem_sys(map, key, value, flags);
164 } else if (IS_FD_PROG_ARRAY(map)) {
165 return bpf_fd_array_map_update_elem(map, f.file, key, value,
166 flags);
167 }
168
169 bpf_disable_instrumentation();
170 if (map->map_type == BPF_MAP_TYPE_PERCPU_HASH ||
171 map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH) {

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

763 map->spin_lock_off = btf_find_spin_lock(btf, value_type);
764
765 if (map_value_has_spin_lock(map)) {
766 if (map->map_flags & BPF_F_RDONLY_PROG)
767 return -EACCES;
768 if (map->map_type != BPF_MAP_TYPE_HASH &&
769 map->map_type != BPF_MAP_TYPE_ARRAY &&
770 map->map_type != BPF_MAP_TYPE_CGROUP_STORAGE &&
165 } else if (IS_FD_PROG_ARRAY(map)) {
166 return bpf_fd_array_map_update_elem(map, f.file, key, value,
167 flags);
168 }
169
170 bpf_disable_instrumentation();
171 if (map->map_type == BPF_MAP_TYPE_PERCPU_HASH ||
172 map->map_type == BPF_MAP_TYPE_LRU_PERCPU_HASH) {

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

764 map->spin_lock_off = btf_find_spin_lock(btf, value_type);
765
766 if (map_value_has_spin_lock(map)) {
767 if (map->map_flags & BPF_F_RDONLY_PROG)
768 return -EACCES;
769 if (map->map_type != BPF_MAP_TYPE_HASH &&
770 map->map_type != BPF_MAP_TYPE_ARRAY &&
771 map->map_type != BPF_MAP_TYPE_CGROUP_STORAGE &&
771 map->map_type != BPF_MAP_TYPE_SK_STORAGE)
772 map->map_type != BPF_MAP_TYPE_SK_STORAGE &&
773 map->map_type != BPF_MAP_TYPE_INODE_STORAGE)
772 return -ENOTSUPP;
773 if (map->spin_lock_off + sizeof(struct bpf_spin_lock) >
774 map->value_size) {
775 WARN_ONCE(1,
776 "verifier bug spin_lock_off %d value_size %d\n",
777 map->spin_lock_off, map->value_size);
778 return -EFAULT;
779 }

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

4009 ret = link->ops->detach(link);
4010 else
4011 ret = -EOPNOTSUPP;
4012
4013 bpf_link_put(link);
4014 return ret;
4015}
4016
774 return -ENOTSUPP;
775 if (map->spin_lock_off + sizeof(struct bpf_spin_lock) >
776 map->value_size) {
777 WARN_ONCE(1,
778 "verifier bug spin_lock_off %d value_size %d\n",
779 map->spin_lock_off, map->value_size);
780 return -EFAULT;
781 }

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

4011 ret = link->ops->detach(link);
4012 else
4013 ret = -EOPNOTSUPP;
4014
4015 bpf_link_put(link);
4016 return ret;
4017}
4018
4017static int bpf_link_inc_not_zero(struct bpf_link *link)
4019static struct bpf_link *bpf_link_inc_not_zero(struct bpf_link *link)
4018{
4020{
4019 return atomic64_fetch_add_unless(&link->refcnt, 1, 0) ? 0 : -ENOENT;
4021 return atomic64_fetch_add_unless(&link->refcnt, 1, 0) ? link : ERR_PTR(-ENOENT);
4020}
4021
4022}
4023
4022#define BPF_LINK_GET_FD_BY_ID_LAST_FIELD link_id
4023
4024static int bpf_link_get_fd_by_id(const union bpf_attr *attr)
4024struct bpf_link *bpf_link_by_id(u32 id)
4025{
4026 struct bpf_link *link;
4025{
4026 struct bpf_link *link;
4027 u32 id = attr->link_id;
4028 int fd, err;
4029
4027
4030 if (CHECK_ATTR(BPF_LINK_GET_FD_BY_ID))
4031 return -EINVAL;
4028 if (!id)
4029 return ERR_PTR(-ENOENT);
4032
4030
4033 if (!capable(CAP_SYS_ADMIN))
4034 return -EPERM;
4035
4036 spin_lock_bh(&link_idr_lock);
4031 spin_lock_bh(&link_idr_lock);
4037 link = idr_find(&link_idr, id);
4038 /* before link is "settled", ID is 0, pretend it doesn't exist yet */
4032 /* before link is "settled", ID is 0, pretend it doesn't exist yet */
4033 link = idr_find(&link_idr, id);
4039 if (link) {
4040 if (link->id)
4034 if (link) {
4035 if (link->id)
4041 err = bpf_link_inc_not_zero(link);
4036 link = bpf_link_inc_not_zero(link);
4042 else
4037 else
4043 err = -EAGAIN;
4038 link = ERR_PTR(-EAGAIN);
4044 } else {
4039 } else {
4045 err = -ENOENT;
4040 link = ERR_PTR(-ENOENT);
4046 }
4047 spin_unlock_bh(&link_idr_lock);
4041 }
4042 spin_unlock_bh(&link_idr_lock);
4043 return link;
4044}
4048
4045
4049 if (err)
4050 return err;
4046#define BPF_LINK_GET_FD_BY_ID_LAST_FIELD link_id
4051
4047
4048static int bpf_link_get_fd_by_id(const union bpf_attr *attr)
4049{
4050 struct bpf_link *link;
4051 u32 id = attr->link_id;
4052 int fd;
4053
4054 if (CHECK_ATTR(BPF_LINK_GET_FD_BY_ID))
4055 return -EINVAL;
4056
4057 if (!capable(CAP_SYS_ADMIN))
4058 return -EPERM;
4059
4060 link = bpf_link_by_id(id);
4061 if (IS_ERR(link))
4062 return PTR_ERR(link);
4063
4052 fd = bpf_link_new_fd(link);
4053 if (fd < 0)
4054 bpf_link_put(link);
4055
4056 return fd;
4057}
4058
4059DEFINE_MUTEX(bpf_stats_enabled_mutex);

--- 216 unchanged lines hidden ---
4064 fd = bpf_link_new_fd(link);
4065 if (fd < 0)
4066 bpf_link_put(link);
4067
4068 return fd;
4069}
4070
4071DEFINE_MUTEX(bpf_stats_enabled_mutex);

--- 216 unchanged lines hidden ---