Skip to content

Commit e15ea97

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 9e8b921 commit e15ea97

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

tests/integration_tests/security/test_jail.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,60 @@ 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+
Regression test for #1089 / PR #1093.
232+
"""
233+
test_microvm = uvm
234+
chroot = Path(test_microvm.chroot())
235+
236+
kernel_jail_name = "vmlinux.bin"
237+
rootfs_jail_name = "rootfs.img"
238+
kernel_mount_point = chroot / kernel_jail_name
239+
rootfs_mount_point = chroot / rootfs_jail_name
240+
kernel_mount_point.touch()
241+
rootfs_mount_point.touch()
242+
subprocess.check_call(
243+
["mount", "--bind", str(test_microvm.kernel_file), str(kernel_mount_point)]
244+
)
245+
subprocess.check_call(
246+
["mount", "--bind", str(test_microvm.rootfs_file), str(rootfs_mount_point)]
247+
)
248+
try:
249+
test_microvm.spawn()
250+
251+
# Drive the API directly: basic_config() would hardlink over our
252+
# bind-mount points and mask what we are testing.
253+
test_microvm.api.machine_config.put(vcpu_count=2, mem_size_mib=256)
254+
test_microvm.boot_args = (
255+
"reboot=k panic=1 nomodule swiotlb=noforce console=ttyS0 cryptomgr.notests"
256+
)
257+
if not test_microvm.pci_enabled:
258+
test_microvm.boot_args += " pci=off"
259+
test_microvm.api.boot.put(
260+
kernel_image_path=f"/{kernel_jail_name}",
261+
boot_args=test_microvm.boot_args,
262+
)
263+
test_microvm.api.drive.put(
264+
drive_id="rootfs",
265+
path_on_host=f"/{rootfs_jail_name}",
266+
is_root_device=True,
267+
is_read_only=True,
268+
)
269+
test_microvm.add_net_iface()
270+
test_microvm.start()
271+
test_microvm.ssh.check_output("true")
272+
finally:
273+
# Unmount before the framework's chroot rmtree so it never
274+
# recurses into the bind-mount sources.
275+
test_microvm.kill()
276+
for mp in (rootfs_mount_point, kernel_mount_point):
277+
subprocess.run(["umount", str(mp)], check=False)
278+
279+
226280
class Cgroups:
227281
"""Helper class to work with cgroups"""
228282

0 commit comments

Comments
 (0)