Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
aa29c0bd
Unverified
Commit
aa29c0bd
authored
Dec 01, 2019
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cgroups/devices: introduce ebpf device cgroup global rule types
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
5d14cf6f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
13 deletions
+31
-13
cgfsng.c
src/lxc/cgroups/cgfsng.c
+4
-2
cgroup2_devices.c
src/lxc/cgroups/cgroup2_devices.c
+16
-7
cgroup2_devices.h
src/lxc/cgroups/cgroup2_devices.h
+1
-1
conf.h
src/lxc/conf.h
+10
-3
No files found.
src/lxc/cgroups/cgfsng.c
View file @
aa29c0bd
...
...
@@ -2303,11 +2303,13 @@ static int device_cgroup_rule_parse(struct device_item *device, const char *key,
device
->
type
=
'a'
;
device
->
major
=
-
1
;
device
->
minor
=
-
1
;
device
->
global_rule
=
device
->
allow
;
device
->
global_rule
=
device
->
allow
?
LXC_BPF_DEVICE_CGROUP_BLACKLIST
:
LXC_BPF_DEVICE_CGROUP_WHITELIST
;
device
->
allow
=
-
1
;
return
0
;
}
else
{
device
->
global_rule
=
-
1
;
device
->
global_rule
=
LXC_BPF_DEVICE_CGROUP_LOCAL_RULE
;
}
switch
(
*
val
)
{
...
...
src/lxc/cgroups/cgroup2_devices.c
View file @
aa29c0bd
...
...
@@ -173,6 +173,10 @@ struct bpf_program *bpf_program_new(uint32_t prog_type)
prog
->
prog_type
=
prog_type
;
prog
->
kernel_fd
=
-
EBADF
;
/*
* By default a whitelist is used unless the user tells us otherwise.
*/
prog
->
device_list_type
=
LXC_BPF_DEVICE_CGROUP_WHITELIST
;
return
move_ptr
(
prog
);
}
...
...
@@ -216,8 +220,8 @@ int bpf_program_append_device(struct bpf_program *prog, struct device_item *devi
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
;
if
(
device
->
global_rule
>
LXC_BPF_DEVICE_CGROUP_LOCAL_RULE
)
{
prog
->
device_list_type
=
device
->
global_rule
;
return
0
;
}
...
...
@@ -292,7 +296,7 @@ int bpf_program_append_device(struct bpf_program *prog, struct device_item *devi
int
bpf_program_finalize
(
struct
bpf_program
*
prog
)
{
struct
bpf_insn
ins
[]
=
{
BPF_MOV64_IMM
(
BPF_REG_0
,
prog
->
blacklist
?
1
:
0
),
BPF_MOV64_IMM
(
BPF_REG_0
,
prog
->
device_list_type
),
BPF_EXIT_INSN
(),
};
...
...
@@ -300,7 +304,9 @@ int bpf_program_finalize(struct bpf_program *prog)
return
minus_one_set_errno
(
EINVAL
);
TRACE
(
"Implementing %s bpf device cgroup program"
,
prog
->
blacklist
?
"blacklist"
:
"whitelist"
);
prog
->
device_list_type
==
LXC_BPF_DEVICE_CGROUP_BLACKLIST
?
"blacklist"
:
"whitelist"
);
return
bpf_program_add_instructions
(
prog
,
ins
,
ARRAY_SIZE
(
ins
));
}
...
...
@@ -443,9 +449,12 @@ int bpf_list_add_device(struct lxc_conf *conf, struct device_item *device)
if
(
cur
->
global_rule
!=
-
1
&&
device
->
global_rule
!=
-
1
)
{
TRACE
(
"Switched from %s to %s"
,
cur
->
global_rule
==
0
?
"whitelist"
:
"blacklist"
,
device
->
global_rule
==
0
?
"whitelist"
:
"blacklist"
);
cur
->
global_rule
==
LXC_BPF_DEVICE_CGROUP_WHITELIST
?
"whitelist"
:
"blacklist"
,
device
->
global_rule
==
LXC_BPF_DEVICE_CGROUP_WHITELIST
?
"whitelist"
:
"blacklist"
);
cur
->
global_rule
=
device
->
global_rule
;
return
1
;
}
...
...
src/lxc/cgroups/cgroup2_devices.h
View file @
aa29c0bd
...
...
@@ -63,7 +63,7 @@ static inline int missing_bpf(int cmd, union bpf_attr *attr, size_t size)
#endif
struct
bpf_program
{
bool
blacklist
;
int
device_list_type
;
int
kernel_fd
;
uint32_t
prog_type
;
...
...
src/lxc/conf.h
View file @
aa29c0bd
...
...
@@ -223,15 +223,22 @@ struct lxc_state_client {
lxc_state_t
states
[
MAX_STATE
];
};
enum
{
LXC_BPF_DEVICE_CGROUP_WHITELIST
=
0
,
LXC_BPF_DEVICE_CGROUP_BLACKLIST
=
1
,
LXC_BPF_DEVICE_CGROUP_LOCAL_RULE
=
-
1
,
};
struct
device_item
{
char
type
;
int
major
;
int
minor
;
char
access
[
4
];
int
allow
;
/* -1 -> no global rule
* 0 -> whitelist (deny all)
* 1 -> blacklist (allow all)
/*
* LXC_BPF_DEVICE_CGROUP_LOCAL_RULE -> no global rule
* LXC_BPF_DEVICE_CGROUP_WHITELIST -> whitelist (deny all)
* LXC_BPF_DEVICE_CGROUP_BLACKLIST -> blacklist (allow all)
*/
int
global_rule
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment