summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-12-10 03:42:50 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-12-14 19:36:27 +0100
commit94ba5b15329d9d19277ca418bfd0266da98f7b2a (patch)
tree7519b1d3970afd0b0badfb8343435151630b0037
parentbinfmt-util: also check if binfmt is mounted in read-write (diff)
downloadsystemd-94ba5b15329d9d19277ca418bfd0266da98f7b2a.tar.xz
systemd-94ba5b15329d9d19277ca418bfd0266da98f7b2a.zip
binfmt: check if binfmt is mounted before applying rules
-rw-r--r--src/binfmt/binfmt.c24
-rw-r--r--src/shared/binfmt-util.c2
-rw-r--r--src/shared/binfmt-util.h1
3 files changed, 24 insertions, 3 deletions
diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c
index ba209a8d47..624c63ec98 100644
--- a/src/binfmt/binfmt.c
+++ b/src/binfmt/binfmt.c
@@ -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)
diff --git a/src/shared/binfmt-util.c b/src/shared/binfmt-util.c
index 51fc245c01..a26175474b 100644
--- a/src/shared/binfmt-util.c
+++ b/src/shared/binfmt-util.c
@@ -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;
diff --git a/src/shared/binfmt-util.h b/src/shared/binfmt-util.h
index 2f008d12ff..13f4548b7c 100644
--- a/src/shared/binfmt-util.h
+++ b/src/shared/binfmt-util.h
@@ -1,4 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
+int binfmt_mounted(void);
int disable_binfmt(void);