binfmt: check if binfmt is mounted before applying rules

This commit is contained in:
Yu Watanabe
2022-12-15 03:36:27 +09:00
parent 5aaa79ce96
commit 94ba5b1532
3 changed files with 24 additions and 3 deletions
+22 -2
View File
@@ -190,6 +190,18 @@ static int parse_argv(int argc, char *argv[]) {
return 1;
}
static int binfmt_mounted_warn(void) {
int r;
r = binfmt_mounted();
if (r < 0)
return log_error_errno(r, "Failed to check if /proc/sys/fs/binfmt_misc is mounted: %m");
if (r == 0)
log_debug("/proc/sys/fs/binfmt_misc is not mounted in read-write mode, skipping.");
return r;
}
static int run(int argc, char *argv[]) {
int r, k;
@@ -206,13 +218,17 @@ static int run(int argc, char *argv[]) {
if (arg_unregister)
return disable_binfmt();
if (argc > optind)
if (argc > optind) {
r = binfmt_mounted_warn();
if (r <= 0)
return r;
for (int i = optind; i < argc; i++) {
k = apply_file(argv[i], false);
if (k < 0 && r >= 0)
r = k;
}
else {
} else {
_cleanup_strv_free_ char **files = NULL;
r = conf_files_list_strv(&files, ".conf", NULL, 0, (const char**) CONF_PATHS_STRV("binfmt.d"));
@@ -225,6 +241,10 @@ static int run(int argc, char *argv[]) {
return cat_files(NULL, files, 0);
}
r = binfmt_mounted_warn();
if (r <= 0)
return r;
/* Flush out all rules */
r = write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", WRITE_STRING_FILE_DISABLE_BUFFER);
if (r < 0)
+1 -1
View File
@@ -12,7 +12,7 @@
#include "missing_magic.h"
#include "stat-util.h"
static int binfmt_mounted(void) {
int binfmt_mounted(void) {
_cleanup_close_ int fd = -EBADF;
int r;
+1
View File
@@ -1,4 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
int binfmt_mounted(void);
int disable_binfmt(void);