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

systemd / systemd / 18052125394

26 Sep 2025 11:00PM UTC coverage: 72.224% (+0.02%) from 72.205%
18052125394

push

github

YHNdnzj
pam_systemd: correct alignment

Follow-up for cf2630aca

303350 of 420010 relevant lines covered (72.22%)

1058085.05 hits per line

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

72.22
/src/shared/mount-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <stdlib.h>
4
#include <sys/mount.h>
5
#include <sys/stat.h>
6
#include <unistd.h>
7

8
#include "alloc-util.h"
9
#include "chase.h"
10
#include "dissect-image.h"
11
#include "errno-util.h"
12
#include "extract-word.h"
13
#include "fd-util.h"
14
#include "fileio.h"
15
#include "format-util.h"
16
#include "fs-util.h"
17
#include "fstab-util.h"
18
#include "glyph-util.h"
19
#include "hashmap.h"
20
#include "libmount-util.h"
21
#include "log.h"
22
#include "mkdir-label.h"
23
#include "mount-util.h"
24
#include "mountpoint-util.h"
25
#include "namespace-util.h"
26
#include "os-util.h"
27
#include "path-util.h"
28
#include "pidref.h"
29
#include "process-util.h"
30
#include "set.h"
31
#include "sort-util.h"
32
#include "stat-util.h"
33
#include "string-util.h"
34
#include "strv.h"
35
#include "tmpfile-util.h"
36
#include "user-util.h"
37

38
int umount_recursive_full(const char *prefix, int flags, char **keep) {
8,099✔
39
        _cleanup_fclose_ FILE *f = NULL;
8,099✔
40
        int n = 0, r;
8,099✔
41

42
        /* Try to umount everything recursively below a directory. Also, take care of stacked mounts, and
43
         * keep unmounting them until they are gone. */
44

45
        f = fopen("/proc/self/mountinfo", "re"); /* Pin the file, in case we unmount /proc/ as part of the logic here */
8,099✔
46
        if (!f)
8,099✔
47
                return log_debug_errno(errno, "Failed to open %s: %m", "/proc/self/mountinfo");
×
48

49
        for (;;) {
17,327✔
50
                _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
25,426✔
51
                _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
17,327✔
52
                bool again = false;
25,426✔
53

54
                r = libmount_parse_mountinfo(f, &table, &iter);
25,426✔
55
                if (r < 0)
25,426✔
56
                        return log_debug_errno(r, "Failed to parse /proc/self/mountinfo: %m");
×
57

58
                for (;;) {
2,777,084✔
59
                        bool shall_keep = false;
1,401,255✔
60
                        struct libmnt_fs *fs;
1,401,255✔
61
                        const char *path;
1,401,255✔
62

63
                        r = sym_mnt_table_next_fs(table, iter, &fs);
1,401,255✔
64
                        if (r == 1)
1,401,255✔
65
                                break;
66
                        if (r < 0)
1,393,156✔
67
                                return log_debug_errno(r, "Failed to get next entry from /proc/self/mountinfo: %m");
×
68

69
                        path = sym_mnt_fs_get_target(fs);
1,393,156✔
70
                        if (!path)
1,393,156✔
71
                                continue;
1,375,829✔
72

73
                        if (prefix && !path_startswith(path, prefix)) {
2,785,915✔
74
                                // FIXME: This is extremely noisy, we're probably doing something very wrong
75
                                // to trigger this so often, needs more investigation.
76
                                // log_trace("Not unmounting %s, outside of prefix: %s", path, prefix);
77
                                continue;
1,366,814✔
78
                        }
79

80
                        STRV_FOREACH(k, keep)
26,424✔
81
                                /* Match against anything in the path to the dirs to keep, or below the dirs to keep */
82
                                if (path_startswith(path, *k) || path_startswith(*k, path)) {
412✔
83
                                        shall_keep = true;
330✔
84
                                        break;
330✔
85
                                }
86
                        if (shall_keep) {
26,672✔
87
                                log_debug("Not unmounting %s, referenced by keep list.", path);
330✔
88
                                continue;
330✔
89
                        }
90

91
                        if (umount2(path, flags | UMOUNT_NOFOLLOW) < 0) {
26,012✔
92
                                log_debug_errno(errno, "Failed to umount %s, ignoring: %m", path);
8,685✔
93
                                continue;
8,685✔
94
                        }
95

96
                        log_trace("Successfully unmounted %s", path);
17,327✔
97

98
                        again = true;
17,327✔
99
                        n++;
17,327✔
100

101
                        break;
17,327✔
102
                }
103

104
                if (!again)
8,099✔
105
                        break;
106

107
                rewind(f);
17,327✔
108
        }
109

110
        return n;
8,099✔
111
}
112

113
#define MS_CONVERTIBLE_FLAGS (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_NOSYMFOLLOW|MS_RELATIME|MS_NOATIME|MS_STRICTATIME|MS_NODIRATIME)
114

115
static uint64_t ms_flags_to_mount_attr(unsigned long a) {
35,208✔
116
        uint64_t f = 0;
35,208✔
117

118
        if (FLAGS_SET(a, MS_RDONLY))
35,208✔
119
                f |= MOUNT_ATTR_RDONLY;
1,365✔
120

121
        if (FLAGS_SET(a, MS_NOSUID))
35,208✔
122
                f |= MOUNT_ATTR_NOSUID;
16,241✔
123

124
        if (FLAGS_SET(a, MS_NODEV))
35,208✔
125
                f |= MOUNT_ATTR_NODEV;
2✔
126

127
        if (FLAGS_SET(a, MS_NOEXEC))
35,208✔
128
                f |= MOUNT_ATTR_NOEXEC;
2✔
129

130
        if (FLAGS_SET(a, MS_NOSYMFOLLOW))
35,208✔
131
                f |= MOUNT_ATTR_NOSYMFOLLOW;
×
132

133
        if (FLAGS_SET(a, MS_RELATIME))
35,208✔
134
                f |= MOUNT_ATTR_RELATIME;
35,208✔
135

136
        if (FLAGS_SET(a, MS_NOATIME))
35,208✔
137
                f |= MOUNT_ATTR_NOATIME;
×
138

139
        if (FLAGS_SET(a, MS_STRICTATIME))
35,208✔
140
                f |= MOUNT_ATTR_STRICTATIME;
×
141

142
        if (FLAGS_SET(a, MS_NODIRATIME))
35,208✔
143
                f |= MOUNT_ATTR_NODIRATIME;
×
144

145
        return f;
35,208✔
146
}
147

148
static uint64_t ms_flags_to_mount_attr_clr(unsigned long a) {
2✔
149
        uint64_t f = 0;
2✔
150

151
        /* As per documentation, if relatime/noatime/strictatime are set, we need to clear the atime flag
152
         * too, otherwise -EINVAL will be returned by the kernel. */
153
        if (FLAGS_SET(a, MS_RELATIME))
2✔
154
                f |= MOUNT_ATTR__ATIME;
×
155

156
        if (FLAGS_SET(a, MS_NOATIME))
2✔
157
                f |= MOUNT_ATTR__ATIME;
×
158

159
        if (FLAGS_SET(a, MS_STRICTATIME))
2✔
160
                f |= MOUNT_ATTR__ATIME;
×
161

162
        return f;
2✔
163
}
164

165
static bool skip_mount_set_attr = false;
166

167
/* Use this function only if you do not have direct access to /proc/self/mountinfo but the caller can open it
168
 * for you. This is the case when /proc is masked or not mounted. Otherwise, use bind_remount_recursive. */
169
int bind_remount_recursive_with_mountinfo(
33,980✔
170
                const char *prefix,
171
                unsigned long new_flags,
172
                unsigned long flags_mask,
173
                char **deny_list,
174
                FILE *proc_self_mountinfo) {
175

176
        _cleanup_fclose_ FILE *proc_self_mountinfo_opened = NULL;
33,980✔
177
        _cleanup_set_free_ Set *done = NULL;
33,980✔
178
        unsigned n_tries = 0;
33,980✔
179
        int r;
33,980✔
180

181
        assert(prefix);
33,980✔
182

183
        if ((flags_mask & ~MS_CONVERTIBLE_FLAGS) == 0 && strv_isempty(deny_list) && !skip_mount_set_attr) {
49,511✔
184
                /* Let's take a shortcut for all the flags we know how to convert into mount_setattr() flags */
185

186
                if (mount_setattr(AT_FDCWD, prefix, AT_SYMLINK_NOFOLLOW|AT_RECURSIVE,
15,531✔
187
                                  &(struct mount_attr) {
15,531✔
188
                                          .attr_set = ms_flags_to_mount_attr(new_flags & flags_mask),
15,531✔
189
                                          .attr_clr = ms_flags_to_mount_attr(~new_flags & flags_mask),
15,531✔
190
                                  }, MOUNT_ATTR_SIZE_VER0) < 0) {
191

192
                        log_debug_errno(errno, "mount_setattr() failed, falling back to classic remounting: %m");
2✔
193

194
                        /* We fall through to classic behaviour if not supported (i.e. kernel < 5.12). We
195
                         * also do this for all other kinds of errors since they are so many different, and
196
                         * mount_setattr() has no graceful mode where it continues despite seeing errors one
197
                         * some mounts, but we want that. Moreover mount_setattr() only works on the mount
198
                         * point inode itself, not a non-mount point inode, and we want to support arbitrary
199
                         * prefixes here. */
200

201
                        if (ERRNO_IS_NOT_SUPPORTED(errno)) /* if not supported, then don't bother at all anymore */
2✔
202
                                skip_mount_set_attr = true;
×
203
                } else
204
                        return 0; /* Nice, this worked! */
15,529✔
205
        }
206

207
        if (!proc_self_mountinfo) {
18,451✔
208
                r = fopen_unlocked("/proc/self/mountinfo", "re", &proc_self_mountinfo_opened);
3✔
209
                if (r < 0)
3✔
210
                        return r;
211

212
                proc_self_mountinfo = proc_self_mountinfo_opened;
3✔
213
        }
214

215
        /* Recursively remount a directory (and all its submounts) with desired flags (MS_READONLY,
216
         * MS_NOSUID, MS_NOEXEC). If the directory is already mounted, we reuse the mount and simply mark it
217
         * MS_BIND|MS_RDONLY (or remove the MS_RDONLY for read-write operation), ditto for other flags. If it
218
         * isn't we first make it one. Afterwards we apply (or remove) the flags to all submounts we can
219
         * access, too. When mounts are stacked on the same mount point we only care for each individual
220
         * "top-level" mount on each point, as we cannot influence/access the underlying mounts anyway. We do
221
         * not have any effect on future submounts that might get propagated, they might be writable
222
         * etc. This includes future submounts that have been triggered via autofs. Also note that we can't
223
         * operate atomically here. Mounts established while we process the tree might or might not get
224
         * noticed and thus might or might not be covered.
225
         *
226
         * If the "deny_list" parameter is specified it may contain a list of subtrees to exclude from the
227
         * remount operation. Note that we'll ignore the deny list for the top-level path. */
228

229
        for (;;) {
36,906✔
230
                _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
36,906✔
231
                _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
36,906✔
232
                _cleanup_hashmap_free_ Hashmap *todo = NULL;
36,904✔
233
                bool top_autofs = false;
36,906✔
234

235
                if (n_tries++ >= 32) /* Let's not retry this loop forever */
36,906✔
236
                        return -EBUSY;
237

238
                rewind(proc_self_mountinfo);
36,906✔
239

240
                r = libmount_parse_mountinfo(proc_self_mountinfo, &table, &iter);
36,906✔
241
                if (r < 0)
36,906✔
242
                        return log_debug_errno(r, "Failed to parse /proc/self/mountinfo: %m");
×
243

244
                for (;;) {
2,618,455✔
245
                        _cleanup_free_ char *d = NULL;
2,581,549✔
246
                        const char *path, *type, *opts;
2,618,455✔
247
                        unsigned long flags = 0;
2,618,455✔
248
                        struct libmnt_fs *fs;
2,618,455✔
249

250
                        r = sym_mnt_table_next_fs(table, iter, &fs);
2,618,455✔
251
                        if (r == 1) /* EOF */
2,618,455✔
252
                                break;
253
                        if (r < 0)
2,581,549✔
254
                                return log_debug_errno(r, "Failed to get next entry from /proc/self/mountinfo: %m");
×
255

256
                        path = sym_mnt_fs_get_target(fs);
2,581,549✔
257
                        if (!path)
2,581,549✔
258
                                continue;
×
259

260
                        if (!path_startswith(path, prefix))
2,581,549✔
261
                                continue;
2,517,860✔
262

263
                        type = sym_mnt_fs_get_fstype(fs);
63,689✔
264
                        if (!type)
63,689✔
265
                                continue;
×
266

267
                        /* Let's ignore autofs mounts. If they aren't triggered yet, we want to avoid
268
                         * triggering them, as we don't make any guarantees for future submounts anyway. If
269
                         * they are already triggered, then we will find another entry for this. */
270
                        if (streq(type, "autofs")) {
63,689✔
271
                                top_autofs = top_autofs || path_equal(path, prefix);
4,972✔
272
                                continue;
2,486✔
273
                        }
274

275
                        if (set_contains(done, path))
61,203✔
276
                                continue;
22,347✔
277

278
                        /* Ignore this mount if it is deny-listed, but only if it isn't the top-level mount
279
                         * we shall operate on. */
280
                        if (!path_equal(path, prefix)) {
38,856✔
281
                                bool deny_listed = false;
269,320✔
282

283
                                STRV_FOREACH(i, deny_list) {
269,320✔
284
                                        if (path_equal(*i, prefix))
265,427✔
285
                                                continue;
20,392✔
286

287
                                        if (!path_startswith(*i, prefix))
245,035✔
288
                                                continue;
138,086✔
289

290
                                        if (path_startswith(path, *i)) {
106,949✔
291
                                                deny_listed = true;
292
                                                log_trace("Not remounting %s deny-listed by %s, called for %s", path, *i, prefix);
293
                                                break;
294
                                        }
295
                                }
296

297
                                if (deny_listed)
20,403✔
298
                                        continue;
16,510✔
299
                        }
300

301
                        opts = sym_mnt_fs_get_vfs_options(fs);
22,346✔
302
                        if (opts) {
22,346✔
303
                                r = sym_mnt_optstr_get_flags(opts, &flags, sym_mnt_get_builtin_optmap(MNT_LINUX_MAP));
22,346✔
304
                                if (r < 0)
22,346✔
305
                                        log_debug_errno(r, "Could not get flags for '%s', ignoring: %m", path);
×
306
                        }
307

308
                        d = strdup(path);
22,346✔
309
                        if (!d)
22,346✔
310
                                return -ENOMEM;
311

312
                        r = hashmap_ensure_put(&todo, &path_hash_ops_free, d, ULONG_TO_PTR(flags));
22,346✔
313
                        if (r == -EEXIST)
22,346✔
314
                                /* If the same path was recorded, but with different mount flags, update it:
315
                                 * it means a mount point is overmounted, and libmount returns the "bottom" (or
316
                                 * older one) first, but we want to reapply the flags from the "top" (or newer
317
                                 * one). See: https://github.com/systemd/systemd/issues/20032
318
                                 * Note that this shouldn't really fail, as we were just told that the key
319
                                 * exists, and it's an update so we want 'd' to be freed immediately. */
320
                                r = hashmap_update(todo, d, ULONG_TO_PTR(flags));
9✔
321
                        if (r < 0)
22,346✔
322
                                return r;
323
                        if (r > 0)
22,346✔
324
                                TAKE_PTR(d);
22,303✔
325
                }
326

327
                /* Check if the top-level directory was among what we have seen so far. For that check both
328
                 * 'done' and 'todo'. Also check 'top_autofs' because if the top-level dir is an autofs we'll
329
                 * not include it in either set but will set this bool. */
330
                if (!set_contains(done, prefix) &&
36,906✔
331
                    !(top_autofs || hashmap_contains(todo, prefix))) {
18,453✔
332

333
                        /* The prefix directory itself is not yet a mount, make it one. */
334
                        r = mount_nofollow(prefix, prefix, NULL, MS_BIND|MS_REC, NULL);
2✔
335
                        if (r < 0)
2✔
336
                                return r;
337

338
                        /* Immediately rescan, so that we pick up the new mount's flags */
339
                        continue;
2✔
340
                }
341

342
                /* If we have no submounts to process anymore, we are done */
343
                if (hashmap_isempty(todo))
36,904✔
344
                        return 0;
345

346
                for (;;) {
40,755✔
347
                        unsigned long flags;
40,755✔
348
                        char *x = NULL;
40,755✔
349

350
                        /* Take the first mount from our list of mounts to still process */
351
                        flags = PTR_TO_ULONG(hashmap_steal_first_key_and_value(todo, (void**) &x));
40,755✔
352
                        if (!x)
40,755✔
353
                                break;
354

355
                        r = set_ensure_consume(&done, &path_hash_ops_free, x);
22,302✔
356
                        if (IN_SET(r, 0, -EEXIST))
22,302✔
357
                                continue; /* Already done */
270✔
358
                        if (r < 0)
22,302✔
359
                                return r;
×
360

361
                        /* Now, remount this with the new flags set, but exclude MS_RELATIME from it. (It's
362
                         * the default anyway, thus redundant, and in userns we'll get an error if we try to
363
                         * explicitly enable it) */
364
                        r = mount_nofollow(NULL, x, NULL, ((flags & ~flags_mask)|MS_BIND|MS_REMOUNT|new_flags) & ~MS_RELATIME, NULL);
22,302✔
365
                        if (r < 0) {
22,302✔
366
                                int q;
270✔
367

368
                                /* OK, so the remount of this entry failed. We'll ultimately ignore this in
369
                                 * almost all cases (there are simply so many reasons why this can fail,
370
                                 * think autofs, NFS, FUSE, …), but let's generate useful debug messages at
371
                                 * the very least. */
372

373
                                q = path_is_mount_point(x);
270✔
374
                                if (IN_SET(q, 0, -ENOENT)) {
270✔
375
                                        /* Hmm, whaaaa? The mount point is not actually a mount point? Then
376
                                         * it is either obstructed by a later mount or somebody has been
377
                                         * racing against us and removed it. Either way the mount point
378
                                         * doesn't matter to us, let's ignore it hence. */
379
                                        log_debug_errno(r, "Mount point '%s' to remount is not a mount point anymore, ignoring remount failure: %m", x);
266✔
380
                                        continue;
266✔
381
                                }
382
                                if (q < 0) /* Any other error on this? Just log and continue */
4✔
383
                                        log_debug_errno(q, "Failed to determine whether '%s' is a mount point or not, ignoring: %m", x);
×
384

385
                                if (((flags ^ new_flags) & flags_mask & ~MS_RELATIME) == 0) { /* ignore MS_RELATIME while comparing */
4✔
386
                                        log_debug_errno(r, "Couldn't remount '%s', but the flags already match what we want, hence ignoring: %m", x);
×
387
                                        continue;
×
388
                                }
389

390
                                /* Make this fatal if this is the top-level mount */
391
                                if (path_equal(x, prefix))
4✔
392
                                        return r;
393

394
                                /* If this is not the top-level mount, then handle this gracefully: log but
395
                                 * otherwise ignore. With NFS, FUSE, autofs there are just too many reasons
396
                                 * this might fail without a chance for us to do anything about it, let's
397
                                 * hence be strict on the top-level mount and lenient on the inner ones. */
398
                                log_debug_errno(r, "Couldn't remount submount '%s' for unexpected reason, ignoring: %m", x);
4✔
399
                                continue;
4✔
400
                        }
401

402
                        log_trace("Remounted %s.", x);
22,032✔
403
                }
404
        }
405
}
406

407
int bind_remount_one_with_mountinfo(
2,072✔
408
                const char *path,
409
                unsigned long new_flags,
410
                unsigned long flags_mask,
411
                FILE *proc_self_mountinfo) {
412

413
        _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
×
414
        unsigned long flags = 0;
2,072✔
415
        struct libmnt_fs *fs;
2,072✔
416
        const char *opts;
2,072✔
417
        int r;
2,072✔
418

419
        assert(path);
2,072✔
420
        assert(proc_self_mountinfo);
2,072✔
421

422
        if ((flags_mask & ~MS_CONVERTIBLE_FLAGS) == 0 && !skip_mount_set_attr) {
2,072✔
423
                /* Let's take a shortcut for all the flags we know how to convert into mount_setattr() flags */
424

425
                if (mount_setattr(AT_FDCWD, path, AT_SYMLINK_NOFOLLOW,
2,072✔
426
                                  &(struct mount_attr) {
2,072✔
427
                                          .attr_set = ms_flags_to_mount_attr(new_flags & flags_mask),
2,072✔
428
                                          .attr_clr = ms_flags_to_mount_attr(~new_flags & flags_mask),
2,072✔
429
                                  }, MOUNT_ATTR_SIZE_VER0) < 0) {
430

431
                        log_debug_errno(errno, "mount_setattr() didn't work, falling back to classic remounting: %m");
4✔
432

433
                        if (ERRNO_IS_NOT_SUPPORTED(errno)) /* if not supported, then don't bother at all anymore */
4✔
434
                                skip_mount_set_attr = true;
×
435
                } else
436
                        return 0; /* Nice, this worked! */
2,068✔
437
        }
438

439
        rewind(proc_self_mountinfo);
4✔
440

441
        r = dlopen_libmount();
4✔
442
        if (r < 0)
4✔
443
                return r;
444

445
        table = sym_mnt_new_table();
4✔
446
        if (!table)
4✔
447
                return -ENOMEM;
448

449
        r = sym_mnt_table_parse_stream(table, proc_self_mountinfo, "/proc/self/mountinfo");
4✔
450
        if (r < 0)
4✔
451
                return r;
452

453
        fs = sym_mnt_table_find_target(table, path, MNT_ITER_FORWARD);
4✔
454
        if (!fs) {
4✔
455
                r = access_nofollow(path, F_OK); /* Hmm, it's not in the mount table, but does it exist at all? */
4✔
456
                if (r < 0)
4✔
457
                        return r;
458

459
                return -EINVAL; /* Not a mount point we recognize */
2✔
460
        }
461

462
        opts = sym_mnt_fs_get_vfs_options(fs);
×
463
        if (opts) {
×
464
                r = sym_mnt_optstr_get_flags(opts, &flags, sym_mnt_get_builtin_optmap(MNT_LINUX_MAP));
×
465
                if (r < 0)
×
466
                        log_debug_errno(r, "Could not get flags for '%s', ignoring: %m", path);
×
467
        }
468

469
        r = mount_nofollow(NULL, path, NULL, ((flags & ~flags_mask)|MS_BIND|MS_REMOUNT|new_flags) & ~MS_RELATIME, NULL);
×
470
        if (r < 0) {
×
471
                if (((flags ^ new_flags) & flags_mask & ~MS_RELATIME) != 0) /* Ignore MS_RELATIME again,
×
472
                                                                             * since kernel adds it in
473
                                                                             * everywhere, because it's the
474
                                                                             * default. */
475
                        return r;
476

477
                /* Let's handle redundant remounts gracefully */
478
                log_debug_errno(r, "Failed to remount '%s' but flags already match what we want, ignoring: %m", path);
2,072✔
479
        }
480

481
        return 0;
482
}
483

484
int bind_remount_one(const char *path, unsigned long new_flags, unsigned long flags_mask) {
53✔
485
        _cleanup_fclose_ FILE *proc_self_mountinfo = NULL;
53✔
486

487
        proc_self_mountinfo = fopen("/proc/self/mountinfo", "re");
53✔
488
        if (!proc_self_mountinfo)
53✔
489
                return log_debug_errno(errno, "Failed to open %s: %m", "/proc/self/mountinfo");
×
490

491
        return bind_remount_one_with_mountinfo(path, new_flags, flags_mask, proc_self_mountinfo);
53✔
492
}
493

494
static int mount_switch_root_pivot(int fd_newroot, const char *path) {
2,190✔
495
        assert(fd_newroot >= 0);
2,190✔
496
        assert(path);
2,190✔
497

498
        /* Let the kernel tuck the new root under the old one. */
499
        if (pivot_root(".", ".") < 0)
2,190✔
500
                return log_debug_errno(errno, "Failed to pivot root to new rootfs '%s': %m", path);
×
501

502
        /* Get rid of the old root and reveal our brand new root. (This will always operate on the top-most
503
         * mount on our cwd, regardless what our current directory actually points to.) */
504
        if (umount2(".", MNT_DETACH) < 0)
2,190✔
505
                return log_debug_errno(errno, "Failed to unmount old rootfs: %m");
×
506

507
        return 0;
508
}
509

510
static int mount_switch_root_move(int fd_newroot, const char *path) {
×
511
        assert(fd_newroot >= 0);
×
512
        assert(path);
×
513

514
        /* Move the new root fs */
515
        if (mount(".", "/", NULL, MS_MOVE, NULL) < 0)
×
516
                return log_debug_errno(errno, "Failed to move new rootfs '%s': %m", path);
×
517

518
        /* Also change root dir */
519
        if (chroot(".") < 0)
×
520
                return log_debug_errno(errno, "Failed to chroot to new rootfs '%s': %m", path);
×
521

522
        return 0;
523
}
524

525
int mount_switch_root_full(const char *path, unsigned long mount_propagation_flag, bool force_ms_move) {
2,192✔
526
        _cleanup_close_ int fd_newroot = -EBADF;
2,192✔
527
        int r, is_current_root;
2,192✔
528

529
        assert(path);
2,192✔
530
        assert(mount_propagation_flag_is_valid(mount_propagation_flag));
2,192✔
531

532
        fd_newroot = open(path, O_PATH|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
2,192✔
533
        if (fd_newroot < 0)
2,192✔
534
                return log_debug_errno(errno, "Failed to open new rootfs '%s': %m", path);
×
535

536
        is_current_root = path_is_root_at(fd_newroot, NULL);
2,192✔
537
        if (is_current_root < 0)
2,192✔
538
                return log_debug_errno(is_current_root, "Failed to determine if target dir is our root already: %m");
×
539

540
        /* Change into the new rootfs. */
541
        if (fchdir(fd_newroot) < 0)
2,192✔
542
                return log_debug_errno(errno, "Failed to chdir into new rootfs '%s': %m", path);
×
543

544
        /* Make this a NOP if we are supposed to switch to our current root fs. After all, both pivot_root()
545
         * and MS_MOVE don't like that. */
546
        if (!is_current_root) {
2,192✔
547
                if (!force_ms_move) {
2,190✔
548
                        r = mount_switch_root_pivot(fd_newroot, path);
2,190✔
549
                        if (r < 0) {
2,190✔
550
                                log_debug_errno(r, "Failed to pivot into new rootfs '%s', will try to use MS_MOVE instead: %m", path);
×
551
                                force_ms_move = true;
552
                        }
553
                }
554
                if (force_ms_move) {
555
                        /* Failed to pivot_root() fallback to MS_MOVE. For example, this may happen if the rootfs is
556
                         * an initramfs in which case pivot_root() isn't supported. */
557
                        r = mount_switch_root_move(fd_newroot, path);
×
558
                        if (r < 0)
×
559
                                return log_debug_errno(r, "Failed to switch to new rootfs '%s' with MS_MOVE: %m", path);
×
560
                }
561
        }
562

563
        log_debug("Successfully switched root to '%s'.", path);
2,192✔
564

565
        /* Finally, let's establish the requested propagation flags. */
566
        if (mount_propagation_flag == 0)
2,192✔
567
                return 0;
568

569
        if (mount(NULL, ".", NULL, mount_propagation_flag | MS_REC, NULL) < 0)
241✔
570
                return log_debug_errno(errno, "Failed to turn new rootfs '%s' into %s mount: %m",
×
571
                                       mount_propagation_flag_to_string(mount_propagation_flag), path);
572

573
        return 0;
574
}
575

576
int repeat_unmount(const char *path, int flags) {
17✔
577
        bool done = false;
17✔
578

579
        assert(path);
17✔
580

581
        /* If there are multiple mounts on a mount point, this
582
         * removes them all */
583

584
        for (;;) {
34✔
585
                if (umount2(path, flags) < 0) {
34✔
586

587
                        if (errno == EINVAL)
17✔
588
                                return done;
17✔
589

590
                        return -errno;
×
591
                }
592

593
                done = true;
594
        }
595
}
596

597
int mode_to_inaccessible_node(
4,563✔
598
                const char *runtime_dir,
599
                mode_t mode,
600
                char **ret) {
601

602
        /* This function maps a node type to a corresponding inaccessible file node. These nodes are created
603
         * during early boot by PID 1. In some cases we lacked the privs to create the character and block
604
         * devices (maybe because we run in an userns environment, or miss CAP_SYS_MKNOD, or run with a
605
         * devices policy that excludes device nodes with major and minor of 0), but that's fine, in that
606
         * case we use an AF_UNIX file node instead, which is not the same, but close enough for most
607
         * uses. And most importantly, the kernel allows bind mounts from socket nodes to any non-directory
608
         * file nodes, and that's the most important thing that matters.
609
         *
610
         * Note that the runtime directory argument shall be the top-level runtime directory, i.e. /run/ if
611
         * we operate in system context and $XDG_RUNTIME_DIR if we operate in user context. */
612

613
        _cleanup_free_ char *d = NULL;
4,563✔
614
        const char *node;
4,563✔
615

616
        assert(ret);
4,563✔
617

618
        if (!runtime_dir)
4,563✔
619
                runtime_dir = "/run";
4✔
620

621
        if (S_ISLNK(mode))
4,563✔
622
                return -EINVAL;
623

624
        node = inode_type_to_string(mode);
4,563✔
625
        if (!node)
4,563✔
626
                return -EINVAL;
627

628
        d = path_join(runtime_dir, "systemd/inaccessible", node);
4,563✔
629
        if (!d)
4,563✔
630
                return -ENOMEM;
631

632
        /* On new kernels unprivileged users are permitted to create 0:0 char device nodes (because they also
633
         * act as whiteout inode for overlayfs), but no other char or block device nodes. On old kernels no
634
         * device node whatsoever may be created by unprivileged processes. Hence, if the caller asks for the
635
         * inaccessible block device node let's see if the block device node actually exists, and if not,
636
         * fall back to the character device node. From there fall back to the socket device node. This means
637
         * in the best case we'll get the right device node type — but if not we'll hopefully at least get a
638
         * device node at all. */
639

640
        if (S_ISBLK(mode) &&
4,563✔
641
            access(d, F_OK) < 0 && errno == ENOENT) {
×
642
                free(d);
×
643
                d = path_join(runtime_dir, "/systemd/inaccessible/chr");
×
644
                if (!d)
×
645
                        return -ENOMEM;
646
        }
647

648
        if (IN_SET(mode & S_IFMT, S_IFBLK, S_IFCHR) &&
5,092✔
649
            access(d, F_OK) < 0 && errno == ENOENT) {
529✔
650
                free(d);
×
651
                d = path_join(runtime_dir, "/systemd/inaccessible/sock");
×
652
                if (!d)
×
653
                        return -ENOMEM;
654
        }
655

656
        *ret = TAKE_PTR(d);
4,563✔
657
        return 0;
4,563✔
658
}
659

660
int mount_flags_to_string(unsigned long flags, char **ret) {
47,767✔
661
        static const struct {
47,767✔
662
                unsigned long flag;
663
                const char *name;
664
        } map[] = {
665
                { .flag = MS_RDONLY,      .name = "MS_RDONLY",      },
666
                { .flag = MS_NOSUID,      .name = "MS_NOSUID",      },
667
                { .flag = MS_NODEV,       .name = "MS_NODEV",       },
668
                { .flag = MS_NOEXEC,      .name = "MS_NOEXEC",      },
669
                { .flag = MS_SYNCHRONOUS, .name = "MS_SYNCHRONOUS", },
670
                { .flag = MS_REMOUNT,     .name = "MS_REMOUNT",     },
671
                { .flag = MS_MANDLOCK,    .name = "MS_MANDLOCK",    },
672
                { .flag = MS_DIRSYNC,     .name = "MS_DIRSYNC",     },
673
                { .flag = MS_NOSYMFOLLOW, .name = "MS_NOSYMFOLLOW", },
674
                { .flag = MS_NOATIME,     .name = "MS_NOATIME",     },
675
                { .flag = MS_NODIRATIME,  .name = "MS_NODIRATIME",  },
676
                { .flag = MS_BIND,        .name = "MS_BIND",        },
677
                { .flag = MS_MOVE,        .name = "MS_MOVE",        },
678
                { .flag = MS_REC,         .name = "MS_REC",         },
679
                { .flag = MS_SILENT,      .name = "MS_SILENT",      },
680
                { .flag = MS_POSIXACL,    .name = "MS_POSIXACL",    },
681
                { .flag = MS_UNBINDABLE,  .name = "MS_UNBINDABLE",  },
682
                { .flag = MS_PRIVATE,     .name = "MS_PRIVATE",     },
683
                { .flag = MS_SLAVE,       .name = "MS_SLAVE",       },
684
                { .flag = MS_SHARED,      .name = "MS_SHARED",      },
685
                { .flag = MS_RELATIME,    .name = "MS_RELATIME",    },
686
                { .flag = MS_KERNMOUNT,   .name = "MS_KERNMOUNT",   },
687
                { .flag = MS_I_VERSION,   .name = "MS_I_VERSION",   },
688
                { .flag = MS_STRICTATIME, .name = "MS_STRICTATIME", },
689
                { .flag = MS_LAZYTIME,    .name = "MS_LAZYTIME",    },
690
        };
691
        _cleanup_free_ char *str = NULL;
47,767✔
692

693
        assert(ret);
47,767✔
694

695
        FOREACH_ELEMENT(entry, map)
1,241,942✔
696
                if (flags & entry->flag) {
1,194,175✔
697
                        if (!strextend_with_separator(&str, "|", entry->name))
115,576✔
698
                                return -ENOMEM;
699
                        flags &= ~entry->flag;
115,576✔
700
                }
701

702
        if (!str || flags != 0)
47,767✔
703
                if (strextendf_with_separator(&str, "|", "%lx", flags) < 0)
136✔
704
                        return -ENOMEM;
705

706
        *ret = TAKE_PTR(str);
47,767✔
707
        return 0;
47,767✔
708
}
709

710
int mount_verbose_full(
47,737✔
711
                int error_log_level,
712
                const char *what,
713
                const char *where,
714
                const char *type,
715
                unsigned long flags,
716
                const char *options,
717
                bool follow_symlink) {
718

719
        _cleanup_free_ char *fl = NULL, *o = NULL;
47,737✔
720
        unsigned long f;
47,737✔
721
        int r;
47,737✔
722

723
        r = mount_option_mangle(options, flags, &f, &o);
47,737✔
724
        if (r < 0)
47,737✔
725
                return log_full_errno(error_log_level, r,
×
726
                                      "Failed to mangle mount options %s: %m",
727
                                      strempty(options));
728

729
        (void) mount_flags_to_string(f, &fl);
47,737✔
730

731
        if (FLAGS_SET(f, MS_REMOUNT|MS_BIND))
47,737✔
732
                log_debug("Changing mount flags %s (%s \"%s\")...",
11,155✔
733
                          where, strnull(fl), strempty(o));
734
        else if (f & MS_REMOUNT)
42,159✔
735
                log_debug("Remounting superblock %s (%s \"%s\")...",
4✔
736
                          where, strnull(fl), strempty(o));
737
        else if (f & (MS_SHARED|MS_PRIVATE|MS_SLAVE|MS_UNBINDABLE))
42,155✔
738
                log_debug("Changing mount propagation %s (%s \"%s\")",
6,680✔
739
                          where, strnull(fl), strempty(o));
740
        else if (f & MS_BIND)
38,815✔
741
                log_debug("Bind-mounting %s on %s (%s \"%s\")...",
53,877✔
742
                          what, where, strnull(fl), strempty(o));
743
        else if (f & MS_MOVE)
11,864✔
744
                log_debug("Moving mount %s %s %s (%s \"%s\")...",
7,400✔
745
                          what, glyph(GLYPH_ARROW_RIGHT), where, strnull(fl), strempty(o));
746
        else
747
                log_debug("Mounting %s (%s) on %s (%s \"%s\")...",
9,511✔
748
                          strna(what), strna(type), where, strnull(fl), strempty(o));
749

750
        if (follow_symlink)
47,737✔
751
                r = RET_NERRNO(mount(what, where, type, f, o));
48,133✔
752
        else
753
                r = mount_nofollow(what, where, type, f, o);
42,545✔
754
        if (r < 0)
42,941✔
755
                return log_full_errno(error_log_level, r,
9,329✔
756
                                      "Failed to mount %s (type %s) on %s (%s \"%s\"): %m",
757
                                      strna(what), strna(type), where, strnull(fl), strempty(o));
758
        return 0;
759
}
760

761
int umount_verbose(
525✔
762
                int error_log_level,
763
                const char *where,
764
                int flags) {
765

766
        assert(where);
525✔
767

768
        log_debug("Unmounting '%s'...", where);
525✔
769

770
        if (umount2(where, flags) < 0)
525✔
771
                return log_full_errno(error_log_level, errno, "Failed to unmount '%s': %m", where);
89✔
772

773
        return 0;
774
}
775

776
int umountat_detach_verbose(
240✔
777
                int error_log_level,
778
                int fd,
779
                const char *where) {
780

781
        /* Similar to umountat_verbose(), but goes by fd + path. This implies MNT_DETACH, since to do this we
782
         * must pin the inode in question via an fd. */
783

784
        assert(fd >= 0 || fd == AT_FDCWD);
240✔
785

786
        /* If neither fd nor path are specified take this as reference to the cwd */
787
        if (fd == AT_FDCWD && isempty(where))
240✔
788
                return umount_verbose(error_log_level, ".", MNT_DETACH|UMOUNT_NOFOLLOW);
240✔
789

790
        /* If we don't actually take the fd into consideration for this operation shortcut things, so that we
791
         * don't have to open the inode */
792
        if (fd == AT_FDCWD || path_is_absolute(where))
240✔
793
                return umount_verbose(error_log_level, where, MNT_DETACH|UMOUNT_NOFOLLOW);
×
794

795
        _cleanup_free_ char *prefix = NULL;
480✔
796
        const char *p;
240✔
797
        if (fd_get_path(fd, &prefix) < 0)
240✔
798
                p = "<fd>"; /* if we can't get the path, return something vaguely useful */
799
        else
800
                p = prefix;
240✔
801
        _cleanup_free_ char *joined = isempty(where) ? strdup(p) : path_join(p, where);
615✔
802

803
        log_debug("Unmounting '%s'...", strna(joined));
240✔
804

805
        _cleanup_close_ int inode_fd = -EBADF;
240✔
806
        int mnt_fd;
240✔
807
        if (isempty(where))
240✔
808
                mnt_fd = fd;
809
        else {
810
                inode_fd = openat(fd, where, O_PATH|O_CLOEXEC|O_NOFOLLOW);
135✔
811
                if (inode_fd < 0)
135✔
812
                        return log_full_errno(error_log_level, errno, "Failed to pin '%s': %m", strna(joined));
×
813

814
                mnt_fd = inode_fd;
815
        }
816

817
        if (umount2(FORMAT_PROC_FD_PATH(mnt_fd), MNT_DETACH) < 0)
240✔
818
                return log_full_errno(error_log_level, errno, "Failed to unmount '%s': %m", strna(joined));
15✔
819

820
        return 0;
225✔
821
}
822

823
int mount_exchange_graceful(int fsmount_fd, const char *dest, bool mount_beneath) {
25✔
824
        int r;
25✔
825

826
        assert(fsmount_fd >= 0);
25✔
827
        assert(dest);
25✔
828

829
        /* First, try to mount beneath an existing mount point, and if that works, umount the old mount,
830
         * which is now at the top. This will ensure we can atomically replace a mount. Note that this works
831
         * also in the case where there are submounts down the tree. Mount propagation is allowed but
832
         * restricted to layouts that don't end up propagation the new mount on top of the mount stack.  If
833
         * this is not supported (minimum kernel v6.5), or if there is no mount on the mountpoint, we get
834
         * -EINVAL and then we fallback to normal mounting. */
835

836
        r = RET_NERRNO(move_mount(fsmount_fd, /* from_path = */ "",
35✔
837
                                  /* to_fd = */ -EBADF, dest,
838
                                  MOVE_MOUNT_F_EMPTY_PATH | (mount_beneath ? MOVE_MOUNT_BENEATH : 0)));
839
        if (mount_beneath) {
25✔
840
                if (r >= 0) /* Mounting beneath worked! Now unmount the upper mount. */
15✔
841
                        return umount_verbose(LOG_DEBUG, dest, UMOUNT_NOFOLLOW|MNT_DETACH);
11✔
842

843
                if (r == -EINVAL) { /* Fallback if mount_beneath is not supported */
4✔
844
                        log_debug_errno(r,
4✔
845
                                        "Cannot mount beneath '%s', falling back to overmount: %m",
846
                                        dest);
847
                        return mount_exchange_graceful(fsmount_fd, dest, /* mount_beneath = */ false);
4✔
848
                }
849
        }
850

851
        return r;
852
}
853

854
int mount_option_mangle(
47,809✔
855
                const char *options,
856
                unsigned long mount_flags,
857
                unsigned long *ret_mount_flags,
858
                char **ret_remaining_options) {
859

860
        const struct libmnt_optmap *map;
47,809✔
861
        _cleanup_free_ char *ret = NULL;
47,809✔
862
        int r;
47,809✔
863

864
        /* This extracts mount flags from the mount options, and stores
865
         * non-mount-flag options to '*ret_remaining_options'.
866
         * E.g.,
867
         * "rw,nosuid,nodev,relatime,size=1630748k,mode=0700,uid=1000,gid=1000"
868
         * is split to MS_NOSUID|MS_NODEV|MS_RELATIME and
869
         * "size=1630748k,mode=0700,uid=1000,gid=1000".
870
         * See more examples in test-mount-util.c.
871
         *
872
         * If 'options' does not contain any non-mount-flag options,
873
         * then '*ret_remaining_options' is set to NULL instead of empty string.
874
         * The validity of options stored in '*ret_remaining_options' is not checked.
875
         * If 'options' is NULL, this just copies 'mount_flags' to *ret_mount_flags. */
876

877
        assert(ret_mount_flags);
47,809✔
878
        assert(ret_remaining_options);
47,809✔
879

880
        r = dlopen_libmount();
47,809✔
881
        if (r < 0)
47,809✔
882
                return r;
883

884
        map = sym_mnt_get_builtin_optmap(MNT_LINUX_MAP);
47,809✔
885
        if (!map)
47,809✔
886
                return -EINVAL;
887

888
        for (const char *p = options;;) {
47,809✔
889
                _cleanup_free_ char *word = NULL;
23,774✔
890
                const struct libmnt_optmap *ent;
71,582✔
891

892
                r = extract_first_word(&p, &word, ",", EXTRACT_KEEP_QUOTE);
71,582✔
893
                if (r < 0)
71,582✔
894
                        return r;
895
                if (r == 0)
71,581✔
896
                        break;
897

898
                for (ent = map; ent->name; ent++) {
995,883✔
899
                        /* All entries in MNT_LINUX_MAP do not take any argument.
900
                         * Thus, ent->name does not contain "=" or "[=]". */
901
                        if (!streq(word, ent->name))
972,201✔
902
                                continue;
972,110✔
903

904
                        if (!(ent->mask & MNT_INVERT))
91✔
905
                                mount_flags |= ent->id;
82✔
906
                        else
907
                                mount_flags &= ~ent->id;
9✔
908

909
                        break;
910
                }
911

912
                /* If 'word' is not a mount flag, then store it in '*ret_remaining_options'. */
913
                if (!ent->name &&
47,455✔
914
                    !startswith_no_case(word, "x-") &&
47,362✔
915
                    !strextend_with_separator(&ret, ",", word))
23,680✔
916
                        return -ENOMEM;
917
        }
918

919
        *ret_mount_flags = mount_flags;
47,808✔
920
        *ret_remaining_options = TAKE_PTR(ret);
47,808✔
921

922
        return 0;
47,808✔
923
}
924

925
static int mount_in_namespace_legacy(
×
926
                const char *chased_src_path,
927
                int chased_src_fd,
928
                struct stat *chased_src_st,
929
                const char *propagate_path,
930
                const char *incoming_path,
931
                const char *dest,
932
                int pidns_fd,
933
                int mntns_fd,
934
                int root_fd,
935
                MountInNamespaceFlags flags,
936
                const MountOptions *options,
937
                const ImagePolicy *image_policy) {
938

939
        _cleanup_close_pair_ int errno_pipe_fd[2] = EBADF_PAIR;
×
940
        char mount_slave[] = "/tmp/propagate.XXXXXX", *mount_tmp, *mount_outside, *p;
×
941
        bool mount_slave_created = false, mount_slave_mounted = false,
×
942
                mount_tmp_created = false, mount_tmp_mounted = false,
×
943
                mount_outside_created = false, mount_outside_mounted = false;
×
944
        pid_t child;
×
945
        int r;
×
946

947
        assert(chased_src_path);
×
948
        assert(chased_src_fd >= 0);
×
949
        assert(chased_src_st);
×
950
        assert(propagate_path);
×
951
        assert(incoming_path);
×
952
        assert(dest);
×
953
        assert(pidns_fd >= 0);
×
954
        assert(mntns_fd >= 0);
×
955
        assert(root_fd >= 0);
×
956
        assert(!options || (flags & MOUNT_IN_NAMESPACE_IS_IMAGE));
×
957

958
        p = strjoina(propagate_path, "/");
×
959
        r = access_nofollow(p, F_OK);
×
960
        if (r < 0)
×
961
                return log_debug_errno(r == -ENOENT ? SYNTHETIC_ERRNO(EOPNOTSUPP) : r, "Target does not allow propagation of mount points");
×
962

963
        /* Our goal is to install a new bind mount into the container,
964
           possibly read-only. This is irritatingly complex
965
           unfortunately, currently.
966

967
           First, we start by creating a private playground in /tmp,
968
           that we can mount MS_SLAVE. (Which is necessary, since
969
           MS_MOVE cannot be applied to mounts with MS_SHARED parent
970
           mounts.) */
971

972
        if (!mkdtemp(mount_slave))
×
973
                return log_debug_errno(errno, "Failed to create playground %s: %m", mount_slave);
×
974

975
        mount_slave_created = true;
×
976

977
        r = mount_nofollow_verbose(LOG_DEBUG, mount_slave, mount_slave, NULL, MS_BIND, NULL);
×
978
        if (r < 0)
×
979
                goto finish;
×
980

981
        mount_slave_mounted = true;
×
982

983
        r = mount_nofollow_verbose(LOG_DEBUG, NULL, mount_slave, NULL, MS_SLAVE, NULL);
×
984
        if (r < 0)
×
985
                goto finish;
×
986

987
        /* Second, we mount the source file or directory to a directory inside of our MS_SLAVE playground. */
988
        mount_tmp = strjoina(mount_slave, "/mount");
×
989
        r = make_mount_point_inode_from_mode(AT_FDCWD, mount_tmp, (flags & MOUNT_IN_NAMESPACE_IS_IMAGE) ? S_IFDIR : chased_src_st->st_mode, 0700);
×
990
        if (r < 0) {
×
991
                log_debug_errno(r, "Failed to create temporary mount point %s: %m", mount_tmp);
×
992
                goto finish;
×
993
        }
994

995
        mount_tmp_created = true;
×
996

997
        if (flags & MOUNT_IN_NAMESPACE_IS_IMAGE)
×
998
                r = verity_dissect_and_mount(
×
999
                                chased_src_fd,
1000
                                chased_src_path,
1001
                                mount_tmp,
1002
                                options,
1003
                                image_policy,
1004
                                /* image_filter= */ NULL,
1005
                                /* extension_release_data= */ NULL,
1006
                                /* required_class= */ _IMAGE_CLASS_INVALID,
1007
                                /* verity= */ NULL,
1008
                                /* ret_image= */ NULL);
1009
        else
1010
                r = mount_follow_verbose(LOG_DEBUG, FORMAT_PROC_FD_PATH(chased_src_fd), mount_tmp, NULL, MS_BIND, NULL);
×
1011
        if (r < 0)
×
1012
                goto finish;
×
1013

1014
        mount_tmp_mounted = true;
×
1015

1016
        /* Third, we remount the new bind mount read-only if requested. */
1017
        if (flags & MOUNT_IN_NAMESPACE_READ_ONLY) {
×
1018
                r = mount_nofollow_verbose(LOG_DEBUG, NULL, mount_tmp, NULL, MS_BIND|MS_REMOUNT|MS_RDONLY, NULL);
×
1019
                if (r < 0)
×
1020
                        goto finish;
×
1021
        }
1022

1023
        /* Fourth, we move the new bind mount into the propagation directory. This way it will appear there read-only
1024
         * right-away. */
1025

1026
        mount_outside = strjoina(propagate_path, "/XXXXXX");
×
1027
        if ((flags & MOUNT_IN_NAMESPACE_IS_IMAGE) || S_ISDIR(chased_src_st->st_mode))
×
1028
                r = mkdtemp(mount_outside) ? 0 : -errno;
×
1029
        else {
1030
                r = mkostemp_safe(mount_outside);
×
1031
                safe_close(r);
×
1032
        }
1033
        if (r < 0) {
×
1034
                log_debug_errno(r, "Cannot create propagation file or directory %s: %m", mount_outside);
×
1035
                goto finish;
×
1036
        }
1037

1038
        mount_outside_created = true;
×
1039

1040
        r = mount_nofollow_verbose(LOG_DEBUG, mount_tmp, mount_outside, NULL, MS_MOVE, NULL);
×
1041
        if (r < 0)
×
1042
                goto finish;
×
1043

1044
        mount_outside_mounted = true;
×
1045
        mount_tmp_mounted = false;
×
1046

1047
        if ((flags & MOUNT_IN_NAMESPACE_IS_IMAGE) || S_ISDIR(chased_src_st->st_mode))
×
1048
                (void) rmdir(mount_tmp);
×
1049
        else
1050
                (void) unlink(mount_tmp);
×
1051
        mount_tmp_created = false;
×
1052

1053
        (void) umount_verbose(LOG_DEBUG, mount_slave, UMOUNT_NOFOLLOW);
×
1054
        mount_slave_mounted = false;
×
1055

1056
        (void) rmdir(mount_slave);
×
1057
        mount_slave_created = false;
×
1058

1059
        if (pipe2(errno_pipe_fd, O_CLOEXEC|O_NONBLOCK) < 0) {
×
1060
                log_debug_errno(errno, "Failed to create pipe: %m");
×
1061
                goto finish;
×
1062
        }
1063

1064
        r = namespace_fork(
×
1065
                        "(sd-bindmnt)",
1066
                        "(sd-bindmnt-inner)",
1067
                        /* except_fds= */ NULL,
1068
                        /* n_except_fds= */ 0,
1069
                        FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGTERM,
1070
                        pidns_fd,
1071
                        mntns_fd,
1072
                        /* netns_fd= */ -EBADF,
1073
                        /* userns_fd= */ -EBADF,
1074
                        root_fd,
1075
                        &child);
1076
        if (r < 0)
×
1077
                goto finish;
×
1078
        if (r == 0) {
×
1079
                _cleanup_free_ char *mount_outside_fn = NULL, *mount_inside = NULL;
×
1080

1081
                errno_pipe_fd[0] = safe_close(errno_pipe_fd[0]);
×
1082

1083
                _cleanup_close_ int dest_fd = -EBADF;
×
1084
                _cleanup_free_ char *dest_fn = NULL;
×
1085
                r = chase(dest, /* root= */ NULL, CHASE_PARENT|CHASE_EXTRACT_FILENAME|((flags & MOUNT_IN_NAMESPACE_MAKE_FILE_OR_DIRECTORY) ? CHASE_MKDIR_0755 : 0), &dest_fn, &dest_fd);
×
1086
                if (r < 0)
×
1087
                        log_debug_errno(r, "Failed to pin parent directory of mount '%s', ignoring: %m", dest);
×
1088
                else if (flags & MOUNT_IN_NAMESPACE_MAKE_FILE_OR_DIRECTORY) {
×
1089
                        r = make_mount_point_inode_from_mode(dest_fd, dest_fn, (flags & MOUNT_IN_NAMESPACE_IS_IMAGE) ? S_IFDIR : chased_src_st->st_mode, 0700);
×
1090
                        if (r < 0)
×
1091
                                log_debug_errno(r, "Failed to make mount point inode of mount '%s', ignoring: %m", dest);
×
1092
                }
1093

1094
                /* Fifth, move the mount to the right place inside */
1095
                r = path_extract_filename(mount_outside, &mount_outside_fn);
×
1096
                if (r < 0) {
×
1097
                        log_debug_errno(r, "Failed to extract filename from propagation file or directory '%s': %m", mount_outside);
×
1098
                        report_errno_and_exit(errno_pipe_fd[1], r);
×
1099
                }
1100

1101
                mount_inside = path_join(incoming_path, mount_outside_fn);
×
1102
                if (!mount_inside)
×
1103
                        report_errno_and_exit(errno_pipe_fd[1], log_oom_debug());
×
1104

1105
                r = mount_nofollow_verbose(LOG_DEBUG, mount_inside, dest_fd >= 0 ? FORMAT_PROC_FD_PATH(dest_fd) : dest, /* fstype= */ NULL, MS_MOVE, /* options= */ NULL);
×
1106
                if (r < 0)
×
1107
                        report_errno_and_exit(errno_pipe_fd[1], r);
×
1108

1109
                _exit(EXIT_SUCCESS);
×
1110
        }
1111

1112
        errno_pipe_fd[1] = safe_close(errno_pipe_fd[1]);
×
1113

1114
        r = wait_for_terminate_and_check("(sd-bindmnt)", child, 0);
×
1115
        if (r < 0) {
×
1116
                log_debug_errno(r, "Failed to wait for child: %m");
×
1117
                goto finish;
×
1118
        }
1119
        if (r != EXIT_SUCCESS) {
×
1120
                if (read(errno_pipe_fd[0], &r, sizeof(r)) == sizeof(r))
×
1121
                        log_debug_errno(r, "Failed to mount: %m");
×
1122
                else
1123
                        log_debug("Child failed.");
×
1124
                goto finish;
×
1125
        }
1126

1127
finish:
×
1128
        if (mount_outside_mounted)
×
1129
                (void) umount_verbose(LOG_DEBUG, mount_outside, UMOUNT_NOFOLLOW);
×
1130
        if (mount_outside_created) {
×
1131
                if ((flags & MOUNT_IN_NAMESPACE_IS_IMAGE) || S_ISDIR(chased_src_st->st_mode))
×
1132
                        (void) rmdir(mount_outside);
×
1133
                else
1134
                        (void) unlink(mount_outside);
×
1135
        }
1136

1137
        if (mount_tmp_mounted)
×
1138
                (void) umount_verbose(LOG_DEBUG, mount_tmp, UMOUNT_NOFOLLOW);
×
1139
        if (mount_tmp_created) {
×
1140
                if ((flags & MOUNT_IN_NAMESPACE_IS_IMAGE) || S_ISDIR(chased_src_st->st_mode))
×
1141
                        (void) rmdir(mount_tmp);
×
1142
                else
1143
                        (void) unlink(mount_tmp);
×
1144
        }
1145

1146
        if (mount_slave_mounted)
×
1147
                (void) umount_verbose(LOG_DEBUG, mount_slave, UMOUNT_NOFOLLOW);
×
1148
        if (mount_slave_created)
×
1149
                (void) rmdir(mount_slave);
×
1150

1151
        return r;
×
1152
}
1153

1154
static int mount_in_namespace(
6✔
1155
                const PidRef *target,
1156
                const char *propagate_path,
1157
                const char *incoming_path,
1158
                const char *src,
1159
                const char *dest,
1160
                MountInNamespaceFlags flags,
1161
                const MountOptions *options,
1162
                const ImagePolicy *image_policy) {
1163

1164
        _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF, pidns_fd = -EBADF, chased_src_fd = -EBADF;
18✔
1165
        _cleanup_free_ char *chased_src_path = NULL;
6✔
1166
        struct stat st;
6✔
1167
        int r;
6✔
1168

1169
        assert(propagate_path);
6✔
1170
        assert(incoming_path);
6✔
1171
        assert(src);
6✔
1172
        assert(dest);
6✔
1173
        assert((flags & MOUNT_IN_NAMESPACE_IS_IMAGE) || (!options && !image_policy));
6✔
1174

1175
        if (!pidref_is_set(target))
12✔
1176
                return -ESRCH;
1177

1178
        r = pidref_namespace_open(target, &pidns_fd, &mntns_fd, /* ret_netns_fd = */ NULL, /* ret_userns_fd = */ NULL, &root_fd);
6✔
1179
        if (r < 0)
6✔
1180
                return log_debug_errno(r, "Failed to retrieve FDs of the target process' namespace: %m");
×
1181

1182
        r = is_our_namespace(mntns_fd, NAMESPACE_MOUNT);
6✔
1183
        if (r < 0)
6✔
1184
                return log_debug_errno(r, "Failed to determine if mount namespaces are equal: %m");
×
1185
        /* We can't add new mounts at runtime if the process wasn't started in a namespace */
1186
        if (r > 0)
6✔
1187
                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to activate bind mount in target, not running in a mount namespace.");
×
1188

1189
        r = chase(src, NULL, 0, &chased_src_path, &chased_src_fd);
6✔
1190
        if (r < 0)
6✔
1191
                return log_debug_errno(r, "Failed to resolve source path '%s': %m", src);
×
1192
        log_debug("Chased source path '%s': %s", src, chased_src_path);
6✔
1193

1194
        if (fstat(chased_src_fd, &st) < 0)
6✔
1195
                return log_debug_errno(errno, "Failed to stat() resolved source path '%s': %m", src);
×
1196
        if (S_ISLNK(st.st_mode)) /* This shouldn't really happen, given that we just chased the symlinks above, but let's better be safe… */
6✔
1197
                return log_debug_errno(SYNTHETIC_ERRNO(ELOOP), "Source path '%s' can't be a symbolic link.", src);
×
1198

1199
        if (!mount_new_api_supported()) /* Fallback if we can't use the new mount API */
6✔
1200
                return mount_in_namespace_legacy(
×
1201
                                chased_src_path,
1202
                                chased_src_fd,
1203
                                &st,
1204
                                propagate_path,
1205
                                incoming_path,
1206
                                dest,
1207
                                pidns_fd,
1208
                                mntns_fd,
1209
                                root_fd,
1210
                                flags,
1211
                                options,
1212
                                image_policy);
1213

1214
        _cleanup_(dissected_image_unrefp) DissectedImage *img = NULL;
×
1215
        _cleanup_close_ int new_mount_fd = -EBADF;
6✔
1216
        _cleanup_close_pair_ int errno_pipe_fd[2] = EBADF_PAIR;
6✔
1217
        pid_t child;
6✔
1218

1219
        if (flags & MOUNT_IN_NAMESPACE_IS_IMAGE) {
6✔
1220
                r = verity_dissect_and_mount(
2✔
1221
                                chased_src_fd,
1222
                                chased_src_path,
1223
                                /* dest= */ NULL,
1224
                                options,
1225
                                image_policy,
1226
                                /* image_filter= */ NULL,
1227
                                /* extension_release_data= */ NULL,
1228
                                /* required_class= */ _IMAGE_CLASS_INVALID,
1229
                                /* verity= */ NULL,
1230
                                &img);
1231
                if (r < 0)
2✔
1232
                        return log_debug_errno(r,
×
1233
                                               "Failed to dissect and mount image '%s': %m",
1234
                                               chased_src_path);
1235
        } else {
1236
                new_mount_fd = open_tree(
4✔
1237
                                chased_src_fd,
1238
                                "",
1239
                                OPEN_TREE_CLONE|OPEN_TREE_CLOEXEC|AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH);
1240
                if (new_mount_fd < 0)
4✔
1241
                        return log_debug_errno(
×
1242
                                        errno,
1243
                                        "Failed to open mount source '%s': %m",
1244
                                        chased_src_path);
1245

1246
                if ((flags & MOUNT_IN_NAMESPACE_READ_ONLY) && mount_setattr(new_mount_fd, "", AT_EMPTY_PATH,
4✔
1247
                                               &(struct mount_attr) {
×
1248
                                                       .attr_set = MOUNT_ATTR_RDONLY,
1249
                                               }, MOUNT_ATTR_SIZE_VER0) < 0)
1250
                        return log_debug_errno(errno,
×
1251
                                               "Failed to set mount for '%s' to read only: %m",
1252
                                               chased_src_path);
1253
        }
1254

1255
        if (pipe2(errno_pipe_fd, O_CLOEXEC|O_NONBLOCK) < 0)
6✔
1256
                return log_debug_errno(errno, "Failed to create pipe: %m");
×
1257

1258
        r = namespace_fork("(sd-bindmnt)",
6✔
1259
                           "(sd-bindmnt-inner)",
1260
                           /* except_fds= */ NULL,
1261
                           /* n_except_fds= */ 0,
1262
                           FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGTERM,
1263
                           pidns_fd,
1264
                           mntns_fd,
1265
                           /* netns_fd= */ -EBADF,
1266
                           /* userns_fd= */ -EBADF,
1267
                           root_fd,
1268
                           &child);
1269
        if (r < 0)
12✔
1270
                return log_debug_errno(r, "Failed to fork off mount helper into namespace: %m");
×
1271
        if (r == 0) {
12✔
1272
                errno_pipe_fd[0] = safe_close(errno_pipe_fd[0]);
6✔
1273

1274
                _cleanup_close_ int dest_fd = -EBADF;
×
1275
                _cleanup_free_ char *dest_fn = NULL;
×
1276
                r = chase(dest, /* root= */ NULL, CHASE_PARENT|CHASE_EXTRACT_FILENAME|((flags & MOUNT_IN_NAMESPACE_MAKE_FILE_OR_DIRECTORY) ? CHASE_MKDIR_0755 : 0), &dest_fn, &dest_fd);
6✔
1277
                if (r < 0)
6✔
1278
                        report_errno_and_exit(errno_pipe_fd[1], r);
×
1279

1280
                if (flags & MOUNT_IN_NAMESPACE_MAKE_FILE_OR_DIRECTORY)
6✔
1281
                        (void) make_mount_point_inode_from_mode(dest_fd, dest_fn, img ? S_IFDIR : st.st_mode, 0700);
6✔
1282

1283
                if (img) {
6✔
1284
                        DissectImageFlags f =
2✔
1285
                                DISSECT_IMAGE_TRY_ATOMIC_MOUNT_EXCHANGE |
1286
                                DISSECT_IMAGE_ALLOW_USERSPACE_VERITY;
1287

1288
                        if (flags & MOUNT_IN_NAMESPACE_MAKE_FILE_OR_DIRECTORY)
2✔
1289
                                f |= DISSECT_IMAGE_MKDIR;
2✔
1290

1291
                        if (flags & MOUNT_IN_NAMESPACE_READ_ONLY)
2✔
1292
                                f |= DISSECT_IMAGE_READ_ONLY;
×
1293

1294
                        r = dissected_image_mount(
2✔
1295
                                        img,
1296
                                        dest,
1297
                                        /* uid_shift= */ UID_INVALID,
1298
                                        /* uid_range= */ UID_INVALID,
1299
                                        /* userns_fd= */ -EBADF,
1300
                                        f);
1301
                } else
1302
                        r = mount_exchange_graceful(new_mount_fd, dest, /* mount_beneath= */ true);
4✔
1303

1304
                report_errno_and_exit(errno_pipe_fd[1], r);
6✔
1305
        }
1306

1307
        errno_pipe_fd[1] = safe_close(errno_pipe_fd[1]);
6✔
1308

1309
        r = wait_for_terminate_and_check("(sd-bindmnt)", child, 0);
6✔
1310
        if (r < 0)
6✔
1311
                return log_debug_errno(r, "Failed to wait for child: %m");
×
1312
        if (r != EXIT_SUCCESS) {
6✔
1313
                if (read(errno_pipe_fd[0], &r, sizeof(r)) == sizeof(r))
×
1314
                        return log_debug_errno(r, "Failed to mount into namespace: %m");
×
1315

1316
                return log_debug_errno(SYNTHETIC_ERRNO(EPROTO), "Child failed.");
×
1317
        }
1318

1319
        return 0;
1320
}
1321

1322
int bind_mount_in_namespace(
4✔
1323
                const PidRef *target,
1324
                const char *propagate_path,
1325
                const char *incoming_path,
1326
                const char *src,
1327
                const char *dest,
1328
                MountInNamespaceFlags flags) {
1329

1330
        return mount_in_namespace(target,
8✔
1331
                                  propagate_path,
1332
                                  incoming_path,
1333
                                  src,
1334
                                  dest,
1335
                                  flags & ~MOUNT_IN_NAMESPACE_IS_IMAGE,
4✔
1336
                                  /* options = */ NULL,
1337
                                  /* image_policy = */ NULL);
1338
}
1339

1340
int mount_image_in_namespace(
2✔
1341
                const PidRef *target,
1342
                const char *propagate_path,
1343
                const char *incoming_path,
1344
                const char *src,
1345
                const char *dest,
1346
                MountInNamespaceFlags flags,
1347
                const MountOptions *options,
1348
                const ImagePolicy *image_policy) {
1349

1350
        return mount_in_namespace(target,
4✔
1351
                                  propagate_path,
1352
                                  incoming_path,
1353
                                  src,
1354
                                  dest,
1355
                                  flags | MOUNT_IN_NAMESPACE_IS_IMAGE,
2✔
1356
                                  options,
1357
                                  image_policy);
1358
}
1359

1360
int make_mount_point(const char *path) {
27✔
1361
        int r;
27✔
1362

1363
        assert(path);
27✔
1364

1365
        /* If 'path' is already a mount point, does nothing and returns 0. If it is not it makes it one, and returns 1. */
1366

1367
        r = path_is_mount_point(path);
27✔
1368
        if (r < 0)
27✔
1369
                return log_debug_errno(r, "Failed to determine whether '%s' is a mount point: %m", path);
×
1370
        if (r > 0)
27✔
1371
                return 0;
1372

1373
        r = mount_nofollow_verbose(LOG_DEBUG, path, path, NULL, MS_BIND|MS_REC, NULL);
11✔
1374
        if (r < 0)
11✔
1375
                return r;
×
1376

1377
        return 1;
1378
}
1379

1380
int fd_make_mount_point(int fd) {
13✔
1381
        int r;
13✔
1382

1383
        assert(fd >= 0);
13✔
1384

1385
        r = is_mount_point_at(fd, NULL, 0);
13✔
1386
        if (r < 0)
13✔
1387
                return log_debug_errno(r, "Failed to determine whether file descriptor is a mount point: %m");
×
1388
        if (r > 0)
13✔
1389
                return 0;
1390

1391
        r = mount_follow_verbose(LOG_DEBUG, FORMAT_PROC_FD_PATH(fd), FORMAT_PROC_FD_PATH(fd), NULL, MS_BIND|MS_REC, NULL);
1✔
1392
        if (r < 0)
1✔
1393
                return r;
×
1394

1395
        return 1;
1396
}
1397

1398
int make_userns(uid_t uid_shift,
130✔
1399
                uid_t uid_range,
1400
                uid_t source_owner,
1401
                uid_t dest_owner,
1402
                RemountIdmapping idmapping) {
1403

1404
        _cleanup_close_ int userns_fd = -EBADF;
130✔
1405
        _cleanup_free_ char *line = NULL;
130✔
1406
        uid_t source_base = 0;
130✔
1407

1408
        /* Allocates a userns file descriptor with the mapping we need. For this we'll fork off a child
1409
         * process whose only purpose is to give us a new user namespace. It's killed when we got it. */
1410

1411
        if (!userns_shift_range_valid(uid_shift, uid_range))
130✔
1412
                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid UID range for user namespace.");
×
1413

1414
        switch (idmapping) {
130✔
1415

1416
        case REMOUNT_IDMAPPING_FOREIGN_WITH_HOST_ROOT:
2✔
1417
                source_base = FOREIGN_UID_BASE;
2✔
1418
                _fallthrough_;
92✔
1419

1420
        case REMOUNT_IDMAPPING_NONE:
92✔
1421
        case REMOUNT_IDMAPPING_HOST_ROOT:
1422

1423
                if (asprintf(&line,
92✔
1424
                             UID_FMT " " UID_FMT " " UID_FMT "\n",
1425
                             source_base, uid_shift, uid_range) < 0)
1426
                        return log_oom_debug();
×
1427

1428
                /* If requested we'll include an entry in the mapping so that the host root user can make
1429
                 * changes to the uidmapped mount like it normally would. Specifically, we'll map the user
1430
                 * with UID_MAPPED_ROOT on the backing fs to UID 0. This is useful, since nspawn code wants
1431
                 * to create various missing inodes in the OS tree before booting into it, and this becomes
1432
                 * very easy and straightforward to do if it can just do it under its own regular UID. Note
1433
                 * that in that case the container's runtime uidmap (i.e. the one the container payload
1434
                 * processes run in) will leave this UID unmapped, i.e. if we accidentally leave files owned
1435
                 * by host root in the already uidmapped tree around they'll show up as owned by 'nobody',
1436
                 * which is safe. (Of course, we shouldn't leave such inodes around, but always chown() them
1437
                 * to the container's own UID range, but it's good to have a safety net, in case we
1438
                 * forget it.) */
1439
                if (idmapping == REMOUNT_IDMAPPING_HOST_ROOT)
92✔
1440
                        if (strextendf(&line,
90✔
1441
                                       UID_FMT " " UID_FMT " " UID_FMT "\n",
1442
                                       UID_MAPPED_ROOT, (uid_t) 0u, (uid_t) 1u) < 0)
1443
                                return log_oom_debug();
×
1444

1445
                break;
1446

1447
        case REMOUNT_IDMAPPING_HOST_OWNER:
6✔
1448
                /* Remap the owner of the bind mounted directory to the root user within the container. This
1449
                 * way every file written by root within the container to the bind-mounted directory will
1450
                 * be owned by the original user from the host. All other users will remain unmapped. */
1451
                if (asprintf(&line,
6✔
1452
                             UID_FMT " " UID_FMT " " UID_FMT "\n",
1453
                             source_owner, uid_shift, (uid_t) 1u) < 0)
1454
                        return log_oom_debug();
×
1455
                break;
1456

1457
        case REMOUNT_IDMAPPING_HOST_OWNER_TO_TARGET_OWNER:
32✔
1458
                /* Remap the owner of the bind mounted directory to the owner of the target directory
1459
                 * within the container. This way every file written by target directory owner within the
1460
                 * container to the bind-mounted directory will be owned by the original host user.
1461
                 * All other users will remain unmapped. */
1462
                if (asprintf(&line,
32✔
1463
                             UID_FMT " " UID_FMT " " UID_FMT "\n",
1464
                             source_owner, dest_owner, (uid_t) 1u) < 0)
1465
                        return log_oom_debug();
×
1466
                break;
1467

1468
        default:
×
1469
                assert_not_reached();
×
1470
        }
1471

1472
        /* We always assign the same UID and GID ranges */
1473
        userns_fd = userns_acquire(line, line, /* setgroups_deny= */ true);
130✔
1474
        if (userns_fd < 0)
130✔
1475
                return log_debug_errno(userns_fd, "Failed to acquire new userns: %m");
×
1476

1477
        return TAKE_FD(userns_fd);
1478
}
1479

1480
int open_tree_attr_with_fallback(int dir_fd, const char *path, unsigned int flags, struct mount_attr *attr) {
431✔
1481
        _cleanup_close_ int fd = -EBADF;
431✔
1482

1483
        assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
431✔
1484
        assert(attr);
431✔
1485

1486
        if (isempty(path)) {
431✔
1487
                path = "";
×
1488
                flags |= AT_EMPTY_PATH;
×
1489
        }
1490

1491
        fd = open_tree_attr(dir_fd, path, flags, attr, sizeof(struct mount_attr));
431✔
1492
        if (fd >= 0)
431✔
1493
                return TAKE_FD(fd);
431✔
1494
        if (!ERRNO_IS_NOT_SUPPORTED(errno))
15✔
1495
                return log_debug_errno(errno, "Failed to open tree and set mount attributes: %m");
2✔
1496

1497
        if (attr->attr_clr & MOUNT_ATTR_IDMAP)
13✔
1498
                return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Cannot clear idmap from mount without open_tree_attr()");
×
1499

1500
        fd = open_tree(dir_fd, path, flags);
13✔
1501
        if (fd < 0)
13✔
1502
                return log_debug_errno(errno, "Failed to open tree: %m");
×
1503

1504
        if (mount_setattr(fd, "", AT_EMPTY_PATH | (flags & AT_RECURSIVE), attr, sizeof(struct mount_attr)) < 0)
13✔
1505
                return log_debug_errno(errno, "Failed to change mount attributes: %m");
×
1506

1507
        return TAKE_FD(fd);
1508
}
1509

1510
int remount_idmap_fd(
141✔
1511
                char **paths,
1512
                int userns_fd,
1513
                uint64_t extra_mount_attr_set) {
1514

1515
        int r;
141✔
1516

1517
        assert(userns_fd >= 0);
141✔
1518

1519
        /* This remounts all specified paths with the specified userns as idmap. It will do so in the
1520
         * order specified in the strv: the expectation is that the top-level directories are at the
1521
         * beginning, and nested directories in the right, so that the tree can be built correctly from left
1522
         * to right. */
1523

1524
        size_t n = strv_length(paths);
141✔
1525
        if (n == 0) /* Nothing to do? */
141✔
1526
                return 0;
141✔
1527

1528
        int *mount_fds = NULL;
141✔
1529
        size_t n_mounts_fds = 0;
141✔
1530

1531
        mount_fds = new(int, n);
141✔
1532
        if (!mount_fds)
141✔
1533
                return log_oom_debug();
×
1534

1535
        CLEANUP_ARRAY(mount_fds, n_mounts_fds, close_many_and_free);
141✔
1536

1537
        for (size_t i = 0; i < n; i++) {
280✔
1538
                /* Clone the mount point and et the user namespace mapping attribute on the cloned mount point. */
1539
                mount_fds[n_mounts_fds] = open_tree_attr_with_fallback(
282✔
1540
                                AT_FDCWD,
1541
                                paths[i],
141✔
1542
                                OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC,
1543
                                &(struct mount_attr) {
141✔
1544
                                          .attr_set = MOUNT_ATTR_IDMAP | extra_mount_attr_set,
141✔
1545
                                          .userns_fd = userns_fd,
1546
                                });
1547
                if (mount_fds[n_mounts_fds] < 0)
141✔
1548
                        return mount_fds[n_mounts_fds];
2✔
1549

1550
                n_mounts_fds++;
139✔
1551
        }
1552

1553
        for (size_t i = n; i > 0; i--) { /* Unmount the paths right-to-left */
278✔
1554
                /* Remove the old mount points now that we have a idmapped mounts as replacement for all of them */
1555
                r = umount_verbose(LOG_DEBUG, paths[i-1], UMOUNT_NOFOLLOW);
139✔
1556
                if (r < 0)
139✔
1557
                        return r;
1558
        }
1559

1560
        for (size_t i = 0; i < n; i++) { /* Mount the replacement mounts left-to-right */
278✔
1561
                /* And place the cloned version in its place */
1562
                log_debug("Mounting idmapped fs to '%s'", paths[i]);
139✔
1563
                if (move_mount(mount_fds[i], "", -EBADF, paths[i], MOVE_MOUNT_F_EMPTY_PATH) < 0)
139✔
1564
                        return log_debug_errno(errno, "Failed to attach UID mapped mount to '%s': %m", paths[i]);
×
1565
        }
1566

1567
        return 0;
1568
}
1569

1570
int remount_idmap(
128✔
1571
                char **p,
1572
                uid_t uid_shift,
1573
                uid_t uid_range,
1574
                uid_t source_owner,
1575
                uid_t dest_owner,
1576
                RemountIdmapping idmapping) {
1577

1578
        _cleanup_close_ int userns_fd = -EBADF;
128✔
1579

1580
        userns_fd = make_userns(uid_shift, uid_range, source_owner, dest_owner, idmapping);
128✔
1581
        if (userns_fd < 0)
128✔
1582
                return userns_fd;
1583

1584
        return remount_idmap_fd(p, userns_fd, /* extra_mount_attr_set= */ 0);
128✔
1585
}
1586

1587
static void sub_mount_clear(SubMount *s) {
5,562✔
1588
        assert(s);
5,562✔
1589

1590
        s->path = mfree(s->path);
5,562✔
1591
        s->mount_fd = safe_close(s->mount_fd);
5,562✔
1592
}
5,562✔
1593

1594
void sub_mount_array_free(SubMount *s, size_t n) {
1,192✔
1595
        assert(s || n == 0);
1,192✔
1596

1597
        for (size_t i = 0; i < n; i++)
5,955✔
1598
                sub_mount_clear(s + i);
4,763✔
1599

1600
        free(s);
1,192✔
1601
}
1,192✔
1602

1603
static int sub_mount_compare(const SubMount *a, const SubMount *b) {
7,130✔
1604
        assert(a);
7,130✔
1605
        assert(b);
7,130✔
1606
        assert(a->path);
7,130✔
1607
        assert(b->path);
7,130✔
1608

1609
        return path_compare(a->path, b->path);
7,130✔
1610
}
1611

1612
static void sub_mount_drop(SubMount *s, size_t n) {
1,770✔
1613
        assert(s || n == 0);
1,770✔
1614

1615
        for (size_t m = 0, i = 1; i < n; i++) {
5,341✔
1616
                if (path_startswith(s[i].path, s[m].path))
3,571✔
1617
                        sub_mount_clear(s + i);
799✔
1618
                else
1619
                        m = i;
1620
        }
1621
}
1,770✔
1622

1623
int get_sub_mounts(const char *prefix, SubMount **ret_mounts, size_t *ret_n_mounts) {
1,770✔
1624

1625
        _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
1,770✔
1626
        _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
1,770✔
1627
        SubMount *mounts = NULL;
1,770✔
1628
        size_t n = 0;
1,770✔
1629
        int r;
1,770✔
1630

1631
        CLEANUP_ARRAY(mounts, n, sub_mount_array_free);
1,770✔
1632

1633
        assert(prefix);
1,770✔
1634
        assert(ret_mounts);
1,770✔
1635
        assert(ret_n_mounts);
1,770✔
1636

1637
        r = libmount_parse_mountinfo(/* source = */ NULL, &table, &iter);
1,770✔
1638
        if (r < 0)
1,770✔
1639
                return log_debug_errno(r, "Failed to parse /proc/self/mountinfo: %m");
×
1640

1641
        for (;;) {
90,954✔
1642
                _cleanup_close_ int mount_fd = -EBADF;
89,184✔
1643
                _cleanup_free_ char *p = NULL;
90,954✔
1644
                struct libmnt_fs *fs;
90,954✔
1645
                const char *path;
90,954✔
1646
                int id1, id2;
90,954✔
1647

1648
                r = sym_mnt_table_next_fs(table, iter, &fs);
90,954✔
1649
                if (r == 1)
90,954✔
1650
                        break; /* EOF */
1651
                if (r < 0)
89,184✔
1652
                        return log_debug_errno(r, "Failed to get next entry from /proc/self/mountinfo: %m");
×
1653

1654
                path = sym_mnt_fs_get_target(fs);
89,184✔
1655
                if (!path)
89,184✔
1656
                        continue;
×
1657

1658
                if (isempty(path_startswith(path, prefix)))
89,184✔
1659
                        continue;
83,627✔
1660

1661
                id1 = sym_mnt_fs_get_id(fs);
5,557✔
1662
                r = path_get_mnt_id(path, &id2);
5,557✔
1663
                if (r < 0) {
5,557✔
1664
                        log_debug_errno(r, "Failed to get mount ID of '%s', ignoring: %m", path);
×
1665
                        continue;
×
1666
                }
1667
                if (id1 != id2) {
5,557✔
1668
                        /* The path may be hidden by another over-mount or already remounted. */
1669
                        log_debug("The mount IDs of '%s' obtained by libmount and path_get_mnt_id() are different (%i vs %i), ignoring.",
794✔
1670
                                  path, id1, id2);
1671
                        continue;
794✔
1672
                }
1673

1674
                mount_fd = open(path, O_CLOEXEC|O_PATH);
4,763✔
1675
                if (mount_fd < 0) {
4,763✔
1676
                        if (errno == ENOENT) /* The path may be hidden by another over-mount or already unmounted. */
×
1677
                                continue;
×
1678

1679
                        return log_debug_errno(errno, "Failed to open subtree of mounted filesystem '%s': %m", path);
×
1680
                }
1681

1682
                p = strdup(path);
4,763✔
1683
                if (!p)
4,763✔
1684
                        return log_oom_debug();
×
1685

1686
                if (!GREEDY_REALLOC(mounts, n + 1))
4,763✔
1687
                        return log_oom_debug();
×
1688

1689
                mounts[n++] = (SubMount) {
4,763✔
1690
                        .path = TAKE_PTR(p),
4,763✔
1691
                        .mount_fd = TAKE_FD(mount_fd),
4,763✔
1692
                };
1693
        }
1694

1695
        typesafe_qsort(mounts, n, sub_mount_compare);
1,770✔
1696
        sub_mount_drop(mounts, n);
1,770✔
1697

1698
        *ret_mounts = TAKE_PTR(mounts);
1,770✔
1699
        *ret_n_mounts = n;
1,770✔
1700
        return 0;
1,770✔
1701
}
1702

1703
int bind_mount_submounts(
1,200✔
1704
                const char *source,
1705
                const char *target) {
1706

1707
        SubMount *mounts = NULL;
1,200✔
1708
        size_t n = 0;
1,200✔
1709
        int ret = 0, r;
1,200✔
1710

1711
        /* Bind mounts all child mounts of 'source' to 'target'. Useful when setting up a new procfs instance
1712
         * with new mount options to copy the original submounts over. */
1713

1714
        assert(source);
1,200✔
1715
        assert(target);
1,200✔
1716

1717
        CLEANUP_ARRAY(mounts, n, sub_mount_array_free);
1,200✔
1718

1719
        r = get_sub_mounts(source, &mounts, &n);
1,200✔
1720
        if (r < 0)
1,200✔
1721
                return r;
1722

1723
        FOREACH_ARRAY(m, mounts, n) {
5,959✔
1724
                _cleanup_free_ char *t = NULL;
4,759✔
1725
                const char *suffix;
4,759✔
1726

1727
                if (isempty(m->path))
4,759✔
1728
                        continue;
799✔
1729

1730
                assert_se(suffix = path_startswith(m->path, source));
3,960✔
1731

1732
                t = path_join(target, suffix);
3,960✔
1733
                if (!t)
3,960✔
1734
                        return -ENOMEM;
×
1735

1736
                r = path_is_mount_point(t);
3,960✔
1737
                if (r < 0) {
3,960✔
1738
                        log_debug_errno(r, "Failed to detect if '%s' already is a mount point, ignoring: %m", t);
11✔
1739
                        continue;
11✔
1740
                }
1741
                if (r > 0) {
3,949✔
1742
                        log_debug("Not bind mounting '%s' from '%s' to '%s', since there's already a mountpoint.", suffix, source, target);
×
1743
                        continue;
×
1744
                }
1745

1746
                r = mount_follow_verbose(LOG_DEBUG, FORMAT_PROC_FD_PATH(m->mount_fd), t, NULL, MS_BIND|MS_REC, NULL);
3,949✔
1747
                if (r < 0 && ret == 0)
3,949✔
1748
                        ret = r;
396✔
1749
        }
1750

1751
        return ret;
1752
}
1753

1754
int make_mount_point_inode_from_mode(int dir_fd, const char *dest, mode_t source_mode, mode_t target_mode) {
1,039✔
1755
        assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
1,039✔
1756
        assert(dest);
1,039✔
1757

1758
        if (S_ISDIR(source_mode))
1,039✔
1759
                return mkdirat_label(dir_fd, dest, target_mode & 07777);
1,012✔
1760
        else
1761
                return RET_NERRNO(mknodat(dir_fd, dest, S_IFREG|(target_mode & 07666), 0)); /* Mask off X bit */
28✔
1762
}
1763

1764
int make_mount_point_inode_from_path(const char *source, const char *dest, mode_t access_mode) {
867✔
1765
        struct stat st;
867✔
1766

1767
        assert(source);
867✔
1768
        assert(dest);
867✔
1769

1770
        if (stat(source, &st) < 0)
867✔
1771
                return -errno;
×
1772

1773
        return make_mount_point_inode_from_mode(AT_FDCWD, dest, st.st_mode, access_mode);
867✔
1774
}
1775

1776
int trigger_automount_at(int dir_fd, const char *path) {
424✔
1777
        _cleanup_free_ char *nested = NULL;
848✔
1778

1779
        assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
424✔
1780

1781
        nested = path_join(path, "a");
424✔
1782
        if (!nested)
424✔
1783
                return -ENOMEM;
1784

1785
        (void) faccessat(dir_fd, nested, F_OK, 0);
424✔
1786

1787
        return 0;
424✔
1788
}
1789

1790
unsigned long credentials_fs_mount_flags(bool ro) {
4,074✔
1791
        /* A tight set of mount flags for credentials mounts */
1792
        return MS_NODEV|MS_NOEXEC|MS_NOSUID|ms_nosymfollow_supported()|(ro ? MS_RDONLY : 0);
4,074✔
1793
}
1794

1795
int mount_credentials_fs(const char *path, size_t size, bool ro) {
2,037✔
1796
        _cleanup_free_ char *opts = NULL;
2,037✔
1797
        int r, noswap_supported;
2,037✔
1798

1799
        /* Mounts a file system we can place credentials in, i.e. with tight access modes right from the
1800
         * beginning, and ideally swapping turned off. In order of preference:
1801
         *
1802
         *      1. tmpfs if it supports "noswap"
1803
         *      2. ramfs
1804
         *      3. tmpfs if it doesn't support "noswap"
1805
         */
1806

1807
        noswap_supported = mount_option_supported("tmpfs", "noswap", NULL); /* Check explicitly to avoid kmsg noise */
2,037✔
1808
        if (noswap_supported > 0) {
2,037✔
1809
                _cleanup_free_ char *noswap_opts = NULL;
2,036✔
1810

1811
                if (asprintf(&noswap_opts, "mode=0700,nr_inodes=1024,size=%zu,noswap", size) < 0)
2,036✔
1812
                        return -ENOMEM;
1813

1814
                /* Best case: tmpfs with noswap (needs kernel >= 6.3) */
1815

1816
                r = mount_nofollow_verbose(
2,036✔
1817
                                LOG_DEBUG,
1818
                                "tmpfs",
1819
                                path,
1820
                                "tmpfs",
1821
                                credentials_fs_mount_flags(ro),
1822
                                noswap_opts);
1823
                if (r >= 0)
2,036✔
1824
                        return r;
1825
        }
1826

1827
        r = mount_nofollow_verbose(
1✔
1828
                        LOG_DEBUG,
1829
                        "ramfs",
1830
                        path,
1831
                        "ramfs",
1832
                        credentials_fs_mount_flags(ro),
1833
                        "mode=0700");
1834
        if (r >= 0)
1✔
1835
                return r;
1836

1837
        if (asprintf(&opts, "mode=0700,nr_inodes=1024,size=%zu", size) < 0)
1✔
1838
                return -ENOMEM;
1839

1840
        return mount_nofollow_verbose(
2,037✔
1841
                        LOG_DEBUG,
1842
                        "tmpfs",
1843
                        path,
1844
                        "tmpfs",
1845
                        credentials_fs_mount_flags(ro),
1846
                        opts);
1847
}
1848

1849
int make_fsmount(
2✔
1850
                int error_log_level,
1851
                const char *what,
1852
                const char *type,
1853
                unsigned long flags,
1854
                const char *options,
1855
                int userns_fd) {
1856

1857
        _cleanup_close_ int fs_fd = -EBADF, mnt_fd = -EBADF;
2✔
1858
        _cleanup_free_ char *o = NULL;
2✔
1859
        unsigned long f;
2✔
1860
        int r;
2✔
1861

1862
        assert(type);
2✔
1863
        assert(what);
2✔
1864

1865
        r = mount_option_mangle(options, flags, &f, &o);
2✔
1866
        if (r < 0)
2✔
1867
                return log_full_errno(
×
1868
                                error_log_level, r, "Failed to mangle mount options %s: %m",
1869
                                strempty(options));
1870

1871
        if (DEBUG_LOGGING) {
2✔
1872
                _cleanup_free_ char *fl = NULL;
2✔
1873
                (void) mount_flags_to_string(f, &fl);
2✔
1874

1875
                log_debug("Creating mount fd for %s (%s) (%s \"%s\")...",
4✔
1876
                        strna(what), strna(type), strnull(fl), strempty(o));
1877
        }
1878

1879
        fs_fd = fsopen(type, FSOPEN_CLOEXEC);
2✔
1880
        if (fs_fd < 0)
2✔
1881
                return log_full_errno(error_log_level, errno, "Failed to open superblock for \"%s\": %m", type);
×
1882

1883
        if (fsconfig(fs_fd, FSCONFIG_SET_STRING, "source", what, 0) < 0)
2✔
1884
                return log_full_errno(error_log_level, errno, "Failed to set mount source for \"%s\" to \"%s\": %m", type, what);
×
1885

1886
        if (FLAGS_SET(f, MS_RDONLY))
2✔
1887
                if (fsconfig(fs_fd, FSCONFIG_SET_FLAG, "ro", NULL, 0) < 0)
2✔
1888
                        return log_full_errno(error_log_level, errno, "Failed to set read only mount flag for \"%s\": %m", type);
×
1889

1890
        for (const char *p = o;;) {
2✔
1891
                _cleanup_free_ char *word = NULL;
×
1892
                char *eq;
2✔
1893

1894
                r = extract_first_word(&p, &word, ",", EXTRACT_KEEP_QUOTE);
2✔
1895
                if (r < 0)
2✔
1896
                        return log_full_errno(error_log_level, r, "Failed to parse mount option string \"%s\": %m", o);
×
1897
                if (r == 0)
2✔
1898
                        break;
1899

1900
                eq = strchr(word, '=');
×
1901
                if (eq) {
×
1902
                        *eq = 0;
×
1903
                        eq++;
×
1904

1905
                        if (fsconfig(fs_fd, FSCONFIG_SET_STRING, word, eq, 0) < 0)
×
1906
                                return log_full_errno(error_log_level, errno, "Failed to set mount option \"%s=%s\" for \"%s\": %m", word, eq, type);
×
1907
                } else {
1908
                        if (fsconfig(fs_fd, FSCONFIG_SET_FLAG, word, NULL, 0) < 0)
×
1909
                                return log_full_errno(error_log_level, errno, "Failed to set mount flag \"%s\" for \"%s\": %m", word, type);
×
1910
                }
1911
        }
1912

1913
        if (fsconfig(fs_fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0)
2✔
1914
                return log_full_errno(error_log_level, errno, "Failed to realize fs fd for \"%s\" (\"%s\"): %m", what, type);
×
1915

1916
        mnt_fd = fsmount(fs_fd, FSMOUNT_CLOEXEC, 0);
2✔
1917
        if (mnt_fd < 0)
2✔
1918
                return log_full_errno(error_log_level, errno, "Failed to create mount fd for \"%s\" (\"%s\"): %m", what, type);
×
1919

1920
        struct mount_attr ma = {
4✔
1921
                .attr_clr = ms_flags_to_mount_attr_clr(f),
2✔
1922
                .attr_set = ms_flags_to_mount_attr(f) | (userns_fd >= 0 ? MOUNT_ATTR_IDMAP : 0),
2✔
1923
                .userns_fd = userns_fd,
1924
        };
1925
        if (ma.attr_set != 0 && mount_setattr(mnt_fd, "", AT_EMPTY_PATH|AT_RECURSIVE, &ma, MOUNT_ATTR_SIZE_VER0) < 0)
2✔
1926
                return log_full_errno(error_log_level,
×
1927
                                      errno,
1928
                                      "Failed to set mount flags for \"%s\" (\"%s\"): %m",
1929
                                      what,
1930
                                      type);
1931

1932
        return TAKE_FD(mnt_fd);
1933
}
1934

1935
char* umount_and_rmdir_and_free(char *p) {
158✔
1936
        if (!p)
158✔
1937
                return NULL;
158✔
1938

1939
        PROTECT_ERRNO;
×
1940
        (void) umount_recursive(p, 0);
158✔
1941
        (void) rmdir(p);
158✔
1942
        return mfree(p);
158✔
1943
}
1944

1945
char* umount_and_free(char *p) {
39✔
1946
        if (!p)
39✔
1947
                return NULL;
39✔
1948

1949
        PROTECT_ERRNO;
×
1950
        (void) umount_recursive(p, 0);
39✔
1951
        return mfree(p);
39✔
1952
}
1953

1954
char* umount_and_unlink_and_free(char *p) {
1✔
1955
        if (!p)
1✔
1956
                return NULL;
1✔
1957

1958
        PROTECT_ERRNO;
2✔
1959
        (void) umount2(p, 0);
1✔
1960
        (void) unlink(p);
1✔
1961
        return mfree(p);
1✔
1962
}
1963

1964
int path_get_mount_info_at(
781✔
1965
                int dir_fd,
1966
                const char *path,
1967
                char **ret_fstype,
1968
                char **ret_options,
1969
                char **ret_source) {
1970

1971
        _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
781✔
1972
        _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
781✔
1973
        int r, mnt_id;
781✔
1974

1975
        assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
781✔
1976

1977
        r = path_get_mnt_id_at(dir_fd, path, &mnt_id);
781✔
1978
        if (r < 0)
781✔
1979
                return log_debug_errno(r, "Failed to get mount ID: %m");
×
1980

1981
        /* When getting options is requested, we also need to parse utab, otherwise userspace options like
1982
         * "_netdev" will be lost. */
1983
        if (ret_options)
781✔
1984
                r = libmount_parse_with_utab(&table, &iter);
771✔
1985
        else
1986
                r = libmount_parse_mountinfo(/* source = */ NULL, &table, &iter);
10✔
1987
        if (r < 0)
781✔
1988
                return log_debug_errno(r, "Failed to parse /proc/self/mountinfo: %m");
×
1989

1990
        for (;;) {
4,977✔
1991
                struct libmnt_fs *fs;
2,879✔
1992

1993
                r = sym_mnt_table_next_fs(table, iter, &fs);
2,879✔
1994
                if (r == 1)
2,879✔
1995
                        break; /* EOF */
1996
                if (r < 0)
2,879✔
1997
                        return log_debug_errno(r, "Failed to get next entry from /proc/self/mountinfo: %m");
781✔
1998

1999
                if (sym_mnt_fs_get_id(fs) != mnt_id)
2,879✔
2000
                        continue;
2,098✔
2001

2002
                _cleanup_free_ char *fstype = NULL, *options = NULL, *source = NULL;
781✔
2003

2004
                if (ret_fstype) {
781✔
2005
                        fstype = strdup(strempty(sym_mnt_fs_get_fstype(fs)));
771✔
2006
                        if (!fstype)
771✔
2007
                                return log_oom_debug();
×
2008
                }
2009

2010
                if (ret_options) {
781✔
2011
                        options = strdup(strempty(sym_mnt_fs_get_options(fs)));
771✔
2012
                        if (!options)
771✔
2013
                                return log_oom_debug();
×
2014
                }
2015

2016
                if (ret_source) {
781✔
2017
                        source = strdup(strempty(sym_mnt_fs_get_source(fs)));
10✔
2018
                        if (!source)
10✔
2019
                                return log_oom_debug();
×
2020
                }
2021

2022
                if (ret_fstype)
781✔
2023
                        *ret_fstype = TAKE_PTR(fstype);
771✔
2024
                if (ret_options)
781✔
2025
                        *ret_options = TAKE_PTR(options);
771✔
2026
                if (ret_source)
781✔
2027
                        *ret_source = TAKE_PTR(source);
10✔
2028

2029
                return 0;
2030
        }
2031

2032
        return log_debug_errno(SYNTHETIC_ERRNO(ESTALE), "Cannot find mount ID %i from /proc/self/mountinfo.", mnt_id);
×
2033
}
2034

2035
int path_is_network_fs_harder_at(int dir_fd, const char *path) {
801✔
2036
        _cleanup_close_ int fd = -EBADF;
801✔
2037
        int r;
801✔
2038

2039
        assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
801✔
2040

2041
        fd = xopenat(dir_fd, path, O_PATH | O_CLOEXEC | O_NOFOLLOW);
801✔
2042
        if (fd < 0)
801✔
2043
                return fd;
2044

2045
        r = fd_is_network_fs(fd);
771✔
2046
        if (r != 0)
771✔
2047
                return r;
2048

2049
        _cleanup_free_ char *fstype = NULL, *options = NULL;
771✔
2050
        r = path_get_mount_info_at(fd, /* path = */ NULL, &fstype, &options, /* ret_source = */ NULL);
771✔
2051
        if (r < 0)
771✔
2052
                return r;
2053

2054
        if (fstype_is_network(fstype))
771✔
2055
                return true;
2056

2057
        if (fstab_test_option(options, "_netdev\0"))
771✔
2058
                return true;
×
2059

2060
        return false;
2061
}
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