From: kernel test robot <lkp@intel.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: oe-kbuild-all@lists.linux.dev
Subject: [ardb:efi-zboot-elf 21/22] drivers/firmware/efi/libstub/zboot.c:78:16: warning: cast to pointer from integer of different size
Date: Thu, 26 Nov 2026 05:43:35 +0100 [thread overview]
Message-ID: <20261126054123.bwonqnCJ-lkp@intel.com> (raw)
tree: https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git efi-zboot-elf
head: ee915eebcaa3ed159fd8a2e4d07cc33e348a6531
commit: 71668402cb4161b23740dc1f8a88d286e8917665 [21/22] efi/zboot: Add support for ELF payloads
config: loongarch-randconfig-r2300-20261126 (https://download.01.org/0day-ci/archive/20261126/20261126054123.bwonqnCJ-lkp@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 16.2.0
sparse: v0.6.5-rc1-21-g84ec0658
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261126/20261126054123.bwonqnCJ-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261126054123.bwonqnCJ-lkp@intel.com/
All warnings (new ones prefixed by >>):
drivers/firmware/efi/libstub/zboot.c: In function 'zboot_prepare_elf':
>> drivers/firmware/efi/libstub/zboot.c:78:16: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
78 | phdr = (const Elf64_Phdr *)(*head_buf + ehdr->e_phoff);
| ^
sparse warnings: (new ones prefixed by >>)
command-line: note: in included file:
builtin:1:9: sparse: sparse: preprocessor token __STDC_HOSTED__ redefined
builtin:0:0: sparse: this was the original definition
>> drivers/firmware/efi/libstub/zboot.c:78:49: sparse: sparse: non size-preserving integer to pointer cast
vim +78 drivers/firmware/efi/libstub/zboot.c
12
13 static efi_status_t zboot_prepare_elf(unsigned long body_size,
14 unsigned long *head_buf,
15 unsigned long *head_size,
16 unsigned long *tail_size,
17 unsigned long *image_size,
18 unsigned long *elf_align)
19 {
20 unsigned long head_clen = _gzdata_start - _elfdata_start;
21 unsigned long tail_clen = _elfdata_end - _gzdata_end;
22 const Elf64_Phdr *phdr, *load = NULL;
23 const Elf64_Ehdr *ehdr;
24 unsigned long total;
25 efi_status_t status;
26
27 if (!IS_ENABLED(CONFIG_EFI_ZBOOT_ELF)) {
28 *image_size = body_size;
29 *head_buf = *head_size = *tail_size = *elf_align = 0;
30 return EFI_SUCCESS;
31 }
32
33 status = efi_zboot_decompress_size(_elfdata_start, head_clen,
34 head_size);
35 if (status != EFI_SUCCESS)
36 return status;
37
38 if (*head_size < sizeof(Elf64_Ehdr))
39 return EFI_LOAD_ERROR;
40
41 status = efi_zboot_decompress_size(_gzdata_end, tail_clen,
42 tail_size);
43 if (status != EFI_SUCCESS)
44 return status;
45
46 if (check_add_overflow(*head_size, body_size, &total) ||
47 check_add_overflow(total, *tail_size, &total))
48 return EFI_LOAD_ERROR;
49
50 status = efi_allocate_pages(*head_size, head_buf, ULONG_MAX);
51 if (status != EFI_SUCCESS)
52 return status;
53
54 status = efi_zboot_decompress(_elfdata_start, head_clen,
55 (u8 *)*head_buf, *head_size);
56 if (status != EFI_SUCCESS)
57 goto err;
58
59 ehdr = (const Elf64_Ehdr *)*head_buf;
60 if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0 ||
61 ehdr->e_ident[EI_CLASS] != ELF_CLASS ||
62 ehdr->e_ident[EI_DATA] != ELF_DATA ||
63 ehdr->e_machine != ELF_ARCH) {
64 efi_err("Payload is not an ELF image for this architecture\n");
65 status = EFI_LOAD_ERROR;
66 goto err;
67 }
68
69 if (ehdr->e_phentsize != sizeof(Elf64_Phdr) ||
70 ehdr->e_phnum == 0 ||
71 ehdr->e_phoff > *head_size ||
72 ehdr->e_phnum > (*head_size - ehdr->e_phoff) / sizeof(Elf64_Phdr)) {
73 efi_err("Unexpected ELF header layout\n");
74 status = EFI_LOAD_ERROR;
75 goto err;
76 }
77
> 78 phdr = (const Elf64_Phdr *)(*head_buf + ehdr->e_phoff);
79 for (int i = 0; i < ehdr->e_phnum; i++) {
80 if (phdr[i].p_type != PT_LOAD)
81 continue;
82 if (load) {
83 efi_err("Multiple ELF PT_LOAD segments not supported\n");
84 status = EFI_LOAD_ERROR;
85 goto err;
86 }
87 load = &phdr[i];
88 }
89
90 if (!load || load->p_offset != *head_size ||
91 load->p_filesz != body_size ||
92 load->p_filesz > load->p_memsz ||
93 (load->p_align > 1 && !is_power_of_2(load->p_align))) {
94 efi_err("Invalid ELF PT_LOAD header\n");
95 status = EFI_LOAD_ERROR;
96 goto err;
97 }
98
99 efi_info("ELF zboot payload detected\n");
100
101 *image_size = load->p_memsz;
102 *elf_align = load->p_align;
103 return EFI_SUCCESS;
104 err:
105 efi_free(*head_size, *head_buf);
106 return status;
107 }
108
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
reply other threads:[~2026-11-26 4:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261126054123.bwonqnCJ-lkp@intel.com \
--to=lkp@intel.com \
--cc=ardb@kernel.org \
--cc=oe-kbuild-all@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.