IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an
email to Administrator. User accounts are meant only to access repo
and report issues and/or generate pull requests.
This is a purpose-specific Git hosting for
BaseALT
projects. Thank you for your understanding!
Только зарегистрированные пользователи имеют доступ к сервису!
Для получения аккаунта, обратитесь к администратору.
* bpf.c (print_ebpf_prog): Remove "decode" argument, all users updated.
(print_bpf_prog_info): Use the minimum of xlated_prog_len values on
entering and exiting syscall as the size of xlated_prog_insns array
to be decoded. Likewise, use the minimum of nr_map_ids values on entering
and exiting syscall as the size of map_ids array to be decoded.
* bpf.c (print_bpf_map_info): Print only those fields that are
present in the structure, as it has been growing over time.
(print_bpf_prog_info): Likewise. Print map_ids field as an array
of uint32_t instead of uint64_t; print "name" field.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
As it is needed for proper info_len printing on exiting.
* bpf.c (print_bpf_obj_info_fn): Change return type to void, add "saved"
argument.
(struct obj_get_info_saved): New type definition.
(print_bpf_map_info, print_bpf_prog_info): Change return type to void,
add "saved" argument, do not handle private tcb data allocation and
obtainment.
(print_bpf_obj_info_addr): Change return type to void, add tcb argument,
print the address only on exiting.
(print_bpf_obj_info): Change return type to void, add "saved" argument.
(BEGIN_BPF_CMD_DECODER(BPF_OBJ_GET_INFO_BY_FD)): Handle private data
allocation/saving/restoring, use it for storing/printing info_len field.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)): Print log_buf field
as a string.
* tests/bpf.c: Update expected output.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
If xlated_prog_len is zero on entering syscall and non-zero on exiting,
the program itself is not written into xlated_prog_insns.
* bpf.c (print_ebpf_prog): Add decode argument, print the address only
if decode is false.
(BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)): Specify decode == true argument
to print_ebpf_prog.
(print_bpf_prog_info): Specify saved xlated_prog_len as decode argument
to print_ebpf_prog.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
* bpf.c (print_ebpf_prog): Add static qualifier. Change the type
of "addr" argument from kernel_ulong_t to uint64_t, print it using
print_big_u64_addr.
(BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD), print_bpf_prog_info): Do not call
print_big_u64_addr before print_ebpf_prog.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
* bpf_attr.h [!BPF_TAG_SIZE] (BPF_TAG_SIZE): Define.
[BPF_TAG_SIZE]: Check that BPF_TAG_SIZE is 8.
(struct bpf_map_info_struct, struct bpf_prog_info_struct): New
structures.
(bpf_map_info_struct_size, expected_bpf_map_info_struct_size,
bpf_prog_info_struct_size, expected_bpf_prog_info_struct_size): New
macro constants.
* bpf.c (print_bpf_obj_info_fn): New type.
(print_bpf_map_info, print_bpf_prog_info, fetch_bpf_obj_info,
print_bpf_obj_info_addr, print_bpf_obj_info): New functions.
(BEGIN_BPF_CMD_DECODER(BPF_OBJ_GET_INFO_BY_FD)): Print bpf_fd and info_len
fields only on entering, call print_bpf_obj_info for printing info field.
* tests/bpf.c (BPF_OBJ_GET_INFO_BY_FD_checks): Print info field
as a pointer.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
As various bpf commands need different data to save between entering
and exiting of the syscall, do not emulate union bpf_attr approach.
* bpf.c (struct bpf_priv_data): Remove.
(DECL_BPF_CMD_DECODER): Remove "struct bpf_priv_data *" argument.
(BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)): Use set_tcb_priv_ulong
and get_tcb_priv_ulong to keep bpf_attr.query.prog_cnt field.
(SYS_FUNC(bpf)): Remove priv variable, do not initialize it,
and do not pass it to bpf_cmd_decoders.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)): Use
print_uint32_array_member instead of print_uint64_array_member for
printing prog_ids elements (and change the type of prog_id_buf from
uint64_t to uint32_t), as they are 32-bit; use common trick with
print_big_u64_addr for handling possible ambiguity with prog_ids
address.
* tests/bpf.c (BIG_ADDR_MAYBE): New macro.
(BPF_PROG_QUERY_checks): Update expected output.
* xlat/ebpf_regs.in: New file.
* bpf.c (struct ebpf_insn, struct ebpf_insns_data): New type definitions.
(print_ebpf_insn, print_ebpf_prog): New functions.
(DEF_BPF_CMD_DECODER(BPF_PROG_LOAD)): Use them.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_LOOKUP_ELEM),
BEGIN_BPF_CMD_DECODER(BPF_MAP_UPDATE_ELEM)): Print key and value
fields using PRINT_FIELD_ADDR64.
(BEGIN_BPF_CMD_DECODER(BPF_MAP_DELETE_ELEM)): Print key field using
PRINT_FIELD_ADDR64.
(BEGIN_BPF_CMD_DECODER(BPF_MAP_GET_NEXT_KEY)): Print key and next_key
field using PRINT_FIELD_ADDR64.
(BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)): Print insns and log_buf fields
using PRINT_FIELD_ADDR64.
(BEGIN_BPF_CMD_DECODER(BPF_PROG_TEST_RUN)): Print data_in and data_out
fields using PRINT_FIELD_ADDR64.
* tests/bpf.c: Update expected output.
The rest of the decoder uses offsetof to check the length.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_OBJ_PIN),
BEGIN_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID),
BEGIN_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID),
BEGIN_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID)): Use offsetof instead
of offsetofend.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_CREATE)): Decode map_name
and map_ifindex fields that were added in Linux commits
v4.15-rc1~84^2~605^2~3 and v4.16-rc1~123^2~145^2~5^2~8, respectively.
* bpf_attr.h (struct BPF_MAP_CREATE_struct): Add map_name
and map_ifindex fields.
* tests/bpf.c (init_BPF_MAP_CREATE_attr7): New function.
(BPF_MAP_CREATE_checks): Remove const qualifier, add two more checks.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_CREATE)): Skip printing
the rest of the structure if len is less than the offset of the end
of max_entries, map_flags, or inner_map_fd field.
* tests/bpf.c (BPF_MAP_CREATE_checks): Add two more checks.
As the value of -1 has a special meaning. The issue is complicated
by the fact that this constant is not exported by UAPI.
* xlat/numa_node.in: New file.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_CREATE)): Print numa_node field
using printxvals_ex with a special xlat style.
BPF_PROG_QUERY was introduced in Linux commit v4.15-rc1~84^2~558^2~6.
* xlat/bpf_commands.in (BPF_PROG_QUERY): New constant.
* xlat/bpf_query_flags.in: New file.
* bpf.c: Include it.
(DECL_BPF_CMD_DECODER): Add priv argument for passing tcb private data.
(BEGIN_BPF_CMD_DECODER(BPF_PROG_QUERY)): New function.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Add BPF_PROG_QUERY entry.
(SYS_FUNC(bpf)): Fetch buf on entering and exiting, pass buf on exiting,
retrieve private data on exiting, pass it to decoder as well, explicitly
rework rc handling logic for size argument printing.
* bpf_attr.h (struct BPF_PROG_QUERY_struct): New structure declaration.
(BPF_PROG_QUERY_struct_size, expected_BPF_PROG_QUERY_struct_size): New
macro.
* tests/bpf.c: Add checks for BPF_PROG_QUERY command.
* bpf.c (BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)): Add support for decoding
of prog_name (introduced in Linux commit v4.15-rc1~84^2~605^2~4) and
prog_ifindex (introduced as prog_target_ifindex in v4.15-rc1~84^2~127^2~13,
renamed in v4.15-rc1~15^2~5^2~3^2~7).
* bpf_attr.h [!BPF_OBJ_NAME_LEN] (BPF_OBJ_NAME_LEN): New macro constant.
[BPF_OBJ_NAME_LEN]: Check that BPF_OBJ_NAME_LEN is equal to 16.
(struct BPF_PROG_LOAD_struct): Add prog_name and prog_ifindex fields.
(BPF_PROG_LOAD_struct_size, expected_BPF_PROG_LOAD_struct_size): Update.
* tests/bpf.c (init_BPF_PROG_LOAD_attr): Rename
to init_BPF_PROG_LOAD_attr3.
(print_BPF_PROG_LOAD_attr): Rename to print_BPF_PROG_LOAD_attr3.
(init_BPF_PROG_LOAD_attr4, print_BPF_PROG_LOAD_attr4): New functions.
(BPF_PROG_LOAD_checks): Check new decoding features.
Since pointers stored in the bpf_attr union are 64-bit regardless
of architecture bitness.
* bpf.c (DEF_BPF_CMD_DECODER(BPF_PROG_LOAD)): Call print_big_u64_addr
for attr.license.
(DEF_BPF_CMD_DECODER(BPF_OBJ_PIN)): Call print_big_u64_addr
for attr.pathname.
* tests/bpf.c (BPF_OBJ_PIN_checks): Check it.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
These were introduced by Linux commit v4.15-rc1~84^2~384^2~4.
* bpf_attr.h (struct BPF_OBJ_PIN_struct): Add file_flags field.
(struct BPF_PROG_GET_NEXT_ID_struct, struct BPF_PROG_GET_FD_BY_ID_struct,
struct BPF_MAP_GET_FD_BY_ID_struct): Add open_flags field.
(BPF_OBJ_PIN_struct_size, expected_BPF_OBJ_PIN_struct_size,
expected_BPF_PROG_GET_NEXT_ID_struct_size,
expected_BPF_PROG_GET_FD_BY_ID_struct_size,
expected_BPF_MAP_GET_FD_BY_ID_struct_size): Update.
* bpf.c (DEF_BPF_CMD_DECODER(BPF_OBJ_PIN)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the bpf_fd field, print file_flags field otherwise.
(DEF_BPF_CMD_DECODER(BPF_PROG_GET_NEXT_ID),
DEF_BPF_CMD_DECODER(BPF_PROG_GET_FD_BY_ID),
DEF_BPF_CMD_DECODER(BPF_MAP_GET_FD_BY_ID)): Check the length, skip
printing the rest of attributes if it is less than offset of the
end of the next_id field, print open_flags field otherwise.
* xlat/bpf_file_mode_flags.in: New file.
* tests/bpf.c (BPF_OBJ_PIN_checks, BPF_PROG_GET_NEXT_ID_checks,
BPF_PROG_GET_FD_BY_ID_checks, BPF_MAP_GET_FD_BY_ID_checks): Check it.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
This also unifies decoders of bpf commands by moving common code
to new macros.
* bpf_attr.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* bpf.c: Include it.
(DEF_BPF_CMD_DECODER): Rename to BEGIN_BPF_CMD_DECODER, add code common
to all decoders. All users updated.
(END_BPF_CMD_DECODER): New macro, add its invocation to all users
of BEGIN_BPF_CMD_DECODER macro.
As it could be not entirely clear what bytes are printed.
* bpf.c (decode_attr_extra_data): Print a comment about the byte range
to be printed.
* tests/bpf.c: Update expected output.
As program attributes have been added gradually over kernel versions,
attribute size less than expected should be printed accordingly.
* bpf.c (DEF_BPF_CMD_DECODER(BPF_PROG_LOAD)): Do not print structure
fields if their size is less than the initially introduced (in Linux
commit v3.18-rc1~52^2~1^2~7) version. Print fields of union bpf_attr
introduced in various kernel versions when the length is big enough
(new fields were introduced in Linux commits v3.18-rc1~52^2~1^2~4,
v4.1-rc1~84^2~50, and v4.12-rc2~34^2~29^2~2).
* tests/bpf.c (print_BPF_PROG_LOAD_first): Update expected output.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
get_pagesize() has a static cache anyway, no need to duplicate it.
* bpf.c (SYS_FUNC(bpf)): Remove static size_t page_size and its
initialisation, use get_pagesize() as the size of buf directly.
* bpf.c (DEF_BPF_CMD_DECODER(BPF_PROG_LOAD)): Print
union bpf_attr.kern_version in the form of KERNEL_VERSION macro call.
* tests/bpf.c: Update expected output.
* configure.ac: Check for union bpf_attr.test.duration.
* bpf.c (decode_BPF_PROG_TEST_RUN): New function.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Use it.
* NEWS: Mention this.
* tests/bpf.c: Include "print_fields.h".
Add macro guard for BPF_PROG_TEST_RUN decoder test.
[HAVE_UNION_BPF_ATTR_TEST_DURATION] (sample_BPF_PROG_TEST_RUN_attr):
New variable.
[HAVE_UNION_BPF_ATTR_TEST_DURATION] (init_BPF_PROG_TEST_RUN_first,
print_BPF_PROG_TEST_RUN_first, init_BPF_PROG_TEST_RUN_attr,
print_BPF_PROG_TEST_RUN_attr): New functions.
(main) [HAVE_UNION_BPF_ATTR_TEST_DURATION]: Use them.
Implement decoding of union bpf_attr.numa_node field for BPF_MAP_CREATE
command introduced by linux kernel commit v4.14-rc1~130^2~196^2~1.
* configure.ac: Check for numa_node member of union bpf_attr
instead of inner_map_fd.
(decode_BPF_MAP_CREATE): Add numa_node field to the structure, print it.
* NEWS: Mention this.
* tests/bpf.c: Update macro guards of BPF_MAP_CREATE decoder test.
(init_BPF_MAP_CREATE_first, print_BPF_MAP_CREATE_attr): Update expected
output.
(init_BPF_MAP_CREATE_attr): Initialize numa_node field, update offset.
Print union bpf_attr.value field of BPF_MAP_LOOKUP_ELEM command
and union bpf_attr.next_key field of BPF_MAP_GET_NEXT_KEY command
on entering syscall. These fields are addresses specified to the
kernel from userspace. The amount of data written by the kernel
to these addresses is specified at the map creation time
by BPF_MAP_CREATE command and is not available at this point.
* bpf.c (decode_BPF_MAP_LOOKUP_ELEM): Print union bpf_attr.value
on entering syscall.
(decode_BPF_MAP_GET_NEXT_KEY): Print union bpf_attr.next_key
on entering syscall.
(bpf_map_io): Remove.
* tests/bpf.c (print_BPF_MAP_DELETE_ELEM_first,
print_BPF_MAP_DELETE_ELEM_attr, print_BPF_MAP_GET_NEXT_KEY_first,
print_BPF_MAP_GET_NEXT_KEY_attr): Replace macro redirects with
new functions.
(print_BPF_MAP_LOOKUP_ELEM_first, print_BPF_MAP_LOOKUP_ELEM_attr,
Implement decoding of map_flags and inner_map_fd fields of union bpf_attr
for BPF_MAP_CREATE command introduced by linux kernel commits
v4.6-rc1~91^2~108^2~6 and v4.12-rc1~64^3~373^2~2, respectively.
* configure.ac: Check for inner_map_fd member of union bpf_attr
instead of max_entries.
* xlat/bpf_map_flags.in: New file.
* bpf.c: Include "xlat/bpf_map_flags.h".
(decode_BPF_MAP_CREATE): Add map_flags and inner_map_fd fields
to the structure, print them.
* tests/bpf.c: Update macro guards of BPF_MAP_CREATE decoder test.
(init_BPF_MAP_CREATE_first, print_BPF_MAP_CREATE_attr): Update expected
output.
(init_BPF_MAP_CREATE_attr): Initialize map_flags and inner_map_fd
fields, update offset.
Implement decoding of union bpf_attr.prog_flags field for BPF_PROG_LOAD
command introduced by linux kernel commit v4.12-rc2~34^2~29^2~2.
* configure.ac: Check for prog_flags member of union bpf_attr
instead of kern_version.
* xlat/bpf_prog_flags.in: New file.
* bpf.c: Include "xlat/bpf_prog_flags.h".
(decode_BPF_PROG_LOAD): Add prog_flags field to the structure, print it.
* tests/bpf.c: Update macro guards of BPF_PROG_LOAD decoder test.
(init_BPF_PROG_LOAD_first, print_BPF_PROG_LOAD_attr): Update expected
output.
(init_BPF_PROG_LOAD_attr): Initialize prog_flags field, update offset.
When the size argument specifies more data than necessary for the given
command, kernel checks that all unused fields of union bpf_attr are
zero. Print this extra data when it contains non-zero bytes to enhance
debugging experience.
* bpf.c (decode_attr_extra_data): New function.
(decode_BPF_MAP_CREATE, decode_BPF_MAP_UPDATE_ELEM,
decode_BPF_MAP_DELETE_ELEM, bpf_map_io, decode_BPF_PROG_LOAD,
decode_BPF_OBJ_PIN, decode_BPF_OBJ_GET, decode_BPF_PROG_ATTACH,
decode_BPF_PROG_DETACH): Use it to print extra data passed
via bpf_attr pointer.
(bpf_obj_manage, bpf_prog_attach_detach): Remove.
* tests/bpf.c (map_delete_elem): New function.
(main): Use it.
When the size argument exceeds PAGE_SIZE, the kernel fails with E2BIG
without parsing union bpf_attr.
When the whole chunk of memory specified by addr and size arguments is
not readable, the kernel fails with EFAULT.
* bpf.c (DECL_BPF_CMD_DECODER) <bpf_cmd_decoder>: Add const qualifier
to size argument, add data argument.
(decode_BPF_MAP_CREATE, decode_BPF_MAP_UPDATE_ELEM,
decode_BPF_MAP_DELETE_ELEM, bpf_map_io, decode_BPF_PROG_LOAD,
bpf_obj_manage, bpf_prog_attach_detach): Move size argument check and
memory fetching ...
(SYS_FUNC(bpf)) ... here, add PAGE_SIZE check, pass fetched memory
to command-specific parsers.
* bpf.c (DECL_BPF_CMD_DECODER, DEF_BPF_CMD_DECODER, BPF_CMD_ENTRY):
New macros.
(bpf_cmd_decoder_t): New typedef.
Rename static parser functions using DEF_BPF_CMD_DECODER.
(decode_BPF_MAP_LOOKUP_ELEM, decode_BPF_MAP_GET_NEXT_KEY): New proxy
functions.
(SYS_FUNC(bpf)): Replace big switch statement with a dispatch table.
* print_fields.h (PRINT_FIELD_STR, PRINT_FIELD_PATH): New macros.
* bpf.c: Include "print_fields.h".
(bpf_map_create): Use PRINT_FIELD_U and PRINT_FIELD_XVAL.
(bpf_map_update_elem): Use PRINT_FIELD_FD, PRINT_FIELD_X, and
PRINT_FIELD_XVAL.
(bpf_map_delete_elem, bpf_map_io): Use PRINT_FIELD_FD and PRINT_FIELD_X.
(bpf_prog_load): Use PRINT_FIELD_STR, PRINT_FIELD_U, PRINT_FIELD_X,
and PRINT_FIELD_XVAL.
(bpf_obj_manage): Use PRINT_FIELD_FD and PRINT_FIELD_PATH.
(bpf_prog_attach_detach): Use PRINT_FIELD_FD, PRINT_FIELD_FLAGS,
and PRINT_FIELD_XVAL.
Implement decoding of BPF_F_ALLOW_OVERRIDE flag of BPF_PROG_ATTACH
command introduced by linux kernel commit v4.10-rc7-174-g7f67763.
* configure.ac: Check for union bpf_attr.attach_flags
instead of union bpf_attr.attach_type.
* xlat/bpf_attach_flags.in: New file.
* bpf.c: Include "xlat/bpf_attach_flags.h".
(bpf_prog_attach_detach): Rename print_attach_bpf_fd argument
to print_attach. Add attach_flags field to the structure,
print it in case of BPF_PROG_ATTACH.
* tests/bpf.c: Check for HAVE_UNION_BPF_ATTR_ATTACH_FLAGS
instead of HAVE_UNION_BPF_ATTR_ATTACH_TYPE.
(prog_cgroup): Initialize attach_flags field.
(main): Update expected output.
Implement decoding of BPF_OBJ_PIN, BPF_OBJ_GET, BPF_PROG_ATTACH,
and BPF_PROG_DETACH commands.
* bpf.c: Include "xlat/bpf_attach_type.h".
(bpf_obj_manage, bpf_prog_attach, bpf_prog_detach): New functions.
(SYS_FUNC(bpf)): Use them.
* configure.ac: Check for union bpf_attr.bpf_fd and union
bpf_attr.attach_type.
* xlat/bpf_attach_type.in: New file.
* xlat/bpf_commands.in: Update list of BPF_* command constants.
* xlat/bpf_map_types.in: Update list of BPF_MAP_TYPE_* constants.
* xlat/bpf_prog_types.in: Update list of BPF_PROG_TYPE_* constants.
* tests/bpf.c [HAVE_UNION_BPF_ATTR_BPF_FD] (obj_manage): New function.
[HAVE_UNION_BPF_ATTR_ATTACH_TYPE] (prog_cgroup): Likewise.
(main): Use them.
Remove temporary types created for transition from long
to kernel_ulong_t.
Automatically replace kernel_scno_t and kernel_ureg_t with
kernel_ulong_t using
$ git grep -El 'kernel_(scno|ureg)_t' |
xargs sed -ri 's/kernel_(scno|ureg)_t/kernel_ulong_t/g'
* kernel_types.h (kernel_scno_t, kernel_ureg_t): Remove.
All users updated.
As about half of all printstr uses cases are invocations with the last
argument set to -1, create a dedicated function for this use case.
* defs.h (printstr): Rename to printstrn. All callers updated.
(printstr): New static inline function. All callers updated.
* bpf.c (bpf_map_create, bpf_map_update_elem, bpf_map_delete_elem,
bpf_map_io, bpf_prog_load, SYS_FUNC(bpf)): Change address argument
type from long to kernel_ureg_t.