Skip to content

Commit 277f674

Browse files
committed
.
1 parent 58e5d9f commit 277f674

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src2/ssl_read.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "vmlinux.h"
1+
#include <linux/types.h>
22
#include <bpf/bpf_helpers.h>
33
#include <bpf/bpf_tracing.h>
44
#include <bpf/bpf_core_read.h>
@@ -18,52 +18,53 @@ struct event {
1818
struct {
1919
__uint(type, BPF_MAP_TYPE_HASH);
2020
__uint(max_entries, 1024);
21-
__type(key, __u64); // pid_tgid | TLS_MASK
21+
__type(key, __u64);
2222
__type(value, void *);
2323
} ssl_read_args SEC(".maps");
2424

2525
struct {
2626
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
2727
} events SEC(".maps");
2828

29-
// --- Helper to store buffer pointer at function entry ---
3029
static __always_inline void ssl_uprobe_read_enter_v3(struct pt_regs *ctx, __u64 id, __u32 pid, void *ssl, void *buffer, int num, int dummy) {
31-
if (buffer == NULL)
32-
return;
33-
30+
if (buffer == NULL) return;
3431
bpf_map_update_elem(&ssl_read_args, &id, &buffer, BPF_ANY);
3532
}
3633

37-
// --- Helper to process the return from SSL_read ---
3834
static __always_inline void process_exit_of_syscalls_read_recvfrom(struct pt_regs *ctx, __u64 id, __u64 pid, int ret, int is_tls) {
3935
void **bufp = bpf_map_lookup_elem(&ssl_read_args, &id);
40-
if (!bufp)
41-
return;
36+
if (!bufp) return;
4237

4338
void *buf = *bufp;
4439
bpf_map_delete_elem(&ssl_read_args, &id);
4540

46-
if (ret <= 0 || ret > MAX_BUF_SIZE)
47-
return;
41+
if (ret <= 0 || ret > MAX_BUF_SIZE) return;
4842

4943
struct event evt = {};
5044
evt.pid = pid;
5145
evt.tid = id;
5246
evt.len = ret;
53-
54-
// Read plaintext data from buffer
5547
bpf_probe_read_user(&evt.buf, ret, buf);
56-
57-
// Submit to userspace
5848
bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &evt, sizeof(evt));
5949
}
6050

61-
// --- Entry probe for SSL_read ---
62-
SEC("uprobe/SSL_read_v3")
63-
void BPF_UPROBE(ssl_read_enter_v3, void *ssl, void *buffer, int num) {
51+
SEC("uprobe/SSL_read")
52+
int BPF_UPROBE(ssl_read_enter_v3, void *ssl, void *buffer, int num) {
6453
__u64 pid_tgid = bpf_get_current_pid_tgid();
6554
__u32 pid = pid_tgid >> 32;
6655
__u64 id = pid_tgid | TLS_MASK;
6756

6857
ssl_uprobe_read_enter_v3(ctx, id, pid, ssl, buffer, num, 0);
58+
return 0;
59+
}
60+
61+
SEC("uretprobe/SSL_read")
62+
int BPF_URETPROBE(ssl_ret_read_v3) {
63+
__u64 pid_tgid = bpf_get_current_pid_tgid();
64+
__u64 pid = pid_tgid >> 32;
65+
__u64 id = pid_tgid | TLS_MASK;
66+
67+
int returnValue = PT_REGS_RC(ctx);
68+
process_exit_of_syscalls_read_recvfrom(ctx, id, pid, returnValue, 1);
69+
return 0;
6970
}

0 commit comments

Comments
 (0)