From: Pingfan Liu <piliu@redhat.com>
To: kexec@lists.infradead.org
Cc: Pingfan Liu <piliu@redhat.com>, Simon Horman <horms@kernel.org>,
Philipp Rudo <prudo@redhat.com>
Subject: [PATCH 2/3] kexec: Create a temporary file to hold .linux section in uki_probe()
Date: Tue, 5 Nov 2024 11:57:06 +0800 [thread overview]
Message-ID: <20241105035710.11384-3-piliu@redhat.com> (raw)
In-Reply-To: <20241105035710.11384-1-piliu@redhat.com>
**Problem**
In the arm64 case, a temporary file for kernel is created in
pez_arm64_probe() and passed down to info.kernel_fd later.
However in the x86_64 case, nobody passes a temporary fd to info.kernel_fd,
so finally the fd of the UKI image is passed to syscall. That is not the
expected behavior.
**Situation**
The current framework of kexec-tools passes kernel fd to syscall.
Meanwhile info.kernel_fd presents each probe with an opportunity to
overwhelm the existing kernel fd.
**Solution**
In the UKI probe, a temporary file is created to hold the .linux
section. Later, if no other probe methods set info.kernel_fd, it will be
set in the UKI load method. This way, the correct fd can be passed to
the syscall.
Signed-off-by: Pingfan Liu <piliu@redhat.com>
Cc: Simon Horman <horms@kernel.org>
To: kexec@lists.infradead.org
---
kexec/arch/arm64/kexec-vmlinuz-arm64.c | 2 ++
kexec/kexec-uki.c | 14 ++++++++++++++
2 files changed, 16 insertions(+)
diff --git a/kexec/arch/arm64/kexec-vmlinuz-arm64.c b/kexec/arch/arm64/kexec-vmlinuz-arm64.c
index e291a34..e558296 100644
--- a/kexec/arch/arm64/kexec-vmlinuz-arm64.c
+++ b/kexec/arch/arm64/kexec-vmlinuz-arm64.c
@@ -104,6 +104,8 @@ int pez_arm64_load(int argc, char **argv, const char *buf, off_t len,
off_t nread;
int fd;
+ if (info->kernel_fd > 0)
+ close(info->kernel_fd);
info->kernel_fd = kernel_fd;
fd = dup(kernel_fd);
if (fd < 0) {
diff --git a/kexec/kexec-uki.c b/kexec/kexec-uki.c
index 8a7d349..235f5a1 100644
--- a/kexec/kexec-uki.c
+++ b/kexec/kexec-uki.c
@@ -15,8 +15,10 @@
#define UKI_DTB_SECTION ".dtb"
#define FILENAME_UKI_INITRD "/tmp/InitrdXXXXXX"
+#define FILENAME_UKI_KERNEL "/tmp/KernelXXXXXX"
static int embeded_linux_format_index = -1;
+static int kernel_fd = -1;
/*
* Return -1 if not PE, else offset of the PE header
@@ -98,6 +100,15 @@ int uki_image_probe(const char *file_buf, off_t buf_sz)
if (linux_sz == -1) {
printf("ERR: can not find .linux section\n");
return -1;
+ } else {
+ int res;
+
+ res = create_tmpfd(FILENAME_UKI_KERNEL, linux_src, linux_sz,
+ &kernel_fd);
+ if (res < 0) {
+ printf("ERR: can not create tmp file to hold .linux section\n");
+ return -1;
+ }
}
/*
* After stripping the UKI coat, the real kernel format can be handled now.
@@ -120,6 +131,9 @@ int uki_image_probe(const char *file_buf, off_t buf_sz)
int uki_image_load(int argc, char **argv, const char *buf, off_t len,
struct kexec_info *info)
{
+ /* In probe() chain, if nobody sets info->kernel_fd, set it now */
+ if (info->kernel_fd == -1)
+ info->kernel_fd = kernel_fd;
return file_type[embeded_linux_format_index].load(argc, argv, buf, len, info);
}
--
2.41.0
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
next prev parent reply other threads:[~2024-11-05 3:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 3:57 [PATCH 0/3] Enable UKI image load on x86_64 Pingfan Liu
2024-11-05 3:57 ` [PATCH 1/3] UKI: Split out the routine to create temporary fd Pingfan Liu
2024-11-05 3:57 ` Pingfan Liu [this message]
2024-11-05 3:57 ` [PATCH 3/3] x86_64: Support UKI image format Pingfan Liu
2024-11-22 2:12 ` [PATCH 0/3] Enable UKI image load on x86_64 Dave Young
2024-12-02 13:06 ` Simon Horman
2024-12-02 13:34 ` Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241105035710.11384-3-piliu@redhat.com \
--to=piliu@redhat.com \
--cc=horms@kernel.org \
--cc=kexec@lists.infradead.org \
--cc=prudo@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox