From: Jan Kiszka <jan.kiszka@siemens.com>
To: isar-users <isar-users@googlegroups.com>
Subject: [PATCH v2] Avoid sharing of /dev/shm from the build context
Date: Fri, 18 Mar 2022 18:46:00 +0100 [thread overview]
Message-ID: <50a15579-0b26-8dbe-6c71-d037f04bf53a@siemens.com> (raw)
From: Jan Kiszka <jan.kiszka@siemens.com>
By bind-mounting complete /dev into the various chroots, we also share
the host instance of /dev/shm between them. If some package installation
should actually make use of that tmpfs instance, it may find content of
others there. That is at least not desirable, in few cases even
problematic (sysrepo package uses it during postinst, and this causes
troubles when multiple images are built in parallel).
This decouples all instances by mounting new instances over the
bind-mounted ones.
While at it, it switches the recursive bind-mounting of /dev to
explicit one. /dev/shm then becomes the only sub-mount. This is assumed
to be sufficient for the given use cases.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
Changes in v2:
- replace --rbind with --bind
- link both sub-shell mounts via &&
meta/classes/buildchroot.bbclass | 3 ++-
meta/classes/rootfs.bbclass | 3 ++-
meta/recipes-core/isar-bootstrap/isar-bootstrap.inc | 4 +++-
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/meta/classes/buildchroot.bbclass b/meta/classes/buildchroot.bbclass
index dd8f4206..01078684 100644
--- a/meta/classes/buildchroot.bbclass
+++ b/meta/classes/buildchroot.bbclass
@@ -42,7 +42,8 @@ buildchroot_do_mounts() {
mount --bind '${CCACHE_DIR}' '${BUILDCHROOT_DIR}/ccache'
fi
mountpoint -q '${BUILDCHROOT_DIR}/dev' ||
- mount --rbind /dev '${BUILDCHROOT_DIR}/dev'
+ ( mount --bind /dev '${BUILDCHROOT_DIR}/dev' &&
+ mount -t tmpfs none '${BUILDCHROOT_DIR}/dev/shm' )
mount --make-rslave '${BUILDCHROOT_DIR}/dev'
mountpoint -q '${BUILDCHROOT_DIR}/proc' ||
mount -t proc none '${BUILDCHROOT_DIR}/proc'
diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
index 927af13f..16303778 100644
--- a/meta/classes/rootfs.bbclass
+++ b/meta/classes/rootfs.bbclass
@@ -34,7 +34,8 @@ rootfs_do_mounts() {
sudo -s <<'EOSUDO'
set -e
mountpoint -q '${ROOTFSDIR}/dev' || \
- mount --rbind /dev '${ROOTFSDIR}/dev'
+ ( mount --bind /dev '${ROOTFSDIR}/dev' &&
+ mount -t tmpfs none '${ROOTFSDIR}/dev/shm' )
mount --make-rslave '${ROOTFSDIR}/dev'
mountpoint -q '${ROOTFSDIR}/proc' || \
mount -t proc none '${ROOTFSDIR}/proc'
diff --git a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
index 1b16f874..9e858a46 100644
--- a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
+++ b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
@@ -360,7 +360,8 @@ do_bootstrap() {
"${ROOTFSDIR}/chroot-setup.sh" "setup" "${ROOTFSDIR}"
# update APT
- mount --rbind /dev ${ROOTFSDIR}/dev
+ mount --bind /dev ${ROOTFSDIR}/dev
+ mount -t tmpfs none "${ROOTFSDIR}/dev/shm"
mount --make-rslave ${ROOTFSDIR}/dev
mount -t proc none ${ROOTFSDIR}/proc
mount --rbind /sys ${ROOTFSDIR}/sys
@@ -381,6 +382,7 @@ do_bootstrap() {
chroot "${ROOTFSDIR}" /usr/bin/apt-get dist-upgrade -y \
-o Debug::pkgProblemResolver=yes
+ umount -l "${ROOTFSDIR}/dev/shm"
umount -l "${ROOTFSDIR}/dev"
umount -l "${ROOTFSDIR}/proc"
umount -l "${ROOTFSDIR}/sys"
--
2.34.1
next reply other threads:[~2022-03-18 17:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-18 17:46 Jan Kiszka [this message]
2022-03-21 11:25 ` Baurzhan Ismagulov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50a15579-0b26-8dbe-6c71-d037f04bf53a@siemens.com \
--to=jan.kiszka@siemens.com \
--cc=isar-users@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox