Skip to content

Commit a061312

Browse files
committed
kernel-install: Avoid reopening file descriptor via /proc
kernel-install used to work without /proc mounted before the rewrite in C. Let's restore that property by making sure we don't reopen file descriptors via /proc. In this case, parse_env_file_fdv() calls fdopen_independent() to get a FILE * for the given file descriptor (which itself calls fd_reopen()). Let's avoid the call to fdopen_independent() by using chase_and_fopenat_unlocked() which gives us a FILE * immediately without having to reopen any file descriptors.
1 parent 7f92564 commit a061312

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/kernel-install/kernel-install.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static int context_ensure_conf_root(Context *c) {
340340
}
341341

342342
static int context_load_install_conf_one(Context *c, const char *path) {
343-
_cleanup_close_ int fd = -EBADF;
343+
_cleanup_fclose_ FILE *f = NULL;
344344
_cleanup_free_ char
345345
*conf = NULL, *machine_id = NULL, *boot_root = NULL, *layout = NULL,
346346
*initrd_generator = NULL, *uki_generator = NULL;
@@ -353,20 +353,20 @@ static int context_load_install_conf_one(Context *c, const char *path) {
353353
if (!conf)
354354
return log_oom();
355355

356-
r = chaseat(c->rfd, conf, CHASE_AT_RESOLVE_IN_ROOT, NULL, &fd);
356+
r = chase_and_fopenat_unlocked(c->rfd, conf, CHASE_AT_RESOLVE_IN_ROOT, "re", NULL, &f);
357357
if (r == -ENOENT)
358358
return 0;
359359
if (r < 0)
360360
return log_error_errno(r, "Failed to chase %s: %m", conf);
361361

362362
log_debug("Loading %s…", conf);
363363

364-
r = parse_env_file_fd(fd, conf,
365-
"MACHINE_ID", &machine_id,
366-
"BOOT_ROOT", &boot_root,
367-
"layout", &layout,
368-
"initrd_generator", &initrd_generator,
369-
"uki_generator", &uki_generator);
364+
r = parse_env_file(f, conf,
365+
"MACHINE_ID", &machine_id,
366+
"BOOT_ROOT", &boot_root,
367+
"layout", &layout,
368+
"initrd_generator", &initrd_generator,
369+
"uki_generator", &uki_generator);
370370
if (r < 0)
371371
return log_error_errno(r, "Failed to parse '%s': %m", conf);
372372

@@ -401,7 +401,7 @@ static int context_load_install_conf(Context *c) {
401401
}
402402

403403
static int context_load_machine_info(Context *c) {
404-
_cleanup_close_ int fd = -EBADF;
404+
_cleanup_fclose_ FILE *f = NULL;
405405
_cleanup_free_ char *machine_id = NULL, *layout = NULL;
406406
static const char *path = "/etc/machine-info";
407407
int r;
@@ -423,17 +423,17 @@ static int context_load_machine_info(Context *c) {
423423
return 0;
424424
}
425425

426-
r = chaseat(c->rfd, path, CHASE_AT_RESOLVE_IN_ROOT, NULL, &fd);
426+
r = chase_and_fopenat_unlocked(c->rfd, path, CHASE_AT_RESOLVE_IN_ROOT, "re", NULL, &f);
427427
if (r == -ENOENT)
428428
return 0;
429429
if (r < 0)
430430
return log_error_errno(r, "Failed to chase %s: %m", path);
431431

432432
log_debug("Loading %s…", path);
433433

434-
r = parse_env_file_fd(fd, path,
435-
"KERNEL_INSTALL_MACHINE_ID", &machine_id,
436-
"KERNEL_INSTALL_LAYOUT", &layout);
434+
r = parse_env_file(f, path,
435+
"KERNEL_INSTALL_MACHINE_ID", &machine_id,
436+
"KERNEL_INSTALL_LAYOUT", &layout);
437437
if (r < 0)
438438
return log_error_errno(r, "Failed to parse '%s': %m", path);
439439

0 commit comments

Comments
 (0)