bianbu-linux-6.6/tools/include/uapi/linux
Kumar Kartikeya Dwivedi c0a5a21c25 bpf: Allow storing referenced kptr in map
Extending the code in previous commits, introduce referenced kptr
support, which needs to be tagged using 'kptr_ref' tag instead. Unlike
unreferenced kptr, referenced kptr have a lot more restrictions. In
addition to the type matching, only a newly introduced bpf_kptr_xchg
helper is allowed to modify the map value at that offset. This transfers
the referenced pointer being stored into the map, releasing the
references state for the program, and returning the old value and
creating new reference state for the returned pointer.

Similar to unreferenced pointer case, return value for this case will
also be PTR_TO_BTF_ID_OR_NULL. The reference for the returned pointer
must either be eventually released by calling the corresponding release
function, otherwise it must be transferred into another map.

It is also allowed to call bpf_kptr_xchg with a NULL pointer, to clear
the value, and obtain the old value if any.

BPF_LDX, BPF_STX, and BPF_ST cannot access referenced kptr. A future
commit will permit using BPF_LDX for such pointers, but attempt at
making it safe, since the lifetime of object won't be guaranteed.

There are valid reasons to enforce the restriction of permitting only
bpf_kptr_xchg to operate on referenced kptr. The pointer value must be
consistent in face of concurrent modification, and any prior values
contained in the map must also be released before a new one is moved
into the map. To ensure proper transfer of this ownership, bpf_kptr_xchg
returns the old value, which the verifier would require the user to
either free or move into another map, and releases the reference held
for the pointer being moved in.

In the future, direct BPF_XCHG instruction may also be permitted to work
like bpf_kptr_xchg helper.

Note that process_kptr_func doesn't have to call
check_helper_mem_access, since we already disallow rdonly/wronly flags
for map, which is what check_map_access_type checks, and we already
ensure the PTR_TO_MAP_VALUE refers to kptr by obtaining its off_desc,
so check_map_access is also not required.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220424214901.2743946-4-memxor@gmail.com
2022-04-25 20:26:05 -07:00
..
tc_act net: Move all TC actions identifiers to one place 2019-02-10 09:28:43 -08:00
bpf.h bpf: Allow storing referenced kptr in map 2022-04-25 20:26:05 -07:00
bpf_common.h bpf: Sync kernel ABI header with tooling header for bpf_common.h 2018-02-09 00:24:38 +01:00
bpf_perf_event.h tools, headers: Sync struct bpf_perf_event_data 2021-01-26 00:15:03 +01:00
btf.h bpf: Correct the comment for BTF kind bitfield 2022-04-03 17:06:52 -07:00
const.h tools headers UAPI: Sync linux/const.h with the kernel headers 2020-12-18 17:32:28 -03:00
erspan.h tools, include: Grab a copy of linux/erspan.h 2018-04-30 17:56:24 +02:00
ethtool.h tools: include: Add ethtool_drvinfo definition to UAPI header 2021-08-24 14:48:40 -07:00
fadvise.h tools headers uapi: Grab a copy of fadvise.h 2018-12-18 16:17:40 -03:00
fcntl.h tools headers API: Update faccessat2 affected files 2020-06-09 12:40:03 -03:00
filter.h tools: bpf: Use local copy of headers including uapi/linux/filter.h 2020-07-21 10:50:35 +01:00
fs.h tools headers UAPI: Sync linux/fs.h with the kernel sources 2021-09-11 16:14:53 -03:00
fscrypt.h tools headers UAPI: Sync linux/fscrypt.h with the kernel sources 2020-12-18 17:32:28 -03:00
hw_breakpoint.h tools/headers: Synchronize kernel ABI headers 2017-11-04 09:27:46 +01:00
if_link.h bonding: add new option ns_ip6_target 2022-02-21 12:13:45 +00:00
if_tun.h selftests/bpf: fix compilation error for flow_dissector.c 2019-05-29 15:15:07 +02:00
if_xdp.h xsk: Add new statistics 2020-07-13 15:32:56 -07:00
in.h tools headers UAPI: Sync linux/in.h copy with the kernel sources 2021-09-11 16:12:26 -03:00
kcmp.h tools headers: Synchronize kernel ABI headers wrt SPDX tags 2017-11-28 14:29:20 -03:00
kvm.h tools headers UAPI: Sync linux/kvm.h with the kernel sources 2022-04-01 16:19:35 -03:00
mman.h tools UAPI: Update copy of linux/mman.h from the kernel sources 2020-11-03 08:36:51 -03:00
mount.h tools include UAPI: Update linux/mount.h copy 2021-09-10 18:15:22 -03:00
netlink.h net: netlink: rename NETLINK_DUMP_STRICT_CHK -> NETLINK_GET_STRICT_CHK 2018-12-14 11:44:31 -08:00
openat2.h tools headers UAPI: Sync openat2.h with the kernel sources 2021-03-06 16:54:22 -03:00
perf_event.h Changes for this cycle were: 2022-03-22 13:06:49 -07:00
pkt_cls.h net: sched: remove NET_CLS_IND config option 2019-06-15 14:06:13 -07:00
pkt_sched.h sch_htb: Hierarchical QoS hardware offload 2021-01-22 20:41:29 -08:00
prctl.h tools headers UAPI: Sync linux/prctl.h with the kernel sources 2022-02-01 13:04:22 -03:00
sched.h tools headers UAPI: Sync sched.h with the kernel 2020-04-14 09:01:08 -03:00
seg6.h selftests/bpf: missing headers test_lwt_seg6local 2018-05-28 17:41:00 +02:00
seg6_local.h selftests/bpf: missing headers test_lwt_seg6local 2018-05-28 17:41:00 +02:00
stat.h tools headers UAPI: Sync linux/stat.h with the kernel sources 2020-12-17 14:40:24 -03:00
tcp.h bpf: Remove extra lock_sock for TCP_ZEROCOPY_RECEIVE 2021-01-20 14:23:00 -08:00
tls.h bpf, tls: add tls header to tools infrastructure 2018-10-16 08:10:01 -07:00
types.h tools/bpf: Move linux/types.h for selftests and bpftool 2020-03-13 20:56:34 +01:00
usbdevice_fs.h tools headers uapi: Sync linux/usbdevice_fs.h with the kernel sources 2019-09-30 17:29:02 -03:00
vhost.h tools kvm headers: Update KVM headers from the kernel sources 2020-11-03 08:46:30 -03:00