Skip to content

Commit 6f57881

Browse files
committed
bpf: Stop hashing strings, use container ID as string
Signed-off-by: Michal Rostecki <[email protected]>
1 parent bf1beea commit 6f57881

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

lockc/src/bpf/limits.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*/
88
#define PID_MAX_LIMIT 4194304
99

10+
/* Container ID limit. */
11+
#define CONTAINER_ID_LIMIT 64
12+
1013
/* Our arbitrary path length limit. */
1114
#define PATH_LEN 64
1215
#define PATH_MAX_LIMIT 128

lockc/src/bpf/lockc.bpf.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ static __always_inline int handle_new_process(struct task_struct *parent,
5555
bpf_printk("found parent containerized process: %d\n", ppid);
5656
bpf_printk("comm: %s\n", BPF_CORE_READ(child, comm));
5757

58-
u32 container_id = parent_lookup->container_id;
59-
u32 *container_lookup = bpf_map_lookup_elem(&containers, &container_id);
58+
struct container_id container_id = parent_lookup->container_id;
59+
struct container *container_lookup =
60+
bpf_map_lookup_elem(&containers, &container_id);
6061
if (!container_lookup) {
6162
/* Shouldn't happen */
6263
bpf_printk("error: handle_new_process: cound not find a "
6364
"container for a registered process %d, "
64-
"container id: %d\n",
65-
pid, container_id);
65+
"container id: %s\n",
66+
pid, container_id.id);
6667
return -EPERM;
6768
}
6869

lockc/src/bpf/map_structs.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
#include "limits.h"
55
#include "policy.h"
66

7+
struct container_id {
8+
unsigned char id[CONTAINER_ID_LIMIT];
9+
};
10+
711
struct container {
812
enum container_policy_level policy_level;
913
};
1014

1115
struct process {
12-
unsigned int container_id;
16+
struct container_id container_id;
1317
};
1418

1519
struct accessed_path {

lockc/src/bpf/maps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
struct bpf_map_def SEC("maps/containers") containers = {
1212
.type = BPF_MAP_TYPE_HASH,
1313
.max_entries = PID_MAX_LIMIT,
14-
.key_size = sizeof(u32),
14+
.key_size = sizeof(struct container_id),
1515
.value_size = sizeof(struct container),
1616
};
1717

0 commit comments

Comments
 (0)