mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

cgroup_xattr/read_cgroupfs_xattr has two issues:
1. cgroup_xattr/read_cgroupfs_xattr messes up lo without creating a netns
first. This causes issue with other tests.
Fix this by using a different hook (lsm.s/file_open) and not messing
with lo.
2. cgroup_xattr/read_cgroupfs_xattr sets up cgroups without proper
mount namespaces.
Fix this by using the existing cgroup helpers. A new helper
set_cgroup_xattr() is added to set xattr on cgroup files.
Fixes: f4fba2d6d2
("selftests/bpf: Add tests for bpf_cgroup_read_xattr")
Reported-by: Alexei Starovoitov <ast@kernel.org>
Closes: https://lore.kernel.org/bpf/CAADnVQ+iqMi2HEj_iH7hsx+XJAsqaMWqSDe4tzcGAnehFWA9Sw@mail.gmail.com/
Signed-off-by: Song Liu <song@kernel.org>
Tested-by: Eduard Zingerman <eddyz87@gmail.com>
Tested-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Link: https://lore.kernel.org/r/20250627191221.765921-1-song@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
45 lines
1.4 KiB
C
45 lines
1.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __CGROUP_HELPERS_H
|
|
#define __CGROUP_HELPERS_H
|
|
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
|
|
#define clean_errno() (errno == 0 ? "None" : strerror(errno))
|
|
#define log_err(MSG, ...) fprintf(stderr, "(%s:%d: errno: %s) " MSG "\n", \
|
|
__FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
|
|
|
|
/* cgroupv2 related */
|
|
int enable_controllers(const char *relative_path, const char *controllers);
|
|
int write_cgroup_file(const char *relative_path, const char *file,
|
|
const char *buf);
|
|
int write_cgroup_file_parent(const char *relative_path, const char *file,
|
|
const char *buf);
|
|
int cgroup_setup_and_join(const char *relative_path);
|
|
int get_root_cgroup(void);
|
|
int create_and_get_cgroup(const char *relative_path);
|
|
void remove_cgroup(const char *relative_path);
|
|
unsigned long long get_cgroup_id(const char *relative_path);
|
|
int get_cgroup1_hierarchy_id(const char *subsys_name);
|
|
|
|
int join_cgroup(const char *relative_path);
|
|
int join_root_cgroup(void);
|
|
int join_parent_cgroup(const char *relative_path);
|
|
|
|
int set_cgroup_xattr(const char *relative_path,
|
|
const char *name,
|
|
const char *value);
|
|
|
|
int setup_cgroup_environment(void);
|
|
void cleanup_cgroup_environment(void);
|
|
|
|
/* cgroupv1 related */
|
|
int set_classid(void);
|
|
int join_classid(void);
|
|
unsigned long long get_classid_cgroup_id(void);
|
|
int open_classid(void);
|
|
|
|
int setup_classid_environment(void);
|
|
void cleanup_classid_environment(void);
|
|
|
|
#endif /* __CGROUP_HELPERS_H */
|