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

systemd / systemd / 20561496515

28 Dec 2025 11:55AM UTC coverage: 72.478% (-0.2%) from 72.692%
20561496515

push

github

web-flow
core: several follow-ups for BindNetworkInterface= (#40202)

13 of 54 new or added lines in 5 files covered. (24.07%)

1051 existing lines in 43 files now uncovered.

309149 of 426542 relevant lines covered (72.48%)

1254687.42 hits per line

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

71.28
/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,422✔
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,422✔
38
        char *iface;
2,422✔
39
        struct in_addr_prefix *iaai;
2,422✔
40
        int r;
2,422✔
41

42
        assert(f);
2,422✔
43

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

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

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

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

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

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

67
        if (c->cpu_weight != CGROUP_WEIGHT_INVALID) {
2,422✔
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,422✔
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,422✔
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,422✔
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,422✔
92
        if (!cpuset_cpus)
2,422✔
93
                return log_oom_debug();
×
94

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

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

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

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

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

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

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

123
        if (c->io_weight != CGROUP_WEIGHT_INVALID) {
2,422✔
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,422✔
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,422✔
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,422✔
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,422✔
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,422✔
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,422✔
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,422✔
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,422✔
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,422✔
178
                r = serialize_item_format(f, "exec-cgroup-context-memory-max", "%" PRIu64, c->memory_max);
1✔
179
                if (r < 0)
1✔
180
                        return r;
181
        }
182

183
        if (c->startup_memory_max != CGROUP_LIMIT_MAX) {
2,422✔
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,422✔
190
                r = serialize_item_format(f, "exec-cgroup-context-memory-swap-max", "%" PRIu64, c->memory_swap_max);
1✔
191
                if (r < 0)
1✔
192
                        return r;
193
        }
194

195
        if (c->startup_memory_swap_max != CGROUP_LIMIT_MAX) {
2,422✔
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,422✔
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,422✔
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,422✔
214
        if (r < 0)
2,422✔
215
                return r;
216

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

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

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

233
        r = serialize_bool_elide(f, "exec-cgroup-context-default-memory-low-set", c->default_memory_low_set);
2,422✔
234
        if (r < 0)
2,422✔
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,422✔
238
        if (r < 0)
2,422✔
239
                return r;
240

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

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

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

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

257
        r = serialize_bool_elide(f, "exec-cgroup-context-startup-memory-max-set", c->startup_memory_max_set);
2,422✔
258
        if (r < 0)
2,422✔
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,422✔
262
        if (r < 0)
2,422✔
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,422✔
266
        if (r < 0)
2,422✔
267
                return r;
268

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

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

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

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

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

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

293
        r = serialize_item(f, "exec-cgroup-context-managed-oom-swap", managed_oom_mode_to_string(c->moom_swap));
2,422✔
294
        if (r < 0)
2,422✔
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,422✔
298
        if (r < 0)
2,422✔
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,422✔
302
        if (r < 0)
2,422✔
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,422✔
306
        if (r < 0)
2,422✔
307
                return r;
308

309
        r = serialize_item(f, "exec-cgroup-context-managed-oom-preference", managed_oom_preference_to_string(c->moom_preference));
2,422✔
310
        if (r < 0)
2,422✔
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,422✔
314
        if (r < 0)
2,422✔
315
                return r;
316

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

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

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

335
        LIST_FOREACH(device_weights, iw, c->io_device_weights) {
2,422✔
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,422✔
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,422✔
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,422✔
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,692✔
375
                r = serialize_item(f,
270✔
376
                                   "exec-cgroup-context-ip-address-deny",
377
                                   IN_ADDR_PREFIX_TO_STRING(iaai->family, &iaai->address, iaai->prefixlen));
270✔
378
                if (r < 0)
270✔
379
                        return r;
×
380
        }
381

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

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

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

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

398
        LIST_FOREACH(programs, p, c->bpf_foreign_programs) {
2,422✔
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,422✔
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,422✔
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,422✔
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,844✔
425
                        f,
426
                        "exec-cgroup-context-restrict-network-interfaces-is-allow-list",
427
                        c->restrict_network_interfaces_is_allow_list);
2,422✔
428
        if (r < 0)
2,422✔
429
                return r;
430

431
        r = serialize_item(f, "exec-cgroup-context-bind-iface", c->bind_network_interface);
2,422✔
432
        if (r < 0)
2,422✔
433
                return r;
434

435
        fputc('\n', f); /* End marker */
2,422✔
436

437
        return 0;
438
}
439

440
static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) {
10,019✔
441
        int r;
10,019✔
442

443
        assert(f);
10,019✔
444

445
        if (!c)
10,019✔
446
                return 0;
447

448
        for (;;) {
373,765✔
449
                _cleanup_free_ char *l = NULL;
181,873✔
450
                const char *val;
191,892✔
451

452
                r = deserialize_read_line(f, &l);
191,892✔
453
                if (r < 0)
191,892✔
454
                        return r;
455
                if (r == 0) /* eof or end marker */
191,892✔
456
                        break;
457

458
                if ((val = startswith(l, "exec-cgroup-context-io-accounting="))) {
181,873✔
459
                        r = parse_boolean(val);
2✔
460
                        if (r < 0)
2✔
461
                                return r;
462
                        c->io_accounting = r;
2✔
463
                } else if ((val = startswith(l, "exec-cgroup-context-memory-accounting="))) {
181,871✔
464
                        r = parse_boolean(val);
9,697✔
465
                        if (r < 0)
9,697✔
466
                                return r;
467
                        c->memory_accounting = r;
9,697✔
468
                } else if ((val = startswith(l, "exec-cgroup-context-tasks-accounting="))) {
172,174✔
469
                        r = parse_boolean(val);
10,019✔
470
                        if (r < 0)
10,019✔
471
                                return r;
472
                        c->tasks_accounting = r;
10,019✔
473
                } else if ((val = startswith(l, "exec-cgroup-context-ip-accounting="))) {
162,155✔
474
                        r = parse_boolean(val);
×
475
                        if (r < 0)
×
476
                                return r;
477
                        c->ip_accounting = r;
×
478
                } else if ((val = startswith(l, "exec-cgroup-context-memory-oom-group="))) {
162,155✔
479
                        r = parse_boolean(val);
2✔
480
                        if (r < 0)
2✔
481
                                return r;
482
                        c->memory_oom_group = r;
2✔
483
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-weight="))) {
162,153✔
484
                        r = safe_atou64(val, &c->cpu_weight);
1✔
485
                        if (r < 0)
1✔
486
                                return r;
487
                } else if ((val = startswith(l, "exec-cgroup-context-startup-cpu-weight="))) {
162,152✔
488
                        r = safe_atou64(val, &c->startup_cpu_weight);
×
489
                        if (r < 0)
×
490
                                return r;
491
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-quota-per-sec-usec="))) {
162,152✔
492
                        r = deserialize_usec(val, &c->cpu_quota_per_sec_usec);
×
493
                        if (r < 0)
×
494
                                return r;
495
                } else if ((val = startswith(l, "exec-cgroup-context-cpu-quota-period-usec="))) {
162,152✔
496
                        r = deserialize_usec(val, &c->cpu_quota_period_usec);
×
497
                        if (r < 0)
×
498
                                return r;
499
                } else if ((val = startswith(l, "exec-cgroup-context-allowed-cpus="))) {
162,152✔
500
                        if (c->cpuset_cpus.set)
10,019✔
501
                                return -EINVAL; /* duplicated */
502

503
                        r = parse_cpu_set(val, &c->cpuset_cpus);
10,019✔
504
                        if (r < 0)
10,019✔
505
                                return r;
506
                } else if ((val = startswith(l, "exec-cgroup-context-startup-allowed-cpus="))) {
152,133✔
507
                        if (c->startup_cpuset_cpus.set)
10,019✔
508
                                return -EINVAL; /* duplicated */
509

510
                        r = parse_cpu_set(val, &c->startup_cpuset_cpus);
10,019✔
511
                        if (r < 0)
10,019✔
512
                                return r;
513
                } else if ((val = startswith(l, "exec-cgroup-context-allowed-memory-nodes="))) {
142,114✔
514
                        if (c->cpuset_mems.set)
10,019✔
515
                                return -EINVAL; /* duplicated */
516

517
                        r = parse_cpu_set(val, &c->cpuset_mems);
10,019✔
518
                        if (r < 0)
10,019✔
519
                                return r;
520
                } else if ((val = startswith(l, "exec-cgroup-context-startup-allowed-memory-nodes="))) {
132,095✔
521
                        if (c->startup_cpuset_mems.set)
10,019✔
522
                                return -EINVAL; /* duplicated */
523

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

703
                        r = extract_many_words(&val, " ", 0, &path, &rwm);
3,337✔
704
                        if (r < 0)
3,337✔
705
                                return r;
706
                        if (r == 0)
3,337✔
707
                                return -EINVAL;
708

709
                        p = isempty(rwm) ? 0 : cgroup_device_permissions_from_string(rwm);
6,674✔
710
                        if (p < 0)
3,337✔
711
                                return p;
712

713
                        r = cgroup_context_add_or_update_device_allow(c, path, p);
3,337✔
714
                        if (r < 0)
3,337✔
715
                                return r;
716
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-weight="))) {
17,526✔
717
                        _cleanup_free_ char *path = NULL, *weight = NULL;
×
718
                        CGroupIODeviceWeight *a = NULL;
×
719

720
                        r = extract_many_words(&val, " ", 0, &path, &weight);
×
721
                        if (r < 0)
×
722
                                return r;
723
                        if (r != 2)
×
724
                                return -EINVAL;
725

726
                        LIST_FOREACH(device_weights, b, c->io_device_weights)
×
727
                                if (path_equal(b->path, path)) {
×
728
                                        a = b;
729
                                        break;
730
                                }
731

732
                        if (!a) {
×
733
                                a = new0(CGroupIODeviceWeight, 1);
×
734
                                if (!a)
×
735
                                        return log_oom_debug();
×
736

737
                                a->path = TAKE_PTR(path);
×
738

739
                                LIST_PREPEND(device_weights, c->io_device_weights, a);
×
740
                        }
741

742
                        r = safe_atou64(weight, &a->weight);
×
743
                        if (r < 0)
×
744
                                return r;
745
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-latency-target-usec="))) {
17,526✔
746
                        _cleanup_free_ char *path = NULL, *target = NULL;
×
747
                        CGroupIODeviceLatency *a = NULL;
×
748

749
                        r = extract_many_words(&val, " ", 0, &path, &target);
×
750
                        if (r < 0)
×
751
                                return r;
752
                        if (r != 2)
×
753
                                return -EINVAL;
754

755
                        LIST_FOREACH(device_latencies, b, c->io_device_latencies)
×
756
                                if (path_equal(b->path, path)) {
×
757
                                        a = b;
758
                                        break;
759
                                }
760

761
                        if (!a) {
×
762
                                a = new0(CGroupIODeviceLatency, 1);
×
763
                                if (!a)
×
764
                                        return log_oom_debug();
×
765

766
                                a->path = TAKE_PTR(path);
×
767

768
                                LIST_PREPEND(device_latencies, c->io_device_latencies, a);
×
769
                        }
770

771
                        r = deserialize_usec(target, &a->target_usec);
×
772
                        if (r < 0)
×
773
                                return r;
774
                } else if ((val = startswith(l, "exec-cgroup-context-io-device-limit-"))) {
17,526✔
775
                        _cleanup_free_ char *type = NULL, *path = NULL, *limits = NULL;
×
776
                        CGroupIODeviceLimit *limit = NULL;
×
777
                        CGroupIOLimitType t;
×
778

779
                        r = extract_many_words(&val, "= ", 0, &type, &path, &limits);
×
780
                        if (r < 0)
×
781
                                return r;
782
                        if (r != 3)
×
783
                                return -EINVAL;
784

785
                        t = cgroup_io_limit_type_from_string(type);
×
786
                        if (t < 0)
×
787
                                return t;
788

789
                        LIST_FOREACH(device_limits, i, c->io_device_limits)
×
790
                                if (path_equal(path, i->path)) {
×
791
                                        limit = i;
792
                                        break;
793
                                }
794

795
                        if (!limit) {
×
796
                                limit = new0(CGroupIODeviceLimit, 1);
×
797
                                if (!limit)
×
798
                                        return log_oom_debug();
×
799

800
                                limit->path = TAKE_PTR(path);
×
801
                                for (CGroupIOLimitType i = 0; i < _CGROUP_IO_LIMIT_TYPE_MAX; i++)
×
802
                                        limit->limits[i] = cgroup_io_limit_defaults[i];
×
803

804
                                LIST_PREPEND(device_limits, c->io_device_limits, limit);
×
805
                        }
806

807
                        r = safe_atou64(limits, &limit->limits[t]);
×
808
                        if (r < 0)
×
809
                                return r;
810
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-allow="))) {
17,526✔
811
                        struct in_addr_prefix a;
×
812

813
                        r = in_addr_prefix_from_string_auto(val, &a.family, &a.address, &a.prefixlen);
×
814
                        if (r < 0)
×
815
                                return r;
×
816

817
                        r = in_addr_prefix_add(&c->ip_address_allow, &a);
×
818
                        if (r < 0)
×
819
                                return r;
820
                } else if ((val = startswith(l, "exec-cgroup-context-ip-address-deny="))) {
17,526✔
821
                        struct in_addr_prefix a;
1,366✔
822

823
                        r = in_addr_prefix_from_string_auto(val, &a.family, &a.address, &a.prefixlen);
1,366✔
824
                        if (r < 0)
1,366✔
825
                                return r;
×
826

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

852
                        r = extract_many_words(&val, " ", 0, &type, &path);
×
853
                        if (r < 0)
×
854
                                return r;
855
                        if (r != 2)
×
856
                                return -EINVAL;
857

858
                        r = safe_atou32(type, &t);
×
859
                        if (r < 0)
×
860
                                return r;
861

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

870
                        r = parse_socket_bind_item(val, &af, &ip_protocol, &nr_ports, &port_min);
×
871
                        if (r < 0)
×
872
                                return r;
×
873

874
                        item = new(CGroupSocketBindItem, 1);
×
875
                        if (!item)
×
876
                                return log_oom_debug();
×
877
                        *item = (CGroupSocketBindItem) {
×
878
                                .address_family = af,
879
                                .ip_protocol = ip_protocol,
880
                                .nr_ports = nr_ports,
881
                                .port_min = port_min,
882
                        };
883

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

890
                        r = parse_socket_bind_item(val, &af, &ip_protocol, &nr_ports, &port_min);
×
891
                        if (r < 0)
×
892
                                return r;
×
893

894
                        item = new(CGroupSocketBindItem, 1);
×
895
                        if (!item)
×
896
                                return log_oom_debug();
×
897
                        *item = (CGroupSocketBindItem) {
×
898
                                .address_family = af,
899
                                .ip_protocol = ip_protocol,
900
                                .nr_ports = nr_ports,
901
                                .port_min = port_min,
902
                        };
903

904
                        LIST_PREPEND(socket_bind_items, c->socket_bind_deny, item);
×
905
                } else if ((val = startswith(l, "exec-cgroup-context-restrict-network-interfaces="))) {
24✔
906
                        r = set_put_strdup(&c->restrict_network_interfaces, val);
15✔
907
                        if (r < 0)
15✔
908
                                return r;
909
                } else if ((val = startswith(l, "exec-cgroup-context-restrict-network-interfaces-is-allow-list="))) {
9✔
910
                        r = parse_boolean(val);
9✔
911
                        if (r < 0)
9✔
912
                                return r;
913
                        c->restrict_network_interfaces_is_allow_list = r;
9✔
914
                } else if ((val = startswith(l, "exec-cgroup-context-bind-iface="))) {
×
915
                        r = free_and_strdup(&c->bind_network_interface, val);
×
916
                        if (r < 0)
×
917
                                return r;
918
                } else
919
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
920
        }
921

922
        return 0;
10,019✔
923
}
924

925
static int exec_runtime_serialize(const ExecRuntime *rt, FILE *f, FDSet *fds) {
2,422✔
926
        int r;
2,422✔
927

928
        assert(f);
2,422✔
929
        assert(fds);
2,422✔
930

931
        if (!rt) {
2,422✔
932
                fputc('\n', f); /* End marker */
2,345✔
933
                return 0;
2,345✔
934
        }
935

936
        if (rt->shared) {
77✔
937
                r = serialize_item(f, "exec-runtime-id", rt->shared->id);
75✔
938
                if (r < 0)
75✔
939
                        return r;
940

941
                r = serialize_item(f, "exec-runtime-tmp-dir", rt->shared->tmp_dir);
75✔
942
                if (r < 0)
75✔
943
                        return r;
944

945
                r = serialize_item(f, "exec-runtime-var-tmp-dir", rt->shared->var_tmp_dir);
75✔
946
                if (r < 0)
75✔
947
                        return r;
948

949
                if (rt->shared->userns_storage_socket[0] >= 0 && rt->shared->userns_storage_socket[1] >= 0) {
75✔
950
                        r = serialize_fd_many(f, fds, "exec-runtime-userns-storage-socket", rt->shared->userns_storage_socket, 2);
×
951
                        if (r < 0)
×
952
                                return r;
953
                }
954

955
                if (rt->shared->netns_storage_socket[0] >= 0 && rt->shared->netns_storage_socket[1] >= 0) {
75✔
956
                        r = serialize_fd_many(f, fds, "exec-runtime-netns-storage-socket", rt->shared->netns_storage_socket, 2);
8✔
957
                        if (r < 0)
8✔
958
                                return r;
959
                }
960

961
                if (rt->shared->ipcns_storage_socket[0] >= 0 && rt->shared->ipcns_storage_socket[1] >= 0) {
75✔
962
                        r = serialize_fd_many(f, fds, "exec-runtime-ipcns-storage-socket", rt->shared->ipcns_storage_socket, 2);
2✔
963
                        if (r < 0)
2✔
964
                                return r;
965
                }
966
        }
967

968
        if (rt->dynamic_creds) {
77✔
969
                r = dynamic_user_serialize_one(rt->dynamic_creds->user, "exec-runtime-dynamic-creds-user", f, fds);
2✔
970
                if (r < 0)
2✔
971
                        return r;
972
        }
973

974
        if (rt->dynamic_creds && rt->dynamic_creds->group && rt->dynamic_creds->group == rt->dynamic_creds->user) {
77✔
975
                r = serialize_bool(f, "exec-runtime-dynamic-creds-group-copy", true);
2✔
976
                if (r < 0)
2✔
977
                        return r;
978
        } else if (rt->dynamic_creds) {
75✔
979
                r = dynamic_user_serialize_one(rt->dynamic_creds->group, "exec-runtime-dynamic-creds-group", f, fds);
×
980
                if (r < 0)
×
981
                        return r;
982
        }
983

984
        r = serialize_item(f, "exec-runtime-ephemeral-copy", rt->ephemeral_copy);
77✔
985
        if (r < 0)
77✔
986
                return r;
987

988
        if (rt->ephemeral_storage_socket[0] >= 0 && rt->ephemeral_storage_socket[1] >= 0) {
77✔
989
                r = serialize_fd_many(f, fds, "exec-runtime-ephemeral-storage-socket", rt->ephemeral_storage_socket, 2);
×
990
                if (r < 0)
×
991
                        return r;
992
        }
993

994
        fputc('\n', f); /* End marker */
77✔
995

996
        return 0;
77✔
997
}
998

999
static int exec_runtime_deserialize(ExecRuntime *rt, FILE *f, FDSet *fds) {
10,019✔
1000
        int r;
10,019✔
1001

1002
        assert(rt);
10,019✔
1003
        assert(rt->shared);
10,019✔
1004
        assert(rt->dynamic_creds);
10,019✔
1005
        assert(f);
10,019✔
1006
        assert(fds);
10,019✔
1007

1008
        for (;;) {
11,264✔
1009
                _cleanup_free_ char *l = NULL;
1,245✔
1010
                const char *val;
11,264✔
1011

1012
                r = deserialize_read_line(f, &l);
11,264✔
1013
                if (r < 0)
11,264✔
1014
                        return r;
1015
                if (r == 0) /* eof or end marker */
11,264✔
1016
                        break;
1017

1018
                if ((val = startswith(l, "exec-runtime-id="))) {
1,245✔
1019
                        r = free_and_strdup(&rt->shared->id, val);
373✔
1020
                        if (r < 0)
373✔
1021
                                return r;
1022
                } else if ((val = startswith(l, "exec-runtime-tmp-dir="))) {
872✔
1023
                        r = free_and_strdup(&rt->shared->tmp_dir, val);
349✔
1024
                        if (r < 0)
349✔
1025
                                return r;
1026
                } else if ((val = startswith(l, "exec-runtime-var-tmp-dir="))) {
523✔
1027
                        r = free_and_strdup(&rt->shared->var_tmp_dir, val);
349✔
1028
                        if (r < 0)
349✔
1029
                                return r;
1030
                } else if ((val = startswith(l, "exec-runtime-userns-storage-socket="))) {
174✔
1031

1032
                        r = deserialize_fd_many(fds, val, 2, rt->shared->userns_storage_socket);
3✔
1033
                        if (r < 0)
3✔
1034
                                continue;
×
1035

1036
                } else if ((val = startswith(l, "exec-runtime-netns-storage-socket="))) {
171✔
1037

1038
                        r = deserialize_fd_many(fds, val, 2, rt->shared->netns_storage_socket);
71✔
1039
                        if (r < 0)
71✔
1040
                                continue;
×
1041

1042
                } else if ((val = startswith(l, "exec-runtime-ipcns-storage-socket="))) {
100✔
1043

1044
                        r = deserialize_fd_many(fds, val, 2, rt->shared->ipcns_storage_socket);
6✔
1045
                        if (r < 0)
6✔
1046
                                continue;
×
1047

1048
                } else if ((val = startswith(l, "exec-runtime-dynamic-creds-user=")))
94✔
1049
                        dynamic_user_deserialize_one(/* m= */ NULL, val, fds, &rt->dynamic_creds->user);
47✔
1050
                else if ((val = startswith(l, "exec-runtime-dynamic-creds-group=")))
47✔
1051
                        dynamic_user_deserialize_one(/* m= */ NULL, val, fds, &rt->dynamic_creds->group);
×
1052
                else if ((val = startswith(l, "exec-runtime-dynamic-creds-group-copy="))) {
47✔
1053
                        r = parse_boolean(val);
47✔
1054
                        if (r < 0)
47✔
1055
                                return r;
1056
                        if (!r)
47✔
1057
                                continue; /* Nothing to do */
×
1058

1059
                        if (!rt->dynamic_creds->user)
47✔
1060
                                return -EINVAL;
1061

1062
                        rt->dynamic_creds->group = dynamic_user_ref(rt->dynamic_creds->user);
47✔
1063
                } else if ((val = startswith(l, "exec-runtime-ephemeral-copy="))) {
×
1064
                        r = free_and_strdup(&rt->ephemeral_copy, val);
×
1065
                        if (r < 0)
×
1066
                                return r;
1067
                } else if ((val = startswith(l, "exec-runtime-ephemeral-storage-socket="))) {
×
1068

1069
                        r = deserialize_fd_many(fds, val, 2, rt->ephemeral_storage_socket);
×
1070
                        if (r < 0)
×
1071
                                continue;
×
1072
                } else
1073
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
1074
        }
1075

1076
        return 0;
10,019✔
1077
}
1078

1079
static bool exec_parameters_is_idle_pipe_set(const ExecParameters *p) {
2,422✔
1080
        assert(p);
2,422✔
1081

1082
        return p->idle_pipe &&
2,452✔
1083
                p->idle_pipe[0] >= 0 &&
30✔
1084
                p->idle_pipe[1] >= 0 &&
28✔
1085
                p->idle_pipe[2] >= 0 &&
2,450✔
1086
                p->idle_pipe[3] >= 0;
28✔
1087
}
1088

1089
static int exec_parameters_serialize(const ExecParameters *p, const ExecContext *c, FILE *f, FDSet *fds) {
2,422✔
1090
        int r;
2,422✔
1091

1092
        assert(f);
2,422✔
1093
        assert(fds);
2,422✔
1094

1095
        if (!p)
2,422✔
1096
                return 0;
1097

1098
        r = serialize_item(f, "exec-parameters-runtime-scope", runtime_scope_to_string(p->runtime_scope));
2,422✔
1099
        if (r < 0)
2,422✔
1100
                return r;
1101

1102
        r = serialize_strv(f, "exec-parameters-environment", p->environment);
2,422✔
1103
        if (r < 0)
2,422✔
1104
                return r;
1105

1106
        if (p->fds) {
2,422✔
1107
                if (p->n_socket_fds > 0) {
534✔
1108
                        r = serialize_item_format(f, "exec-parameters-n-socket-fds", "%zu", p->n_socket_fds);
533✔
1109
                        if (r < 0)
533✔
1110
                                return r;
1111
                }
1112

1113
                if (p->n_stashed_fds > 0) {
534✔
1114
                        r = serialize_item_format(f, "exec-parameters-n-stashed-fds", "%zu", p->n_stashed_fds);
4✔
1115
                        if (r < 0)
4✔
1116
                                return r;
1117
                }
1118

1119
                r = serialize_fd_many(f, fds, "exec-parameters-fds", p->fds, p->n_socket_fds + p->n_stashed_fds);
534✔
1120
                if (r < 0)
534✔
1121
                        return r;
1122

1123
                r = serialize_strv(f, "exec-parameters-fd-names", p->fd_names);
534✔
1124
                if (r < 0)
534✔
1125
                        return r;
1126
        }
1127

1128
        if (p->flags != 0) {
2,422✔
1129
                r = serialize_item_format(f, "exec-parameters-flags", "%u", (unsigned) p->flags);
2,422✔
1130
                if (r < 0)
2,422✔
1131
                        return r;
1132
        }
1133

1134
        r = serialize_bool_elide(f, "exec-parameters-selinux-context-net", p->selinux_context_net);
2,422✔
1135
        if (r < 0)
2,422✔
1136
                return r;
1137

1138
        r = serialize_item(f, "exec-parameters-cgroup-path", p->cgroup_path);
2,422✔
1139
        if (r < 0)
2,422✔
1140
                return r;
1141

1142
        r = serialize_item_format(f, "exec-parameters-cgroup-id", "%" PRIu64, p->cgroup_id);
2,422✔
1143
        if (r < 0)
2,422✔
1144
                return r;
1145

1146
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
14,532✔
1147
                _cleanup_free_ char *key = NULL;
12,110✔
1148

1149
                key = strjoin("exec-parameters-prefix-directories-", exec_directory_type_to_string(dt));
12,110✔
1150
                if (!key)
12,110✔
1151
                        return log_oom_debug();
×
1152

1153
                /* Always serialize, even an empty prefix, as this is a fixed array and we always expect
1154
                 * to have all elements (unless fuzzing is happening, hence the NULL check). */
1155
                r = serialize_item(f, key, strempty(p->prefix ? p->prefix[dt] : NULL));
12,110✔
1156
                if (r < 0)
12,110✔
1157
                        return r;
1158
        }
1159

1160
        r = serialize_item(f, "exec-parameters-received-credentials-directory", p->received_credentials_directory);
2,422✔
1161
        if (r < 0)
2,422✔
1162
                return r;
1163

1164
        r = serialize_item(f, "exec-parameters-received-encrypted-credentials-directory", p->received_encrypted_credentials_directory);
2,422✔
1165
        if (r < 0)
2,422✔
1166
                return r;
1167

1168
        r = serialize_item(f, "exec-parameters-confirm-spawn", p->confirm_spawn);
2,422✔
1169
        if (r < 0)
2,422✔
1170
                return r;
1171

1172
        r = serialize_bool_elide(f, "exec-parameters-shall-confirm-spawn", p->shall_confirm_spawn);
2,422✔
1173
        if (r < 0)
2,422✔
1174
                return r;
1175

1176
        if (p->watchdog_usec > 0) {
2,422✔
1177
                r = serialize_usec(f, "exec-parameters-watchdog-usec", p->watchdog_usec);
232✔
1178
                if (r < 0)
232✔
1179
                        return r;
1180
        }
1181

1182
        if (exec_parameters_is_idle_pipe_set(p)) {
2,422✔
1183
                r = serialize_fd_many(f, fds, "exec-parameters-idle-pipe", p->idle_pipe, 4);
28✔
1184
                if (r < 0)
28✔
1185
                        return r;
1186
        }
1187

1188
        r = serialize_fd(f, fds, "exec-parameters-stdin-fd", p->stdin_fd);
2,422✔
1189
        if (r < 0)
2,422✔
1190
                return r;
1191

1192
        r = serialize_fd(f, fds, "exec-parameters-stdout-fd", p->stdout_fd);
2,422✔
1193
        if (r < 0)
2,422✔
1194
                return r;
1195

1196
        r = serialize_fd(f, fds, "exec-parameters-stderr-fd", p->stderr_fd);
2,422✔
1197
        if (r < 0)
2,422✔
1198
                return r;
1199

1200
        r = serialize_fd(f, fds, "exec-parameters-root-directory-fd", p->root_directory_fd);
2,422✔
1201
        if (r < 0)
2,422✔
1202
                return r;
1203

1204
        r = serialize_fd(f, fds, "exec-parameters-exec-fd", p->exec_fd);
2,422✔
1205
        if (r < 0)
2,422✔
1206
                return r;
1207

1208
        r = serialize_fd(f, fds, "exec-parameters-handoff-timestamp-fd", p->handoff_timestamp_fd);
2,422✔
1209
        if (r < 0)
2,422✔
1210
                return r;
1211

1212
        r = serialize_fd(f, fds, "exec-parameters-pidref-transport-fd", p->pidref_transport_fd);
2,422✔
1213
        if (r < 0)
2,422✔
1214
                return r;
1215

1216
        if (c && exec_context_restrict_filesystems_set(c)) {
2,422✔
1217
                r = serialize_fd(f, fds, "exec-parameters-bpf-outer-map-fd", p->bpf_restrict_fs_map_fd);
×
1218
                if (r < 0)
×
1219
                        return r;
1220
        }
1221

1222
        r = serialize_item(f, "exec-parameters-notify-socket", p->notify_socket);
2,422✔
1223
        if (r < 0)
2,422✔
1224
                return r;
1225

1226
        LIST_FOREACH(open_files, file, p->open_files) {
2,422✔
1227
                _cleanup_free_ char *ofs = NULL;
×
1228

1229
                r = open_file_to_string(file, &ofs);
×
1230
                if (r < 0)
×
1231
                        return r;
1232

1233
                r = serialize_item(f, "exec-parameters-open-file", ofs);
×
1234
                if (r < 0)
×
1235
                        return r;
1236
        }
1237

1238
        r = serialize_item(f, "exec-parameters-fallback-smack-process-label", p->fallback_smack_process_label);
2,422✔
1239
        if (r < 0)
2,422✔
1240
                return r;
1241

1242
        r = serialize_fd(f, fds, "exec-parameters-user-lookup-fd", p->user_lookup_fd);
2,422✔
1243
        if (r < 0)
2,422✔
1244
                return r;
1245

1246
        r = serialize_strv(f, "exec-parameters-files-env", p->files_env);
2,422✔
1247
        if (r < 0)
2,422✔
1248
                return r;
1249

1250
        r = serialize_item(f, "exec-parameters-unit-id", p->unit_id);
2,422✔
1251
        if (r < 0)
2,422✔
1252
                return r;
1253

1254
        r = serialize_item(f, "exec-parameters-invocation-id-string", p->invocation_id_string);
2,422✔
1255
        if (r < 0)
2,422✔
1256
                return r;
1257

1258
        r = serialize_bool_elide(f, "exec-parameters-debug-invocation", p->debug_invocation);
2,422✔
1259
        if (r < 0)
2,422✔
1260
                return r;
1261

1262
        fputc('\n', f); /* End marker */
2,422✔
1263

1264
        return 0;
2,422✔
1265
}
1266

1267
static int exec_parameters_deserialize(ExecParameters *p, FILE *f, FDSet *fds) {
10,019✔
1268
        int r;
10,019✔
1269

1270
        assert(p);
10,019✔
1271
        assert(f);
10,019✔
1272
        assert(fds);
10,019✔
1273

1274
        unsigned nr_open = MAX(read_nr_open(), NR_OPEN_MINIMUM);
10,019✔
1275

1276
        for (;;) {
213,912✔
1277
                _cleanup_free_ char *l = NULL;
203,893✔
1278
                const char *val;
213,912✔
1279

1280
                r = deserialize_read_line(f, &l);
213,912✔
1281
                if (r < 0)
213,912✔
1282
                        return r;
1283
                if (r == 0) /* eof or end marker */
213,912✔
1284
                        break;
1285

1286
                if ((val = startswith(l, "exec-parameters-runtime-scope="))) {
203,893✔
1287
                        p->runtime_scope = runtime_scope_from_string(val);
10,019✔
1288
                        if (p->runtime_scope < 0)
10,019✔
1289
                                return p->runtime_scope;
1290
                } else if ((val = startswith(l, "exec-parameters-environment="))) {
193,874✔
1291
                        r = deserialize_strv(val, &p->environment);
42,658✔
1292
                        if (r < 0)
42,658✔
1293
                                return r;
1294
                } else if ((val = startswith(l, "exec-parameters-n-socket-fds="))) {
151,216✔
1295
                        if (p->fds)
1,744✔
1296
                                return -EINVAL; /* Already received */
1297

1298
                        r = safe_atozu(val, &p->n_socket_fds);
1,744✔
1299
                        if (r < 0)
1,744✔
1300
                                return r;
1301

1302
                        if (p->n_socket_fds > nr_open)
1,744✔
1303
                                return -EINVAL; /* too many, someone is playing games with us */
1304
                } else if ((val = startswith(l, "exec-parameters-n-stashed-fds="))) {
149,472✔
1305
                        if (p->fds)
110✔
1306
                                return -EINVAL; /* Already received */
1307

1308
                        r = safe_atozu(val, &p->n_stashed_fds);
110✔
1309
                        if (r < 0)
110✔
1310
                                return r;
1311

1312
                        if (p->n_stashed_fds > nr_open)
110✔
1313
                                return -EINVAL; /* too many, someone is playing games with us */
1314
                } else if ((val = startswith(l, "exec-parameters-fds="))) {
149,362✔
1315
                        if (p->n_socket_fds + p->n_stashed_fds == 0)
1,749✔
1316
                                return log_warning_errno(
×
1317
                                                SYNTHETIC_ERRNO(EINVAL),
1318
                                                "Got exec-parameters-fds= without "
1319
                                                "prior exec-parameters-n-socket-fds= or exec-parameters-n-stashed-fds=");
1320
                        if (p->n_socket_fds + p->n_stashed_fds > nr_open)
1,749✔
1321
                                return -EINVAL; /* too many, someone is playing games with us */
1322

1323
                        if (p->fds)
1,749✔
1324
                                return -EINVAL; /* duplicated */
1325

1326
                        p->fds = new(int, p->n_socket_fds + p->n_stashed_fds);
1,749✔
1327
                        if (!p->fds)
1,749✔
1328
                                return log_oom_debug();
×
1329

1330
                        /* Ensure we don't leave any FD uninitialized on error, it makes the fuzzer sad */
1331
                        FOREACH_ARRAY(i, p->fds, p->n_socket_fds + p->n_stashed_fds)
5,428✔
1332
                                *i = -EBADF;
3,679✔
1333

1334
                        r = deserialize_fd_many(fds, val, p->n_socket_fds + p->n_stashed_fds, p->fds);
1,749✔
1335
                        if (r < 0)
1,749✔
1336
                                continue;
×
1337

1338
                } else if ((val = startswith(l, "exec-parameters-fd-names="))) {
147,613✔
1339
                        r = deserialize_strv(val, &p->fd_names);
3,679✔
1340
                        if (r < 0)
3,679✔
1341
                                return r;
1342
                } else if ((val = startswith(l, "exec-parameters-flags="))) {
143,934✔
1343
                        unsigned flags;
10,019✔
1344

1345
                        r = safe_atou(val, &flags);
10,019✔
1346
                        if (r < 0)
10,019✔
1347
                                return r;
×
1348
                        p->flags = flags;
10,019✔
1349
                } else if ((val = startswith(l, "exec-parameters-selinux-context-net="))) {
133,915✔
1350
                        r = parse_boolean(val);
×
1351
                        if (r < 0)
×
1352
                                return r;
1353

1354
                        p->selinux_context_net = r;
×
1355
                } else if ((val = startswith(l, "exec-parameters-cgroup-path="))) {
133,915✔
1356
                        r = free_and_strdup(&p->cgroup_path, val);
10,019✔
1357
                        if (r < 0)
10,019✔
1358
                                return r;
1359
                } else if ((val = startswith(l, "exec-parameters-cgroup-id="))) {
123,896✔
1360
                        r = safe_atou64(val, &p->cgroup_id);
10,019✔
1361
                        if (r < 0)
10,019✔
1362
                                return r;
1363
                } else if ((val = startswith(l, "exec-parameters-prefix-directories-"))) {
113,877✔
1364
                        _cleanup_free_ char *type = NULL, *prefix = NULL;
50,095✔
1365
                        ExecDirectoryType dt;
50,095✔
1366

1367
                        r = extract_many_words(&val, "= ", 0, &type, &prefix);
50,095✔
1368
                        if (r < 0)
50,095✔
1369
                                return r;
1370
                        if (r == 0)
50,095✔
1371
                                return -EINVAL;
1372

1373
                        dt = exec_directory_type_from_string(type);
50,095✔
1374
                        if (dt < 0)
50,095✔
1375
                                return -EINVAL;
1376

1377
                        if (!p->prefix) {
50,095✔
1378
                                p->prefix = new0(char*, _EXEC_DIRECTORY_TYPE_MAX+1);
10,019✔
1379
                                if (!p->prefix)
10,019✔
1380
                                        return log_oom_debug();
×
1381
                        }
1382

1383
                        if (isempty(prefix))
50,095✔
1384
                                p->prefix[dt] = mfree(p->prefix[dt]);
×
1385
                        else
1386
                                free_and_replace(p->prefix[dt], prefix);
50,095✔
1387
                } else if ((val = startswith(l, "exec-parameters-received-credentials-directory="))) {
63,782✔
1388
                        r = free_and_strdup(&p->received_credentials_directory, val);
9,328✔
1389
                        if (r < 0)
9,328✔
1390
                                return r;
1391
                } else if ((val = startswith(l, "exec-parameters-received-encrypted-credentials-directory="))) {
54,454✔
UNCOV
1392
                        r = free_and_strdup(&p->received_encrypted_credentials_directory, val);
×
UNCOV
1393
                        if (r < 0)
×
1394
                                return r;
1395
                } else if ((val = startswith(l, "exec-parameters-confirm-spawn="))) {
54,454✔
1396
                        r = free_and_strdup(&p->confirm_spawn, val);
×
1397
                        if (r < 0)
×
1398
                                return r;
1399
                } else if ((val = startswith(l, "exec-parameters-shall-confirm-spawn="))) {
54,454✔
1400
                        r = parse_boolean(val);
×
1401
                        if (r < 0)
×
1402
                                return r;
1403

1404
                        p->shall_confirm_spawn = r;
×
1405
                } else if ((val = startswith(l, "exec-parameters-watchdog-usec="))) {
54,454✔
1406
                        r = deserialize_usec(val, &p->watchdog_usec);
1,481✔
1407
                        if (r < 0)
1,481✔
1408
                                return r;
1409
                } else if ((val = startswith(l, "exec-parameters-idle-pipe="))) {
52,973✔
1410
                        if (p->idle_pipe)
86✔
1411
                                return -EINVAL; /* duplicated */
1412

1413
                        p->idle_pipe = new(int, 4);
86✔
1414
                        if (!p->idle_pipe)
86✔
1415
                                return log_oom_debug();
×
1416

1417
                        p->idle_pipe[0] = p->idle_pipe[1] = p->idle_pipe[2] = p->idle_pipe[3] = -EBADF;
86✔
1418

1419
                        r = deserialize_fd_many(fds, val, 4, p->idle_pipe);
86✔
1420
                        if (r < 0)
86✔
1421
                                continue;
×
1422

1423
                } else if ((val = startswith(l, "exec-parameters-stdin-fd="))) {
52,887✔
1424
                        int fd;
544✔
1425

1426
                        fd = deserialize_fd(fds, val);
544✔
1427
                        if (fd < 0)
544✔
1428
                                continue;
×
1429

1430
                        close_and_replace(p->stdin_fd, fd);
544✔
1431

1432
                } else if ((val = startswith(l, "exec-parameters-stdout-fd="))) {
52,343✔
1433
                        int fd;
544✔
1434

1435
                        fd = deserialize_fd(fds, val);
544✔
1436
                        if (fd < 0)
544✔
1437
                                continue;
×
1438

1439
                        close_and_replace(p->stdout_fd, fd);
544✔
1440

1441
                } else if ((val = startswith(l, "exec-parameters-stderr-fd="))) {
51,799✔
1442
                        int fd;
544✔
1443

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

1448
                        close_and_replace(p->stderr_fd, fd);
544✔
1449

1450
                } else if ((val = startswith(l, "exec-parameters-root-directory-fd="))) {
51,255✔
1451
                        int fd;
2✔
1452

1453
                        fd = deserialize_fd(fds, val);
2✔
1454
                        if (fd < 0)
2✔
1455
                                continue;
×
1456

1457
                        close_and_replace(p->root_directory_fd, fd);
2✔
1458

1459
                } else if ((val = startswith(l, "exec-parameters-exec-fd="))) {
51,253✔
1460
                        int fd;
428✔
1461

1462
                        fd = deserialize_fd(fds, val);
428✔
1463
                        if (fd < 0)
428✔
1464
                                continue;
×
1465

1466
                        close_and_replace(p->exec_fd, fd);
428✔
1467
                } else if ((val = startswith(l, "exec-parameters-handoff-timestamp-fd="))) {
50,825✔
1468
                        int fd;
10,019✔
1469

1470
                        fd = deserialize_fd(fds, val);
10,019✔
1471
                        if (fd < 0)
10,019✔
1472
                                continue;
×
1473

1474
                        close_and_replace(p->handoff_timestamp_fd, fd);
10,019✔
1475
                } else if ((val = startswith(l, "exec-parameters-pidref-transport-fd="))) {
40,806✔
1476
                        int fd;
8,858✔
1477

1478
                        fd = deserialize_fd(fds, val);
8,858✔
1479
                        if (fd < 0)
8,858✔
1480
                                continue;
×
1481

1482
                        close_and_replace(p->pidref_transport_fd, fd);
8,858✔
1483
                } else if ((val = startswith(l, "exec-parameters-bpf-outer-map-fd="))) {
31,948✔
1484
                        int fd;
×
1485

1486
                        fd = deserialize_fd(fds, val);
×
1487
                        if (fd < 0)
×
1488
                                continue;
×
1489

1490
                        close_and_replace(p->bpf_restrict_fs_map_fd, fd);
×
1491
                } else if ((val = startswith(l, "exec-parameters-notify-socket="))) {
31,948✔
1492
                        r = free_and_strdup(&p->notify_socket, val);
1,882✔
1493
                        if (r < 0)
1,882✔
1494
                                return r;
1495
                } else if ((val = startswith(l, "exec-parameters-open-file="))) {
30,066✔
1496
                        OpenFile *of;
5✔
1497

1498
                        r = open_file_parse(val, &of);
5✔
1499
                        if (r < 0)
5✔
1500
                                return r;
×
1501

1502
                        LIST_APPEND(open_files, p->open_files, of);
5✔
1503
                } else if ((val = startswith(l, "exec-parameters-fallback-smack-process-label="))) {
30,061✔
1504
                        r = free_and_strdup(&p->fallback_smack_process_label, val);
×
1505
                        if (r < 0)
×
1506
                                return r;
1507
                } else if ((val = startswith(l, "exec-parameters-user-lookup-fd="))) {
30,061✔
1508
                        int fd;
10,019✔
1509

1510
                        fd = deserialize_fd(fds, val);
10,019✔
1511
                        if (fd < 0)
10,019✔
1512
                                continue;
×
1513

1514
                        close_and_replace(p->user_lookup_fd, fd);
10,019✔
1515
                } else if ((val = startswith(l, "exec-parameters-files-env="))) {
20,042✔
1516
                        r = deserialize_strv(val, &p->files_env);
2✔
1517
                        if (r < 0)
2✔
1518
                                return r;
1519
                } else if ((val = startswith(l, "exec-parameters-unit-id="))) {
20,040✔
1520
                        r = free_and_strdup(&p->unit_id, val);
10,019✔
1521
                        if (r < 0)
10,019✔
1522
                                return r;
1523
                } else if ((val = startswith(l, "exec-parameters-invocation-id-string="))) {
10,021✔
1524
                        if (strlen(val) > SD_ID128_STRING_MAX - 1)
10,019✔
1525
                                return -EINVAL;
1526

1527
                        r = sd_id128_from_string(val, &p->invocation_id);
10,019✔
1528
                        if (r < 0)
10,019✔
1529
                                return r;
1530

1531
                        sd_id128_to_string(p->invocation_id, p->invocation_id_string);
10,019✔
1532
                } else if ((val = startswith(l, "exec-parameters-debug-invocation="))) {
2✔
1533
                        r = parse_boolean(val);
2✔
1534
                        if (r < 0)
2✔
1535
                                return r;
1536

1537
                        p->debug_invocation = r;
2✔
1538
                } else
1539
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
1540
        }
1541

1542
        /* Bail out if we got exec-parameters-n-{socket/stashed}-fds= but no corresponding
1543
         * exec-parameters-fds= */
1544
        if (p->n_socket_fds + p->n_stashed_fds > 0 && !p->fds)
10,019✔
1545
                return -EINVAL;
×
1546

1547
        return 0;
1548
}
1549

1550
static int exec_context_serialize(const ExecContext *c, FILE *f) {
2,422✔
1551
        int r;
2,422✔
1552

1553
        assert(f);
2,422✔
1554

1555
        if (!c)
2,422✔
1556
                return 0;
2,422✔
1557

1558
        r = serialize_strv(f, "exec-context-environment", c->environment);
2,422✔
1559
        if (r < 0)
2,422✔
1560
                return r;
1561

1562
        r = serialize_strv(f, "exec-context-environment-files", c->environment_files);
2,422✔
1563
        if (r < 0)
2,422✔
1564
                return r;
1565

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

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

1574
        r = serialize_item_escaped(f, "exec-context-working-directory", c->working_directory);
2,422✔
1575
        if (r < 0)
2,422✔
1576
                return r;
1577

1578
        r = serialize_bool_elide(f, "exec-context-working-directory-missing-ok", c->working_directory_missing_ok);
2,422✔
1579
        if (r < 0)
2,422✔
1580
                return r;
1581

1582
        r = serialize_bool_elide(f, "exec-context-working-directory-home", c->working_directory_home);
2,422✔
1583
        if (r < 0)
2,422✔
1584
                return r;
1585

1586
        r = serialize_item_escaped(f, "exec-context-root-directory", c->root_directory);
2,422✔
1587
        if (r < 0)
2,422✔
1588
                return r;
1589

1590
        r = serialize_item_escaped(f, "exec-context-root-image", c->root_image);
2,422✔
1591
        if (r < 0)
2,422✔
1592
                return r;
1593

1594
        if (c->root_image_options) {
2,422✔
1595
                _cleanup_free_ char *options = NULL;
×
1596

1597
                LIST_FOREACH(mount_options, o, c->root_image_options) {
×
1598
                        if (isempty(o->options))
×
1599
                                continue;
×
1600

1601
                        _cleanup_free_ char *escaped = NULL;
×
1602
                        escaped = shell_escape(o->options, ":");
×
1603
                        if (!escaped)
×
1604
                                return log_oom_debug();
×
1605

1606
                        if (!strextend(&options,
×
1607
                                        " ",
1608
                                        partition_designator_to_string(o->partition_designator),
1609
                                               ":",
1610
                                               escaped))
1611
                                        return log_oom_debug();
×
1612
                }
1613

1614
                r = serialize_item(f, "exec-context-root-image-options", options);
×
1615
                if (r < 0)
×
1616
                        return r;
1617
        }
1618

1619
        r = serialize_item(f, "exec-context-root-verity", c->root_verity);
2,422✔
1620
        if (r < 0)
2,422✔
1621
                return r;
1622

1623
        r = serialize_item(f, "exec-context-root-hash-path", c->root_hash_path);
2,422✔
1624
        if (r < 0)
2,422✔
1625
                return r;
1626

1627
        r = serialize_item(f, "exec-context-root-hash-sig-path", c->root_hash_sig_path);
2,422✔
1628
        if (r < 0)
2,422✔
1629
                return r;
1630

1631
        r = serialize_item_hexmem(f, "exec-context-root-hash", c->root_hash.iov_base, c->root_hash.iov_len);
2,422✔
1632
        if (r < 0)
2,422✔
1633
                return r;
1634

1635
        r = serialize_item_base64mem(f, "exec-context-root-hash-sig", c->root_hash_sig.iov_base, c->root_hash_sig.iov_len);
2,422✔
1636
        if (r < 0)
2,422✔
1637
                return r;
1638

1639
        r = serialize_bool_elide(f, "exec-context-root-ephemeral", c->root_ephemeral);
2,422✔
1640
        if (r < 0)
2,422✔
1641
                return r;
1642

1643
        r = serialize_item_format(f, "exec-context-umask", "%04o", c->umask);
2,422✔
1644
        if (r < 0)
2,422✔
1645
                return r;
1646

1647
        r = serialize_bool_elide(f, "exec-context-non-blocking", c->non_blocking);
2,422✔
1648
        if (r < 0)
2,422✔
1649
                return r;
1650

1651
        r = serialize_item_tristate(f, "exec-context-private-mounts", c->private_mounts);
2,422✔
1652
        if (r < 0)
28✔
1653
                return r;
1654

1655
        r = serialize_item_tristate(f, "exec-context-mount-api-vfs", c->mount_apivfs);
2,422✔
1656
        if (r < 0)
2✔
1657
                return r;
1658

1659
        r = serialize_item_tristate(f, "exec-context-bind-log-sockets", c->bind_log_sockets);
2,422✔
1660
        if (r < 0)
×
1661
                return r;
1662

1663
        r = serialize_item_tristate(f, "exec-context-memory-ksm", c->memory_ksm);
2,422✔
1664
        if (r < 0)
×
1665
                return r;
1666

1667
        r = serialize_item(f, "exec-context-private-tmp", private_tmp_to_string(c->private_tmp));
2,422✔
1668
        if (r < 0)
2,422✔
1669
                return r;
1670

1671
        /* This must be set in unit_patch_contexts() before executing a command. */
1672
        assert(c->private_var_tmp >= 0 && c->private_var_tmp < _PRIVATE_TMP_MAX);
2,422✔
1673
        r = serialize_item(f, "exec-context-private-var-tmp", private_tmp_to_string(c->private_var_tmp));
2,422✔
1674
        if (r < 0)
2,422✔
1675
                return r;
1676

1677
        r = serialize_bool_elide(f, "exec-context-private-devices", c->private_devices);
2,422✔
1678
        if (r < 0)
2,422✔
1679
                return r;
1680

1681
        r = serialize_bool_elide(f, "exec-context-protect-kernel-tunables", c->protect_kernel_tunables);
2,422✔
1682
        if (r < 0)
2,422✔
1683
                return r;
1684

1685
        r = serialize_bool_elide(f, "exec-context-protect-kernel-modules", c->protect_kernel_modules);
2,422✔
1686
        if (r < 0)
2,422✔
1687
                return r;
1688

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

1693
        r = serialize_bool_elide(f, "exec-context-protect-clock", c->protect_clock);
2,422✔
1694
        if (r < 0)
2,422✔
1695
                return r;
1696

1697
        r = serialize_item(f, "exec-context-protect-control-groups", protect_control_groups_to_string(c->protect_control_groups));
2,422✔
1698
        if (r < 0)
2,422✔
1699
                return r;
1700

1701
        r = serialize_bool_elide(f, "exec-context-private-network", c->private_network);
2,422✔
1702
        if (r < 0)
2,422✔
1703
                return r;
1704

1705
        r = serialize_item(f, "exec-context-private-users", private_users_to_string(c->private_users));
2,422✔
1706
        if (r < 0)
2,422✔
1707
                return r;
1708

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

1713
        r = serialize_item(f, "exec-context-private-pids", private_pids_to_string(c->private_pids));
2,422✔
1714
        if (r < 0)
2,422✔
1715
                return r;
1716

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

1721
        r = serialize_item(f, "exec-context-protect-home", protect_home_to_string(c->protect_home));
2,422✔
1722
        if (r < 0)
2,422✔
1723
                return r;
1724

1725
        r = serialize_item(f, "exec-context-protect-system", protect_system_to_string(c->protect_system));
2,422✔
1726
        if (r < 0)
2,422✔
1727
                return r;
1728

1729
        r = serialize_bool_elide(f, "exec-context-same-pgrp", c->same_pgrp);
2,422✔
1730
        if (r < 0)
2,422✔
1731
                return r;
1732

1733
        r = serialize_bool(f, "exec-context-ignore-sigpipe", c->ignore_sigpipe);
2,422✔
1734
        if (r < 0)
2,422✔
1735
                return r;
1736

1737
        r = serialize_bool_elide(f, "exec-context-memory-deny-write-execute", c->memory_deny_write_execute);
2,422✔
1738
        if (r < 0)
2,422✔
1739
                return r;
1740

1741
        r = serialize_bool_elide(f, "exec-context-restrict-realtime", c->restrict_realtime);
2,422✔
1742
        if (r < 0)
2,422✔
1743
                return r;
1744

1745
        r = serialize_bool_elide(f, "exec-context-restrict-suid-sgid", c->restrict_suid_sgid);
2,422✔
1746
        if (r < 0)
2,422✔
1747
                return r;
1748

1749
        r = serialize_item(f, "exec-context-keyring-mode", exec_keyring_mode_to_string(c->keyring_mode));
2,422✔
1750
        if (r < 0)
2,422✔
1751
                return r;
1752

1753
        r = serialize_item(f, "exec-context-protect-hostname", protect_hostname_to_string(c->protect_hostname));
2,422✔
1754
        if (r < 0)
2,422✔
1755
                return r;
1756

1757
        r = serialize_item(f, "exec-context-private-hostname", c->private_hostname);
2,422✔
1758
        if (r < 0)
2,422✔
1759
                return r;
1760

1761
        r = serialize_item(f, "exec-context-protect-proc", protect_proc_to_string(c->protect_proc));
2,422✔
1762
        if (r < 0)
2,422✔
1763
                return r;
1764

1765
        r = serialize_item(f, "exec-context-proc-subset", proc_subset_to_string(c->proc_subset));
2,422✔
1766
        if (r < 0)
2,422✔
1767
                return r;
1768

1769
        r = serialize_item(f, "exec-context-private-bpf", private_bpf_to_string(c->private_bpf));
2,422✔
1770
        if (r < 0)
2,422✔
1771
                return r;
1772

1773
        if (c->bpf_delegate_commands != 0) {
2,422✔
1774
                r = serialize_item_format(f, "exec-context-bpf-delegate-commands", "0x%"PRIx64, c->bpf_delegate_commands);
×
1775
                if (r < 0)
×
1776
                        return r;
1777
        }
1778

1779
        if (c->bpf_delegate_maps != 0) {
2,422✔
1780
                r = serialize_item_format(f, "exec-context-bpf-delegate-maps", "0x%"PRIx64, c->bpf_delegate_maps);
×
1781
                if (r < 0)
×
1782
                        return r;
1783
        }
1784

1785
        if (c->bpf_delegate_programs != 0) {
2,422✔
1786
                r = serialize_item_format(f, "exec-context-bpf-delegate-programs", "0x%"PRIx64, c->bpf_delegate_programs);
×
1787
                if (r < 0)
×
1788
                        return r;
1789
        }
1790

1791
        if (c->bpf_delegate_attachments != 0) {
2,422✔
1792
                r = serialize_item_format(f, "exec-context-bpf-delegate-attachments", "0x%"PRIx64, c->bpf_delegate_attachments);
×
1793
                if (r < 0)
×
1794
                        return r;
1795
        }
1796

1797
        r = serialize_item(f, "exec-context-runtime-directory-preserve-mode", exec_preserve_mode_to_string(c->runtime_directory_preserve_mode));
2,422✔
1798
        if (r < 0)
2,422✔
1799
                return r;
1800

1801
        for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
14,532✔
1802
                _cleanup_free_ char *key = NULL, *value = NULL;
12,110✔
1803

1804
                key = strjoin("exec-context-directories-", exec_directory_type_to_string(dt));
12,110✔
1805
                if (!key)
12,110✔
1806
                        return log_oom_debug();
×
1807

1808
                if (asprintf(&value, "%04o", c->directories[dt].mode) < 0)
12,110✔
1809
                        return log_oom_debug();
×
1810

1811
                FOREACH_ARRAY(i, c->directories[dt].items, c->directories[dt].n_items) {
12,535✔
1812
                        _cleanup_free_ char *path_escaped = NULL;
425✔
1813

1814
                        path_escaped = shell_escape(i->path, ":" WHITESPACE);
425✔
1815
                        if (!path_escaped)
425✔
1816
                                return log_oom_debug();
×
1817

1818
                        if (!strextend(&value, " ", path_escaped))
425✔
1819
                                return log_oom_debug();
×
1820

1821
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_ONLY_CREATE))))
845✔
1822
                                return log_oom_debug();
×
1823

1824
                        if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_READ_ONLY))))
848✔
1825
                                return log_oom_debug();
×
1826

1827
                        STRV_FOREACH(d, i->symlinks) {
431✔
1828
                                _cleanup_free_ char *link_escaped = NULL;
6✔
1829

1830
                                link_escaped = shell_escape(*d, ":" WHITESPACE);
6✔
1831
                                if (!link_escaped)
6✔
1832
                                        return log_oom_debug();
×
1833

1834
                                if (!strextend(&value, ":", link_escaped))
6✔
1835
                                        return log_oom_debug();
×
1836
                        }
1837
                }
1838

1839
                r = serialize_item(f, key, value);
12,110✔
1840
                if (r < 0)
12,110✔
1841
                        return r;
1842

1843
                if (c->directories[dt].exec_quota.quota_enforce) {
12,110✔
1844
                        _cleanup_free_ char *key_quota = NULL;
×
1845
                        key_quota = strjoin("exec-context-quota-directories-", exec_directory_type_to_string(dt));
×
1846
                        if (!key_quota)
×
1847
                                return log_oom_debug();
×
1848

1849
                        r = serialize_item_format(f, key_quota, "%" PRIu64 " %" PRIu32, c->directories[dt].exec_quota.quota_absolute,
×
1850
                                                                                        c->directories[dt].exec_quota.quota_scale);
×
1851
                        if (r < 0)
×
1852
                                return r;
1853

1854
                } else if (c->directories[dt].exec_quota.quota_accounting) {
12,110✔
1855
                        _cleanup_free_ char *key_quota = NULL;
×
1856
                        key_quota = strjoin("exec-context-quota-accounting-directories-", exec_directory_type_to_string(dt));
×
1857
                        if (!key_quota)
×
1858
                                return log_oom_debug();
×
1859

1860
                        r = serialize_bool(f, key_quota, c->directories[dt].exec_quota.quota_accounting);
×
1861
                        if (r < 0)
×
1862
                                return r;
1863
                }
1864
        }
1865

1866
        r = serialize_usec(f, "exec-context-timeout-clean-usec", c->timeout_clean_usec);
2,422✔
1867
        if (r < 0)
2,422✔
1868
                return r;
1869

1870
        if (c->nice_set) {
2,422✔
1871
                r = serialize_item_format(f, "exec-context-nice", "%i", c->nice);
3✔
1872
                if (r < 0)
3✔
1873
                        return r;
1874
        }
1875

1876
        if (c->oom_score_adjust_set) {
2,422✔
1877
                r = serialize_item_format(f, "exec-context-oom-score-adjust", "%i", c->oom_score_adjust);
597✔
1878
                if (r < 0)
597✔
1879
                        return r;
1880
        }
1881

1882
        if (c->coredump_filter_set) {
2,422✔
1883
                r = serialize_item_format(f, "exec-context-coredump-filter", "%"PRIx64, c->coredump_filter);
×
1884
                if (r < 0)
×
1885
                        return r;
1886
        }
1887

1888
        for (unsigned i = 0; i < RLIM_NLIMITS; i++) {
41,174✔
1889
                _cleanup_free_ char *key = NULL, *limit = NULL;
4,838✔
1890

1891
                if (!c->rlimit[i])
38,752✔
1892
                        continue;
33,914✔
1893

1894
                key = strjoin("exec-context-limit-", rlimit_to_string(i));
4,838✔
1895
                if (!key)
4,838✔
1896
                        return log_oom_debug();
×
1897

1898
                r = rlimit_format(c->rlimit[i], &limit);
4,838✔
1899
                if (r < 0)
4,838✔
1900
                        return r;
1901

1902
                r = serialize_item(f, key, limit);
4,838✔
1903
                if (r < 0)
4,838✔
1904
                        return r;
1905
        }
1906

1907
        if (c->ioprio_is_set) {
2,422✔
1908
                r = serialize_item_format(f, "exec-context-ioprio", "%d", c->ioprio);
5✔
1909
                if (r < 0)
5✔
1910
                        return r;
1911
        }
1912

1913
        if (c->cpu_sched_set) {
2,422✔
1914
                _cleanup_free_ char *policy_str = NULL;
×
1915

1916
                r = sched_policy_to_string_alloc(c->cpu_sched_policy, &policy_str);
×
1917
                if (r < 0)
×
1918
                        return r;
1919

1920
                r = serialize_item(f, "exec-context-cpu-scheduling-policy", policy_str);
×
1921
                if (r < 0)
×
1922
                        return r;
1923

1924
                r = serialize_item_format(f, "exec-context-cpu-scheduling-priority", "%i", c->cpu_sched_priority);
×
1925
                if (r < 0)
×
1926
                        return r;
1927

1928
                r = serialize_bool_elide(f, "exec-context-cpu-scheduling-reset-on-fork", c->cpu_sched_reset_on_fork);
×
1929
                if (r < 0)
×
1930
                        return r;
1931
        }
1932

1933
        if (c->cpu_set.set) {
2,422✔
1934
                _cleanup_free_ char *affinity = NULL;
×
1935

1936
                affinity = cpu_set_to_range_string(&c->cpu_set);
×
1937
                if (!affinity)
×
1938
                        return log_oom_debug();
×
1939

1940
                r = serialize_item(f, "exec-context-cpu-affinity", affinity);
×
1941
                if (r < 0)
×
1942
                        return r;
1943
        }
1944

1945
        if (mpol_is_valid(numa_policy_get_type(&c->numa_policy))) {
2,422✔
1946
                _cleanup_free_ char *nodes = NULL;
×
1947

1948
                nodes = cpu_set_to_range_string(&c->numa_policy.nodes);
×
1949
                if (!nodes)
×
1950
                        return log_oom_debug();
×
1951

1952
                if (nodes) {
×
1953
                        r = serialize_item(f, "exec-context-numa-mask", nodes);
×
1954
                        if (r < 0)
×
1955
                                return r;
1956
                }
1957

1958
                r = serialize_item_format(f, "exec-context-numa-policy", "%d", c->numa_policy.type);
×
1959
                if (r < 0)
×
1960
                        return r;
1961
        }
1962

1963
        r = serialize_bool_elide(f, "exec-context-cpu-affinity-from-numa", c->cpu_affinity_from_numa);
2,422✔
1964
        if (r < 0)
2,422✔
1965
                return r;
1966

1967
        if (c->timer_slack_nsec != NSEC_INFINITY) {
2,422✔
1968
                r = serialize_item_format(f, "exec-context-timer-slack-nsec", NSEC_FMT, c->timer_slack_nsec);
×
1969
                if (r < 0)
×
1970
                        return r;
1971
        }
1972

1973
        r = serialize_bool_elide(f, "exec-context-root-directory-as-fd", c->root_directory_as_fd);
2,422✔
1974
        if (r < 0)
2,422✔
1975
                return r;
1976

1977
        r = serialize_item(f, "exec-context-std-input", exec_input_to_string(c->std_input));
2,422✔
1978
        if (r < 0)
2,422✔
1979
                return r;
1980

1981
        r = serialize_item(f, "exec-context-std-output", exec_output_to_string(c->std_output));
2,422✔
1982
        if (r < 0)
2,422✔
1983
                return r;
1984

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

1989
        r = serialize_bool_elide(f, "exec-context-stdio-as-fds", c->stdio_as_fds);
2,422✔
1990
        if (r < 0)
2,422✔
1991
                return r;
1992

1993
        switch (c->std_input) {
2,422✔
1994

1995
        case EXEC_INPUT_NAMED_FD:
×
1996
                r = serialize_item(f, "exec-context-std-input-fd-name", c->stdio_fdname[STDIN_FILENO]);
×
1997
                break;
1998

1999
        case EXEC_INPUT_FILE:
×
2000
                r = serialize_item_escaped(f, "exec-context-std-input-file", c->stdio_file[STDIN_FILENO]);
×
2001
                break;
2002

2003
        case EXEC_INPUT_DATA:
×
2004
                r = serialize_item_base64mem(f, "exec-context-std-input-data", c->stdin_data, c->stdin_data_size);
×
2005
                break;
2006

2007
        default:
2008
                r = 0;
2009
        }
2010
        if (r < 0)
×
2011
                return r;
2012

2013
        switch (c->std_output) {
2,422✔
2014

2015
        case EXEC_OUTPUT_NAMED_FD:
×
2016
                r = serialize_item(f, "exec-context-std-output-fd-name", c->stdio_fdname[STDOUT_FILENO]);
×
2017
                break;
2018

2019
        case EXEC_OUTPUT_FILE:
2✔
2020
        case EXEC_OUTPUT_FILE_APPEND:
2021
        case EXEC_OUTPUT_FILE_TRUNCATE:
2022
                r = serialize_item_escaped(f, "exec-context-std-output-file", c->stdio_file[STDOUT_FILENO]);
2✔
2023
                break;
2024

2025
        default:
2026
                r = 0;
2027
        }
2028
        if (r < 0)
2✔
2029
                return r;
2030

2031

2032
        switch (c->std_error) {
2,422✔
2033

2034
        case EXEC_OUTPUT_NAMED_FD:
×
2035
                r = serialize_item(f, "exec-context-std-error-fd-name", c->stdio_fdname[STDERR_FILENO]);
×
2036
                break;
2037

2038
        case EXEC_OUTPUT_FILE:
×
2039
        case EXEC_OUTPUT_FILE_APPEND:
2040
        case EXEC_OUTPUT_FILE_TRUNCATE:
2041
                r = serialize_item_escaped(f, "exec-context-std-error-file", c->stdio_file[STDERR_FILENO]);
×
2042
                break;
2043

2044
        default:
2045
                r = 0;
2046
        }
2047
        if (r < 0)
×
2048
                return r;
2049

2050
        r = serialize_item(f, "exec-context-tty-path", c->tty_path);
2,422✔
2051
        if (r < 0)
2,422✔
2052
                return r;
2053

2054
        r = serialize_bool_elide(f, "exec-context-tty-reset", c->tty_reset);
2,422✔
2055
        if (r < 0)
2,422✔
2056
                return r;
2057

2058
        r = serialize_bool_elide(f, "exec-context-tty-vhangup", c->tty_vhangup);
2,422✔
2059
        if (r < 0)
2,422✔
2060
                return r;
2061

2062
        r = serialize_bool_elide(f, "exec-context-tty-vt-disallocate", c->tty_vt_disallocate);
2,422✔
2063
        if (r < 0)
2,422✔
2064
                return r;
2065

2066
        r = serialize_item_format(f, "exec-context-tty-rows", "%u", c->tty_rows);
2,422✔
2067
        if (r < 0)
2,422✔
2068
                return r;
2069

2070
        r = serialize_item_format(f, "exec-context-tty-columns", "%u", c->tty_cols);
2,422✔
2071
        if (r < 0)
2,422✔
2072
                return r;
2073

2074
        r = serialize_item_format(f, "exec-context-syslog-priority", "%i", c->syslog_priority);
2,422✔
2075
        if (r < 0)
2,422✔
2076
                return r;
2077

2078
        r = serialize_bool(f, "exec-context-syslog-level-prefix", c->syslog_level_prefix);
2,422✔
2079
        if (r < 0)
2,422✔
2080
                return r;
2081

2082
        r = serialize_item(f, "exec-context-syslog-identifier", c->syslog_identifier);
2,422✔
2083
        if (r < 0)
2,422✔
2084
                return r;
2085

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

2092
        if (c->log_ratelimit.interval > 0) {
2,422✔
2093
                r = serialize_usec(f, "exec-context-log-ratelimit-interval-usec", c->log_ratelimit.interval);
×
2094
                if (r < 0)
×
2095
                        return r;
2096
        }
2097

2098
        if (c->log_ratelimit.burst > 0) {
2,422✔
2099
                r = serialize_item_format(f, "exec-context-log-ratelimit-burst", "%u", c->log_ratelimit.burst);
×
2100
                if (r < 0)
×
2101
                        return r;
2102
        }
2103

2104
        r = serialize_string_set(f, "exec-context-log-filter-allowed-patterns", c->log_filter_allowed_patterns);
2,422✔
2105
        if (r < 0)
2,422✔
2106
                return r;
2107

2108
        r = serialize_string_set(f, "exec-context-log-filter-denied-patterns", c->log_filter_denied_patterns);
2,422✔
2109
        if (r < 0)
2,422✔
2110
                return r;
2111

2112
        FOREACH_ARRAY(field, c->log_extra_fields, c->n_log_extra_fields) {
2,663✔
2113
                r = serialize_item(f, "exec-context-log-extra-fields", field->iov_base);
241✔
2114
                if (r < 0)
241✔
2115
                        return r;
2116
        }
2117

2118
        r = serialize_item(f, "exec-context-log-namespace", c->log_namespace);
2,422✔
2119
        if (r < 0)
2,422✔
2120
                return r;
2121

2122
        if (c->secure_bits != 0) {
2,422✔
2123
                r = serialize_item_format(f, "exec-context-secure-bits", "%d", c->secure_bits);
×
2124
                if (r < 0)
×
2125
                        return r;
2126
        }
2127

2128
        if (c->capability_bounding_set != CAP_MASK_UNSET) {
2,422✔
2129
                r = serialize_item_format(f, "exec-context-capability-bounding-set", "%" PRIu64, c->capability_bounding_set);
2,422✔
2130
                if (r < 0)
2,422✔
2131
                        return r;
2132
        }
2133

2134
        if (c->capability_ambient_set != 0) {
2,422✔
2135
                r = serialize_item_format(f, "exec-context-capability-ambient-set", "%" PRIu64, c->capability_ambient_set);
69✔
2136
                if (r < 0)
69✔
2137
                        return r;
2138
        }
2139

2140
        if (c->user) {
2,422✔
2141
                r = serialize_item(f, "exec-context-user", c->user);
199✔
2142
                if (r < 0)
199✔
2143
                        return r;
2144
        }
2145

2146
        r = serialize_item(f, "exec-context-group", c->group);
2,422✔
2147
        if (r < 0)
2,422✔
2148
                return r;
2149

2150
        r = serialize_bool_elide(f, "exec-context-dynamic-user", c->dynamic_user);
2,422✔
2151
        if (r < 0)
2,422✔
2152
                return r;
2153

2154
        r = serialize_strv(f, "exec-context-supplementary-groups", c->supplementary_groups);
2,422✔
2155
        if (r < 0)
2,422✔
2156
                return r;
2157

2158
        r = serialize_item_tristate(f, "exec-context-set-login-environment", c->set_login_environment);
2,422✔
2159
        if (r < 0)
×
2160
                return r;
2161

2162
        r = serialize_item(f, "exec-context-pam-name", c->pam_name);
2,422✔
2163
        if (r < 0)
2,422✔
2164
                return r;
2165

2166
        r = serialize_strv(f, "exec-context-read-write-paths", c->read_write_paths);
2,422✔
2167
        if (r < 0)
2,422✔
2168
                return r;
2169

2170
        r = serialize_strv(f, "exec-context-read-only-paths", c->read_only_paths);
2,422✔
2171
        if (r < 0)
2,422✔
2172
                return r;
2173

2174
        r = serialize_strv(f, "exec-context-inaccessible-paths", c->inaccessible_paths);
2,422✔
2175
        if (r < 0)
2,422✔
2176
                return r;
2177

2178
        r = serialize_strv(f, "exec-context-exec-paths", c->exec_paths);
2,422✔
2179
        if (r < 0)
2,422✔
2180
                return r;
2181

2182
        r = serialize_strv(f, "exec-context-no-exec-paths", c->no_exec_paths);
2,422✔
2183
        if (r < 0)
2,422✔
2184
                return r;
2185

2186
        r = serialize_strv(f, "exec-context-exec-search-path", c->exec_search_path);
2,422✔
2187
        if (r < 0)
2,422✔
2188
                return r;
2189

2190
        r = serialize_item_format(f, "exec-context-mount-propagation-flag", "%lu", c->mount_propagation_flag);
2,422✔
2191
        if (r < 0)
2,422✔
2192
                return r;
2193

2194
        FOREACH_ARRAY(mount, c->bind_mounts, c->n_bind_mounts) {
2,437✔
2195
                _cleanup_free_ char *src_escaped = NULL, *dst_escaped = NULL;
15✔
2196

2197
                src_escaped = shell_escape(mount->source, ":" WHITESPACE);
15✔
2198
                if (!src_escaped)
15✔
2199
                        return log_oom_debug();
×
2200

2201
                dst_escaped = shell_escape(mount->destination, ":" WHITESPACE);
15✔
2202
                if (!dst_escaped)
15✔
2203
                        return log_oom_debug();
×
2204

2205
                r = serialize_item_format(f,
15✔
2206
                                          mount->read_only ? "exec-context-bind-read-only-path" : "exec-context-bind-path",
15✔
2207
                                          "%s%s:%s:%s",
2208
                                          mount->ignore_enoent ? "-" : "",
15✔
2209
                                          src_escaped,
2210
                                          dst_escaped,
2211
                                          mount->recursive ? "rbind" : "norbind");
15✔
2212
                if (r < 0)
15✔
2213
                        return r;
2214
        }
2215

2216
        FOREACH_ARRAY(tmpfs, c->temporary_filesystems, c->n_temporary_filesystems) {
2,426✔
2217
                _cleanup_free_ char *escaped = NULL;
4✔
2218

2219
                if (!isempty(tmpfs->options)) {
4✔
2220
                        escaped = shell_escape(tmpfs->options, ":");
×
2221
                        if (!escaped)
×
2222
                                return log_oom_debug();
×
2223
                }
2224

2225
                r = serialize_item_format(f, "exec-context-temporary-filesystems", "%s%s%s",
×
2226
                                          tmpfs->path,
2227
                                          isempty(escaped) ? "" : ":",
4✔
2228
                                          strempty(escaped));
2229
                if (r < 0)
4✔
2230
                        return r;
2231
        }
2232

2233
        r = serialize_item(f, "exec-context-utmp-id", c->utmp_id);
2,422✔
2234
        if (r < 0)
2,422✔
2235
                return r;
2236

2237
        r = serialize_item(f, "exec-context-utmp-mode", exec_utmp_mode_to_string(c->utmp_mode));
2,422✔
2238
        if (r < 0)
2,422✔
2239
                return r;
2240

2241
        r = serialize_bool_elide(f, "exec-context-no-new-privileges", c->no_new_privileges);
2,422✔
2242
        if (r < 0)
2,422✔
2243
                return r;
2244

2245
        if (c->selinux_context) {
2,422✔
2246
                r = serialize_item_format(f, "exec-context-selinux-context",
×
2247
                                          "%s%s",
2248
                                          c->selinux_context_ignore ? "-" : "",
×
2249
                                          c->selinux_context);
2250
                if (r < 0)
×
2251
                        return r;
2252
        }
2253

2254
        if (c->apparmor_profile) {
2,422✔
2255
                r = serialize_item_format(f, "exec-context-apparmor-profile",
×
2256
                                          "%s%s",
2257
                                          c->apparmor_profile_ignore ? "-" : "",
×
2258
                                          c->apparmor_profile);
2259
                if (r < 0)
×
2260
                        return r;
2261
        }
2262

2263
        if (c->smack_process_label) {
2,422✔
2264
                r = serialize_item_format(f, "exec-context-smack-process-label",
×
2265
                                          "%s%s",
2266
                                          c->smack_process_label_ignore ? "-" : "",
×
2267
                                          c->smack_process_label);
2268
                if (r < 0)
×
2269
                        return r;
2270
        }
2271

2272
        if (c->personality != PERSONALITY_INVALID) {
2,422✔
2273
                r = serialize_item(f, "exec-context-personality", personality_to_string(c->personality));
×
2274
                if (r < 0)
×
2275
                        return r;
2276
        }
2277

2278
        r = serialize_bool_elide(f, "exec-context-lock-personality", c->lock_personality);
2,422✔
2279
        if (r < 0)
2,422✔
2280
                return r;
2281

2282
#if HAVE_SECCOMP
2283
        if (!hashmap_isempty(c->syscall_filter)) {
2,422✔
2284
                void *errno_num, *id;
231✔
2285
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_filter) {
88,616✔
2286
                        r = serialize_item_format(f, "exec-context-syscall-filter", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
88,385✔
2287
                        if (r < 0)
88,385✔
2288
                                return r;
×
2289
                }
2290
        }
2291

2292
        if (!set_isempty(c->syscall_archs)) {
2,422✔
2293
                void *id;
227✔
2294
                SET_FOREACH(id, c->syscall_archs) {
454✔
2295
                        r = serialize_item_format(f, "exec-context-syscall-archs", "%u", PTR_TO_UINT(id) - 1);
227✔
2296
                        if (r < 0)
227✔
2297
                                return r;
×
2298
                }
2299
        }
2300

2301
        if (c->syscall_errno > 0) {
2,422✔
2302
                r = serialize_item_format(f, "exec-context-syscall-errno", "%d", c->syscall_errno);
2,422✔
2303
                if (r < 0)
2,422✔
2304
                        return r;
2305
        }
2306

2307
        r = serialize_bool_elide(f, "exec-context-syscall-allow-list", c->syscall_allow_list);
2,422✔
2308
        if (r < 0)
2,422✔
2309
                return r;
2310

2311
        if (!hashmap_isempty(c->syscall_log)) {
2,422✔
2312
                void *errno_num, *id;
×
2313
                HASHMAP_FOREACH_KEY(errno_num, id, c->syscall_log) {
×
2314
                        r = serialize_item_format(f, "exec-context-syscall-log", "%d %d", PTR_TO_INT(id) - 1, PTR_TO_INT(errno_num));
×
2315
                        if (r < 0)
×
2316
                                return r;
×
2317
                }
2318
        }
2319

2320
        r = serialize_bool_elide(f, "exec-context-syscall-log-allow-list", c->syscall_log_allow_list);
2,422✔
2321
        if (r < 0)
2,422✔
2322
                return r;
2323
#endif
2324

2325
        if (c->restrict_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,422✔
2326
                r = serialize_item_format(f, "exec-context-restrict-namespaces", "%lu", c->restrict_namespaces);
178✔
2327
                if (r < 0)
178✔
2328
                        return r;
2329
        }
2330

2331
        if (c->delegate_namespaces != NAMESPACE_FLAGS_INITIAL) {
2,422✔
2332
                r = serialize_item_format(f, "exec-context-delegate-namespaces", "%lu", c->delegate_namespaces);
9✔
2333
                if (r < 0)
9✔
2334
                        return r;
2335
        }
2336

2337
#if HAVE_LIBBPF
2338
        if (exec_context_restrict_filesystems_set(c)) {
2,422✔
2339
                char *fs;
×
2340
                SET_FOREACH(fs, c->restrict_filesystems) {
×
2341
                        r = serialize_item(f, "exec-context-restrict-filesystems", fs);
×
2342
                        if (r < 0)
×
2343
                                return r;
×
2344
                }
2345
        }
2346

2347
        r = serialize_bool_elide(f, "exec-context-restrict-filesystems-allow-list", c->restrict_filesystems_allow_list);
2,422✔
2348
        if (r < 0)
2,422✔
2349
                return r;
2350
#endif
2351

2352
        if (!set_isempty(c->address_families)) {
2,422✔
2353
                void *afp;
227✔
2354

2355
                SET_FOREACH(afp, c->address_families) {
1,109✔
2356
                        int af = PTR_TO_INT(afp);
882✔
2357

2358
                        if (af <= 0 || af >= af_max())
882✔
2359
                                continue;
×
2360

2361
                        r = serialize_item_format(f, "exec-context-address-families", "%d", af);
882✔
2362
                        if (r < 0)
882✔
2363
                                return r;
×
2364
                }
2365
        }
2366

2367
        r = serialize_bool_elide(f, "exec-context-address-families-allow-list", c->address_families_allow_list);
2,422✔
2368
        if (r < 0)
2,422✔
2369
                return r;
2370

2371
        r = serialize_item(f, "exec-context-user-namespace-path", c->user_namespace_path);
2,422✔
2372
        if (r < 0)
2,422✔
2373
                return r;
2374

2375
        r = serialize_item(f, "exec-context-network-namespace-path", c->network_namespace_path);
2,422✔
2376
        if (r < 0)
2,422✔
2377
                return r;
2378

2379
        r = serialize_item(f, "exec-context-ipc-namespace-path", c->ipc_namespace_path);
2,422✔
2380
        if (r < 0)
2,422✔
2381
                return r;
2382

2383
        FOREACH_ARRAY(mount, c->mount_images, c->n_mount_images) {
2,422✔
2384
                _cleanup_free_ char *s = NULL, *source_escaped = NULL, *dest_escaped = NULL;
×
2385

2386
                source_escaped = shell_escape(mount->source, WHITESPACE);
×
2387
                if (!source_escaped)
×
2388
                        return log_oom_debug();
×
2389

2390
                dest_escaped = shell_escape(mount->destination, WHITESPACE);
×
2391
                if (!dest_escaped)
×
2392
                        return log_oom_debug();
×
2393

2394
                s = strjoin(mount->ignore_enoent ? "-" : "",
×
2395
                            source_escaped,
2396
                            " ",
2397
                            dest_escaped);
2398
                if (!s)
×
2399
                        return log_oom_debug();
×
2400

2401
                LIST_FOREACH(mount_options, o, mount->mount_options) {
×
2402
                        _cleanup_free_ char *escaped = NULL;
×
2403

2404
                        if (isempty(o->options))
×
2405
                                continue;
×
2406

2407
                        escaped = shell_escape(o->options, ":");
×
2408
                        if (!escaped)
×
2409
                                return log_oom_debug();
×
2410

2411
                        if (!strextend(&s,
×
2412
                                       " ",
2413
                                       partition_designator_to_string(o->partition_designator),
2414
                                       ":",
2415
                                       escaped))
2416
                                return log_oom_debug();
×
2417
                }
2418

2419
                r = serialize_item(f, "exec-context-mount-image", s);
×
2420
                if (r < 0)
×
2421
                        return r;
2422
        }
2423

2424
        FOREACH_ARRAY(mount, c->extension_images, c->n_extension_images) {
2,427✔
2425
                _cleanup_free_ char *s = NULL, *source_escaped = NULL;
5✔
2426

2427
                source_escaped = shell_escape(mount->source, ":" WHITESPACE);
5✔
2428
                if (!source_escaped)
5✔
2429
                        return log_oom_debug();
×
2430

2431
                s = strjoin(mount->ignore_enoent ? "-" : "",
10✔
2432
                            source_escaped);
2433
                if (!s)
5✔
2434
                        return log_oom_debug();
×
2435

2436
                LIST_FOREACH(mount_options, o, mount->mount_options) {
5✔
2437
                        _cleanup_free_ char *escaped = NULL;
×
2438

2439
                        if (isempty(o->options))
×
2440
                                continue;
×
2441

2442
                        escaped = shell_escape(o->options, ":");
×
2443
                        if (!escaped)
×
2444
                                return log_oom_debug();
×
2445

2446
                        if (!strextend(&s,
×
2447
                                       " ",
2448
                                       partition_designator_to_string(o->partition_designator),
2449
                                       ":",
2450
                                       escaped))
2451
                                return log_oom_debug();
×
2452
                }
2453

2454
                r = serialize_item(f, "exec-context-extension-image", s);
5✔
2455
                if (r < 0)
5✔
2456
                        return r;
2457
        }
2458

2459
        r = serialize_strv(f, "exec-context-extension-directories", c->extension_directories);
2,422✔
2460
        if (r < 0)
2,422✔
2461
                return r;
2462

2463
        ExecSetCredential *sc;
2,422✔
2464
        HASHMAP_FOREACH(sc, c->set_credentials) {
2,428✔
2465
                _cleanup_free_ char *data = NULL;
6✔
2466

2467
                if (base64mem(sc->data, sc->size, &data) < 0)
6✔
2468
                        return log_oom_debug();
×
2469

2470
                r = serialize_item_format(f, "exec-context-set-credentials", "%s %s %s", sc->id, data, yes_no(sc->encrypted));
12✔
2471
                if (r < 0)
6✔
2472
                        return r;
2473
        }
2474

2475
        ExecLoadCredential *lc;
2,422✔
2476
        HASHMAP_FOREACH(lc, c->load_credentials) {
2,433✔
2477
                r = serialize_item_format(f, "exec-context-load-credentials", "%s %s %s", lc->id, lc->path, yes_no(lc->encrypted));
21✔
2478
                if (r < 0)
11✔
2479
                        return r;
×
2480
        }
2481

2482
        ExecImportCredential *ic;
2,422✔
2483
        ORDERED_SET_FOREACH(ic, c->import_credentials) {
3,376✔
2484
                r = serialize_item_format(f, "exec-context-import-credentials", "%s%s%s",
1,856✔
2485
                                          ic->glob,
2486
                                          ic->rename ? " " : "",
2487
                                          strempty(ic->rename));
954✔
2488
                if (r < 0)
954✔
2489
                        return r;
×
2490
        }
2491

2492
        r = serialize_image_policy(f, "exec-context-root-image-policy", c->root_image_policy);
2,422✔
2493
        if (r < 0)
2,422✔
2494
                return r;
2495

2496
        r = serialize_image_policy(f, "exec-context-mount-image-policy", c->mount_image_policy);
2,422✔
2497
        if (r < 0)
2,422✔
2498
                return r;
2499

2500
        r = serialize_image_policy(f, "exec-context-extension-image-policy", c->extension_image_policy);
2,422✔
2501
        if (r < 0)
2,422✔
2502
                return r;
2503

2504
        fputc('\n', f); /* End marker */
2,422✔
2505

2506
        return 0;
2507
}
2508

2509
static int exec_context_deserialize(ExecContext *c, FILE *f) {
10,019✔
2510
        int r;
10,019✔
2511

2512
        assert(f);
10,019✔
2513

2514
        if (!c)
10,019✔
2515
                return 0;
2516

2517
        for (;;) {
958,533✔
2518
                _cleanup_free_ char *l = NULL;
948,514✔
2519
                const char *val;
958,533✔
2520

2521
                r = deserialize_read_line(f, &l);
958,533✔
2522
                if (r < 0)
958,533✔
2523
                        return r;
2524
                if (r == 0) /* eof or end marker */
958,533✔
2525
                        break;
2526

2527
                if ((val = startswith(l, "exec-context-environment="))) {
948,514✔
2528
                        r = deserialize_strv(val, &c->environment);
3,493✔
2529
                        if (r < 0)
3,493✔
2530
                                return r;
2531
                } else if ((val = startswith(l, "exec-context-environment-files="))) {
945,021✔
2532
                        r = deserialize_strv(val, &c->environment_files);
344✔
2533
                        if (r < 0)
344✔
2534
                                return r;
2535
                } else if ((val = startswith(l, "exec-context-pass-environment="))) {
944,677✔
2536
                        r = deserialize_strv(val, &c->pass_environment);
315✔
2537
                        if (r < 0)
315✔
2538
                                return r;
2539
                } else if ((val = startswith(l, "exec-context-unset-environment="))) {
944,362✔
2540
                        r = deserialize_strv(val, &c->unset_environment);
972✔
2541
                        if (r < 0)
972✔
2542
                                return r;
2543
                } else if ((val = startswith(l, "exec-context-working-directory="))) {
943,390✔
2544
                        ssize_t k;
757✔
2545
                        char *p;
757✔
2546

2547
                        k = cunescape(val, 0, &p);
757✔
2548
                        if (k < 0)
757✔
2549
                                return k;
×
2550
                        free_and_replace(c->working_directory, p);
757✔
2551
                } else if ((val = startswith(l, "exec-context-root-directory="))) {
942,633✔
2552
                        ssize_t k;
7✔
2553
                        char *p;
7✔
2554

2555
                        k = cunescape(val, 0, &p);
7✔
2556
                        if (k < 0)
7✔
2557
                                return k;
×
2558
                        free_and_replace(c->root_directory, p);
7✔
2559
                } else if ((val = startswith(l, "exec-context-root-image="))) {
942,626✔
2560
                        ssize_t k;
9✔
2561
                        char *p;
9✔
2562

2563
                        k = cunescape(val, 0, &p);
9✔
2564
                        if (k < 0)
9✔
2565
                                return k;
×
2566
                        free_and_replace(c->root_image, p);
9✔
2567
                } else if ((val = startswith(l, "exec-context-root-image-options="))) {
942,617✔
2568
                        for (;;) {
×
2569
                                _cleanup_free_ char *word = NULL, *mount_options = NULL, *partition = NULL;
×
2570
                                PartitionDesignator partition_designator;
×
2571
                                MountOptions *o = NULL;
×
2572
                                const char *p;
×
2573

2574
                                r = extract_first_word(&val, &word, NULL, 0);
×
2575
                                if (r < 0)
×
2576
                                        return r;
2577
                                if (r == 0)
×
2578
                                        break;
2579

2580
                                p = word;
×
2581
                                r = extract_many_words(&p, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options);
×
2582
                                if (r < 0)
×
2583
                                        return r;
2584
                                if (r == 0)
×
2585
                                        continue;
×
2586

2587
                                partition_designator = partition_designator_from_string(partition);
×
2588
                                if (partition_designator < 0)
×
2589
                                        return -EINVAL;
2590

2591
                                o = new(MountOptions, 1);
×
2592
                                if (!o)
×
2593
                                        return log_oom_debug();
×
2594
                                *o = (MountOptions) {
×
2595
                                        .partition_designator = partition_designator,
2596
                                        .options = TAKE_PTR(mount_options),
×
2597
                                };
2598
                                LIST_APPEND(mount_options, c->root_image_options, o);
×
2599
                        }
2600
                } else if ((val = startswith(l, "exec-context-root-verity="))) {
942,617✔
2601
                        r = free_and_strdup(&c->root_verity, val);
×
2602
                        if (r < 0)
×
2603
                                return r;
2604
                } else if ((val = startswith(l, "exec-context-root-hash-path="))) {
942,617✔
2605
                        r = free_and_strdup(&c->root_hash_path, val);
×
2606
                        if (r < 0)
×
2607
                                return r;
2608
                } else if ((val = startswith(l, "exec-context-root-hash-sig-path="))) {
942,617✔
2609
                        r = free_and_strdup(&c->root_hash_sig_path, val);
×
2610
                        if (r < 0)
×
2611
                                return r;
2612
                } else if ((val = startswith(l, "exec-context-root-hash="))) {
942,617✔
2613
                        iovec_done(&c->root_hash);
4✔
2614
                        r = unhexmem(val, &c->root_hash.iov_base, &c->root_hash.iov_len);
4✔
2615
                        if (r < 0)
4✔
2616
                                return r;
2617
                } else if ((val = startswith(l, "exec-context-root-hash-sig="))) {
942,613✔
2618
                        iovec_done(&c->root_hash_sig);
×
2619
                        r = unbase64mem(val, &c->root_hash_sig.iov_base, &c->root_hash_sig.iov_len);
×
2620
                        if (r < 0)
×
2621
                                return r;
2622
                } else if ((val = startswith(l, "exec-context-root-ephemeral="))) {
942,613✔
2623
                        r = parse_boolean(val);
×
2624
                        if (r < 0)
×
2625
                                return r;
2626
                        c->root_ephemeral = r;
×
2627
                } else if ((val = startswith(l, "exec-context-umask="))) {
942,613✔
2628
                        r = parse_mode(val, &c->umask);
10,019✔
2629
                        if (r < 0)
10,019✔
2630
                                return r;
2631
                } else if ((val = startswith(l, "exec-context-private-non-blocking="))) {
932,594✔
2632
                        r = parse_boolean(val);
×
2633
                        if (r < 0)
×
2634
                                return r;
2635
                        c->non_blocking = r;
×
2636
                } else if ((val = startswith(l, "exec-context-private-mounts="))) {
932,594✔
2637
                        r = safe_atoi(val, &c->private_mounts);
139✔
2638
                        if (r < 0)
139✔
2639
                                return r;
2640
                } else if ((val = startswith(l, "exec-context-mount-api-vfs="))) {
932,455✔
2641
                        r = safe_atoi(val, &c->mount_apivfs);
29✔
2642
                        if (r < 0)
29✔
2643
                                return r;
2644
                } else if ((val = startswith(l, "exec-context-bind-log-sockets="))) {
932,426✔
2645
                        r = safe_atoi(val, &c->bind_log_sockets);
2✔
2646
                        if (r < 0)
2✔
2647
                                return r;
2648
                } else if ((val = startswith(l, "exec-context-memory-ksm="))) {
932,424✔
2649
                        r = safe_atoi(val, &c->memory_ksm);
×
2650
                        if (r < 0)
×
2651
                                return r;
2652
                } else if ((val = startswith(l, "exec-context-private-tmp="))) {
932,424✔
2653
                        c->private_tmp = private_tmp_from_string(val);
10,019✔
2654
                        if (c->private_tmp < 0)
10,019✔
2655
                                return c->private_tmp;
2656
                } else if ((val = startswith(l, "exec-context-private-var-tmp="))) {
922,405✔
2657
                        c->private_var_tmp = private_tmp_from_string(val);
10,019✔
2658
                        if (c->private_var_tmp < 0)
10,019✔
2659
                                return c->private_var_tmp;
2660
                } else if ((val = startswith(l, "exec-context-private-devices="))) {
912,386✔
2661
                        r = parse_boolean(val);
493✔
2662
                        if (r < 0)
493✔
2663
                                return r;
2664
                        c->private_devices = r;
493✔
2665
                } else if ((val = startswith(l, "exec-context-protect-kernel-tunables="))) {
911,893✔
2666
                        r = parse_boolean(val);
310✔
2667
                        if (r < 0)
310✔
2668
                                return r;
2669
                        c->protect_kernel_tunables = r;
310✔
2670
                } else if ((val = startswith(l, "exec-context-protect-kernel-modules="))) {
911,583✔
2671
                        r = parse_boolean(val);
1,104✔
2672
                        if (r < 0)
1,104✔
2673
                                return r;
2674
                        c->protect_kernel_modules = r;
1,104✔
2675
                } else if ((val = startswith(l, "exec-context-protect-kernel-logs="))) {
910,479✔
2676
                        r = parse_boolean(val);
1,104✔
2677
                        if (r < 0)
1,104✔
2678
                                return r;
2679
                        c->protect_kernel_logs = r;
1,104✔
2680
                } else if ((val = startswith(l, "exec-context-protect-clock="))) {
909,375✔
2681
                        r = parse_boolean(val);
899✔
2682
                        if (r < 0)
899✔
2683
                                return r;
2684
                        c->protect_clock = r;
899✔
2685
                } else if ((val = startswith(l, "exec-context-protect-control-groups="))) {
908,476✔
2686
                        r = protect_control_groups_from_string(val);
10,019✔
2687
                        if (r < 0)
10,019✔
2688
                                return r;
2689
                        c->protect_control_groups = r;
10,019✔
2690
                } else if ((val = startswith(l, "exec-context-private-network="))) {
898,457✔
2691
                        r = parse_boolean(val);
70✔
2692
                        if (r < 0)
70✔
2693
                                return r;
2694
                        c->private_network = r;
70✔
2695
                } else if ((val = startswith(l, "exec-context-private-users="))) {
898,387✔
2696
                        c->private_users = private_users_from_string(val);
10,019✔
2697
                        if (c->private_users < 0)
10,019✔
2698
                                return -EINVAL;
2699
                } else if ((val = startswith(l, "exec-context-private-ipc="))) {
888,368✔
2700
                        r = parse_boolean(val);
6✔
2701
                        if (r < 0)
6✔
2702
                                return r;
2703
                        c->private_ipc = r;
6✔
2704
                } else if ((val = startswith(l, "exec-context-private-pids="))) {
888,362✔
2705
                        c->private_pids = private_pids_from_string(val);
10,019✔
2706
                        if (c->private_pids < 0)
10,019✔
2707
                                return -EINVAL;
2708
                } else if ((val = startswith(l, "exec-context-remove-ipc="))) {
878,343✔
2709
                        r = parse_boolean(val);
55✔
2710
                        if (r < 0)
55✔
2711
                                return r;
2712
                        c->remove_ipc = r;
55✔
2713
                } else if ((val = startswith(l, "exec-context-protect-home="))) {
878,288✔
2714
                        c->protect_home = protect_home_from_string(val);
10,019✔
2715
                        if (c->protect_home < 0)
10,019✔
2716
                                return -EINVAL;
2717
                } else if ((val = startswith(l, "exec-context-protect-system="))) {
868,269✔
2718
                        c->protect_system = protect_system_from_string(val);
10,019✔
2719
                        if (c->protect_system < 0)
10,019✔
2720
                                return -EINVAL;
2721
                } else if ((val = startswith(l, "exec-context-same-pgrp="))) {
858,250✔
2722
                        r = parse_boolean(val);
838✔
2723
                        if (r < 0)
838✔
2724
                                return r;
2725
                        c->same_pgrp = r;
838✔
2726
                } else if ((val = startswith(l, "exec-context-non-blocking="))) {
857,412✔
2727
                        r = parse_boolean(val);
×
2728
                        if (r < 0)
×
2729
                                return r;
2730
                        c->non_blocking = r;
×
2731
                } else if ((val = startswith(l, "exec-context-ignore-sigpipe="))) {
857,412✔
2732
                        r = parse_boolean(val);
10,019✔
2733
                        if (r < 0)
10,019✔
2734
                                return r;
2735
                        c->ignore_sigpipe = r;
10,019✔
2736
                } else if ((val = startswith(l, "exec-context-memory-deny-write-execute="))) {
847,393✔
2737
                        r = parse_boolean(val);
1,466✔
2738
                        if (r < 0)
1,466✔
2739
                                return r;
2740
                        c->memory_deny_write_execute = r;
1,466✔
2741
                } else if ((val = startswith(l, "exec-context-restrict-realtime="))) {
845,927✔
2742
                        r = parse_boolean(val);
1,468✔
2743
                        if (r < 0)
1,468✔
2744
                                return r;
2745
                        c->restrict_realtime = r;
1,468✔
2746
                } else if ((val = startswith(l, "exec-context-restrict-suid-sgid="))) {
844,459✔
2747
                        r = parse_boolean(val);
1,370✔
2748
                        if (r < 0)
1,370✔
2749
                                return r;
2750
                        c->restrict_suid_sgid = r;
1,370✔
2751
                } else if ((val = startswith(l, "exec-context-keyring-mode="))) {
843,089✔
2752
                        c->keyring_mode = exec_keyring_mode_from_string(val);
10,019✔
2753
                        if (c->keyring_mode < 0)
10,019✔
2754
                                return -EINVAL;
2755
                } else if ((val = startswith(l, "exec-context-protect-hostname="))) {
833,070✔
2756
                        c->protect_hostname = protect_hostname_from_string(val);
10,019✔
2757
                        if (c->protect_hostname < 0)
10,019✔
2758
                                return -EINVAL;
2759
                } else if ((val = startswith(l, "exec-context-private-hostname="))) {
823,051✔
2760
                        r = free_and_strdup(&c->private_hostname, val);
5✔
2761
                        if (r < 0)
5✔
2762
                                return r;
2763
                } else if ((val = startswith(l, "exec-context-protect-proc="))) {
823,046✔
2764
                        c->protect_proc = protect_proc_from_string(val);
10,019✔
2765
                        if (c->protect_proc < 0)
10,019✔
2766
                                return -EINVAL;
2767
                } else if ((val = startswith(l, "exec-context-proc-subset="))) {
813,027✔
2768
                        c->proc_subset = proc_subset_from_string(val);
10,019✔
2769
                        if (c->proc_subset < 0)
10,019✔
2770
                                return -EINVAL;
2771
                } else if ((val = startswith(l, "exec-context-private-bpf="))) {
803,008✔
2772
                        c->private_bpf = private_bpf_from_string(val);
10,019✔
2773
                        if (c->private_bpf < 0)
10,019✔
2774
                                return -EINVAL;
2775
                } else if ((val = startswith(l, "exec-context-bpf-delegate-commands="))) {
792,989✔
2776
                        r = safe_atoux64(val, &c->bpf_delegate_commands);
2✔
2777
                        if (r < 0)
2✔
2778
                                return r;
2779
                } else if ((val = startswith(l, "exec-context-bpf-delegate-maps="))) {
792,987✔
2780
                        r = safe_atoux64(val, &c->bpf_delegate_maps);
1✔
2781
                        if (r < 0)
1✔
2782
                                return r;
2783
                } else if ((val = startswith(l, "exec-context-bpf-delegate-programs="))) {
792,986✔
2784
                        r = safe_atoux64(val, &c->bpf_delegate_programs);
1✔
2785
                        if (r < 0)
1✔
2786
                                return r;
2787
                } else if ((val = startswith(l, "exec-context-bpf-delegate-attachments="))) {
792,985✔
2788
                        r = safe_atoux64(val, &c->bpf_delegate_attachments);
1✔
2789
                        if (r < 0)
1✔
2790
                                return r;
2791
                } else if ((val = startswith(l, "exec-context-runtime-directory-preserve-mode="))) {
792,984✔
2792
                        c->runtime_directory_preserve_mode = exec_preserve_mode_from_string(val);
10,019✔
2793
                        if (c->runtime_directory_preserve_mode < 0)
10,019✔
2794
                                return -EINVAL;
2795
                } else if ((val = startswith(l, "exec-context-directories-"))) {
782,965✔
2796
                        _cleanup_free_ char *type = NULL, *mode = NULL;
×
2797
                        ExecDirectoryType dt;
50,095✔
2798

2799
                        r = extract_many_words(&val, "= ", 0, &type, &mode);
50,095✔
2800
                        if (r < 0)
50,095✔
2801
                                return r;
2802
                        if (r == 0 || !mode)
50,095✔
2803
                                return -EINVAL;
2804

2805
                        dt = exec_directory_type_from_string(type);
50,095✔
2806
                        if (dt < 0)
50,095✔
2807
                                return dt;
2808

2809
                        r = parse_mode(mode, &c->directories[dt].mode);
50,095✔
2810
                        if (r < 0)
50,095✔
2811
                                return r;
2812

2813
                        for (;;) {
53,046✔
2814
                                _cleanup_free_ char *tuple = NULL, *path = NULL, *only_create = NULL, *read_only = NULL;
52,939✔
2815
                                ExecDirectoryFlags exec_directory_flags = 0;
53,046✔
2816
                                const char *p;
53,046✔
2817

2818
                                /* Use EXTRACT_UNESCAPE_RELAX here, as we unescape the colons in subsequent calls */
2819
                                r = extract_first_word(&val, &tuple, WHITESPACE, EXTRACT_UNESCAPE_SEPARATORS|EXTRACT_UNESCAPE_RELAX);
53,046✔
2820
                                if (r < 0)
53,046✔
2821
                                        return r;
2822
                                if (r == 0)
53,046✔
2823
                                        break;
2824

2825
                                p = tuple;
2,951✔
2826
                                r = extract_many_words(&p, ":", EXTRACT_UNESCAPE_SEPARATORS, &path, &only_create, &read_only);
2,951✔
2827
                                if (r < 0)
2,951✔
2828
                                        return r;
2829
                                if (r < 2)
2,951✔
2830
                                        continue;
×
2831

2832
                                r = parse_boolean(only_create);
2,951✔
2833
                                if (r < 0)
2,951✔
2834
                                        return r;
2835
                                if (r > 0)
2,951✔
2836
                                        exec_directory_flags |= EXEC_DIRECTORY_ONLY_CREATE;
5✔
2837

2838
                                r = parse_boolean(read_only);
2,951✔
2839
                                if (r < 0)
2,951✔
2840
                                        return r;
2841
                                if (r > 0)
2,951✔
2842
                                        exec_directory_flags |= EXEC_DIRECTORY_READ_ONLY;
50✔
2843

2844
                                r = exec_directory_add(&c->directories[dt], path, /* symlink= */ NULL, exec_directory_flags);
2,951✔
2845
                                if (r < 0)
2,951✔
2846
                                        return r;
2847

2848
                                if (isempty(p))
2,951✔
2849
                                        continue;
2,844✔
2850

2851
                                for (;;) {
385✔
2852
                                        _cleanup_free_ char *link = NULL;
246✔
2853

2854
                                        r = extract_first_word(&p, &link, ":", EXTRACT_UNESCAPE_SEPARATORS);
246✔
2855
                                        if (r < 0)
246✔
2856
                                                return r;
2857
                                        if (r == 0)
246✔
2858
                                                break;
2859

2860
                                        r = strv_consume(&c->directories[dt].items[c->directories[dt].n_items - 1].symlinks, TAKE_PTR(link));
139✔
2861
                                        if (r < 0)
139✔
2862
                                                return r;
2863
                                }
2864
                        }
2865
                } else if ((val = startswith(l, "exec-context-quota-accounting-directories-"))) {
732,870✔
2866
                        _cleanup_free_ char *type = NULL, *quota_accounting = NULL;
×
2867
                        ExecDirectoryType dt;
×
2868

2869
                        r = split_pair(val, "=", &type, &quota_accounting);
×
2870
                        if (r < 0)
×
2871
                                return r;
2872

2873
                        dt = exec_directory_type_from_string(type);
×
2874
                        if (dt < 0)
×
2875
                                return dt;
2876

2877
                        r = parse_boolean(quota_accounting);
×
2878
                        if (r < 0)
×
2879
                                return r;
2880

2881
                        c->directories[dt].exec_quota.quota_accounting = r;
×
2882
                } else if ((val = startswith(l, "exec-context-quota-directories-"))) {
732,870✔
2883
                        _cleanup_free_ char *type = NULL, *quota_info = NULL, *quota_absolute = NULL, *quota_scale = NULL;
×
2884
                        ExecDirectoryType dt;
×
2885

2886
                        r = split_pair(val, "=", &type, &quota_info);
×
2887
                        if (r < 0)
×
2888
                                return r;
2889

2890
                        r = split_pair(quota_info, " ", &quota_absolute, &quota_scale);
×
2891
                        if (r < 0)
×
2892
                                return r;
2893

2894
                        dt = exec_directory_type_from_string(type);
×
2895
                        if (dt < 0)
×
2896
                                return dt;
2897

2898
                        r = safe_atou64(quota_absolute, &c->directories[dt].exec_quota.quota_absolute);
×
2899
                        if (r < 0)
×
2900
                               return r;
2901

2902
                        r = safe_atou32(quota_scale, &c->directories[dt].exec_quota.quota_scale);
×
2903
                        if (r < 0)
×
2904
                               return r;
2905

2906
                        c->directories[dt].exec_quota.quota_enforce = true;
×
2907
                } else if ((val = startswith(l, "exec-context-timeout-clean-usec="))) {
732,870✔
2908
                        r = deserialize_usec(val, &c->timeout_clean_usec);
×
2909
                        if (r < 0)
×
2910
                                return r;
2911
                } else if ((val = startswith(l, "exec-context-nice="))) {
732,870✔
2912
                        r = safe_atoi(val, &c->nice);
19✔
2913
                        if (r < 0)
19✔
2914
                                return r;
2915
                        c->nice_set = true;
19✔
2916
                } else if ((val = startswith(l, "exec-context-working-directory-missing-ok="))) {
732,851✔
2917
                        r = parse_boolean(val);
696✔
2918
                        if (r < 0)
696✔
2919
                                return r;
2920
                        c->working_directory_missing_ok = r;
696✔
2921
                } else if ((val = startswith(l, "exec-context-working-directory-home="))) {
732,155✔
2922
                        r = parse_boolean(val);
179✔
2923
                        if (r < 0)
179✔
2924
                                return r;
2925
                        c->working_directory_home = r;
179✔
2926
                } else if ((val = startswith(l, "exec-context-oom-score-adjust="))) {
731,976✔
2927
                        r = safe_atoi(val, &c->oom_score_adjust);
1,083✔
2928
                        if (r < 0)
1,083✔
2929
                                return r;
2930
                        c->oom_score_adjust_set = true;
1,083✔
2931
                } else if ((val = startswith(l, "exec-context-coredump-filter="))) {
730,893✔
2932
                        r = safe_atoux64(val, &c->coredump_filter);
2✔
2933
                        if (r < 0)
2✔
2934
                                return r;
2935
                        c->coredump_filter_set = true;
2✔
2936
                } else if ((val = startswith(l, "exec-context-limit-"))) {
730,891✔
2937
                        _cleanup_free_ struct rlimit *rlimit = NULL;
×
2938
                        _cleanup_free_ char *limit = NULL;
20,033✔
2939
                        int type;
20,033✔
2940

2941
                        r = extract_first_word(&val, &limit, "=", 0);
20,033✔
2942
                        if (r < 0)
20,033✔
2943
                                return r;
2944
                        if (r == 0 || !val)
20,033✔
2945
                                return -EINVAL;
2946

2947
                        type = rlimit_from_string(limit);
20,033✔
2948
                        if (type < 0)
20,033✔
2949
                                return -EINVAL;
2950

2951
                        if (!c->rlimit[type]) {
20,033✔
2952
                                rlimit = new0(struct rlimit, 1);
20,033✔
2953
                                if (!rlimit)
20,033✔
2954
                                        return log_oom_debug();
×
2955

2956
                                r = rlimit_parse(type, val, rlimit);
20,033✔
2957
                                if (r < 0)
20,033✔
2958
                                        return r;
2959

2960
                                c->rlimit[type] = TAKE_PTR(rlimit);
20,033✔
2961
                        } else {
2962
                                r = rlimit_parse(type, val, c->rlimit[type]);
×
2963
                                if (r < 0)
×
2964
                                        return r;
2965
                        }
2966
                } else if ((val = startswith(l, "exec-context-ioprio="))) {
710,858✔
2967
                        r = safe_atoi(val, &c->ioprio);
11✔
2968
                        if (r < 0)
11✔
2969
                                return r;
2970
                        c->ioprio_is_set = true;
11✔
2971
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-policy="))) {
710,847✔
2972
                        c->cpu_sched_policy = sched_policy_from_string(val);
×
2973
                        if (c->cpu_sched_policy < 0)
×
2974
                                return -EINVAL;
2975
                        c->cpu_sched_set = true;
×
2976
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-priority="))) {
710,847✔
2977
                        r = safe_atoi(val, &c->cpu_sched_priority);
×
2978
                        if (r < 0)
×
2979
                                return r;
2980
                        c->cpu_sched_set = true;
×
2981
                } else if ((val = startswith(l, "exec-context-cpu-scheduling-reset-on-fork="))) {
710,847✔
2982
                        r = parse_boolean(val);
×
2983
                        if (r < 0)
×
2984
                                return r;
2985
                        c->cpu_sched_reset_on_fork = r;
×
2986
                        c->cpu_sched_set = true;
×
2987
                } else if ((val = startswith(l, "exec-context-cpu-affinity="))) {
710,847✔
2988
                        if (c->cpu_set.set)
×
2989
                                return -EINVAL; /* duplicated */
2990

2991
                        r = parse_cpu_set(val, &c->cpu_set);
×
2992
                        if (r < 0)
×
2993
                                return r;
2994
                } else if ((val = startswith(l, "exec-context-numa-mask="))) {
710,847✔
2995
                        if (c->numa_policy.nodes.set)
19✔
2996
                                return -EINVAL; /* duplicated */
2997

2998
                        r = parse_cpu_set(val, &c->numa_policy.nodes);
19✔
2999
                        if (r < 0)
19✔
3000
                                return r;
3001
                } else if ((val = startswith(l, "exec-context-numa-policy="))) {
710,828✔
3002
                        r = safe_atoi(val, &c->numa_policy.type);
19✔
3003
                        if (r < 0)
19✔
3004
                                return r;
3005
                } else if ((val = startswith(l, "exec-context-cpu-affinity-from-numa="))) {
710,809✔
3006
                        r = parse_boolean(val);
2✔
3007
                        if (r < 0)
2✔
3008
                                return r;
3009
                        c->cpu_affinity_from_numa = r;
2✔
3010
                } else if ((val = startswith(l, "exec-context-timer-slack-nsec="))) {
710,807✔
3011
                        r = deserialize_usec(val, (usec_t *)&c->timer_slack_nsec);
×
3012
                        if (r < 0)
×
3013
                                return r;
3014
                } else if ((val = startswith(l, "exec-context-root-directory-as-fd="))) {
710,807✔
3015
                        r = parse_boolean(val);
2✔
3016
                        if (r < 0)
2✔
3017
                                return r;
3018
                        c->root_directory_as_fd = r;
2✔
3019
                } else if ((val = startswith(l, "exec-context-std-input="))) {
710,805✔
3020
                        c->std_input = exec_input_from_string(val);
10,019✔
3021
                        if (c->std_input < 0)
10,019✔
3022
                                return c->std_input;
3023
                } else if ((val = startswith(l, "exec-context-std-output="))) {
700,786✔
3024
                        c->std_output = exec_output_from_string(val);
10,019✔
3025
                        if (c->std_output < 0)
10,019✔
3026
                                return c->std_output;
3027
                } else if ((val = startswith(l, "exec-context-std-error="))) {
690,767✔
3028
                        c->std_error = exec_output_from_string(val);
10,019✔
3029
                        if (c->std_error < 0)
10,019✔
3030
                                return c->std_error;
3031
                } else if ((val = startswith(l, "exec-context-stdio-as-fds="))) {
680,748✔
3032
                        r = parse_boolean(val);
544✔
3033
                        if (r < 0)
544✔
3034
                                return r;
3035
                        c->stdio_as_fds = r;
544✔
3036
                } else if ((val = startswith(l, "exec-context-std-input-data="))) {
680,204✔
3037
                        if (c->stdin_data)
1✔
3038
                                return -EINVAL; /* duplicated */
3039

3040
                        r = unbase64mem(val, &c->stdin_data, &c->stdin_data_size);
1✔
3041
                        if (r < 0)
1✔
3042
                                return r;
3043
                } else if ((val = startswith(l, "exec-context-std-input-fd-name="))) {
680,203✔
3044
                        r = free_and_strdup(&c->stdio_fdname[STDIN_FILENO], val);
×
3045
                        if (r < 0)
×
3046
                                return r;
3047
                } else if ((val = startswith(l, "exec-context-std-output-fd-name="))) {
680,203✔
3048
                        r = free_and_strdup(&c->stdio_fdname[STDOUT_FILENO], val);
×
3049
                        if (r < 0)
×
3050
                                return r;
3051
                } else if ((val = startswith(l, "exec-context-std-error-fd-name="))) {
680,203✔
3052
                        r = free_and_strdup(&c->stdio_fdname[STDERR_FILENO], val);
×
3053
                        if (r < 0)
×
3054
                                return r;
3055
                } else if ((val = startswith(l, "exec-context-std-input-file="))) {
680,203✔
3056
                        ssize_t k;
×
3057
                        char *p;
×
3058

3059
                        k = cunescape(val, 0, &p);
×
3060
                        if (k < 0)
×
3061
                                return k;
×
3062

3063
                        free_and_replace(c->stdio_file[STDIN_FILENO], p);
×
3064

3065
                } else if ((val = startswith(l, "exec-context-std-output-file="))) {
680,203✔
3066
                        ssize_t k;
53✔
3067
                        char *p;
53✔
3068

3069
                        k = cunescape(val, 0, &p);
53✔
3070
                        if (k < 0)
53✔
3071
                                return k;
×
3072

3073
                        free_and_replace(c->stdio_file[STDOUT_FILENO], p);
53✔
3074

3075
                } else if ((val = startswith(l, "exec-context-std-error-file="))) {
680,150✔
3076
                        ssize_t k;
49✔
3077
                        char *p;
49✔
3078

3079
                        k = cunescape(val, 0, &p);
49✔
3080
                        if (k < 0)
49✔
3081
                                return k;
×
3082

3083
                        free_and_replace(c->stdio_file[STDERR_FILENO], p);
49✔
3084

3085
                } else if ((val = startswith(l, "exec-context-tty-path="))) {
680,101✔
3086
                        r = free_and_strdup(&c->tty_path, val);
105✔
3087
                        if (r < 0)
105✔
3088
                                return r;
3089
                } else if ((val = startswith(l, "exec-context-tty-reset="))) {
679,996✔
3090
                        r = parse_boolean(val);
194✔
3091
                        if (r < 0)
194✔
3092
                                return r;
3093
                        c->tty_reset = r;
194✔
3094
                } else if ((val = startswith(l, "exec-context-tty-vhangup="))) {
679,802✔
3095
                        r = parse_boolean(val);
84✔
3096
                        if (r < 0)
84✔
3097
                                return r;
3098
                        c->tty_vhangup = r;
84✔
3099
                } else if ((val = startswith(l, "exec-context-tty-vt-disallocate="))) {
679,718✔
3100
                        r = parse_boolean(val);
46✔
3101
                        if (r < 0)
46✔
3102
                                return r;
3103
                        c->tty_vt_disallocate = r;
46✔
3104
                } else if ((val = startswith(l, "exec-context-tty-rows="))) {
679,672✔
3105
                        r = safe_atou(val, &c->tty_rows);
10,019✔
3106
                        if (r < 0)
10,019✔
3107
                                return r;
3108
                } else if ((val = startswith(l, "exec-context-tty-columns="))) {
669,653✔
3109
                        r = safe_atou(val, &c->tty_cols);
10,019✔
3110
                        if (r < 0)
10,019✔
3111
                                return r;
3112
                } else if ((val = startswith(l, "exec-context-syslog-priority="))) {
659,634✔
3113
                        r = safe_atoi(val, &c->syslog_priority);
10,019✔
3114
                        if (r < 0)
10,019✔
3115
                                return r;
3116
                } else if ((val = startswith(l, "exec-context-syslog-level-prefix="))) {
649,615✔
3117
                        r = parse_boolean(val);
10,019✔
3118
                        if (r < 0)
10,019✔
3119
                                return r;
3120
                        c->syslog_level_prefix = r;
10,019✔
3121
                } else if ((val = startswith(l, "exec-context-syslog-identifier="))) {
639,596✔
3122
                        r = free_and_strdup(&c->syslog_identifier, val);
×
3123
                        if (r < 0)
×
3124
                                return r;
3125
                } else if ((val = startswith(l, "exec-context-log-level-max="))) {
639,596✔
3126
                        /* See comment in serialization. */
3127
                        r = safe_atoi(val, &c->log_level_max);
10,019✔
3128
                        if (r < 0)
10,019✔
3129
                                return r;
3130
                } else if ((val = startswith(l, "exec-context-log-ratelimit-interval-usec="))) {
629,577✔
3131
                        r = deserialize_usec(val, &c->log_ratelimit.interval);
×
3132
                        if (r < 0)
×
3133
                                return r;
3134
                } else if ((val = startswith(l, "exec-context-log-ratelimit-burst="))) {
629,577✔
3135
                        r = safe_atou(val, &c->log_ratelimit.burst);
×
3136
                        if (r < 0)
×
3137
                                return r;
3138
                } else if ((val = startswith(l, "exec-context-log-filter-allowed-patterns="))) {
629,577✔
3139
                        r = set_put_strdup(&c->log_filter_allowed_patterns, val);
20✔
3140
                        if (r < 0)
20✔
3141
                                return r;
3142
                } else if ((val = startswith(l, "exec-context-log-filter-denied-patterns="))) {
629,557✔
3143
                        r = set_put_strdup(&c->log_filter_denied_patterns, val);
13✔
3144
                        if (r < 0)
13✔
3145
                                return r;
3146
                } else if ((val = startswith(l, "exec-context-log-extra-fields="))) {
629,544✔
3147
                        if (!GREEDY_REALLOC(c->log_extra_fields, c->n_log_extra_fields + 1))
706✔
3148
                                return log_oom_debug();
×
3149

3150
                        c->log_extra_fields[c->n_log_extra_fields++].iov_base = strdup(val);
706✔
3151
                        if (!c->log_extra_fields[c->n_log_extra_fields-1].iov_base)
706✔
3152
                                return log_oom_debug();
×
3153
                } else if ((val = startswith(l, "exec-context-log-namespace="))) {
628,838✔
3154
                        r = free_and_strdup(&c->log_namespace, val);
2✔
3155
                        if (r < 0)
2✔
3156
                                return r;
3157
                } else if ((val = startswith(l, "exec-context-secure-bits="))) {
628,836✔
3158
                        r = safe_atoi(val, &c->secure_bits);
×
3159
                        if (r < 0)
×
3160
                                return r;
3161
                } else if ((val = startswith(l, "exec-context-capability-bounding-set="))) {
628,836✔
3162
                        r = safe_atou64(val, &c->capability_bounding_set);
10,019✔
3163
                        if (r < 0)
10,019✔
3164
                                return r;
3165
                } else if ((val = startswith(l, "exec-context-capability-ambient-set="))) {
618,817✔
3166
                        r = safe_atou64(val, &c->capability_ambient_set);
654✔
3167
                        if (r < 0)
654✔
3168
                                return r;
3169
                } else if ((val = startswith(l, "exec-context-user="))) {
618,163✔
3170
                        r = free_and_strdup(&c->user, val);
2,076✔
3171
                        if (r < 0)
2,076✔
3172
                                return r;
3173
                } else if ((val = startswith(l, "exec-context-group="))) {
616,087✔
3174
                        r = free_and_strdup(&c->group, val);
60✔
3175
                        if (r < 0)
60✔
3176
                                return r;
3177
                } else if ((val = startswith(l, "exec-context-dynamic-user="))) {
616,027✔
3178
                        r = parse_boolean(val);
47✔
3179
                        if (r < 0)
47✔
3180
                                return r;
3181
                        c->dynamic_user = r;
47✔
3182
                } else if ((val = startswith(l, "exec-context-supplementary-groups="))) {
615,980✔
3183
                        r = deserialize_strv(val, &c->supplementary_groups);
12✔
3184
                        if (r < 0)
12✔
3185
                                return r;
3186
                } else if ((val = startswith(l, "exec-context-set-login-environment="))) {
615,968✔
3187
                        r = safe_atoi(val, &c->set_login_environment);
×
3188
                        if (r < 0)
×
3189
                                return r;
3190
                } else if ((val = startswith(l, "exec-context-pam-name="))) {
615,968✔
3191
                        r = free_and_strdup(&c->pam_name, val);
509✔
3192
                        if (r < 0)
509✔
3193
                                return r;
3194
                } else if ((val = startswith(l, "exec-context-read-write-paths="))) {
615,459✔
3195
                        r = deserialize_strv(val, &c->read_write_paths);
822✔
3196
                        if (r < 0)
822✔
3197
                                return r;
3198
                } else if ((val = startswith(l, "exec-context-read-only-paths="))) {
614,637✔
3199
                        r = deserialize_strv(val, &c->read_only_paths);
2✔
3200
                        if (r < 0)
2✔
3201
                                return r;
3202
                } else if ((val = startswith(l, "exec-context-inaccessible-paths="))) {
614,635✔
3203
                        r = deserialize_strv(val, &c->inaccessible_paths);
5✔
3204
                        if (r < 0)
5✔
3205
                                return r;
3206
                } else if ((val = startswith(l, "exec-context-exec-paths="))) {
614,630✔
3207
                        r = deserialize_strv(val, &c->exec_paths);
1✔
3208
                        if (r < 0)
1✔
3209
                                return r;
3210
                } else if ((val = startswith(l, "exec-context-no-exec-paths="))) {
614,629✔
3211
                        r = deserialize_strv(val, &c->no_exec_paths);
1✔
3212
                        if (r < 0)
1✔
3213
                                return r;
3214
                } else if ((val = startswith(l, "exec-context-exec-search-path="))) {
614,628✔
3215
                        r = deserialize_strv(val, &c->exec_search_path);
×
3216
                        if (r < 0)
×
3217
                                return r;
3218
                } else if ((val = startswith(l, "exec-context-mount-propagation-flag="))) {
614,628✔
3219
                        r = safe_atolu(val, &c->mount_propagation_flag);
10,019✔
3220
                        if (r < 0)
10,019✔
3221
                                return r;
3222
                } else if ((val = startswith(l, "exec-context-bind-read-only-path="))) {
604,609✔
3223
                        _cleanup_free_ char *source = NULL, *destination = NULL;
7✔
3224
                        bool rbind = true, ignore_enoent = false;
7✔
3225
                        char *s = NULL, *d = NULL;
7✔
3226

3227
                        r = extract_first_word(&val,
7✔
3228
                                               &source,
3229
                                               ":" WHITESPACE,
3230
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3231
                        if (r < 0)
7✔
3232
                                return r;
3233
                        if (r == 0)
7✔
3234
                                return -EINVAL;
3235

3236
                        s = source;
7✔
3237
                        if (s[0] == '-') {
7✔
3238
                                ignore_enoent = true;
1✔
3239
                                s++;
1✔
3240
                        }
3241

3242
                        if (val && val[-1] == ':') {
7✔
3243
                                r = extract_first_word(&val,
7✔
3244
                                                       &destination,
3245
                                                       ":" WHITESPACE,
3246
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3247
                                if (r < 0)
7✔
3248
                                        return r;
3249
                                if (r == 0)
7✔
3250
                                        continue;
×
3251

3252
                                d = destination;
7✔
3253

3254
                                if (val && val[-1] == ':') {
7✔
3255
                                        _cleanup_free_ char *options = NULL;
7✔
3256

3257
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
7✔
3258
                                        if (r < 0)
7✔
3259
                                                return -r;
×
3260

3261
                                        if (isempty(options) || streq(options, "rbind"))
15✔
3262
                                                rbind = true;
3263
                                        else if (streq(options, "norbind"))
1✔
3264
                                                rbind = false;
3265
                                        else
3266
                                                continue;
×
3267
                                }
3268
                        } else
3269
                                d = s;
3270

3271
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
14✔
3272
                                        &(BindMount) {
7✔
3273
                                                .source = s,
3274
                                                .destination = d,
3275
                                                .read_only = true,
3276
                                                .recursive = rbind,
3277
                                                .ignore_enoent = ignore_enoent,
3278
                                        });
3279
                        if (r < 0)
7✔
3280
                                return log_oom_debug();
×
3281
                } else if ((val = startswith(l, "exec-context-bind-path="))) {
604,602✔
3282
                        _cleanup_free_ char *source = NULL, *destination = NULL;
20✔
3283
                        bool rbind = true, ignore_enoent = false;
20✔
3284
                        char *s = NULL, *d = NULL;
20✔
3285

3286
                        r = extract_first_word(&val,
20✔
3287
                                               &source,
3288
                                               ":" WHITESPACE,
3289
                                               EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3290
                        if (r < 0)
20✔
3291
                                return r;
3292
                        if (r == 0)
20✔
3293
                                return -EINVAL;
3294

3295
                        s = source;
20✔
3296
                        if (s[0] == '-') {
20✔
3297
                                ignore_enoent = true;
1✔
3298
                                s++;
1✔
3299
                        }
3300

3301
                        if (val && val[-1] == ':') {
20✔
3302
                                r = extract_first_word(&val,
20✔
3303
                                                       &destination,
3304
                                                       ":" WHITESPACE,
3305
                                                       EXTRACT_UNQUOTE|EXTRACT_DONT_COALESCE_SEPARATORS|EXTRACT_UNESCAPE_SEPARATORS);
3306
                                if (r < 0)
20✔
3307
                                        return r;
3308
                                if (r == 0)
20✔
3309
                                        continue;
×
3310

3311
                                d = destination;
20✔
3312

3313
                                if (val && val[-1] == ':') {
20✔
3314
                                        _cleanup_free_ char *options = NULL;
20✔
3315

3316
                                        r = extract_first_word(&val, &options, NULL, EXTRACT_UNQUOTE);
20✔
3317
                                        if (r < 0)
20✔
3318
                                                return -r;
×
3319

3320
                                        if (isempty(options) || streq(options, "rbind"))
43✔
3321
                                                rbind = true;
3322
                                        else if (streq(options, "norbind"))
3✔
3323
                                                rbind = false;
3324
                                        else
3325
                                                continue;
×
3326
                                }
3327
                        } else
3328
                                d = s;
3329

3330
                        r = bind_mount_add(&c->bind_mounts, &c->n_bind_mounts,
40✔
3331
                                        &(BindMount) {
20✔
3332
                                                .source = s,
3333
                                                .destination = d,
3334
                                                .read_only = false,
3335
                                                .recursive = rbind,
3336
                                                .ignore_enoent = ignore_enoent,
3337
                                        });
3338
                        if (r < 0)
20✔
3339
                                return log_oom_debug();
×
3340
                } else if ((val = startswith(l, "exec-context-temporary-filesystems="))) {
604,582✔
3341
                        _cleanup_free_ char *path = NULL, *options = NULL;
61✔
3342

3343
                        r = extract_many_words(&val, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &path, &options);
61✔
3344
                        if (r < 0)
61✔
3345
                                return r;
3346
                        if (r < 1)
61✔
3347
                                continue;
×
3348

3349
                        r = temporary_filesystem_add(&c->temporary_filesystems, &c->n_temporary_filesystems, path, options);
61✔
3350
                        if (r < 0)
61✔
3351
                                return log_oom_debug();
×
3352
                } else if ((val = startswith(l, "exec-context-utmp-id="))) {
604,521✔
3353
                        r = free_and_strdup(&c->utmp_id, val);
91✔
3354
                        if (r < 0)
91✔
3355
                                return r;
3356
                } else if ((val = startswith(l, "exec-context-utmp-mode="))) {
604,430✔
3357
                        c->utmp_mode = exec_utmp_mode_from_string(val);
10,019✔
3358
                        if (c->utmp_mode < 0)
10,019✔
3359
                                return c->utmp_mode;
3360
                } else if ((val = startswith(l, "exec-context-no-new-privileges="))) {
594,411✔
3361
                        r = parse_boolean(val);
1,397✔
3362
                        if (r < 0)
1,397✔
3363
                                return r;
3364
                        c->no_new_privileges = r;
1,397✔
3365
                } else if ((val = startswith(l, "exec-context-selinux-context="))) {
593,014✔
3366
                        if (val[0] == '-') {
×
3367
                                c->selinux_context_ignore = true;
×
3368
                                val++;
×
3369
                        } else
3370
                                c->selinux_context_ignore = false;
×
3371

3372
                        r = free_and_strdup(&c->selinux_context, val);
×
3373
                        if (r < 0)
×
3374
                                return r;
3375
                } else if ((val = startswith(l, "exec-context-apparmor-profile="))) {
593,014✔
3376
                        if (val[0] == '-') {
×
3377
                                c->apparmor_profile_ignore = true;
×
3378
                                val++;
×
3379
                        } else
3380
                                c->apparmor_profile_ignore = false;
×
3381

3382
                        r = free_and_strdup(&c->apparmor_profile, val);
×
3383
                        if (r < 0)
×
3384
                                return r;
3385
                } else if ((val = startswith(l, "exec-context-smack-process-label="))) {
593,014✔
3386
                        if (val[0] == '-') {
×
3387
                                c->smack_process_label_ignore = true;
×
3388
                                val++;
×
3389
                        } else
3390
                                c->smack_process_label_ignore = false;
×
3391

3392
                        r = free_and_strdup(&c->smack_process_label, val);
×
3393
                        if (r < 0)
×
3394
                                return r;
3395
                } else if ((val = startswith(l, "exec-context-personality="))) {
593,014✔
3396
                        c->personality = personality_from_string(val);
×
3397
                        if (c->personality == PERSONALITY_INVALID)
×
3398
                                return -EINVAL;
3399
                } else if ((val = startswith(l, "exec-context-lock-personality="))) {
593,014✔
3400
                        r = parse_boolean(val);
1,471✔
3401
                        if (r < 0)
1,471✔
3402
                                return r;
3403
                        c->lock_personality = r;
1,471✔
3404
#if HAVE_SECCOMP
3405
                } else if ((val = startswith(l, "exec-context-syscall-filter="))) {
591,543✔
3406
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
565,908✔
3407
                        int id, errno_num;
565,908✔
3408

3409
                        r = extract_many_words(&val, NULL, 0, &s_id, &s_errno_num);
565,908✔
3410
                        if (r < 0)
565,908✔
3411
                                return r;
3412
                        if (r != 2)
565,908✔
3413
                                continue;
×
3414

3415
                        r = safe_atoi(s_id, &id);
565,908✔
3416
                        if (r < 0)
565,908✔
3417
                                return r;
3418

3419
                        r = safe_atoi(s_errno_num, &errno_num);
565,908✔
3420
                        if (r < 0)
565,908✔
3421
                                return r;
3422

3423
                        r = hashmap_ensure_put(&c->syscall_filter, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
565,908✔
3424
                        if (r < 0)
565,908✔
3425
                                return r;
3426
                } else if ((val = startswith(l, "exec-context-syscall-archs="))) {
25,635✔
3427
                        unsigned id;
1,472✔
3428

3429
                        r = safe_atou(val, &id);
1,472✔
3430
                        if (r < 0)
1,472✔
3431
                                return r;
×
3432

3433
                        r = set_ensure_put(&c->syscall_archs, NULL, UINT_TO_PTR(id + 1));
1,472✔
3434
                        if (r < 0)
1,472✔
3435
                                return r;
3436
                } else if ((val = startswith(l, "exec-context-syscall-errno="))) {
24,163✔
3437
                        r = safe_atoi(val, &c->syscall_errno);
10,019✔
3438
                        if (r < 0)
10,019✔
3439
                                return r;
3440
                } else if ((val = startswith(l, "exec-context-syscall-allow-list="))) {
14,144✔
3441
                        r = parse_boolean(val);
1,448✔
3442
                        if (r < 0)
1,448✔
3443
                                return r;
3444
                        c->syscall_allow_list = r;
1,448✔
3445
                } else if ((val = startswith(l, "exec-context-syscall-log="))) {
12,696✔
3446
                        _cleanup_free_ char *s_id = NULL, *s_errno_num = NULL;
×
3447
                        int id, errno_num;
×
3448

3449
                        r = extract_many_words(&val, " ", 0, &s_id, &s_errno_num);
×
3450
                        if (r < 0)
×
3451
                                return r;
3452
                        if (r != 2)
×
3453
                                continue;
×
3454

3455
                        r = safe_atoi(s_id, &id);
×
3456
                        if (r < 0)
×
3457
                                return r;
3458

3459
                        r = safe_atoi(s_errno_num, &errno_num);
×
3460
                        if (r < 0)
×
3461
                                return r;
3462

3463
                        r = hashmap_ensure_put(&c->syscall_log, NULL, INT_TO_PTR(id + 1), INT_TO_PTR(errno_num));
×
3464
                        if (r < 0)
×
3465
                                return r;
3466
                } else if ((val = startswith(l, "exec-context-syscall-log-allow-list="))) {
12,696✔
3467
                        r = parse_boolean(val);
×
3468
                        if (r < 0)
×
3469
                                return r;
3470
                        c->syscall_log_allow_list = r;
×
3471
#endif
3472
                } else if ((val = startswith(l, "exec-context-restrict-namespaces="))) {
12,696✔
3473
                        r = safe_atolu(val, &c->restrict_namespaces);
1,219✔
3474
                        if (r < 0)
1,219✔
3475
                                return r;
3476
                } else if ((val = startswith(l, "exec-context-delegate-namespaces="))) {
11,477✔
3477
                        r = safe_atolu(val, &c->delegate_namespaces);
21✔
3478
                        if (r < 0)
21✔
3479
                                return r;
3480
                } else if ((val = startswith(l, "exec-context-restrict-filesystems="))) {
11,456✔
3481
                        r = set_put_strdup(&c->restrict_filesystems, val);
×
3482
                        if (r < 0)
×
3483
                                return r;
3484
                } else if ((val = startswith(l, "exec-context-restrict-filesystems-allow-list="))) {
11,456✔
3485
                        r = parse_boolean(val);
×
3486
                        if (r < 0)
×
3487
                                return r;
3488
                        c->restrict_filesystems_allow_list = r;
×
3489
                } else if ((val = startswith(l, "exec-context-address-families="))) {
11,456✔
3490
                        int af;
5,782✔
3491

3492
                        r = safe_atoi(val, &af);
5,782✔
3493
                        if (r < 0)
5,782✔
3494
                                return r;
×
3495

3496
                        r = set_ensure_put(&c->address_families, NULL, INT_TO_PTR(af));
5,782✔
3497
                        if (r < 0)
5,782✔
3498
                                return r;
3499
                } else if ((val = startswith(l, "exec-context-address-families-allow-list="))) {
5,674✔
3500
                        r = parse_boolean(val);
1,466✔
3501
                        if (r < 0)
1,466✔
3502
                                return r;
3503
                        c->address_families_allow_list = r;
1,466✔
3504
                } else if ((val = startswith(l, "exec-context-network-namespace-path="))) {
4,208✔
3505
                        r = free_and_strdup(&c->network_namespace_path, val);
1✔
3506
                        if (r < 0)
1✔
3507
                                return r;
3508
                } else if ((val = startswith(l, "exec-context-user-namespace-path="))) {
4,207✔
3509
                        r = free_and_strdup(&c->user_namespace_path, val);
3✔
3510
                        if (r < 0)
3✔
3511
                                return r;
3512
                } else if ((val = startswith(l, "exec-context-ipc-namespace-path="))) {
4,204✔
3513
                        r = free_and_strdup(&c->ipc_namespace_path, val);
×
3514
                        if (r < 0)
×
3515
                                return r;
3516
                } else if ((val = startswith(l, "exec-context-mount-image="))) {
4,204✔
3517
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3518
                        _cleanup_free_ char *source = NULL, *destination = NULL;
57✔
3519
                        bool permissive = false;
57✔
3520
                        char *s;
57✔
3521

3522
                        r = extract_many_words(&val,
57✔
3523
                                               NULL,
3524
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3525
                                               &source,
3526
                                               &destination);
3527
                        if (r < 0)
57✔
3528
                                return r;
3529
                        if (r == 0)
57✔
3530
                                return -EINVAL;
3531

3532
                        s = source;
57✔
3533
                        if (s[0] == '-') {
57✔
3534
                                permissive = true;
×
3535
                                s++;
×
3536
                        }
3537

3538
                        if (isempty(destination))
57✔
3539
                                continue;
×
3540

3541
                        for (;;) {
62✔
3542
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
5✔
3543
                                PartitionDesignator partition_designator;
62✔
3544
                                MountOptions *o = NULL;
62✔
3545
                                const char *p;
62✔
3546

3547
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
62✔
3548
                                if (r < 0)
62✔
3549
                                        return r;
3550
                                if (r == 0)
62✔
3551
                                        break;
3552

3553
                                p = tuple;
5✔
3554
                                r = extract_many_words(&p,
5✔
3555
                                                       ":",
3556
                                                       EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3557
                                                       &partition,
3558
                                                       &opts);
3559
                                if (r < 0)
5✔
3560
                                        return r;
3561
                                if (r == 0)
5✔
3562
                                        continue;
×
3563
                                if (r == 1) {
5✔
3564
                                        o = new(MountOptions, 1);
×
3565
                                        if (!o)
×
3566
                                                return log_oom_debug();
×
3567
                                        *o = (MountOptions) {
×
3568
                                                .partition_designator = PARTITION_ROOT,
3569
                                                .options = TAKE_PTR(partition),
×
3570
                                        };
3571
                                        LIST_APPEND(mount_options, options, o);
×
3572

3573
                                        continue;
×
3574
                                }
3575

3576
                                partition_designator = partition_designator_from_string(partition);
5✔
3577
                                if (partition_designator < 0)
5✔
3578
                                        continue;
×
3579

3580
                                o = new(MountOptions, 1);
5✔
3581
                                if (!o)
5✔
3582
                                        return log_oom_debug();
×
3583
                                *o = (MountOptions) {
5✔
3584
                                        .partition_designator = partition_designator,
3585
                                        .options = TAKE_PTR(opts),
5✔
3586
                                };
3587
                                LIST_APPEND(mount_options, options, o);
5✔
3588
                        }
3589

3590
                        r = mount_image_add(&c->mount_images, &c->n_mount_images,
114✔
3591
                                        &(MountImage) {
57✔
3592
                                                .source = s,
3593
                                                .destination = destination,
3594
                                                .mount_options = options,
3595
                                                .ignore_enoent = permissive,
3596
                                                .type = MOUNT_IMAGE_DISCRETE,
3597
                                        });
3598
                        if (r < 0)
57✔
3599
                                return log_oom_debug();
×
3600
                } else if ((val = startswith(l, "exec-context-extension-image="))) {
4,147✔
3601
                        _cleanup_(mount_options_free_allp) MountOptions *options = NULL;
×
3602
                        _cleanup_free_ char *source = NULL;
13✔
3603
                        bool permissive = false;
13✔
3604
                        char *s;
13✔
3605

3606
                        r = extract_first_word(&val,
13✔
3607
                                               &source,
3608
                                               NULL,
3609
                                               EXTRACT_UNQUOTE|EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS);
3610
                        if (r < 0)
13✔
3611
                                return r;
3612
                        if (r == 0)
13✔
3613
                                return -EINVAL;
3614

3615
                        s = source;
13✔
3616
                        if (s[0] == '-') {
13✔
3617
                                permissive = true;
3✔
3618
                                s++;
3✔
3619
                        }
3620

3621
                        for (;;) {
13✔
3622
                                _cleanup_free_ char *tuple = NULL, *partition = NULL, *opts = NULL;
×
3623
                                PartitionDesignator partition_designator;
13✔
3624
                                MountOptions *o = NULL;
13✔
3625
                                const char *p;
13✔
3626

3627
                                r = extract_first_word(&val, &tuple, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
13✔
3628
                                if (r < 0)
13✔
3629
                                        return r;
3630
                                if (r == 0)
13✔
3631
                                        break;
3632

3633
                                p = tuple;
×
3634
                                r = extract_many_words(&p,
×
3635
                                                       ":",
3636
                                                       EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS,
3637
                                                       &partition,
3638
                                                       &opts);
3639
                                if (r < 0)
×
3640
                                        return r;
3641
                                if (r == 0)
×
3642
                                        continue;
×
3643
                                if (r == 1) {
×
3644
                                        o = new(MountOptions, 1);
×
3645
                                        if (!o)
×
3646
                                                return log_oom_debug();
×
3647
                                        *o = (MountOptions) {
×
3648
                                                .partition_designator = PARTITION_ROOT,
3649
                                                .options = TAKE_PTR(partition),
×
3650
                                        };
3651
                                        LIST_APPEND(mount_options, options, o);
×
3652

3653
                                        continue;
×
3654
                                }
3655

3656
                                partition_designator = partition_designator_from_string(partition);
×
3657
                                if (partition_designator < 0)
×
3658
                                        continue;
×
3659

3660
                                o = new(MountOptions, 1);
×
3661
                                if (!o)
×
3662
                                        return log_oom_debug();
×
3663
                                *o = (MountOptions) {
×
3664
                                        .partition_designator = partition_designator,
3665
                                        .options = TAKE_PTR(opts),
×
3666
                                };
3667
                                LIST_APPEND(mount_options, options, o);
×
3668
                        }
3669

3670
                        r = mount_image_add(&c->extension_images, &c->n_extension_images,
26✔
3671
                                        &(MountImage) {
13✔
3672
                                                .source = s,
3673
                                                .mount_options = options,
3674
                                                .ignore_enoent = permissive,
3675
                                                .type = MOUNT_IMAGE_EXTENSION,
3676
                                        });
3677
                        if (r < 0)
13✔
3678
                                return log_oom_debug();
×
3679
                } else if ((val = startswith(l, "exec-context-extension-directories="))) {
4,134✔
3680
                        r = deserialize_strv(val, &c->extension_directories);
8✔
3681
                        if (r < 0)
8✔
3682
                                return r;
3683
                } else if ((val = startswith(l, "exec-context-set-credentials="))) {
4,126✔
3684
                        _cleanup_free_ char *id = NULL, *data = NULL, *encrypted = NULL;
×
3685

3686
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &data, &encrypted);
93✔
3687
                        if (r < 0)
93✔
3688
                                return r;
3689
                        if (r != 3)
93✔
3690
                                return -EINVAL;
3691

3692
                        r = parse_boolean(encrypted);
93✔
3693
                        if (r < 0)
93✔
3694
                                return r;
3695
                        bool e = r;
93✔
3696

3697
                        _cleanup_free_ void *d = NULL;
93✔
3698
                        size_t size;
93✔
3699

3700
                        r = unbase64mem_full(data, SIZE_MAX, /* secure= */ true, &d, &size);
93✔
3701
                        if (r < 0)
93✔
3702
                                return r;
3703

3704
                        r = exec_context_put_set_credential(c, id, TAKE_PTR(d), size, e);
93✔
3705
                        if (r < 0)
93✔
3706
                                return r;
3707
                } else if ((val = startswith(l, "exec-context-load-credentials="))) {
4,033✔
3708
                        _cleanup_free_ char *id = NULL, *path = NULL, *encrypted = NULL;
34✔
3709

3710
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &id, &path, &encrypted);
34✔
3711
                        if (r < 0)
34✔
3712
                                return r;
3713
                        if (r != 3)
34✔
3714
                                return -EINVAL;
3715

3716
                        r = parse_boolean(encrypted);
34✔
3717
                        if (r < 0)
34✔
3718
                                return r;
3719

3720
                        r = exec_context_put_load_credential(c, id, path, r > 0);
34✔
3721
                        if (r < 0)
34✔
3722
                                return r;
3723
                } else if ((val = startswith(l, "exec-context-import-credentials="))) {
3,999✔
3724
                        _cleanup_free_ char *glob = NULL, *rename = NULL;
3,993✔
3725

3726
                        r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &glob, &rename);
3,993✔
3727
                        if (r < 0)
3,993✔
3728
                                return r;
3729
                        if (r == 0)
3,993✔
3730
                                return -EINVAL;
3731

3732
                        r = exec_context_put_import_credential(c, glob, rename);
3,993✔
3733
                        if (r < 0)
3,993✔
3734
                                return r;
3735
                } else if ((val = startswith(l, "exec-context-root-image-policy="))) {
6✔
3736
                        if (c->root_image_policy)
4✔
3737
                                return -EINVAL; /* duplicated */
3738

3739
                        r = image_policy_from_string(val, /* graceful= */ false, &c->root_image_policy);
4✔
3740
                        if (r < 0)
4✔
3741
                                return r;
3742
                } else if ((val = startswith(l, "exec-context-mount-image-policy="))) {
2✔
3743
                        if (c->mount_image_policy)
×
3744
                                return -EINVAL; /* duplicated */
3745

3746
                        r = image_policy_from_string(val, /* graceful= */ false, &c->mount_image_policy);
×
3747
                        if (r < 0)
×
3748
                                return r;
3749
                } else if ((val = startswith(l, "exec-context-extension-image-policy="))) {
2✔
3750
                        if (c->extension_image_policy)
2✔
3751
                                return -EINVAL; /* duplicated */
3752

3753
                        r = image_policy_from_string(val, /* graceful= */ false, &c->extension_image_policy);
2✔
3754
                        if (r < 0)
2✔
3755
                                return r;
3756
                } else
3757
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3758
        }
3759

3760
        return 0;
10,019✔
3761
}
3762

3763
static int exec_command_serialize(const ExecCommand *c, FILE *f) {
2,422✔
3764
        int r;
2,422✔
3765

3766
        assert(c);
2,422✔
3767
        assert(f);
2,422✔
3768

3769
        r = serialize_item(f, "exec-command-path", c->path);
2,422✔
3770
        if (r < 0)
2,422✔
3771
                return r;
3772

3773
        r = serialize_strv(f, "exec-command-argv", c->argv);
2,422✔
3774
        if (r < 0)
2,422✔
3775
                return r;
3776

3777
        r = serialize_item_format(f, "exec-command-flags", "%d", (int) c->flags);
2,422✔
3778
        if (r < 0)
2,422✔
3779
                return r;
3780

3781
        fputc('\n', f); /* End marker */
2,422✔
3782

3783
        return 0;
2,422✔
3784
}
3785

3786
static int exec_command_deserialize(ExecCommand *c, FILE *f) {
10,019✔
3787
        int r;
10,019✔
3788

3789
        assert(c);
10,019✔
3790
        assert(f);
10,019✔
3791

3792
        for (;;) {
108,453✔
3793
                _cleanup_free_ char *l = NULL;
49,217✔
3794
                const char *val;
59,236✔
3795

3796
                r = deserialize_read_line(f, &l);
59,236✔
3797
                if (r < 0)
59,236✔
3798
                        return r;
3799
                if (r == 0) /* eof or end marker */
59,236✔
3800
                        break;
3801

3802
                if ((val = startswith(l, "exec-command-path="))) {
49,217✔
3803
                        r = free_and_strdup(&c->path, val);
10,019✔
3804
                        if (r < 0)
10,019✔
3805
                                return r;
3806
                } else if ((val = startswith(l, "exec-command-argv="))) {
39,198✔
3807
                        r = deserialize_strv(val, &c->argv);
29,179✔
3808
                        if (r < 0)
29,179✔
3809
                                return r;
3810
                } else if ((val = startswith(l, "exec-command-flags="))) {
10,019✔
3811
                        r = safe_atoi(val, &c->flags);
10,019✔
3812
                        if (r < 0)
10,019✔
3813
                                return r;
3814
                } else
3815
                        log_warning("Failed to parse serialized line, ignoring: %s", l);
×
3816

3817
        }
3818

3819
        return 0;
10,019✔
3820
}
3821

3822
int exec_serialize_invocation(
2,422✔
3823
                FILE *f,
3824
                FDSet *fds,
3825
                const ExecContext *ctx,
3826
                const ExecCommand *cmd,
3827
                const ExecParameters *p,
3828
                const ExecRuntime *rt,
3829
                const CGroupContext *cg) {
3830

3831
        int r;
2,422✔
3832

3833
        assert(f);
2,422✔
3834
        assert(fds);
2,422✔
3835

3836
        r = exec_context_serialize(ctx, f);
2,422✔
3837
        if (r < 0)
2,422✔
3838
                return log_debug_errno(r, "Failed to serialize context: %m");
×
3839

3840
        r = exec_command_serialize(cmd, f);
2,422✔
3841
        if (r < 0)
2,422✔
3842
                return log_debug_errno(r, "Failed to serialize command: %m");
×
3843

3844
        r = exec_parameters_serialize(p, ctx, f, fds);
2,422✔
3845
        if (r < 0)
2,422✔
3846
                return log_debug_errno(r, "Failed to serialize parameters: %m");
×
3847

3848
        r = exec_runtime_serialize(rt, f, fds);
2,422✔
3849
        if (r < 0)
2,422✔
3850
                return log_debug_errno(r, "Failed to serialize runtime: %m");
×
3851

3852
        r = exec_cgroup_context_serialize(cg, f);
2,422✔
3853
        if (r < 0)
2,422✔
3854
                return log_debug_errno(r, "Failed to serialize cgroup context: %m");
×
3855

3856
        return 0;
3857
}
3858

3859
int exec_deserialize_invocation(
10,019✔
3860
                FILE *f,
3861
                FDSet *fds,
3862
                ExecContext *ctx,
3863
                ExecCommand *cmd,
3864
                ExecParameters *p,
3865
                ExecRuntime *rt,
3866
                CGroupContext *cg) {
3867

3868
        int r;
10,019✔
3869

3870
        assert(f);
10,019✔
3871
        assert(fds);
10,019✔
3872

3873
        r = exec_context_deserialize(ctx, f);
10,019✔
3874
        if (r < 0)
10,019✔
3875
                return log_debug_errno(r, "Failed to deserialize context: %m");
×
3876

3877
        r = exec_command_deserialize(cmd, f);
10,019✔
3878
        if (r < 0)
10,019✔
3879
                return log_debug_errno(r, "Failed to deserialize command: %m");
×
3880

3881
        r = exec_parameters_deserialize(p, f, fds);
10,019✔
3882
        if (r < 0)
10,019✔
3883
                return log_debug_errno(r, "Failed to deserialize parameters: %m");
×
3884

3885
        r = exec_runtime_deserialize(rt, f, fds);
10,019✔
3886
        if (r < 0)
10,019✔
3887
                return log_debug_errno(r, "Failed to deserialize runtime: %m");
×
3888

3889
        r = exec_cgroup_context_deserialize(cg, f);
10,019✔
3890
        if (r < 0)
10,019✔
3891
                return log_debug_errno(r, "Failed to deserialize cgroup context: %m");
×
3892

3893
        return 0;
3894
}
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