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

systemd / systemd / 18958539692

30 Oct 2025 09:15PM UTC coverage: 72.046% (-0.2%) from 72.245%
18958539692

push

github

web-flow
importd: port export-tar code to use the one systemd-dissect already uses (#39405)

Split out of #38728.

(Testcase is part of that PR)

92 of 135 new or added lines in 5 files covered. (68.15%)

4530 existing lines in 57 files now uncovered.

304067 of 422048 relevant lines covered (72.05%)

1172093.27 hits per line

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

71.01
/src/core/execute-serialize.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <unistd.h>
4

5
#include "af-list.h"
6
#include "capability-util.h"
7
#include "cgroup.h"
8
#include "dissect-image.h"
9
#include "dynamic-user.h"
10
#include "escape.h"
11
#include "exec-credential.h"
12
#include "execute.h"
13
#include "execute-serialize.h"
14
#include "extract-word.h"
15
#include "fd-util.h"
16
#include "hexdecoct.h"
17
#include "image-policy.h"
18
#include "in-addr-prefix-util.h"
19
#include "log.h"
20
#include "nsflags.h"
21
#include "open-file.h"
22
#include "ordered-set.h"
23
#include "parse-helpers.h"
24
#include "parse-util.h"
25
#include "path-util.h"
26
#include "process-util.h"
27
#include "rlimit-util.h"
28
#include "serialize.h"
29
#include "set.h"
30
#include "string-util.h"
31
#include "strv.h"
32
#include "time-util.h"
33

34
static int exec_cgroup_context_serialize(const CGroupContext *c, FILE *f) {
2,115✔
35
        _cleanup_free_ char *disable_controllers_str = NULL, *delegate_controllers_str = NULL,
×
36
                            *cpuset_cpus = NULL, *cpuset_mems = NULL, *startup_cpuset_cpus = NULL,
×
37
                            *startup_cpuset_mems = NULL;
2,115✔
38
        char *iface;
2,115✔
39
        struct in_addr_prefix *iaai;
2,115✔
40
        int r;
2,115✔
41

42
        assert(f);
2,115✔
43

44
        if (!c)
2,115✔
45
                return 0;
46

47
        r = serialize_bool_elide(f, "exec-cgroup-context-io-accounting", c->io_accounting);
2,115✔
48
        if (r < 0)
2,115✔
49
                return r;
50

51
        r = serialize_bool_elide(f, "exec-cgroup-context-memory-accounting", c->memory_accounting);
2,115✔
52
        if (r < 0)
2,115✔
53
                return r;
54

55
        r = serialize_bool_elide(f, "exec-cgroup-context-tasks-accounting", c->tasks_accounting);
2,115✔
56
        if (r < 0)
2,115✔
57
                return r;
58

59
        r = serialize_bool_elide(f, "exec-cgroup-context-ip-accounting", c->ip_accounting);
2,115✔
60
        if (r < 0)
2,115✔
61
                return r;
62

63
        r = serialize_bool_elide(f, "exec-cgroup-context-memory-oom-group", c->memory_oom_group);
2,115✔
64
        if (r < 0)
2,115✔
65
                return r;
66

67
        if (c->cpu_weight != CGROUP_WEIGHT_INVALID) {
2,115✔
68
                r = serialize_item_format(f, "exec-cgroup-context-cpu-weight", "%" PRIu64, c->cpu_weight);
×
69
                if (r < 0)
×
70
                        return r;
71
        }
72

73
        if (c->startup_cpu_weight != CGROUP_WEIGHT_INVALID) {
2,115✔
74
                r = serialize_item_format(f, "exec-cgroup-context-startup-cpu-weight", "%" PRIu64, c->startup_cpu_weight);
×
75
                if (r < 0)
×
76
                        return r;
77
        }
78

79
        if (c->cpu_quota_per_sec_usec != USEC_INFINITY) {
2,115✔
80
                r = serialize_usec(f, "exec-cgroup-context-cpu-quota-per-sec-usec", c->cpu_quota_per_sec_usec);
×
81
                if (r < 0)
×
82
                        return r;
83
        }
84

85
        if (c->cpu_quota_period_usec != USEC_INFINITY) {
2,115✔
86
                r = serialize_usec(f, "exec-cgroup-context-cpu-quota-period-usec", c->cpu_quota_period_usec);
×
87
                if (r < 0)
×
88
                        return r;
89
        }
90

91
        cpuset_cpus = cpu_set_to_range_string(&c->cpuset_cpus);
2,115✔
92
        if (!cpuset_cpus)
2,115✔
93
                return log_oom_debug();
×
94

95
        r = serialize_item(f, "exec-cgroup-context-allowed-cpus", cpuset_cpus);
2,115✔
96
        if (r < 0)
2,115✔
97
                return r;
98

99
        startup_cpuset_cpus = cpu_set_to_range_string(&c->startup_cpuset_cpus);
2,115✔
100
        if (!startup_cpuset_cpus)
2,115✔
101
                return log_oom_debug();
×
102

103
        r = serialize_item(f, "exec-cgroup-context-startup-allowed-cpus", startup_cpuset_cpus);
2,115✔
104
        if (r < 0)
2,115✔
105
                return r;
106

107
        cpuset_mems = cpu_set_to_range_string(&c->cpuset_mems);
2,115✔
108
        if (!cpuset_mems)
2,115✔
109
                return log_oom_debug();
×
110

111
        r = serialize_item(f, "exec-cgroup-context-allowed-memory-nodes", cpuset_mems);
2,115✔
112
        if (r < 0)
2,115✔
113
                return r;
114

115
        startup_cpuset_mems = cpu_set_to_range_string(&c->startup_cpuset_mems);
2,115✔
116
        if (!startup_cpuset_mems)
2,115✔
117
                return log_oom_debug();
×
118

119
        r = serialize_item(f, "exec-cgroup-context-startup-allowed-memory-nodes", startup_cpuset_mems);
2,115✔
120
        if (r < 0)
2,115✔
121
                return r;
122

123
        if (c->io_weight != CGROUP_WEIGHT_INVALID) {
2,115✔
124
                r = serialize_item_format(f, "exec-cgroup-context-io-weight", "%" PRIu64, c->io_weight);
×
125
                if (r < 0)
×
126
                        return r;
127
        }
128

129
        if (c->startup_io_weight != CGROUP_WEIGHT_INVALID) {
2,115✔
130
                r = serialize_item_format(f, "exec-cgroup-context-startup-io-weight", "%" PRIu64, c->startup_io_weight);
×
131
                if (r < 0)
×
132
                        return r;
133
        }
134

135
        if (c->default_memory_min > 0) {
2,115✔
136
                r = serialize_item_format(f, "exec-cgroup-context-default-memory-min", "%" PRIu64, c->default_memory_min);
×
137
                if (r < 0)
×
138
                        return r;
139
        }
140

141
        if (c->default_memory_low > 0) {
2,115✔
142
                r = serialize_item_format(f, "exec-cgroup-context-default-memory-low", "%" PRIu64, c->default_memory_low);
×
143
                if (r < 0)
×
144
                        return r;
145
        }
146

147
        if (c->memory_min > 0) {
2,115✔
148
                r = serialize_item_format(f, "exec-cgroup-context-memory-min", "%" PRIu64, c->memory_min);
×
149
                if (r < 0)
×
150
                        return r;
151
        }
152

153
        if (c->memory_low > 0) {
2,115✔
154
                r = serialize_item_format(f, "exec-cgroup-context-memory-low", "%" PRIu64, c->memory_low);
×
155
                if (r < 0)
×
156
                        return r;
157
        }
158

159
        if (c->startup_memory_low > 0) {
2,115✔
160
                r = serialize_item_format(f, "exec-cgroup-context-startup-memory-low", "%" PRIu64, c->startup_memory_low);
×
161
                if (r < 0)
×
162
                        return r;
163
        }
164

165
        if (c->memory_high != CGROUP_LIMIT_MAX) {
2,115✔
166
                r = serialize_item_format(f, "exec-cgroup-context-memory-high", "%" PRIu64, c->memory_high);
2✔
167
                if (r < 0)
2✔
168
                        return r;
169
        }
170

171
        if (c->startup_memory_high != CGROUP_LIMIT_MAX) {
2,115✔
172
                r = serialize_item_format(f, "exec-cgroup-context-startup-memory-high", "%" PRIu64, c->startup_memory_high);
×
173
                if (r < 0)
×
174
                        return r;
175
        }
176

177
        if (c->memory_max != CGROUP_LIMIT_MAX) {
2,115✔
178
                r = serialize_item_format(f, "exec-cgroup-context-memory-max", "%" PRIu64, c->memory_max);
×
179
                if (r < 0)
×
180
                        return r;
181
        }
182

183
        if (c->startup_memory_max != CGROUP_LIMIT_MAX) {
2,115✔
184
                r = serialize_item_format(f, "exec-cgroup-context-startup-memory-max", "%" PRIu64, c->startup_memory_max);
×
185
                if (r < 0)
×
186
                        return r;
187
        }
188

189
        if (c->memory_swap_max != CGROUP_LIMIT_MAX) {
2,115✔
190
                r = serialize_item_format(f, "exec-cgroup-context-memory-swap-max", "%" PRIu64, c->memory_swap_max);
×
191
                if (r < 0)
×
192
                        return r;
193
        }
194

195
        if (c->startup_memory_swap_max != CGROUP_LIMIT_MAX) {
2,115✔
196
                r = serialize_item_format(f, "exec-cgroup-context-startup-memory-swap-max", "%" PRIu64, c->startup_memory_swap_max);
×
197
                if (r < 0)
×
198
                        return r;
199
        }
200

201
        if (c->memory_zswap_max != CGROUP_LIMIT_MAX) {
2,115✔
202
                r = serialize_item_format(f, "exec-cgroup-context-memory-zswap-max", "%" PRIu64, c->memory_zswap_max);
×
203
                if (r < 0)
×
204
                        return r;
205
        }
206

207
        if (c->startup_memory_zswap_max != CGROUP_LIMIT_MAX) {
2,115✔
208
                r = serialize_item_format(f, "exec-cgroup-context-startup-memory-zswap-max", "%" PRIu64, c->startup_memory_zswap_max);
×
209
                if (r < 0)
×
210
                        return r;
211
        }
212

213
        r = serialize_bool(f, "exec-cgroup-context-memory-zswap-writeback", c->memory_zswap_writeback);
2,115✔
214
        if (r < 0)
2,115✔
215
                return r;
216

217
        if (c->tasks_max.value != UINT64_MAX) {
2,115✔
218
                r = serialize_item_format(f, "exec-cgroup-context-tasks-max-value", "%" PRIu64, c->tasks_max.value);
2,066✔
219
                if (r < 0)
2,066✔
220
                        return r;
221
        }
222

223
        if (c->tasks_max.scale > 0) {
2,115✔
224
                r = serialize_item_format(f, "exec-cgroup-context-tasks-max-scale", "%" PRIu64, c->tasks_max.scale);
2,064✔
225
                if (r < 0)
2,064✔
226
                        return r;
227
        }
228

229
        r = serialize_bool_elide(f, "exec-cgroup-context-default-memory-min-set", c->default_memory_min_set);
2,115✔
230
        if (r < 0)
2,115✔
231
                return r;
232

233
        r = serialize_bool_elide(f, "exec-cgroup-context-default-memory-low-set", c->default_memory_low_set);
2,115✔
234
        if (r < 0)
2,115✔
235
                return r;
236

237
        r = serialize_bool_elide(f, "exec-cgroup-context-default-startup-memory-low-set", c->default_startup_memory_low_set);
2,115✔
238
        if (r < 0)
2,115✔
239
                return r;
240

241
        r = serialize_bool_elide(f, "exec-cgroup-context-memory-min-set", c->memory_min_set);
2,115✔
242
        if (r < 0)
2,115✔
243
                return r;
244

245
        r = serialize_bool_elide(f, "exec-cgroup-context-memory-low-set", c->memory_low_set);
2,115✔
246
        if (r < 0)
2,115✔
247
                return r;
248

249
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-low-set", c->startup_memory_low_set);
2,115✔
250
        if (r < 0)
2,115✔
251
                return r;
252

253
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-high-set", c->startup_memory_high_set);
2,115✔
254
        if (r < 0)
2,115✔
255
                return r;
256

257
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-max-set", c->startup_memory_max_set);
2,115✔
258
        if (r < 0)
2,115✔
259
                return r;
260

261
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-swap-max-set", c->startup_memory_swap_max_set);
2,115✔
262
        if (r < 0)
2,115✔
263
                return r;
264

265
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-zswap-max-set", c->startup_memory_zswap_max_set);
2,115✔
266
        if (r < 0)
2,115✔
267
                return r;
268

269
        r = serialize_item(f, "exec-cgroup-context-device-policy", cgroup_device_policy_to_string(c->device_policy));
2,115✔
270
        if (r < 0)
2,115✔
271
                return r;
272

273
        r = cg_mask_to_string(c->disable_controllers, &disable_controllers_str);
2,115✔
274
        if (r < 0)
2,115✔
275
                return r;
276

277
        r = serialize_item(f, "exec-cgroup-context-disable-controllers", disable_controllers_str);
2,115✔
278
        if (r < 0)
2,115✔
279
                return r;
280

281
        r = cg_mask_to_string(c->delegate_controllers, &delegate_controllers_str);
2,115✔
282
        if (r < 0)
2,115✔
283
                return r;
284

285
        r = serialize_item(f, "exec-cgroup-context-delegate-controllers", delegate_controllers_str);
2,115✔
286
        if (r < 0)
2,115✔
287
                return r;
288

289
        r = serialize_bool_elide(f, "exec-cgroup-context-delegate", c->delegate);
2,115✔
290
        if (r < 0)
2,115✔
291
                return r;
292

293
        r = serialize_item(f, "exec-cgroup-context-managed-oom-swap", managed_oom_mode_to_string(c->moom_swap));
2,115✔
294
        if (r < 0)
2,115✔
295
                return r;
296

297
        r = serialize_item(f, "exec-cgroup-context-managed-oom-memory-pressure", managed_oom_mode_to_string(c->moom_mem_pressure));
2,115✔
298
        if (r < 0)
2,115✔
299
                return r;
300

301
        r = serialize_item_format(f, "exec-cgroup-context-managed-oom-memory-pressure-limit", "%" PRIu32, c->moom_mem_pressure_limit);
2,115✔
302
        if (r < 0)
2,115✔
303
                return r;
304

305
        r = serialize_usec(f, "exec-cgroup-context-managed-oom-memory-pressure-duration-usec", c->moom_mem_pressure_duration_usec);
2,115✔
306
        if (r < 0)
2,115✔
307
                return r;
308

309
        r = serialize_item(f, "exec-cgroup-context-managed-oom-preference", managed_oom_preference_to_string(c->moom_preference));
2,115✔
310
        if (r < 0)
2,115✔
311
                return r;
312

313
        r = serialize_item(f, "exec-cgroup-context-memory-pressure-watch", cgroup_pressure_watch_to_string(c->memory_pressure_watch));
2,115✔
314
        if (r < 0)
2,115✔
315
                return r;
316

317
        r = serialize_item(f, "exec-cgroup-context-delegate-subgroup", c->delegate_subgroup);
2,115✔
318
        if (r < 0)
2,115✔
319
                return r;
320

321
        if (c->memory_pressure_threshold_usec != USEC_INFINITY) {
2,115✔
322
                r = serialize_usec(f, "exec-cgroup-context-memory-pressure-threshold-usec", c->memory_pressure_threshold_usec);
2,115✔
323
                if (r < 0)
2,115✔
324
                        return r;
325
        }
326

327
        LIST_FOREACH(device_allow, a, c->device_allow) {
2,633✔
328
                r = serialize_item_format(f, "exec-cgroup-context-device-allow", "%s %s",
518✔
329
                                          a->path,
330
                                          cgroup_device_permissions_to_string(a->permissions));
331
                if (r < 0)
518✔
332
                        return r;
333
        }
334

335
        LIST_FOREACH(device_weights, iw, c->io_device_weights) {
2,115✔
336
                r = serialize_item_format(f, "exec-cgroup-context-io-device-weight", "%s %" PRIu64,
×
337
                                          iw->path,
338
                                          iw->weight);
339
                if (r < 0)
×
340
                        return r;
341
        }
342

343
        LIST_FOREACH(device_latencies, l, c->io_device_latencies) {
2,115✔
344
                r = serialize_item_format(f, "exec-cgroup-context-io-device-latency-target-usec", "%s " USEC_FMT,
×
345
                                          l->path,
346
                                          l->target_usec);
347
                if (r < 0)
×
348
                        return r;
349
        }
350

351
        LIST_FOREACH(device_limits, il, c->io_device_limits)
2,115✔
352
                for (CGroupIOLimitType type = 0; type < _CGROUP_IO_LIMIT_TYPE_MAX; type++) {
×
353
                        _cleanup_free_ char *key = NULL;
×
354

355
                        if (il->limits[type] == cgroup_io_limit_defaults[type])
×
356
                                continue;
×
357

358
                        key = strjoin("exec-cgroup-context-io-device-limit-", cgroup_io_limit_type_to_string(type));
×
359
                        if (!key)
×
360
                                return -ENOMEM;
361

362
                        r = serialize_item_format(f, key, "%s %" PRIu64, il->path, il->limits[type]);
×
363
                        if (r < 0)
×
364
                                return r;
365
                }
366

367
        SET_FOREACH(iaai, c->ip_address_allow) {
2,115✔
368
                r = serialize_item(f,
×
369
                                   "exec-cgroup-context-ip-address-allow",
370
                                   IN_ADDR_PREFIX_TO_STRING(iaai->family, &iaai->address, iaai->prefixlen));
×
371
                if (r < 0)
×
372
                        return r;
×
373
        }
374
        SET_FOREACH(iaai, c->ip_address_deny) {
2,367✔
375
                r = serialize_item(f,
252✔
376
                                   "exec-cgroup-context-ip-address-deny",
377
                                   IN_ADDR_PREFIX_TO_STRING(iaai->family, &iaai->address, iaai->prefixlen));
252✔
378
                if (r < 0)
252✔
379
                        return r;
×
380
        }
381

382
        r = serialize_bool_elide(f, "exec-cgroup-context-ip-address-allow-reduced", c->ip_address_allow_reduced);
2,115✔
383
        if (r < 0)
2,115✔
384
                return r;
385

386
        r = serialize_bool_elide(f, "exec-cgroup-context-ip-address-deny-reduced", c->ip_address_deny_reduced);
2,115✔
387
        if (r < 0)
2,115✔
388
                return r;
389

390
        r = serialize_strv(f, "exec-cgroup-context-ip-ingress-filter-path", c->ip_filters_ingress);
2,115✔
391
        if (r < 0)
2,115✔
392
                return r;
393

394
        r = serialize_strv(f, "exec-cgroup-context-ip-egress-filter-path", c->ip_filters_egress);
2,115✔
395
        if (r < 0)
2,115✔
396
                return r;
397

398
        LIST_FOREACH(programs, p, c->bpf_foreign_programs) {
2,115✔
399
                r = serialize_item_format(f, "exec-cgroup-context-bpf-program", "%" PRIu32 " %s",
×
400
                                          p->attach_type,
401
                                          p->bpffs_path);
402
                if (r < 0)
×
403
                        return r;
404
        }
405

406
        LIST_FOREACH(socket_bind_items, bi, c->socket_bind_allow) {
2,115✔
407
                fprintf(f, "exec-cgroup-context-socket-bind-allow=");
×
408
                cgroup_context_dump_socket_bind_item(bi, f);
×
409
                fputc('\n', f);
×
410
        }
411

412
        LIST_FOREACH(socket_bind_items, bi, c->socket_bind_deny) {
2,115✔
413
                fprintf(f, "exec-cgroup-context-socket-bind-deny=");
×
414
                cgroup_context_dump_socket_bind_item(bi, f);
×
415
                fputc('\n', f);
×
416
        }
417

418
        SET_FOREACH(iface, c->restrict_network_interfaces) {
2,115✔
419
                r = serialize_item(f, "exec-cgroup-context-restrict-network-interfaces", iface);
×
420
                if (r < 0)
×
421
                        return r;
×
422
        }
423

424
        r = serialize_bool_elide(
4,230✔
425
                        f,
426
                        "exec-cgroup-context-restrict-network-interfaces-is-allow-list",
427
                        c->restrict_network_interfaces_is_allow_list);
2,115✔
428
        if (r < 0)
2,115✔
429
                return r;
430

431
        fputc('\n', f); /* End marker */
2,115✔
432

433
        return 0;
434
}
435

436
static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) {
11,867✔
437
        int r;
11,867✔
438

439
        assert(f);
11,867✔
440

441
        if (!c)
11,867✔
442
                return 0;
443

444
        for (;;) {
444,749✔
445
                _cleanup_free_ char *l = NULL;
216,441✔
446
                const char *val;
228,308✔
447

448
                r = deserialize_read_line(f, &l);
228,308✔
449
                if (r < 0)
228,308✔
450
                        return r;
451
                if (r == 0) /* eof or end marker */
228,308✔
452
                        break;
453

454
                if ((val = startswith(l, "exec-cgroup-context-io-accounting="))) {
216,441✔
455
                        r = parse_boolean(val);
2✔
456
                        if (r < 0)
2✔
457
                                return r;
458
                        c->io_accounting = r;
2✔
459
                } else if ((val = startswith(l, "exec-cgroup-context-memory-accounting="))) {
216,439✔
460
                        r = parse_boolean(val);
11,548✔
461
                        if (r < 0)
11,548✔
462
                                return r;
463
                        c->memory_accounting = r;
11,548✔
464
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-accounting="))) {
204,891✔
465
                        r = parse_boolean(val);
11,867✔
466
                        if (r < 0)
11,867✔
467
                                return r;
468
                        c->tasks_accounting = r;
11,867✔
469
                } else if ((val = startswith(l, "exec-cgroup-context-ip-accounting="))) {
193,024✔
470
                        r = parse_boolean(val);
×
471
                        if (r < 0)
×
472
                                return r;
473
                        c->ip_accounting = r;
×
474
                } else if ((val = startswith(l, "exec-cgroup-context-memory-oom-group="))) {
193,024✔
475
                        r = parse_boolean(val);
2✔
476
                        if (r < 0)
2✔
477
                                return r;
478
                        c->memory_oom_group = r;
2✔
479
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-weight="))) {
193,022✔
480
                        r = safe_atou64(val, &c->cpu_weight);
1✔
481
                        if (r < 0)
1✔
482
                                return r;
483
                } else if ((val = startswith(l, "exec-cgroup-context-startup-cpu-weight="))) {
193,021✔
484
                        r = safe_atou64(val, &c->startup_cpu_weight);
×
485
                        if (r < 0)
×
486
                                return r;
487
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-quota-per-sec-usec="))) {
193,021✔
488
                        r = deserialize_usec(val, &c->cpu_quota_per_sec_usec);
×
489
                        if (r < 0)
×
490
                                return r;
491
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-quota-period-usec="))) {
193,021✔
492
                        r = deserialize_usec(val, &c->cpu_quota_period_usec);
×
493
                        if (r < 0)
×
494
                                return r;
495
                } else if ((val = startswith(l, "exec-cgroup-context-allowed-cpus="))) {
193,021✔
496
                        if (c->cpuset_cpus.set)
11,867✔
497
                                return -EINVAL; /* duplicated */
498

499
                        r = parse_cpu_set(val, &c->cpuset_cpus);
11,867✔
500
                        if (r < 0)
11,867✔
501
                                return r;
502
                } else if ((val = startswith(l, "exec-cgroup-context-startup-allowed-cpus="))) {
181,154✔
503
                        if (c->startup_cpuset_cpus.set)
11,867✔
504
                                return -EINVAL; /* duplicated */
505

506
                        r = parse_cpu_set(val, &c->startup_cpuset_cpus);
11,867✔
507
                        if (r < 0)
11,867✔
508
                                return r;
509
                } else if ((val = startswith(l, "exec-cgroup-context-allowed-memory-nodes="))) {
169,287✔
510
                        if (c->cpuset_mems.set)
11,867✔
511
                                return -EINVAL; /* duplicated */
512

513
                        r = parse_cpu_set(val, &c->cpuset_mems);
11,867✔
514
                        if (r < 0)
11,867✔
515
                                return r;
516
                } else if ((val = startswith(l, "exec-cgroup-context-startup-allowed-memory-nodes="))) {
157,420✔
517
                        if (c->startup_cpuset_mems.set)
11,867✔
518
                                return -EINVAL; /* duplicated */
519

520
                        r = parse_cpu_set(val, &c->startup_cpuset_mems);
11,867✔
521
                        if (r < 0)
11,867✔
522
                                return r;
523
                } else if ((val = startswith(l, "exec-cgroup-context-io-weight="))) {
145,553✔
524
                        r = safe_atou64(val, &c->io_weight);
×
525
                        if (r < 0)
×
526
                                return r;
527
                } else if ((val = startswith(l, "exec-cgroup-context-startup-io-weight="))) {
145,553✔
528
                        r = safe_atou64(val, &c->startup_io_weight);
×
529
                        if (r < 0)
×
530
                                return r;
531
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-min="))) {
145,553✔
532
                        r = safe_atou64(val, &c->default_memory_min);
×
533
                        if (r < 0)
×
534
                                return r;
535
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-low="))) {
145,553✔
536
                        r = safe_atou64(val, &c->default_memory_low);
×
537
                        if (r < 0)
×
538
                                return r;
539
                } else if ((val = startswith(l, "exec-cgroup-context-memory-min="))) {
145,553✔
540
                        r = safe_atou64(val, &c->memory_min);
1✔
541
                        if (r < 0)
1✔
542
                                return r;
543
                } else if ((val = startswith(l, "exec-cgroup-context-memory-low="))) {
145,552✔
544
                        r = safe_atou64(val, &c->memory_low);
1✔
545
                        if (r < 0)
1✔
546
                                return r;
547
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-low="))) {
145,551✔
548
                        r = safe_atou64(val, &c->startup_memory_low);
×
549
                        if (r < 0)
×
550
                                return r;
551
                } else if ((val = startswith(l, "exec-cgroup-context-memory-high="))) {
145,551✔
552
                        r = safe_atou64(val, &c->memory_high);
10✔
553
                        if (r < 0)
10✔
554
                                return r;
555
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-high="))) {
145,541✔
556
                        r = safe_atou64(val, &c->startup_memory_high);
×
557
                        if (r < 0)
×
558
                                return r;
559
                } else if ((val = startswith(l, "exec-cgroup-context-memory-max="))) {
145,541✔
560
                        r = safe_atou64(val, &c->memory_max);
2✔
561
                        if (r < 0)
2✔
562
                                return r;
563
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-max="))) {
145,539✔
564
                        r = safe_atou64(val, &c->startup_memory_max);
×
565
                        if (r < 0)
×
566
                                return r;
567
                } else if ((val = startswith(l, "exec-cgroup-context-memory-swap-max="))) {
145,539✔
568
                        r = safe_atou64(val, &c->memory_swap_max);
1✔
569
                        if (r < 0)
1✔
570
                                return r;
571
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-swap-max="))) {
145,538✔
572
                        r = safe_atou64(val, &c->startup_memory_swap_max);
×
573
                        if (r < 0)
×
574
                                return r;
575
                } else if ((val = startswith(l, "exec-cgroup-context-memory-zswap-max="))) {
145,538✔
576
                        r = safe_atou64(val, &c->memory_zswap_max);
1✔
577
                        if (r < 0)
1✔
578
                                return r;
579
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-zswap-max="))) {
145,537✔
580
                        r = safe_atou64(val, &c->startup_memory_zswap_max);
×
581
                        if (r < 0)
×
582
                                return r;
583
                } else if ((val = startswith(l, "exec-cgroup-context-memory-zswap-writeback="))) {
145,537✔
584
                        r = parse_boolean(val);
11,867✔
585
                        if (r < 0)
11,867✔
586
                                return r;
587
                        c->memory_zswap_writeback = r;
11,867✔
588
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-max-value="))) {
133,670✔
589
                        r = safe_atou64(val, &c->tasks_max.value);
11,570✔
590
                        if (r < 0)
11,570✔
591
                                return r;
592
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-max-scale="))) {
122,100✔
593
                        r = safe_atou64(val, &c->tasks_max.scale);
11,530✔
594
                        if (r < 0)
11,530✔
595
                                return r;
596
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-min-set="))) {
110,570✔
597
                        r = parse_boolean(val);
×
598
                        if (r < 0)
×
599
                                return r;
600
                        c->default_memory_min_set = r;
×
601
                } else if ((val = startswith(l, "exec-cgroup-context-default-memory-low-set="))) {
110,570✔
602
                        r = parse_boolean(val);
×
603
                        if (r < 0)
×
604
                                return r;
605
                        c->default_memory_low_set = r;
×
606
                } else if ((val = startswith(l, "exec-cgroup-context-default-startup-memory-low-set="))) {
110,570✔
607
                        r = parse_boolean(val);
×
608
                        if (r < 0)
×
609
                                return r;
610
                        c->default_startup_memory_low_set = r;
×
611
                } else if ((val = startswith(l, "exec-cgroup-context-memory-min-set="))) {
110,570✔
612
                        r = parse_boolean(val);
1✔
613
                        if (r < 0)
1✔
614
                                return r;
615
                        c->memory_min_set = r;
1✔
616
                } else if ((val = startswith(l, "exec-cgroup-context-memory-low-set="))) {
110,569✔
617
                        r = parse_boolean(val);
1✔
618
                        if (r < 0)
1✔
619
                                return r;
620
                        c->memory_low_set = r;
1✔
621
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-low-set="))) {
110,568✔
622
                        r = parse_boolean(val);
×
623
                        if (r < 0)
×
624
                                return r;
625
                        c->startup_memory_low_set = r;
×
626
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-high-set="))) {
110,568✔
627
                        r = parse_boolean(val);
×
628
                        if (r < 0)
×
629
                                return r;
630
                        c->startup_memory_high_set = r;
×
631
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-max-set="))) {
110,568✔
632
                        r = parse_boolean(val);
×
633
                        if (r < 0)
×
634
                                return r;
635
                        c->startup_memory_max_set = r;
×
636
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-swap-max-set="))) {
110,568✔
637
                        r = parse_boolean(val);
×
638
                        if (r < 0)
×
639
                                return r;
640
                        c->startup_memory_swap_max_set = r;
×
641
                } else if ((val = startswith(l, "exec-cgroup-context-startup-memory-zswap-max-set="))) {
110,568✔
642
                        r = parse_boolean(val);
×
643
                        if (r < 0)
×
644
                                return r;
645
                        c->startup_memory_zswap_max_set = r;
×
646
                } else if ((val = startswith(l, "exec-cgroup-context-device-policy="))) {
110,568✔
647
                        c->device_policy = cgroup_device_policy_from_string(val);
11,867✔
648
                        if (c->device_policy < 0)
11,867✔
649
                                return -EINVAL;
650
                } else if ((val = startswith(l, "exec-cgroup-context-disable-controllers="))) {
98,701✔
651
                        r = cg_mask_from_string(val, &c->disable_controllers);
×
652
                        if (r < 0)
×
653
                                return r;
654
                } else if ((val = startswith(l, "exec-cgroup-context-delegate-controllers="))) {
98,701✔
655
                        r = cg_mask_from_string(val, &c->delegate_controllers);
577✔
656
                        if (r < 0)
577✔
657
                                return r;
658
                } else if ((val = startswith(l, "exec-cgroup-context-delegate="))) {
98,124✔
659
                        r = parse_boolean(val);
690✔
660
                        if (r < 0)
690✔
661
                                return r;
662
                        c->delegate = r;
690✔
663
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-swap="))) {
97,434✔
664
                        c->moom_swap = managed_oom_mode_from_string(val);
11,867✔
665
                        if (c->moom_swap < 0)
11,867✔
666
                                return -EINVAL;
667
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure="))) {
85,567✔
668
                        c->moom_mem_pressure = managed_oom_mode_from_string(val);
11,867✔
669
                        if (c->moom_mem_pressure < 0)
11,867✔
670
                                return -EINVAL;
671
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure-limit="))) {
73,700✔
672
                        r = safe_atou32(val, &c->moom_mem_pressure_limit);
11,867✔
673
                        if (r < 0)
11,867✔
674
                                return r;
675
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-preference="))) {
61,833✔
676
                        c->moom_preference = managed_oom_preference_from_string(val);
11,867✔
677
                        if (c->moom_preference < 0)
11,867✔
678
                                return -EINVAL;
679
                } else if ((val = startswith(l, "exec-cgroup-context-managed-oom-memory-pressure-duration-usec="))) {
49,966✔
680
                        r = deserialize_usec(val, &c->moom_mem_pressure_duration_usec);
1✔
681
                        if (r < 0)
1✔
682
                                return r;
683
                } else if ((val = startswith(l, "exec-cgroup-context-memory-pressure-watch="))) {
49,965✔
684
                        c->memory_pressure_watch = cgroup_pressure_watch_from_string(val);
11,867✔
685
                        if (c->memory_pressure_watch < 0)
11,867✔
686
                                return -EINVAL;
687
                } else if ((val = startswith(l, "exec-cgroup-context-delegate-subgroup="))) {
38,098✔
688
                        r = free_and_strdup(&c->delegate_subgroup, val);
346✔
689
                        if (r < 0)
346✔
690
                                return r;
691
                } else if ((val = startswith(l, "exec-cgroup-context-memory-pressure-threshold-usec="))) {
37,752✔
692
                        r = deserialize_usec(val, &c->memory_pressure_threshold_usec);
11,867✔
693
                        if (r < 0)
11,867✔
694
                                return r;
695
                } else if ((val = startswith(l, "exec-cgroup-context-device-allow="))) {
25,885✔
696
                        _cleanup_free_ char *path = NULL, *rwm = NULL;
4,635✔
697
                        CGroupDevicePermissions p;
4,635✔
698

699
                        r = extract_many_words(&val, " ", 0, &path, &rwm);
4,635✔
700
                        if (r < 0)
4,635✔
701
                                return r;
702
                        if (r == 0)
4,635✔
703
                                return -EINVAL;
704

705
                        p = isempty(rwm) ? 0 : cgroup_device_permissions_from_string(rwm);
9,270✔
706
                        if (p < 0)
4,635✔
707
                                return p;
708

709
                        r = cgroup_context_add_or_update_device_allow(c, path, p);
4,635✔
710
                        if (r < 0)
4,635✔
711
                                return r;
712
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-weight="))) {
21,250✔
713
                        _cleanup_free_ char *path = NULL, *weight = NULL;
×
714
                        CGroupIODeviceWeight *a = NULL;
×
715

716
                        r = extract_many_words(&val, " ", 0, &path, &weight);
×
717
                        if (r < 0)
×
718
                                return r;
719
                        if (r != 2)
×
720
                                return -EINVAL;
721

722
                        LIST_FOREACH(device_weights, b, c->io_device_weights)
×
723
                                if (path_equal(b->path, path)) {
×
724
                                        a = b;
725
                                        break;
726
                                }
727

728
                        if (!a) {
×
729
                                a = new0(CGroupIODeviceWeight, 1);
×
730
                                if (!a)
×
731
                                        return log_oom_debug();
×
732

733
                                a->path = TAKE_PTR(path);
×
734

735
                                LIST_PREPEND(device_weights, c->io_device_weights, a);
×
736
                        }
737

738
                        r = safe_atou64(weight, &a->weight);
×
739
                        if (r < 0)
×
740
                                return r;
741
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-latency-target-usec="))) {
21,250✔
742
                        _cleanup_free_ char *path = NULL, *target = NULL;
×
743
                        CGroupIODeviceLatency *a = NULL;
×
744

745
                        r = extract_many_words(&val, " ", 0, &path, &target);
×
746
                        if (r < 0)
×
747
                                return r;
748
                        if (r != 2)
×
749
                                return -EINVAL;
750

751
                        LIST_FOREACH(device_latencies, b, c->io_device_latencies)
×
752
                                if (path_equal(b->path, path)) {
×
753
                                        a = b;
754
                                        break;
755
                                }
756

757
                        if (!a) {
×
758
                                a = new0(CGroupIODeviceLatency, 1);
×
759
                                if (!a)
×
760
                                        return log_oom_debug();
×
761

762
                                a->path = TAKE_PTR(path);
×
763

764
                                LIST_PREPEND(device_latencies, c->io_device_latencies, a);
×
765
                        }
766

767
                        r = deserialize_usec(target, &a->target_usec);
×
768
                        if (r < 0)
×
769
                                return r;
770
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-limit-"))) {
21,250✔
771
                        _cleanup_free_ char *type = NULL, *path = NULL, *limits = NULL;
×
772
                        CGroupIODeviceLimit *limit = NULL;
×
773
                        CGroupIOLimitType t;
×
774

775
                        r = extract_many_words(&val, "= ", 0, &type, &path, &limits);
×
776
                        if (r < 0)
×
777
                                return r;
778
                        if (r != 3)
×
779
                                return -EINVAL;
780

781
                        t = cgroup_io_limit_type_from_string(type);
×
782
                        if (t < 0)
×
783
                                return t;
784

785
                        LIST_FOREACH(device_limits, i, c->io_device_limits)
×
786
                                if (path_equal(path, i->path)) {
×
787
                                        limit = i;
788
                                        break;
789
                                }
790

791
                        if (!limit) {
×
792
                                limit = new0(CGroupIODeviceLimit, 1);
×
793
                                if (!limit)
×
794
                                        return log_oom_debug();
×
795

796
                                limit->path = TAKE_PTR(path);
×
797
                                for (CGroupIOLimitType i = 0; i < _CGROUP_IO_LIMIT_TYPE_MAX; i++)
×
798
                                        limit->limits[i] = cgroup_io_limit_defaults[i];
×
799

800
                                LIST_PREPEND(device_limits, c->io_device_limits, limit);
×
801
                        }
802

803
                        r = safe_atou64(limits, &limit->limits[t]);
×
804
                        if (r < 0)
×
805
                                return r;
806
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-allow="))) {
21,250✔
807
                        struct in_addr_prefix a;
×
808

809
                        r = in_addr_prefix_from_string_auto(val, &a.family, &a.address, &a.prefixlen);
×
810
                        if (r < 0)
×
811
                                return r;
×
812

813
                        r = in_addr_prefix_add(&c->ip_address_allow, &a);
×
814
                        if (r < 0)
×
815
                                return r;
816
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-deny="))) {
21,250✔
817
                        struct in_addr_prefix a;
1,602✔
818

819
                        r = in_addr_prefix_from_string_auto(val, &a.family, &a.address, &a.prefixlen);
1,602✔
820
                        if (r < 0)
1,602✔
821
                                return r;
×
822

823
                        r = in_addr_prefix_add(&c->ip_address_deny, &a);
1,602✔
824
                        if (r < 0)
1,602✔
825
                                return r;
826
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-allow-reduced="))) {
19,648✔
827
                        r = parse_boolean(val);
9,812✔
828
                        if (r < 0)
9,812✔
829
                                return r;
830
                        c->ip_address_allow_reduced = r;
9,812✔
831
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-deny-reduced="))) {
9,836✔
832
                        r = parse_boolean(val);
9,812✔
833
                        if (r < 0)
9,812✔
834
                                return r;
835
                        c->ip_address_deny_reduced = r;
9,812✔
836
                } else if ((val = startswith(l, "exec-cgroup-context-ip-ingress-filter-path="))) {
24✔
837
                        r = deserialize_strv(val, &c->ip_filters_ingress);
×
838
                        if (r < 0)
×
839
                                return r;
840
                } else if ((val = startswith(l, "exec-cgroup-context-ip-egress-filter-path="))) {
24✔
841
                        r = deserialize_strv(val, &c->ip_filters_egress);
×
842
                        if (r < 0)
×
843
                                return r;
844
                } else if ((val = startswith(l, "exec-cgroup-context-bpf-program="))) {
24✔
845
                        _cleanup_free_ char *type = NULL, *path = NULL;
×
846
                        uint32_t t;
×
847

848
                        r = extract_many_words(&val, " ", 0, &type, &path);
×
849
                        if (r < 0)
×
850
                                return r;
851
                        if (r != 2)
×
852
                                return -EINVAL;
853

854
                        r = safe_atou32(type, &t);
×
855
                        if (r < 0)
×
856
                                return r;
857

858
                        r = cgroup_context_add_bpf_foreign_program(c, t, path);
×
859
                        if (r < 0)
×
860
                                return r;
861
                } else if ((val = startswith(l, "exec-cgroup-context-socket-bind-allow="))) {
24✔
862
                        CGroupSocketBindItem *item;
×
863
                        uint16_t nr_ports, port_min;
×
864
                        int af, ip_protocol;
×
865

866
                        r = parse_socket_bind_item(val, &af, &ip_protocol, &nr_ports, &port_min);
×
867
                        if (r < 0)
×
868
                                return r;
×
869

870
                        item = new(CGroupSocketBindItem, 1);
×
871
                        if (!item)
×
872
                                return log_oom_debug();
×
873
                        *item = (CGroupSocketBindItem) {
×
874
                                .address_family = af,
875
                                .ip_protocol = ip_protocol,
876
                                .nr_ports = nr_ports,
877
                                .port_min = port_min,
878
                        };
879

880
                        LIST_PREPEND(socket_bind_items, c->socket_bind_allow, item);
×
881
                } else if ((val = startswith(l, "exec-cgroup-context-socket-bind-deny="))) {
24✔
882
                        CGroupSocketBindItem *item;
×
883
                        uint16_t nr_ports, port_min;
×
884
                        int af, ip_protocol;
×
885

886
                        r = parse_socket_bind_item(val, &af, &ip_protocol, &nr_ports, &port_min);
×
887
                        if (r < 0)
×
888
                                return r;
×
889

890
                        item = new(CGroupSocketBindItem, 1);
×
891
                        if (!item)
×
892
                                return log_oom_debug();
×
893
                        *item = (CGroupSocketBindItem) {
×
894
                                .address_family = af,
895
                                .ip_protocol = ip_protocol,
896
                                .nr_ports = nr_ports,
897
                                .port_min = port_min,
898
                        };
899

900
                        LIST_PREPEND(socket_bind_items, c->socket_bind_deny, item);
×
901
                } else if ((val = startswith(l, "exec-cgroup-context-restrict-network-interfaces="))) {
24✔
902
                        r = set_put_strdup(&c->restrict_network_interfaces, val);
15✔
903
                        if (r < 0)
15✔
904
                                return r;
905
                } else if ((val = startswith(l, "exec-cgroup-context-restrict-network-interfaces-is-allow-list="))) {
9✔
906
                        r = parse_boolean(val);
9✔
907
                        if (r < 0)
9✔
908
                                return r;
909
                        c->restrict_network_interfaces_is_allow_list = r;
9✔
910
                } else
911
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
912
        }
913

914
        return 0;
11,867✔
915
}
916

917
static int exec_runtime_serialize(const ExecRuntime *rt, FILE *f, FDSet *fds) {
2,115✔
918
        int r;
2,115✔
919

920
        assert(f);
2,115✔
921
        assert(fds);
2,115✔
922

923
        if (!rt) {
2,115✔
924
                fputc('\n', f); /* End marker */
2,043✔
925
                return 0;
2,043✔
926
        }
927

928
        if (rt->shared) {
72✔
929
                r = serialize_item(f, "exec-runtime-id", rt->shared->id);
71✔
930
                if (r < 0)
71✔
931
                        return r;
932

933
                r = serialize_item(f, "exec-runtime-tmp-dir", rt->shared->tmp_dir);
71✔
934
                if (r < 0)
71✔
935
                        return r;
936

937
                r = serialize_item(f, "exec-runtime-var-tmp-dir", rt->shared->var_tmp_dir);
71✔
938
                if (r < 0)
71✔
939
                        return r;
940

941
                if (rt->shared->netns_storage_socket[0] >= 0 && rt->shared->netns_storage_socket[1] >= 0) {
71✔
942
                        r = serialize_fd_many(f, fds, "exec-runtime-netns-storage-socket", rt->shared->netns_storage_socket, 2);
7✔
943
                        if (r < 0)
7✔
944
                                return r;
945
                }
946

947
                if (rt->shared->ipcns_storage_socket[0] >= 0 && rt->shared->ipcns_storage_socket[1] >= 0) {
71✔
948
                        r = serialize_fd_many(f, fds, "exec-runtime-ipcns-storage-socket", rt->shared->ipcns_storage_socket, 2);
2✔
949
                        if (r < 0)
2✔
950
                                return r;
951
                }
952
        }
953

954
        if (rt->dynamic_creds) {
72✔
955
                r = dynamic_user_serialize_one(rt->dynamic_creds->user, "exec-runtime-dynamic-creds-user", f, fds);
1✔
956
                if (r < 0)
1✔
957
                        return r;
958
        }
959

960
        if (rt->dynamic_creds && rt->dynamic_creds->group && rt->dynamic_creds->group == rt->dynamic_creds->user) {
72✔
961
                r = serialize_bool(f, "exec-runtime-dynamic-creds-group-copy", true);
1✔
962
                if (r < 0)
1✔
963
                        return r;
964
        } else if (rt->dynamic_creds) {
71✔
965
                r = dynamic_user_serialize_one(rt->dynamic_creds->group, "exec-runtime-dynamic-creds-group", f, fds);
×
966
                if (r < 0)
×
967
                        return r;
968
        }
969

970
        r = serialize_item(f, "exec-runtime-ephemeral-copy", rt->ephemeral_copy);
72✔
971
        if (r < 0)
72✔
972
                return r;
973

974
        if (rt->ephemeral_storage_socket[0] >= 0 && rt->ephemeral_storage_socket[1] >= 0) {
72✔
975
                r = serialize_fd_many(f, fds, "exec-runtime-ephemeral-storage-socket", rt->ephemeral_storage_socket, 2);
×
976
                if (r < 0)
×
977
                        return r;
978
        }
979

980
        fputc('\n', f); /* End marker */
72✔
981

982
        return 0;
72✔
983
}
984

985
static int exec_runtime_deserialize(ExecRuntime *rt, FILE *f, FDSet *fds) {
11,867✔
986
        int r;
11,867✔
987

988
        assert(rt);
11,867✔
989
        assert(rt->shared);
11,867✔
990
        assert(rt->dynamic_creds);
11,867✔
991
        assert(f);
11,867✔
992
        assert(fds);
11,867✔
993

994
        for (;;) {
13,094✔
995
                _cleanup_free_ char *l = NULL;
1,227✔
996
                const char *val;
13,094✔
997

998
                r = deserialize_read_line(f, &l);
13,094✔
999
                if (r < 0)
13,094✔
1000
                        return r;
1001
                if (r == 0) /* eof or end marker */
13,094✔
1002
                        break;
1003

1004
                if ((val = startswith(l, "exec-runtime-id="))) {
1,227✔
1005
                        r = free_and_strdup(&rt->shared->id, val);
357✔
1006
                        if (r < 0)
357✔
1007
                                return r;
1008
                } else if ((val = startswith(l, "exec-runtime-tmp-dir="))) {
870✔
1009
                        r = free_and_strdup(&rt->shared->tmp_dir, val);
337✔
1010
                        if (r < 0)
337✔
1011
                                return r;
1012
                } else if ((val = startswith(l, "exec-runtime-var-tmp-dir="))) {
533✔
1013
                        r = free_and_strdup(&rt->shared->var_tmp_dir, val);
337✔
1014
                        if (r < 0)
337✔
1015
                                return r;
1016
                } else if ((val = startswith(l, "exec-runtime-netns-storage-socket="))) {
196✔
1017

1018
                        r = deserialize_fd_many(fds, val, 2, rt->shared->netns_storage_socket);
66✔
1019
                        if (r < 0)
66✔
1020
                                continue;
×
1021

1022
                } else if ((val = startswith(l, "exec-runtime-ipcns-storage-socket="))) {
130✔
1023

1024
                        r = deserialize_fd_many(fds, val, 2, rt->shared->ipcns_storage_socket);
6✔
1025
                        if (r < 0)
6✔
1026
                                continue;
×
1027

1028
                } else if ((val = startswith(l, "exec-runtime-dynamic-creds-user=")))
124✔
1029
                        dynamic_user_deserialize_one(/* m= */ NULL, val, fds, &rt->dynamic_creds->user);
62✔
1030
                else if ((val = startswith(l, "exec-runtime-dynamic-creds-group=")))
62✔
1031
                        dynamic_user_deserialize_one(/* m= */ NULL, val, fds, &rt->dynamic_creds->group);
×
1032
                else if ((val = startswith(l, "exec-runtime-dynamic-creds-group-copy="))) {
62✔
1033
                        r = parse_boolean(val);
62✔
1034
                        if (r < 0)
62✔
1035
                                return r;
1036
                        if (!r)
62✔
1037
                                continue; /* Nothing to do */
×
1038

1039
                        if (!rt->dynamic_creds->user)
62✔
1040
                                return -EINVAL;
1041

1042
                        rt->dynamic_creds->group = dynamic_user_ref(rt->dynamic_creds->user);
62✔
1043
                } else if ((val = startswith(l, "exec-runtime-ephemeral-copy="))) {
×
1044
                        r = free_and_strdup(&rt->ephemeral_copy, val);
×
1045
                        if (r < 0)
×
1046
                                return r;
1047
                } else if ((val = startswith(l, "exec-runtime-ephemeral-storage-socket="))) {
×
1048

1049
                        r = deserialize_fd_many(fds, val, 2, rt->ephemeral_storage_socket);
×
1050
                        if (r < 0)
×
1051
                                continue;
×
1052
                } else
1053
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
1054
        }
1055

1056
        return 0;
11,867✔
1057
}
1058

1059
static bool exec_parameters_is_idle_pipe_set(const ExecParameters *p) {
2,115✔
1060
        assert(p);
2,115✔
1061

1062
        return p->idle_pipe &&
2,144✔
1063
                p->idle_pipe[0] >= 0 &&
29✔
1064
                p->idle_pipe[1] >= 0 &&
27✔
1065
                p->idle_pipe[2] >= 0 &&
2,142✔
1066
                p->idle_pipe[3] >= 0;
27✔
1067
}
1068

1069
static int exec_parameters_serialize(const ExecParameters *p, const ExecContext *c, FILE *f, FDSet *fds) {
2,115✔
1070
        int r;
2,115✔
1071

1072
        assert(f);
2,115✔
1073
        assert(fds);
2,115✔
1074

1075
        if (!p)
2,115✔
1076
                return 0;
1077

1078
        r = serialize_item(f, "exec-parameters-runtime-scope", runtime_scope_to_string(p->runtime_scope));
2,115✔
1079
        if (r < 0)
2,115✔
1080
                return r;
1081

1082
        r = serialize_strv(f, "exec-parameters-environment", p->environment);
2,115✔
1083
        if (r < 0)
2,115✔
1084
                return r;
1085

1086
        if (p->fds) {
2,115✔
1087
                if (p->n_socket_fds > 0) {
426✔
1088
                        r = serialize_item_format(f, "exec-parameters-n-socket-fds", "%zu", p->n_socket_fds);
425✔
1089
                        if (r < 0)
425✔
1090
                                return r;
1091
                }
1092

1093
                if (p->n_stashed_fds > 0) {
426✔
1094
                        r = serialize_item_format(f, "exec-parameters-n-stashed-fds", "%zu", p->n_stashed_fds);
4✔
1095
                        if (r < 0)
4✔
1096
                                return r;
1097
                }
1098

1099
                r = serialize_fd_many(f, fds, "exec-parameters-fds", p->fds, p->n_socket_fds + p->n_stashed_fds);
426✔
1100
                if (r < 0)
426✔
1101
                        return r;
1102

1103
                r = serialize_strv(f, "exec-parameters-fd-names", p->fd_names);
426✔
1104
                if (r < 0)
426✔
1105
                        return r;
1106
        }
1107

1108
        if (p->flags != 0) {
2,115✔
1109
                r = serialize_item_format(f, "exec-parameters-flags", "%u", (unsigned) p->flags);
2,115✔
1110
                if (r < 0)
2,115✔
1111
                        return r;
1112
        }
1113

1114
        r = serialize_bool_elide(f, "exec-parameters-selinux-context-net", p->selinux_context_net);
2,115✔
1115
        if (r < 0)
2,115✔
1116
                return r;
1117

1118
        r = serialize_item(f, "exec-parameters-cgroup-path", p->cgroup_path);
2,115✔
1119
        if (r < 0)
2,115✔
1120
                return r;
1121

1122
        r = serialize_item_format(f, "exec-parameters-cgroup-id", "%" PRIu64, p->cgroup_id);
2,115✔
1123
        if (r < 0)
2,115✔
1124
                return r;
1125

1126
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
12,690✔
1127
                _cleanup_free_ char *key = NULL;
10,575✔
1128

1129
                key = strjoin("exec-parameters-prefix-directories-", exec_directory_type_to_string(dt));
10,575✔
1130
                if (!key)
10,575✔
UNCOV
1131
                        return log_oom_debug();
×
1132

1133
                /* Always serialize, even an empty prefix, as this is a fixed array and we always expect
1134
                 * to have all elements (unless fuzzing is happening, hence the NULL check). */
1135
                r = serialize_item(f, key, strempty(p->prefix ? p->prefix[dt] : NULL));
10,575✔
1136
                if (r < 0)
10,575✔
1137
                        return r;
1138
        }
1139

1140
        r = serialize_item(f, "exec-parameters-received-credentials-directory", p->received_credentials_directory);
2,115✔
1141
        if (r < 0)
2,115✔
1142
                return r;
1143

1144
        r = serialize_item(f, "exec-parameters-received-encrypted-credentials-directory", p->received_encrypted_credentials_directory);
2,115✔
1145
        if (r < 0)
2,115✔
1146
                return r;
1147

1148
        r = serialize_item(f, "exec-parameters-confirm-spawn", p->confirm_spawn);
2,115✔
1149
        if (r < 0)
2,115✔
1150
                return r;
1151

1152
        r = serialize_bool_elide(f, "exec-parameters-shall-confirm-spawn", p->shall_confirm_spawn);
2,115✔
1153
        if (r < 0)
2,115✔
1154
                return r;
1155

1156
        if (p->watchdog_usec > 0) {
2,115✔
1157
                r = serialize_usec(f, "exec-parameters-watchdog-usec", p->watchdog_usec);
210✔
1158
                if (r < 0)
210✔
1159
                        return r;
1160
        }
1161

1162
        if (exec_parameters_is_idle_pipe_set(p)) {
2,115✔
1163
                r = serialize_fd_many(f, fds, "exec-parameters-idle-pipe", p->idle_pipe, 4);
27✔
1164
                if (r < 0)
27✔
1165
                        return r;
1166
        }
1167

1168
        r = serialize_fd(f, fds, "exec-parameters-stdin-fd", p->stdin_fd);
2,115✔
1169
        if (r < 0)
2,115✔
1170
                return r;
1171

1172
        r = serialize_fd(f, fds, "exec-parameters-stdout-fd", p->stdout_fd);
2,115✔
1173
        if (r < 0)
2,115✔
1174
                return r;
1175

1176
        r = serialize_fd(f, fds, "exec-parameters-stderr-fd", p->stderr_fd);
2,115✔
1177
        if (r < 0)
2,115✔
1178
                return r;
1179

1180
        r = serialize_fd(f, fds, "exec-parameters-exec-fd", p->exec_fd);
2,115✔
1181
        if (r < 0)
2,115✔
1182
                return r;
1183

1184
        r = serialize_fd(f, fds, "exec-parameters-handoff-timestamp-fd", p->handoff_timestamp_fd);
2,115✔
1185
        if (r < 0)
2,115✔
1186
                return r;
1187

1188
        r = serialize_fd(f, fds, "exec-parameters-pidref-transport-fd", p->pidref_transport_fd);
2,115✔
1189
        if (r < 0)
2,115✔
1190
                return r;
1191

1192
        if (c && exec_context_restrict_filesystems_set(c)) {
2,115✔
UNCOV
1193
                r = serialize_fd(f, fds, "exec-parameters-bpf-outer-map-fd", p->bpf_restrict_fs_map_fd);
×
UNCOV
1194
                if (r < 0)
×
1195
                        return r;
1196
        }
1197

1198
        r = serialize_item(f, "exec-parameters-notify-socket", p->notify_socket);
2,115✔
1199
        if (r < 0)
2,115✔
1200
                return r;
1201

1202
        LIST_FOREACH(open_files, file, p->open_files) {
2,115✔
UNCOV
1203
                _cleanup_free_ char *ofs = NULL;
×
1204

1205
                r = open_file_to_string(file, &ofs);
×
1206
                if (r < 0)
×
1207
                        return r;
1208

UNCOV
1209
                r = serialize_item(f, "exec-parameters-open-file", ofs);
×
UNCOV
1210
                if (r < 0)
×
1211
                        return r;
1212
        }
1213

1214
        r = serialize_item(f, "exec-parameters-fallback-smack-process-label", p->fallback_smack_process_label);
2,115✔
1215
        if (r < 0)
2,115✔
1216
                return r;
1217

1218
        r = serialize_fd(f, fds, "exec-parameters-user-lookup-fd", p->user_lookup_fd);
2,115✔
1219
        if (r < 0)
2,115✔
1220
                return r;
1221

1222
        r = serialize_strv(f, "exec-parameters-files-env", p->files_env);
2,115✔
1223
        if (r < 0)
2,115✔
1224
                return r;
1225

1226
        r = serialize_item(f, "exec-parameters-unit-id", p->unit_id);
2,115✔
1227
        if (r < 0)
2,115✔
1228
                return r;
1229

1230
        r = serialize_item(f, "exec-parameters-invocation-id-string", p->invocation_id_string);
2,115✔
1231
        if (r < 0)
2,115✔
1232
                return r;
1233

1234
        r = serialize_bool_elide(f, "exec-parameters-debug-invocation", p->debug_invocation);
2,115✔
1235
        if (r < 0)
2,115✔
1236
                return r;
1237

1238
        fputc('\n', f); /* End marker */
2,115✔
1239

1240
        return 0;
2,115✔
1241
}
1242

1243
static int exec_parameters_deserialize(ExecParameters *p, FILE *f, FDSet *fds) {
11,867✔
1244
        int r;
11,867✔
1245

1246
        assert(p);
11,867✔
1247
        assert(f);
11,867✔
1248
        assert(fds);
11,867✔
1249

1250
        unsigned nr_open = MAX(read_nr_open(), NR_OPEN_MINIMUM);
11,867✔
1251

1252
        for (;;) {
253,761✔
1253
                _cleanup_free_ char *l = NULL;
241,894✔
1254
                const char *val;
253,761✔
1255

1256
                r = deserialize_read_line(f, &l);
253,761✔
1257
                if (r < 0)
253,761✔
1258
                        return r;
1259
                if (r == 0) /* eof or end marker */
253,761✔
1260
                        break;
1261

1262
                if ((val = startswith(l, "exec-parameters-runtime-scope="))) {
241,894✔
1263
                        p->runtime_scope = runtime_scope_from_string(val);
11,867✔
1264
                        if (p->runtime_scope < 0)
11,867✔
1265
                                return p->runtime_scope;
1266
                } else if ((val = startswith(l, "exec-parameters-environment="))) {
230,027✔
1267
                        r = deserialize_strv(val, &p->environment);
48,490✔
1268
                        if (r < 0)
48,490✔
1269
                                return r;
1270
                } else if ((val = startswith(l, "exec-parameters-n-socket-fds="))) {
181,537✔
1271
                        if (p->fds)
2,449✔
1272
                                return -EINVAL; /* Already received */
1273

1274
                        r = safe_atozu(val, &p->n_socket_fds);
2,449✔
1275
                        if (r < 0)
2,449✔
1276
                                return r;
1277

1278
                        if (p->n_socket_fds > nr_open)
2,449✔
1279
                                return -EINVAL; /* too many, someone is playing games with us */
1280
                } else if ((val = startswith(l, "exec-parameters-n-stashed-fds="))) {
179,088✔
1281
                        if (p->fds)
147✔
1282
                                return -EINVAL; /* Already received */
1283

1284
                        r = safe_atozu(val, &p->n_stashed_fds);
147✔
1285
                        if (r < 0)
147✔
1286
                                return r;
1287

1288
                        if (p->n_stashed_fds > nr_open)
147✔
1289
                                return -EINVAL; /* too many, someone is playing games with us */
1290
                } else if ((val = startswith(l, "exec-parameters-fds="))) {
178,941✔
1291
                        if (p->n_socket_fds + p->n_stashed_fds == 0)
2,454✔
UNCOV
1292
                                return log_warning_errno(
×
1293
                                                SYNTHETIC_ERRNO(EINVAL),
1294
                                                "Got exec-parameters-fds= without "
1295
                                                "prior exec-parameters-n-socket-fds= or exec-parameters-n-stashed-fds=");
1296
                        if (p->n_socket_fds + p->n_stashed_fds > nr_open)
2,454✔
1297
                                return -EINVAL; /* too many, someone is playing games with us */
1298

1299
                        if (p->fds)
2,454✔
1300
                                return -EINVAL; /* duplicated */
1301

1302
                        p->fds = new(int, p->n_socket_fds + p->n_stashed_fds);
2,454✔
1303
                        if (!p->fds)
2,454✔
UNCOV
1304
                                return log_oom_debug();
×
1305

1306
                        /* Ensure we don't leave any FD uninitialized on error, it makes the fuzzer sad */
1307
                        FOREACH_ARRAY(i, p->fds, p->n_socket_fds + p->n_stashed_fds)
7,443✔
1308
                                *i = -EBADF;
4,989✔
1309

1310
                        r = deserialize_fd_many(fds, val, p->n_socket_fds + p->n_stashed_fds, p->fds);
2,454✔
1311
                        if (r < 0)
2,454✔
UNCOV
1312
                                continue;
×
1313

1314
                } else if ((val = startswith(l, "exec-parameters-fd-names="))) {
176,487✔
1315
                        r = deserialize_strv(val, &p->fd_names);
4,989✔
1316
                        if (r < 0)
4,989✔
1317
                                return r;
1318
                } else if ((val = startswith(l, "exec-parameters-flags="))) {
171,498✔
1319
                        unsigned flags;
11,867✔
1320

1321
                        r = safe_atou(val, &flags);
11,867✔
1322
                        if (r < 0)
11,867✔
UNCOV
1323
                                return r;
×
1324
                        p->flags = flags;
11,867✔
1325
                } else if ((val = startswith(l, "exec-parameters-selinux-context-net="))) {
159,631✔
1326
                        r = parse_boolean(val);
×
UNCOV
1327
                        if (r < 0)
×
1328
                                return r;
1329

UNCOV
1330
                        p->selinux_context_net = r;
×
1331
                } else if ((val = startswith(l, "exec-parameters-cgroup-path="))) {
159,631✔
1332
                        r = free_and_strdup(&p->cgroup_path, val);
11,867✔
1333
                        if (r < 0)
11,867✔
1334
                                return r;
1335
                } else if ((val = startswith(l, "exec-parameters-cgroup-id="))) {
147,764✔
1336
                        r = safe_atou64(val, &p->cgroup_id);
11,867✔
1337
                        if (r < 0)
11,867✔
1338
                                return r;
1339
                } else if ((val = startswith(l, "exec-parameters-prefix-directories-"))) {
135,897✔
1340
                        _cleanup_free_ char *type = NULL, *prefix = NULL;
59,335✔
1341
                        ExecDirectoryType dt;
59,335✔
1342

1343
                        r = extract_many_words(&val, "= ", 0, &type, &prefix);
59,335✔
1344
                        if (r < 0)
59,335✔
1345
                                return r;
1346
                        if (r == 0)
59,335✔
1347
                                return -EINVAL;
1348

1349
                        dt = exec_directory_type_from_string(type);
59,335✔
1350
                        if (dt < 0)
59,335✔
1351
                                return -EINVAL;
1352

1353
                        if (!p->prefix) {
59,335✔
1354
                                p->prefix = new0(char*, _EXEC_DIRECTORY_TYPE_MAX+1);
11,867✔
1355
                                if (!p->prefix)
11,867✔
UNCOV
1356
                                        return log_oom_debug();
×
1357
                        }
1358

1359
                        if (isempty(prefix))
59,335✔
UNCOV
1360
                                p->prefix[dt] = mfree(p->prefix[dt]);
×
1361
                        else
1362
                                free_and_replace(p->prefix[dt], prefix);
59,335✔
1363
                } else if ((val = startswith(l, "exec-parameters-received-credentials-directory="))) {
76,562✔
1364
                        r = free_and_strdup(&p->received_credentials_directory, val);
11,196✔
1365
                        if (r < 0)
11,196✔
1366
                                return r;
1367
                } else if ((val = startswith(l, "exec-parameters-received-encrypted-credentials-directory="))) {
65,366✔
UNCOV
1368
                        r = free_and_strdup(&p->received_encrypted_credentials_directory, val);
×
UNCOV
1369
                        if (r < 0)
×
1370
                                return r;
1371
                } else if ((val = startswith(l, "exec-parameters-confirm-spawn="))) {
65,366✔
UNCOV
1372
                        r = free_and_strdup(&p->confirm_spawn, val);
×
UNCOV
1373
                        if (r < 0)
×
1374
                                return r;
1375
                } else if ((val = startswith(l, "exec-parameters-shall-confirm-spawn="))) {
65,366✔
UNCOV
1376
                        r = parse_boolean(val);
×
UNCOV
1377
                        if (r < 0)
×
1378
                                return r;
1379

UNCOV
1380
                        p->shall_confirm_spawn = r;
×
1381
                } else if ((val = startswith(l, "exec-parameters-watchdog-usec="))) {
65,366✔
1382
                        r = deserialize_usec(val, &p->watchdog_usec);
2,190✔
1383
                        if (r < 0)
2,190✔
1384
                                return r;
1385
                } else if ((val = startswith(l, "exec-parameters-idle-pipe="))) {
63,176✔
1386
                        if (p->idle_pipe)
158✔
1387
                                return -EINVAL; /* duplicated */
1388

1389
                        p->idle_pipe = new(int, 4);
158✔
1390
                        if (!p->idle_pipe)
158✔
UNCOV
1391
                                return log_oom_debug();
×
1392

1393
                        p->idle_pipe[0] = p->idle_pipe[1] = p->idle_pipe[2] = p->idle_pipe[3] = -EBADF;
158✔
1394

1395
                        r = deserialize_fd_many(fds, val, 4, p->idle_pipe);
158✔
1396
                        if (r < 0)
158✔
1397
                                continue;
×
1398

1399
                } else if ((val = startswith(l, "exec-parameters-stdin-fd="))) {
63,018✔
1400
                        int fd;
587✔
1401

1402
                        fd = deserialize_fd(fds, val);
587✔
1403
                        if (fd < 0)
587✔
UNCOV
1404
                                continue;
×
1405

1406
                        close_and_replace(p->stdin_fd, fd);
587✔
1407

1408
                } else if ((val = startswith(l, "exec-parameters-stdout-fd="))) {
62,431✔
1409
                        int fd;
587✔
1410

1411
                        fd = deserialize_fd(fds, val);
587✔
1412
                        if (fd < 0)
587✔
UNCOV
1413
                                continue;
×
1414

1415
                        close_and_replace(p->stdout_fd, fd);
587✔
1416

1417
                } else if ((val = startswith(l, "exec-parameters-stderr-fd="))) {
61,844✔
1418
                        int fd;
587✔
1419

1420
                        fd = deserialize_fd(fds, val);
587✔
1421
                        if (fd < 0)
587✔
UNCOV
1422
                                continue;
×
1423

1424
                        close_and_replace(p->stderr_fd, fd);
587✔
1425
                } else if ((val = startswith(l, "exec-parameters-exec-fd="))) {
61,257✔
1426
                        int fd;
471✔
1427

1428
                        fd = deserialize_fd(fds, val);
471✔
1429
                        if (fd < 0)
471✔
UNCOV
1430
                                continue;
×
1431

1432
                        close_and_replace(p->exec_fd, fd);
471✔
1433
                } else if ((val = startswith(l, "exec-parameters-handoff-timestamp-fd="))) {
60,786✔
1434
                        int fd;
11,867✔
1435

1436
                        fd = deserialize_fd(fds, val);
11,867✔
1437
                        if (fd < 0)
11,867✔
UNCOV
1438
                                continue;
×
1439

1440
                        close_and_replace(p->handoff_timestamp_fd, fd);
11,867✔
1441
                } else if ((val = startswith(l, "exec-parameters-pidref-transport-fd="))) {
48,919✔
1442
                        int fd;
10,718✔
1443

1444
                        fd = deserialize_fd(fds, val);
10,718✔
1445
                        if (fd < 0)
10,718✔
UNCOV
1446
                                continue;
×
1447

1448
                        close_and_replace(p->pidref_transport_fd, fd);
10,718✔
1449
                } else if ((val = startswith(l, "exec-parameters-bpf-outer-map-fd="))) {
38,201✔
UNCOV
1450
                        int fd;
×
1451

UNCOV
1452
                        fd = deserialize_fd(fds, val);
×
UNCOV
1453
                        if (fd < 0)
×
UNCOV
1454
                                continue;
×
1455

UNCOV
1456
                        close_and_replace(p->bpf_restrict_fs_map_fd, fd);
×
1457
                } else if ((val = startswith(l, "exec-parameters-notify-socket="))) {
38,201✔
1458
                        r = free_and_strdup(&p->notify_socket, val);
2,591✔
1459
                        if (r < 0)
2,591✔
1460
                                return r;
1461
                } else if ((val = startswith(l, "exec-parameters-open-file="))) {
35,610✔
1462
                        OpenFile *of;
5✔
1463

1464
                        r = open_file_parse(val, &of);
5✔
1465
                        if (r < 0)
5✔
UNCOV
1466
                                return r;
×
1467

1468
                        LIST_APPEND(open_files, p->open_files, of);
5✔
1469
                } else if ((val = startswith(l, "exec-parameters-fallback-smack-process-label="))) {
35,605✔
UNCOV
1470
                        r = free_and_strdup(&p->fallback_smack_process_label, val);
×
UNCOV
1471
                        if (r < 0)
×
1472
                                return r;
1473
                } else if ((val = startswith(l, "exec-parameters-user-lookup-fd="))) {
35,605✔
1474
                        int fd;
11,867✔
1475

1476
                        fd = deserialize_fd(fds, val);
11,867✔
1477
                        if (fd < 0)
11,867✔
UNCOV
1478
                                continue;
×
1479

1480
                        close_and_replace(p->user_lookup_fd, fd);
11,867✔
1481
                } else if ((val = startswith(l, "exec-parameters-files-env="))) {
23,738✔
1482
                        r = deserialize_strv(val, &p->files_env);
2✔
1483
                        if (r < 0)
2✔
1484
                                return r;
1485
                } else if ((val = startswith(l, "exec-parameters-unit-id="))) {
23,736✔
1486
                        r = free_and_strdup(&p->unit_id, val);
11,867✔
1487
                        if (r < 0)
11,867✔
1488
                                return r;
1489
                } else if ((val = startswith(l, "exec-parameters-invocation-id-string="))) {
11,869✔
1490
                        if (strlen(val) > SD_ID128_STRING_MAX - 1)
11,867✔
1491
                                return -EINVAL;
1492

1493
                        r = sd_id128_from_string(val, &p->invocation_id);
11,867✔
1494
                        if (r < 0)
11,867✔
1495
                                return r;
1496

1497
                        sd_id128_to_string(p->invocation_id, p->invocation_id_string);
11,867✔
1498
                } else if ((val = startswith(l, "exec-parameters-debug-invocation="))) {
2✔
1499
                        r = parse_boolean(val);
2✔
1500
                        if (r < 0)
2✔
1501
                                return r;
1502

1503
                        p->debug_invocation = r;
2✔
1504
                } else
UNCOV
1505
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
1506
        }
1507

1508
        /* Bail out if we got exec-parameters-n-{socket/stashed}-fds= but no corresponding
1509
         * exec-parameters-fds= */
1510
        if (p->n_socket_fds + p->n_stashed_fds > 0 && !p->fds)
11,867✔
UNCOV
1511
                return -EINVAL;
×
1512

1513
        return 0;
1514
}
1515

1516
static int serialize_std_out_err(const ExecContext *c, FILE *f, int fileno) {
4,230✔
1517
        char *key, *value;
4,230✔
1518
        const char *type;
4,230✔
1519

1520
        assert(c);
4,230✔
1521
        assert(f);
4,230✔
1522
        assert(IN_SET(fileno, STDOUT_FILENO, STDERR_FILENO));
4,230✔
1523

1524
        type = fileno == STDOUT_FILENO ? "output" : "error";
4,230✔
1525

1526
        switch (fileno == STDOUT_FILENO ? c->std_output : c->std_error) {
4,230✔
UNCOV
1527
        case EXEC_OUTPUT_NAMED_FD:
×
UNCOV
1528
                key = strjoina("exec-context-std-", type, "-fd-name");
×
UNCOV
1529
                value = c->stdio_fdname[fileno];
×
1530

UNCOV
1531
                break;
×
1532

1533
        case EXEC_OUTPUT_FILE:
2✔
1534
                key = strjoina("exec-context-std-", type, "-file");
14✔
1535
                value = c->stdio_file[fileno];
2✔
1536

1537
                break;
2✔
1538

UNCOV
1539
        case EXEC_OUTPUT_FILE_APPEND:
×
1540
                key = strjoina("exec-context-std-", type, "-file-append");
×
UNCOV
1541
                value = c->stdio_file[fileno];
×
1542

UNCOV
1543
                break;
×
1544

UNCOV
1545
        case EXEC_OUTPUT_FILE_TRUNCATE:
×
UNCOV
1546
                key = strjoina("exec-context-std-", type, "-file-truncate");
×
UNCOV
1547
                value = c->stdio_file[fileno];
×
1548

UNCOV
1549
                break;
×
1550

1551
        default:
1552
                return 0;
1553
        }
1554

1555
        return serialize_item(f, key, value);
2✔
1556
}
1557

1558
static int exec_context_serialize(const ExecContext *c, FILE *f) {
2,115✔
1559
        int r;
2,115✔
1560

1561
        assert(f);
2,115✔
1562

1563
        if (!c)
2,115✔
1564
                return 0;
2,115✔
1565

1566
        r = serialize_strv(f, "exec-context-environment", c->environment);
2,115✔
1567
        if (r < 0)
2,115✔
1568
                return r;
1569

1570
        r = serialize_strv(f, "exec-context-environment-files", c->environment_files);
2,115✔
1571
        if (r < 0)
2,115✔
1572
                return r;
1573

1574
        r = serialize_strv(f, "exec-context-pass-environment", c->pass_environment);
2,115✔
1575
        if (r < 0)
2,115✔
1576
                return r;
1577

1578
        r = serialize_strv(f, "exec-context-unset-environment", c->unset_environment);
2,115✔
1579
        if (r < 0)
2,115✔
1580
                return r;
1581

1582
        r = serialize_item_escaped(f, "exec-context-working-directory", c->working_directory);
2,115✔
1583
        if (r < 0)
2,115✔
1584
                return r;
1585

1586
        r = serialize_bool_elide(f, "exec-context-working-directory-missing-ok", c->working_directory_missing_ok);
2,115✔
1587
        if (r < 0)
2,115✔
1588
                return r;
1589

1590
        r = serialize_bool_elide(f, "exec-context-working-directory-home", c->working_directory_home);
2,115✔
1591
        if (r < 0)
2,115✔
1592
                return r;
1593

1594
        r = serialize_item_escaped(f, "exec-context-root-directory", c->root_directory);
2,115✔
1595
        if (r < 0)
2,115✔
1596
                return r;
1597

1598
        r = serialize_item_escaped(f, "exec-context-root-image", c->root_image);
2,115✔
1599
        if (r < 0)
2,115✔
1600
                return r;
1601

1602
        if (c->root_image_options) {
2,115✔
UNCOV
1603
                _cleanup_free_ char *options = NULL;
×
1604

UNCOV
1605
                LIST_FOREACH(mount_options, o, c->root_image_options) {
×
UNCOV
1606
                        if (isempty(o->options))
×
UNCOV
1607
                                continue;
×
1608

UNCOV
1609
                        _cleanup_free_ char *escaped = NULL;
×
UNCOV
1610
                        escaped = shell_escape(o->options, ":");
×
UNCOV
1611
                        if (!escaped)
×
UNCOV
1612
                                return log_oom_debug();
×
1613

UNCOV
1614
                        if (!strextend(&options,
×
1615
                                        " ",
1616
                                        partition_designator_to_string(o->partition_designator),
1617
                                               ":",
1618
                                               escaped))
UNCOV
1619
                                        return log_oom_debug();
×
1620
                }
1621

UNCOV
1622
                r = serialize_item(f, "exec-context-root-image-options", options);
×
UNCOV
1623
                if (r < 0)
×
1624
                        return r;
1625
        }
1626

1627
        r = serialize_item(f, "exec-context-root-verity", c->root_verity);
2,115✔
1628
        if (r < 0)
2,115✔
1629
                return r;
1630

1631
        r = serialize_item(f, "exec-context-root-hash-path", c->root_hash_path);
2,115✔
1632
        if (r < 0)
2,115✔
1633
                return r;
1634

1635
        r = serialize_item(f, "exec-context-root-hash-sig-path", c->root_hash_sig_path);
2,115✔
1636
        if (r < 0)
2,115✔
1637
                return r;
1638

1639
        r = serialize_item_hexmem(f, "exec-context-root-hash", c->root_hash, c->root_hash_size);
2,115✔
1640
        if (r < 0)
2,115✔
1641
                return r;
1642

1643
        r = serialize_item_base64mem(f, "exec-context-root-hash-sig", c->root_hash_sig, c->root_hash_sig_size);
2,115✔
1644
        if (r < 0)
2,115✔
1645
                return r;
1646

1647
        r = serialize_bool_elide(f, "exec-context-root-ephemeral", c->root_ephemeral);
2,115✔
1648
        if (r < 0)
2,115✔
1649
                return r;
1650

1651
        r = serialize_item_format(f, "exec-context-umask", "%04o", c->umask);
2,115✔
1652
        if (r < 0)
2,115✔
1653
                return r;
1654

1655
        r = serialize_bool_elide(f, "exec-context-non-blocking", c->non_blocking);
2,115✔
1656
        if (r < 0)
2,115✔
1657
                return r;
1658

1659
        r = serialize_item_tristate(f, "exec-context-private-mounts", c->private_mounts);
2,115✔
1660
        if (r < 0)
27✔
1661
                return r;
1662

1663
        r = serialize_item_tristate(f, "exec-context-mount-api-vfs", c->mount_apivfs);
2,115✔
1664
        if (r < 0)
2✔
1665
                return r;
1666

1667
        r = serialize_item_tristate(f, "exec-context-bind-log-sockets", c->bind_log_sockets);
2,115✔
UNCOV
1668
        if (r < 0)
×
1669
                return r;
1670

1671
        r = serialize_item_tristate(f, "exec-context-memory-ksm", c->memory_ksm);
2,115✔
UNCOV
1672
        if (r < 0)
×
1673
                return r;
1674

1675
        r = serialize_item(f, "exec-context-private-tmp", private_tmp_to_string(c->private_tmp));
2,115✔
1676
        if (r < 0)
2,115✔
1677
                return r;
1678

1679
        /* This must be set in unit_patch_contexts() before executing a command. */
1680
        assert(c->private_var_tmp >= 0 && c->private_var_tmp < _PRIVATE_TMP_MAX);
2,115✔
1681
        r = serialize_item(f, "exec-context-private-var-tmp", private_tmp_to_string(c->private_var_tmp));
2,115✔
1682
        if (r < 0)
2,115✔
1683
                return r;
1684

1685
        r = serialize_bool_elide(f, "exec-context-private-devices", c->private_devices);
2,115✔
1686
        if (r < 0)
2,115✔
1687
                return r;
1688

1689
        r = serialize_bool_elide(f, "exec-context-protect-kernel-tunables", c->protect_kernel_tunables);
2,115✔
1690
        if (r < 0)
2,115✔
1691
                return r;
1692

1693
        r = serialize_bool_elide(f, "exec-context-protect-kernel-modules", c->protect_kernel_modules);
2,115✔
1694
        if (r < 0)
2,115✔
1695
                return r;
1696

1697
        r = serialize_bool_elide(f, "exec-context-protect-kernel-logs", c->protect_kernel_logs);
2,115✔
1698
        if (r < 0)
2,115✔
1699
                return r;
1700

1701
        r = serialize_bool_elide(f, "exec-context-protect-clock", c->protect_clock);
2,115✔
1702
        if (r < 0)
2,115✔
1703
                return r;
1704

1705
        r = serialize_item(f, "exec-context-protect-control-groups", protect_control_groups_to_string(c->protect_control_groups));
2,115✔
1706
        if (r < 0)
2,115✔
1707
                return r;
1708

1709
        r = serialize_bool_elide(f, "exec-context-private-network", c->private_network);
2,115✔
1710
        if (r < 0)
2,115✔
1711
                return r;
1712

1713
        r = serialize_item(f, "exec-context-private-users", private_users_to_string(c->private_users));
2,115✔
1714
        if (r < 0)
2,115✔
1715
                return r;
1716

1717
        r = serialize_bool_elide(f, "exec-context-private-ipc", c->private_ipc);
2,115✔
1718
        if (r < 0)
2,115✔
1719
                return r;
1720

1721
        r = serialize_item(f, "exec-context-private-pids", private_pids_to_string(c->private_pids));
2,115✔
1722
        if (r < 0)
2,115✔
1723
                return r;
1724

1725
        r = serialize_bool_elide(f, "exec-context-remove-ipc", c->remove_ipc);
2,115✔
1726
        if (r < 0)
2,115✔
1727
                return r;
1728

1729
        r = serialize_item(f, "exec-context-protect-home", protect_home_to_string(c->protect_home));
2,115✔
1730
        if (r < 0)
2,115✔
1731
                return r;
1732

1733
        r = serialize_item(f, "exec-context-protect-system", protect_system_to_string(c->protect_system));
2,115✔
1734
        if (r < 0)
2,115✔
1735
                return r;
1736

1737
        r = serialize_bool_elide(f, "exec-context-same-pgrp", c->same_pgrp);
2,115✔
1738
        if (r < 0)
2,115✔
1739
                return r;
1740

1741
        r = serialize_bool(f, "exec-context-ignore-sigpipe", c->ignore_sigpipe);
2,115✔
1742
        if (r < 0)
2,115✔
1743
                return r;
1744

1745
        r = serialize_bool_elide(f, "exec-context-memory-deny-write-execute", c->memory_deny_write_execute);
2,115✔
1746
        if (r < 0)
2,115✔
1747
                return r;
1748

1749
        r = serialize_bool_elide(f, "exec-context-restrict-realtime", c->restrict_realtime);
2,115✔
1750
        if (r < 0)
2,115✔
1751
                return r;
1752

1753
        r = serialize_bool_elide(f, "exec-context-restrict-suid-sgid", c->restrict_suid_sgid);
2,115✔
1754
        if (r < 0)
2,115✔
1755
                return r;
1756

1757
        r = serialize_item(f, "exec-context-keyring-mode", exec_keyring_mode_to_string(c->keyring_mode));
2,115✔
1758
        if (r < 0)
2,115✔
1759
                return r;
1760

1761
        r = serialize_item(f, "exec-context-protect-hostname", protect_hostname_to_string(c->protect_hostname));
2,115✔
1762
        if (r < 0)
2,115✔
1763
                return r;
1764

1765
        r = serialize_item(f, "exec-context-private-hostname", c->private_hostname);
2,115✔
1766
        if (r < 0)
2,115✔
1767
                return r;
1768

1769
        r = serialize_item(f, "exec-context-protect-proc", protect_proc_to_string(c->protect_proc));
2,115✔
1770
        if (r < 0)
2,115✔
1771
                return r;
1772

1773
        r = serialize_item(f, "exec-context-proc-subset", proc_subset_to_string(c->proc_subset));
2,115✔
1774
        if (r < 0)
2,115✔
1775
                return r;
1776

1777
        r = serialize_item(f, "exec-context-private-bpf", private_bpf_to_string(c->private_bpf));
2,115✔
1778
        if (r < 0)
2,115✔
1779
                return r;
1780

1781
        if (c->bpf_delegate_commands != 0) {
2,115✔
UNCOV
1782
                r = serialize_item_format(f, "exec-context-bpf-delegate-commands", "0x%"PRIx64, c->bpf_delegate_commands);
×
UNCOV
1783
                if (r < 0)
×
1784
                        return r;
1785
        }
1786

1787
        if (c->bpf_delegate_maps != 0) {
2,115✔
UNCOV
1788
                r = serialize_item_format(f, "exec-context-bpf-delegate-maps", "0x%"PRIx64, c->bpf_delegate_maps);
×
UNCOV
1789
                if (r < 0)
×
1790
                        return r;
1791
        }
1792

1793
        if (c->bpf_delegate_programs != 0) {
2,115✔
UNCOV
1794
                r = serialize_item_format(f, "exec-context-bpf-delegate-programs", "0x%"PRIx64, c->bpf_delegate_programs);
×
UNCOV
1795
                if (r < 0)
×
1796
                        return r;
1797
        }
1798

1799
        if (c->bpf_delegate_attachments != 0) {
2,115✔
UNCOV
1800
                r = serialize_item_format(f, "exec-context-bpf-delegate-attachments", "0x%"PRIx64, c->bpf_delegate_attachments);
×
UNCOV
1801
                if (r < 0)
×
1802
                        return r;
1803
        }
1804

1805
        r = serialize_item(f, "exec-context-runtime-directory-preserve-mode", exec_preserve_mode_to_string(c->runtime_directory_preserve_mode));
2,115✔
1806
        if (r < 0)
2,115✔
1807
                return r;
1808

1809
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
12,690✔
1810
                _cleanup_free_ char *key = NULL, *value = NULL;
10,575✔
1811

1812
                key = strjoin("exec-context-directories-", exec_directory_type_to_string(dt));
10,575✔
1813
                if (!key)
10,575✔
UNCOV
1814
                        return log_oom_debug();
×
1815

1816
                if (asprintf(&value, "%04o", c->directories[dt].mode) < 0)
10,575✔
1817
                        return log_oom_debug();
×
1818

1819
                FOREACH_ARRAY(i, c->directories[dt].items, c->directories[dt].n_items) {
10,980✔
1820
                        _cleanup_free_ char *path_escaped = NULL;
405✔
1821

1822
                        path_escaped = shell_escape(i->path, ":" WHITESPACE);
405✔
1823
                        if (!path_escaped)
405✔
1824
                                return log_oom_debug();
×
1825

1826
                        if (!strextend(&value, " ", path_escaped))
405✔
UNCOV
1827
                                return log_oom_debug();
×
1828

1829
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_ONLY_CREATE))))
805✔
1830
                                return log_oom_debug();
×
1831

1832
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_READ_ONLY))))
808✔
UNCOV
1833
                                return log_oom_debug();
×
1834

1835
                        STRV_FOREACH(d, i->symlinks) {
411✔
1836
                                _cleanup_free_ char *link_escaped = NULL;
6✔
1837

1838
                                link_escaped = shell_escape(*d, ":" WHITESPACE);
6✔
1839
                                if (!link_escaped)
6✔
UNCOV
1840
                                        return log_oom_debug();
×
1841

1842
                                if (!strextend(&value, ":", link_escaped))
6✔
1843
                                        return log_oom_debug();
×
1844
                        }
1845
                }
1846

1847
                r = serialize_item(f, key, value);
10,575✔
1848
                if (r < 0)
10,575✔
1849
                        return r;
1850

1851
                if (c->directories[dt].exec_quota.quota_enforce) {
10,575✔
UNCOV
1852
                        _cleanup_free_ char *key_quota = NULL;
×
1853
                        key_quota = strjoin("exec-context-quota-directories-", exec_directory_type_to_string(dt));
×
UNCOV
1854
                        if (!key_quota)
×
UNCOV
1855
                                return log_oom_debug();
×
1856

UNCOV
1857
                        r = serialize_item_format(f, key_quota, "%" PRIu64 " %" PRIu32, c->directories[dt].exec_quota.quota_absolute,
×
UNCOV
1858
                                                                                        c->directories[dt].exec_quota.quota_scale);
×
1859
                        if (r < 0)
×
1860
                                return r;
1861

1862
                } else if (c->directories[dt].exec_quota.quota_accounting) {
10,575✔
UNCOV
1863
                        _cleanup_free_ char *key_quota = NULL;
×
UNCOV
1864
                        key_quota = strjoin("exec-context-quota-accounting-directories-", exec_directory_type_to_string(dt));
×
UNCOV
1865
                        if (!key_quota)
×
UNCOV
1866
                                return log_oom_debug();
×
1867

UNCOV
1868
                        r = serialize_bool(f, key_quota, c->directories[dt].exec_quota.quota_accounting);
×
1869
                        if (r < 0)
×
1870
                                return r;
1871
                }
1872
        }
1873

1874
        r = serialize_usec(f, "exec-context-timeout-clean-usec", c->timeout_clean_usec);
2,115✔
1875
        if (r < 0)
2,115✔
1876
                return r;
1877

1878
        if (c->nice_set) {
2,115✔
1879
                r = serialize_item_format(f, "exec-context-nice", "%i", c->nice);
2✔
1880
                if (r < 0)
2✔
1881
                        return r;
1882
        }
1883

1884
        if (c->oom_score_adjust_set) {
2,115✔
1885
                r = serialize_item_format(f, "exec-context-oom-score-adjust", "%i", c->oom_score_adjust);
574✔
1886
                if (r < 0)
574✔
1887
                        return r;
1888
        }
1889

1890
        if (c->coredump_filter_set) {
2,115✔
UNCOV
1891
                r = serialize_item_format(f, "exec-context-coredump-filter", "%"PRIx64, c->coredump_filter);
×
1892
                if (r < 0)
×
1893
                        return r;
1894
        }
1895

1896
        for (unsigned i = 0; i < RLIM_NLIMITS; i++) {
35,955✔
1897
                _cleanup_free_ char *key = NULL, *limit = NULL;
4,223✔
1898

1899
                if (!c->rlimit[i])
33,840✔
1900
                        continue;
29,617✔
1901

1902
                key = strjoin("exec-context-limit-", rlimit_to_string(i));
4,223✔
1903
                if (!key)
4,223✔
UNCOV
1904
                        return log_oom_debug();
×
1905

1906
                r = rlimit_format(c->rlimit[i], &limit);
4,223✔
1907
                if (r < 0)
4,223✔
1908
                        return r;
1909

1910
                r = serialize_item(f, key, limit);
4,223✔
1911
                if (r < 0)
4,223✔
1912
                        return r;
1913
        }
1914

1915
        if (c->ioprio_is_set) {
2,115✔
1916
                r = serialize_item_format(f, "exec-context-ioprio", "%d", c->ioprio);
5✔
1917
                if (r < 0)
5✔
1918
                        return r;
1919
        }
1920

1921
        if (c->cpu_sched_set) {
2,115✔
UNCOV
1922
                _cleanup_free_ char *policy_str = NULL;
×
1923

UNCOV
1924
                r = sched_policy_to_string_alloc(c->cpu_sched_policy, &policy_str);
×
UNCOV
1925
                if (r < 0)
×
1926
                        return r;
1927

UNCOV
1928
                r = serialize_item(f, "exec-context-cpu-scheduling-policy", policy_str);
×
UNCOV
1929
                if (r < 0)
×
1930
                        return r;
1931

UNCOV
1932
                r = serialize_item_format(f, "exec-context-cpu-scheduling-priority", "%i", c->cpu_sched_priority);
×
1933
                if (r < 0)
×
1934
                        return r;
1935

UNCOV
1936
                r = serialize_bool_elide(f, "exec-context-cpu-scheduling-reset-on-fork", c->cpu_sched_reset_on_fork);
×
UNCOV
1937
                if (r < 0)
×
1938
                        return r;
1939
        }
1940

1941
        if (c->cpu_set.set) {
2,115✔
UNCOV
1942
                _cleanup_free_ char *affinity = NULL;
×
1943

UNCOV
1944
                affinity = cpu_set_to_range_string(&c->cpu_set);
×
UNCOV
1945
                if (!affinity)
×
UNCOV
1946
                        return log_oom_debug();
×
1947

UNCOV
1948
                r = serialize_item(f, "exec-context-cpu-affinity", affinity);
×
UNCOV
1949
                if (r < 0)
×
1950
                        return r;
1951
        }
1952

1953
        if (mpol_is_valid(numa_policy_get_type(&c->numa_policy))) {
2,115✔
1954
                _cleanup_free_ char *nodes = NULL;
×
1955

UNCOV
1956
                nodes = cpu_set_to_range_string(&c->numa_policy.nodes);
×
1957
                if (!nodes)
×
1958
                        return log_oom_debug();
×
1959

UNCOV
1960
                if (nodes) {
×
1961
                        r = serialize_item(f, "exec-context-numa-mask", nodes);
×
1962
                        if (r < 0)
×
1963
                                return r;
1964
                }
1965

1966
                r = serialize_item_format(f, "exec-context-numa-policy", "%d", c->numa_policy.type);
×
UNCOV
1967
                if (r < 0)
×
1968
                        return r;
1969
        }
1970

1971
        r = serialize_bool_elide(f, "exec-context-cpu-affinity-from-numa", c->cpu_affinity_from_numa);
2,115✔
1972
        if (r < 0)
2,115✔
1973
                return r;
1974

1975
        if (c->timer_slack_nsec != NSEC_INFINITY) {
2,115✔
UNCOV
1976
                r = serialize_item_format(f, "exec-context-timer-slack-nsec", NSEC_FMT, c->timer_slack_nsec);
×
1977
                if (r < 0)
×
1978
                        return r;
1979
        }
1980

1981
        r = serialize_item(f, "exec-context-std-input", exec_input_to_string(c->std_input));
2,115✔
1982
        if (r < 0)
2,115✔
1983
                return r;
1984

1985
        r = serialize_item(f, "exec-context-std-output", exec_output_to_string(c->std_output));
2,115✔
1986
        if (r < 0)
2,115✔
1987
                return r;
1988

1989
        r = serialize_item(f, "exec-context-std-error", exec_output_to_string(c->std_error));
2,115✔
1990
        if (r < 0)
2,115✔
1991
                return r;
1992

1993
        r = serialize_bool_elide(f, "exec-context-stdio-as-fds", c->stdio_as_fds);
2,115✔
1994
        if (r < 0)
2,115✔
1995
                return r;
1996

1997
        switch (c->std_input) {
2,115✔
UNCOV
1998
        case EXEC_INPUT_NAMED_FD:
×
UNCOV
1999
                r = serialize_item(f, "exec-context-std-input-fd-name", c->stdio_fdname[STDIN_FILENO]);
×
UNCOV
2000
                if (r < 0)
×
2001
                        return r;
2002
                break;
2003

UNCOV
2004
        case EXEC_INPUT_FILE:
×
2005
                r = serialize_item(f, "exec-context-std-input-file", c->stdio_file[STDIN_FILENO]);
×
2006
                if (r < 0)
×
2007
                        return r;
2008
                break;
2009

2010
        default:
2,115✔
2011
                ;
2,115✔
2012
        }
2013

2014
        r = serialize_std_out_err(c, f, STDOUT_FILENO);
2,115✔
2015
        if (r < 0)
2,115✔
2016
                return r;
2017

2018
        r = serialize_std_out_err(c, f, STDERR_FILENO);
2,115✔
2019
        if (r < 0)
2,115✔
2020
                return r;
2021

2022
        r = serialize_item_base64mem(f, "exec-context-stdin-data", c->stdin_data, c->stdin_data_size);
2,115✔
2023
        if (r < 0)
2,115✔
2024
                return r;
2025

2026
        r = serialize_item(f, "exec-context-tty-path", c->tty_path);
2,115✔
2027
        if (r < 0)
2,115✔
2028
                return r;
2029

2030
        r = serialize_bool_elide(f, "exec-context-tty-reset", c->tty_reset);
2,115✔
2031
        if (r < 0)
2,115✔
2032
                return r;
2033

2034
        r = serialize_bool_elide(f, "exec-context-tty-vhangup", c->tty_vhangup);
2,115✔
2035
        if (r < 0)
2,115✔
2036
                return r;
2037

2038
        r = serialize_bool_elide(f, "exec-context-tty-vt-disallocate", c->tty_vt_disallocate);
2,115✔
2039
        if (r < 0)
2,115✔
2040
                return r;
2041

2042
        r = serialize_item_format(f, "exec-context-tty-rows", "%u", c->tty_rows);
2,115✔
2043
        if (r < 0)
2,115✔
2044
                return r;
2045

2046
        r = serialize_item_format(f, "exec-context-tty-columns", "%u", c->tty_cols);
2,115✔
2047
        if (r < 0)
2,115✔
2048
                return r;
2049

2050
        r = serialize_item_format(f, "exec-context-syslog-priority", "%i", c->syslog_priority);
2,115✔
2051
        if (r < 0)
2,115✔
2052
                return r;
2053

2054
        r = serialize_bool(f, "exec-context-syslog-level-prefix", c->syslog_level_prefix);
2,115✔
2055
        if (r < 0)
2,115✔
2056
                return r;
2057

2058
        r = serialize_item(f, "exec-context-syslog-identifier", c->syslog_identifier);
2,115✔
2059
        if (r < 0)
2,115✔
2060
                return r;
2061

2062
        /* This is also passed to executor as an argument. So, the information should be redundant in general.
2063
         * But, let's keep this as is for consistency with other elements of ExecContext. See exec_spawn(). */
2064
        r = serialize_item_format(f, "exec-context-log-level-max", "%d", c->log_level_max);
2,115✔
2065
        if (r < 0)
2,115✔
2066
                return r;
2067

2068
        if (c->log_ratelimit.interval > 0) {
2,115✔
UNCOV
2069
                r = serialize_usec(f, "exec-context-log-ratelimit-interval-usec", c->log_ratelimit.interval);
×
UNCOV
2070
                if (r < 0)
×
2071
                        return r;
2072
        }
2073

2074
        if (c->log_ratelimit.burst > 0) {
2,115✔
UNCOV
2075
                r = serialize_item_format(f, "exec-context-log-ratelimit-burst", "%u", c->log_ratelimit.burst);
×
UNCOV
2076
                if (r < 0)
×
2077
                        return r;
2078
        }
2079

2080
        r = serialize_string_set(f, "exec-context-log-filter-allowed-patterns", c->log_filter_allowed_patterns);
2,115✔
2081
        if (r < 0)
2,115✔
2082
                return r;
2083

2084
        r = serialize_string_set(f, "exec-context-log-filter-denied-patterns", c->log_filter_denied_patterns);
2,115✔
2085
        if (r < 0)
2,115✔
2086
                return r;
2087

2088
        FOREACH_ARRAY(field, c->log_extra_fields, c->n_log_extra_fields) {
2,115✔
UNCOV
2089
                r = serialize_item(f, "exec-context-log-extra-fields", field->iov_base);
×
UNCOV
2090
                if (r < 0)
×
2091
                        return r;
2092
        }
2093

2094
        r = serialize_item(f, "exec-context-log-namespace", c->log_namespace);
2,115✔
2095
        if (r < 0)
2,115✔
2096
                return r;
2097

2098
        if (c->secure_bits != 0) {
2,115✔
2099
                r = serialize_item_format(f, "exec-context-secure-bits", "%d", c->secure_bits);
×
UNCOV
2100
                if (r < 0)
×
2101
                        return r;
2102
        }
2103

2104
        if (c->capability_bounding_set != CAP_MASK_UNSET) {
2,115✔
2105
                r = serialize_item_format(f, "exec-context-capability-bounding-set", "%" PRIu64, c->capability_bounding_set);
250✔
2106
                if (r < 0)
250✔
2107
                        return r;
2108
        }
2109

2110
        if (c->capability_ambient_set != 0) {
2,115✔
2111
                r = serialize_item_format(f, "exec-context-capability-ambient-set", "%" PRIu64, c->capability_ambient_set);
63✔
2112
                if (r < 0)
63✔
2113
                        return r;
2114
        }
2115

2116
        if (c->user) {
2,115✔
2117
                r = serialize_item(f, "exec-context-user", c->user);
144✔
2118
                if (r < 0)
144✔
2119
                        return r;
2120
        }
2121

2122
        r = serialize_item(f, "exec-context-group", c->group);
2,115✔
2123
        if (r < 0)
2,115✔
2124
                return r;
2125

2126
        r = serialize_bool_elide(f, "exec-context-dynamic-user", c->dynamic_user);
2,115✔
2127
        if (r < 0)
2,115✔
2128
                return r;
2129

2130
        r = serialize_strv(f, "exec-context-supplementary-groups", c->supplementary_groups);
2,115✔
2131
        if (r < 0)
2,115✔
2132
                return r;
2133

2134
        r = serialize_item_tristate(f, "exec-context-set-login-environment", c->set_login_environment);
2,115✔
UNCOV
2135
        if (r < 0)
×
2136
                return r;
2137

2138
        r = serialize_item(f, "exec-context-pam-name", c->pam_name);
2,115✔
2139
        if (r < 0)
2,115✔
2140
                return r;
2141

2142
        r = serialize_strv(f, "exec-context-read-write-paths", c->read_write_paths);
2,115✔
2143
        if (r < 0)
2,115✔
2144
                return r;
2145

2146
        r = serialize_strv(f, "exec-context-read-only-paths", c->read_only_paths);
2,115✔
2147
        if (r < 0)
2,115✔
2148
                return r;
2149

2150
        r = serialize_strv(f, "exec-context-inaccessible-paths", c->inaccessible_paths);
2,115✔
2151
        if (r < 0)
2,115✔
2152
                return r;
2153

2154
        r = serialize_strv(f, "exec-context-exec-paths", c->exec_paths);
2,115✔
2155
        if (r < 0)
2,115✔
2156
                return r;
2157

2158
        r = serialize_strv(f, "exec-context-no-exec-paths", c->no_exec_paths);
2,115✔
2159
        if (r < 0)
2,115✔
2160
                return r;
2161

2162
        r = serialize_strv(f, "exec-context-exec-search-path", c->exec_search_path);
2,115✔
2163
        if (r < 0)
2,115✔
2164
                return r;
2165

2166
        r = serialize_item_format(f, "exec-context-mount-propagation-flag", "%lu", c->mount_propagation_flag);
2,115✔
2167
        if (r < 0)
2,115✔
2168
                return r;
2169

2170
        FOREACH_ARRAY(mount, c->bind_mounts, c->n_bind_mounts) {
2,130✔
2171
                _cleanup_free_ char *src_escaped = NULL, *dst_escaped = NULL;
15✔
2172

2173
                src_escaped = shell_escape(mount->source, ":" WHITESPACE);
15✔
2174
                if (!src_escaped)
15✔
UNCOV
2175
                        return log_oom_debug();
×
2176

2177
                dst_escaped = shell_escape(mount->destination, ":" WHITESPACE);
15✔
2178
                if (!dst_escaped)
15✔
UNCOV
2179
                        return log_oom_debug();
×
2180

2181
                r = serialize_item_format(f,
15✔
2182
                                          mount->read_only ? "exec-context-bind-read-only-path" : "exec-context-bind-path",
15✔
2183
                                          "%s%s:%s:%s",
2184
                                          mount->ignore_enoent ? "-" : "",
15✔
2185
                                          src_escaped,
2186
                                          dst_escaped,
2187
                                          mount->recursive ? "rbind" : "norbind");
15✔
2188
                if (r < 0)
15✔
2189
                        return r;
2190
        }
2191

2192
        FOREACH_ARRAY(tmpfs, c->temporary_filesystems, c->n_temporary_filesystems) {
2,119✔
2193
                _cleanup_free_ char *escaped = NULL;
4✔
2194

2195
                if (!isempty(tmpfs->options)) {
4✔
UNCOV
2196
                        escaped = shell_escape(tmpfs->options, ":");
×
UNCOV
2197
                        if (!escaped)
×
UNCOV
2198
                                return log_oom_debug();
×
2199
                }
2200

UNCOV
2201
                r = serialize_item_format(f, "exec-context-temporary-filesystems", "%s%s%s",
×
2202
                                          tmpfs->path,
2203
                                          isempty(escaped) ? "" : ":",
4✔
2204
                                          strempty(escaped));
2205
                if (r < 0)
4✔
2206
                        return r;
2207
        }
2208

2209
        r = serialize_item(f, "exec-context-utmp-id", c->utmp_id);
2,115✔
2210
        if (r < 0)
2,115✔
2211
                return r;
2212

2213
        r = serialize_item(f, "exec-context-utmp-mode", exec_utmp_mode_to_string(c->utmp_mode));
2,115✔
2214
        if (r < 0)
2,115✔
2215
                return r;
2216

2217
        r = serialize_bool_elide(f, "exec-context-no-new-privileges", c->no_new_privileges);
2,115✔
2218
        if (r < 0)
2,115✔
2219
                return r;
2220

2221
        if (c->selinux_context) {
2,115✔
UNCOV
2222
                r = serialize_item_format(f, "exec-context-selinux-context",
×
2223
                                          "%s%s",
UNCOV
2224
                                          c->selinux_context_ignore ? "-" : "",
×
2225
                                          c->selinux_context);
2226
                if (r < 0)
×
2227
                        return r;
2228
        }
2229

2230
        if (c->apparmor_profile) {
2,115✔
UNCOV
2231
                r = serialize_item_format(f, "exec-context-apparmor-profile",
×
2232
                                          "%s%s",
UNCOV
2233
                                          c->apparmor_profile_ignore ? "-" : "",
×
2234
                                          c->apparmor_profile);
UNCOV
2235
                if (r < 0)
×
2236
                        return r;
2237
        }
2238

2239
        if (c->smack_process_label) {
2,115✔
UNCOV
2240
                r = serialize_item_format(f, "exec-context-smack-process-label",
×
2241
                                          "%s%s",
UNCOV
2242
                                          c->smack_process_label_ignore ? "-" : "",
×
2243
                                          c->smack_process_label);
UNCOV
2244
                if (r < 0)
×
2245
                        return r;
2246
        }
2247

2248
        if (c->personality != PERSONALITY_INVALID) {
2,115✔
UNCOV
2249
                r = serialize_item(f, "exec-context-personality", personality_to_string(c->personality));
×
UNCOV
2250
                if (r < 0)
×
2251
                        return r;
2252
        }
2253

2254
        r = serialize_bool_elide(f, "exec-context-lock-personality", c->lock_personality);
2,115✔
2255
        if (r < 0)
2,115✔
2256
                return r;
2257

2258
#if HAVE_SECCOMP
2259
        if (!hashmap_isempty(c->syscall_filter)) {
2,115✔
2260
                void *errno_num, *id;
211✔
2261
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_filter) {
82,707✔
2262
                        r = serialize_item_format(f, "exec-context-syscall-filter", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
82,496✔
2263
                        if (r < 0)
82,496✔
2264
                                return r;
×
2265
                }
2266
        }
2267

2268
        if (!set_isempty(c->syscall_archs)) {
2,115✔
2269
                void *id;
211✔
2270
                SET_FOREACH(id, c->syscall_archs) {
422✔
2271
                        r = serialize_item_format(f, "exec-context-syscall-archs", "%u", PTR_TO_UINT(id) - 1);
211✔
2272
                        if (r < 0)
211✔
2273
                                return r;
×
2274
                }
2275
        }
2276

2277
        if (c->syscall_errno > 0) {
2,115✔
2278
                r = serialize_item_format(f, "exec-context-syscall-errno", "%d", c->syscall_errno);
2,115✔
2279
                if (r < 0)
2,115✔
2280
                        return r;
2281
        }
2282

2283
        r = serialize_bool_elide(f, "exec-context-syscall-allow-list", c->syscall_allow_list);
2,115✔
2284
        if (r < 0)
2,115✔
2285
                return r;
2286

2287
        if (!hashmap_isempty(c->syscall_log)) {
2,115✔
UNCOV
2288
                void *errno_num, *id;
×
UNCOV
2289
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_log) {
×
UNCOV
2290
                        r = serialize_item_format(f, "exec-context-syscall-log", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
×
UNCOV
2291
                        if (r < 0)
×
UNCOV
2292
                                return r;
×
2293
                }
2294
        }
2295

2296
        r = serialize_bool_elide(f, "exec-context-syscall-log-allow-list", c->syscall_log_allow_list);
2,115✔
2297
        if (r < 0)
2,115✔
2298
                return r;
2299
#endif
2300

2301
        if (c->restrict_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,115✔
2302
                r = serialize_item_format(f, "exec-context-restrict-namespaces", "%lu", c->restrict_namespaces);
167✔
2303
                if (r < 0)
167✔
2304
                        return r;
2305
        }
2306

2307
        if (c->delegate_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,115✔
2308
                r = serialize_item_format(f, "exec-context-delegate-namespaces", "%lu", c->delegate_namespaces);
9✔
2309
                if (r < 0)
9✔
2310
                        return r;
2311
        }
2312

2313
#if HAVE_LIBBPF
2314
        if (exec_context_restrict_filesystems_set(c)) {
2,115✔
UNCOV
2315
                char *fs;
×
UNCOV
2316
                SET_FOREACH(fs, c->restrict_filesystems) {
×
2317
                        r = serialize_item(f, "exec-context-restrict-filesystems", fs);
×
2318
                        if (r < 0)
×
2319
                                return r;
×
2320
                }
2321
        }
2322

2323
        r = serialize_bool_elide(f, "exec-context-restrict-filesystems-allow-list", c->restrict_filesystems_allow_list);
2,115✔
2324
        if (r < 0)
2,115✔
2325
                return r;
2326
#endif
2327

2328
        if (!set_isempty(c->address_families)) {
2,115✔
2329
                void *afp;
211✔
2330

2331
                SET_FOREACH(afp, c->address_families) {
1,033✔
2332
                        int af = PTR_TO_INT(afp);
822✔
2333

2334
                        if (af <= 0 || af >= af_max())
822✔
UNCOV
2335
                                continue;
×
2336

2337
                        r = serialize_item_format(f, "exec-context-address-families", "%d", af);
822✔
2338
                        if (r < 0)
822✔
UNCOV
2339
                                return r;
×
2340
                }
2341
        }
2342

2343
        r = serialize_bool_elide(f, "exec-context-address-families-allow-list", c->address_families_allow_list);
2,115✔
2344
        if (r < 0)
2,115✔
2345
                return r;
2346

2347
        r = serialize_item(f, "exec-context-network-namespace-path", c->network_namespace_path);
2,115✔
2348
        if (r < 0)
2,115✔
2349
                return r;
2350

2351
        r = serialize_item(f, "exec-context-ipc-namespace-path", c->ipc_namespace_path);
2,115✔
2352
        if (r < 0)
2,115✔
2353
                return r;
2354

2355
        FOREACH_ARRAY(mount, c->mount_images, c->n_mount_images) {
2,115✔
UNCOV
2356
                _cleanup_free_ char *s = NULL, *source_escaped = NULL, *dest_escaped = NULL;
×
2357

UNCOV
2358
                source_escaped = shell_escape(mount->source, WHITESPACE);
×
UNCOV
2359
                if (!source_escaped)
×
UNCOV
2360
                        return log_oom_debug();
×
2361

UNCOV
2362
                dest_escaped = shell_escape(mount->destination, WHITESPACE);
×
UNCOV
2363
                if (!dest_escaped)
×
2364
                        return log_oom_debug();
×
2365

UNCOV
2366
                s = strjoin(mount->ignore_enoent ? "-" : "",
×
2367
                            source_escaped,
2368
                            " ",
2369
                            dest_escaped);
UNCOV
2370
                if (!s)
×
UNCOV
2371
                        return log_oom_debug();
×
2372

UNCOV
2373
                LIST_FOREACH(mount_options, o, mount->mount_options) {
×
UNCOV
2374
                        _cleanup_free_ char *escaped = NULL;
×
2375

UNCOV
2376
                        if (isempty(o->options))
×
UNCOV
2377
                                continue;
×
2378

UNCOV
2379
                        escaped = shell_escape(o->options, ":");
×
UNCOV
2380
                        if (!escaped)
×
UNCOV
2381
                                return log_oom_debug();
×
2382

UNCOV
2383
                        if (!strextend(&s,
×
2384
                                       " ",
2385
                                       partition_designator_to_string(o->partition_designator),
2386
                                       ":",
2387
                                       escaped))
2388
                                return log_oom_debug();
×
2389
                }
2390

2391
                r = serialize_item(f, "exec-context-mount-image", s);
×
2392
                if (r < 0)
×
2393
                        return r;
2394
        }
2395

2396
        FOREACH_ARRAY(mount, c->extension_images, c->n_extension_images) {
2,120✔
2397
                _cleanup_free_ char *s = NULL, *source_escaped = NULL;
5✔
2398

2399
                source_escaped = shell_escape(mount->source, ":" WHITESPACE);
5✔
2400
                if (!source_escaped)
5✔
UNCOV
2401
                        return log_oom_debug();
×
2402

2403
                s = strjoin(mount->ignore_enoent ? "-" : "",
10✔
2404
                            source_escaped);
2405
                if (!s)
5✔
2406
                        return log_oom_debug();
×
2407

2408
                LIST_FOREACH(mount_options, o, mount->mount_options) {
5✔
2409
                        _cleanup_free_ char *escaped = NULL;
×
2410

UNCOV
2411
                        if (isempty(o->options))
×
2412
                                continue;
×
2413

UNCOV
2414
                        escaped = shell_escape(o->options, ":");
×
UNCOV
2415
                        if (!escaped)
×
UNCOV
2416
                                return log_oom_debug();
×
2417

UNCOV
2418
                        if (!strextend(&s,
×
2419
                                       " ",
2420
                                       partition_designator_to_string(o->partition_designator),
2421
                                       ":",
2422
                                       escaped))
UNCOV
2423
                                return log_oom_debug();
×
2424
                }
2425

2426
                r = serialize_item(f, "exec-context-extension-image", s);
5✔
2427
                if (r < 0)
5✔
2428
                        return r;
2429
        }
2430

2431
        r = serialize_strv(f, "exec-context-extension-directories", c->extension_directories);
2,115✔
2432
        if (r < 0)
2,115✔
2433
                return r;
2434

2435
        ExecSetCredential *sc;
2,115✔
2436
        HASHMAP_FOREACH(sc, c->set_credentials) {
2,115✔
UNCOV
2437
                _cleanup_free_ char *data = NULL;
×
2438

UNCOV
2439
                if (base64mem(sc->data, sc->size, &data) < 0)
×
2440
                        return log_oom_debug();
×
2441

UNCOV
2442
                r = serialize_item_format(f, "exec-context-set-credentials", "%s %s %s", sc->id, data, yes_no(sc->encrypted));
×
2443
                if (r < 0)
×
2444
                        return r;
2445
        }
2446

2447
        ExecLoadCredential *lc;
2,115✔
2448
        HASHMAP_FOREACH(lc, c->load_credentials) {
2,123✔
2449
                r = serialize_item_format(f, "exec-context-load-credentials", "%s %s %s", lc->id, lc->path, yes_no(lc->encrypted));
15✔
2450
                if (r < 0)
8✔
UNCOV
2451
                        return r;
×
2452
        }
2453

2454
        ExecImportCredential *ic;
2,115✔
2455
        ORDERED_SET_FOREACH(ic, c->import_credentials) {
3,027✔
2456
                r = serialize_item_format(f, "exec-context-import-credentials", "%s%s%s",
1,774✔
2457
                                          ic->glob,
2458
                                          ic->rename ? " " : "",
2459
                                          strempty(ic->rename));
912✔
2460
                if (r < 0)
912✔
UNCOV
2461
                        return r;
×
2462
        }
2463

2464
        r = serialize_image_policy(f, "exec-context-root-image-policy", c->root_image_policy);
2,115✔
2465
        if (r < 0)
2,115✔
2466
                return r;
2467

2468
        r = serialize_image_policy(f, "exec-context-mount-image-policy", c->mount_image_policy);
2,115✔
2469
        if (r < 0)
2,115✔
2470
                return r;
2471

2472
        r = serialize_image_policy(f, "exec-context-extension-image-policy", c->extension_image_policy);
2,115✔
2473
        if (r < 0)
2,115✔
2474
                return r;
2475

2476
        fputc('\n', f); /* End marker */
2,115✔
2477

2478
        return 0;
2479
}
2480

2481
static int exec_context_deserialize(ExecContext *c, FILE *f) {
11,867✔
2482
        int r;
11,867✔
2483

2484
        assert(f);
11,867✔
2485

2486
        if (!c)
11,867✔
2487
                return 0;
2488

2489
        for (;;) {
1,308,201✔
2490
                _cleanup_free_ char *l = NULL;
1,296,334✔
2491
                const char *val;
1,308,201✔
2492

2493
                r = deserialize_read_line(f, &l);
1,308,201✔
2494
                if (r < 0)
1,308,201✔
2495
                        return r;
2496
                if (r == 0) /* eof or end marker */
1,308,201✔
2497
                        break;
2498

2499
                if ((val = startswith(l, "exec-context-environment="))) {
1,296,334✔
2500
                        r = deserialize_strv(val, &c->environment);
3,857✔
2501
                        if (r < 0)
3,857✔
2502
                                return r;
2503
                } else if ((val = startswith(l, "exec-context-environment-files="))) {
1,292,477✔
2504
                        r = deserialize_strv(val, &c->environment_files);
341✔
2505
                        if (r < 0)
341✔
2506
                                return r;
2507
                } else if ((val = startswith(l, "exec-context-pass-environment="))) {
1,292,136✔
2508
                        r = deserialize_strv(val, &c->pass_environment);
440✔
2509
                        if (r < 0)
440✔
2510
                                return r;
2511
                } else if ((val = startswith(l, "exec-context-unset-environment="))) {
1,291,696✔
2512
                        r = deserialize_strv(val, &c->unset_environment);
1,543✔
2513
                        if (r < 0)
1,543✔
2514
                                return r;
2515
                } else if ((val = startswith(l, "exec-context-working-directory="))) {
1,290,153✔
2516
                        ssize_t k;
736✔
2517
                        char *p;
736✔
2518

2519
                        k = cunescape(val, 0, &p);
736✔
2520
                        if (k < 0)
736✔
UNCOV
2521
                                return k;
×
2522
                        free_and_replace(c->working_directory, p);
736✔
2523
                } else if ((val = startswith(l, "exec-context-root-directory="))) {
1,289,417✔
2524
                        ssize_t k;
7✔
2525
                        char *p;
7✔
2526

2527
                        k = cunescape(val, 0, &p);
7✔
2528
                        if (k < 0)
7✔
UNCOV
2529
                                return k;
×
2530
                        free_and_replace(c->root_directory, p);
7✔
2531
                } else if ((val = startswith(l, "exec-context-root-image="))) {
1,289,410✔
2532
                        ssize_t k;
9✔
2533
                        char *p;
9✔
2534

2535
                        k = cunescape(val, 0, &p);
9✔
2536
                        if (k < 0)
9✔
UNCOV
2537
                                return k;
×
2538
                        free_and_replace(c->root_image, p);
9✔
2539
                } else if ((val = startswith(l, "exec-context-root-image-options="))) {
1,289,401✔
UNCOV
2540
                        for (;;) {
×
UNCOV
2541
                                _cleanup_free_ char *word = NULL, *mount_options = NULL, *partition = NULL;
×
UNCOV
2542
                                PartitionDesignator partition_designator;
×
UNCOV
2543
                                MountOptions *o = NULL;
×
UNCOV
2544
                                const char *p;
×
2545

UNCOV
2546
                                r = extract_first_word(&val, &word, NULL, 0);
×
UNCOV
2547
                                if (r < 0)
×
2548
                                        return r;
UNCOV
2549
                                if (r == 0)
×
2550
                                        break;
2551

UNCOV
2552
                                p = word;
×
UNCOV
2553
                                r = extract_many_words(&p, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options);
×
UNCOV
2554
                                if (r < 0)
×
2555
                                        return r;
UNCOV
2556
                                if (r == 0)
×
UNCOV
2557
                                        continue;
×
2558

UNCOV
2559
                                partition_designator = partition_designator_from_string(partition);
×
UNCOV
2560
                                if (partition_designator < 0)
×
2561
                                        return -EINVAL;
2562

UNCOV
2563
                                o = new(MountOptions, 1);
×
UNCOV
2564
                                if (!o)
×
UNCOV
2565
                                        return log_oom_debug();
×
2566
                                *o = (MountOptions) {
×
2567
                                        .partition_designator = partition_designator,
UNCOV
2568
                                        .options = TAKE_PTR(mount_options),
×
2569
                                };
2570
                                LIST_APPEND(mount_options, c->root_image_options, o);
×
2571
                        }
2572
                } else if ((val = startswith(l, "exec-context-root-verity="))) {
1,289,401✔
2573
                        r = free_and_strdup(&c->root_verity, val);
×
UNCOV
2574
                        if (r < 0)
×
2575
                                return r;
2576
                } else if ((val = startswith(l, "exec-context-root-hash-path="))) {
1,289,401✔
UNCOV
2577
                        r = free_and_strdup(&c->root_hash_path, val);
×
2578
                        if (r < 0)
×
2579
                                return r;
2580
                } else if ((val = startswith(l, "exec-context-root-hash-sig-path="))) {
1,289,401✔
2581
                        r = free_and_strdup(&c->root_hash_sig_path, val);
×
2582
                        if (r < 0)
×
2583
                                return r;
2584
                } else if ((val = startswith(l, "exec-context-root-hash="))) {
1,289,401✔
2585
                        c->root_hash = mfree(c->root_hash);
4✔
2586
                        r = unhexmem(val, &c->root_hash, &c->root_hash_size);
4✔
2587
                        if (r < 0)
4✔
2588
                                return r;
2589
                } else if ((val = startswith(l, "exec-context-root-hash-sig="))) {
1,289,397✔
UNCOV
2590
                        c->root_hash_sig = mfree(c->root_hash_sig);
×
UNCOV
2591
                        r= unbase64mem(val, &c->root_hash_sig, &c->root_hash_sig_size);
×
2592
                        if (r < 0)
×
2593
                                return r;
2594
                } else if ((val = startswith(l, "exec-context-root-ephemeral="))) {
1,289,397✔
2595
                        r = parse_boolean(val);
×
UNCOV
2596
                        if (r < 0)
×
2597
                                return r;
UNCOV
2598
                        c->root_ephemeral = r;
×
2599
                } else if ((val = startswith(l, "exec-context-umask="))) {
1,289,397✔
2600
                        r = parse_mode(val, &c->umask);
11,867✔
2601
                        if (r < 0)
11,867✔
2602
                                return r;
2603
                } else if ((val = startswith(l, "exec-context-private-non-blocking="))) {
1,277,530✔
UNCOV
2604
                        r = parse_boolean(val);
×
UNCOV
2605
                        if (r < 0)
×
2606
                                return r;
2607
                        c->non_blocking = r;
×
2608
                } else if ((val = startswith(l, "exec-context-private-mounts="))) {
1,277,530✔
2609
                        r = safe_atoi(val, &c->private_mounts);
135✔
2610
                        if (r < 0)
135✔
2611
                                return r;
2612
                } else if ((val = startswith(l, "exec-context-mount-api-vfs="))) {
1,277,395✔
2613
                        r = safe_atoi(val, &c->mount_apivfs);
29✔
2614
                        if (r < 0)
29✔
2615
                                return r;
2616
                } else if ((val = startswith(l, "exec-context-bind-log-sockets="))) {
1,277,366✔
2617
                        r = safe_atoi(val, &c->bind_log_sockets);
2✔
2618
                        if (r < 0)
2✔
2619
                                return r;
2620
                } else if ((val = startswith(l, "exec-context-memory-ksm="))) {
1,277,364✔
2621
                        r = safe_atoi(val, &c->memory_ksm);
×
UNCOV
2622
                        if (r < 0)
×
2623
                                return r;
2624
                } else if ((val = startswith(l, "exec-context-private-tmp="))) {
1,277,364✔
2625
                        c->private_tmp = private_tmp_from_string(val);
11,867✔
2626
                        if (c->private_tmp < 0)
11,867✔
2627
                                return c->private_tmp;
2628
                } else if ((val = startswith(l, "exec-context-private-var-tmp="))) {
1,265,497✔
2629
                        c->private_var_tmp = private_tmp_from_string(val);
11,867✔
2630
                        if (c->private_var_tmp < 0)
11,867✔
2631
                                return c->private_var_tmp;
2632
                } else if ((val = startswith(l, "exec-context-private-devices="))) {
1,253,630✔
2633
                        r = parse_boolean(val);
659✔
2634
                        if (r < 0)
659✔
2635
                                return r;
2636
                        c->private_devices = r;
659✔
2637
                } else if ((val = startswith(l, "exec-context-protect-kernel-tunables="))) {
1,252,971✔
2638
                        r = parse_boolean(val);
474✔
2639
                        if (r < 0)
474✔
2640
                                return r;
2641
                        c->protect_kernel_tunables = r;
474✔
2642
                } else if ((val = startswith(l, "exec-context-protect-kernel-modules="))) {
1,252,497✔
2643
                        r = parse_boolean(val);
1,693✔
2644
                        if (r < 0)
1,693✔
2645
                                return r;
2646
                        c->protect_kernel_modules = r;
1,693✔
2647
                } else if ((val = startswith(l, "exec-context-protect-kernel-logs="))) {
1,250,804✔
2648
                        r = parse_boolean(val);
1,693✔
2649
                        if (r < 0)
1,693✔
2650
                                return r;
2651
                        c->protect_kernel_logs = r;
1,693✔
2652
                } else if ((val = startswith(l, "exec-context-protect-clock="))) {
1,249,111✔
2653
                        r = parse_boolean(val);
1,611✔
2654
                        if (r < 0)
1,611✔
2655
                                return r;
2656
                        c->protect_clock = r;
1,611✔
2657
                } else if ((val = startswith(l, "exec-context-protect-control-groups="))) {
1,247,500✔
2658
                        r = protect_control_groups_from_string(val);
11,867✔
2659
                        if (r < 0)
11,867✔
2660
                                return r;
2661
                        c->protect_control_groups = r;
11,867✔
2662
                } else if ((val = startswith(l, "exec-context-private-network="))) {
1,235,633✔
2663
                        r = parse_boolean(val);
66✔
2664
                        if (r < 0)
66✔
2665
                                return r;
2666
                        c->private_network = r;
66✔
2667
                } else if ((val = startswith(l, "exec-context-private-users="))) {
1,235,567✔
2668
                        c->private_users = private_users_from_string(val);
11,867✔
2669
                        if (c->private_users < 0)
11,867✔
2670
                                return -EINVAL;
2671
                } else if ((val = startswith(l, "exec-context-private-ipc="))) {
1,223,700✔
2672
                        r = parse_boolean(val);
6✔
2673
                        if (r < 0)
6✔
2674
                                return r;
2675
                        c->private_ipc = r;
6✔
2676
                } else if ((val = startswith(l, "exec-context-private-pids="))) {
1,223,694✔
2677
                        c->private_pids = private_pids_from_string(val);
11,867✔
2678
                        if (c->private_pids < 0)
11,867✔
2679
                                return -EINVAL;
2680
                } else if ((val = startswith(l, "exec-context-remove-ipc="))) {
1,211,827✔
2681
                        r = parse_boolean(val);
70✔
2682
                        if (r < 0)
70✔
2683
                                return r;
2684
                        c->remove_ipc = r;
70✔
2685
                } else if ((val = startswith(l, "exec-context-protect-home="))) {
1,211,757✔
2686
                        c->protect_home = protect_home_from_string(val);
11,867✔
2687
                        if (c->protect_home < 0)
11,867✔
2688
                                return -EINVAL;
2689
                } else if ((val = startswith(l, "exec-context-protect-system="))) {
1,199,890✔
2690
                        c->protect_system = protect_system_from_string(val);
11,867✔
2691
                        if (c->protect_system < 0)
11,867✔
2692
                                return -EINVAL;
2693
                } else if ((val = startswith(l, "exec-context-same-pgrp="))) {
1,188,023✔
2694
                        r = parse_boolean(val);
830✔
2695
                        if (r < 0)
830✔
2696
                                return r;
2697
                        c->same_pgrp = r;
830✔
2698
                } else if ((val = startswith(l, "exec-context-non-blocking="))) {
1,187,193✔
UNCOV
2699
                        r = parse_boolean(val);
×
UNCOV
2700
                        if (r < 0)
×
2701
                                return r;
UNCOV
2702
                        c->non_blocking = r;
×
2703
                } else if ((val = startswith(l, "exec-context-ignore-sigpipe="))) {
1,187,193✔
2704
                        r = parse_boolean(val);
11,867✔
2705
                        if (r < 0)
11,867✔
2706
                                return r;
2707
                        c->ignore_sigpipe = r;
11,867✔
2708
                } else if ((val = startswith(l, "exec-context-memory-deny-write-execute="))) {
1,175,326✔
2709
                        r = parse_boolean(val);
2,176✔
2710
                        if (r < 0)
2,176✔
2711
                                return r;
2712
                        c->memory_deny_write_execute = r;
2,176✔
2713
                } else if ((val = startswith(l, "exec-context-restrict-realtime="))) {
1,173,150✔
2714
                        r = parse_boolean(val);
2,178✔
2715
                        if (r < 0)
2,178✔
2716
                                return r;
2717
                        c->restrict_realtime = r;
2,178✔
2718
                } else if ((val = startswith(l, "exec-context-restrict-suid-sgid="))) {
1,170,972✔
2719
                        r = parse_boolean(val);
2,097✔
2720
                        if (r < 0)
2,097✔
2721
                                return r;
2722
                        c->restrict_suid_sgid = r;
2,097✔
2723
                } else if ((val = startswith(l, "exec-context-keyring-mode="))) {
1,168,875✔
2724
                        c->keyring_mode = exec_keyring_mode_from_string(val);
11,867✔
2725
                        if (c->keyring_mode < 0)
11,867✔
2726
                                return -EINVAL;
2727
                } else if ((val = startswith(l, "exec-context-protect-hostname="))) {
1,157,008✔
2728
                        c->protect_hostname = protect_hostname_from_string(val);
11,867✔
2729
                        if (c->protect_hostname < 0)
11,867✔
2730
                                return -EINVAL;
2731
                } else if ((val = startswith(l, "exec-context-private-hostname="))) {
1,145,141✔
2732
                        r = free_and_strdup(&c->private_hostname, val);
5✔
2733
                        if (r < 0)
5✔
2734
                                return r;
2735
                } else if ((val = startswith(l, "exec-context-protect-proc="))) {
1,145,136✔
2736
                        c->protect_proc = protect_proc_from_string(val);
11,867✔
2737
                        if (c->protect_proc < 0)
11,867✔
2738
                                return -EINVAL;
2739
                } else if ((val = startswith(l, "exec-context-proc-subset="))) {
1,133,269✔
2740
                        c->proc_subset = proc_subset_from_string(val);
11,867✔
2741
                        if (c->proc_subset < 0)
11,867✔
2742
                                return -EINVAL;
2743
                } else if ((val = startswith(l, "exec-context-private-bpf="))) {
1,121,402✔
2744
                        c->private_bpf = private_bpf_from_string(val);
11,867✔
2745
                        if (c->private_bpf < 0)
11,867✔
2746
                                return -EINVAL;
2747
                } else if ((val = startswith(l, "exec-context-bpf-delegate-commands="))) {
1,109,535✔
2748
                        r = safe_atoux64(val, &c->bpf_delegate_commands);
2✔
2749
                        if (r < 0)
2✔
2750
                                return r;
2751
                } else if ((val = startswith(l, "exec-context-bpf-delegate-maps="))) {
1,109,533✔
2752
                        r = safe_atoux64(val, &c->bpf_delegate_maps);
1✔
2753
                        if (r < 0)
1✔
2754
                                return r;
2755
                } else if ((val = startswith(l, "exec-context-bpf-delegate-programs="))) {
1,109,532✔
2756
                        r = safe_atoux64(val, &c->bpf_delegate_programs);
1✔
2757
                        if (r < 0)
1✔
2758
                                return r;
2759
                } else if ((val = startswith(l, "exec-context-bpf-delegate-attachments="))) {
1,109,531✔
2760
                        r = safe_atoux64(val, &c->bpf_delegate_attachments);
1✔
2761
                        if (r < 0)
1✔
2762
                                return r;
2763
                } else if ((val = startswith(l, "exec-context-runtime-directory-preserve-mode="))) {
1,109,530✔
2764
                        c->runtime_directory_preserve_mode = exec_preserve_mode_from_string(val);
11,867✔
2765
                        if (c->runtime_directory_preserve_mode < 0)
11,867✔
2766
                                return -EINVAL;
2767
                } else if ((val = startswith(l, "exec-context-directories-"))) {
1,097,663✔
UNCOV
2768
                        _cleanup_free_ char *type = NULL, *mode = NULL;
×
2769
                        ExecDirectoryType dt;
59,335✔
2770

2771
                        r = extract_many_words(&val, "= ", 0, &type, &mode);
59,335✔
2772
                        if (r < 0)
59,335✔
2773
                                return r;
2774
                        if (r == 0 || !mode)
59,335✔
2775
                                return -EINVAL;
2776

2777
                        dt = exec_directory_type_from_string(type);
59,335✔
2778
                        if (dt < 0)
59,335✔
2779
                                return dt;
2780

2781
                        r = parse_mode(mode, &c->directories[dt].mode);
59,335✔
2782
                        if (r < 0)
59,335✔
2783
                                return r;
2784

2785
                        for (;;) {
62,979✔
2786
                                _cleanup_free_ char *tuple = NULL, *path = NULL, *only_create = NULL, *read_only = NULL;
62,872✔
2787
                                ExecDirectoryFlags exec_directory_flags = 0;
62,979✔
2788
                                const char *p;
62,979✔
2789

2790
                                /* Use EXTRACT_UNESCAPE_RELAX here, as we unescape the colons in subsequent calls */
2791
                                r = extract_first_word(&val, &tuple, WHITESPACE, EXTRACT_UNESCAPE_SEPARATORS|EXTRACT_UNESCAPE_RELAX);
62,979✔
2792
                                if (r < 0)
62,979✔
2793
                                        return r;
2794
                                if (r == 0)
62,979✔
2795
                                        break;
2796

2797
                                p = tuple;
3,644✔
2798
                                r = extract_many_words(&p, ":", EXTRACT_UNESCAPE_SEPARATORS, &path, &only_create, &read_only);
3,644✔
2799
                                if (r < 0)
3,644✔
2800
                                        return r;
2801
                                if (r < 2)
3,644✔
UNCOV
2802
                                        continue;
×
2803

2804
                                r = parse_boolean(only_create);
3,644✔
2805
                                if (r < 0)
3,644✔
2806
                                        return r;
2807
                                if (r > 0)
3,644✔
2808
                                        exec_directory_flags |= EXEC_DIRECTORY_ONLY_CREATE;
5✔
2809

2810
                                r = parse_boolean(read_only);
3,644✔
2811
                                if (r < 0)
3,644✔
2812
                                        return r;
2813
                                if (r > 0)
3,644✔
2814
                                        exec_directory_flags |= EXEC_DIRECTORY_READ_ONLY;
50✔
2815

2816
                                r = exec_directory_add(&c->directories[dt], path, /* symlink= */ NULL, exec_directory_flags);
3,644✔
2817
                                if (r < 0)
3,644✔
2818
                                        return r;
2819

2820
                                if (isempty(p))
3,644✔
2821
                                        continue;
3,537✔
2822

2823
                                for (;;) {
385✔
2824
                                        _cleanup_free_ char *link = NULL;
246✔
2825

2826
                                        r = extract_first_word(&p, &link, ":", EXTRACT_UNESCAPE_SEPARATORS);
246✔
2827
                                        if (r < 0)
246✔
2828
                                                return r;
2829
                                        if (r == 0)
246✔
2830
                                                break;
2831

2832
                                        r = strv_consume(&c->directories[dt].items[c->directories[dt].n_items - 1].symlinks, TAKE_PTR(link));
139✔
2833
                                        if (r < 0)
139✔
2834
                                                return r;
2835
                                }
2836
                        }
2837
                } else if ((val = startswith(l, "exec-context-quota-accounting-directories-"))) {
1,038,328✔
UNCOV
2838
                        _cleanup_free_ char *type = NULL, *quota_accounting = NULL;
×
UNCOV
2839
                        ExecDirectoryType dt;
×
2840

UNCOV
2841
                        r = split_pair(val, "=", &type, &quota_accounting);
×
UNCOV
2842
                        if (r < 0)
×
2843
                                return r;
2844

UNCOV
2845
                        dt = exec_directory_type_from_string(type);
×
UNCOV
2846
                        if (dt < 0)
×
2847
                                return dt;
2848

UNCOV
2849
                        r = parse_boolean(quota_accounting);
×
UNCOV
2850
                        if (r < 0)
×
2851
                                return r;
2852

UNCOV
2853
                        c->directories[dt].exec_quota.quota_accounting = r;
×
2854
                } else if ((val = startswith(l, "exec-context-quota-directories-"))) {
1,038,328✔
UNCOV
2855
                        _cleanup_free_ char *type = NULL, *quota_info = NULL, *quota_absolute = NULL, *quota_scale = NULL;
×
UNCOV
2856
                        ExecDirectoryType dt;
×
2857

UNCOV
2858
                        r = split_pair(val, "=", &type, &quota_info);
×
UNCOV
2859
                        if (r < 0)
×
2860
                                return r;
2861

UNCOV
2862
                        r = split_pair(quota_info, " ", &quota_absolute, &quota_scale);
×
UNCOV
2863
                        if (r < 0)
×
2864
                                return r;
2865

UNCOV
2866
                        dt = exec_directory_type_from_string(type);
×
2867
                        if (dt < 0)
×
2868
                                return dt;
2869

2870
                        r = safe_atou64(quota_absolute, &c->directories[dt].exec_quota.quota_absolute);
×
2871
                        if (r < 0)
×
2872
                               return r;
2873

2874
                        r = safe_atou32(quota_scale, &c->directories[dt].exec_quota.quota_scale);
×
2875
                        if (r < 0)
×
2876
                               return r;
2877

2878
                        c->directories[dt].exec_quota.quota_enforce = true;
×
2879
                } else if ((val = startswith(l, "exec-context-timeout-clean-usec="))) {
1,038,328✔
UNCOV
2880
                        r = deserialize_usec(val, &c->timeout_clean_usec);
×
UNCOV
2881
                        if (r < 0)
×
2882
                                return r;
2883
                } else if ((val = startswith(l, "exec-context-nice="))) {
1,038,328✔
2884
                        r = safe_atoi(val, &c->nice);
19✔
2885
                        if (r < 0)
19✔
2886
                                return r;
2887
                        c->nice_set = true;
19✔
2888
                } else if ((val = startswith(l, "exec-context-working-directory-missing-ok="))) {
1,038,309✔
2889
                        r = parse_boolean(val);
676✔
2890
                        if (r < 0)
676✔
2891
                                return r;
2892
                        c->working_directory_missing_ok = r;
676✔
2893
                } else if ((val = startswith(l, "exec-context-working-directory-home="))) {
1,037,633✔
2894
                        r = parse_boolean(val);
173✔
2895
                        if (r < 0)
173✔
2896
                                return r;
2897
                        c->working_directory_home = r;
173✔
2898
                } else if ((val = startswith(l, "exec-context-oom-score-adjust="))) {
1,037,460✔
2899
                        r = safe_atoi(val, &c->oom_score_adjust);
1,217✔
2900
                        if (r < 0)
1,217✔
2901
                                return r;
2902
                        c->oom_score_adjust_set = true;
1,217✔
2903
                } else if ((val = startswith(l, "exec-context-coredump-filter="))) {
1,036,243✔
2904
                        r = safe_atoux64(val, &c->coredump_filter);
2✔
2905
                        if (r < 0)
2✔
2906
                                return r;
2907
                        c->coredump_filter_set = true;
2✔
2908
                } else if ((val = startswith(l, "exec-context-limit-"))) {
1,036,241✔
2909
                        _cleanup_free_ struct rlimit *rlimit = NULL;
×
2910
                        _cleanup_free_ char *limit = NULL;
23,729✔
2911
                        int type;
23,729✔
2912

2913
                        r = extract_first_word(&val, &limit, "=", 0);
23,729✔
2914
                        if (r < 0)
23,729✔
2915
                                return r;
2916
                        if (r == 0 || !val)
23,729✔
2917
                                return -EINVAL;
2918

2919
                        type = rlimit_from_string(limit);
23,729✔
2920
                        if (type < 0)
23,729✔
2921
                                return -EINVAL;
2922

2923
                        if (!c->rlimit[type]) {
23,729✔
2924
                                rlimit = new0(struct rlimit, 1);
23,729✔
2925
                                if (!rlimit)
23,729✔
UNCOV
2926
                                        return log_oom_debug();
×
2927

2928
                                r = rlimit_parse(type, val, rlimit);
23,729✔
2929
                                if (r < 0)
23,729✔
2930
                                        return r;
2931

2932
                                c->rlimit[type] = TAKE_PTR(rlimit);
23,729✔
2933
                        } else {
UNCOV
2934
                                r = rlimit_parse(type, val, c->rlimit[type]);
×
UNCOV
2935
                                if (r < 0)
×
2936
                                        return r;
2937
                        }
2938
                } else if ((val = startswith(l, "exec-context-ioprio="))) {
1,012,512✔
2939
                        r = safe_atoi(val, &c->ioprio);
11✔
2940
                        if (r < 0)
11✔
2941
                                return r;
2942
                        c->ioprio_is_set = true;
11✔
2943
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-policy="))) {
1,012,501✔
UNCOV
2944
                        c->cpu_sched_policy = sched_policy_from_string(val);
×
UNCOV
2945
                        if (c->cpu_sched_policy < 0)
×
2946
                                return -EINVAL;
UNCOV
2947
                        c->cpu_sched_set = true;
×
2948
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-priority="))) {
1,012,501✔
UNCOV
2949
                        r = safe_atoi(val, &c->cpu_sched_priority);
×
UNCOV
2950
                        if (r < 0)
×
2951
                                return r;
UNCOV
2952
                        c->cpu_sched_set = true;
×
2953
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-reset-on-fork="))) {
1,012,501✔
UNCOV
2954
                        r = parse_boolean(val);
×
2955
                        if (r < 0)
×
2956
                                return r;
UNCOV
2957
                        c->cpu_sched_reset_on_fork = r;
×
UNCOV
2958
                        c->cpu_sched_set = true;
×
2959
                } else if ((val = startswith(l, "exec-context-cpu-affinity="))) {
1,012,501✔
UNCOV
2960
                        if (c->cpu_set.set)
×
2961
                                return -EINVAL; /* duplicated */
2962

2963
                        r = parse_cpu_set(val, &c->cpu_set);
×
2964
                        if (r < 0)
×
2965
                                return r;
2966
                } else if ((val = startswith(l, "exec-context-numa-mask="))) {
1,012,501✔
2967
                        if (c->numa_policy.nodes.set)
19✔
2968
                                return -EINVAL; /* duplicated */
2969

2970
                        r = parse_cpu_set(val, &c->numa_policy.nodes);
19✔
2971
                        if (r < 0)
19✔
2972
                                return r;
2973
                } else if ((val = startswith(l, "exec-context-numa-policy="))) {
1,012,482✔
2974
                        r = safe_atoi(val, &c->numa_policy.type);
19✔
2975
                        if (r < 0)
19✔
2976
                                return r;
2977
                } else if ((val = startswith(l, "exec-context-cpu-affinity-from-numa="))) {
1,012,463✔
2978
                        r = parse_boolean(val);
2✔
2979
                        if (r < 0)
2✔
2980
                                return r;
2981
                        c->cpu_affinity_from_numa = r;
2✔
2982
                } else if ((val = startswith(l, "exec-context-timer-slack-nsec="))) {
1,012,461✔
2983
                        r = deserialize_usec(val, (usec_t *)&c->timer_slack_nsec);
×
2984
                        if (r < 0)
×
2985
                                return r;
2986
                } else if ((val = startswith(l, "exec-context-std-input="))) {
1,012,461✔
2987
                        c->std_input = exec_input_from_string(val);
11,867✔
2988
                        if (c->std_input < 0)
11,867✔
2989
                                return c->std_input;
2990
                } else if ((val = startswith(l, "exec-context-std-output="))) {
1,000,594✔
2991
                        c->std_output = exec_output_from_string(val);
11,867✔
2992
                        if (c->std_output < 0)
11,867✔
2993
                                return c->std_output;
2994
                } else if ((val = startswith(l, "exec-context-std-error="))) {
988,727✔
2995
                        c->std_error = exec_output_from_string(val);
11,867✔
2996
                        if (c->std_error < 0)
11,867✔
2997
                                return c->std_error;
2998
                } else if ((val = startswith(l, "exec-context-stdio-as-fds="))) {
976,860✔
2999
                        r = parse_boolean(val);
587✔
3000
                        if (r < 0)
587✔
3001
                                return r;
3002
                        c->stdio_as_fds = r;
587✔
3003
                } else if ((val = startswith(l, "exec-context-std-input-fd-name="))) {
976,273✔
UNCOV
3004
                        r = free_and_strdup(&c->stdio_fdname[STDIN_FILENO], val);
×
UNCOV
3005
                        if (r < 0)
×
3006
                                return r;
3007
                } else if ((val = startswith(l, "exec-context-std-output-fd-name="))) {
976,273✔
UNCOV
3008
                        r = free_and_strdup(&c->stdio_fdname[STDOUT_FILENO], val);
×
UNCOV
3009
                        if (r < 0)
×
3010
                                return r;
3011
                } else if ((val = startswith(l, "exec-context-std-error-fd-name="))) {
976,273✔
3012
                        r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], val);
×
3013
                        if (r < 0)
×
3014
                                return r;
3015
                } else if ((val = startswith(l, "exec-context-std-input-file="))) {
976,273✔
UNCOV
3016
                        r = free_and_strdup(&c->stdio_file[STDIN_FILENO], val);
×
UNCOV
3017
                        if (r < 0)
×
3018
                                return r;
3019
                } else if ((val = startswith(l, "exec-context-std-output-file="))) {
976,273✔
3020
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
50✔
3021
                        if (r < 0)
50✔
3022
                                return r;
3023
                } else if ((val = startswith(l, "exec-context-std-output-file-append="))) {
976,223✔
3024
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
1✔
3025
                        if (r < 0)
1✔
3026
                                return r;
3027
                } else if ((val = startswith(l, "exec-context-std-output-file-truncate="))) {
976,222✔
3028
                        r = free_and_strdup(&c->stdio_file[STDOUT_FILENO], val);
2✔
3029
                        if (r < 0)
2✔
3030
                                return r;
3031
                } else if ((val = startswith(l, "exec-context-std-error-file="))) {
976,220✔
3032
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
47✔
3033
                        if (r < 0)
47✔
3034
                                return r;
3035
                } else if ((val = startswith(l, "exec-context-std-error-file-append="))) {
976,173✔
3036
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
1✔
3037
                        if (r < 0)
1✔
3038
                                return r;
3039
                } else if ((val = startswith(l, "exec-context-std-error-file-truncate="))) {
976,172✔
3040
                        r = free_and_strdup(&c->stdio_file[STDERR_FILENO], val);
1✔
3041
                        if (r < 0)
1✔
3042
                                return r;
3043
                } else if ((val = startswith(l, "exec-context-stdin-data="))) {
976,171✔
3044
                        if (c->stdin_data)
1✔
3045
                                return -EINVAL; /* duplicated */
3046

3047
                        r = unbase64mem(val, &c->stdin_data, &c->stdin_data_size);
1✔
3048
                        if (r < 0)
1✔
3049
                                return r;
3050
                } else if ((val = startswith(l, "exec-context-tty-path="))) {
976,170✔
3051
                        r = free_and_strdup(&c->tty_path, val);
177✔
3052
                        if (r < 0)
177✔
3053
                                return r;
3054
                } else if ((val = startswith(l, "exec-context-tty-reset="))) {
975,993✔
3055
                        r = parse_boolean(val);
367✔
3056
                        if (r < 0)
367✔
3057
                                return r;
3058
                        c->tty_reset = r;
367✔
3059
                } else if ((val = startswith(l, "exec-context-tty-vhangup="))) {
975,626✔
3060
                        r = parse_boolean(val);
156✔
3061
                        if (r < 0)
156✔
3062
                                return r;
3063
                        c->tty_vhangup = r;
156✔
3064
                } else if ((val = startswith(l, "exec-context-tty-vt-disallocate="))) {
975,470✔
3065
                        r = parse_boolean(val);
87✔
3066
                        if (r < 0)
87✔
3067
                                return r;
3068
                        c->tty_vt_disallocate = r;
87✔
3069
                } else if ((val = startswith(l, "exec-context-tty-rows="))) {
975,383✔
3070
                        r = safe_atou(val, &c->tty_rows);
11,867✔
3071
                        if (r < 0)
11,867✔
3072
                                return r;
3073
                } else if ((val = startswith(l, "exec-context-tty-columns="))) {
963,516✔
3074
                        r = safe_atou(val, &c->tty_cols);
11,867✔
3075
                        if (r < 0)
11,867✔
3076
                                return r;
3077
                } else if ((val = startswith(l, "exec-context-syslog-priority="))) {
951,649✔
3078
                        r = safe_atoi(val, &c->syslog_priority);
11,867✔
3079
                        if (r < 0)
11,867✔
3080
                                return r;
3081
                } else if ((val = startswith(l, "exec-context-syslog-level-prefix="))) {
939,782✔
3082
                        r = parse_boolean(val);
11,867✔
3083
                        if (r < 0)
11,867✔
3084
                                return r;
3085
                        c->syslog_level_prefix = r;
11,867✔
3086
                } else if ((val = startswith(l, "exec-context-syslog-identifier="))) {
927,915✔
UNCOV
3087
                        r = free_and_strdup(&c->syslog_identifier, val);
×
UNCOV
3088
                        if (r < 0)
×
3089
                                return r;
3090
                } else if ((val = startswith(l, "exec-context-log-level-max="))) {
927,915✔
3091
                        /* See comment in serialization. */
3092
                        r = safe_atoi(val, &c->log_level_max);
11,867✔
3093
                        if (r < 0)
11,867✔
3094
                                return r;
3095
                } else if ((val = startswith(l, "exec-context-log-ratelimit-interval-usec="))) {
916,048✔
UNCOV
3096
                        r = deserialize_usec(val, &c->log_ratelimit.interval);
×
UNCOV
3097
                        if (r < 0)
×
3098
                                return r;
3099
                } else if ((val = startswith(l, "exec-context-log-ratelimit-burst="))) {
916,048✔
UNCOV
3100
                        r = safe_atou(val, &c->log_ratelimit.burst);
×
UNCOV
3101
                        if (r < 0)
×
3102
                                return r;
3103
                } else if ((val = startswith(l, "exec-context-log-filter-allowed-patterns="))) {
916,048✔
3104
                        r = set_put_strdup(&c->log_filter_allowed_patterns, val);
20✔
3105
                        if (r < 0)
20✔
3106
                                return r;
3107
                } else if ((val = startswith(l, "exec-context-log-filter-denied-patterns="))) {
916,028✔
3108
                        r = set_put_strdup(&c->log_filter_denied_patterns, val);
13✔
3109
                        if (r < 0)
13✔
3110
                                return r;
3111
                } else if ((val = startswith(l, "exec-context-log-extra-fields="))) {
916,015✔
3112
                        if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
685✔
UNCOV
3113
                                return log_oom_debug();
×
3114

3115
                        c->log_extra_fields[c->n_log_extra_fields++].iov_base = strdup(val);
685✔
3116
                        if (!c->log_extra_fields[c->n_log_extra_fields-1].iov_base)
685✔
3117
                                return log_oom_debug();
×
3118
                } else if ((val = startswith(l, "exec-context-log-namespace="))) {
915,330✔
3119
                        r = free_and_strdup(&c->log_namespace, val);
2✔
3120
                        if (r < 0)
2✔
3121
                                return r;
3122
                } else if ((val = startswith(l, "exec-context-secure-bits="))) {
915,328✔
UNCOV
3123
                        r = safe_atoi(val, &c->secure_bits);
×
UNCOV
3124
                        if (r < 0)
×
3125
                                return r;
3126
                } else if ((val = startswith(l, "exec-context-capability-bounding-set="))) {
915,328✔
3127
                        r = safe_atou64(val, &c->capability_bounding_set);
2,309✔
3128
                        if (r < 0)
2,309✔
3129
                                return r;
3130
                } else if ((val = startswith(l, "exec-context-capability-ambient-set="))) {
913,019✔
3131
                        r = safe_atou64(val, &c->capability_ambient_set);
1,248✔
3132
                        if (r < 0)
1,248✔
3133
                                return r;
3134
                } else if ((val = startswith(l, "exec-context-user="))) {
911,771✔
3135
                        r = free_and_strdup(&c->user, val);
2,652✔
3136
                        if (r < 0)
2,652✔
3137
                                return r;
3138
                } else if ((val = startswith(l, "exec-context-group="))) {
909,119✔
3139
                        r = free_and_strdup(&c->group, val);
73✔
3140
                        if (r < 0)
73✔
3141
                                return r;
3142
                } else if ((val = startswith(l, "exec-context-dynamic-user="))) {
909,046✔
3143
                        r = parse_boolean(val);
62✔
3144
                        if (r < 0)
62✔
3145
                                return r;
3146
                        c->dynamic_user = r;
62✔
3147
                } else if ((val = startswith(l, "exec-context-supplementary-groups="))) {
908,984✔
3148
                        r = deserialize_strv(val, &c->supplementary_groups);
9✔
3149
                        if (r < 0)
9✔
3150
                                return r;
3151
                } else if ((val = startswith(l, "exec-context-set-login-environment="))) {
908,975✔
3152
                        r = safe_atoi(val, &c->set_login_environment);
×
3153
                        if (r < 0)
×
3154
                                return r;
3155
                } else if ((val = startswith(l, "exec-context-pam-name="))) {
908,975✔
3156
                        r = free_and_strdup(&c->pam_name, val);
495✔
3157
                        if (r < 0)
495✔
3158
                                return r;
3159
                } else if ((val = startswith(l, "exec-context-read-write-paths="))) {
908,480✔
3160
                        r = deserialize_strv(val, &c->read_write_paths);
819✔
3161
                        if (r < 0)
819✔
3162
                                return r;
3163
                } else if ((val = startswith(l, "exec-context-read-only-paths="))) {
907,661✔
3164
                        r = deserialize_strv(val, &c->read_only_paths);
2✔
3165
                        if (r < 0)
2✔
3166
                                return r;
3167
                } else if ((val = startswith(l, "exec-context-inaccessible-paths="))) {
907,659✔
3168
                        r = deserialize_strv(val, &c->inaccessible_paths);
5✔
3169
                        if (r < 0)
5✔
3170
                                return r;
3171
                } else if ((val = startswith(l, "exec-context-exec-paths="))) {
907,654✔
3172
                        r = deserialize_strv(val, &c->exec_paths);
1✔
3173
                        if (r < 0)
1✔
3174
                                return r;
3175
                } else if ((val = startswith(l, "exec-context-no-exec-paths="))) {
907,653✔
3176
                        r = deserialize_strv(val, &c->no_exec_paths);
1✔
3177
                        if (r < 0)
1✔
3178
                                return r;
3179
                } else if ((val = startswith(l, "exec-context-exec-search-path="))) {
907,652✔
UNCOV
3180
                        r = deserialize_strv(val, &c->exec_search_path);
×
3181
                        if (r < 0)
×
3182
                                return r;
3183
                } else if ((val = startswith(l, "exec-context-mount-propagation-flag="))) {
907,652✔
3184
                        r = safe_atolu(val, &c->mount_propagation_flag);
11,867✔
3185
                        if (r < 0)
11,867✔
3186
                                return r;
3187
                } else if ((val = startswith(l, "exec-context-bind-read-only-path="))) {
895,785✔
3188
                        _cleanup_free_ char *source = NULL, *destination = NULL;
7✔
3189
                        bool rbind = true, ignore_enoent = false;
7✔
3190
                        char *s = NULL, *d = NULL;
7✔
3191

3192
                        r = extract_first_word(&val,
7✔
3193
                                               &source,
3194
                                               ":" WHITESPACE,
3195
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3196
                        if (r < 0)
7✔
3197
                                return r;
3198
                        if (r == 0)
7✔
3199
                                return -EINVAL;
3200

3201
                        s = source;
7✔
3202
                        if (s[0] == '-') {
7✔
3203
                                ignore_enoent = true;
1✔
3204
                                s++;
1✔
3205
                        }
3206

3207
                        if (val && val[-1] == ':') {
7✔
3208
                                r = extract_first_word(&val,
7✔
3209
                                                       &destination,
3210
                                                       ":" WHITESPACE,
3211
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3212
                                if (r < 0)
7✔
3213
                                        return r;
3214
                                if (r == 0)
7✔
UNCOV
3215
                                        continue;
×
3216

3217
                                d = destination;
7✔
3218

3219
                                if (val && val[-1] == ':') {
7✔
3220
                                        _cleanup_free_ char *options = NULL;
7✔
3221

3222
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
7✔
3223
                                        if (r < 0)
7✔
UNCOV
3224
                                                return -r;
×
3225

3226
                                        if (isempty(options) || streq(options, "rbind"))
15✔
3227
                                                rbind = true;
3228
                                        else if (streq(options, "norbind"))
1✔
3229
                                                rbind = false;
3230
                                        else
UNCOV
3231
                                                continue;
×
3232
                                }
3233
                        } else
3234
                                d = s;
3235

3236
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
14✔
3237
                                        &(BindMount) {
7✔
3238
                                                .source = s,
3239
                                                .destination = d,
3240
                                                .read_only = true,
3241
                                                .recursive = rbind,
3242
                                                .ignore_enoent = ignore_enoent,
3243
                                        });
3244
                        if (r < 0)
7✔
UNCOV
3245
                                return log_oom_debug();
×
3246
                } else if ((val = startswith(l, "exec-context-bind-path="))) {
895,778✔
3247
                        _cleanup_free_ char *source = NULL, *destination = NULL;
20✔
3248
                        bool rbind = true, ignore_enoent = false;
20✔
3249
                        char *s = NULL, *d = NULL;
20✔
3250

3251
                        r = extract_first_word(&val,
20✔
3252
                                               &source,
3253
                                               ":" WHITESPACE,
3254
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3255
                        if (r < 0)
20✔
3256
                                return r;
3257
                        if (r == 0)
20✔
3258
                                return -EINVAL;
3259

3260
                        s = source;
20✔
3261
                        if (s[0] == '-') {
20✔
3262
                                ignore_enoent = true;
1✔
3263
                                s++;
1✔
3264
                        }
3265

3266
                        if (val && val[-1] == ':') {
20✔
3267
                                r = extract_first_word(&val,
20✔
3268
                                                       &destination,
3269
                                                       ":" WHITESPACE,
3270
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3271
                                if (r < 0)
20✔
3272
                                        return r;
3273
                                if (r == 0)
20✔
3274
                                        continue;
×
3275

3276
                                d = destination;
20✔
3277

3278
                                if (val && val[-1] == ':') {
20✔
3279
                                        _cleanup_free_ char *options = NULL;
20✔
3280

3281
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
20✔
3282
                                        if (r < 0)
20✔
UNCOV
3283
                                                return -r;
×
3284

3285
                                        if (isempty(options) || streq(options, "rbind"))
43✔
3286
                                                rbind = true;
3287
                                        else if (streq(options, "norbind"))
3✔
3288
                                                rbind = false;
3289
                                        else
UNCOV
3290
                                                continue;
×
3291
                                }
3292
                        } else
3293
                                d = s;
3294

3295
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
40✔
3296
                                        &(BindMount) {
20✔
3297
                                                .source = s,
3298
                                                .destination = d,
3299
                                                .read_only = false,
3300
                                                .recursive = rbind,
3301
                                                .ignore_enoent = ignore_enoent,
3302
                                        });
3303
                        if (r < 0)
20✔
UNCOV
3304
                                return log_oom_debug();
×
3305
                } else if ((val = startswith(l, "exec-context-temporary-filesystems="))) {
895,758✔
3306
                        _cleanup_free_ char *path = NULL, *options = NULL;
61✔
3307

3308
                        r = extract_many_words(&val, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &path, &options);
61✔
3309
                        if (r < 0)
61✔
3310
                                return r;
3311
                        if (r < 1)
61✔
3312
                                continue;
×
3313

3314
                        r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
61✔
3315
                        if (r < 0)
61✔
UNCOV
3316
                                return log_oom_debug();
×
3317
                } else if ((val = startswith(l, "exec-context-utmp-id="))) {
895,697✔
3318
                        r = free_and_strdup(&c->utmp_id, val);
163✔
3319
                        if (r < 0)
163✔
3320
                                return r;
3321
                } else if ((val = startswith(l, "exec-context-utmp-mode="))) {
895,534✔
3322
                        c->utmp_mode = exec_utmp_mode_from_string(val);
11,867✔
3323
                        if (c->utmp_mode < 0)
11,867✔
3324
                                return c->utmp_mode;
3325
                } else if ((val = startswith(l, "exec-context-no-new-privileges="))) {
883,667✔
3326
                        r = parse_boolean(val);
2,125✔
3327
                        if (r < 0)
2,125✔
3328
                                return r;
3329
                        c->no_new_privileges = r;
2,125✔
3330
                } else if ((val = startswith(l, "exec-context-selinux-context="))) {
881,542✔
UNCOV
3331
                        if (val[0] == '-') {
×
UNCOV
3332
                                c->selinux_context_ignore = true;
×
3333
                                val++;
×
3334
                        } else
UNCOV
3335
                                c->selinux_context_ignore = false;
×
3336

UNCOV
3337
                        r = free_and_strdup(&c->selinux_context, val);
×
UNCOV
3338
                        if (r < 0)
×
3339
                                return r;
3340
                } else if ((val = startswith(l, "exec-context-apparmor-profile="))) {
881,542✔
3341
                        if (val[0] == '-') {
×
UNCOV
3342
                                c->apparmor_profile_ignore = true;
×
UNCOV
3343
                                val++;
×
3344
                        } else
3345
                                c->apparmor_profile_ignore = false;
×
3346

UNCOV
3347
                        r = free_and_strdup(&c->apparmor_profile, val);
×
UNCOV
3348
                        if (r < 0)
×
3349
                                return r;
3350
                } else if ((val = startswith(l, "exec-context-smack-process-label="))) {
881,542✔
UNCOV
3351
                        if (val[0] == '-') {
×
UNCOV
3352
                                c->smack_process_label_ignore = true;
×
UNCOV
3353
                                val++;
×
3354
                        } else
UNCOV
3355
                                c->smack_process_label_ignore = false;
×
3356

UNCOV
3357
                        r = free_and_strdup(&c->smack_process_label, val);
×
UNCOV
3358
                        if (r < 0)
×
3359
                                return r;
3360
                } else if ((val = startswith(l, "exec-context-personality="))) {
881,542✔
3361
                        c->personality = personality_from_string(val);
×
3362
                        if (c->personality == PERSONALITY_INVALID)
×
3363
                                return -EINVAL;
3364
                } else if ((val = startswith(l, "exec-context-lock-personality="))) {
881,542✔
3365
                        r = parse_boolean(val);
2,181✔
3366
                        if (r < 0)
2,181✔
3367
                                return r;
3368
                        c->lock_personality = r;
2,181✔
3369
#if HAVE_SECCOMP
3370
                } else if ((val = startswith(l, "exec-context-syscall-filter="))) {
879,361✔
3371
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
841,743✔
3372
                        int id, errno_num;
841,743✔
3373

3374
                        r = extract_many_words(&val, NULL, 0, &s_id, &s_errno_num);
841,743✔
3375
                        if (r < 0)
841,743✔
3376
                                return r;
3377
                        if (r != 2)
841,743✔
UNCOV
3378
                                continue;
×
3379

3380
                        r = safe_atoi(s_id, &id);
841,743✔
3381
                        if (r < 0)
841,743✔
3382
                                return r;
3383

3384
                        r = safe_atoi(s_errno_num, &errno_num);
841,743✔
3385
                        if (r < 0)
841,743✔
3386
                                return r;
3387

3388
                        r = hashmap_ensure_put(&c->syscall_filter, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
841,743✔
3389
                        if (r < 0)
841,743✔
3390
                                return r;
3391
                } else if ((val = startswith(l, "exec-context-syscall-archs="))) {
37,618✔
3392
                        unsigned id;
2,176✔
3393

3394
                        r = safe_atou(val, &id);
2,176✔
3395
                        if (r < 0)
2,176✔
UNCOV
3396
                                return r;
×
3397

3398
                        r = set_ensure_put(&c->syscall_archs, NULL, UINT_TO_PTR(id + 1));
2,176✔
3399
                        if (r < 0)
2,176✔
3400
                                return r;
3401
                } else if ((val = startswith(l, "exec-context-syscall-errno="))) {
35,442✔
3402
                        r = safe_atoi(val, &c->syscall_errno);
11,867✔
3403
                        if (r < 0)
11,867✔
3404
                                return r;
3405
                } else if ((val = startswith(l, "exec-context-syscall-allow-list="))) {
23,575✔
3406
                        r = parse_boolean(val);
2,158✔
3407
                        if (r < 0)
2,158✔
3408
                                return r;
3409
                        c->syscall_allow_list = r;
2,158✔
3410
                } else if ((val = startswith(l, "exec-context-syscall-log="))) {
21,417✔
UNCOV
3411
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
×
UNCOV
3412
                        int id, errno_num;
×
3413

UNCOV
3414
                        r = extract_many_words(&val, " ", 0, &s_id, &s_errno_num);
×
UNCOV
3415
                        if (r < 0)
×
3416
                                return r;
UNCOV
3417
                        if (r != 2)
×
UNCOV
3418
                                continue;
×
3419

UNCOV
3420
                        r = safe_atoi(s_id, &id);
×
UNCOV
3421
                        if (r < 0)
×
3422
                                return r;
3423

UNCOV
3424
                        r = safe_atoi(s_errno_num, &errno_num);
×
3425
                        if (r < 0)
×
3426
                                return r;
3427

UNCOV
3428
                        r = hashmap_ensure_put(&c->syscall_log, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
×
UNCOV
3429
                        if (r < 0)
×
3430
                                return r;
3431
                } else if ((val = startswith(l, "exec-context-syscall-log-allow-list="))) {
21,417✔
UNCOV
3432
                        r = parse_boolean(val);
×
UNCOV
3433
                        if (r < 0)
×
3434
                                return r;
UNCOV
3435
                        c->syscall_log_allow_list = r;
×
3436
#endif
3437
                } else if ((val = startswith(l, "exec-context-restrict-namespaces="))) {
21,417✔
3438
                        r = safe_atolu(val, &c->restrict_namespaces);
1,926✔
3439
                        if (r < 0)
1,926✔
3440
                                return r;
3441
                } else if ((val = startswith(l, "exec-context-delegate-namespaces="))) {
19,491✔
3442
                        r = safe_atolu(val, &c->delegate_namespaces);
20✔
3443
                        if (r < 0)
20✔
3444
                                return r;
3445
                } else if ((val = startswith(l, "exec-context-restrict-filesystems="))) {
19,471✔
3446
                        r = set_put_strdup(&c->restrict_filesystems, val);
×
3447
                        if (r < 0)
×
3448
                                return r;
3449
                } else if ((val = startswith(l, "exec-context-restrict-filesystems-allow-list="))) {
19,471✔
3450
                        r = parse_boolean(val);
×
UNCOV
3451
                        if (r < 0)
×
3452
                                return r;
3453
                        c->restrict_filesystems_allow_list = r;
×
3454
                } else if ((val = startswith(l, "exec-context-address-families="))) {
19,471✔
3455
                        int af;
9,187✔
3456

3457
                        r = safe_atoi(val, &af);
9,187✔
3458
                        if (r < 0)
9,187✔
UNCOV
3459
                                return r;
×
3460

3461
                        r = set_ensure_put(&c->address_families, NULL, INT_TO_PTR(af));
9,187✔
3462
                        if (r < 0)
9,187✔
3463
                                return r;
3464
                } else if ((val = startswith(l, "exec-context-address-families-allow-list="))) {
10,284✔
3465
                        r = parse_boolean(val);
2,176✔
3466
                        if (r < 0)
2,176✔
3467
                                return r;
3468
                        c->address_families_allow_list = r;
2,176✔
3469
                } else if ((val = startswith(l, "exec-context-network-namespace-path="))) {
8,108✔
UNCOV
3470
                        r = free_and_strdup(&c->network_namespace_path, val);
×
UNCOV
3471
                        if (r < 0)
×
3472
                                return r;
3473
                } else if ((val = startswith(l, "exec-context-ipc-namespace-path="))) {
8,108✔
UNCOV
3474
                        r = free_and_strdup(&c->ipc_namespace_path, val);
×
3475
                        if (r < 0)
×
3476
                                return r;
3477
                } else if ((val = startswith(l, "exec-context-mount-image="))) {
8,108✔
UNCOV
3478
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3479
                        _cleanup_free_ char *source = NULL, *destination = NULL;
41✔
3480
                        bool permissive = false;
41✔
3481
                        char *s;
41✔
3482

3483
                        r = extract_many_words(&val,
41✔
3484
                                               NULL,
3485
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3486
                                               &source,
3487
                                               &destination);
3488
                        if (r < 0)
41✔
3489
                                return r;
3490
                        if (r == 0)
41✔
3491
                                return -EINVAL;
3492

3493
                        s = source;
41✔
3494
                        if (s[0] == '-') {
41✔
UNCOV
3495
                                permissive = true;
×
UNCOV
3496
                                s++;
×
3497
                        }
3498

3499
                        if (isempty(destination))
41✔
3500
                                continue;
×
3501

3502
                        for (;;) {
46✔
3503
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
5✔
3504
                                PartitionDesignator partition_designator;
46✔
3505
                                MountOptions *o = NULL;
46✔
3506
                                const char *p;
46✔
3507

3508
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
46✔
3509
                                if (r < 0)
46✔
3510
                                        return r;
3511
                                if (r == 0)
46✔
3512
                                        break;
3513

3514
                                p = tuple;
5✔
3515
                                r = extract_many_words(&p,
5✔
3516
                                                       ":",
3517
                                                       EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3518
                                                       &partition,
3519
                                                       &opts);
3520
                                if (r < 0)
5✔
3521
                                        return r;
3522
                                if (r == 0)
5✔
UNCOV
3523
                                        continue;
×
3524
                                if (r == 1) {
5✔
3525
                                        o = new(MountOptions, 1);
×
UNCOV
3526
                                        if (!o)
×
UNCOV
3527
                                                return log_oom_debug();
×
UNCOV
3528
                                        *o = (MountOptions) {
×
3529
                                                .partition_designator = PARTITION_ROOT,
UNCOV
3530
                                                .options = TAKE_PTR(partition),
×
3531
                                        };
UNCOV
3532
                                        LIST_APPEND(mount_options, options, o);
×
3533

UNCOV
3534
                                        continue;
×
3535
                                }
3536

3537
                                partition_designator = partition_designator_from_string(partition);
5✔
3538
                                if (partition_designator < 0)
5✔
UNCOV
3539
                                        continue;
×
3540

3541
                                o = new(MountOptions, 1);
5✔
3542
                                if (!o)
5✔
UNCOV
3543
                                        return log_oom_debug();
×
3544
                                *o = (MountOptions) {
5✔
3545
                                        .partition_designator = partition_designator,
3546
                                        .options = TAKE_PTR(opts),
5✔
3547
                                };
3548
                                LIST_APPEND(mount_options, options, o);
5✔
3549
                        }
3550

3551
                        r = mount_image_add(&c->mount_images, &c->n_mount_images,
82✔
3552
                                        &(MountImage) {
41✔
3553
                                                .source = s,
3554
                                                .destination = destination,
3555
                                                .mount_options = options,
3556
                                                .ignore_enoent = permissive,
3557
                                                .type = MOUNT_IMAGE_DISCRETE,
3558
                                        });
3559
                        if (r < 0)
41✔
UNCOV
3560
                                return log_oom_debug();
×
3561
                } else if ((val = startswith(l, "exec-context-extension-image="))) {
8,067✔
UNCOV
3562
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3563
                        _cleanup_free_ char *source = NULL;
13✔
3564
                        bool permissive = false;
13✔
3565
                        char *s;
13✔
3566

3567
                        r = extract_first_word(&val,
13✔
3568
                                               &source,
3569
                                               NULL,
3570
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS);
3571
                        if (r < 0)
13✔
3572
                                return r;
3573
                        if (r == 0)
13✔
3574
                                return -EINVAL;
3575

3576
                        s = source;
13✔
3577
                        if (s[0] == '-') {
13✔
3578
                                permissive = true;
3✔
3579
                                s++;
3✔
3580
                        }
3581

3582
                        for (;;) {
13✔
UNCOV
3583
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
×
3584
                                PartitionDesignator partition_designator;
13✔
3585
                                MountOptions *o = NULL;
13✔
3586
                                const char *p;
13✔
3587

3588
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
13✔
3589
                                if (r < 0)
13✔
3590
                                        return r;
3591
                                if (r == 0)
13✔
3592
                                        break;
3593

UNCOV
3594
                                p = tuple;
×
UNCOV
3595
                                r = extract_many_words(&p,
×
3596
                                                       ":",
3597
                                                       EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3598
                                                       &partition,
3599
                                                       &opts);
UNCOV
3600
                                if (r < 0)
×
3601
                                        return r;
UNCOV
3602
                                if (r == 0)
×
UNCOV
3603
                                        continue;
×
UNCOV
3604
                                if (r == 1) {
×
UNCOV
3605
                                        o = new(MountOptions, 1);
×
UNCOV
3606
                                        if (!o)
×
UNCOV
3607
                                                return log_oom_debug();
×
UNCOV
3608
                                        *o = (MountOptions) {
×
3609
                                                .partition_designator = PARTITION_ROOT,
UNCOV
3610
                                                .options = TAKE_PTR(partition),
×
3611
                                        };
3612
                                        LIST_APPEND(mount_options, options, o);
×
3613

UNCOV
3614
                                        continue;
×
3615
                                }
3616

UNCOV
3617
                                partition_designator = partition_designator_from_string(partition);
×
UNCOV
3618
                                if (partition_designator < 0)
×
UNCOV
3619
                                        continue;
×
3620

UNCOV
3621
                                o = new(MountOptions, 1);
×
UNCOV
3622
                                if (!o)
×
3623
                                        return log_oom_debug();
×
3624
                                *o = (MountOptions) {
×
3625
                                        .partition_designator = partition_designator,
UNCOV
3626
                                        .options = TAKE_PTR(opts),
×
3627
                                };
UNCOV
3628
                                LIST_APPEND(mount_options, options, o);
×
3629
                        }
3630

3631
                        r = mount_image_add(&c->extension_images, &c->n_extension_images,
26✔
3632
                                        &(MountImage) {
13✔
3633
                                                .source = s,
3634
                                                .mount_options = options,
3635
                                                .ignore_enoent = permissive,
3636
                                                .type = MOUNT_IMAGE_EXTENSION,
3637
                                        });
3638
                        if (r < 0)
13✔
3639
                                return log_oom_debug();
×
3640
                } else if ((val = startswith(l, "exec-context-extension-directories="))) {
8,054✔
3641
                        r = deserialize_strv(val, &c->extension_directories);
8✔
3642
                        if (r < 0)
8✔
3643
                                return r;
3644
                } else if ((val = startswith(l, "exec-context-set-credentials="))) {
8,046✔
UNCOV
3645
                        _cleanup_free_ char *id = NULL, *data = NULL, *encrypted = NULL;
×
3646

3647
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &data, &encrypted);
186✔
3648
                        if (r < 0)
186✔
3649
                                return r;
3650
                        if (r != 3)
186✔
3651
                                return -EINVAL;
3652

3653
                        r = parse_boolean(encrypted);
186✔
3654
                        if (r < 0)
186✔
3655
                                return r;
3656
                        bool e = r;
186✔
3657

3658
                        _cleanup_free_ void *d = NULL;
186✔
3659
                        size_t size;
186✔
3660

3661
                        r = unbase64mem_full(data, SIZE_MAX, /* secure = */ true, &d, &size);
186✔
3662
                        if (r < 0)
186✔
3663
                                return r;
3664

3665
                        r = exec_context_put_set_credential(c, id, TAKE_PTR(d), size, e);
186✔
3666
                        if (r < 0)
186✔
3667
                                return r;
3668
                } else if ((val = startswith(l, "exec-context-load-credentials="))) {
7,860✔
3669
                        _cleanup_free_ char *id = NULL, *path = NULL, *encrypted = NULL;
61✔
3670

3671
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &path, &encrypted);
61✔
3672
                        if (r < 0)
61✔
3673
                                return r;
3674
                        if (r != 3)
61✔
3675
                                return -EINVAL;
3676

3677
                        r = parse_boolean(encrypted);
61✔
3678
                        if (r < 0)
61✔
3679
                                return r;
3680

3681
                        r = exec_context_put_load_credential(c, id, path, r > 0);
61✔
3682
                        if (r < 0)
61✔
3683
                                return r;
3684
                } else if ((val = startswith(l, "exec-context-import-credentials="))) {
7,799✔
3685
                        _cleanup_free_ char *glob = NULL, *rename = NULL;
7,793✔
3686

3687
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &glob, &rename);
7,793✔
3688
                        if (r < 0)
7,793✔
3689
                                return r;
3690
                        if (r == 0)
7,793✔
3691
                                return -EINVAL;
3692

3693
                        r = exec_context_put_import_credential(c, glob, rename);
7,793✔
3694
                        if (r < 0)
7,793✔
3695
                                return r;
3696
                } else if ((val = startswith(l, "exec-context-root-image-policy="))) {
6✔
3697
                        if (c->root_image_policy)
4✔
3698
                                return -EINVAL; /* duplicated */
3699

3700
                        r = image_policy_from_string(val, &c->root_image_policy);
4✔
3701
                        if (r < 0)
4✔
3702
                                return r;
3703
                } else if ((val = startswith(l, "exec-context-mount-image-policy="))) {
2✔
UNCOV
3704
                        if (c->mount_image_policy)
×
3705
                                return -EINVAL; /* duplicated */
3706

UNCOV
3707
                        r = image_policy_from_string(val, &c->mount_image_policy);
×
UNCOV
3708
                        if (r < 0)
×
3709
                                return r;
3710
                } else if ((val = startswith(l, "exec-context-extension-image-policy="))) {
2✔
3711
                        if (c->extension_image_policy)
2✔
3712
                                return -EINVAL; /* duplicated */
3713

3714
                        r = image_policy_from_string(val, &c->extension_image_policy);
2✔
3715
                        if (r < 0)
2✔
3716
                                return r;
3717
                } else
UNCOV
3718
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3719
        }
3720

3721
        return 0;
11,867✔
3722
}
3723

3724
static int exec_command_serialize(const ExecCommand *c, FILE *f) {
2,115✔
3725
        int r;
2,115✔
3726

3727
        assert(c);
2,115✔
3728
        assert(f);
2,115✔
3729

3730
        r = serialize_item(f, "exec-command-path", c->path);
2,115✔
3731
        if (r < 0)
2,115✔
3732
                return r;
3733

3734
        r = serialize_strv(f, "exec-command-argv", c->argv);
2,115✔
3735
        if (r < 0)
2,115✔
3736
                return r;
3737

3738
        r = serialize_item_format(f, "exec-command-flags", "%d", (int) c->flags);
2,115✔
3739
        if (r < 0)
2,115✔
3740
                return r;
3741

3742
        fputc('\n', f); /* End marker */
2,115✔
3743

3744
        return 0;
2,115✔
3745
}
3746

3747
static int exec_command_deserialize(ExecCommand *c, FILE *f) {
11,867✔
3748
        int r;
11,867✔
3749

3750
        assert(c);
11,867✔
3751
        assert(f);
11,867✔
3752

3753
        for (;;) {
126,689✔
3754
                _cleanup_free_ char *l = NULL;
57,411✔
3755
                const char *val;
69,278✔
3756

3757
                r = deserialize_read_line(f, &l);
69,278✔
3758
                if (r < 0)
69,278✔
3759
                        return r;
3760
                if (r == 0) /* eof or end marker */
69,278✔
3761
                        break;
3762

3763
                if ((val = startswith(l, "exec-command-path="))) {
57,411✔
3764
                        r = free_and_strdup(&c->path, val);
11,867✔
3765
                        if (r < 0)
11,867✔
3766
                                return r;
3767
                } else if ((val = startswith(l, "exec-command-argv="))) {
45,544✔
3768
                        r = deserialize_strv(val, &c->argv);
33,677✔
3769
                        if (r < 0)
33,677✔
3770
                                return r;
3771
                } else if ((val = startswith(l, "exec-command-flags="))) {
11,867✔
3772
                        r = safe_atoi(val, &c->flags);
11,867✔
3773
                        if (r < 0)
11,867✔
3774
                                return r;
3775
                } else
UNCOV
3776
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3777

3778
        }
3779

3780
        return 0;
11,867✔
3781
}
3782

3783
int exec_serialize_invocation(
2,115✔
3784
                FILE *f,
3785
                FDSet *fds,
3786
                const ExecContext *ctx,
3787
                const ExecCommand *cmd,
3788
                const ExecParameters *p,
3789
                const ExecRuntime *rt,
3790
                const CGroupContext *cg) {
3791

3792
        int r;
2,115✔
3793

3794
        assert(f);
2,115✔
3795
        assert(fds);
2,115✔
3796

3797
        r = exec_context_serialize(ctx, f);
2,115✔
3798
        if (r < 0)
2,115✔
UNCOV
3799
                return log_debug_errno(r, "Failed to serialize context: %m");
×
3800

3801
        r = exec_command_serialize(cmd, f);
2,115✔
3802
        if (r < 0)
2,115✔
UNCOV
3803
                return log_debug_errno(r, "Failed to serialize command: %m");
×
3804

3805
        r = exec_parameters_serialize(p, ctx, f, fds);
2,115✔
3806
        if (r < 0)
2,115✔
UNCOV
3807
                return log_debug_errno(r, "Failed to serialize parameters: %m");
×
3808

3809
        r = exec_runtime_serialize(rt, f, fds);
2,115✔
3810
        if (r < 0)
2,115✔
UNCOV
3811
                return log_debug_errno(r, "Failed to serialize runtime: %m");
×
3812

3813
        r = exec_cgroup_context_serialize(cg, f);
2,115✔
3814
        if (r < 0)
2,115✔
UNCOV
3815
                return log_debug_errno(r, "Failed to serialize cgroup context: %m");
×
3816

3817
        return 0;
3818
}
3819

3820
int exec_deserialize_invocation(
11,867✔
3821
                FILE *f,
3822
                FDSet *fds,
3823
                ExecContext *ctx,
3824
                ExecCommand *cmd,
3825
                ExecParameters *p,
3826
                ExecRuntime *rt,
3827
                CGroupContext *cg) {
3828

3829
        int r;
11,867✔
3830

3831
        assert(f);
11,867✔
3832
        assert(fds);
11,867✔
3833

3834
        r = exec_context_deserialize(ctx, f);
11,867✔
3835
        if (r < 0)
11,867✔
3836
                return log_debug_errno(r, "Failed to deserialize context: %m");
×
3837

3838
        r = exec_command_deserialize(cmd, f);
11,867✔
3839
        if (r < 0)
11,867✔
3840
                return log_debug_errno(r, "Failed to deserialize command: %m");
×
3841

3842
        r = exec_parameters_deserialize(p, f, fds);
11,867✔
3843
        if (r < 0)
11,867✔
3844
                return log_debug_errno(r, "Failed to deserialize parameters: %m");
×
3845

3846
        r = exec_runtime_deserialize(rt, f, fds);
11,867✔
3847
        if (r < 0)
11,867✔
UNCOV
3848
                return log_debug_errno(r, "Failed to deserialize runtime: %m");
×
3849

3850
        r = exec_cgroup_context_deserialize(cg, f);
11,867✔
3851
        if (r < 0)
11,867✔
UNCOV
3852
                return log_debug_errno(r, "Failed to deserialize cgroup context: %m");
×
3853

3854
        return 0;
3855
}
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