From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E174142BC54 for ; Fri, 14 Aug 2026 07:59:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786694368; cv=none; b=aCy2KxrHAXSbFcYxl9Jk0MbcsBgjgYTaYMvX/83k+G2eghucWaihM8uv/TRjjx7+MchWenVQYGrQreWfnD4gE3DHajpt4vKaBmd7x1cU5EAIA85euMBOik266iLDqd1GXwkUFaIMb978KXVGqHp8O8nERflKh6GSfM7MmaQVQe8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786694368; c=relaxed/simple; bh=YFZXXCTx4SOuXXY6Oz21P4RKwwP6/R0X0JZtRJSh9b8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ROb9TqF+FUT9HPzDO8vBMzDk1GoVzgaHUyeAwlrDyoE3N6WVB4GUm75PF3ZfWy7T8Yef79UTYv5Clhp6RlV8CH8h5f7NHZDEP+9Q60mlAEr0QknBaeRe7e6exB9KGF1uHdttNVQ2PhWL7jxq4VXDov4MsgSUwn3AWt4h/b6jB00= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=D5jQtuy4; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Qt0hc1Uv; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="D5jQtuy4"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Qt0hc1Uv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786694366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F8O34Xc16ur4O9EtunTdCdf0boIbkU6LPLycJBfuzuA=; b=D5jQtuy4DYOMGRfn1+VPYGyg4R25wmqw9YX72MhiFbWLzpEPbwYakq64BH6E++pI9JyI+4 evRwShKRjPqqMmgJyz3wVkf3U5YbRoCOenj8xy75pNJM2a9yYYnt0/Dzi+k7hJEb4rzqWu Pj4MPo0iLkO2ROrVOXj/o8KZB56NiVc= Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-93-xtNV6FvCM868rNRrXbhp4Q-1; Fri, 14 Aug 2026 03:59:24 -0400 X-MC-Unique: xtNV6FvCM868rNRrXbhp4Q-1 X-Mimecast-MFC-AGG-ID: xtNV6FvCM868rNRrXbhp4Q_1786694363 Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-84eee2147ffso785608b3a.0 for ; Fri, 14 Aug 2026 00:59:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1786694363; x=1787299163; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=F8O34Xc16ur4O9EtunTdCdf0boIbkU6LPLycJBfuzuA=; b=Qt0hc1UvBK6lKH6eI1dGJ1NevMgCMx7egsELuWAmyYVoq0JGgP7voxFJXyD4/kdMKq Z4Saqtv34qhz7659MpWeYLNZMnmgYpgkGmtC6a7FiHyACCpu75QGsLv0uHkLyAjLrW2+ fYcVHXYWT6LCXUb2+L/cHFk3OjQfUU/CQtLOMZzc1NMB4xwNBh72q9SQ9b1TwCc03R7L DezwJpVQMRHacMsnRO6e9A0u+fjJO82Ahbmlg1A1lJF3Br0jMlGyHfIFme9p1XthhltG ZFJyk8wjpU9f/bYXa1xLxpKXZkU+njSuD1D0t+lORMO0DXUUB9dnFBpIVn3004LZ2D7K w8bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786694363; x=1787299163; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=F8O34Xc16ur4O9EtunTdCdf0boIbkU6LPLycJBfuzuA=; b=kAoLcUONiUZYfKiEmk+p6S9s9WWtqmj/e9B6kHf+avh29MT4giSsiNZ6isSI99y/87 hadRdOvsdoWsrzOK0ZOjciD+T1QrJv2eDDWV7wkgkOif7Nly/3Q/zaoVLtkMUVOEl8cX r/NRmYm91/BhG2+Wtk/IeVraGmePwjXYrNzxLZPZqw8DDqIFbZYrUV/u43/WXYu6Z2vg ixYLYwZ9W94SCZWHGJ3cnMVxIbKrioactua2KVrLdmx6QSZuLV8TlF5tD5o2PwyurwAw uYuKiassSOuuqMfCE7jbNRAcgGMHS6laf6+IdyUYKnCZkKOPlzeCr8qpusK6TQPjsPzr Kl8w== X-Forwarded-Encrypted: i=1; AHgh+Rris06u9HMF48lFS5X653n9q0cgaPzcywztD56bBjuZMlPEdzLvqkKW/zb7eBcfHotaZPT1eQrRIKXD69M=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4O5W6yYes9FU7UhAHopNRmNSmZMz7MIJtpZuScpJjphh9KbBP SOExP5sWdiYIJ6Hxyz3R68544akm1SrxS/YEyV2Oe2jZh3sXJHH1Sa/mltwTuNwEcWoxeILVaQ5 SXoWo6zWSfy527lsnFjgmx0E1tzz0q9c83ZX4lZjbMV+tfrs2DDT4YLs8KgE2p5n0Yg== X-Gm-Gg: AR+sD11jQn0PBvJ7jDfymPCreSG/JnMpzT+n6Oa6KU6hn+QAYkTVA92x4EDmQoGPUb2 L22dJehga3yyYo80oc97+f27VqS0tzalyM7/At+LTHJfaTH152aororW6Dcz5Ex98bW1SgqgF9C iJqAb8VkbWpIhL6x0Q37b3TiYM5j0EY0GSmgccJ/FbBxeIa6ySOk2XO9e6shvAo+YH8T8HE8fdS plceDM19kLR7WN2mti/JrPprOc4leg4xVVSdfy9i/3KIy1TiW/gMQ0cFy+u598xr++wzJgwdKle CA758tFureisgY1zOmaDTDKn5Nv/SV7f4u70j00KkAKaQbzMOuPvc5/jwsMZfQzw8Ifq0A20wip +aqn6Y/RjUlBJtKX6Zw== X-Received: by 2002:a05:6a00:2d98:b0:84a:646f:193 with SMTP id d2e1a72fcca58-84fdde42b9bmr3951023b3a.0.1786694363315; Fri, 14 Aug 2026 00:59:23 -0700 (PDT) X-Received: by 2002:a05:6a00:2d98:b0:84a:646f:193 with SMTP id d2e1a72fcca58-84fdde42b9bmr3950974b3a.0.1786694362810; Fri, 14 Aug 2026 00:59:22 -0700 (PDT) Received: from [192.168.1.2] ([122.171.16.134]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8517d249b26sm121142b3a.43.2026.08.14.00.59.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 14 Aug 2026 00:59:22 -0700 (PDT) Message-ID: <81cb568c-e65f-4359-9c6f-f994f910f2f1@redhat.com> Date: Fri, 14 Aug 2026 13:29:15 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] kexec: return -ENOEXEC from image probe functions on mismatch To: Philipp Rudo Cc: Catalin Marinas , Will Deacon , Mark Rutland , Huacai Chen , WANG Xuerui , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Andrew Morton , Baoquan He , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Tao Liu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, kexec@lists.infradead.org References: <20260813-mpilaniy-v1-1-777d4d0e30f7@redhat.com> <20260813151350.6b511155@rotkaeppchen> Content-Language: en-US From: Mukesh Pilaniya In-Reply-To: <20260813151350.6b511155@rotkaeppchen> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Philipp, On 13/08/26 6:43 pm, Philipp Rudo wrote: > Hi Mukesh, > > the patch looks good to me. > > There is also a corresponding kexec-tools patch, which was accidentally > opened as a Github PR (https://github.com/horms/kexec-tools/pull/12). > It will be sent to kexec@lists.infradead.org shortly. > > Thanks > > Reviewed-by: Philipp Rudo > The kexec-tools patch has now been posted to the mailing list. It can be found here: https://lore.kernel.org/all/20260814075329.30203-1-mpilaniy@redhat.com/ > On Thu, 13 Aug 2026 12:36:29 +0530 > Mukesh Pilaniya 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 >> --- >> branch: next-20260812 >> base commit: 28d012efb4327f9c75d5e042a7c91e9a542efa98 >> --- >> 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; >> >> --- >> base-commit: 28d012efb4327f9c75d5e042a7c91e9a542efa98 >> change-id: 20260813-mpilaniy-ffb0cc92c313 >> >> Best regards, >> -- >> Mukesh Pilaniya >> >