void bpf_program_free(struct bpf_program *prog)
{
+ if (!prog)
+ return;
+
(void)bpf_program_cgroup_detach(prog);
if (prog->kernel_fd >= 0)
int bpf_program_init(struct bpf_program *prog)
{
+ if (!prog)
+ return minus_one_set_errno(EINVAL);
+
const struct bpf_insn pre_insn[] = {
/* load device type to r2 */
BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, offsetof(struct bpf_cgroup_dev_ctx, access_type)),
int access_mask;
int device_type;
+ if (!prog || !device)
+ return minus_one_set_errno(EINVAL);
+
/* This is a global rule so no need to append anything. */
if (device->global_rule >= 0) {
prog->blacklist = device->global_rule;
BPF_EXIT_INSN(),
};
+ if (!prog)
+ return minus_one_set_errno(EINVAL);
+
TRACE("Implementing %s bpf device cgroup program",
prog->blacklist ? "blacklist" : "whitelist");
return bpf_program_add_instructions(prog, ins, ARRAY_SIZE(ins));
union bpf_attr attr;
int ret;
+ if (!prog)
+ return minus_one_set_errno(EINVAL);
+
if (flags & ~(BPF_F_ALLOW_OVERRIDE, BPF_F_ALLOW_MULTI))
return error_log_errno(EINVAL, "Invalid flags for bpf program");