diff options
author | David Vernet <void@manifault.com> | 2023-03-25 16:31:42 -0500 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2023-03-25 16:56:22 -0700 |
commit | 1431d0b584a673ea690c88a5f7e1aedd9caf0e84 (patch) | |
tree | 52176b94e675a53d6b00772fdd112605e443391d /drivers/hid/bpf | |
parent | 55fbae05476df65e5eee8be54f61d0257af0240b (diff) | |
download | linux-stable-1431d0b584a673ea690c88a5f7e1aedd9caf0e84.tar.gz linux-stable-1431d0b584a673ea690c88a5f7e1aedd9caf0e84.tar.bz2 linux-stable-1431d0b584a673ea690c88a5f7e1aedd9caf0e84.zip |
bpf: Only invoke kptr dtor following non-NULL xchg
When a map value is being freed, we loop over all of the fields of the
corresponding BPF object and issue the appropriate cleanup calls
corresponding to the field's type. If the field is a referenced kptr, we
atomically xchg the value out of the map, and invoke the kptr's
destructor on whatever was there before (or bpf_obj_drop() it if it was
a local kptr).
Currently, we always invoke the destructor (either bpf_obj_drop() or the
kptr's registered destructor) on any KPTR_REF-type field in a map, even
if there wasn't a value in the map. This means that any function serving
as the kptr's KF_RELEASE destructor must always treat the argument as
possibly NULL, as the following can and regularly does happen:
void *xchgd_field;
/* No value was in the map, so xchgd_field is NULL */
xchgd_field = (void *)xchg(unsigned long *field_ptr, 0);
field->kptr.dtor(xchgd_field);
These are odd semantics to impose on KF_RELEASE kfuncs -- BPF programs
are prohibited by the verifier from passing NULL pointers to KF_RELEASE
kfuncs, so it doesn't make sense to require this of BPF programs, but
not the main kernel destructor path. It's also unnecessary to invoke any
cleanup logic for local kptrs. If there is no object there, there's
nothing to drop.
So as to allow KF_RELEASE kfuncs to fully assume that an argument is
non-NULL, this patch updates a KPTR_REF's destructor to only be invoked
when a non-NULL value is xchg'd out of the kptr map field.
Signed-off-by: David Vernet <void@manifault.com>
Link: https://lore.kernel.org/r/20230325213144.486885-2-void@manifault.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'drivers/hid/bpf')
0 files changed, 0 insertions, 0 deletions