mount: restore root mount flags

Mount flags belong to mount and mount namespace of the Container, so we
should preserve them, as Container user will not expect mounts switching
between ro and rw over c/r.

Fixes: #2632

v5: fix both mount-v1 and mount-v2

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This commit is contained in:
Pavel Tikhomirov 2025-04-02 12:02:46 +08:00 committed by Andrei Vagin
parent b6dca31162
commit 88cb552f69
2 changed files with 13 additions and 0 deletions

View file

@ -443,6 +443,7 @@ err:
/* Mounts root container mount. */
static int do_mount_root_v2(struct mount_info *mi)
{
unsigned long mflags = mi->flags & (~MS_PROPAGATE);
unsigned long flags = MS_BIND;
int fd;
@ -477,6 +478,11 @@ static int do_mount_root_v2(struct mount_info *mi)
return -1;
}
if (mflags && mount(NULL, mi->plain_mountpoint, NULL, MS_REMOUNT | MS_BIND | mflags, NULL)) {
pr_perror("Unable to apply root mount options");
return -1;
}
mi->mounted = true;
return 0;

View file

@ -2690,9 +2690,16 @@ shared:
static int do_mount_root(struct mount_info *mi)
{
unsigned long mflags = mi->flags & (~MS_PROPAGATE);
if (restore_shared_options(mi, !mi->shared_id && !mi->master_id, mi->shared_id, mi->master_id))
return -1;
if (mflags && mount(NULL, service_mountpoint(mi), NULL, MS_REMOUNT | MS_BIND | mflags, NULL)) {
pr_perror("Unable to apply root mount options");
return -1;
}
return fetch_rt_stat(mi, service_mountpoint(mi));
}