cgroups/devices: handle NULL

parent ba2cb20d
...@@ -51,6 +51,9 @@ static int bpf_program_add_instructions(struct bpf_program *prog, ...@@ -51,6 +51,9 @@ static int bpf_program_add_instructions(struct bpf_program *prog,
void bpf_program_free(struct bpf_program *prog) void bpf_program_free(struct bpf_program *prog)
{ {
if (!prog)
return;
(void)bpf_program_cgroup_detach(prog); (void)bpf_program_cgroup_detach(prog);
if (prog->kernel_fd >= 0) if (prog->kernel_fd >= 0)
...@@ -176,6 +179,9 @@ struct bpf_program *bpf_program_new(uint32_t prog_type) ...@@ -176,6 +179,9 @@ struct bpf_program *bpf_program_new(uint32_t prog_type)
int bpf_program_init(struct bpf_program *prog) int bpf_program_init(struct bpf_program *prog)
{ {
if (!prog)
return minus_one_set_errno(EINVAL);
const struct bpf_insn pre_insn[] = { const struct bpf_insn pre_insn[] = {
/* load device type to r2 */ /* load device type to r2 */
BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, offsetof(struct bpf_cgroup_dev_ctx, access_type)), BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, offsetof(struct bpf_cgroup_dev_ctx, access_type)),
...@@ -206,6 +212,9 @@ int bpf_program_append_device(struct bpf_program *prog, struct device_item *devi ...@@ -206,6 +212,9 @@ int bpf_program_append_device(struct bpf_program *prog, struct device_item *devi
int access_mask; int access_mask;
int device_type; int device_type;
if (!prog || !device)
return minus_one_set_errno(EINVAL);
/* This is a global rule so no need to append anything. */ /* This is a global rule so no need to append anything. */
if (device->global_rule >= 0) { if (device->global_rule >= 0) {
prog->blacklist = device->global_rule; prog->blacklist = device->global_rule;
...@@ -287,6 +296,9 @@ int bpf_program_finalize(struct bpf_program *prog) ...@@ -287,6 +296,9 @@ int bpf_program_finalize(struct bpf_program *prog)
BPF_EXIT_INSN(), BPF_EXIT_INSN(),
}; };
if (!prog)
return minus_one_set_errno(EINVAL);
TRACE("Implementing %s bpf device cgroup program", TRACE("Implementing %s bpf device cgroup program",
prog->blacklist ? "blacklist" : "whitelist"); prog->blacklist ? "blacklist" : "whitelist");
return bpf_program_add_instructions(prog, ins, ARRAY_SIZE(ins)); return bpf_program_add_instructions(prog, ins, ARRAY_SIZE(ins));
...@@ -327,6 +339,9 @@ int bpf_program_cgroup_attach(struct bpf_program *prog, int type, ...@@ -327,6 +339,9 @@ int bpf_program_cgroup_attach(struct bpf_program *prog, int type,
union bpf_attr attr; union bpf_attr attr;
int ret; int ret;
if (!prog)
return minus_one_set_errno(EINVAL);
if (flags & ~(BPF_F_ALLOW_OVERRIDE, BPF_F_ALLOW_MULTI)) if (flags & ~(BPF_F_ALLOW_OVERRIDE, BPF_F_ALLOW_MULTI))
return error_log_errno(EINVAL, "Invalid flags for bpf program"); return error_log_errno(EINVAL, "Invalid flags for bpf program");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment