Skip to content

Commit 35ae6ff

Browse files
committed
test: don't use bpf_usdt_readarg_p
Instead of using the undocumented bcc helper bpf_usdt_readarg_p(), use bpf_usdt_readarg() [1] and bpf_probe_read_user{_str}() [2, 3] as documented in the bcc USDT reference guide [1]. Note that the bpf_probe_read_user() documentation says the following: > For safety, all user address space memory reads must pass through bpf_probe_read_user(). It's assumed that using bpf_usdt_readarg_p() caused a lifetime issue. See bitcoin/bitcoin#27380 (comment) With bpf_usdt_readarg() and bpf_probe_read_user(), this doesn't seem to be a problem anymore. See bitcoin/bitcoin#27380 (comment) [1]: https://github.com/iovisor/bcc/blob/master/docs/reference_guide.md#6-usdt-probes [2]: https://github.com/iovisor/bcc/blob/master/docs/reference_guide.md#10-bpf_probe_read_user [3]: https://github.com/iovisor/bcc/blob/master/docs/reference_guide.md#11-bpf_probe_read_user_str
1 parent ede388d commit 35ae6ff

5 files changed

+63
-29
lines changed

test/functional/interface_usdt_coinselection.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@
4949
5050
int trace_selected_coins(struct pt_regs *ctx) {
5151
struct event_data data;
52+
void *pwallet_name = NULL, *palgo = NULL;
5253
__builtin_memset(&data, 0, sizeof(data));
5354
data.type = 1;
54-
bpf_usdt_readarg_p(1, ctx, &data.wallet_name, WALLET_NAME_LENGTH);
55-
bpf_usdt_readarg_p(2, ctx, &data.algo, ALGO_NAME_LENGTH);
55+
bpf_usdt_readarg(1, ctx, &pwallet_name);
56+
bpf_probe_read_user_str(&data.wallet_name, WALLET_NAME_LENGTH, pwallet_name);
57+
bpf_usdt_readarg(2, ctx, &palgo);
58+
bpf_probe_read_user_str(&data.algo, ALGO_NAME_LENGTH, palgo);
5659
bpf_usdt_readarg(3, ctx, &data.target);
5760
bpf_usdt_readarg(4, ctx, &data.waste);
5861
bpf_usdt_readarg(5, ctx, &data.selected_value);
@@ -62,9 +65,11 @@
6265
6366
int trace_normal_create_tx(struct pt_regs *ctx) {
6467
struct event_data data;
68+
void *pwallet_name = NULL;
6569
__builtin_memset(&data, 0, sizeof(data));
6670
data.type = 2;
67-
bpf_usdt_readarg_p(1, ctx, &data.wallet_name, WALLET_NAME_LENGTH);
71+
bpf_usdt_readarg(1, ctx, &pwallet_name);
72+
bpf_probe_read_user_str(&data.wallet_name, WALLET_NAME_LENGTH, pwallet_name);
6873
bpf_usdt_readarg(2, ctx, &data.success);
6974
bpf_usdt_readarg(3, ctx, &data.fee);
7075
bpf_usdt_readarg(4, ctx, &data.change_pos);
@@ -74,18 +79,22 @@
7479
7580
int trace_attempt_aps(struct pt_regs *ctx) {
7681
struct event_data data;
82+
void *pwallet_name = NULL;
7783
__builtin_memset(&data, 0, sizeof(data));
7884
data.type = 3;
79-
bpf_usdt_readarg_p(1, ctx, &data.wallet_name, WALLET_NAME_LENGTH);
85+
bpf_usdt_readarg(1, ctx, &pwallet_name);
86+
bpf_probe_read_user_str(&data.wallet_name, WALLET_NAME_LENGTH, pwallet_name);
8087
coin_selection_events.push(&data, 0);
8188
return 0;
8289
}
8390
8491
int trace_aps_create_tx(struct pt_regs *ctx) {
8592
struct event_data data;
93+
void *pwallet_name = NULL;
8694
__builtin_memset(&data, 0, sizeof(data));
8795
data.type = 4;
88-
bpf_usdt_readarg_p(1, ctx, &data.wallet_name, WALLET_NAME_LENGTH);
96+
bpf_usdt_readarg(1, ctx, &pwallet_name);
97+
bpf_probe_read_user_str(&data.wallet_name, WALLET_NAME_LENGTH, pwallet_name);
8998
bpf_usdt_readarg(2, ctx, &data.use_aps);
9099
bpf_usdt_readarg(3, ctx, &data.success);
91100
bpf_usdt_readarg(4, ctx, &data.fee);

test/functional/interface_usdt_mempool.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@
7575
7676
int trace_added(struct pt_regs *ctx) {
7777
struct added_event added = {};
78-
79-
bpf_usdt_readarg_p(1, ctx, &added.hash, HASH_LENGTH);
78+
void *phash = NULL;
79+
bpf_usdt_readarg(1, ctx, &phash);
80+
bpf_probe_read_user(&added.hash, sizeof(added.hash), phash);
8081
bpf_usdt_readarg(2, ctx, &added.vsize);
8182
bpf_usdt_readarg(3, ctx, &added.fee);
8283
@@ -86,9 +87,11 @@
8687
8788
int trace_removed(struct pt_regs *ctx) {
8889
struct removed_event removed = {};
89-
90-
bpf_usdt_readarg_p(1, ctx, &removed.hash, HASH_LENGTH);
91-
bpf_usdt_readarg_p(2, ctx, &removed.reason, MAX_REMOVAL_REASON_LENGTH);
90+
void *phash = NULL, *preason = NULL;
91+
bpf_usdt_readarg(1, ctx, &phash);
92+
bpf_probe_read_user(&removed.hash, sizeof(removed.hash), phash);
93+
bpf_usdt_readarg(2, ctx, &preason);
94+
bpf_probe_read_user_str(&removed.reason, sizeof(removed.reason), preason);
9295
bpf_usdt_readarg(3, ctx, &removed.vsize);
9396
bpf_usdt_readarg(4, ctx, &removed.fee);
9497
bpf_usdt_readarg(5, ctx, &removed.entry_time);
@@ -99,22 +102,25 @@
99102
100103
int trace_rejected(struct pt_regs *ctx) {
101104
struct rejected_event rejected = {};
102-
103-
bpf_usdt_readarg_p(1, ctx, &rejected.hash, HASH_LENGTH);
104-
bpf_usdt_readarg_p(2, ctx, &rejected.reason, MAX_REJECT_REASON_LENGTH);
105-
105+
void *phash = NULL, *preason = NULL;
106+
bpf_usdt_readarg(1, ctx, &phash);
107+
bpf_probe_read_user(&rejected.hash, sizeof(rejected.hash), phash);
108+
bpf_usdt_readarg(2, ctx, &preason);
109+
bpf_probe_read_user_str(&rejected.reason, sizeof(rejected.reason), preason);
106110
rejected_events.perf_submit(ctx, &rejected, sizeof(rejected));
107111
return 0;
108112
}
109113
110114
int trace_replaced(struct pt_regs *ctx) {
111115
struct replaced_event replaced = {};
112-
113-
bpf_usdt_readarg_p(1, ctx, &replaced.replaced_hash, HASH_LENGTH);
116+
void *preplaced_hash = NULL, *preplacement_hash = NULL;
117+
bpf_usdt_readarg(1, ctx, &preplaced_hash);
118+
bpf_probe_read_user(&replaced.replaced_hash, sizeof(replaced.replaced_hash), preplaced_hash);
114119
bpf_usdt_readarg(2, ctx, &replaced.replaced_vsize);
115120
bpf_usdt_readarg(3, ctx, &replaced.replaced_fee);
116121
bpf_usdt_readarg(4, ctx, &replaced.replaced_entry_time);
117-
bpf_usdt_readarg_p(5, ctx, &replaced.replacement_hash, HASH_LENGTH);
122+
bpf_usdt_readarg(5, ctx, &preplacement_hash);
123+
bpf_probe_read_user(&replaced.replacement_hash, sizeof(replaced.replacement_hash), preplacement_hash);
118124
bpf_usdt_readarg(6, ctx, &replaced.replacement_vsize);
119125
bpf_usdt_readarg(7, ctx, &replaced.replacement_fee);
120126
bpf_usdt_readarg(8, ctx, &replaced.replaced_by_transaction);

test/functional/interface_usdt_net.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,36 @@
9191
BPF_PERF_OUTPUT(inbound_messages);
9292
int trace_inbound_message(struct pt_regs *ctx) {
9393
struct p2p_message msg = {};
94+
void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL, *pmsg = NULL;
9495
bpf_usdt_readarg(1, ctx, &msg.peer_id);
95-
bpf_usdt_readarg_p(2, ctx, &msg.peer_addr, MAX_PEER_ADDR_LENGTH);
96-
bpf_usdt_readarg_p(3, ctx, &msg.peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH);
97-
bpf_usdt_readarg_p(4, ctx, &msg.msg_type, MAX_MSG_TYPE_LENGTH);
96+
bpf_usdt_readarg(2, ctx, &paddr);
97+
bpf_probe_read_user_str(&msg.peer_addr, sizeof(msg.peer_addr), paddr);
98+
bpf_usdt_readarg(3, ctx, &pconn_type);
99+
bpf_probe_read_user_str(&msg.peer_conn_type, sizeof(msg.peer_conn_type), pconn_type);
100+
bpf_usdt_readarg(4, ctx, &pmsg_type);
101+
bpf_probe_read_user_str(&msg.msg_type, sizeof(msg.msg_type), pmsg_type);
98102
bpf_usdt_readarg(5, ctx, &msg.msg_size);
99-
bpf_usdt_readarg_p(6, ctx, &msg.msg, _TRACEPOINT_TEST_MIN(msg.msg_size, MAX_MSG_DATA_LENGTH));
103+
bpf_usdt_readarg(6, ctx, &pmsg);
104+
bpf_probe_read_user(&msg.msg, _TRACEPOINT_TEST_MIN(msg.msg_size, MAX_MSG_DATA_LENGTH), pmsg);
100105
inbound_messages.perf_submit(ctx, &msg, sizeof(msg));
101106
return 0;
102107
}
103108
104109
BPF_PERF_OUTPUT(outbound_messages);
105110
int trace_outbound_message(struct pt_regs *ctx) {
106111
struct p2p_message msg = {};
112+
void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL, *pmsg = NULL;
107113
bpf_usdt_readarg(1, ctx, &msg.peer_id);
108-
bpf_usdt_readarg_p(2, ctx, &msg.peer_addr, MAX_PEER_ADDR_LENGTH);
109-
bpf_usdt_readarg_p(3, ctx, &msg.peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH);
110-
bpf_usdt_readarg_p(4, ctx, &msg.msg_type, MAX_MSG_TYPE_LENGTH);
114+
bpf_usdt_readarg(1, ctx, &msg.peer_id);
115+
bpf_usdt_readarg(2, ctx, &paddr);
116+
bpf_probe_read_user_str(&msg.peer_addr, sizeof(msg.peer_addr), paddr);
117+
bpf_usdt_readarg(3, ctx, &pconn_type);
118+
bpf_probe_read_user_str(&msg.peer_conn_type, sizeof(msg.peer_conn_type), pconn_type);
119+
bpf_usdt_readarg(4, ctx, &pmsg_type);
120+
bpf_probe_read_user_str(&msg.msg_type, sizeof(msg.msg_type), pmsg_type);
111121
bpf_usdt_readarg(5, ctx, &msg.msg_size);
112-
bpf_usdt_readarg_p(6, ctx, &msg.msg, _TRACEPOINT_TEST_MIN(msg.msg_size, MAX_MSG_DATA_LENGTH));
122+
bpf_usdt_readarg(6, ctx, &pmsg);
123+
bpf_probe_read_user(&msg.msg, _TRACEPOINT_TEST_MIN(msg.msg_size, MAX_MSG_DATA_LENGTH), pmsg);
113124
outbound_messages.perf_submit(ctx, &msg, sizeof(msg));
114125
return 0;
115126
};

test/functional/interface_usdt_utxocache.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
BPF_PERF_OUTPUT(utxocache_add);
3636
int trace_utxocache_add(struct pt_regs *ctx) {
3737
struct utxocache_change add = {};
38-
bpf_usdt_readarg_p(1, ctx, &add.txid, 32);
38+
void *ptxid = NULL;
39+
bpf_usdt_readarg(1, ctx, &ptxid);
40+
bpf_probe_read_user(&add.txid, sizeof(add.txid), ptxid);
3941
bpf_usdt_readarg(2, ctx, &add.index);
4042
bpf_usdt_readarg(3, ctx, &add.height);
4143
bpf_usdt_readarg(4, ctx, &add.value);
@@ -47,7 +49,9 @@
4749
BPF_PERF_OUTPUT(utxocache_spent);
4850
int trace_utxocache_spent(struct pt_regs *ctx) {
4951
struct utxocache_change spent = {};
50-
bpf_usdt_readarg_p(1, ctx, &spent.txid, 32);
52+
void *ptxid = NULL;
53+
bpf_usdt_readarg(1, ctx, &ptxid);
54+
bpf_probe_read_user(&spent.txid, sizeof(spent.txid), ptxid);
5155
bpf_usdt_readarg(2, ctx, &spent.index);
5256
bpf_usdt_readarg(3, ctx, &spent.height);
5357
bpf_usdt_readarg(4, ctx, &spent.value);
@@ -59,7 +63,9 @@
5963
BPF_PERF_OUTPUT(utxocache_uncache);
6064
int trace_utxocache_uncache(struct pt_regs *ctx) {
6165
struct utxocache_change uncache = {};
62-
bpf_usdt_readarg_p(1, ctx, &uncache.txid, 32);
66+
void *ptxid = NULL;
67+
bpf_usdt_readarg(1, ctx, &ptxid);
68+
bpf_probe_read_user(&uncache.txid, sizeof(uncache.txid), ptxid);
6369
bpf_usdt_readarg(2, ctx, &uncache.index);
6470
bpf_usdt_readarg(3, ctx, &uncache.height);
6571
bpf_usdt_readarg(4, ctx, &uncache.value);

test/functional/interface_usdt_validation.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
BPF_PERF_OUTPUT(block_connected);
4040
int trace_block_connected(struct pt_regs *ctx) {
4141
struct connected_block block = {};
42-
bpf_usdt_readarg_p(1, ctx, &block.hash, 32);
42+
void *phash = NULL;
43+
bpf_usdt_readarg(1, ctx, &phash);
44+
bpf_probe_read_user(&block.hash, sizeof(block.hash), phash);
4345
bpf_usdt_readarg(2, ctx, &block.height);
4446
bpf_usdt_readarg(3, ctx, &block.transactions);
4547
bpf_usdt_readarg(4, ctx, &block.inputs);

0 commit comments

Comments
 (0)