2015-07-26 02:55:51 +03:00
/*
2017-07-25 15:47:19 +03:00
* Copyright ( c ) 2015 - 2017 Dmitry V . Levin < ldv @ altlinux . org >
2017-01-26 17:36:56 +03:00
* Copyright ( c ) 2017 Quentin Monnet < quentin . monnet @ 6 wind . com >
2015-07-26 02:55:51 +03:00
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
* 1. Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* 2. Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ` ` AS IS ' ' AND ANY EXPRESS OR
* IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED .
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT , INDIRECT ,
* INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT
* NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
# include "defs.h"
2017-07-25 15:47:19 +03:00
# include "print_fields.h"
2015-07-26 02:55:51 +03:00
# ifdef HAVE_LINUX_BPF_H
# include <linux / bpf.h>
# endif
2018-04-02 16:12:57 +03:00
# include "bpf_attr.h"
2015-07-26 02:55:51 +03:00
# include "xlat/bpf_commands.h"
bpf: add support for file mode flags
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>
2018-02-26 21:40:08 +03:00
# include "xlat/bpf_file_mode_flags.h"
2015-07-26 02:55:51 +03:00
# include "xlat/bpf_map_types.h"
2017-07-27 03:44:31 +03:00
# include "xlat/bpf_map_flags.h"
2015-07-26 02:55:51 +03:00
# include "xlat/bpf_prog_types.h"
2017-07-27 03:44:31 +03:00
# include "xlat/bpf_prog_flags.h"
2015-07-26 02:55:51 +03:00
# include "xlat/bpf_map_update_elem_flags.h"
2017-01-26 17:36:56 +03:00
# include "xlat/bpf_attach_type.h"
2017-02-17 03:05:00 +03:00
# include "xlat/bpf_attach_flags.h"
2015-07-26 02:55:51 +03:00
2017-07-25 15:47:19 +03:00
# define DECL_BPF_CMD_DECODER(bpf_cmd_decoder) \
int \
bpf_cmd_decoder ( struct tcb * const tcp , \
const kernel_ulong_t addr , \
bpf: change handling of big and unaccessible data to match the kernel
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.
2017-07-26 13:28:25 +03:00
const unsigned int size , \
void * const data ) \
2017-07-25 15:47:19 +03:00
/* End of DECL_BPF_CMD_DECODER definition. */
2018-04-02 16:12:57 +03:00
# define BEGIN_BPF_CMD_DECODER(bpf_cmd) \
static DECL_BPF_CMD_DECODER ( decode_ # # bpf_cmd ) \
{ \
struct bpf_cmd # # _struct attr = { } ; \
const size_t attr_size = bpf_cmd # # _struct_size ; \
const unsigned int len = MIN ( size , attr_size ) ; \
memcpy ( & attr , data , len ) ; \
do { \
/* End of BEGIN_BPF_CMD_DECODER definition. */
# define END_BPF_CMD_DECODER(rval) \
decode_attr_extra_data ( tcp , data , size , attr_size ) ; \
} while ( 0 ) ; \
tprints ( " } " ) ; \
return ( rval ) ; \
} \
/* End of END_BPF_CMD_DECODER definition. */
2017-07-25 15:47:19 +03:00
# define BPF_CMD_ENTRY(bpf_cmd) \
[ bpf_cmd ] = decode_ # # bpf_cmd
typedef DECL_BPF_CMD_DECODER ( ( * bpf_cmd_decoder_t ) ) ;
bpf: print unused fields of union bpf_attr if one of them is non-zero
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.
2017-07-26 13:28:25 +03:00
static int
decode_attr_extra_data ( struct tcb * const tcp ,
const char * data ,
unsigned int size ,
const size_t attr_size )
{
if ( size < = attr_size )
return 0 ;
data + = attr_size ;
size - = attr_size ;
unsigned int i ;
for ( i = 0 ; i < size ; + + i ) {
if ( data [ i ] ) {
tprints ( " , " ) ;
2018-03-03 05:13:35 +03:00
if ( abbrev ( tcp ) ) {
bpf: print unused fields of union bpf_attr if one of them is non-zero
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.
2017-07-26 13:28:25 +03:00
tprints ( " ... " ) ;
2018-03-03 05:13:35 +03:00
} else {
tprintf ( " /* bytes %zu..%zu */ " ,
attr_size , attr_size + size - 1 ) ;
bpf: print unused fields of union bpf_attr if one of them is non-zero
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.
2017-07-26 13:28:25 +03:00
print_quoted_string ( data , size ,
QUOTE_FORCE_HEX ) ;
2018-03-03 05:13:35 +03:00
}
bpf: print unused fields of union bpf_attr if one of them is non-zero
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.
2017-07-26 13:28:25 +03:00
return RVAL_DECODED ;
}
}
return 0 ;
}
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_MAP_CREATE )
2015-07-26 02:55:51 +03:00
{
bpf: change handling of big and unaccessible data to match the kernel
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.
2017-07-26 13:28:25 +03:00
PRINT_FIELD_XVAL ( " { " , attr , map_type , bpf_map_types ,
" BPF_MAP_TYPE_??? " ) ;
2017-07-25 15:47:19 +03:00
PRINT_FIELD_U ( " , " , attr , key_size ) ;
PRINT_FIELD_U ( " , " , attr , value_size ) ;
PRINT_FIELD_U ( " , " , attr , max_entries ) ;
2017-07-27 03:44:31 +03:00
PRINT_FIELD_FLAGS ( " , " , attr , map_flags , bpf_map_flags , " BPF_F_??? " ) ;
PRINT_FIELD_FD ( " , " , attr , inner_map_fd , tcp ) ;
2017-11-20 02:38:58 +03:00
if ( attr . map_flags & BPF_F_NUMA_NODE )
PRINT_FIELD_U ( " , " , attr , numa_node ) ;
2015-07-26 02:55:51 +03:00
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED | RVAL_FD )
2015-07-26 02:55:51 +03:00
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_MAP_LOOKUP_ELEM )
2017-07-27 23:11:33 +03:00
{
PRINT_FIELD_FD ( " { " , attr , map_fd , tcp ) ;
PRINT_FIELD_X ( " , " , attr , key ) ;
PRINT_FIELD_X ( " , " , attr , value ) ;
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED )
2017-07-27 23:11:33 +03:00
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_MAP_UPDATE_ELEM )
2015-07-26 02:55:51 +03:00
{
2017-07-25 15:47:19 +03:00
PRINT_FIELD_FD ( " { " , attr , map_fd , tcp ) ;
PRINT_FIELD_X ( " , " , attr , key ) ;
PRINT_FIELD_X ( " , " , attr , value ) ;
PRINT_FIELD_XVAL ( " , " , attr , flags , bpf_map_update_elem_flags ,
" BPF_??? " ) ;
2015-07-26 02:55:51 +03:00
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED )
2015-07-26 02:55:51 +03:00
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_MAP_DELETE_ELEM )
2015-07-26 02:55:51 +03:00
{
2017-07-25 15:47:19 +03:00
PRINT_FIELD_FD ( " { " , attr , map_fd , tcp ) ;
PRINT_FIELD_X ( " , " , attr , key ) ;
2015-07-26 02:55:51 +03:00
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED )
2015-07-26 02:55:51 +03:00
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_MAP_GET_NEXT_KEY )
2015-07-26 02:55:51 +03:00
{
2017-07-25 15:47:19 +03:00
PRINT_FIELD_FD ( " { " , attr , map_fd , tcp ) ;
PRINT_FIELD_X ( " , " , attr , key ) ;
2017-07-27 23:11:33 +03:00
PRINT_FIELD_X ( " , " , attr , next_key ) ;
2017-07-25 15:47:19 +03:00
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED )
2017-07-25 15:47:19 +03:00
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_PROG_LOAD )
2015-07-26 02:55:51 +03:00
{
bpf: change handling of big and unaccessible data to match the kernel
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.
2017-07-26 13:28:25 +03:00
PRINT_FIELD_XVAL ( " { " , attr , prog_type , bpf_prog_types ,
" BPF_PROG_TYPE_??? " ) ;
2017-07-25 15:47:19 +03:00
PRINT_FIELD_U ( " , " , attr , insn_cnt ) ;
PRINT_FIELD_X ( " , " , attr , insns ) ;
PRINT_FIELD_STR ( " , " , attr , license , tcp ) ;
2018-02-22 05:17:04 +03:00
/* log_* fields were added in Linux commit v3.18-rc1~52^2~1^2~4. */
2018-04-02 16:12:57 +03:00
if ( len < = offsetof ( struct BPF_PROG_LOAD_struct , log_level ) )
break ;
2017-07-25 15:47:19 +03:00
PRINT_FIELD_U ( " , " , attr , log_level ) ;
PRINT_FIELD_U ( " , " , attr , log_size ) ;
PRINT_FIELD_X ( " , " , attr , log_buf ) ;
2018-02-22 05:17:04 +03:00
/* kern_version field was added in Linux commit v4.1-rc1~84^2~50. */
2018-04-02 16:12:57 +03:00
if ( len < = offsetof ( struct BPF_PROG_LOAD_struct , kern_version ) )
break ;
2018-02-22 04:44:04 +03:00
tprintf ( " , kern_version=KERNEL_VERSION(%u, %u, %u) " ,
attr . kern_version > > 16 ,
( attr . kern_version > > 8 ) & 0xFF ,
attr . kern_version & 0xFF ) ;
2018-02-22 05:17:04 +03:00
/* prog_flags field was added in Linux commit v4.12-rc2~34^2~29^2~2. */
2018-04-02 16:12:57 +03:00
if ( len < = offsetof ( struct BPF_PROG_LOAD_struct , prog_flags ) )
break ;
2017-07-27 03:44:31 +03:00
PRINT_FIELD_FLAGS ( " , " , attr , prog_flags , bpf_prog_flags , " BPF_F_??? " ) ;
2015-07-26 02:55:51 +03:00
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED | RVAL_FD )
2015-07-26 02:55:51 +03:00
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_OBJ_PIN )
2017-01-26 17:36:56 +03:00
{
2017-07-25 15:47:19 +03:00
PRINT_FIELD_PATH ( " { " , attr , pathname , tcp ) ;
PRINT_FIELD_FD ( " , " , attr , bpf_fd , tcp ) ;
bpf: add support for file mode flags
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>
2018-02-26 21:40:08 +03:00
if ( len < = offsetofend ( struct BPF_OBJ_PIN_struct , bpf_fd ) )
break ;
/* file_flags field was added in Linux v4.15-rc1~84^2~384^2~4 */
PRINT_FIELD_FLAGS ( " , " , attr , file_flags , bpf_file_mode_flags ,
" BPF_F_??? " ) ;
2017-01-26 17:36:56 +03:00
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED | RVAL_FD )
2017-01-26 17:36:56 +03:00
bpf: print unused fields of union bpf_attr if one of them is non-zero
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.
2017-07-26 13:28:25 +03:00
# define decode_BPF_OBJ_GET decode_BPF_OBJ_PIN
2017-07-25 15:47:19 +03:00
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_PROG_ATTACH )
2017-01-26 17:36:56 +03:00
{
2017-07-25 15:47:19 +03:00
PRINT_FIELD_FD ( " { " , attr , target_fd , tcp ) ;
bpf: print unused fields of union bpf_attr if one of them is non-zero
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.
2017-07-26 13:28:25 +03:00
PRINT_FIELD_FD ( " , " , attr , attach_bpf_fd , tcp ) ;
2017-07-25 15:47:19 +03:00
PRINT_FIELD_XVAL ( " , " , attr , attach_type , bpf_attach_type , " BPF_??? " ) ;
bpf: print unused fields of union bpf_attr if one of them is non-zero
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.
2017-07-26 13:28:25 +03:00
PRINT_FIELD_FLAGS ( " , " , attr , attach_flags , bpf_attach_flags ,
" BPF_F_??? " ) ;
2017-01-26 17:36:56 +03:00
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED )
2017-01-26 17:36:56 +03:00
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_PROG_DETACH )
2017-01-29 01:11:20 +03:00
{
bpf: print unused fields of union bpf_attr if one of them is non-zero
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.
2017-07-26 13:28:25 +03:00
PRINT_FIELD_FD ( " { " , attr , target_fd , tcp ) ;
PRINT_FIELD_XVAL ( " , " , attr , attach_type , bpf_attach_type , " BPF_??? " ) ;
2017-01-26 17:36:56 +03:00
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED )
2017-01-26 17:36:56 +03:00
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_PROG_TEST_RUN )
2017-11-20 03:29:10 +03:00
{
PRINT_FIELD_FD ( " {test={ " , attr , prog_fd , tcp ) ;
PRINT_FIELD_U ( " , " , attr , retval ) ;
PRINT_FIELD_U ( " , " , attr , data_size_in ) ;
PRINT_FIELD_U ( " , " , attr , data_size_out ) ;
PRINT_FIELD_X ( " , " , attr , data_in ) ;
PRINT_FIELD_X ( " , " , attr , data_out ) ;
PRINT_FIELD_U ( " , " , attr , repeat ) ;
PRINT_FIELD_U ( " , " , attr , duration ) ;
tprints ( " } " ) ;
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED )
2017-11-20 03:29:10 +03:00
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_PROG_GET_NEXT_ID )
Implement decoding of BPF_*_GET_*_ID commands of bpf syscall
* configure.ac: Check for union bpf_attr.next_id.
* bpf.c (decode_BPF_PROG_GET_NEXT_ID, decode_BPF_PROG_GET_FD_BY_ID,
* decode_BPF_MAP_GET_FD_BY_ID): New functions.
(decode_BPF_MAP_GET_NEXT_ID): New macro.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Use them.
* NEWS: Mention this.
* tests/bpf.c: Add macro guard for BPF_*_GET_*_ID decoder tests.
[HAVE_UNION_BPF_ATTR_NEXT_ID] (init_BPF_PROG_GET_NEXT_ID_first,
print_BPF_PROG_GET_NEXT_ID_first, init_BPF_PROG_GET_NEXT_ID_attr,
print_BPF_PROG_GET_NEXT_ID_attr, print_BPF_PROG_GET_FD_BY_ID_first,
print_BPF_PROG_GET_FD_BY_ID_attr, print_BPF_MAP_GET_NEXT_ID_first,
print_BPF_MAP_GET_NEXT_ID_attr): New functions.
(init_BPF_MAP_GET_NEXT_ID_first, print_BPF_MAP_GET_NEXT_ID_first,
init_BPF_MAP_GET_NEXT_ID_attr, print_BPF_MAP_GET_NEXT_ID_attr,
init_BPF_PROG_GET_FD_BY_ID_first, init_BPF_PROG_GET_FD_BY_ID_attr,
init_BPF_MAP_GET_FD_BY_ID_first, init_BPF_MAP_GET_FD_BY_ID_attr):
New macros.
(main) [HAVE_UNION_BPF_ATTR_NEXT_ID]: Use them.
2017-11-22 00:08:19 +03:00
{
PRINT_FIELD_U ( " { " , attr , start_id ) ;
PRINT_FIELD_U ( " , " , attr , next_id ) ;
bpf: add support for file mode flags
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>
2018-02-26 21:40:08 +03:00
if ( len < = offsetofend ( struct BPF_PROG_GET_NEXT_ID_struct , next_id ) )
break ;
/* open_flags field has been added in Linux v4.15-rc1~84^2~384^2~4 */
PRINT_FIELD_FLAGS ( " , " , attr , open_flags , bpf_file_mode_flags ,
" BPF_F_??? " ) ;
Implement decoding of BPF_*_GET_*_ID commands of bpf syscall
* configure.ac: Check for union bpf_attr.next_id.
* bpf.c (decode_BPF_PROG_GET_NEXT_ID, decode_BPF_PROG_GET_FD_BY_ID,
* decode_BPF_MAP_GET_FD_BY_ID): New functions.
(decode_BPF_MAP_GET_NEXT_ID): New macro.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Use them.
* NEWS: Mention this.
* tests/bpf.c: Add macro guard for BPF_*_GET_*_ID decoder tests.
[HAVE_UNION_BPF_ATTR_NEXT_ID] (init_BPF_PROG_GET_NEXT_ID_first,
print_BPF_PROG_GET_NEXT_ID_first, init_BPF_PROG_GET_NEXT_ID_attr,
print_BPF_PROG_GET_NEXT_ID_attr, print_BPF_PROG_GET_FD_BY_ID_first,
print_BPF_PROG_GET_FD_BY_ID_attr, print_BPF_MAP_GET_NEXT_ID_first,
print_BPF_MAP_GET_NEXT_ID_attr): New functions.
(init_BPF_MAP_GET_NEXT_ID_first, print_BPF_MAP_GET_NEXT_ID_first,
init_BPF_MAP_GET_NEXT_ID_attr, print_BPF_MAP_GET_NEXT_ID_attr,
init_BPF_PROG_GET_FD_BY_ID_first, init_BPF_PROG_GET_FD_BY_ID_attr,
init_BPF_MAP_GET_FD_BY_ID_first, init_BPF_MAP_GET_FD_BY_ID_attr):
New macros.
(main) [HAVE_UNION_BPF_ATTR_NEXT_ID]: Use them.
2017-11-22 00:08:19 +03:00
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED )
Implement decoding of BPF_*_GET_*_ID commands of bpf syscall
* configure.ac: Check for union bpf_attr.next_id.
* bpf.c (decode_BPF_PROG_GET_NEXT_ID, decode_BPF_PROG_GET_FD_BY_ID,
* decode_BPF_MAP_GET_FD_BY_ID): New functions.
(decode_BPF_MAP_GET_NEXT_ID): New macro.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Use them.
* NEWS: Mention this.
* tests/bpf.c: Add macro guard for BPF_*_GET_*_ID decoder tests.
[HAVE_UNION_BPF_ATTR_NEXT_ID] (init_BPF_PROG_GET_NEXT_ID_first,
print_BPF_PROG_GET_NEXT_ID_first, init_BPF_PROG_GET_NEXT_ID_attr,
print_BPF_PROG_GET_NEXT_ID_attr, print_BPF_PROG_GET_FD_BY_ID_first,
print_BPF_PROG_GET_FD_BY_ID_attr, print_BPF_MAP_GET_NEXT_ID_first,
print_BPF_MAP_GET_NEXT_ID_attr): New functions.
(init_BPF_MAP_GET_NEXT_ID_first, print_BPF_MAP_GET_NEXT_ID_first,
init_BPF_MAP_GET_NEXT_ID_attr, print_BPF_MAP_GET_NEXT_ID_attr,
init_BPF_PROG_GET_FD_BY_ID_first, init_BPF_PROG_GET_FD_BY_ID_attr,
init_BPF_MAP_GET_FD_BY_ID_first, init_BPF_MAP_GET_FD_BY_ID_attr):
New macros.
(main) [HAVE_UNION_BPF_ATTR_NEXT_ID]: Use them.
2017-11-22 00:08:19 +03:00
# define decode_BPF_MAP_GET_NEXT_ID decode_BPF_PROG_GET_NEXT_ID
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_PROG_GET_FD_BY_ID )
Implement decoding of BPF_*_GET_*_ID commands of bpf syscall
* configure.ac: Check for union bpf_attr.next_id.
* bpf.c (decode_BPF_PROG_GET_NEXT_ID, decode_BPF_PROG_GET_FD_BY_ID,
* decode_BPF_MAP_GET_FD_BY_ID): New functions.
(decode_BPF_MAP_GET_NEXT_ID): New macro.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Use them.
* NEWS: Mention this.
* tests/bpf.c: Add macro guard for BPF_*_GET_*_ID decoder tests.
[HAVE_UNION_BPF_ATTR_NEXT_ID] (init_BPF_PROG_GET_NEXT_ID_first,
print_BPF_PROG_GET_NEXT_ID_first, init_BPF_PROG_GET_NEXT_ID_attr,
print_BPF_PROG_GET_NEXT_ID_attr, print_BPF_PROG_GET_FD_BY_ID_first,
print_BPF_PROG_GET_FD_BY_ID_attr, print_BPF_MAP_GET_NEXT_ID_first,
print_BPF_MAP_GET_NEXT_ID_attr): New functions.
(init_BPF_MAP_GET_NEXT_ID_first, print_BPF_MAP_GET_NEXT_ID_first,
init_BPF_MAP_GET_NEXT_ID_attr, print_BPF_MAP_GET_NEXT_ID_attr,
init_BPF_PROG_GET_FD_BY_ID_first, init_BPF_PROG_GET_FD_BY_ID_attr,
init_BPF_MAP_GET_FD_BY_ID_first, init_BPF_MAP_GET_FD_BY_ID_attr):
New macros.
(main) [HAVE_UNION_BPF_ATTR_NEXT_ID]: Use them.
2017-11-22 00:08:19 +03:00
{
PRINT_FIELD_U ( " { " , attr , prog_id ) ;
PRINT_FIELD_U ( " , " , attr , next_id ) ;
bpf: add support for file mode flags
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>
2018-02-26 21:40:08 +03:00
if ( len < = offsetofend ( struct BPF_PROG_GET_FD_BY_ID_struct , next_id ) )
break ;
/* open_flags field has been added in Linux v4.15-rc1~84^2~384^2~4 */
PRINT_FIELD_FLAGS ( " , " , attr , open_flags , bpf_file_mode_flags ,
" BPF_F_??? " ) ;
Implement decoding of BPF_*_GET_*_ID commands of bpf syscall
* configure.ac: Check for union bpf_attr.next_id.
* bpf.c (decode_BPF_PROG_GET_NEXT_ID, decode_BPF_PROG_GET_FD_BY_ID,
* decode_BPF_MAP_GET_FD_BY_ID): New functions.
(decode_BPF_MAP_GET_NEXT_ID): New macro.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Use them.
* NEWS: Mention this.
* tests/bpf.c: Add macro guard for BPF_*_GET_*_ID decoder tests.
[HAVE_UNION_BPF_ATTR_NEXT_ID] (init_BPF_PROG_GET_NEXT_ID_first,
print_BPF_PROG_GET_NEXT_ID_first, init_BPF_PROG_GET_NEXT_ID_attr,
print_BPF_PROG_GET_NEXT_ID_attr, print_BPF_PROG_GET_FD_BY_ID_first,
print_BPF_PROG_GET_FD_BY_ID_attr, print_BPF_MAP_GET_NEXT_ID_first,
print_BPF_MAP_GET_NEXT_ID_attr): New functions.
(init_BPF_MAP_GET_NEXT_ID_first, print_BPF_MAP_GET_NEXT_ID_first,
init_BPF_MAP_GET_NEXT_ID_attr, print_BPF_MAP_GET_NEXT_ID_attr,
init_BPF_PROG_GET_FD_BY_ID_first, init_BPF_PROG_GET_FD_BY_ID_attr,
init_BPF_MAP_GET_FD_BY_ID_first, init_BPF_MAP_GET_FD_BY_ID_attr):
New macros.
(main) [HAVE_UNION_BPF_ATTR_NEXT_ID]: Use them.
2017-11-22 00:08:19 +03:00
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED )
Implement decoding of BPF_*_GET_*_ID commands of bpf syscall
* configure.ac: Check for union bpf_attr.next_id.
* bpf.c (decode_BPF_PROG_GET_NEXT_ID, decode_BPF_PROG_GET_FD_BY_ID,
* decode_BPF_MAP_GET_FD_BY_ID): New functions.
(decode_BPF_MAP_GET_NEXT_ID): New macro.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Use them.
* NEWS: Mention this.
* tests/bpf.c: Add macro guard for BPF_*_GET_*_ID decoder tests.
[HAVE_UNION_BPF_ATTR_NEXT_ID] (init_BPF_PROG_GET_NEXT_ID_first,
print_BPF_PROG_GET_NEXT_ID_first, init_BPF_PROG_GET_NEXT_ID_attr,
print_BPF_PROG_GET_NEXT_ID_attr, print_BPF_PROG_GET_FD_BY_ID_first,
print_BPF_PROG_GET_FD_BY_ID_attr, print_BPF_MAP_GET_NEXT_ID_first,
print_BPF_MAP_GET_NEXT_ID_attr): New functions.
(init_BPF_MAP_GET_NEXT_ID_first, print_BPF_MAP_GET_NEXT_ID_first,
init_BPF_MAP_GET_NEXT_ID_attr, print_BPF_MAP_GET_NEXT_ID_attr,
init_BPF_PROG_GET_FD_BY_ID_first, init_BPF_PROG_GET_FD_BY_ID_attr,
init_BPF_MAP_GET_FD_BY_ID_first, init_BPF_MAP_GET_FD_BY_ID_attr):
New macros.
(main) [HAVE_UNION_BPF_ATTR_NEXT_ID]: Use them.
2017-11-22 00:08:19 +03:00
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_MAP_GET_FD_BY_ID )
Implement decoding of BPF_*_GET_*_ID commands of bpf syscall
* configure.ac: Check for union bpf_attr.next_id.
* bpf.c (decode_BPF_PROG_GET_NEXT_ID, decode_BPF_PROG_GET_FD_BY_ID,
* decode_BPF_MAP_GET_FD_BY_ID): New functions.
(decode_BPF_MAP_GET_NEXT_ID): New macro.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Use them.
* NEWS: Mention this.
* tests/bpf.c: Add macro guard for BPF_*_GET_*_ID decoder tests.
[HAVE_UNION_BPF_ATTR_NEXT_ID] (init_BPF_PROG_GET_NEXT_ID_first,
print_BPF_PROG_GET_NEXT_ID_first, init_BPF_PROG_GET_NEXT_ID_attr,
print_BPF_PROG_GET_NEXT_ID_attr, print_BPF_PROG_GET_FD_BY_ID_first,
print_BPF_PROG_GET_FD_BY_ID_attr, print_BPF_MAP_GET_NEXT_ID_first,
print_BPF_MAP_GET_NEXT_ID_attr): New functions.
(init_BPF_MAP_GET_NEXT_ID_first, print_BPF_MAP_GET_NEXT_ID_first,
init_BPF_MAP_GET_NEXT_ID_attr, print_BPF_MAP_GET_NEXT_ID_attr,
init_BPF_PROG_GET_FD_BY_ID_first, init_BPF_PROG_GET_FD_BY_ID_attr,
init_BPF_MAP_GET_FD_BY_ID_first, init_BPF_MAP_GET_FD_BY_ID_attr):
New macros.
(main) [HAVE_UNION_BPF_ATTR_NEXT_ID]: Use them.
2017-11-22 00:08:19 +03:00
{
PRINT_FIELD_U ( " { " , attr , map_id ) ;
PRINT_FIELD_U ( " , " , attr , next_id ) ;
bpf: add support for file mode flags
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>
2018-02-26 21:40:08 +03:00
if ( len < = offsetofend ( struct BPF_MAP_GET_FD_BY_ID_struct , next_id ) )
break ;
/* open_flags field has been added in Linux v4.15-rc1~84^2~384^2~4 */
PRINT_FIELD_FLAGS ( " , " , attr , open_flags , bpf_file_mode_flags ,
" BPF_F_??? " ) ;
Implement decoding of BPF_*_GET_*_ID commands of bpf syscall
* configure.ac: Check for union bpf_attr.next_id.
* bpf.c (decode_BPF_PROG_GET_NEXT_ID, decode_BPF_PROG_GET_FD_BY_ID,
* decode_BPF_MAP_GET_FD_BY_ID): New functions.
(decode_BPF_MAP_GET_NEXT_ID): New macro.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Use them.
* NEWS: Mention this.
* tests/bpf.c: Add macro guard for BPF_*_GET_*_ID decoder tests.
[HAVE_UNION_BPF_ATTR_NEXT_ID] (init_BPF_PROG_GET_NEXT_ID_first,
print_BPF_PROG_GET_NEXT_ID_first, init_BPF_PROG_GET_NEXT_ID_attr,
print_BPF_PROG_GET_NEXT_ID_attr, print_BPF_PROG_GET_FD_BY_ID_first,
print_BPF_PROG_GET_FD_BY_ID_attr, print_BPF_MAP_GET_NEXT_ID_first,
print_BPF_MAP_GET_NEXT_ID_attr): New functions.
(init_BPF_MAP_GET_NEXT_ID_first, print_BPF_MAP_GET_NEXT_ID_first,
init_BPF_MAP_GET_NEXT_ID_attr, print_BPF_MAP_GET_NEXT_ID_attr,
init_BPF_PROG_GET_FD_BY_ID_first, init_BPF_PROG_GET_FD_BY_ID_attr,
init_BPF_MAP_GET_FD_BY_ID_first, init_BPF_MAP_GET_FD_BY_ID_attr):
New macros.
(main) [HAVE_UNION_BPF_ATTR_NEXT_ID]: Use them.
2017-11-22 00:08:19 +03:00
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED )
Implement decoding of BPF_*_GET_*_ID commands of bpf syscall
* configure.ac: Check for union bpf_attr.next_id.
* bpf.c (decode_BPF_PROG_GET_NEXT_ID, decode_BPF_PROG_GET_FD_BY_ID,
* decode_BPF_MAP_GET_FD_BY_ID): New functions.
(decode_BPF_MAP_GET_NEXT_ID): New macro.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Use them.
* NEWS: Mention this.
* tests/bpf.c: Add macro guard for BPF_*_GET_*_ID decoder tests.
[HAVE_UNION_BPF_ATTR_NEXT_ID] (init_BPF_PROG_GET_NEXT_ID_first,
print_BPF_PROG_GET_NEXT_ID_first, init_BPF_PROG_GET_NEXT_ID_attr,
print_BPF_PROG_GET_NEXT_ID_attr, print_BPF_PROG_GET_FD_BY_ID_first,
print_BPF_PROG_GET_FD_BY_ID_attr, print_BPF_MAP_GET_NEXT_ID_first,
print_BPF_MAP_GET_NEXT_ID_attr): New functions.
(init_BPF_MAP_GET_NEXT_ID_first, print_BPF_MAP_GET_NEXT_ID_first,
init_BPF_MAP_GET_NEXT_ID_attr, print_BPF_MAP_GET_NEXT_ID_attr,
init_BPF_PROG_GET_FD_BY_ID_first, init_BPF_PROG_GET_FD_BY_ID_attr,
init_BPF_MAP_GET_FD_BY_ID_first, init_BPF_MAP_GET_FD_BY_ID_attr):
New macros.
(main) [HAVE_UNION_BPF_ATTR_NEXT_ID]: Use them.
2017-11-22 00:08:19 +03:00
2018-04-02 16:12:57 +03:00
BEGIN_BPF_CMD_DECODER ( BPF_OBJ_GET_INFO_BY_FD )
2017-11-22 02:12:04 +03:00
{
PRINT_FIELD_FD ( " {info={ " , attr , bpf_fd , tcp ) ;
PRINT_FIELD_U ( " , " , attr , info_len ) ;
PRINT_FIELD_X ( " , " , attr , info ) ;
tprints ( " } " ) ;
}
2018-04-02 16:12:57 +03:00
END_BPF_CMD_DECODER ( RVAL_DECODED | RVAL_FD )
2017-11-22 02:12:04 +03:00
2015-07-26 02:55:51 +03:00
SYS_FUNC ( bpf )
{
2017-07-25 15:47:19 +03:00
static const bpf_cmd_decoder_t bpf_cmd_decoders [ ] = {
BPF_CMD_ENTRY ( BPF_MAP_CREATE ) ,
BPF_CMD_ENTRY ( BPF_MAP_LOOKUP_ELEM ) ,
BPF_CMD_ENTRY ( BPF_MAP_UPDATE_ELEM ) ,
BPF_CMD_ENTRY ( BPF_MAP_DELETE_ELEM ) ,
BPF_CMD_ENTRY ( BPF_MAP_GET_NEXT_KEY ) ,
BPF_CMD_ENTRY ( BPF_PROG_LOAD ) ,
BPF_CMD_ENTRY ( BPF_OBJ_PIN ) ,
BPF_CMD_ENTRY ( BPF_OBJ_GET ) ,
BPF_CMD_ENTRY ( BPF_PROG_ATTACH ) ,
BPF_CMD_ENTRY ( BPF_PROG_DETACH ) ,
2017-11-20 03:29:10 +03:00
BPF_CMD_ENTRY ( BPF_PROG_TEST_RUN ) ,
Implement decoding of BPF_*_GET_*_ID commands of bpf syscall
* configure.ac: Check for union bpf_attr.next_id.
* bpf.c (decode_BPF_PROG_GET_NEXT_ID, decode_BPF_PROG_GET_FD_BY_ID,
* decode_BPF_MAP_GET_FD_BY_ID): New functions.
(decode_BPF_MAP_GET_NEXT_ID): New macro.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Use them.
* NEWS: Mention this.
* tests/bpf.c: Add macro guard for BPF_*_GET_*_ID decoder tests.
[HAVE_UNION_BPF_ATTR_NEXT_ID] (init_BPF_PROG_GET_NEXT_ID_first,
print_BPF_PROG_GET_NEXT_ID_first, init_BPF_PROG_GET_NEXT_ID_attr,
print_BPF_PROG_GET_NEXT_ID_attr, print_BPF_PROG_GET_FD_BY_ID_first,
print_BPF_PROG_GET_FD_BY_ID_attr, print_BPF_MAP_GET_NEXT_ID_first,
print_BPF_MAP_GET_NEXT_ID_attr): New functions.
(init_BPF_MAP_GET_NEXT_ID_first, print_BPF_MAP_GET_NEXT_ID_first,
init_BPF_MAP_GET_NEXT_ID_attr, print_BPF_MAP_GET_NEXT_ID_attr,
init_BPF_PROG_GET_FD_BY_ID_first, init_BPF_PROG_GET_FD_BY_ID_attr,
init_BPF_MAP_GET_FD_BY_ID_first, init_BPF_MAP_GET_FD_BY_ID_attr):
New macros.
(main) [HAVE_UNION_BPF_ATTR_NEXT_ID]: Use them.
2017-11-22 00:08:19 +03:00
BPF_CMD_ENTRY ( BPF_PROG_GET_NEXT_ID ) ,
BPF_CMD_ENTRY ( BPF_MAP_GET_NEXT_ID ) ,
BPF_CMD_ENTRY ( BPF_PROG_GET_FD_BY_ID ) ,
BPF_CMD_ENTRY ( BPF_MAP_GET_FD_BY_ID ) ,
2017-11-22 02:12:04 +03:00
BPF_CMD_ENTRY ( BPF_OBJ_GET_INFO_BY_FD ) ,
2017-07-25 15:47:19 +03:00
} ;
2016-12-21 05:43:47 +03:00
const unsigned int cmd = tcp - > u_arg [ 0 ] ;
2016-12-26 13:26:03 +03:00
const kernel_ulong_t addr = tcp - > u_arg [ 1 ] ;
2015-07-26 02:55:51 +03:00
const unsigned int size = tcp - > u_arg [ 2 ] ;
2017-07-25 15:47:19 +03:00
int rc ;
2015-07-26 02:55:51 +03:00
if ( entering ( tcp ) ) {
bpf: change handling of big and unaccessible data to match the kernel
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.
2017-07-26 13:28:25 +03:00
static char * buf ;
2018-03-05 12:17:44 +03:00
if ( ! buf )
buf = xmalloc ( get_pagesize ( ) ) ;
bpf: change handling of big and unaccessible data to match the kernel
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.
2017-07-26 13:28:25 +03:00
2015-07-26 02:55:51 +03:00
printxval ( bpf_commands , cmd , " BPF_??? " ) ;
tprints ( " , " ) ;
bpf: change handling of big and unaccessible data to match the kernel
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.
2017-07-26 13:28:25 +03:00
if ( size > 0
& & size < = get_pagesize ( )
& & cmd < ARRAY_SIZE ( bpf_cmd_decoders )
& & bpf_cmd_decoders [ cmd ] ) {
rc = umoven_or_printaddr ( tcp , addr , size , buf )
? RVAL_DECODED
: bpf_cmd_decoders [ cmd ] ( tcp , addr , size , buf ) ;
} else {
printaddr ( addr ) ;
rc = RVAL_DECODED ;
}
2017-07-25 15:47:19 +03:00
} else {
bpf: change handling of big and unaccessible data to match the kernel
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.
2017-07-26 13:28:25 +03:00
rc = bpf_cmd_decoders [ cmd ] ( tcp , addr , size , NULL ) | RVAL_DECODED ;
2015-07-26 02:55:51 +03:00
}
if ( rc & RVAL_DECODED )
tprintf ( " , %u " , size ) ;
return rc ;
}