From ec47ba349d0b3cb2d274593ca7b828ae70584e10 Mon Sep 17 00:00:00 2001 From: 0xb10c Date: Tue, 7 Jan 2025 17:29:32 +0100 Subject: [PATCH] contrib: don't use bpf_usdt_readarg_p --- contrib/tracing/log_raw_p2p_msgs.py | 27 ++++++++++++++++++-------- contrib/tracing/mempool_monitor.py | 30 +++++++++++++++++------------ contrib/tracing/p2p_monitor.py | 20 +++++++++++++------ 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/contrib/tracing/log_raw_p2p_msgs.py b/contrib/tracing/log_raw_p2p_msgs.py index 69f457acb1b..1c0f03e19df 100755 --- a/contrib/tracing/log_raw_p2p_msgs.py +++ b/contrib/tracing/log_raw_p2p_msgs.py @@ -78,6 +78,7 @@ BPF_PERF_OUTPUT(outbound_messages); int trace_inbound_message(struct pt_regs *ctx) { int idx = 0; struct p2p_message *msg = msg_arr.lookup(&idx); + void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL, *pmsg = NULL; // lookup() does not return a NULL pointer. However, the BPF verifier // requires an explicit check that that the `msg` pointer isn't a NULL @@ -85,11 +86,15 @@ int trace_inbound_message(struct pt_regs *ctx) { if (msg == NULL) return 1; bpf_usdt_readarg(1, ctx, &msg->peer_id); - bpf_usdt_readarg_p(2, ctx, &msg->peer_addr, MAX_PEER_ADDR_LENGTH); - bpf_usdt_readarg_p(3, ctx, &msg->peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH); - bpf_usdt_readarg_p(4, ctx, &msg->msg_type, MAX_MSG_TYPE_LENGTH); + bpf_usdt_readarg(2, ctx, &paddr); + bpf_probe_read_user_str(&msg->peer_addr, sizeof(msg->peer_addr), paddr); + bpf_usdt_readarg(3, ctx, &pconn_type); + bpf_probe_read_user_str(&msg->peer_conn_type, sizeof(msg->peer_conn_type), pconn_type); + bpf_usdt_readarg(4, ctx, &pmsg_type); + bpf_probe_read_user_str(&msg->msg_type, sizeof(msg->msg_type), pmsg_type); bpf_usdt_readarg(5, ctx, &msg->msg_size); - bpf_usdt_readarg_p(6, ctx, &msg->msg, _TRACEPOINT_TEST_MIN(msg->msg_size, MAX_MSG_DATA_LENGTH)); + bpf_usdt_readarg(6, ctx, &pmsg); + bpf_probe_read_user(&msg->msg, _TRACEPOINT_TEST_MIN(msg->msg_size, MAX_MSG_DATA_LENGTH), pmsg); inbound_messages.perf_submit(ctx, msg, sizeof(*msg)); return 0; @@ -99,17 +104,23 @@ int trace_outbound_message(struct pt_regs *ctx) { int idx = 0; struct p2p_message *msg = msg_arr.lookup(&idx); + void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL, *pmsg = NULL; + // lookup() does not return a NULL pointer. However, the BPF verifier // requires an explicit check that that the `msg` pointer isn't a NULL // pointer. See https://github.com/iovisor/bcc/issues/2595 if (msg == NULL) return 1; bpf_usdt_readarg(1, ctx, &msg->peer_id); - bpf_usdt_readarg_p(2, ctx, &msg->peer_addr, MAX_PEER_ADDR_LENGTH); - bpf_usdt_readarg_p(3, ctx, &msg->peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH); - bpf_usdt_readarg_p(4, ctx, &msg->msg_type, MAX_MSG_TYPE_LENGTH); + bpf_usdt_readarg(2, ctx, &paddr); + bpf_probe_read_user_str(&msg->peer_addr, sizeof(msg->peer_addr), paddr); + bpf_usdt_readarg(3, ctx, &pconn_type); + bpf_probe_read_user_str(&msg->peer_conn_type, sizeof(msg->peer_conn_type), pconn_type); + bpf_usdt_readarg(4, ctx, &pmsg_type); + bpf_probe_read_user_str(&msg->msg_type, sizeof(msg->msg_type), pmsg_type); bpf_usdt_readarg(5, ctx, &msg->msg_size); - bpf_usdt_readarg_p(6, ctx, &msg->msg, _TRACEPOINT_TEST_MIN(msg->msg_size, MAX_MSG_DATA_LENGTH)); + bpf_usdt_readarg(6, ctx, &pmsg); + bpf_probe_read_user(&msg->msg, _TRACEPOINT_TEST_MIN(msg->msg_size, MAX_MSG_DATA_LENGTH), pmsg); outbound_messages.perf_submit(ctx, msg, sizeof(*msg)); return 0; diff --git a/contrib/tracing/mempool_monitor.py b/contrib/tracing/mempool_monitor.py index 4492cb75708..7c184cce46e 100755 --- a/contrib/tracing/mempool_monitor.py +++ b/contrib/tracing/mempool_monitor.py @@ -65,8 +65,9 @@ BPF_PERF_OUTPUT(replaced_events); int trace_added(struct pt_regs *ctx) { struct added_event added = {}; - - bpf_usdt_readarg_p(1, ctx, &added.hash, HASH_LENGTH); + void *phash = NULL; + bpf_usdt_readarg(1, ctx, phash); + bpf_probe_read_user(&added.hash, sizeof(added.hash), phash); bpf_usdt_readarg(2, ctx, &added.vsize); bpf_usdt_readarg(3, ctx, &added.fee); @@ -76,9 +77,11 @@ int trace_added(struct pt_regs *ctx) { int trace_removed(struct pt_regs *ctx) { struct removed_event removed = {}; - - bpf_usdt_readarg_p(1, ctx, &removed.hash, HASH_LENGTH); - bpf_usdt_readarg_p(2, ctx, &removed.reason, MAX_REMOVAL_REASON_LENGTH); + void *phash = NULL, *preason = NULL; + bpf_usdt_readarg(1, ctx, phash); + bpf_probe_read_user(&removed.hash, sizeof(removed.hash), phash); + bpf_usdt_readarg(1, ctx, preason); + bpf_probe_read_user_str(&removed.reason, sizeof(removed.reason), preason); bpf_usdt_readarg(3, ctx, &removed.vsize); bpf_usdt_readarg(4, ctx, &removed.fee); bpf_usdt_readarg(5, ctx, &removed.entry_time); @@ -89,22 +92,25 @@ int trace_removed(struct pt_regs *ctx) { int trace_rejected(struct pt_regs *ctx) { struct rejected_event rejected = {}; - - bpf_usdt_readarg_p(1, ctx, &rejected.hash, HASH_LENGTH); - bpf_usdt_readarg_p(2, ctx, &rejected.reason, MAX_REJECT_REASON_LENGTH); - + void *phash = NULL, *preason = NULL; + bpf_usdt_readarg(1, ctx, phash); + bpf_probe_read_user(&rejected.hash, sizeof(rejected.hash), phash); + bpf_usdt_readarg(1, ctx, preason); + bpf_probe_read_user_str(&rejected.reason, sizeof(rejected.reason), preason); rejected_events.perf_submit(ctx, &rejected, sizeof(rejected)); return 0; } int trace_replaced(struct pt_regs *ctx) { struct replaced_event replaced = {}; - - bpf_usdt_readarg_p(1, ctx, &replaced.replaced_hash, HASH_LENGTH); + void *phash_replaced = NULL, *phash_replacement = NULL; + bpf_usdt_readarg(1, ctx, phash_replaced); + bpf_probe_read_user(&replaced.replaced_hash, sizeof(replaced.replaced_hash), phash_replaced); bpf_usdt_readarg(2, ctx, &replaced.replaced_vsize); bpf_usdt_readarg(3, ctx, &replaced.replaced_fee); bpf_usdt_readarg(4, ctx, &replaced.replaced_entry_time); - bpf_usdt_readarg_p(5, ctx, &replaced.replacement_hash, HASH_LENGTH); + bpf_usdt_readarg(5, ctx, phash_replacement); + bpf_probe_read_user(&replaced.replacement_hash, sizeof(replaced.replacement_hash), phash_replacement); bpf_usdt_readarg(6, ctx, &replaced.replacement_vsize); bpf_usdt_readarg(7, ctx, &replaced.replacement_fee); diff --git a/contrib/tracing/p2p_monitor.py b/contrib/tracing/p2p_monitor.py index 63a27fc17da..78225366d9c 100755 --- a/contrib/tracing/p2p_monitor.py +++ b/contrib/tracing/p2p_monitor.py @@ -47,11 +47,15 @@ BPF_PERF_OUTPUT(outbound_messages); int trace_inbound_message(struct pt_regs *ctx) { struct p2p_message msg = {}; + void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL; bpf_usdt_readarg(1, ctx, &msg.peer_id); - bpf_usdt_readarg_p(2, ctx, &msg.peer_addr, MAX_PEER_ADDR_LENGTH); - bpf_usdt_readarg_p(3, ctx, &msg.peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH); - bpf_usdt_readarg_p(4, ctx, &msg.msg_type, MAX_MSG_TYPE_LENGTH); + bpf_usdt_readarg(2, ctx, &paddr); + bpf_probe_read_user_str(&msg.peer_addr, sizeof(msg.peer_addr), paddr); + bpf_usdt_readarg(3, ctx, &pconn_type); + bpf_probe_read_user_str(&msg.peer_conn_type, sizeof(msg.peer_conn_type), pconn_type); + bpf_usdt_readarg(4, ctx, &pconn_type); + bpf_probe_read_user_str(&msg.msg_type, sizeof(msg.msg_type), pmsg_type); bpf_usdt_readarg(5, ctx, &msg.msg_size); inbound_messages.perf_submit(ctx, &msg, sizeof(msg)); @@ -60,11 +64,15 @@ int trace_inbound_message(struct pt_regs *ctx) { int trace_outbound_message(struct pt_regs *ctx) { struct p2p_message msg = {}; + void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL; bpf_usdt_readarg(1, ctx, &msg.peer_id); - bpf_usdt_readarg_p(2, ctx, &msg.peer_addr, MAX_PEER_ADDR_LENGTH); - bpf_usdt_readarg_p(3, ctx, &msg.peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH); - bpf_usdt_readarg_p(4, ctx, &msg.msg_type, MAX_MSG_TYPE_LENGTH); + bpf_usdt_readarg(2, ctx, &paddr); + bpf_probe_read_user_str(&msg.peer_addr, sizeof(msg.peer_addr), paddr); + bpf_usdt_readarg(3, ctx, &pconn_type); + bpf_probe_read_user_str(&msg.peer_conn_type, sizeof(msg.peer_conn_type), pconn_type); + bpf_usdt_readarg(4, ctx, &pconn_type); + bpf_probe_read_user_str(&msg.msg_type, sizeof(msg.msg_type), pmsg_type); bpf_usdt_readarg(5, ctx, &msg.msg_size); outbound_messages.perf_submit(ctx, &msg, sizeof(msg));