Skip to contentSkip to conversation

efi_loader: image_loader - Coverity Scan errors

DISCUSSION Heinrich Schuchardt 1 participant 1 message Apr 29, 2020 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CA+M6bXn205qcBA2B9upeo6MAR--qar7h1hzGYWuJgCYaGHH4OQ@mail.gmail.com

#2 lore raw

Hello Takahiro,

this relates to your patch

4540dabdcaca
efi_loader: image_loader: support image authentication

Quoted 27 lines · Tom Rini

Can you please look in to these, thanks!

---------- Forwarded message ---------
From: <[email protected]>
Date: Tue, Apr 28, 2020 at 4:12 PM
Subject: New Defects reported by Coverity Scan for Das U-Boot
To: <[email protected]>

Hi,

Please find the latest report on new defect(s) introduced to Das U-Boot found with Coverity Scan.

12 new defect(s) introduced to Das U-Boot found with Coverity Scan.

New defect(s) Reported-by: Coverity Scan
Showing 12 of 12 defect(s)

** CID 300339: (ARRAY_VS_SINGLETON)
/lib/efi_loader/efi_image_loader.c: 299 in efi_image_parse() /lib/efi_loader/efi_image_loader.c: 294 in efi_image_parse() /lib/efi_loader/efi_image_loader.c: 315 in efi_image_parse()

Quoted 6 lines

________________________________________________________________________________________________________
*** CID 300339: (ARRAY_VS_SINGLETON)
/lib/efi_loader/efi_image_loader.c: 299 in efi_image_parse()
293 if (nt64->OptionalHeader.NumberOfRvaAndSizes <= ctidx) {
294 efi_image_region_add(regs,
295 &opt->CheckSum + 1,

+1 is not adding the size of CheckSum to the address but the size of IMAGE_OPTIONAL_HEADER64. This cannot be correct.

Quoted 8 lines

296 efi +
opt->SizeOfHeaders, 0);
297 } else {
298 /* Skip Certificates Table */

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
    CID 300339:    (ARRAY_VS_SINGLETON)
    Using "&opt->CheckSum" as an array.  This might corrupt or misinterpret adjacent memory locations.

299 efi_image_region_add(regs,
300 &opt->CheckSum + 1,

Same here

Quoted 5 lines

301
&opt->DataDirectory[ctidx], 0);
302 efi_image_region_add(regs,
303
&opt->DataDirectory[ctidx] + 1,

Same here

Quoted 26 lines

304 efi +
opt->SizeOfHeaders, 0); /lib/efi_loader/efi_image_loader.c: 294 in efi_image_parse()
288 IMAGE_NT_HEADERS64 *nt64 = (void *)nt;
289 IMAGE_OPTIONAL_HEADER64 *opt = &nt64->OptionalHeader;
290

291                     /* Skip CheckSum */
292                     efi_image_region_add(regs, efi, &opt->CheckSum, 0);
293                     if (nt64->OptionalHeader.NumberOfRvaAndSizes <= ctidx) {
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
    CID 300339:    (ARRAY_VS_SINGLETON)
    Using "&opt->CheckSum" as an array.  This might corrupt or misinterpret adjacent memory locations.

294 efi_image_region_add(regs,
295 &opt->CheckSum + 1,
296 efi +
opt->SizeOfHeaders, 0);
297 } else {
298 /* Skip Certificates Table */
299 efi_image_region_add(regs,
/lib/efi_loader/efi_image_loader.c: 315 in efi_image_parse()
309 authoff = opt->DataDirectory[ctidx].VirtualAddress;
310 authsz = opt->DataDirectory[ctidx].Size;
311 } else if (nt->OptionalHeader.Magic ==
IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
312 IMAGE_OPTIONAL_HEADER32 *opt = &nt->OptionalHeader;
313
314 efi_image_region_add(regs, efi, &opt->CheckSum, 0);

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
    CID 300339:    (ARRAY_VS_SINGLETON)
    Using "&opt->CheckSum" as an array.  This might corrupt or misinterpret adjacent memory locations.

315 efi_image_region_add(regs, &opt->CheckSum + 1,

Same here

Quoted 7 lines

316 &opt->DataDirectory[ctidx], 0);
317 efi_image_region_add(regs,
&opt->DataDirectory[ctidx] + 1,
318 efi + opt->SizeOfHeaders, 0);
319
320 bytes_hashed = opt->SizeOfHeaders;

Please, check the coding and provide a patch.

Best regards

Heinrich