Skip to content

Commit bc1320a

Browse files
yuwatabluca
authored andcommitted
core/namespace: honor MountEntry.read_only, .options, and so on in static entries
Otherwise, ProtectHome=tmpfs makes /home/ and friends not read-only. Also, mount options for /run/ specified in MountAPIVFS=yes are not applied. The function append_static_mounts() was introduced in 5327c91, but at that time, there were neither .read_only nor .options in the struct. But, when later the struct is extended, the function was not updated and they were not copied from the static table. The fields has been used in static tables since e4da7d8, and also in 94293d6. Fixes #34825. (cherry picked from commit 0cc496b) (cherry picked from commit dc44fd6)
1 parent 81c8433 commit bc1320a

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/core/namespace.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,16 @@ static int append_static_mounts(MountList *ml, const MountEntry *mounts, size_t
656656
if (!me)
657657
return log_oom_debug();
658658

659-
*me = (MountEntry) {
660-
.path_const = mount_entry_path(m),
661-
.mode = m->mode,
662-
.ignore = m->ignore || ignore_protect,
663-
};
659+
/* No dynamic values allowed. */
660+
assert(m->path_const);
661+
assert(!m->path_malloc);
662+
assert(!m->unprefixed_path_malloc);
663+
assert(!m->source_malloc);
664+
assert(!m->options_malloc);
665+
assert(!m->overlay_layers);
666+
667+
*me = *m;
668+
me->ignore = me->ignore || ignore_protect;
664669
}
665670

666671
return 0;

test/units/testsuite-07.exec-context.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,22 @@ if [[ -z "${COVERAGE_BUILD_DIR:-}" ]]; then
4646
bash -xec "test ! -w /home; test ! -w /root; test ! -w /run/user; test ! -e $MARK"
4747
systemd-run --wait --pipe -p ProtectHome=read-only \
4848
bash -xec "test ! -w /home; test ! -w /root; test ! -w /run/user; test -e $MARK"
49-
systemd-run --wait --pipe -p ProtectHome=tmpfs \
50-
bash -xec "test -w /home; test -w /root; test -w /run/user; test ! -e $MARK"
49+
systemd-run --wait --pipe -p ProtectHome=tmpfs -p TemporaryFileSystem=/home/foo \
50+
bash -xec "test ! -w /home; test ! -w /root; test ! -w /run/user; test ! -e $MARK; test -w /home/foo"
5151
systemd-run --wait --pipe -p ProtectHome=no \
5252
bash -xec "test -w /home; test -w /root; test -w /run/user; test -e $MARK"
5353
rm -f "$MARK"
5454
fi
5555

56+
systemd-run --wait --pipe -p PrivateMounts=true -p MountAPIVFS=yes \
57+
bash -xec '[[ "$(findmnt --mountpoint /proc --noheadings -o FSTYPE)" == proc ]];
58+
[[ "$$(findmnt --mountpoint /dev --noheadings -o FSTYPE)" =~ (devtmpfs|tmpfs) ]];
59+
[[ "$$(findmnt --mountpoint /sys --noheadings -o FSTYPE)" =~ (sysfs|tmpfs) ]];
60+
[[ "$$(findmnt --mountpoint /run --noheadings -o FSTYPE)" == tmpfs ]];
61+
[[ "$$(findmnt --mountpoint /run --noheadings -o VFS-OPTIONS)" =~ rw ]];
62+
[[ "$$(findmnt --mountpoint /run --noheadings -o VFS-OPTIONS)" =~ nosuid ]];
63+
[[ "$$(findmnt --mountpoint /run --noheadings -o VFS-OPTIONS)" =~ nodev ]]'
64+
5665
if proc_supports_option "hidepid=off"; then
5766
systemd-run --wait --pipe -p ProtectProc=noaccess -p User=testuser \
5867
bash -xec 'test -e /proc/1; test ! -r /proc/1; test -r /proc/$$$$/comm'

0 commit comments

Comments
 (0)