From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 6FCEA1FF13B for ; Wed, 28 Jan 2026 18:18:55 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D1F4F188E8; Wed, 28 Jan 2026 18:19:19 +0100 (CET) From: Filip Schauer To: pve-devel@lists.proxmox.com Subject: [PATCH container] fix #7267: do not inherit host attributes for rootfs Date: Wed, 28 Jan 2026 17:54:05 +0100 Message-ID: <20260128165406.308592-1-f.schauer@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1769619185205 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.001 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lxc.pm] Message-ID-Hash: BRXCDMPABNTXMXFHRVXBUDUP5VD35W7F X-Message-ID-Hash: BRXCDMPABNTXMXFHRVXBUDUP5VD35W7F X-MailFrom: f.schauer@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: With the introduction of 0db559517ac6 (mountpoint_insert_staged: inherit attributes if directory already exists) mountpoints started preserving attributes of the underlying directory they were mounted over. This also unintentionally applied to the rootfs, causing "/" inside the container to be owned by "nobody". This commit exempts the rootfs from the attribute preservation, to avoid inheriting attributes from the host. Signed-off-by: Filip Schauer --- src/PVE/LXC.pm | 18 ++++++++++-------- src/lxc-pve-prestart-hook | 6 ++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index bab27b8..2df0e6c 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -2121,7 +2121,7 @@ sub mountpoint_stage { } sub mountpoint_insert_staged { - my ($mount_fd, $rootdir_fd, $mp_dir, $opt, $root_uid, $root_gid) = @_; + my ($mount_fd, $rootdir_fd, $mp_dir, $opt, $root_uid, $root_gid, $keep_attrs) = @_; if (!defined($rootdir_fd)) { sysopen($rootdir_fd, '.', O_PATH | O_DIRECTORY) @@ -2130,12 +2130,14 @@ sub mountpoint_insert_staged { my $dest_fd = walk_tree_nofollow_fd('/', $rootdir_fd, $mp_dir, 1, $root_uid, $root_gid); - # Preserve attributes of destination directory - my ($mode, $uid, $gid) = (stat($dest_fd))[2, 4, 5]; - PVE::Tools::fchownat(fileno($mount_fd), '', $uid, $gid, PVE::Tools::AT_EMPTY_PATH) - or die "failed to propagate uid and gid to mountpoint: $!\n"; - PVE::Tools::fchmodat(fileno($mount_fd), '.', $mode, 0) - or die "failed to propagate access mode to mountpoint: $!\n"; + if ($keep_attrs) { + # Preserve attributes of destination directory + my ($mode, $uid, $gid) = (stat($dest_fd))[2, 4, 5]; + PVE::Tools::fchownat(fileno($mount_fd), '', $uid, $gid, PVE::Tools::AT_EMPTY_PATH) + or die "failed to propagate uid and gid to mountpoint: $!\n"; + PVE::Tools::fchmodat(fileno($mount_fd), '.', $mode, 0) + or die "failed to propagate access mode to mountpoint: $!\n"; + } PVE::Tools::move_mount( fileno($mount_fd), @@ -2476,7 +2478,7 @@ sub mountpoint_hotplug : prototype($$$$$) { chdir('/') or die "failed to change root directory within the container's mount namespace: $!\n"; - mountpoint_insert_staged($mount_fd, undef, $mp->{mp}, $opt, $root_uid, $root_gid); + mountpoint_insert_staged($mount_fd, undef, $mp->{mp}, $opt, $root_uid, $root_gid, 1); }); } diff --git a/src/lxc-pve-prestart-hook b/src/lxc-pve-prestart-hook index 41af242..d264ab9 100755 --- a/src/lxc-pve-prestart-hook +++ b/src/lxc-pve-prestart-hook @@ -95,11 +95,12 @@ PVE::LXC::Tools::lxc_hook( $mountpoint, $dir, $storage_cfg, undef, $root_uid, $root_gid, ); - my ($dest_dir, $dest_base_fd); + my ($dest_dir, $dest_base_fd, $keep_attrs); if ($rootdir_fd) { # Mount relative to the rootdir fd. $dest_base_fd = $rootdir_fd; $dest_dir = './' . $mountpoint->{mp}; + $keep_attrs = 1; } else { # Assert that 'rootfs' is the first one: die "foreach_mount() error\n" if $opt ne 'rootfs'; @@ -109,10 +110,11 @@ PVE::LXC::Tools::lxc_hook( sysopen($dest_base_fd, '/', O_PATH | O_DIRECTORY) or die "failed to open '.': $!\n"; $dest_dir = $rootdir; + $keep_attrs = 0; } PVE::LXC::mountpoint_insert_staged( - $mount_fd, $dest_base_fd, $dest_dir, $opt, $root_uid, $root_gid, + $mount_fd, $dest_base_fd, $dest_dir, $opt, $root_uid, $root_gid, $keep_attrs, ); # From now on we mount inside our rootfs: -- 2.47.3