mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-02 01:40:12 +02:00
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 https://github.com/bitcoin/bitcoin/issues/27380#issuecomment-2286505348
With bpf_usdt_readarg() and bpf_probe_read_user(), this doesn't seem
to be a problem anymore. See https://github.com/bitcoin/bitcoin/issues/27380#issuecomment-2528671656
[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
This commit is contained in:
@@ -49,10 +49,13 @@ BPF_QUEUE(coin_selection_events, struct event_data, 1024);
|
||||
|
||||
int trace_selected_coins(struct pt_regs *ctx) {
|
||||
struct event_data data;
|
||||
void *pwallet_name = NULL, *palgo = NULL;
|
||||
__builtin_memset(&data, 0, sizeof(data));
|
||||
data.type = 1;
|
||||
bpf_usdt_readarg_p(1, ctx, &data.wallet_name, WALLET_NAME_LENGTH);
|
||||
bpf_usdt_readarg_p(2, ctx, &data.algo, ALGO_NAME_LENGTH);
|
||||
bpf_usdt_readarg(1, ctx, &pwallet_name);
|
||||
bpf_probe_read_user_str(&data.wallet_name, WALLET_NAME_LENGTH, pwallet_name);
|
||||
bpf_usdt_readarg(2, ctx, &palgo);
|
||||
bpf_probe_read_user_str(&data.algo, ALGO_NAME_LENGTH, palgo);
|
||||
bpf_usdt_readarg(3, ctx, &data.target);
|
||||
bpf_usdt_readarg(4, ctx, &data.waste);
|
||||
bpf_usdt_readarg(5, ctx, &data.selected_value);
|
||||
@@ -62,9 +65,11 @@ int trace_selected_coins(struct pt_regs *ctx) {
|
||||
|
||||
int trace_normal_create_tx(struct pt_regs *ctx) {
|
||||
struct event_data data;
|
||||
void *pwallet_name = NULL;
|
||||
__builtin_memset(&data, 0, sizeof(data));
|
||||
data.type = 2;
|
||||
bpf_usdt_readarg_p(1, ctx, &data.wallet_name, WALLET_NAME_LENGTH);
|
||||
bpf_usdt_readarg(1, ctx, &pwallet_name);
|
||||
bpf_probe_read_user_str(&data.wallet_name, WALLET_NAME_LENGTH, pwallet_name);
|
||||
bpf_usdt_readarg(2, ctx, &data.success);
|
||||
bpf_usdt_readarg(3, ctx, &data.fee);
|
||||
bpf_usdt_readarg(4, ctx, &data.change_pos);
|
||||
@@ -74,18 +79,22 @@ int trace_normal_create_tx(struct pt_regs *ctx) {
|
||||
|
||||
int trace_attempt_aps(struct pt_regs *ctx) {
|
||||
struct event_data data;
|
||||
void *pwallet_name = NULL;
|
||||
__builtin_memset(&data, 0, sizeof(data));
|
||||
data.type = 3;
|
||||
bpf_usdt_readarg_p(1, ctx, &data.wallet_name, WALLET_NAME_LENGTH);
|
||||
bpf_usdt_readarg(1, ctx, &pwallet_name);
|
||||
bpf_probe_read_user_str(&data.wallet_name, WALLET_NAME_LENGTH, pwallet_name);
|
||||
coin_selection_events.push(&data, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int trace_aps_create_tx(struct pt_regs *ctx) {
|
||||
struct event_data data;
|
||||
void *pwallet_name = NULL;
|
||||
__builtin_memset(&data, 0, sizeof(data));
|
||||
data.type = 4;
|
||||
bpf_usdt_readarg_p(1, ctx, &data.wallet_name, WALLET_NAME_LENGTH);
|
||||
bpf_usdt_readarg(1, ctx, &pwallet_name);
|
||||
bpf_probe_read_user_str(&data.wallet_name, WALLET_NAME_LENGTH, pwallet_name);
|
||||
bpf_usdt_readarg(2, ctx, &data.use_aps);
|
||||
bpf_usdt_readarg(3, ctx, &data.success);
|
||||
bpf_usdt_readarg(4, ctx, &data.fee);
|
||||
|
||||
Reference in New Issue
Block a user