Skip to content

Commit 53f1b15

Browse files
authored
Merge pull request #1619 from Aryan-sharma11/fix-whitelistpolicy
fix: No Source and resource telemetry
2 parents ccf878c + bf9af57 commit 53f1b15

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

KubeArmor/BPF/enforcer.bpf.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ static inline int match_net_rules(int type, int protocol, u32 eventID) {
275275
if (!inner) {
276276
return 0;
277277
}
278-
279278
u32 zero = 0;
280279
bufs_k *z = bpf_map_lookup_elem(&bufk, &zero);
281280
if (z == NULL)
@@ -312,11 +311,8 @@ static inline int match_net_rules(int type, int protocol, u32 eventID) {
312311
fromSourceCheck = false;
313312

314313
void *ptr = &src_buf->buf[*src_offset];
315-
316-
if (fromSourceCheck) {
317-
bpf_probe_read_str(p->source, MAX_STRING_SIZE, ptr);
318-
319-
if (type == SOCK_STREAM && (protocol == IPPROTO_TCP || protocol == 0)) {
314+
315+
if (type == SOCK_STREAM && (protocol == IPPROTO_TCP || protocol == 0)) {
320316
p0 = sock_proto;
321317
p1 = IPPROTO_TCP;
322318
} else if (type == SOCK_DGRAM &&
@@ -335,23 +331,22 @@ static inline int match_net_rules(int type, int protocol, u32 eventID) {
335331
p1 = protocol;
336332
}
337333

334+
if (fromSourceCheck) {
335+
bpf_probe_read_str(p->source, MAX_STRING_SIZE, ptr);
338336
p->path[0] = p0;
339337
p->path[1] = p1;
340-
338+
bpf_probe_read_str(store->source, MAX_STRING_SIZE, p->source);
341339
val = bpf_map_lookup_elem(inner, p);
342-
343340
if (val) {
344341
match = true;
345342
goto decision;
346343
}
347-
348-
val = bpf_map_lookup_elem(inner, p);
349344
}
345+
// check for rules without fromSource
350346
bpf_map_update_elem(&bufk, &one, z, BPF_ANY);
351-
352347
p->path[0] = p0;
353348
p->path[1] = p1;
354-
349+
355350
val = bpf_map_lookup_elem(inner, p);
356351

357352
if (val) {
@@ -361,17 +356,20 @@ static inline int match_net_rules(int type, int protocol, u32 eventID) {
361356

362357
decision:
363358

359+
bpf_probe_read_str(store->path, MAX_STRING_SIZE, p->path);
364360
if (match) {
365361
if (val && (val->processmask & RULE_DENY)) {
366362
retval = -EPERM;
367363
goto ringbuf;
368364
}
369365
}
370366

371-
bpf_map_update_elem(&bufk, &one, z, BPF_ANY);
372-
p->path[0] = dnet;
367+
bpf_map_update_elem(&bufk, &one, z, BPF_ANY);
368+
p->path[0] = dnet ;
369+
373370
struct data_t *allow = bpf_map_lookup_elem(inner, p);
374371

372+
375373
if (allow) {
376374
if (!match) {
377375
if (allow->processmask == BLOCK_POSTURE) {
@@ -393,8 +391,8 @@ static inline int match_net_rules(int type, int protocol, u32 eventID) {
393391
__builtin_memset(task_info->data.source, 0, sizeof(task_info->data.source));
394392

395393
init_context(task_info);
396-
bpf_probe_read_str(&task_info->data.path, MAX_STRING_SIZE, p->path);
397-
bpf_probe_read_str(&task_info->data.source, MAX_STRING_SIZE, p->source);
394+
bpf_probe_read_str(&task_info->data.path, MAX_STRING_SIZE, store->path);
395+
bpf_probe_read_str(&task_info->data.source, MAX_STRING_SIZE, store->source);
398396

399397
task_info->event_id = eventID;
400398

KubeArmor/enforcer/bpflsm/enforcer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ func (be *BPFEnforcer) TraceEvents() {
339339
log.Resource = string(bytes.Trim(event.Data.Path[:], "\x00"))
340340
log.Data = "lsm=" + mon.GetSyscallName(int32(event.EventID))
341341
}
342+
// fallback logic if we don't receive source from BuildLogBase()
343+
if len(log.Source) == 0 {
344+
log.Source = string(bytes.Trim(event.Data.Source[:], "\x00"))
345+
}
342346
if event.Retval >= 0 {
343347
log.Result = "Passed"
344348
} else {
10.8 KB
Binary file not shown.
10.8 KB
Binary file not shown.
-24 Bytes
Binary file not shown.
-24 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)