diff options
author | Pavel Zhukov <pavel@zhukoff.net> | 2022-02-02 14:57:29 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-02-05 17:46:05 +0000 |
commit | 89ea828861d24b3c446f62a46a5eb38b715742b4 (patch) | |
tree | 681f8fe23ac766be88fc4ac14cdc53b6ee96cb0b | |
parent | 8463a37d70e104b7c23328baf0265f57bdcba12d (diff) | |
download | poky-89ea828861d24b3c446f62a46a5eb38b715742b4.tar.gz |
systemd: allow to create directory whose path contains symlink
Systemd version 250 has a regression which blocks mountd service from
creating subdirectories if path contains symlink. This blocks bind
mounts under /var/run, /lib for example.
Bug-Url: https://github.com/systemd/systemd/issues/22334
(From OE-Core rev: 10f952f4a49ee340f3404df10e9309f90e0c58ab)
Signed-off-by: Pavel Zhukov <pavel.zhukov@huawei.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/recipes-core/systemd/systemd/0001-mkdir-allow-to-create-directory-whose-path-contains-.patch | 130 | ||||
-rw-r--r-- | meta/recipes-core/systemd/systemd_250.3.bb | 1 |
2 files changed, 131 insertions, 0 deletions
diff --git a/meta/recipes-core/systemd/systemd/0001-mkdir-allow-to-create-directory-whose-path-contains-.patch b/meta/recipes-core/systemd/systemd/0001-mkdir-allow-to-create-directory-whose-path-contains-.patch new file mode 100644 index 0000000000..003db430b7 --- /dev/null +++ b/meta/recipes-core/systemd/systemd/0001-mkdir-allow-to-create-directory-whose-path-contains-.patch | |||
@@ -0,0 +1,130 @@ | |||
1 | From b060c53503339c45808efeb4294a03105a2999a5 Mon Sep 17 00:00:00 2001 | ||
2 | From: Yu Watanabe <watanabe.yu+github@gmail.com> | ||
3 | Date: Wed, 2 Feb 2022 14:05:45 +0900 | ||
4 | Subject: [PATCH] mkdir: allow to create directory whose path contains symlink | ||
5 | Cc: pavel@zhukoff.net | ||
6 | |||
7 | Upstream-Status: Backport | ||
8 | Upstream-Url: https://github.com/systemd/systemd/pull/22359 | ||
9 | |||
10 | Signed-off-by: Pavel Zhukov <pavel.zhukov@huawei.com> | ||
11 | |||
12 | |||
13 | core/mount: fail early if directory cannot be created | ||
14 | |||
15 | Prompted by #22334. | ||
16 | |||
17 | mkdir: CHASE_NONEXISTENT cannot used in chase_symlinks_and_stat() | ||
18 | |||
19 | mkdir: allow to create directory whose path contains symlink | ||
20 | |||
21 | Fixes a regression caused by 3008a6f21c1c42efe852d69798a2fdd63fe657ec. | ||
22 | |||
23 | Before the commit, when `mkdir_parents_internal()` is called from `mkdir_p()`, | ||
24 | it uses `_mkdir()` as `flag` is zero. But after the commit, `mkdir_safe_internal()` | ||
25 | is always used. Hence, if the path contains a symlink, it fails with -ENOTDIR. | ||
26 | |||
27 | To fix the issue, this makes `mkdir_p()` calls `mkdir_parents_internal()` with | ||
28 | MKDIR_FOLLOW_SYMLINK flag. | ||
29 | |||
30 | Fixes #22334. | ||
31 | |||
32 | test: add a test for mkdir_p() | ||
33 | --- | ||
34 | src/basic/mkdir.c | 4 ++-- | ||
35 | src/core/mount.c | 4 +++- | ||
36 | src/test/meson.build | 2 ++ | ||
37 | src/test/test-mkdir.c | 30 ++++++++++++++++++++++++++++++ | ||
38 | 4 files changed, 37 insertions(+), 3 deletions(-) | ||
39 | create mode 100644 src/test/test-mkdir.c | ||
40 | |||
41 | diff --git a/src/basic/mkdir.c b/src/basic/mkdir.c | ||
42 | index 6e2b94d024..51a0d74e87 100644 | ||
43 | --- a/src/basic/mkdir.c | ||
44 | +++ b/src/basic/mkdir.c | ||
45 | @@ -42,7 +42,7 @@ int mkdir_safe_internal( | ||
46 | if ((flags & MKDIR_FOLLOW_SYMLINK) && S_ISLNK(st.st_mode)) { | ||
47 | _cleanup_free_ char *p = NULL; | ||
48 | |||
49 | - r = chase_symlinks_and_stat(path, NULL, CHASE_NONEXISTENT, &p, &st, NULL); | ||
50 | + r = chase_symlinks_and_stat(path, NULL, 0, &p, &st, NULL); | ||
51 | if (r < 0) | ||
52 | return r; | ||
53 | if (r == 0) | ||
54 | @@ -162,7 +162,7 @@ int mkdir_p_internal(const char *prefix, const char *path, mode_t mode, uid_t ui | ||
55 | |||
56 | assert(_mkdirat != mkdirat); | ||
57 | |||
58 | - r = mkdir_parents_internal(prefix, path, mode, uid, gid, flags, _mkdirat); | ||
59 | + r = mkdir_parents_internal(prefix, path, mode, uid, gid, flags | MKDIR_FOLLOW_SYMLINK, _mkdirat); | ||
60 | if (r < 0) | ||
61 | return r; | ||
62 | |||
63 | diff --git a/src/core/mount.c b/src/core/mount.c | ||
64 | index 0170406351..c650b5abe2 100644 | ||
65 | --- a/src/core/mount.c | ||
66 | +++ b/src/core/mount.c | ||
67 | @@ -1027,8 +1027,10 @@ static void mount_enter_mounting(Mount *m) { | ||
68 | r = mkdir_p_label(p->what, m->directory_mode); | ||
69 | /* mkdir_p_label() can return -EEXIST if the target path exists and is not a directory - which is | ||
70 | * totally OK, in case the user wants us to overmount a non-directory inode. */ | ||
71 | - if (r < 0 && r != -EEXIST) | ||
72 | + if (r < 0 && r != -EEXIST) { | ||
73 | log_unit_error_errno(UNIT(m), r, "Failed to make bind mount source '%s': %m", p->what); | ||
74 | + goto fail; | ||
75 | + } | ||
76 | } | ||
77 | |||
78 | if (p) { | ||
79 | diff --git a/src/test/meson.build b/src/test/meson.build | ||
80 | index 9a1c481f22..7aa1d9c6ea 100644 | ||
81 | --- a/src/test/meson.build | ||
82 | +++ b/src/test/meson.build | ||
83 | @@ -193,6 +193,8 @@ tests += [ | ||
84 | |||
85 | [['src/test/test-macro.c']], | ||
86 | |||
87 | + [['src/test/test-mkdir.c']], | ||
88 | + | ||
89 | [['src/test/test-json.c']], | ||
90 | |||
91 | [['src/test/test-modhex.c']], | ||
92 | diff --git a/src/test/test-mkdir.c b/src/test/test-mkdir.c | ||
93 | new file mode 100644 | ||
94 | index 0000000000..c715d5f096 | ||
95 | --- /dev/null | ||
96 | +++ b/src/test/test-mkdir.c | ||
97 | @@ -0,0 +1,30 @@ | ||
98 | +/* SPDX-License-Identifier: LGPL-2.1-or-later */ | ||
99 | + | ||
100 | +#include <unistd.h> | ||
101 | + | ||
102 | +#include "mkdir.h" | ||
103 | +#include "path-util.h" | ||
104 | +#include "rm-rf.h" | ||
105 | +#include "tests.h" | ||
106 | +#include "tmpfile-util.h" | ||
107 | + | ||
108 | +TEST(mkdir_p) { | ||
109 | + _cleanup_(rm_rf_physical_and_freep) char *tmp = NULL; | ||
110 | + _cleanup_free_ char *p = NULL; | ||
111 | + | ||
112 | + assert_se(mkdtemp_malloc("/tmp/test-mkdir-XXXXXX", &tmp) >= 0); | ||
113 | + | ||
114 | + assert_se(p = path_join(tmp, "run")); | ||
115 | + assert_se(mkdir_p(p, 0755) >= 0); | ||
116 | + | ||
117 | + p = mfree(p); | ||
118 | + assert_se(p = path_join(tmp, "var/run")); | ||
119 | + assert_se(mkdir_parents(p, 0755) >= 0); | ||
120 | + assert_se(symlink("../run", p) >= 0); | ||
121 | + | ||
122 | + p = mfree(p); | ||
123 | + assert_se(p = path_join(tmp, "var/run/hoge/foo/baz")); | ||
124 | + assert_se(mkdir_p(p, 0755) >= 0); | ||
125 | +} | ||
126 | + | ||
127 | +DEFINE_TEST_MAIN(LOG_DEBUG); | ||
128 | -- | ||
129 | 2.34.1 | ||
130 | |||
diff --git a/meta/recipes-core/systemd/systemd_250.3.bb b/meta/recipes-core/systemd/systemd_250.3.bb index de16a4d78d..57987218a1 100644 --- a/meta/recipes-core/systemd/systemd_250.3.bb +++ b/meta/recipes-core/systemd/systemd_250.3.bb | |||
@@ -25,6 +25,7 @@ SRC_URI += "file://touchscreen.rules \ | |||
25 | file://0003-implment-systemd-sysv-install-for-OE.patch \ | 25 | file://0003-implment-systemd-sysv-install-for-OE.patch \ |
26 | file://0001-systemd.pc.in-use-ROOTPREFIX-without-suffixed-slash.patch \ | 26 | file://0001-systemd.pc.in-use-ROOTPREFIX-without-suffixed-slash.patch \ |
27 | file://0001-test-parse-argument-Include-signal.h.patch \ | 27 | file://0001-test-parse-argument-Include-signal.h.patch \ |
28 | file://0001-mkdir-allow-to-create-directory-whose-path-contains-.patch \ | ||
28 | " | 29 | " |
29 | 30 | ||
30 | # patches needed by musl | 31 | # patches needed by musl |