Skip to content

Commit 9a6dfe7

Browse files
ebpf,dns: initialized structs
On the previus commit we just disabled dns uprobes for armhf/i386 to avoid loading errors. A better fix is to initialized the structs used. On armhf still fails after loading it, when attaching to the uprobes (offsets?), and on i386 it doesn't seem to send anything to userspace (more analysis needed). - Increased the number of IPs associated with a domain that are delivered to userspace. (getfedora.org returns 30 ipv4+ipv6). - Fixed getting the aliases of a domain when using gethostbyname(). (cherry picked from commit 27509d6)
1 parent 0a8827d commit 9a6dfe7

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

ebpf_prog/opensnitch-dns.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333

3434
//-----------------------------------
3535

36+
// random values
3637
#define MAX_ALIASES 5
37-
#define MAX_IPS 5
38+
#define MAX_IPS 30
3839

3940
struct nameLookupEvent {
4041
u32 addr_type;
@@ -104,8 +105,6 @@ int uretprobe__gethostbyname(struct pt_regs *ctx) {
104105
char **ips = {0};
105106
bpf_probe_read(&ips, sizeof(ips), &host->h_addr_list);
106107

107-
#if !defined(__i386__) && !defined(__arm__)
108-
109108
#pragma clang loop unroll(full)
110109
for (int i = 0; i < MAX_IPS; i++) {
111110
char *ip={0};
@@ -134,7 +133,7 @@ int uretprobe__gethostbyname(struct pt_regs *ctx) {
134133
#pragma clang loop unroll(full)
135134
for (int j = 0; j < MAX_ALIASES; j++) {
136135
char *alias = {0};
137-
bpf_probe_read(&alias, sizeof(alias), &aliases[i]);
136+
bpf_probe_read(&alias, sizeof(alias), &aliases[j]);
138137

139138
if (alias == NULL) {
140139
return 0;
@@ -145,8 +144,6 @@ int uretprobe__gethostbyname(struct pt_regs *ctx) {
145144
}
146145
}
147146

148-
#endif
149-
150147
return 0;
151148
}
152149

@@ -188,15 +185,11 @@ int ret_addrinfo(struct pt_regs *ctx) {
188185
}
189186

190187
struct addrinfo **res_p={0};
191-
__builtin_memset(&res_p, 0, sizeof(res_p));
192188
bpf_probe_read(&res_p, sizeof(res_p), &addrinfo_args->addrinfo_ptr);
193189

194-
#if !defined(__i386__) && !defined(__arm__)
195-
196190
#pragma clang loop unroll(full)
197191
for (int i = 0; i < MAX_IPS; i++) {
198-
struct addrinfo *res = {0};
199-
__builtin_memset(&res, 0, sizeof(res));
192+
struct addrinfo *res={0};
200193
bpf_probe_read(&res, sizeof(res), res_p);
201194
if (res == NULL) {
202195
goto out;
@@ -206,38 +199,32 @@ int ret_addrinfo(struct pt_regs *ctx) {
206199

207200
if (data.addr_type == AF_INET) {
208201
struct sockaddr_in *ipv4={0};
209-
__builtin_memset(&ipv4, 0, sizeof(ipv4));
210202
bpf_probe_read(&ipv4, sizeof(ipv4), &res->ai_addr);
211203
// Only copy the 4 relevant bytes
212204
bpf_probe_read_user(&data.ip, 4, &ipv4->sin_addr);
213205
} else if(data.addr_type == AF_INET6) {
214206
struct sockaddr_in6 *ipv6={0};
215-
__builtin_memset(&ipv6, 0, sizeof(ipv6));
216207
bpf_probe_read(&ipv6, sizeof(ipv6), &res->ai_addr);
217208

218209
bpf_probe_read_user(&data.ip, sizeof(data.ip), &ipv6->sin6_addr);
219210
} else {
220-
goto out;
221-
}
211+
goto out;
212+
}
222213

223214
bpf_probe_read_kernel_str(&data.host, sizeof(data.host),
224215
&addrinfo_args->node);
225216

226217
bpf_perf_event_output(ctx, &events, BPF_F_CURRENT_CPU, &data,
227218
sizeof(data));
228219

229-
230220
struct addrinfo * next={0};
231-
__builtin_memset(&next, 0, sizeof(next));
232221
bpf_probe_read(&next, sizeof(next), &res->ai_next);
233222
if (next == NULL){
234223
goto out;
235224
}
236-
res_p = &next;
225+
res_p = &next;
237226
}
238227

239-
#endif
240-
241228
out:
242229
bpf_map_delete_elem(&addrinfo_args_hash, &tid);
243230

0 commit comments

Comments
 (0)