mirror of
https://github.com/netdata/libbpf.git
synced 2026-11-07 10:20:15 +08:00
libbpf: Reject local struct_ops bitfields before data access
A local struct_ops type can contain a bitfield absent from the
corresponding kernel BTF type. bpf_map__init_kern_struct_ops() checks
whether data for an absent local member is zero.
For a bitfield, member->offset contains the bit offset and field width.
bpf_map__init_kern_struct_ops() used the encoded value to calculate the
member data pointer before rejecting the bitfield. The zero-data check
could therefore read outside st_ops->data and crash libbpf.
Reject local bitfields before calculating the member data pointer. Keep
the existing rejection for bitfields in the kernel type.
Fixes: c911fc61a7ce ("libbpf: Skip zeroed or null fields if not found in the kernel type.")
Signed-off-by: Mingpei CAO <caomingpei@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Amery Hung <ameryhung@gmail.com>
Link: https://lore.kernel.org/bpf/20260915162252.473044-2-caomingpei@gmail.com
This commit is contained in:
1 parent
8afaa19944
commit
a1460c8580
1 file changed
+7
-2
+7
-2
@@ -1223,6 +1223,12 @@ static int bpf_map__init_kern_struct_ops(struct bpf_map *map)
|
||||
const char *mname;
|
||||
|
||||
mname = btf__name_by_offset(btf, member->name_off);
|
||||
if (btf_member_bitfield_size(type, i)) {
|
||||
pr_warn("struct_ops init_kern %s: local bitfield %s is not supported\n",
|
||||
map->name, mname);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
moff = member->offset / 8;
|
||||
mdata = data + moff;
|
||||
msize = btf__resolve_size(btf, member->type);
|
||||
@@ -1259,8 +1265,7 @@ static int bpf_map__init_kern_struct_ops(struct bpf_map *map)
|
||||
}
|
||||
|
||||
kern_member_idx = kern_member - btf_members(kern_type);
|
||||
if (btf_member_bitfield_size(type, i) ||
|
||||
btf_member_bitfield_size(kern_type, kern_member_idx)) {
|
||||
if (btf_member_bitfield_size(kern_type, kern_member_idx)) {
|
||||
pr_warn("struct_ops init_kern %s: bitfield %s is not supported\n",
|
||||
map->name, mname);
|
||||
return -ENOTSUP;
|
||||
|
||||
Reference in new issue
Block a user