Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bradley Morgan <include@grrlz.net>
To: mpilaniy@redhat.com
Cc: akpm@linux-foundation.org, alex@ghiti.fr, aou@eecs.berkeley.edu,
	baoquan.he@linux.dev, catalin.marinas@arm.com,
	chenhuacai@kernel.org, kernel@xen0n.name,
	kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
	loongarch@lists.linux.dev, ltao@redhat.com, mark.rutland@arm.com,
	palmer@dabbelt.com, pasha.tatashin@soleen.com, pjw@kernel.org,
	pratyush@kernel.org, prudo@redhat.com, rppt@kernel.org,
	will@kernel.org
Subject: Re: [PATCH v2 1/2] kexec: return -ENOEXEC from image probe functions on mismatch
Date: Wed, 19 Aug 2026 19:33:13 +0100	[thread overview]
Message-ID: <B5D12BAE-2701-46EC-8458-3716F856703D@grrlz.net> (raw)
In-Reply-To: <20260819-mpilaniy-v2-1-95e929ede0e5@redhat.com>

On 19 August 2026 18:47:22 BST, Mukesh Pilaniya <mpilaniy@redhat.com>
wrote:
>Several kexec_file_load() image probe functions return -EINVAL when
>they do not recognize the image format.  A probe function that rejects
>an image should return -ENOEXEC to indicate that the image is not a
>recognized executable format.  -EINVAL implies a problem with the
>syscall parameters, not with image recognition.
>
>kexec_image_probe_default() iterates through registered loaders and
>returns the last probe's error code to the caller.  That error
>propagates as the kexec_file_load() return value to userspace.
>Returning -EINVAL from a probe when no loader matches is semantically
>incorrect and misleads userspace about the nature of the failure.
>
>Return -ENOEXEC from all probe functions and their helpers when the
>image format is not recognized.
>
>Signed-off-by: Mukesh Pilaniya <mpilaniy@redhat.com>
>Reviewed-by: Philipp Rudo <prudo@redhat.com>
>Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Reviewed-by: Bradley Morgan <include@grrlz.net>

>---
> arch/arm64/kernel/kexec_image.c   | 4 ++--
> arch/loongarch/kernel/kexec_efi.c | 4 ++--
> arch/riscv/kernel/kexec_image.c   | 4 ++--
> kernel/kexec_elf.c                | 4 ++--
> 4 files changed, 8 insertions(+), 8 deletions(-)
>
>diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
>index b70f4df15a1a..101259874d44 100644
>--- a/arch/arm64/kernel/kexec_image.c
>+++ b/arch/arm64/kernel/kexec_image.c
>@@ -25,10 +25,10 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len)
> 		(const struct arm64_image_header *)(kernel_buf);
> 
> 	if (!h || (kernel_len < sizeof(*h)))
>-		return -EINVAL;
>+		return -ENOEXEC;
> 
> 	if (memcmp(&h->magic, ARM64_IMAGE_MAGIC, sizeof(h->magic)))
>-		return -EINVAL;
>+		return -ENOEXEC;
> 
> 	return 0;
> }
>diff --git a/arch/loongarch/kernel/kexec_efi.c b/arch/loongarch/kernel/kexec_efi.c
>index 5ee78ebb1546..28a1d0420ba3 100644
>--- a/arch/loongarch/kernel/kexec_efi.c
>+++ b/arch/loongarch/kernel/kexec_efi.c
>@@ -24,12 +24,12 @@ static int efi_kexec_probe(const char *kernel_buf, unsigned long kernel_len)
> 
> 	if (!h || (kernel_len < sizeof(*h))) {
> 		kexec_dprintk("No LoongArch image header.\n");
>-		return -EINVAL;
>+		return -ENOEXEC;
> 	}
> 
> 	if (!loongarch_header_check_dos_sig(h)) {
> 		kexec_dprintk("No LoongArch PE image header.\n");
>-		return -EINVAL;
>+		return -ENOEXEC;
> 	}
> 
> 	return 0;
>diff --git a/arch/riscv/kernel/kexec_image.c b/arch/riscv/kernel/kexec_image.c
>index 51dc89259f16..963a25f5b55b 100644
>--- a/arch/riscv/kernel/kexec_image.c
>+++ b/arch/riscv/kernel/kexec_image.c
>@@ -20,7 +20,7 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len)
> 	const struct riscv_image_header *h = (const struct riscv_image_header *)kernel_buf;
> 
> 	if (!h || kernel_len < sizeof(*h))
>-		return -EINVAL;
>+		return -ENOEXEC;
> 
> 	/* According to Documentation/arch/riscv/boot-image-header.rst,
> 	 * use "magic2" field to check when version >= 0.2.
>@@ -28,7 +28,7 @@ static int image_probe(const char *kernel_buf, unsigned long kernel_len)
> 
> 	if (h->version >= RISCV_HEADER_VERSION &&
> 	    memcmp(&h->magic2, RISCV_IMAGE_MAGIC2, sizeof(h->magic2)))
>-		return -EINVAL;
>+		return -ENOEXEC;
> 
> 	return 0;
> }
>diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c
>index 3a5c25b2adc9..89a444a00693 100644
>--- a/kernel/kexec_elf.c
>+++ b/kernel/kexec_elf.c
>@@ -172,7 +172,7 @@ static int elf_read_ehdr(const char *buf, size_t len, struct elfhdr *ehdr)
> 
> 	default:
> 		pr_debug("Unknown ELF class.\n");
>-		return -EINVAL;
>+		return -ENOEXEC;
> 	}
> 
> 	return elf_is_ehdr_sane(ehdr, len) ? 0 : -ENOEXEC;
>@@ -236,7 +236,7 @@ static int elf_read_phdr(const char *buf, size_t len,
> 
> 	default:
> 		pr_debug("Unknown ELF class.\n");
>-		return -EINVAL;
>+		return -ENOEXEC;
> 	}
> 
> 	return elf_is_phdr_sane(phdr, len) ? 0 : -ENOEXEC;
>
>

Thanks!


  reply	other threads:[~2026-08-19 18:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19 17:47 [PATCH v2 0/2] kexec: fix probe error codes and error propagation Mukesh Pilaniya
2026-08-19 17:47 ` [PATCH v2 1/2] kexec: return -ENOEXEC from image probe functions on mismatch Mukesh Pilaniya
2026-08-19 18:33   ` Bradley Morgan [this message]
2026-08-19 17:47 ` [PATCH v2 2/2] kexec: fix error propagation in kexec_image_probe_default() Mukesh Pilaniya
2026-08-20 12:21   ` Philipp Rudo
2026-08-20 18:11     ` Pratyush Yadav
2026-08-21  7:18       ` Mukesh Pilaniya
2026-08-21  8:08         ` Mike Rapoport
2026-08-21 13:22           ` Mukesh Pilaniya
2026-08-21  8:40       ` Philipp Rudo
2026-08-20 18:08   ` Pratyush Yadav

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=B5D12BAE-2701-46EC-8458-3716F856703D@grrlz.net \
    --to=include@grrlz.net \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=baoquan.he@linux.dev \
    --cc=catalin.marinas@arm.com \
    --cc=chenhuacai@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=kexec@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=loongarch@lists.linux.dev \
    --cc=ltao@redhat.com \
    --cc=mark.rutland@arm.com \
    --cc=mpilaniy@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=pjw@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=prudo@redhat.com \
    --cc=rppt@kernel.org \
    --cc=will@kernel.org \
    /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