Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support of sctp #1886

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions KubeArmor/BPF/enforcer.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ int BPF_PROG(enforce_proc, struct linux_binprm *bprm, int ret) {
if (src_offset == NULL)
fromSourceCheck = false;

void *src_ptr = &src_buf->buf[*src_offset];
void *src_ptr;
if (src_buf->buf[*src_offset]) {
src_ptr = &src_buf->buf[*src_offset];
}
if (src_ptr == NULL)
fromSourceCheck = false;

Expand Down Expand Up @@ -152,10 +155,9 @@ int BPF_PROG(enforce_proc, struct linux_binprm *bprm, int ret) {
goto decision;
}


// match exec name
struct qstr d_name;
d_name = BPF_CORE_READ(f_path.dentry,d_name);
d_name = BPF_CORE_READ(f_path.dentry, d_name);
bpf_map_update_elem(&bufk, &two, z, BPF_ANY);
bpf_probe_read_str(pk->path, MAX_STRING_SIZE, d_name.name);

Expand Down Expand Up @@ -336,6 +338,10 @@ static inline int match_net_rules(int type, int protocol, u32 eventID) {
(type == SOCK_DGRAM || type == SOCK_RAW)) {
p0 = sock_proto;
p1 = IPPROTO_ICMP;
} else if (protocol == IPPROTO_SCTP &&
(type == SOCK_STREAM || type == SOCK_SEQPACKET)) {
p0 = sock_proto;
p1 = IPPROTO_SCTP;
} else if (type == SOCK_RAW && protocol == 0) {
p0 = sock_type;
p1 = SOCK_RAW;
Expand Down
44 changes: 22 additions & 22 deletions KubeArmor/enforcer/bpflsm/enforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
tp "github.com/kubearmor/KubeArmor/KubeArmor/types"
)

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -cc clang enforcer ../../BPF/enforcer.bpf.c -- -I/usr/include/ -O2 -g
//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -cc clang enforcer_path ../../BPF/enforcer_path.bpf.c -- -I/usr/include/ -O2 -g
//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -cc clang enforcer ../../BPF/enforcer.bpf.c -- -I/usr/include/ -O2 -fno-stack-protector -g
//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -cc clang enforcer_path ../../BPF/enforcer_path.bpf.c -- -I/usr/include/ -O2 -fno-stack-protector -g

// ===================== //
// == BPFLSM Enforcer == //
Expand Down Expand Up @@ -426,31 +426,31 @@ func (be *BPFEnforcer) DestroyBPFEnforcer() error {
be.ContainerMapLock.Lock()

if be.BPFContainerMap != nil {
if err := be.BPFContainerMap.Unpin(); err != nil {
be.Logger.Err(err.Error())
errBPFCleanUp = errors.Join(errBPFCleanUp, err)
}
if err := be.BPFContainerMap.Close(); err != nil {
be.Logger.Err(err.Error())
errBPFCleanUp = errors.Join(errBPFCleanUp, err)
}
// if err := be.BPFContainerMap.Unpin(); err != nil {
// be.Logger.Err(err.Error())
// errBPFCleanUp = errors.Join(errBPFCleanUp, err)
// }
// if err := be.BPFContainerMap.Close(); err != nil {
// be.Logger.Err(err.Error())
// errBPFCleanUp = errors.Join(errBPFCleanUp, err)
// }
}

be.ContainerMapLock.Unlock()

if be.Events != nil {
if err := be.obj.KubearmorEvents.Unpin(); err != nil {
be.Logger.Err(err.Error())
errBPFCleanUp = errors.Join(errBPFCleanUp, err)
}
if err := be.obj.KubearmorEvents.Close(); err != nil {
be.Logger.Err(err.Error())
errBPFCleanUp = errors.Join(errBPFCleanUp, err)
}
if err := be.Events.Close(); err != nil {
be.Logger.Err(err.Error())
errBPFCleanUp = errors.Join(errBPFCleanUp, err)
}
// if err := be.obj.KubearmorEvents.Unpin(); err != nil {
// be.Logger.Err(err.Error())
// errBPFCleanUp = errors.Join(errBPFCleanUp, err)
// }
// if err := be.obj.KubearmorEvents.Close(); err != nil {
// be.Logger.Err(err.Error())
// errBPFCleanUp = errors.Join(errBPFCleanUp, err)
// }
// if err := be.Events.Close(); err != nil {
// be.Logger.Err(err.Error())
// errBPFCleanUp = errors.Join(errBPFCleanUp, err)
// }
}

be = nil
Expand Down
Binary file modified KubeArmor/enforcer/bpflsm/enforcer_bpfeb.o
Binary file not shown.
Binary file modified KubeArmor/enforcer/bpflsm/enforcer_bpfel.o
Binary file not shown.
Binary file modified KubeArmor/enforcer/bpflsm/enforcer_path_bpfeb.o
Binary file not shown.
Binary file modified KubeArmor/enforcer/bpflsm/enforcer_path_bpfel.o
Binary file not shown.
7 changes: 6 additions & 1 deletion KubeArmor/enforcer/bpflsm/rulesHandling.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ var protocols = map[string]uint8{
"TCP": 6,
"UDP": 17,
"ICMPv6": 58,
"SCTP": 132,
}

// Socket Type Identifiers for Network Rules
var netType = map[string]uint8{
"RAW": 3,
"DGRAM": 1,
"STREAM": 2,
"RAW": 3,
"RDM": 4,
"SEQPACKET": 5,
}

// Array Keys for Network Rule Keys
Expand Down