File tree 2 files changed +15
-24
lines changed
2 files changed +15
-24
lines changed Original file line number Diff line number Diff line change @@ -31,10 +31,6 @@ pub trait DeviceAccessController {
31
31
minor : u32 ,
32
32
access : Access ,
33
33
) -> Result < ( ) > ;
34
-
35
- /// Stop performing access control. This may allow all accesses, so should only be used when
36
- /// the cgroup is shutdown.
37
- fn stop ( self : Box < Self > ) -> Result < ( ) > ;
38
34
}
39
35
40
36
pub struct DeviceAccessControllerV1 {
@@ -105,10 +101,6 @@ impl DeviceAccessController for DeviceAccessControllerV1 {
105
101
106
102
Ok ( ( ) )
107
103
}
108
-
109
- fn stop ( self : Box < Self > ) -> Result < ( ) > {
110
- Ok ( ( ) )
111
- }
112
104
}
113
105
114
106
#[ repr( C ) ] // This is read as POD by the BPF program.
@@ -179,6 +171,12 @@ impl DeviceAccessControllerV2 {
179
171
}
180
172
}
181
173
174
+ impl Drop for DeviceAccessControllerV2 {
175
+ fn drop ( & mut self ) {
176
+ let _ = std:: fs:: remove_file ( & self . pin ) ;
177
+ }
178
+ }
179
+
182
180
impl DeviceAccessController for DeviceAccessControllerV2 {
183
181
fn set_permission (
184
182
& mut self ,
@@ -199,11 +197,6 @@ impl DeviceAccessController for DeviceAccessControllerV2 {
199
197
}
200
198
Ok ( ( ) )
201
199
}
202
-
203
- fn stop ( self : Box < Self > ) -> Result < ( ) > {
204
- CgroupDevice :: from_pin ( & self . pin ) ?. unpin ( ) ?;
205
- Ok ( ( ) )
206
- }
207
200
}
208
201
209
202
pub struct DeviceAccessControllerDummy ;
@@ -218,8 +211,4 @@ impl DeviceAccessController for DeviceAccessControllerDummy {
218
211
) -> Result < ( ) > {
219
212
bail ! ( "neither cgroup v1 and cgroup v2 works" ) ;
220
213
}
221
-
222
- fn stop ( self : Box < Self > ) -> Result < ( ) > {
223
- Ok ( ( ) )
224
- }
225
214
}
Original file line number Diff line number Diff line change
1
+ use std:: mem:: ManuallyDrop ;
1
2
use std:: pin:: pin;
2
3
use std:: sync:: { Arc , Mutex } ;
3
4
use std:: time:: Duration ;
@@ -22,7 +23,7 @@ pub struct Container {
22
23
id : String ,
23
24
user : String ,
24
25
remove_event : Shared < BoxFuture < ' static , Option < EventMessage > > > ,
25
- cgroup_device_filter : Arc < Mutex < Option < Box < dyn DeviceAccessController + Send > > > > ,
26
+ cgroup_device_filter : Arc < Mutex < Option < ManuallyDrop < Box < dyn DeviceAccessController + Send > > > > > ,
26
27
}
27
28
28
29
impl Container {
@@ -61,6 +62,10 @@ impl Container {
61
62
} ,
62
63
} ;
63
64
65
+ // Dropping the device filter will cause the container to have arbitrary device access.
66
+ // So keep it alive until we're sure that the container is stopped.
67
+ let cgroup_device_filter = ManuallyDrop :: new ( cgroup_device_filter) ;
68
+
64
69
Ok ( Self {
65
70
docker : docker. clone ( ) ,
66
71
id,
@@ -109,12 +114,9 @@ impl Container {
109
114
}
110
115
111
116
// Stop the cgroup device filter. Only do so once we're sure that the container is removed.
112
- self . cgroup_device_filter
113
- . lock ( )
114
- . unwrap ( )
115
- . take ( )
116
- . unwrap ( )
117
- . stop ( ) ?;
117
+ drop ( ManuallyDrop :: into_inner (
118
+ self . cgroup_device_filter . lock ( ) . unwrap ( ) . take ( ) . unwrap ( ) ,
119
+ ) ) ;
118
120
119
121
Ok ( ( ) )
120
122
}
You can’t perform that action at this time.
0 commit comments