]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
bpf: don't close invalid fd, simply swap
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 18 Feb 2021 10:37:28 +0000 (11:37 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 18 Feb 2021 10:54:32 +0000 (11:54 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgroup2_devices.c

index 05ac85877c4d4d569ec68f40f17939957f6d2b55..76d57a33b6fec2037efd19926f3b84c1b6464136 100644 (file)
@@ -365,7 +365,7 @@ static int bpf_program_load_kernel(struct bpf_program *prog)
 int bpf_program_cgroup_attach(struct bpf_program *prog, int type, int fd_cgroup,
                              int replace_bpf_fd, __u32 flags)
 {
-       __do_close int fd_cgroup_dup = -EBADF;
+       __do_close int fd_attach = -EBADF;
        int ret;
        union bpf_attr *attr;
 
@@ -400,8 +400,8 @@ int bpf_program_cgroup_attach(struct bpf_program *prog, int type, int fd_cgroup,
        }
 
        /* Leave the caller's fd alone. */
-       fd_cgroup_dup = dup_cloexec(fd_cgroup);
-       if (fd_cgroup_dup < 0)
+       fd_attach = dup_cloexec(fd_cgroup);
+       if (fd_attach < 0)
                return -errno;
 
        ret = bpf_program_load_kernel(prog);
@@ -410,7 +410,7 @@ int bpf_program_cgroup_attach(struct bpf_program *prog, int type, int fd_cgroup,
 
        attr = &(union bpf_attr){
                .attach_type    = type,
-               .target_fd      = fd_cgroup_dup,
+               .target_fd      = fd_attach,
                .attach_bpf_fd  = prog->kernel_fd,
                .attach_flags   = flags,
        };
@@ -422,7 +422,7 @@ int bpf_program_cgroup_attach(struct bpf_program *prog, int type, int fd_cgroup,
        if (ret < 0)
                return syserrno_set(-errno, "Failed to attach bpf program");
 
-       close_move_fd(prog->fd_cgroup, fd_cgroup_dup);
+       swap(prog->fd_cgroup, fd_attach);
        prog->attached_type = type;
        prog->attached_flags = flags;