Skip to contentSkip to conversation

Unreachable code in mkimagexx (Fwd: New Defects reported by Coverity Scan for GRUB)

DISCUSSION Andrei Borzenkov 2 participants 3 messages Mar 13, 2016 – Jan 24, 2017 1 message 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]

#1 lore raw

We probably need to #ifdef this section for MKIMAGE_ELF64 case only, it makes no sense to compile it for 32 bit target.

________________________________________________________________________________________________________
*** CID 158599: (DEADCODE)
/util/grub-mkimagexx.c: 1317 in translate_relocation_pe()
1311 break;
1312 }
1313 break;
1314 case EM_AARCH64:
1315 switch (ELF_R_TYPE (info))
1316 {

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 257U:".

1317     	case R_AARCH64_ABS64:
1318     	  {
1319     	    ctx->current_address
1320     	      = add_fixup_entry (&ctx->lst,
1321     				 GRUB_PE32_REL_BASED_DIR64,
1322     				 addr, 0, ctx->current_address,
/util/grub-mkimagexx.c: 1331 in translate_relocation_pe()
1325     	  break;
1326     	  /* Relative relocations do not require fixup entries. */
1327     	case R_AARCH64_CALL26:
1328     	case R_AARCH64_JUMP26:
1329     	  break;
1330     	  /* Page-relative relocations do not require fixup entries. */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 275U:".

1331     	case R_AARCH64_ADR_PREL_PG_HI21:
1332     	  /* We page-align the whole kernel, so no need
1333     	     for fixup entries.
1334     	  */
1335     	case R_AARCH64_ADD_ABS_LO12_NC:
1336     	case R_AARCH64_LDST64_ABS_LO12_NC:
/util/grub-mkimagexx.c: 1335 in translate_relocation_pe()
1329     	  break;
1330     	  /* Page-relative relocations do not require fixup entries. */
1331     	case R_AARCH64_ADR_PREL_PG_HI21:
1332     	  /* We page-align the whole kernel, so no need
1333     	     for fixup entries.
1334     	  */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 277U:".

1335     	case R_AARCH64_ADD_ABS_LO12_NC:
1336     	case R_AARCH64_LDST64_ABS_LO12_NC:
1337     	  break;

1338
1339 default:
1340 grub_util_error (_("relocation 0x%x is not implemented yet"),
/util/grub-mkimagexx.c: 1328 in translate_relocation_pe()

1322     				 addr, 0, ctx->current_address,
1323     				 image_target);
1324     	  }
1325     	  break;
1326     	  /* Relative relocations do not require fixup entries. */
1327     	case R_AARCH64_CALL26:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 282U:".

1328     	case R_AARCH64_JUMP26:
1329     	  break;
1330     	  /* Page-relative relocations do not require fixup entries. */
1331     	case R_AARCH64_ADR_PREL_PG_HI21:
1332     	  /* We page-align the whole kernel, so no need
1333     	     for fixup entries.
/util/grub-mkimagexx.c: 1327 in translate_relocation_pe()
1321     				 GRUB_PE32_REL_BASED_DIR64,
1322     				 addr, 0, ctx->current_address,
1323     				 image_target);
1324     	  }
1325     	  break;
1326     	  /* Relative relocations do not require fixup entries. */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 283U:".

1327     	case R_AARCH64_CALL26:
1328     	case R_AARCH64_JUMP26:
1329     	  break;
1330     	  /* Page-relative relocations do not require fixup entries. */
1331     	case R_AARCH64_ADR_PREL_PG_HI21:
1332     	  /* We page-align the whole kernel, so no need
/util/grub-mkimagexx.c: 1336 in translate_relocation_pe()
1330     	  /* Page-relative relocations do not require fixup entries. */
1331     	case R_AARCH64_ADR_PREL_PG_HI21:
1332     	  /* We page-align the whole kernel, so no need
1333     	     for fixup entries.
1334     	  */
1335     	case R_AARCH64_ADD_ABS_LO12_NC:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 286U:".

1336 case R_AARCH64_LDST64_ABS_LO12_NC:
1337 break;
1338

1339     	default:
1340     	  grub_util_error (_("relocation 0x%x is not implemented yet"),
1341     			   (unsigned int) ELF_R_TYPE (info));
#2 lore raw
Quoted 4 lines · Andrei Borzenkov

We probably need to #ifdef this section for MKIMAGE_ELF64 case only, it makes no sense to compile it for 32 bit target.

Hmm ... why translate_relocation_pe, translate_relocation_raw and classify_raw_reloc are not target size specific in the first place? They take Elf_Addr parameters so cannot work for both 32 and 64 bit targets at the same time.

Quoted 94 lines

________________________________________________________________________________________________________
*** CID 158599: (DEADCODE)
/util/grub-mkimagexx.c: 1317 in translate_relocation_pe()
1311 break;
1312 }
1313 break;
1314 case EM_AARCH64:
1315 switch (ELF_R_TYPE (info))
1316 {

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 257U:".

1317 case R_AARCH64_ABS64:
1318 {
1319 ctx->current_address
1320 = add_fixup_entry (&ctx->lst,
1321 GRUB_PE32_REL_BASED_DIR64,
1322 addr, 0, ctx->current_address,
/util/grub-mkimagexx.c: 1331 in translate_relocation_pe()
1325 break;
1326 /* Relative relocations do not require fixup entries. */
1327 case R_AARCH64_CALL26:
1328 case R_AARCH64_JUMP26:
1329 break;
1330 /* Page-relative relocations do not require fixup entries. */

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 275U:".

1331 case R_AARCH64_ADR_PREL_PG_HI21:
1332 /* We page-align the whole kernel, so no need
1333 for fixup entries.
1334 */
1335 case R_AARCH64_ADD_ABS_LO12_NC:
1336 case R_AARCH64_LDST64_ABS_LO12_NC:
/util/grub-mkimagexx.c: 1335 in translate_relocation_pe()
1329 break;
1330 /* Page-relative relocations do not require fixup entries. */
1331 case R_AARCH64_ADR_PREL_PG_HI21:
1332 /* We page-align the whole kernel, so no need
1333 for fixup entries.
1334 */

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 277U:".

1335 case R_AARCH64_ADD_ABS_LO12_NC:
1336 case R_AARCH64_LDST64_ABS_LO12_NC:
1337 break;
1338
1339 default:
1340 grub_util_error (_("relocation 0x%x is not implemented yet"),
/util/grub-mkimagexx.c: 1328 in translate_relocation_pe()
1322 addr, 0, ctx->current_address,
1323 image_target);

1324              }
1325              break;
1326              /* Relative relocations do not require fixup entries. */

1327 case R_AARCH64_CALL26:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 282U:".

1328 case R_AARCH64_JUMP26:
1329 break;
1330 /* Page-relative relocations do not require fixup entries. */
1331 case R_AARCH64_ADR_PREL_PG_HI21:
1332 /* We page-align the whole kernel, so no need
1333 for fixup entries.
/util/grub-mkimagexx.c: 1327 in translate_relocation_pe()

1321                                     GRUB_PE32_REL_BASED_DIR64,
1322                                     addr, 0, ctx->current_address,
1323                                     image_target);
1324              }
1325              break;
1326              /* Relative relocations do not require fixup entries. */
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 283U:".

1327 case R_AARCH64_CALL26:
1328 case R_AARCH64_JUMP26:
1329 break;
1330 /* Page-relative relocations do not require fixup entries. */
1331 case R_AARCH64_ADR_PREL_PG_HI21:
1332 /* We page-align the whole kernel, so no need
/util/grub-mkimagexx.c: 1336 in translate_relocation_pe()
1330 /* Page-relative relocations do not require fixup entries. */
1331 case R_AARCH64_ADR_PREL_PG_HI21:
1332 /* We page-align the whole kernel, so no need
1333 for fixup entries.
1334 */
1335 case R_AARCH64_ADD_ABS_LO12_NC:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 286U:".

1336 case R_AARCH64_LDST64_ABS_LO12_NC:
1337 break;
1338
1339 default:
1340 grub_util_error (_("relocation 0x%x is not implemented yet"),
1341 (unsigned int) ELF_R_TYPE (info));

#3 lore raw

They're used only for arm (32-bit). So they don't need to work for 64-bit.

Quoted 126 lines · On Mon, 14 Mar 2016, 10:01 Andrei Borzenkov <[email protected]> wrote:
Quoted 4 lines · Andrei Borzenkov

We probably need to #ifdef this section for MKIMAGE_ELF64 case only, it makes no sense to compile it for 32 bit target.

Hmm ... why translate_relocation_pe, translate_relocation_raw and classify_raw_reloc are not target size specific in the first place? They take Elf_Addr parameters so cannot work for both 32 and 64 bit targets at the same time.

Quoted 1 line

________________________________________________________________________________________________________

Quoted 10 lines

*** CID 158599: (DEADCODE)
/util/grub-mkimagexx.c: 1317 in translate_relocation_pe()
1311 break;
1312 }
1313 break;
1314 case EM_AARCH64:
1315 switch (ELF_R_TYPE (info))
1316 {

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 257U:".

Quoted 9 lines

1317 case R_AARCH64_ABS64:
1318 {
1319 ctx->current_address
1320 = add_fixup_entry (&ctx->lst,
1321 GRUB_PE32_REL_BASED_DIR64,
1322 addr, 0, ctx->current_address,
/util/grub-mkimagexx.c: 1331 in translate_relocation_pe()
1325 break;
1326 /* Relative relocations do not require fixup entries.

*/

Quoted 4 lines

1327 case R_AARCH64_CALL26:
1328 case R_AARCH64_JUMP26:
1329 break;
1330 /* Page-relative relocations do not require fixup

entries. */

Quoted 11 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 275U:".

1331 case R_AARCH64_ADR_PREL_PG_HI21:
1332 /* We page-align the whole kernel, so no need
1333 for fixup entries.
1334 */
1335 case R_AARCH64_ADD_ABS_LO12_NC:
1336 case R_AARCH64_LDST64_ABS_LO12_NC:
/util/grub-mkimagexx.c: 1335 in translate_relocation_pe()
1329 break;
1330 /* Page-relative relocations do not require fixup

entries. */

Quoted 4 lines

1331 case R_AARCH64_ADR_PREL_PG_HI21:
1332 /* We page-align the whole kernel, so no need
1333 for fixup entries.
1334 */

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 277U:".

1335 case R_AARCH64_ADD_ABS_LO12_NC:
1336 case R_AARCH64_LDST64_ABS_LO12_NC:
1337 break;
1338
1339 default:
1340 grub_util_error (_("relocation 0x%x is not implemented

yet"),

Quoted 6 lines

/util/grub-mkimagexx.c: 1328 in translate_relocation_pe()
1322 addr, 0, ctx->current_address,
1323 image_target);

1324              }
1325              break;
1326              /* Relative relocations do not require fixup entries.

*/

Quoted 6 lines

1327 case R_AARCH64_CALL26:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 282U:".

1328 case R_AARCH64_JUMP26:
1329 break;
1330 /* Page-relative relocations do not require fixup

entries. */

Quoted 10 lines

1331 case R_AARCH64_ADR_PREL_PG_HI21:
1332 /* We page-align the whole kernel, so no need
1333 for fixup entries.
/util/grub-mkimagexx.c: 1327 in translate_relocation_pe()

1321                                     GRUB_PE32_REL_BASED_DIR64,
1322                                     addr, 0, ctx->current_address,
1323                                     image_target);
1324              }
1325              break;
1326              /* Relative relocations do not require fixup entries.

*/

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 283U:".

1327 case R_AARCH64_CALL26:
1328 case R_AARCH64_JUMP26:
1329 break;
1330 /* Page-relative relocations do not require fixup

entries. */

Quoted 4 lines

1331 case R_AARCH64_ADR_PREL_PG_HI21:
1332 /* We page-align the whole kernel, so no need
/util/grub-mkimagexx.c: 1336 in translate_relocation_pe()
1330 /* Page-relative relocations do not require fixup

entries. */

Quoted 5 lines

1331 case R_AARCH64_ADR_PREL_PG_HI21:
1332 /* We page-align the whole kernel, so no need
1333 for fixup entries.
1334 */
1335 case R_AARCH64_ADD_ABS_LO12_NC:

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 158599: (DEADCODE)
Execution cannot reach this statement: "case 286U:".

1336 case R_AARCH64_LDST64_ABS_LO12_NC:
1337 break;
1338
1339 default:
1340 grub_util_error (_("relocation 0x%x is not implemented

yet"),

Quoted 3 lines

1341 (unsigned int) ELF_R_TYPE (info));

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel