summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Blenk <Maximilian.Blenk@bmw.de>2021-09-09 10:05:05 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-10-11 18:41:38 +0100
commite325390b91da7d3b43e78ad840a9fe5cd14a9ab7 (patch)
tree5e08f4ef32864bf1832adaf7df0e32634098c234
parente1d658ef1153ecb16acda19e3f6fe2edea7cf4e4 (diff)
downloadpoky-e325390b91da7d3b43e78ad840a9fe5cd14a9ab7.tar.gz
mount-copybind: add rootcontext mountoption for overlayfs
If selinux is enabled, the context of the mountpoint for overlayfs needs to be specified manually via the rootcontext option. To this end, the required context is determined using matchpathcon(1) and passed via the rootcontext mount option. Additionally, if the mount source directory is created by mount-copybind it also needs to take care that the context of the directory is correct (From OE-Core rev: 57f51e8c73ab9f55f20815a9459c3afad2b281e6) Signed-off-by: Tobias Kaufmann <Tobias.KA.Kaufmann@bmw.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-xmeta/recipes-core/volatile-binds/files/mount-copybind14
1 files changed, 13 insertions, 1 deletions
diff --git a/meta/recipes-core/volatile-binds/files/mount-copybind b/meta/recipes-core/volatile-binds/files/mount-copybind
index 57a5ce5f21..aad022c6e4 100755
--- a/meta/recipes-core/volatile-binds/files/mount-copybind
+++ b/meta/recipes-core/volatile-binds/files/mount-copybind
@@ -31,6 +31,13 @@ if [ -d "$mountpoint" ]; then
31 else 31 else
32 specdir_existed=no 32 specdir_existed=no
33 mkdir "$spec" 33 mkdir "$spec"
34 # If the $spec directory is created we need to take care that
35 # the selinux context is correct
36 if command -v selinuxenabled > /dev/null 2>&1; then
37 if selinuxenabled; then
38 restorecon "$spec"
39 fi
40 fi
34 fi 41 fi
35 42
36 # Fast version of calculating `dirname ${spec}`/.`basename ${spec}`-work 43 # Fast version of calculating `dirname ${spec}`/.`basename ${spec}`-work
@@ -39,7 +46,12 @@ if [ -d "$mountpoint" ]; then
39 46
40 # Try to mount using overlay, which is must faster than copying files. 47 # Try to mount using overlay, which is must faster than copying files.
41 # If that fails, fall back to slower copy. 48 # If that fails, fall back to slower copy.
42 if ! mount -t overlay overlay -olowerdir="$mountpoint",upperdir="$spec",workdir="$overlay_workdir" "$mountpoint" > /dev/null 2>&1; then 49 if command -v selinuxenabled > /dev/null 2>&1; then
50 if selinuxenabled; then
51 mountcontext=",rootcontext=$(matchpathcon -n $mountpoint)"
52 fi
53 fi
54 if ! mount -t overlay overlay -olowerdir="$mountpoint",upperdir="$spec",workdir="$overlay_workdir""$mountcontext" "$mountpoint" > /dev/null 2>&1; then
43 55
44 if [ "$specdir_existed" != "yes" ]; then 56 if [ "$specdir_existed" != "yes" ]; then
45 cp -aPR "$mountpoint"/. "$spec/" 57 cp -aPR "$mountpoint"/. "$spec/"