+++ /dev/null
-From: Lennart Poettering <lennart@poettering.net>
-Date: Thu, 17 Dec 2020 16:19:09 +0100
-Subject: test: fix fd_is_mount_point() check
-
-So the currentl and only fd_is_mount_point() check is actually entirely
-bogus: it passes "/" as filename argument, but that's not actually a
-a valid filename, but an absolute path.
-
-fd_is_mount_point() is written in a way tha the fd refers to a directory
-and the specified path is a file directly below it that shall be
-checked. The test call actually violated that rule, but still expected
-success.
-
-Let's fix this, and check for this explicitly, and refuse it.
-
-Let's extend the test and move it to test-mountpoint-util.c where the
-rest of the tests for related calls are placed.
-
-Replaces: #18004
-Fixes: #17950
-(cherry picked from commit 95231c7215c3ff14c491eb1d2a93312a8fe0c4f6)
----
- src/basic/mountpoint-util.c | 28 ++++++++++++++++++++++++++++
- src/test/test-mountpoint-util.c | 32 ++++++++++++++++++++++++++++++++
- src/test/test-path-util.c | 7 -------
- 3 files changed, 60 insertions(+), 7 deletions(-)
-
-diff --git a/src/basic/mountpoint-util.c b/src/basic/mountpoint-util.c
-index 8bed960..a6602ad 100644
---- a/src/basic/mountpoint-util.c
-+++ b/src/basic/mountpoint-util.c
-@@ -132,6 +132,29 @@ static int fd_fdinfo_mnt_id(int fd, const char *filename, int flags, int *ret_mn
- return safe_atoi(p, ret_mnt_id);
- }
-
-+static bool filename_possibly_with_slash_suffix(const char *s) {
-+ const char *slash, *copied;
-+
-+ /* Checks whether the specified string is either file name, or a filename with a suffix of
-+ * slashes. But nothing else.
-+ *
-+ * this is OK: foo, bar, foo/, bar/, foo//, bar///
-+ * this is not OK: "", "/", "/foo", "foo/bar", ".", ".." … */
-+
-+ slash = strchr(s, '/');
-+ if (!slash)
-+ return filename_is_valid(s);
-+
-+ if (slash - s > FILENAME_MAX) /* We want to allocate on the stack below, hence do a size check first */
-+ return false;
-+
-+ if (slash[strspn(slash, "/")] != 0) /* Check that the suffix consist only of one or more slashes */
-+ return false;
-+
-+ copied = strndupa(s, slash - s);
-+ return filename_is_valid(copied);
-+}
-+
- int fd_is_mount_point(int fd, const char *filename, int flags) {
- _cleanup_free_ struct file_handle *h = NULL, *h_parent = NULL;
- int mount_id = -1, mount_id_parent = -1;
-@@ -144,6 +167,11 @@ int fd_is_mount_point(int fd, const char *filename, int flags) {
- assert(filename);
- assert((flags & ~(AT_SYMLINK_FOLLOW|AT_EMPTY_PATH)) == 0);
-
-+ /* Insist that the specified filename is actually a filename, and not a path, i.e. some inode further
-+ * up or down the tree then immediately below the specified directory fd. */
-+ if (!filename_possibly_with_slash_suffix(filename))
-+ return -EINVAL;
-+
- /* First we will try statx()' STATX_ATTR_MOUNT_ROOT attribute, which is our ideal API, available
- * since kernel 5.8.
- *
-diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c
-index 287488b..47fde5c 100644
---- a/src/test/test-mountpoint-util.c
-+++ b/src/test/test-mountpoint-util.c
-@@ -256,6 +256,37 @@ static void test_path_is_mount_point(void) {
- assert_se(rm_rf(tmp_dir, REMOVE_ROOT|REMOVE_PHYSICAL) == 0);
- }
-
-+static void test_fd_is_mount_point(void) {
-+ _cleanup_close_ int fd = -1;
-+
-+ log_info("/* %s */", __func__);
-+
-+ fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY);
-+ assert_se(fd >= 0);
-+
-+ /* Not allowed, since "/" is a path, not a plain filename */
-+ assert_se(fd_is_mount_point(fd, "/", 0) == -EINVAL);
-+ assert_se(fd_is_mount_point(fd, ".", 0) == -EINVAL);
-+ assert_se(fd_is_mount_point(fd, "./", 0) == -EINVAL);
-+ assert_se(fd_is_mount_point(fd, "..", 0) == -EINVAL);
-+ assert_se(fd_is_mount_point(fd, "../", 0) == -EINVAL);
-+ assert_se(fd_is_mount_point(fd, "", 0) == -EINVAL);
-+ assert_se(fd_is_mount_point(fd, "/proc", 0) == -EINVAL);
-+ assert_se(fd_is_mount_point(fd, "/proc/", 0) == -EINVAL);
-+ assert_se(fd_is_mount_point(fd, "proc/sys", 0) == -EINVAL);
-+ assert_se(fd_is_mount_point(fd, "proc/sys/", 0) == -EINVAL);
-+
-+ /* This one definitely is a mount point */
-+ assert_se(fd_is_mount_point(fd, "proc", 0) > 0);
-+ assert_se(fd_is_mount_point(fd, "proc/", 0) > 0);
-+
-+ /* /root's entire raison d'etre is to be on the root file system (i.e. not in /home/ which might be
-+ * split off), so that the user can always log in, so it cannot be a mount point unless the system is
-+ * borked. Let's allow for it to be missing though. */
-+ assert_se(IN_SET(fd_is_mount_point(fd, "root", 0), -ENOENT, 0));
-+ assert_se(IN_SET(fd_is_mount_point(fd, "root/", 0), -ENOENT, 0));
-+}
-+
- int main(int argc, char *argv[]) {
- test_setup_logging(LOG_DEBUG);
-
-@@ -279,6 +310,7 @@ int main(int argc, char *argv[]) {
-
- test_mnt_id();
- test_path_is_mount_point();
-+ test_fd_is_mount_point();
-
- return 0;
- }
-diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
-index f4f8d05..cb91a1a 100644
---- a/src/test/test-path-util.c
-+++ b/src/test/test-path-util.c
-@@ -6,7 +6,6 @@
- #include "alloc-util.h"
- #include "fd-util.h"
- #include "macro.h"
--#include "mountpoint-util.h"
- #include "path-util.h"
- #include "rm-rf.h"
- #include "stat-util.h"
-@@ -40,8 +39,6 @@ static void test_path_simplify(const char *in, const char *out, const char *out_
- }
-
- static void test_path(void) {
-- _cleanup_close_ int fd = -1;
--
- log_info("/* %s */", __func__);
-
- test_path_compare("/goo", "/goo", 0);
-@@ -80,10 +77,6 @@ static void test_path(void) {
- assert_se(streq(basename("/aa///file..."), "file..."));
- assert_se(streq(basename("file.../"), ""));
-
-- fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY);
-- assert_se(fd >= 0);
-- assert_se(fd_is_mount_point(fd, "/", 0) > 0);
--
- test_path_simplify("aaa/bbb////ccc", "aaa/bbb/ccc", "aaa/bbb/ccc");
- test_path_simplify("//aaa/.////ccc", "/aaa/./ccc", "/aaa/ccc");
- test_path_simplify("///", "/", "/");
+++ /dev/null
-From: Christian Ehrhardt <christian.ehrhardt@canonical.com>
-Date: Tue, 15 Dec 2020 12:05:14 +0100
-Subject: test: use modern qemu numa arguments
-
-Upgrading to qemu 5.2 breaks TEST-36-NUMAPOLICY like:
- qemu-system-x86_64: total memory for NUMA nodes (0x0) should
- equal RAM size (0x20000000)
-
-Use the new (as in >=2014) form of memdev in test 36:
- -object memory-backend-ram,id=mem0,size=512M -numa node,memdev=mem0,nodeid=0
-
-Since some target systems are as old as qemu 1.5.3 (CentOS7) but the new
-kind to specify was added in qemu 2.1 this needs to add version parsing and
-add the argument only when qemu is >=5.2.
-
-Fixes #17986.
-
-Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
-(cherry picked from commit 43b49470d1f2808555c07f64cd0a1529b7ddd559)
----
- test/TEST-36-NUMAPOLICY/test.sh | 6 +++++-
- test/test-functions | 18 ++++++++++++++++++
- 2 files changed, 23 insertions(+), 1 deletion(-)
-
-diff --git a/test/TEST-36-NUMAPOLICY/test.sh b/test/TEST-36-NUMAPOLICY/test.sh
-index 02f0135..a08ad6c 100755
---- a/test/TEST-36-NUMAPOLICY/test.sh
-+++ b/test/TEST-36-NUMAPOLICY/test.sh
-@@ -3,7 +3,11 @@ set -e
-
- TEST_DESCRIPTION="test MUMAPolicy= and NUMAMask= options"
- TEST_NO_NSPAWN=1
--QEMU_OPTIONS="-numa node,nodeid=0"
- . $TEST_BASE_DIR/test-functions
-+if qemu_min_version "5.2.0"; then
-+ QEMU_OPTIONS="-object memory-backend-ram,id=mem0,size=512M -numa node,memdev=mem0,nodeid=0"
-+else
-+ QEMU_OPTIONS="-numa node,nodeid=0"
-+fi
-
- do_test "$@" 36
-diff --git a/test/test-functions b/test/test-functions
-index d5da8e0..52b52bf 100644
---- a/test/test-functions
-+++ b/test/test-functions
-@@ -227,6 +227,24 @@ function find_qemu_bin() {
- fi
- }
-
-+# Compares argument #1=X.Y.Z (X&Y&Z = numeric) to the version of the installed qemu
-+# returns 0 if newer or equal
-+# returns 1 if older
-+# returns 2 if failing
-+function qemu_min_version() {
-+ find_qemu_bin || return 2
-+
-+ # get version from binary
-+ qemu_ver=$($QEMU_BIN --version | awk '/^QEMU emulator version ([0-9]*\.[0-9]*\.[0-9]*) / {print $4}')
-+
-+ # Check version string format
-+ echo "$qemu_ver" | grep -q '^[0-9]*\.[0-9]*\.[0-9]*$' || return 2
-+ echo "$1" | grep -q '^[0-9]*\.[0-9]*\.[0-9]*$' || return 2
-+
-+ # compare as last command to return that value
-+ printf "%s\n%s\n" "$1" "$qemu_ver" | sort -V -C
-+}
-+
- # Return 0 if QEMU did run (then you must check the result state/logs for actual
- # success), or 1 if QEMU is not available.
- run_qemu() {