From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 655DB92405 for ; Mon, 12 Sep 2022 14:42:06 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 59C5D4F88 for ; Mon, 12 Sep 2022 14:42:06 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 12 Sep 2022 14:42:05 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4F42543543 for ; Mon, 12 Sep 2022 14:42:05 +0200 (CEST) Date: Mon, 12 Sep 2022 14:41:55 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: pve-devel@lists.proxmox.com References: <20220912122539.85794-1-l.nunner@proxmox.com> In-Reply-To: <20220912122539.85794-1-l.nunner@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1662985982.t6rahmo5l4.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.010 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pve-devel] [PATCH v2 container] fix #4192: revamp check for systemd version X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Sep 2022 12:42:06 -0000 On September 12, 2022 2:25 pm, Leo Nunner wrote: > Instead of iterating through several folders, it might just be easier to > check the ldd output of /sbin/init and getting the version from there. > Furthermore, the regex for checking the version has been adapted so that > it's more precise. ldd is not suited for this purpose for security reasons, since /sbin/init=20 is a user/attacker-controlled binary in this case and we are only in a=20 chroot while doing the setup, not really containerized. given a crafted=20 container template/backup archive/.. this could execute arbitrary code. it's manpage suggests using objdump -p /path/to/binary and looking at the lines with "NEEDED", which seems to me should be fine=20 for what we want to achieve here :) >=20 > Signed-off-by: Leo Nunner > --- > This solution does actually feel cleaner than manually checking all the f= olders > every time. >=20 > src/PVE/LXC/Setup/Base.pm | 27 +++++++++++++++++---------- > 1 file changed, 17 insertions(+), 10 deletions(-) >=20 > diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm > index cc12914..44b88d9 100644 > --- a/src/PVE/LXC/Setup/Base.pm > +++ b/src/PVE/LXC/Setup/Base.pm > @@ -514,19 +514,26 @@ sub clear_machine_id { > } > } > =20 > -# tries to guess the systemd (major) version based on the existence of > -# (/usr)?/lib/systemd/libsystemd-shared.so. It was introduced i= n v231. > +# tries to guess the systemd (major) version based on the > +# libsystemd-shared.so linked with /sbin/init > sub get_systemd_version { > my ($self) =3D @_; > =20 > - my $sd_lib_dir =3D $self->ct_is_directory("/lib/systemd") ? > - "/lib/systemd" : "/usr/lib/systemd"; > - my $libsd =3D PVE::Tools::dir_glob_regex($sd_lib_dir, "libsystemd-sh= ared-.+\.so"); > - if (defined($libsd) && $libsd =3D~ /libsystemd-shared-(\d+)(?:\..*)?= \.so/) { > - return $1; > - } > - > - return undef; > + my $version =3D undef; > + PVE::Tools::run_command( > + [ > + 'ldd', > + '/sbin/init' > + ], > + outfunc =3D> sub { > + my $line =3D shift; > + if ($line =3D~ /^\s*libsystemd-shared-(\d+)(?:\.[a-zA-Z0-9]*)?\.so/= ) { > + $version =3D $1; > + }}, > + errmsg =3D> "ldd on /sbin/init failed" > + ); > + > + return $version; > } > =20 > sub unified_cgroupv2_support { > --=20 > 2.30.2 >=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20 >=20 >=20