Skip to content

Commit e8c1ff9

Browse files
committed
rimage: propagate verification result to the exit code
Verify mode logged signature failures and a missing header but returned success, so callers using the exit code as a gate would accept a tampered image. Return an error when no header is found and propagate the verification result. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent ef41cc1 commit e8c1ff9

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

tools/rimage/src/manifest.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1682,17 +1682,35 @@ int verify_image(struct image *image)
16821682
/* find CSE header marker "$CPD" */
16831683
if (*(uint32_t *)(buffer + i) == CSE_HEADER_MAKER) {
16841684
image->fw_image = buffer + i;
1685+
/* size of the image from the CSE header to the end of the
1686+
* file, used by v1.5 verification and the signed-payload
1687+
* bounds checks
1688+
*/
1689+
image->image_end = size - i;
16851690
ret = image->adsp->verify_firmware(image);
1691+
/* verify_firmware() returns 1 = valid, 0 = invalid and
1692+
* < 0 = error (OpenSSL RSA_verify semantics); map valid
1693+
* to 0 and invalid to -EINVAL, and leave a < 0 error code
1694+
* as-is, so the CLI exit code reflects the result
1695+
*/
1696+
if (ret == 1)
1697+
ret = 0;
1698+
else if (ret == 0)
1699+
ret = -EINVAL;
16861700
goto out;
16871701
}
16881702
}
16891703

16901704
/* no header found */
16911705
fprintf(stderr, "error: could not find valid CSE header $CPD in %s\n",
16921706
image->verify_file);
1707+
ret = -EINVAL;
16931708
out:
16941709
fclose(in_file);
1695-
return 0;
1710+
/* propagate verification result so callers (and the exit code) can
1711+
* detect a failed/missing verification instead of always seeing success
1712+
*/
1713+
return ret;
16961714
}
16971715

16981716

0 commit comments

Comments
 (0)