Skip to content

Commit 9440020

Browse files
Junren Chenxxgj
authored andcommitted
test(jailer): regression test for chroot bind-mount propagation
Bind mounts established on the host inside the chroot before jailer start must propagate into the jailer's mount namespace. The test bind-mounts kernel and rootfs onto empty placeholders in the chroot and drives the API directly (bypassing basic_config to avoid create_jailed_resource hardlinking over the mounts), then asserts a clean SSH boot. Signed-off-by: Junren Chen <xxgj@outlook.com>
1 parent 255ecb9 commit 9440020

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

tests/integration_tests/security/test_jail.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,63 @@ def test_arbitrary_usocket_location(uvm):
223223
)
224224

225225

226+
@pin_guest_kernel(GUEST_KERNEL_DEFAULT)
227+
def test_jailer_bind_mount_propagation(uvm):
228+
"""
229+
Test that host bind-mounts inside the chroot propagate into the jail.
230+
231+
Mounts that exist before the jailer starts, covering the recursive
232+
self-bind fix (MS_BIND -> MS_BIND | MS_REC).
233+
234+
Regression test for #1089.
235+
"""
236+
test_microvm = uvm
237+
chroot = Path(test_microvm.chroot())
238+
239+
kernel_jail_name = "vmlinux.bin"
240+
rootfs_jail_name = "rootfs.img"
241+
kernel_mount_point = chroot / kernel_jail_name
242+
rootfs_mount_point = chroot / rootfs_jail_name
243+
kernel_mount_point.touch()
244+
rootfs_mount_point.touch()
245+
try:
246+
subprocess.check_call(
247+
["mount", "--bind", str(test_microvm.kernel_file), str(kernel_mount_point)]
248+
)
249+
subprocess.check_call(
250+
["mount", "--bind", str(test_microvm.rootfs_file), str(rootfs_mount_point)]
251+
)
252+
test_microvm.spawn()
253+
254+
# Drive the API directly: basic_config() would hardlink over our
255+
# bind-mount points and mask what we are testing.
256+
test_microvm.api.machine_config.put(vcpu_count=2, mem_size_mib=256)
257+
test_microvm.boot_args = (
258+
"reboot=k panic=1 nomodule swiotlb=noforce console=ttyS0 cryptomgr.notests"
259+
)
260+
if not test_microvm.pci_enabled:
261+
test_microvm.boot_args += " pci=off"
262+
test_microvm.api.boot.put(
263+
kernel_image_path=f"/{kernel_jail_name}",
264+
boot_args=test_microvm.boot_args,
265+
)
266+
test_microvm.api.drive.put(
267+
drive_id="rootfs",
268+
path_on_host=f"/{rootfs_jail_name}",
269+
is_root_device=True,
270+
is_read_only=True,
271+
)
272+
test_microvm.add_net_iface()
273+
test_microvm.start()
274+
test_microvm.ssh.check_output("true")
275+
finally:
276+
# Unmount before the framework's chroot rmtree so it never
277+
# recurses into the bind-mount sources.
278+
test_microvm.kill()
279+
for mp in (rootfs_mount_point, kernel_mount_point):
280+
subprocess.run(["umount", str(mp)], check=False)
281+
282+
226283
class Cgroups:
227284
"""Helper class to work with cgroups"""
228285

0 commit comments

Comments
 (0)