• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 19397511130

15 Nov 2025 09:47PM UTC coverage: 72.518% (+0.1%) from 72.37%
19397511130

push

github

web-flow
sd-event: several follow-ups for recent change (#39743)

3 of 4 new or added lines in 2 files covered. (75.0%)

1869 existing lines in 55 files now uncovered.

308519 of 425439 relevant lines covered (72.52%)

1258617.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.52
/src/nspawn/nspawn-mount.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <linux/magic.h>
4
#include <sys/mount.h>
5
#include <unistd.h>
6

7
#include "alloc-util.h"
8
#include "chase.h"
9
#include "errno-util.h"
10
#include "escape.h"
11
#include "extract-word.h"
12
#include "fd-util.h"
13
#include "format-util.h"
14
#include "fs-util.h"
15
#include "log.h"
16
#include "mkdir-label.h"
17
#include "mount-util.h"
18
#include "mountpoint-util.h"
19
#include "namespace-util.h"
20
#include "nspawn-mount.h"
21
#include "path-util.h"
22
#include "rm-rf.h"
23
#include "sort-util.h"
24
#include "stat-util.h"
25
#include "string-util.h"
26
#include "strv.h"
27
#include "tmpfile-util.h"
28
#include "user-util.h"
29

30
CustomMount* custom_mount_add(CustomMount **l, size_t *n, CustomMountType t) {
566✔
31
        CustomMount *ret;
566✔
32

33
        assert(l);
566✔
34
        assert(n);
566✔
35
        assert(t >= 0);
566✔
36
        assert(t < _CUSTOM_MOUNT_TYPE_MAX);
566✔
37

38
        if (!GREEDY_REALLOC(*l, *n + 1))
566✔
39
                return NULL;
40

41
        ret = *l + *n;
566✔
42
        (*n)++;
566✔
43

44
        *ret = (CustomMount) {
566✔
45
                .type = t,
46
                .destination_uid = UID_INVALID,
47
        };
48

49
        return ret;
566✔
50
}
51

52
void custom_mount_free_all(CustomMount *l, size_t n) {
1,250✔
53
        FOREACH_ARRAY(m, l, n) {
1,524✔
54
                free(m->source);
274✔
55
                free(m->destination);
274✔
56
                free(m->options);
274✔
57

58
                if (m->work_dir) {
274✔
59
                        (void) rm_rf(m->work_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
5✔
60
                        free(m->work_dir);
5✔
61
                }
62

63
                if (m->rm_rf_tmpdir) {
274✔
64
                        (void) rm_rf(m->rm_rf_tmpdir, REMOVE_ROOT|REMOVE_PHYSICAL);
4✔
65
                        free(m->rm_rf_tmpdir);
4✔
66
                }
67

68
                strv_free(m->lower);
274✔
69
                free(m->type_argument);
274✔
70
        }
71

72
        free(l);
1,250✔
73
}
1,250✔
74

75
static int custom_mount_compare(const CustomMount *a, const CustomMount *b) {
118✔
76
        int r;
118✔
77

78
        r = path_compare(a->destination, b->destination);
118✔
79
        if (r != 0)
118✔
80
                return r;
81

82
        return CMP(a->type, b->type);
×
83
}
84

85
static int source_path_parse(const char *p, char **ret) {
531✔
86
        assert(p);
531✔
87
        assert(ret);
531✔
88

89
        if (isempty(p))
531✔
90
                return -EINVAL;
91

92
        if (*p == '+') {
531✔
93
                if (!path_is_absolute(p + 1))
7✔
94
                        return -EINVAL;
531✔
95

96
                char *s = strdup(p);
7✔
97
                if (!s)
7✔
98
                        return -ENOMEM;
99

100
                *ret = TAKE_PTR(s);
7✔
101
                return 0;
7✔
102
        }
103

104
        return path_make_absolute_cwd(p, ret);
524✔
105
}
106

107
static int source_path_parse_nullable(const char *p, char **ret) {
525✔
108
        assert(p);
525✔
109
        assert(ret);
525✔
110

111
        if (isempty(p)) {
525✔
112
                *ret = NULL;
9✔
113
                return 0;
9✔
114
        }
115

116
        return source_path_parse(p, ret);
516✔
117
}
118

119
static char *resolve_source_path(const char *dest, const char *source) {
421✔
120
        if (!source)
421✔
121
                return NULL;
122

123
        if (source[0] == '+')
421✔
124
                return path_join(dest, source + 1);
8✔
125

126
        return strdup(source);
413✔
127
}
128

129
static int allocate_temporary_source(CustomMount *m) {
10✔
130
        int r;
10✔
131

132
        assert(m);
10✔
133
        assert(!m->source);
10✔
134
        assert(!m->rm_rf_tmpdir);
10✔
135

136
        r = mkdtemp_malloc("/var/tmp/nspawn-temp-XXXXXX", &m->rm_rf_tmpdir);
10✔
137
        if (r < 0)
10✔
138
                return log_error_errno(r, "Failed to acquire temporary directory: %m");
×
139

140
        m->source = path_join(m->rm_rf_tmpdir, "src");
10✔
141
        if (!m->source)
10✔
142
                return log_oom();
×
143

144
        if (mkdir(m->source, 0755) < 0)
10✔
145
                return log_error_errno(errno, "Failed to create %s: %m", m->source);
×
146

147
        return 0;
148
}
149

150
int custom_mount_prepare_all(const char *dest, CustomMount *l, size_t n) {
430✔
151
        int r;
430✔
152

153
        /* Prepare all custom mounts. This will make sure we know all temporary directories. This is called in the
154
         * parent process, so that we know the temporary directories to remove on exit before we fork off the
155
         * children. */
156

157
        assert(l || n == 0);
430✔
158

159
        /* Order the custom mounts, and make sure we have a working directory */
160
        typesafe_qsort(l, n, custom_mount_compare);
430✔
161

162
        FOREACH_ARRAY(m, l, n) {
885✔
163
                /* /proc we mount in the inner child, i.e. when we acquired CLONE_NEWPID. All other mounts we mount
164
                 * already in the outer child, so that the mounts are already established before CLONE_NEWPID and in
165
                 * particular CLONE_NEWUSER. This also means any custom mounts below /proc also need to be mounted in
166
                 * the inner child, not the outer one. Determine this here. */
167
                m->in_userns = path_startswith(m->destination, "/proc");
455✔
168

169
                if (m->type == CUSTOM_MOUNT_BIND) {
455✔
170
                        if (m->source) {
405✔
171
                                char *s;
404✔
172

173
                                s = resolve_source_path(dest, m->source);
404✔
174
                                if (!s)
404✔
175
                                        return log_oom();
×
176

177
                                free_and_replace(m->source, s);
404✔
178
                        } else {
179
                                /* No source specified? In that case, use a throw-away temporary directory in /var/tmp */
180

181
                                r = allocate_temporary_source(m);
1✔
182
                                if (r < 0)
1✔
183
                                        return r;
184
                        }
185
                }
186

187
                if (m->type == CUSTOM_MOUNT_OVERLAY) {
455✔
188
                        STRV_FOREACH(j, m->lower) {
26✔
189
                                char *s;
15✔
190

191
                                s = resolve_source_path(dest, *j);
15✔
192
                                if (!s)
15✔
193
                                        return log_oom();
×
194

195
                                free_and_replace(*j, s);
15✔
196
                        }
197

198
                        if (m->source) {
11✔
199
                                char *s;
2✔
200

201
                                s = resolve_source_path(dest, m->source);
2✔
202
                                if (!s)
2✔
203
                                        return log_oom();
×
204

205
                                free_and_replace(m->source, s);
2✔
206
                        } else {
207
                                r = allocate_temporary_source(m);
9✔
208
                                if (r < 0)
9✔
209
                                        return r;
210
                        }
211

212
                        if (m->work_dir) {
11✔
213
                                char *s;
×
214

215
                                s = resolve_source_path(dest, m->work_dir);
×
216
                                if (!s)
×
217
                                        return log_oom();
×
218

219
                                free_and_replace(m->work_dir, s);
×
220
                        } else {
221
                                r = tempfn_random(m->source, NULL, &m->work_dir);
11✔
222
                                if (r < 0)
11✔
223
                                        return log_error_errno(r, "Failed to acquire working directory: %m");
×
224
                        }
225

226
                        (void) mkdir_label(m->work_dir, 0700);
11✔
227
                }
228
        }
229

230
        return 0;
231
}
232

233
int bind_mount_parse(CustomMount **l, size_t *n, const char *s, bool read_only) {
514✔
234
        _cleanup_free_ char *source = NULL, *destination = NULL, *opts = NULL, *p = NULL;
514✔
235
        CustomMount *m;
514✔
236
        int r;
514✔
237

238
        assert(l);
514✔
239
        assert(n);
514✔
240

241
        r = extract_many_words(&s, ":", EXTRACT_DONT_COALESCE_SEPARATORS, &source, &destination);
514✔
242
        if (r < 0)
514✔
243
                return r;
244
        if (r == 0)
514✔
245
                return -EINVAL;
246
        if (r == 1) {
514✔
247
                destination = strdup(source[0] == '+' ? source+1 : source);
480✔
248
                if (!destination)
480✔
249
                        return -ENOMEM;
250
        }
251
        if (r == 2 && !isempty(s)) {
514✔
252
                opts = strdup(s);
12✔
253
                if (!opts)
12✔
254
                        return -ENOMEM;
255
        }
256

257
        r = source_path_parse_nullable(source, &p);
514✔
258
        if (r < 0)
514✔
259
                return r;
260

261
        if (!path_is_absolute(destination))
1,024✔
262
                return -EINVAL;
263

264
        m = custom_mount_add(l, n, CUSTOM_MOUNT_BIND);
510✔
265
        if (!m)
510✔
266
                return -ENOMEM;
267

268
        m->source = TAKE_PTR(p);
510✔
269
        m->destination = TAKE_PTR(destination);
510✔
270
        m->read_only = read_only;
510✔
271
        m->options = TAKE_PTR(opts);
510✔
272

273
        return 0;
510✔
274
}
275

276
int tmpfs_mount_parse(CustomMount **l, size_t *n, const char *s) {
17✔
277
        _cleanup_free_ char *path = NULL, *opts = NULL;
17✔
278
        const char *p = ASSERT_PTR(s);
17✔
279
        CustomMount *m;
17✔
280
        int r;
17✔
281

282
        assert(l);
17✔
283
        assert(n);
17✔
284

285
        r = extract_first_word(&p, &path, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
17✔
286
        if (r < 0)
17✔
287
                return r;
288
        if (r == 0)
17✔
289
                return -EINVAL;
290

291
        if (isempty(p))
17✔
292
                opts = strdup("mode=0755");
16✔
293
        else
294
                opts = strdup(p);
1✔
295
        if (!opts)
17✔
296
                return -ENOMEM;
297

298
        if (!path_is_absolute(path))
32✔
299
                return -EINVAL;
300

301
        m = custom_mount_add(l, n, CUSTOM_MOUNT_TMPFS);
15✔
302
        if (!m)
15✔
303
                return -ENOMEM;
304

305
        m->destination = TAKE_PTR(path);
15✔
306
        m->options = TAKE_PTR(opts);
15✔
307

308
        return 0;
15✔
309
}
310

311
int overlay_mount_parse(CustomMount **l, size_t *n, const char *s, bool read_only) {
15✔
312
        _cleanup_free_ char *upper = NULL, *destination = NULL;
15✔
313
        _cleanup_strv_free_ char **lower = NULL;
15✔
314
        CustomMount *m;
15✔
315
        int r, k;
15✔
316

317
        k = strv_split_full(&lower, s, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
15✔
318
        if (k < 0)
15✔
319
                return k;
320
        if (k < 2)
15✔
321
                return -EADDRNOTAVAIL;
322
        if (k == 2) {
11✔
323
                _cleanup_free_ char *p = NULL;
×
324

325
                /* If two parameters are specified, the first one is the lower, the second one the upper directory. And
326
                 * we'll also define the destination mount point the same as the upper. */
327

328
                r = source_path_parse(lower[0], &p);
×
329
                if (r < 0)
×
330
                        return r;
331

332
                free_and_replace(lower[0], p);
×
333

334
                r = source_path_parse(lower[1], &p);
×
335
                if (r < 0)
×
336
                        return r;
337

338
                free_and_replace(lower[1], p);
×
339

340
                upper = TAKE_PTR(lower[1]);
×
341

342
                destination = strdup(upper[0] == '+' ? upper+1 : upper); /* take the destination without "+" prefix */
×
343
                if (!destination)
×
344
                        return -ENOMEM;
345
        } else {
346
                _cleanup_free_ char *p = NULL;
11✔
347

348
                /* If more than two parameters are specified, the last one is the destination, the second to last one
349
                 * the "upper", and all before that the "lower" directories. */
350

351
                destination = lower[k - 1];
11✔
352
                upper = TAKE_PTR(lower[k - 2]);
11✔
353

354
                STRV_FOREACH(i, lower) {
26✔
355
                        r = source_path_parse(*i, &p);
15✔
356
                        if (r < 0)
15✔
357
                                return r;
358

359
                        free_and_replace(*i, p);
15✔
360
                }
361

362
                /* If the upper directory is unspecified, then let's create it automatically as a throw-away directory
363
                 * in /var/tmp */
364
                r = source_path_parse_nullable(upper, &p);
11✔
365
                if (r < 0)
11✔
366
                        return r;
367

368
                free_and_replace(upper, p);
11✔
369

370
                if (!path_is_absolute(destination))
11✔
371
                        return -EINVAL;
372
        }
373

374
        m = custom_mount_add(l, n, CUSTOM_MOUNT_OVERLAY);
11✔
375
        if (!m)
11✔
376
                return -ENOMEM;
377

378
        m->destination = TAKE_PTR(destination);
11✔
379
        m->source = TAKE_PTR(upper);
11✔
380
        m->lower = TAKE_PTR(lower);
11✔
381
        m->read_only = read_only;
11✔
382

383
        return 0;
11✔
384
}
385

386
int inaccessible_mount_parse(CustomMount **l, size_t *n, const char *s) {
22✔
387
        _cleanup_free_ char *path = NULL;
22✔
388
        CustomMount *m;
22✔
389

390
        assert(l);
22✔
391
        assert(n);
22✔
392
        assert(s);
22✔
393

394
        if (!path_is_absolute(s))
22✔
395
                return -EINVAL;
396

397
        path = strdup(s);
20✔
398
        if (!path)
20✔
399
                return -ENOMEM;
400

401
        m = custom_mount_add(l, n, CUSTOM_MOUNT_INACCESSIBLE);
20✔
402
        if (!m)
20✔
403
                return -ENOMEM;
404

405
        m->destination = TAKE_PTR(path);
20✔
406
        return 0;
20✔
407
}
408

409
int tmpfs_patch_options(
1,138✔
410
                const char *options,
411
                uid_t uid_shift,
412
                const char *selinux_apifs_context,
413
                char **ret) {
414

415
        _cleanup_free_ char *buf = NULL;
1,138✔
416

417
        assert(ret);
1,138✔
418

419
        if (options) {
1,138✔
420
                buf = strdup(options);
1,138✔
421
                if (!buf)
1,138✔
422
                        return -ENOMEM;
423
        }
424

425
        if (uid_shift != UID_INVALID)
1,138✔
426
                if (strextendf_with_separator(&buf, ",", "uid=" UID_FMT ",gid=" UID_FMT, uid_shift, uid_shift) < 0)
1,124✔
427
                        return -ENOMEM;
428

429
#if HAVE_SELINUX
430
        if (selinux_apifs_context)
431
                if (strextendf_with_separator(&buf, ",", "context=\"%s\"", selinux_apifs_context) < 0)
432
                        return -ENOMEM;
433
#endif
434

435
        *ret = TAKE_PTR(buf);
1,138✔
436
        return !!*ret;
1,138✔
437
}
438

439
int mount_sysfs(const char *dest, MountSettingsMask mount_settings) {
122✔
440
        _cleanup_free_ char *top = NULL, *full = NULL;;
122✔
441
        unsigned long extra_flags = 0;
122✔
442
        int r;
122✔
443

444
        top = path_join(dest, "/sys");
122✔
445
        if (!top)
122✔
446
                return log_oom();
×
447

448
        r = path_is_mount_point(top);
122✔
449
        if (r < 0)
122✔
450
                return log_error_errno(r, "Failed to determine if '%s' is a mountpoint: %m", top);
×
451
        if (r == 0) {
122✔
452
                /* If this is not a mount point yet, then mount a tmpfs there */
453
                r = mount_nofollow_verbose(LOG_ERR, "tmpfs", top, "tmpfs", MS_NOSUID|MS_NOEXEC|MS_NODEV, "mode=0555" TMPFS_LIMITS_SYS);
1✔
454
                if (r < 0)
1✔
455
                        return r;
456
        } else {
457
                r = path_is_fs_type(top, SYSFS_MAGIC);
121✔
458
                if (r < 0)
121✔
459
                        return log_error_errno(r, "Failed to determine filesystem type of %s: %m", top);
×
460

461
                /* /sys/ might already be mounted as sysfs by the outer child in the !netns case. In this case, it's
462
                 * all good. Don't touch it because we don't have the right to do so, see
463
                 * https://github.com/systemd/systemd/issues/1555.
464
                 */
465
                if (r > 0)
121✔
466
                        return 0;
467
        }
468

469
        full = path_join(top, "/full");
51✔
470
        if (!full)
51✔
471
                return log_oom();
×
472

473
        if (mkdir(full, 0755) < 0 && errno != EEXIST)
51✔
474
                return log_error_errno(errno, "Failed to create directory '%s': %m", full);
×
475

476
        if (FLAGS_SET(mount_settings, MOUNT_APPLY_APIVFS_RO))
51✔
477
                extra_flags |= MS_RDONLY;
47✔
478

479
        r = mount_nofollow_verbose(LOG_ERR, "sysfs", full, "sysfs",
51✔
480
                                   MS_NOSUID|MS_NOEXEC|MS_NODEV|extra_flags, NULL);
481
        if (r < 0)
51✔
482
                return r;
483

484
        FOREACH_STRING(x, "block", "bus", "class", "dev", "devices", "kernel") {
357✔
485
                _cleanup_free_ char *from = NULL, *to = NULL;
306✔
486

487
                from = path_join(full, x);
306✔
488
                if (!from)
306✔
489
                        return log_oom();
×
490

491
                to = path_join(top, x);
306✔
492
                if (!to)
306✔
493
                        return log_oom();
×
494

495
                (void) mkdir(to, 0755);
306✔
496

497
                r = mount_nofollow_verbose(LOG_ERR, from, to, NULL, MS_BIND, NULL);
306✔
498
                if (r < 0)
306✔
499
                        return r;
500

501
                r = mount_nofollow_verbose(LOG_ERR, NULL, to, NULL,
306✔
502
                                           MS_BIND|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_REMOUNT|extra_flags, NULL);
503
                if (r < 0)
306✔
504
                        return r;
505
        }
506

507
        r = umount_verbose(LOG_ERR, full, UMOUNT_NOFOLLOW);
51✔
508
        if (r < 0)
51✔
509
                return r;
510

511
        if (rmdir(full) < 0)
51✔
512
                return log_error_errno(errno, "Failed to remove %s: %m", full);
×
513

514
        /* Create mountpoints. Otherwise we are not allowed since we remount /sys/ read-only. */
515
        FOREACH_STRING(p, "/fs/cgroup", "/fs/bpf") {
153✔
516
                _cleanup_free_ char *x = path_join(top, p);
204✔
517
                if (!x)
102✔
518
                        return log_oom();
×
519

520
                (void) mkdir_p(x, 0755);
102✔
521
        }
522

523
        return mount_nofollow_verbose(LOG_ERR, NULL, top, NULL,
122✔
524
                                      MS_BIND|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_REMOUNT|extra_flags, NULL);
525
}
526

527
#define PROC_DEFAULT_MOUNT_FLAGS (MS_NOSUID|MS_NOEXEC|MS_NODEV)
528
#define SYS_DEFAULT_MOUNT_FLAGS  (MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV)
529

530
int mount_all(const char *dest,
376✔
531
              MountSettingsMask mount_settings,
532
              uid_t uid_shift,
533
              const char *selinux_apifs_context) {
534

535
#define PROC_INACCESSIBLE_REG(path)                                     \
536
        { "/run/systemd/inaccessible/reg", (path), NULL, NULL, MS_BIND, \
537
          MOUNT_IN_USERNS|MOUNT_APPLY_APIVFS_RO }, /* Bind mount first ... */ \
538
        { NULL, (path), NULL, NULL, MS_BIND|MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_REMOUNT, \
539
          MOUNT_IN_USERNS|MOUNT_APPLY_APIVFS_RO } /* Then, make it r/o */
540

541
#define PROC_READ_ONLY(path)                                            \
542
        { (path), (path), NULL, NULL, MS_BIND,                          \
543
          MOUNT_IN_USERNS|MOUNT_APPLY_APIVFS_RO }, /* Bind mount first ... */ \
544
        { NULL,   (path), NULL, NULL, MS_BIND|MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_REMOUNT, \
545
          MOUNT_IN_USERNS|MOUNT_APPLY_APIVFS_RO } /* Then, make it r/o */
546

547
        typedef struct MountPoint {
376✔
548
                const char *what;
549
                const char *where;
550
                const char *type;
551
                const char *options;
552
                unsigned long flags;
553
                MountSettingsMask mount_settings;
554
        } MountPoint;
555

556
        static const MountPoint mount_table[] = {
376✔
557
                /* First we list inner child mounts (i.e. mounts applied *after* entering user namespacing when we are privileged) */
558
                { "proc",            "/proc",           "proc",  NULL,        PROC_DEFAULT_MOUNT_FLAGS,
559
                  MOUNT_FATAL|MOUNT_IN_USERNS|MOUNT_MKDIR|MOUNT_FOLLOW_SYMLINKS }, /* we follow symlinks here since not following them requires /proc/ already being mounted, which we don't have here. */
560

561
                { "/proc/sys",       "/proc/sys",       NULL,    NULL,        MS_BIND,
562
                  MOUNT_FATAL|MOUNT_IN_USERNS|MOUNT_APPLY_APIVFS_RO },                          /* Bind mount first ... */
563

564
                { "/proc/sys/net",   "/proc/sys/net",   NULL,    NULL,        MS_BIND,
565
                  MOUNT_FATAL|MOUNT_IN_USERNS|MOUNT_APPLY_APIVFS_RO|MOUNT_APPLY_APIVFS_NETNS }, /* (except for this) */
566

567
                { NULL,              "/proc/sys",       NULL,    NULL,        MS_BIND|MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_REMOUNT,
568
                  MOUNT_FATAL|MOUNT_IN_USERNS|MOUNT_APPLY_APIVFS_RO },                          /* ... then, make it r/o */
569

570
                /* Make these files inaccessible to container payloads: they potentially leak information about kernel
571
                 * internals or the host's execution environment to the container */
572
                PROC_INACCESSIBLE_REG("/proc/kallsyms"),
573
                PROC_INACCESSIBLE_REG("/proc/kcore"),
574
                PROC_INACCESSIBLE_REG("/proc/keys"),
575
                PROC_INACCESSIBLE_REG("/proc/sysrq-trigger"),
576
                PROC_INACCESSIBLE_REG("/proc/timer_list"),
577

578
                /* Make these directories read-only to container payloads: they show hardware information, and in some
579
                 * cases contain tunables the container really shouldn't have access to. */
580
                PROC_READ_ONLY("/proc/acpi"),
581
                PROC_READ_ONLY("/proc/apm"),
582
                PROC_READ_ONLY("/proc/asound"),
583
                PROC_READ_ONLY("/proc/bus"),
584
                PROC_READ_ONLY("/proc/fs"),
585
                PROC_READ_ONLY("/proc/irq"),
586
                PROC_READ_ONLY("/proc/scsi"),
587

588
                { "mqueue",                 "/dev/mqueue",                  "mqueue", NULL,                            MS_NOSUID|MS_NOEXEC|MS_NODEV,
589
                  MOUNT_IN_USERNS|MOUNT_MKDIR },
590

591
                /* Then we list outer child mounts (i.e. mounts applied *before* entering user namespacing when we are privileged) */
592
                { "tmpfs",                  "/tmp",                         "tmpfs", "mode=01777" NESTED_TMPFS_LIMITS, MS_NOSUID|MS_NODEV|MS_STRICTATIME,
593
                  MOUNT_FATAL|MOUNT_APPLY_TMPFS_TMP|MOUNT_MKDIR|MOUNT_USRQUOTA_GRACEFUL },
594
                { "tmpfs",                  "/sys",                         "tmpfs", "mode=0555" TMPFS_LIMITS_SYS,     MS_NOSUID|MS_NOEXEC|MS_NODEV,
595
                  MOUNT_FATAL|MOUNT_APPLY_APIVFS_NETNS|MOUNT_MKDIR|MOUNT_UNMANAGED },
596
                { "sysfs",                  "/sys",                         "sysfs", NULL,                             SYS_DEFAULT_MOUNT_FLAGS,
597
                  MOUNT_FATAL|MOUNT_APPLY_APIVFS_RO|MOUNT_MKDIR|MOUNT_UNMANAGED },    /* skipped if above was mounted */
598
                { "sysfs",                  "/sys",                         "sysfs", NULL,                             MS_NOSUID|MS_NOEXEC|MS_NODEV,
599
                  MOUNT_FATAL|MOUNT_MKDIR|MOUNT_UNMANAGED },                          /* skipped if above was mounted */
600
                { "tmpfs",                  "/dev",                         "tmpfs", "mode=0755" TMPFS_LIMITS_PRIVATE_DEV, MS_NOSUID|MS_STRICTATIME,
601
                  MOUNT_FATAL|MOUNT_MKDIR },
602
                { "tmpfs",                  "/dev/shm",                     "tmpfs", "mode=01777" NESTED_TMPFS_LIMITS, MS_NOSUID|MS_NODEV|MS_STRICTATIME,
603
                  MOUNT_FATAL|MOUNT_MKDIR|MOUNT_USRQUOTA_GRACEFUL },
604
                { "tmpfs",                  "/run",                         "tmpfs", "mode=0755" TMPFS_LIMITS_RUN,     MS_NOSUID|MS_NODEV|MS_STRICTATIME,
605
                  MOUNT_FATAL|MOUNT_MKDIR },
606
                { "/run/host",              "/run/host",                    NULL,    NULL,                             MS_BIND,
607
                  MOUNT_FATAL|MOUNT_MKDIR|MOUNT_PREFIX_ROOT }, /* Prepare this so that we can make it read-only when we are done */
608
                { "/etc/os-release",        "/run/host/os-release",         NULL,    NULL,                             MS_BIND,
609
                  MOUNT_TOUCH }, /* As per kernel interface requirements, bind mount first (creating mount points) and make read-only later */
610
                { "/usr/lib/os-release",    "/run/host/os-release",         NULL,    NULL,                             MS_BIND,
611
                  MOUNT_FATAL }, /* If /etc/os-release doesn't exist use the version in /usr/lib as fallback */
612
                { NULL,                     "/run/host/os-release",         NULL,    NULL,                             MS_BIND|MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_REMOUNT,
613
                  MOUNT_FATAL },
614
                { NULL,                     "/run/host/os-release",         NULL,    NULL,                             MS_PRIVATE,
615
                  MOUNT_FATAL },  /* Turn off propagation (we only want that for the mount propagation tunnel dir) */
616
                { NULL,                     "/run/host",                    NULL,    NULL,                             MS_BIND|MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_REMOUNT,
617
                  MOUNT_FATAL|MOUNT_IN_USERNS },
618
#if HAVE_SELINUX
619
                { "/sys/fs/selinux",        "/sys/fs/selinux",              NULL,    NULL,                             MS_BIND,
620
                  MOUNT_MKDIR|MOUNT_PRIVILEGED },  /* Bind mount first (mkdir/chown the mount point in case /sys/ is mounted as minimal skeleton tmpfs) */
621
                { NULL,                     "/sys/fs/selinux",              NULL,    NULL,                             MS_BIND|MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_REMOUNT,
622
                  MOUNT_UNMANAGED|MOUNT_PRIVILEGED },  /* Then, make it r/o (don't mkdir/chown the mount point here, the previous entry already did that) */
623
                { NULL,                     "/sys/fs/selinux",              NULL,    NULL,                             MS_PRIVATE,
624
                  MOUNT_UNMANAGED|MOUNT_PRIVILEGED },  /* Turn off propagation (we only want that for the mount propagation tunnel dir) */
625
#endif
626
        };
627

628
        bool use_userns = FLAGS_SET(mount_settings, MOUNT_USE_USERNS);
376✔
629
        bool netns = FLAGS_SET(mount_settings, MOUNT_APPLY_APIVFS_NETNS);
376✔
630
        bool ro = FLAGS_SET(mount_settings, MOUNT_APPLY_APIVFS_RO);
376✔
631
        bool in_userns = FLAGS_SET(mount_settings, MOUNT_IN_USERNS);
376✔
632
        bool tmpfs_tmp = FLAGS_SET(mount_settings, MOUNT_APPLY_TMPFS_TMP);
376✔
633
        bool unmanaged = FLAGS_SET(mount_settings, MOUNT_UNMANAGED);
376✔
634
        bool privileged = FLAGS_SET(mount_settings, MOUNT_PRIVILEGED);
376✔
635
        int r;
376✔
636

637
        FOREACH_ELEMENT(m, mount_table) {
16,168✔
638
                _cleanup_free_ char *where = NULL, *options = NULL, *prefixed = NULL;
15,792✔
639
                bool fatal = FLAGS_SET(m->mount_settings, MOUNT_FATAL);
15,792✔
640
                const char *o;
15,792✔
641

642
                /* If we are in managed user namespace mode but the entry is marked for mount outside of
643
                 * managed user namespace mode, and to be mounted outside the user namespace, then skip it */
644
                if (!unmanaged && FLAGS_SET(m->mount_settings, MOUNT_UNMANAGED) && !FLAGS_SET(m->mount_settings, MOUNT_IN_USERNS))
15,792✔
645
                        continue;
39✔
646

647
                if (in_userns != FLAGS_SET(m->mount_settings, MOUNT_IN_USERNS))
15,753✔
648
                        continue;
9,081✔
649

650
                if (!netns && FLAGS_SET(m->mount_settings, MOUNT_APPLY_APIVFS_NETNS))
6,672✔
651
                        continue;
213✔
652

653
                if (!ro && FLAGS_SET(m->mount_settings, MOUNT_APPLY_APIVFS_RO))
6,459✔
654
                        continue;
228✔
655

656
                if (!tmpfs_tmp && FLAGS_SET(m->mount_settings, MOUNT_APPLY_TMPFS_TMP))
6,231✔
657
                        continue;
×
658

659
                if (!privileged && FLAGS_SET(m->mount_settings, MOUNT_PRIVILEGED))
6,231✔
660
                        continue;
×
661

662
                r = chase(m->where, dest, CHASE_NONEXISTENT|CHASE_PREFIX_ROOT, &where, NULL);
6,231✔
663
                if (r < 0)
6,231✔
664
                        return log_error_errno(r, "Failed to resolve %s%s: %m", strempty(dest), m->where);
×
665

666
                /* Skip this entry if it is not a remount. */
667
                if (m->what) {
6,231✔
668
                        r = path_is_mount_point(where);
4,119✔
669
                        if (r < 0 && r != -ENOENT)
4,119✔
670
                                return log_error_errno(r, "Failed to detect whether %s is a mount point: %m", where);
×
671
                        if (r > 0)
4,119✔
672
                                continue;
581✔
673
                }
674

675
                if ((m->mount_settings & (MOUNT_MKDIR|MOUNT_TOUCH)) != 0) {
5,650✔
676
                        uid_t u = (use_userns && !in_userns) ? uid_shift : UID_INVALID;
2,009✔
677

678
                        if (FLAGS_SET(m->mount_settings, MOUNT_TOUCH))
2,009✔
679
                                r = mkdir_parents_safe(dest, where, 0755, u, u, 0);
254✔
680
                        else
681
                                r = mkdir_p_safe(dest, where, 0755, u, u, 0);
1,755✔
682
                        if (r < 0 && r != -EEXIST) {
2,009✔
683
                                if (fatal && r != -EROFS)
×
684
                                        return log_error_errno(r, "Failed to create directory %s: %m", where);
×
685

686
                                log_debug_errno(r, "Failed to create directory %s: %m", where);
×
687

688
                                /* If mkdir() or chown() failed due to the root directory being read only,
689
                                 * attempt to mount this fs anyway and let mount_verbose log any errors */
690
                                if (r != -EROFS)
×
691
                                        continue;
×
692
                        }
693
                }
694

695
                if (FLAGS_SET(m->mount_settings, MOUNT_TOUCH)) {
5,650✔
696
                        r = touch(where);
254✔
697
                        if (r < 0 && r != -EEXIST) {
254✔
698
                                if (fatal && r != -EROFS)
×
699
                                        return log_error_errno(r, "Failed to create file %s: %m", where);
×
700

701
                                log_debug_errno(r, "Failed to create file %s: %m", where);
×
702
                                if (r != -EROFS)
×
703
                                        continue;
×
704
                        }
705
                }
706

707
                o = m->options;
5,650✔
708
                if (streq_ptr(m->type, "tmpfs")) {
5,650✔
709
                        r = tmpfs_patch_options(o, in_userns ? 0 : uid_shift, selinux_apifs_context, &options);
2,232✔
710
                        if (r < 0)
1,116✔
711
                                return log_oom();
×
712
                        if (r > 0)
1,116✔
713
                                o = options;
1,116✔
714
                }
715

716
                if (FLAGS_SET(m->mount_settings, MOUNT_USRQUOTA_GRACEFUL)) {
5,650✔
717
                        r = mount_option_supported(m->type, /* key= */ "usrquota", /* value= */ NULL);
508✔
718
                        if (r < 0)
508✔
719
                                log_warning_errno(r, "Failed to determine if '%s' supports 'usrquota', assuming it doesn't: %m", m->type);
×
720
                        else if (r == 0)
508✔
721
                                log_debug("Kernel doesn't support 'usrquota' on '%s', not including in mount options for '%s'.", m->type, m->where);
24✔
722
                        else {
723
                                _cleanup_free_ char *joined = NULL;
×
724

725
                                if (!strextend_with_separator(&joined, ",", o ?: POINTER_MAX, "usrquota"))
484✔
726
                                        return log_oom();
×
727

728
                                free_and_replace(options, joined);
484✔
729
                                o = options;
484✔
730
                        }
731
                }
732

733
                if (FLAGS_SET(m->mount_settings, MOUNT_PREFIX_ROOT)) {
5,650✔
734
                        /* Optionally prefix the mount source with the root dir. This is useful in bind
735
                         * mounts to be created within the container image before we transition into it. Note
736
                         * that MOUNT_IN_USERNS is run after we transitioned hence prefixing is not necessary
737
                         * for those. */
738
                        r = chase(m->what, dest, CHASE_PREFIX_ROOT, &prefixed, NULL);
254✔
739
                        if (r < 0)
254✔
740
                                return log_error_errno(r, "Failed to resolve %s%s: %m", strempty(dest), m->what);
×
741
                }
742

743
                r = mount_verbose_full(
8,762✔
744
                                fatal ? LOG_ERR : LOG_DEBUG,
745
                                prefixed ?: m->what,
5,650✔
746
                                where,
747
                                m->type,
5,650✔
748
                                m->flags,
5,650✔
749
                                o,
750
                                FLAGS_SET(m->mount_settings, MOUNT_FOLLOW_SYMLINKS));
5,650✔
751
                if (r < 0 && fatal)
5,650✔
752
                        return r;
753
        }
754

755
        return 0;
756
}
757

758
static int parse_mount_bind_options(const char *options, unsigned long *open_tree_flags, char **mount_opts, RemountIdmapping *idmapping) {
44✔
759
        unsigned long flags = *open_tree_flags;
44✔
760
        char *opts = NULL;
44✔
761
        RemountIdmapping new_idmapping = *idmapping;
44✔
762
        int r;
44✔
763

764
        assert(options);
44✔
765

766
        for (;;) {
140✔
767
                _cleanup_free_ char *word = NULL;
48✔
768

769
                r = extract_first_word(&options, &word, ",", 0);
92✔
770
                if (r < 0)
92✔
771
                        return log_error_errno(r, "Failed to extract mount option: %m");
×
772
                if (r == 0)
92✔
773
                        break;
774

775
                if (streq(word, "rbind"))
48✔
776
                        flags |= AT_RECURSIVE;
×
777
                else if (streq(word, "norbind"))
48✔
778
                        flags &= ~AT_RECURSIVE;
4✔
779
                else if (streq(word, "idmap"))
44✔
780
                        new_idmapping = REMOUNT_IDMAPPING_HOST_ROOT;
781
                else if (streq(word, "noidmap"))
44✔
782
                        new_idmapping = REMOUNT_IDMAPPING_NONE;
783
                else if (streq(word, "rootidmap"))
40✔
784
                        new_idmapping = REMOUNT_IDMAPPING_HOST_OWNER;
785
                else if (streq(word, "owneridmap"))
32✔
786
                        new_idmapping = REMOUNT_IDMAPPING_HOST_OWNER_TO_TARGET_OWNER;
787
                else
788
                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
789
                                               "Invalid bind mount option: %s", word);
790
        }
791

792
        *open_tree_flags = flags;
44✔
793
        *idmapping = new_idmapping;
44✔
794
        /* in the future mount_opts will hold string options for mount(2) */
795
        *mount_opts = opts;
44✔
796

797
        return 0;
44✔
798
}
799

800
static int mount_bind(const char *dest, CustomMount *m, uid_t uid_shift, uid_t uid_range) {
294✔
801
        _cleanup_free_ char *mount_opts = NULL, *where = NULL;
294✔
802
        unsigned long open_tree_flags = OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC | AT_RECURSIVE;
294✔
803
        struct stat source_st, dest_st;
294✔
804
        uid_t dest_uid = UID_INVALID;
294✔
805
        int r;
294✔
806
        RemountIdmapping idmapping = REMOUNT_IDMAPPING_NONE;
294✔
807

808
        assert(dest);
294✔
809
        assert(m);
294✔
810

811
        if (m->options) {
294✔
812
                r = parse_mount_bind_options(m->options, &open_tree_flags, &mount_opts, &idmapping);
44✔
813
                if (r < 0)
44✔
814
                        return r;
815
        }
816

817
        /* ID remapping cannot be done if user namespaces are not in use (uid_shift is UID_INVALID).
818
         * Fail if idmapping was explicitly requested in this state. Otherwise, treat UID_INVALID
819
         * as 0 for ownership operations. */
820
        if (idmapping != REMOUNT_IDMAPPING_NONE && !uid_is_valid(uid_shift))
294✔
UNCOV
821
                return log_error_errno(
×
822
                                SYNTHETIC_ERRNO(EINVAL),
823
                                "ID remapping requested for %s, but user namespacing is not enabled.",
824
                                m->source);
825

826
        uid_t chown_uid = uid_is_valid(uid_shift) ? uid_shift : 0;
294✔
827

828
        /* If this is a bind mount from a temporary sources change ownership of the source to the container's
829
         * root UID. Otherwise it would always show up as "nobody" if user namespacing is used. */
830
        if (m->rm_rf_tmpdir && chown(m->source, chown_uid, chown_uid) < 0)
294✔
UNCOV
831
                return log_error_errno(errno, "Failed to chown %s: %m", m->source);
×
832

833
        /* UID/GIDs of idmapped mounts are always resolved in the caller's user namespace. In other
834
         * words, they're not nested. If we're doing an idmapped mount from a bind mount that's
835
         * already idmapped itself, the old idmap is replaced with the new one. This means that the
836
         * source uid which we put in the idmap userns has to be the uid of mount source in the
837
         * caller's userns *without* any mount idmapping in place. To get that uid, we clone the
838
         * mount source tree and clear any existing idmapping and temporarily mount that tree over
839
         * the mount source before we stat the mount source to figure out the source uid. */
840
        _cleanup_close_ int fd_clone =
294✔
841
                idmapping == REMOUNT_IDMAPPING_NONE ?
294✔
842
                RET_NERRNO(open_tree(
254✔
843
                        AT_FDCWD,
844
                        m->source,
254✔
845
                        open_tree_flags)) :
294✔
846
                open_tree_try_drop_idmap(
40✔
847
                        AT_FDCWD,
848
                        m->source,
40✔
849
                        open_tree_flags);
850
        if (fd_clone < 0)
40✔
851
                return log_error_errno(errno, "Failed to clone %s: %m", m->source);
×
852

853
        if (fstat(fd_clone, &source_st) < 0)
294✔
UNCOV
854
                return log_error_errno(errno, "Failed to stat %s: %m", m->source);
×
855

856
        r = chase(m->destination, dest, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &where, NULL);
294✔
857
        if (r < 0)
294✔
UNCOV
858
                return log_error_errno(r, "Failed to resolve %s/%s: %m", dest, m->destination);
×
859
        if (r > 0) { /* Path exists already? */
294✔
860

861
                if (stat(where, &dest_st) < 0)
172✔
UNCOV
862
                        return log_error_errno(errno, "Failed to stat %s: %m", where);
×
863

864
                dest_uid = uid_is_valid(m->destination_uid) ? chown_uid + m->destination_uid : dest_st.st_uid;
172✔
865

866
                if (S_ISDIR(source_st.st_mode) && !S_ISDIR(dest_st.st_mode))
172✔
UNCOV
867
                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
868
                                               "Cannot bind mount directory %s on file %s.",
869
                                               m->source, where);
870

871
                if (!S_ISDIR(source_st.st_mode) && S_ISDIR(dest_st.st_mode))
172✔
UNCOV
872
                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
873
                                               "Cannot bind mount file %s on directory %s.",
874
                                               m->source, where);
875

876
        } else { /* Path doesn't exist yet? */
877
                r = mkdir_parents_safe_label(dest, where, 0755, chown_uid, chown_uid, MKDIR_IGNORE_EXISTING);
122✔
878
                if (r < 0)
122✔
879
                        return log_error_errno(r, "Failed to make parents of %s: %m", where);
×
880

881
                /* Create the mount point. Any non-directory file can be
882
                * mounted on any non-directory file (regular, fifo, socket,
883
                * char, block).
884
                */
885
                if (S_ISDIR(source_st.st_mode))
122✔
886
                        r = mkdir_label(where, 0755);
120✔
887
                else
888
                        r = touch(where);
2✔
889
                if (r < 0)
122✔
UNCOV
890
                        return log_error_errno(r, "Failed to create mount point %s: %m", where);
×
891

892
                if (chown(where, chown_uid, chown_uid) < 0)
122✔
UNCOV
893
                        return log_error_errno(errno, "Failed to chown %s: %m", where);
×
894

895
                dest_uid = chown_uid + (uid_is_valid(m->destination_uid) ? m->destination_uid : 0);
152✔
896
        }
897

898
        if (move_mount(fd_clone, "", AT_FDCWD, where, MOVE_MOUNT_F_EMPTY_PATH) < 0)
294✔
UNCOV
899
                return log_error_errno(errno, "Failed to mount %s to %s: %m", m->source, where);
×
900

901
        fd_clone = safe_close(fd_clone);
294✔
902

903
        if (m->read_only) {
294✔
904
                r = bind_remount_recursive(where, MS_RDONLY, MS_RDONLY, NULL);
2✔
905
                if (r < 0)
2✔
UNCOV
906
                        return log_error_errno(r, "Read-only bind mount failed: %m");
×
907
        }
908

909
        if (idmapping != REMOUNT_IDMAPPING_NONE) {
294✔
910
                r = remount_idmap(STRV_MAKE(where), uid_shift, uid_range, source_st.st_uid, dest_uid, idmapping);
40✔
911
                if (r < 0)
40✔
UNCOV
912
                        return log_error_errno(r, "Failed to map ids for bind mount %s: %m", where);
×
913
        }
914

915
        return 0;
916
}
917

918
static int mount_tmpfs(const char *dest, CustomMount *m, uid_t uid_shift, const char *selinux_apifs_context) {
4✔
919
        const char *options;
4✔
920
        _cleanup_free_ char *buf = NULL, *where = NULL;
4✔
921
        int r;
4✔
922

923
        assert(dest);
4✔
924
        assert(m);
4✔
925

926
        r = chase(m->destination, dest, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &where, NULL);
4✔
927
        if (r < 0)
4✔
UNCOV
928
                return log_error_errno(r, "Failed to resolve %s/%s: %m", dest, m->destination);
×
929
        if (r == 0) { /* Doesn't exist yet? */
4✔
UNCOV
930
                r = mkdir_p_label(where, 0755);
×
UNCOV
931
                if (r < 0)
×
UNCOV
932
                        return log_error_errno(r, "Creating mount point for tmpfs %s failed: %m", where);
×
933
        }
934

935
        r = tmpfs_patch_options(m->options, uid_shift == 0 ? UID_INVALID : uid_shift, selinux_apifs_context, &buf);
8✔
936
        if (r < 0)
4✔
UNCOV
937
                return log_oom();
×
938
        options = r > 0 ? buf : m->options;
4✔
939

940
        return mount_nofollow_verbose(LOG_ERR, "tmpfs", where, "tmpfs", MS_NODEV|MS_STRICTATIME, options);
4✔
941
}
942

943
static char *joined_and_escaped_lower_dirs(char **lower) {
2✔
UNCOV
944
        _cleanup_strv_free_ char **sv = NULL;
×
945

946
        sv = strv_copy(lower);
2✔
947
        if (!sv)
2✔
948
                return NULL;
949

950
        strv_reverse(sv);
2✔
951

952
        if (!strv_shell_escape(sv, ",:"))
2✔
953
                return NULL;
954

955
        return strv_join(sv, ":");
2✔
956
}
957

958
static int mount_overlay(const char *dest, CustomMount *m) {
2✔
959
        _cleanup_free_ char *lower = NULL, *where = NULL, *escaped_source = NULL;
2✔
960
        const char *options;
2✔
961
        int r;
2✔
962

963
        assert(dest);
2✔
964
        assert(m);
2✔
965

966
        r = chase(m->destination, dest, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &where, NULL);
2✔
967
        if (r < 0)
2✔
968
                return log_error_errno(r, "Failed to resolve %s/%s: %m", dest, m->destination);
×
969
        if (r == 0) { /* Doesn't exist yet? */
2✔
UNCOV
970
                r = mkdir_label(where, 0755);
×
UNCOV
971
                if (r < 0)
×
972
                        return log_error_errno(r, "Creating mount point for overlay %s failed: %m", where);
×
973
        }
974

975
        (void) mkdir_p_label(m->source, 0755);
2✔
976

977
        lower = joined_and_escaped_lower_dirs(m->lower);
2✔
978
        if (!lower)
2✔
UNCOV
979
                return log_oom();
×
980

981
        escaped_source = shell_escape(m->source, ",:");
2✔
982
        if (!escaped_source)
2✔
UNCOV
983
                return log_oom();
×
984

985
        if (m->read_only)
2✔
UNCOV
986
                options = strjoina("lowerdir=", escaped_source, ":", lower);
×
987
        else {
988
                _cleanup_free_ char *escaped_work_dir = NULL;
2✔
989

990
                escaped_work_dir = shell_escape(m->work_dir, ",:");
2✔
991
                if (!escaped_work_dir)
2✔
UNCOV
992
                        return log_oom();
×
993

994
                options = strjoina("lowerdir=", lower, ",upperdir=", escaped_source, ",workdir=", escaped_work_dir);
26✔
995
        }
996

997
        return mount_nofollow_verbose(LOG_ERR, "overlay", where, "overlay", m->read_only ? MS_RDONLY : 0, options);
2✔
998
}
999

1000
static int mount_inaccessible(const char *dest, CustomMount *m) {
4✔
1001
        _cleanup_free_ char *where = NULL, *source = NULL;
4✔
1002
        struct stat st;
4✔
1003
        int r;
4✔
1004

1005
        assert(dest);
4✔
1006
        assert(m);
4✔
1007

1008
        r = chase_and_stat(m->destination, dest, CHASE_PREFIX_ROOT, &where, &st);
4✔
1009
        if (r < 0) {
4✔
UNCOV
1010
                log_full_errno(m->graceful ? LOG_DEBUG : LOG_ERR, r, "Failed to resolve %s/%s: %m", dest, m->destination);
×
UNCOV
1011
                return m->graceful ? 0 : r;
×
1012
        }
1013

1014
        r = mode_to_inaccessible_node(NULL, st.st_mode, &source);
4✔
1015
        if (r < 0)
4✔
UNCOV
1016
                return m->graceful ? 0 : r;
×
1017

1018
        r = mount_nofollow_verbose(m->graceful ? LOG_DEBUG : LOG_ERR, source, where, NULL, MS_BIND, NULL);
4✔
1019
        if (r < 0)
4✔
1020
                return m->graceful ? 0 : r;
×
1021

1022
        r = mount_nofollow_verbose(m->graceful ? LOG_DEBUG : LOG_ERR, NULL, where, NULL, MS_BIND|MS_RDONLY|MS_REMOUNT, NULL);
4✔
1023
        if (r < 0) {
4✔
1024
                (void) umount_verbose(m->graceful ? LOG_DEBUG : LOG_ERR, where, UMOUNT_NOFOLLOW);
×
1025
                return m->graceful ? 0 : r;
×
1026
        }
1027

1028
        return 0;
1029
}
1030

1031
static int mount_arbitrary(const char *dest, CustomMount *m) {
×
1032
        _cleanup_free_ char *where = NULL;
×
1033
        int r;
×
1034

UNCOV
1035
        assert(dest);
×
1036
        assert(m);
×
1037

UNCOV
1038
        r = chase(m->destination, dest, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &where, NULL);
×
UNCOV
1039
        if (r < 0)
×
UNCOV
1040
                return log_error_errno(r, "Failed to resolve %s/%s: %m", dest, m->destination);
×
UNCOV
1041
        if (r == 0) { /* Doesn't exist yet? */
×
UNCOV
1042
                r = mkdir_p_label(where, 0755);
×
UNCOV
1043
                if (r < 0)
×
UNCOV
1044
                        return log_error_errno(r, "Creating mount point for mount %s failed: %m", where);
×
1045
        }
1046

UNCOV
1047
        return mount_nofollow_verbose(LOG_ERR, m->source, where, m->type_argument, 0, m->options);
×
1048
}
1049

1050
int mount_custom(
638✔
1051
                const char *dest,
1052
                CustomMount *mounts, size_t n,
1053
                uid_t uid_shift,
1054
                uid_t uid_range,
1055
                const char *selinux_apifs_context,
1056
                MountSettingsMask mount_settings) {
1057
        int r;
638✔
1058

1059
        assert(dest);
638✔
1060

1061
        FOREACH_ARRAY(m, mounts, n) {
1,386✔
1062
                if (FLAGS_SET(mount_settings, MOUNT_IN_USERNS) != m->in_userns)
748✔
1063
                        continue;
148✔
1064

1065
                if (FLAGS_SET(mount_settings, MOUNT_ROOT_ONLY) && !path_equal(m->destination, "/"))
600✔
1066
                        continue;
296✔
1067

1068
                if (FLAGS_SET(mount_settings, MOUNT_NON_ROOT_ONLY) && path_equal(m->destination, "/"))
304✔
UNCOV
1069
                        continue;
×
1070

1071
                switch (m->type) {
304✔
1072

1073
                case CUSTOM_MOUNT_BIND:
294✔
1074
                        r = mount_bind(dest, m, uid_shift, uid_range);
294✔
1075
                        break;
294✔
1076

1077
                case CUSTOM_MOUNT_TMPFS:
4✔
1078
                        r = mount_tmpfs(dest, m, uid_shift, selinux_apifs_context);
4✔
1079
                        break;
4✔
1080

1081
                case CUSTOM_MOUNT_OVERLAY:
2✔
1082
                        r = mount_overlay(dest, m);
2✔
1083
                        break;
2✔
1084

1085
                case CUSTOM_MOUNT_INACCESSIBLE:
4✔
1086
                        r = mount_inaccessible(dest, m);
4✔
1087
                        break;
4✔
1088

UNCOV
1089
                case CUSTOM_MOUNT_ARBITRARY:
×
UNCOV
1090
                        r = mount_arbitrary(dest, m);
×
UNCOV
1091
                        break;
×
1092

UNCOV
1093
                default:
×
UNCOV
1094
                        assert_not_reached();
×
1095
                }
1096

1097
                if (r < 0)
304✔
1098
                        return r;
1099
        }
1100

1101
        return 0;
1102
}
1103

1104
bool has_custom_root_mount(const CustomMount *mounts, size_t n) {
493✔
1105
        FOREACH_ARRAY(m, mounts, n)
1,009✔
1106
                if (path_equal(m->destination, "/"))
516✔
1107
                        return true;
1108

1109
        return false;
1110
}
1111

1112
static int setup_volatile_state(const char *directory) {
4✔
1113
        int r;
4✔
1114

1115
        assert(directory);
4✔
1116

1117
        /* --volatile=state means we simply overmount /var with a tmpfs, and the rest read-only. */
1118

1119
        /* First, remount the root directory. */
1120
        r = bind_remount_recursive(directory, MS_RDONLY, MS_RDONLY, NULL);
4✔
1121
        if (r < 0)
4✔
UNCOV
1122
                return log_error_errno(r, "Failed to remount %s read-only: %m", directory);
×
1123

1124
        return 0;
1125
}
1126

1127
static int setup_volatile_state_after_remount_idmap(const char *directory, uid_t uid_shift, const char *selinux_apifs_context) {
4✔
1128
        _cleanup_free_ char *buf = NULL;
8✔
1129
        int r;
4✔
1130

1131
        assert(directory);
4✔
1132

1133
        /* Then, after remount_idmap(), overmount /var/ with a tmpfs. */
1134

1135
        _cleanup_free_ char *p = path_join(directory, "/var");
8✔
1136
        if (!p)
4✔
UNCOV
1137
                return log_oom();
×
1138

1139
        r = mkdir(p, 0755);
4✔
1140
        if (r < 0 && errno != EEXIST)
4✔
UNCOV
1141
                return log_error_errno(errno, "Failed to create %s: %m", directory);
×
1142

1143
        const char *options = "mode=0755" TMPFS_LIMITS_VOLATILE_STATE;
4✔
1144
        r = tmpfs_patch_options(options, uid_shift == 0 ? UID_INVALID : uid_shift, selinux_apifs_context, &buf);
6✔
1145
        if (r < 0)
4✔
UNCOV
1146
                return log_oom();
×
1147
        if (r > 0)
4✔
1148
                options = buf;
4✔
1149

1150
        return mount_nofollow_verbose(LOG_ERR, "tmpfs", p, "tmpfs", MS_STRICTATIME, options);
4✔
1151
}
1152

1153
static int setup_volatile_yes(const char *directory, uid_t uid_shift, const char *selinux_apifs_context) {
10✔
1154
        bool tmpfs_mounted = false, bind_mounted = false;
10✔
UNCOV
1155
        _cleanup_(rmdir_and_freep) char *template = NULL;
×
1156
        _cleanup_free_ char *buf = NULL, *bindir = NULL, *f = NULL, *t = NULL;
10✔
1157
        struct stat st;
10✔
1158
        int r;
10✔
1159

1160
        assert(directory);
10✔
1161

1162
        /* --volatile=yes means we mount a tmpfs to the root dir, and the original /usr to use inside it, and
1163
         * that read-only. Before we start setting this up let's validate if the image has the /usr merge
1164
         * implemented, and let's output a friendly log message if it hasn't. */
1165

1166
        bindir = path_join(directory, "/bin");
10✔
1167
        if (!bindir)
10✔
UNCOV
1168
                return log_oom();
×
1169
        if (lstat(bindir, &st) < 0) {
10✔
UNCOV
1170
                if (errno != ENOENT)
×
UNCOV
1171
                        return log_error_errno(errno, "Failed to stat /bin directory below image: %m");
×
1172

1173
                /* ENOENT is fine, just means the image is probably just a naked /usr and we can create the
1174
                 * rest. */
1175
        } else if (S_ISDIR(st.st_mode))
10✔
UNCOV
1176
                return log_error_errno(SYNTHETIC_ERRNO(EISDIR),
×
1177
                                       "Sorry, --volatile=yes mode is not supported with OS images that have not merged /bin/, /sbin/, /lib/, /lib64/ into /usr/. "
1178
                                       "Please work with your distribution and help them adopt the merged /usr scheme.");
1179
        else if (!S_ISLNK(st.st_mode))
10✔
UNCOV
1180
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
1181
                                       "Error starting image: if --volatile=yes is used /bin must be a symlink (for merged /usr support) or non-existent (in which case a symlink is created automatically).");
1182

1183
        r = mkdtemp_malloc("/tmp/nspawn-volatile-XXXXXX", &template);
10✔
1184
        if (r < 0)
10✔
1185
                return log_error_errno(r, "Failed to create temporary directory: %m");
×
1186

1187
        const char *options = "mode=0755" TMPFS_LIMITS_ROOTFS;
10✔
1188
        r = tmpfs_patch_options(options, uid_shift == 0 ? UID_INVALID : uid_shift, selinux_apifs_context, &buf);
16✔
1189
        if (r < 0)
10✔
UNCOV
1190
                goto fail;
×
1191
        if (r > 0)
10✔
1192
                options = buf;
10✔
1193

1194
        r = mount_nofollow_verbose(LOG_ERR, "tmpfs", template, "tmpfs", MS_STRICTATIME, options);
10✔
1195
        if (r < 0)
10✔
UNCOV
1196
                goto fail;
×
1197

1198
        tmpfs_mounted = true;
10✔
1199

1200
        f = path_join(directory, "/usr");
10✔
1201
        if (!f) {
10✔
UNCOV
1202
                r = log_oom();
×
1203
                goto fail;
×
1204
        }
1205

1206
        t = path_join(template, "/usr");
10✔
1207
        if (!t) {
10✔
UNCOV
1208
                r = log_oom();
×
1209
                goto fail;
×
1210
        }
1211

1212
        r = mkdir(t, 0755);
10✔
1213
        if (r < 0 && errno != EEXIST) {
10✔
UNCOV
1214
                r = log_error_errno(errno, "Failed to create %s: %m", t);
×
1215
                goto fail;
×
1216
        }
1217

1218
        r = mount_nofollow_verbose(LOG_ERR, f, t, NULL, MS_BIND|MS_REC, NULL);
10✔
1219
        if (r < 0)
10✔
UNCOV
1220
                goto fail;
×
1221

1222
        bind_mounted = true;
10✔
1223

1224
        r = bind_remount_recursive(t, MS_RDONLY, MS_RDONLY, NULL);
10✔
1225
        if (r < 0) {
10✔
UNCOV
1226
                log_error_errno(r, "Failed to remount %s read-only: %m", t);
×
UNCOV
1227
                goto fail;
×
1228
        }
1229

1230
        r = mount_nofollow_verbose(LOG_ERR, template, directory, NULL, MS_MOVE, NULL);
10✔
1231
        if (r < 0)
10✔
1232
                goto fail;
×
1233

1234
        (void) rmdir(template);
10✔
1235

1236
        return 0;
10✔
1237

1238
fail:
UNCOV
1239
        if (bind_mounted)
×
UNCOV
1240
                (void) umount_verbose(LOG_ERR, t, UMOUNT_NOFOLLOW);
×
1241

UNCOV
1242
        if (tmpfs_mounted)
×
UNCOV
1243
                (void) umount_verbose(LOG_ERR, template, UMOUNT_NOFOLLOW);
×
1244

1245
        return r;
1246
}
1247

1248
static int setup_volatile_overlay(const char *directory, uid_t uid_shift, const char *selinux_apifs_context) {
4✔
1249
        _cleanup_free_ char *buf = NULL, *escaped_directory = NULL, *escaped_upper = NULL, *escaped_work = NULL;
4✔
1250
        _cleanup_(rmdir_and_freep) char *template = NULL;
4✔
1251
        const char *upper, *work, *options;
4✔
1252
        bool tmpfs_mounted = false;
4✔
1253
        int r;
4✔
1254

1255
        assert(directory);
4✔
1256

1257
        /* --volatile=overlay means we mount an overlayfs to the root dir. */
1258

1259
        r = mkdtemp_malloc("/tmp/nspawn-volatile-XXXXXX", &template);
4✔
1260
        if (r < 0)
4✔
1261
                return log_error_errno(r, "Failed to create temporary directory: %m");
×
1262

1263
        options = "mode=0755" TMPFS_LIMITS_ROOTFS;
4✔
1264
        r = tmpfs_patch_options(options, uid_shift == 0 ? UID_INVALID : uid_shift, selinux_apifs_context, &buf);
6✔
1265
        if (r < 0)
4✔
UNCOV
1266
                goto finish;
×
1267
        if (r > 0)
4✔
1268
                options = buf;
4✔
1269

1270
        r = mount_nofollow_verbose(LOG_ERR, "tmpfs", template, "tmpfs", MS_STRICTATIME, options);
4✔
1271
        if (r < 0)
4✔
UNCOV
1272
                goto finish;
×
1273

1274
        tmpfs_mounted = true;
4✔
1275

1276
        upper = strjoina(template, "/upper");
20✔
1277
        work = strjoina(template, "/work");
20✔
1278

1279
        if (mkdir(upper, 0755) < 0) {
4✔
UNCOV
1280
                r = log_error_errno(errno, "Failed to create %s: %m", upper);
×
UNCOV
1281
                goto finish;
×
1282
        }
1283
        if (mkdir(work, 0755) < 0) {
4✔
1284
                r = log_error_errno(errno, "Failed to create %s: %m", work);
×
1285
                goto finish;
×
1286
        }
1287

1288
        /* And now, let's overmount the root dir with an overlayfs that uses the root dir as lower dir. It's kinda nice
1289
         * that the kernel allows us to do that without going through some mount point rearrangements. */
1290

1291
        escaped_directory = shell_escape(directory, ",:");
4✔
1292
        escaped_upper = shell_escape(upper, ",:");
4✔
1293
        escaped_work = shell_escape(work, ",:");
4✔
1294
        if (!escaped_directory || !escaped_upper || !escaped_work) {
4✔
UNCOV
1295
                r = -ENOMEM;
×
UNCOV
1296
                goto finish;
×
1297
        }
1298

1299
        options = strjoina("lowerdir=", escaped_directory, ",upperdir=", escaped_upper, ",workdir=", escaped_work);
52✔
1300
        r = mount_nofollow_verbose(LOG_ERR, "overlay", directory, "overlay", 0, options);
4✔
1301

1302
finish:
UNCOV
1303
        if (tmpfs_mounted)
×
1304
                (void) umount_verbose(LOG_ERR, template, UMOUNT_NOFOLLOW);
4✔
1305

1306
        return r;
1307
}
1308

1309
int setup_volatile_mode(
256✔
1310
                const char *directory,
1311
                VolatileMode mode,
1312
                uid_t uid_shift,
1313
                const char *selinux_apifs_context) {
1314

1315
        switch (mode) {
256✔
1316

1317
        case VOLATILE_YES:
10✔
1318
                return setup_volatile_yes(directory, uid_shift, selinux_apifs_context);
10✔
1319

1320
        case VOLATILE_STATE:
4✔
1321
                return setup_volatile_state(directory);
4✔
1322

1323
        case VOLATILE_OVERLAY:
4✔
1324
                return setup_volatile_overlay(directory, uid_shift, selinux_apifs_context);
4✔
1325

1326
        default:
1327
                return 0;
1328
        }
1329
}
1330

1331
int setup_volatile_mode_after_remount_idmap(
254✔
1332
                const char *directory,
1333
                VolatileMode mode,
1334
                uid_t uid_shift,
1335
                const char *selinux_apifs_context) {
1336

1337
        switch (mode) {
254✔
1338

1339
        case VOLATILE_STATE:
4✔
1340
                return setup_volatile_state_after_remount_idmap(directory, uid_shift, selinux_apifs_context);
4✔
1341

1342
        default:
1343
                return 0;
1344
        }
1345
}
1346

1347
/* Expects *pivot_root_new and *pivot_root_old to be initialised to allocated memory or NULL. */
1348
int pivot_root_parse(char **pivot_root_new, char **pivot_root_old, const char *s) {
2✔
1349
        _cleanup_free_ char *root_new = NULL, *root_old = NULL;
2✔
1350
        const char *p = s;
2✔
1351
        int r;
2✔
1352

1353
        assert(pivot_root_new);
2✔
1354
        assert(pivot_root_old);
2✔
1355

1356
        r = extract_first_word(&p, &root_new, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
2✔
1357
        if (r < 0)
2✔
1358
                return r;
1359
        if (r == 0)
2✔
1360
                return -EINVAL;
1361

1362
        if (isempty(p))
2✔
1363
                root_old = NULL;
1364
        else {
1365
                root_old = strdup(p);
×
UNCOV
1366
                if (!root_old)
×
1367
                        return -ENOMEM;
1368
        }
1369

1370
        if (!path_is_absolute(root_new))
2✔
1371
                return -EINVAL;
UNCOV
1372
        if (root_old && !path_is_absolute(root_old))
×
1373
                return -EINVAL;
1374

UNCOV
1375
        free_and_replace(*pivot_root_new, root_new);
×
UNCOV
1376
        free_and_replace(*pivot_root_old, root_old);
×
1377

UNCOV
1378
        return 0;
×
1379
}
1380

1381
int setup_pivot_root(const char *directory, const char *pivot_root_new, const char *pivot_root_old) {
256✔
1382
        _cleanup_free_ char *directory_pivot_root_new = NULL;
512✔
1383
        _cleanup_free_ char *pivot_tmp_pivot_root_old = NULL;
256✔
1384
        _cleanup_(rmdir_and_freep) char *pivot_tmp = NULL;
256✔
1385
        int r;
256✔
1386

1387
        assert(directory);
256✔
1388

1389
        if (!pivot_root_new)
256✔
1390
                return 0;
1391

1392
        /* Pivot pivot_root_new to / and the existing / to pivot_root_old.
1393
         * If pivot_root_old is NULL, the existing / disappears.
1394
         * This requires a temporary directory, pivot_tmp, which is
1395
         * not a child of either.
1396
         *
1397
         * This is typically used for OSTree-style containers, where the root partition contains several
1398
         * sysroots which could be run. Normally, one would be chosen by the bootloader and pivoted to / by
1399
         * initrd.
1400
         *
1401
         * For example, for an OSTree deployment, pivot_root_new
1402
         * would be: /ostree/deploy/$os/deploy/$checksum. Note that this
1403
         * code doesn’t do the /var mount which OSTree expects: use
1404
         * --bind +/sysroot/ostree/deploy/$os/var:/var for that.
1405
         *
1406
         * So in the OSTree case, we’ll end up with something like:
1407
         *  - directory = /tmp/nspawn-root-123456
1408
         *  - pivot_root_new = /ostree/deploy/os/deploy/123abc
1409
         *  - pivot_root_old = /sysroot
1410
         *  - directory_pivot_root_new =
1411
         *       /tmp/nspawn-root-123456/ostree/deploy/os/deploy/123abc
1412
         *  - pivot_tmp = /tmp/nspawn-pivot-123456
1413
         *  - pivot_tmp_pivot_root_old = /tmp/nspawn-pivot-123456/sysroot
1414
         *
1415
         * Requires all file systems at directory and below to be mounted
1416
         * MS_PRIVATE or MS_SLAVE so they can be moved.
1417
         */
1418
        directory_pivot_root_new = path_join(directory, pivot_root_new);
×
1419
        if (!directory_pivot_root_new)
×
UNCOV
1420
                return log_oom();
×
1421

1422
        /* Remount directory_pivot_root_new to make it movable. */
1423
        r = mount_nofollow_verbose(LOG_ERR, directory_pivot_root_new, directory_pivot_root_new, NULL, MS_BIND, NULL);
×
UNCOV
1424
        if (r < 0)
×
1425
                return r;
1426

UNCOV
1427
        if (pivot_root_old) {
×
UNCOV
1428
                r = mkdtemp_malloc("/tmp/nspawn-pivot-XXXXXX", &pivot_tmp);
×
1429
                if (r < 0)
×
1430
                        return log_error_errno(r, "Failed to create temporary directory: %m");
×
1431

UNCOV
1432
                pivot_tmp_pivot_root_old = path_join(pivot_tmp, pivot_root_old);
×
1433
                if (!pivot_tmp_pivot_root_old)
×
UNCOV
1434
                        return log_oom();
×
1435

UNCOV
1436
                r = mount_nofollow_verbose(LOG_ERR, directory_pivot_root_new, pivot_tmp, NULL, MS_MOVE, NULL);
×
1437
                if (r < 0)
×
1438
                        return r;
1439

UNCOV
1440
                r = mount_nofollow_verbose(LOG_ERR, directory, pivot_tmp_pivot_root_old, NULL, MS_MOVE, NULL);
×
UNCOV
1441
                if (r < 0)
×
1442
                        return r;
1443

UNCOV
1444
                r = mount_nofollow_verbose(LOG_ERR, pivot_tmp, directory, NULL, MS_MOVE, NULL);
×
1445
        } else
UNCOV
1446
                r = mount_nofollow_verbose(LOG_ERR, directory_pivot_root_new, directory, NULL, MS_MOVE, NULL);
×
1447

UNCOV
1448
        if (r < 0)
×
UNCOV
1449
                return r;
×
1450

1451
        return 0;
1452
}
1453

1454
#define NSPAWN_PRIVATE_FULLY_VISIBLE_PROCFS "/run/host/proc"
1455
#define NSPAWN_PRIVATE_FULLY_VISIBLE_SYSFS "/run/host/sys"
1456

1457
int pin_fully_visible_api_fs(void) {
112✔
1458
        int r;
112✔
1459

1460
        log_debug("Pinning fully visible API FS");
112✔
1461

1462
        (void) mkdir_p(NSPAWN_PRIVATE_FULLY_VISIBLE_PROCFS, 0755);
112✔
1463
        (void) mkdir_p(NSPAWN_PRIVATE_FULLY_VISIBLE_SYSFS, 0755);
112✔
1464

1465
        r = mount_follow_verbose(LOG_ERR, "proc", NSPAWN_PRIVATE_FULLY_VISIBLE_PROCFS, "proc", PROC_DEFAULT_MOUNT_FLAGS, NULL);
112✔
1466
        if (r < 0)
112✔
1467
                return r;
1468

1469
        r = mount_follow_verbose(LOG_ERR, "sysfs", NSPAWN_PRIVATE_FULLY_VISIBLE_SYSFS, "sysfs", SYS_DEFAULT_MOUNT_FLAGS, NULL);
112✔
1470
        if (r < 0)
112✔
UNCOV
1471
                return r;
×
1472

1473
        return 0;
1474
}
1475

1476
static int do_wipe_fully_visible_api_fs(void) {
65✔
1477
        if (umount2(NSPAWN_PRIVATE_FULLY_VISIBLE_PROCFS, MNT_DETACH) < 0)
65✔
UNCOV
1478
                return log_error_errno(errno, "Failed to unmount temporary proc: %m");
×
1479

1480
        if (rmdir(NSPAWN_PRIVATE_FULLY_VISIBLE_PROCFS) < 0)
65✔
UNCOV
1481
                return log_error_errno(errno, "Failed to remove temporary proc mountpoint: %m");
×
1482

1483
        if (umount2(NSPAWN_PRIVATE_FULLY_VISIBLE_SYSFS, MNT_DETACH) < 0)
65✔
UNCOV
1484
                return log_error_errno(errno, "Failed to unmount temporary sys: %m");
×
1485

1486
        if (rmdir(NSPAWN_PRIVATE_FULLY_VISIBLE_SYSFS) < 0)
65✔
UNCOV
1487
                return log_error_errno(errno, "Failed to remove temporary sys mountpoint: %m");
×
1488

1489
        return 0;
1490
}
1491

1492
int wipe_fully_visible_api_fs(int mntns_fd) {
65✔
1493
        _cleanup_close_ int orig_mntns_fd = -EBADF;
65✔
1494
        int r, rr;
65✔
1495

1496
        log_debug("Wiping fully visible API FS");
65✔
1497

1498
        orig_mntns_fd = namespace_open_by_type(NAMESPACE_MOUNT);
65✔
1499
        if (orig_mntns_fd < 0)
65✔
UNCOV
1500
                return log_error_errno(orig_mntns_fd, "Failed to pin originating mount namespace: %m");
×
1501

1502
        r = namespace_enter(/* pidns_fd = */ -EBADF,
65✔
1503
                            mntns_fd,
1504
                            /* netns_fd = */ -EBADF,
1505
                            /* userns_fd = */ -EBADF,
1506
                            /* root_fd = */ -EBADF);
1507
        if (r < 0)
65✔
UNCOV
1508
                return log_error_errno(r, "Failed to enter mount namespace: %m");
×
1509

1510
        rr = do_wipe_fully_visible_api_fs();
65✔
1511

1512
        r = namespace_enter(/* pidns_fd = */ -EBADF,
65✔
1513
                            orig_mntns_fd,
1514
                            /* netns_fd = */ -EBADF,
1515
                            /* userns_fd = */ -EBADF,
1516
                            /* root_fd = */ -EBADF);
1517
        if (r < 0)
65✔
UNCOV
1518
                return log_error_errno(r, "Failed to enter original mount namespace: %m");
×
1519

1520
        return rr;
1521
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc