lxc / lxcfs

FUSE filesystem for LXC
https://linuxcontainers.org/lxcfs
Other
1.04k stars 251 forks source link

Null pointer reference in bpf_program_finalize #607

Closed peppaJoeng closed 1 year ago

peppaJoeng commented 1 year ago

https://github.com/lxc/lxcfs/blob/587c661b7ad3e2f7bca7a5a396ae135fd0e7c18f/src/cgroups/cgroup2_devices.c#L291C1-L306C2

int bpf_program_finalize(struct bpf_program *prog)
{
        struct bpf_insn ins[] = {
            BPF_MOV64_IMM(BPF_REG_0, prog->device_list_type),
            BPF_EXIT_INSN(),
        };

        if (!prog)
                return ret_set_errno(-1, EINVAL);
        TRACE("Implementing %s bpf device cgroup program",

When I study this part of the code, in the bpf_program_finalize function, first get the proc variable, and then judge whether the proc variable is empty, there will be a null pointer reference.

By the way, why do you need to use bpf_program_xxx type functions in lxcfs, which seems to be related to ebpf

mihalicyn commented 1 year ago

When I study this part of the code, in the bpf_program_finalize function, first get the proc variable, and then judge whether the proc variable is empty, there will be a null pointer reference.

yes, you are right.

At the same time this function is not called anywhere in LXCFS because the whole file was imported from LXC project. Some functions are redundant.

Probably I need to go through it and make some clean up. If you want to send a PR you are welcome too!

peppaJoeng commented 1 year ago

I'm not very familiar with this part, if you want to do a unified cleanup, it's up to you to fix it, I want to learn.