@@ -28,17 +28,17 @@ int BPF_PROG(socketpair_e, struct pt_regs *regs, long id) {
2828 /*=============================== COLLECT PARAMETERS ===========================*/
2929
3030 /* Parameter 1: domain (type: PT_ENUMFLAGS32) */
31- /* why to send 32 bits if we need only 8 bits? */
31+ /* Why to send 32 bits if we need only 8 bits? */
3232 uint8_t domain = (uint8_t )args [0 ];
3333 ringbuf__store_u32 (& ringbuf , (uint32_t )socket_family_to_scap (domain ));
3434
3535 /* Parameter 2: type (type: PT_UINT32) */
36- /* this should be an int, not a uint32 */
36+ /* This should be an int, not an uint32. */
3737 uint32_t type = (uint32_t )args [1 ];
3838 ringbuf__store_u32 (& ringbuf , type );
3939
4040 /* Parameter 3: proto (type: PT_UINT32) */
41- /* this should be an int, not a uint32 */
41+ /* This should be an int, not an uint32. */
4242 uint32_t proto = (uint32_t )args [2 ];
4343 ringbuf__store_u32 (& ringbuf , proto );
4444
@@ -55,6 +55,12 @@ int BPF_PROG(socketpair_e, struct pt_regs *regs, long id) {
5555
5656SEC ("tp_btf/sys_exit" )
5757int BPF_PROG (socketpair_x , struct pt_regs * regs , long ret ) {
58+ /* We need to keep this at the beginning of the program because otherwise we alter the state of
59+ * the ebpf registers causing a verifier issue.
60+ */
61+ unsigned long args [4 ] = {0 };
62+ extract__network_args (args , 4 , regs );
63+
5864 struct ringbuf_struct ringbuf ;
5965 if (!ringbuf__reserve_space (& ringbuf , SOCKETPAIR_X_SIZE , PPME_SOCKET_SOCKETPAIR_X )) {
6066 return 0 ;
@@ -68,18 +74,13 @@ int BPF_PROG(socketpair_x, struct pt_regs *regs, long ret) {
6874 ringbuf__store_s64 (& ringbuf , ret );
6975
7076 int32_t fds [2 ] = {-1 , -1 };
71- unsigned long source = 0 ;
72- unsigned long peer = 0 ;
73- unsigned long fds_pointer = 0 ;
77+ uint64_t source = 0 ;
78+ uint64_t peer = 0 ;
7479
7580 /* In case of success we have 0. */
7681 if (ret == 0 ) {
77- /* Collect parameters at the beginning to manage socketcalls */
78- unsigned long args [4 ] = {0 };
79- extract__network_args (args , 4 , regs );
80-
8182 /* Get new sockets. */
82- fds_pointer = args [3 ];
83+ void * fds_pointer = ( void * ) args [3 ];
8384 bpf_probe_read_user ((void * )fds , 2 * sizeof (int32_t ), (void * )fds_pointer );
8485
8586 /* Get source and peer. */
@@ -104,6 +105,21 @@ int BPF_PROG(socketpair_x, struct pt_regs *regs, long ret) {
104105 /* Parameter 5: peer (type: PT_UINT64) */
105106 ringbuf__store_u64 (& ringbuf , peer );
106107
108+ /* Parameter 6: domain (type: PT_ENUMFLAGS32) */
109+ /* Why to send 32 bits if we need only 8 bits? */
110+ uint8_t domain = (uint8_t )args [0 ];
111+ ringbuf__store_u32 (& ringbuf , (uint32_t )socket_family_to_scap (domain ));
112+
113+ /* Parameter 7: type (type: PT_UINT32) */
114+ /* This should be an int, not an uint32. */
115+ uint32_t type = (uint32_t )args [1 ];
116+ ringbuf__store_u32 (& ringbuf , type );
117+
118+ /* Parameter 8: proto (type: PT_UINT32) */
119+ /* This should be an int, not an uint32. */
120+ uint32_t proto = (uint32_t )args [2 ];
121+ ringbuf__store_u32 (& ringbuf , proto );
122+
107123 /*=============================== COLLECT PARAMETERS ===========================*/
108124
109125 ringbuf__submit_event (& ringbuf );
0 commit comments