From c67a977731f07dfb8b4c29fcc5ee9e4cb0e32eda Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Mon, 10 Feb 2020 19:58:25 +0100 Subject: [PATCH 1/5] lkl tools: fix cpfromfs relative path handling utimensat() needs a valid directory fd if the pathname is relative. Use AT_FDCWD to ensure that relative paths are correctly handled. Signed-off-by: David Disseldorp --- tools/lkl/cptofs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/lkl/cptofs.c b/tools/lkl/cptofs.c index 38d2e1fd5b5255..8bb4b522d0afbe 100644 --- a/tools/lkl/cptofs.c +++ b/tools/lkl/cptofs.c @@ -413,7 +413,7 @@ static int do_entry(const char *_src, const char *_dst, const char *name) if (cptofs) { struct lkl_timespec lkl_ts[] = { atime, mtime }; - ret = lkl_sys_utimensat(-1, dst, + ret = lkl_sys_utimensat(LKL_AT_FDCWD, dst, (struct __lkl__kernel_timespec *)lkl_ts, LKL_AT_SYMLINK_NOFOLLOW); @@ -423,7 +423,7 @@ static int do_entry(const char *_src, const char *_dst, const char *name) { .tv_sec = mtime.tv_sec, .tv_nsec = mtime.tv_nsec, }, }; - ret = utimensat(-1, dst, ts, AT_SYMLINK_NOFOLLOW); + ret = utimensat(AT_FDCWD, dst, ts, AT_SYMLINK_NOFOLLOW); } } From 643a7ff50af66f1e6b2b25982bb3aea24c687132 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Wed, 13 Sep 2023 00:27:56 +0200 Subject: [PATCH 2/5] lkl: allow some Makefile install paths to be overridden Some distributions require libraries in e.g. /usr/lib64, so add support for overriding common install paths via LIBDIR, BINDIR and INCDIR. Signed-off-by: David Disseldorp --- tools/lkl/Makefile | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/lkl/Makefile b/tools/lkl/Makefile index a62b31b5b557f8..777f97e8aefabe 100644 --- a/tools/lkl/Makefile +++ b/tools/lkl/Makefile @@ -13,7 +13,10 @@ ifneq ($(silent),1) endif endif -PREFIX := /usr +PREFIX := /usr +BINDIR := $(PREFIX)/bin +INCDIR := $(PREFIX)/include +LIBDIR := $(PREFIX)/lib ifeq (,$(srctree)) srctree := $(patsubst %/,%,$(dir $(shell pwd))) @@ -119,20 +122,20 @@ clean-conf: clean headers_install: $(TARGETS) $(call QUIET_INSTALL, headers) \ - install -d $(DESTDIR)$(PREFIX)/include ; \ + install -d $(DESTDIR)$(INCDIR) ; \ install -m 644 include/lkl.h include/lkl_host.h $(OUTPUT)include/lkl_autoconf.h \ - include/lkl_config.h $(DESTDIR)$(PREFIX)/include ; \ - cp -r $(OUTPUT)include/lkl $(DESTDIR)$(PREFIX)/include + include/lkl_config.h $(DESTDIR)$(INCDIR) ; \ + cp -r $(OUTPUT)include/lkl $(DESTDIR)$(INCDIR) libraries_install: $(libs-y:%=$(OUTPUT)%$(SOSUF)) $(OUTPUT)liblkl.a $(call QUIET_INSTALL, libraries) \ - install -d $(DESTDIR)$(PREFIX)/lib ; \ - install -m 644 $^ $(DESTDIR)$(PREFIX)/lib + install -d $(DESTDIR)$(LIBDIR) ; \ + install -m 644 $^ $(DESTDIR)$(LIBDIR) programs_install: $(progs-y:%=$(OUTPUT)%$(EXESUF)) $(call QUIET_INSTALL, programs) \ - install -d $(DESTDIR)$(PREFIX)/bin ; \ - install -m 755 $^ $(DESTDIR)$(PREFIX)/bin + install -d $(DESTDIR)$(BINDIR) ; \ + install -m 755 $^ $(DESTDIR)$(BINDIR) install: headers_install libraries_install programs_install From c3fcefd7fee145b39dad1cdf52672cf578ce6f52 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Thu, 14 Sep 2023 14:01:15 +0200 Subject: [PATCH 3/5] lkl/fs2tar: cleanup ARGP_KEY_END handling The current handler unintentionally returns ARGP_ERROR_UNKNOWN for the non-error case (via case fallthrough). As per argp.h, this error return gets ignored, so doesn't cause any problems: What to return for unrecognized keys. For special ARGP_KEY_ keys, such returns will simply be ignored. Still worth fixing for the compiler warnings. Signed-off-by: David Disseldorp --- tools/lkl/fs2tar.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/lkl/fs2tar.c b/tools/lkl/fs2tar.c index 30dd8f30856da8..432f28808f0cc6 100644 --- a/tools/lkl/fs2tar.c +++ b/tools/lkl/fs2tar.c @@ -70,6 +70,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) case ARGP_KEY_END: if (state->arg_num < 2 || !cla->fsimg_type) argp_usage(state); + break; default: return ARGP_ERR_UNKNOWN; } From 3171b5635913da9a9df446a4c860630d01db3afa Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Fri, 15 Sep 2023 23:38:10 +0200 Subject: [PATCH 4/5] lkl: Mark the stack non-executable to fix a binutils warning As per commit bd71558d585a ("arch: um: Mark the stack non-executable to fix a binutils warning"): Since binutils 2.39, ld will print a warning if any stack section is executable, which is the default for stack sections on files without a .note.GNU-stack section. Signed-off-by: David Disseldorp --- tools/lkl/Makefile.autoconf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/lkl/Makefile.autoconf b/tools/lkl/Makefile.autoconf index a15753193a4f6e..311163d12dc47f 100644 --- a/tools/lkl/Makefile.autoconf +++ b/tools/lkl/Makefile.autoconf @@ -55,6 +55,7 @@ define virtio_net_dpdk CFLAGS += -I$$(RTE_SDK)/$$(RTE_TARGET)/include -msse4.2 -mpopcnt LDFLAGS +=-L$$(RTE_SDK)/$$(RTE_TARGET)/lib LDFLAGS +=-Wl,--whole-archive $$(DPDK_LIBS) -Wl,--no-whole-archive -lm -ldl + LDFLAGS +=-z noexecstack endef define virtio_net_vde @@ -72,7 +73,7 @@ define posix_host $(call set_autoconf_var,VIRTIO_NET,y) $(call set_autoconf_var,VIRTIO_NET_FD,y) $(if $(strip $(call find_include,linux/vfio.h)),$(call set_autoconf_var,VFIO_PCI,y)) - LDFLAGS += -pie + LDFLAGS += -pie -z noexecstack CFLAGS += -fPIC -pthread SOSUF := .so $(if $(call is_defined,__ANDROID__),$(call android_host),LDLIBS += -lrt -lpthread) From d3a47cfb720d180ecc269cee62d5d0941e067f14 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Fri, 8 Sep 2023 22:51:36 +0200 Subject: [PATCH 5/5] lkl/tests: add disk parameters check to avoid segfaulting Check for disk (image) and fstype parameters, to avoid segfaulting immediately. Failure to open the image or invalid fstype will still result in segfault. Signed-off-by: David Disseldorp --- tools/lkl/tests/disk.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/lkl/tests/disk.c b/tools/lkl/tests/disk.c index ed99d698da05ac..57e30ca8de7e03 100644 --- a/tools/lkl/tests/disk.c +++ b/tools/lkl/tests/disk.c @@ -126,7 +126,7 @@ static int lkl_test_opendir(void) dir = lkl_opendir(mnt_point, &err); - lkl_test_logf("lkl_opedir(%s) = %d %s\n", mnt_point, err, + lkl_test_logf("lkl_opendir(%s) = %d %s\n", mnt_point, err, lkl_strerror(err)); if (err == 0) @@ -182,6 +182,11 @@ int main(int argc, const char **argv) if (parse_args(argc, argv, args) < 0) return -1; + if (!cla.disk || !cla.fstype) { + fprintf(stderr, "disk and type parameters required.\n"); + return -1; + } + lkl_host_ops.print = lkl_test_log; lkl_init(&lkl_host_ops);