int max_regions;
char path[200];
int count;
+ int len;
+ uint32_t size;
debug("%s: fdt=%p, conf='%s', sig='%s'\n", __func__, key_blob,
fit_get_name(fit, noffset, NULL),
}
/* Add the strings */
- strings = fdt_getprop(fit, noffset, "hashed-strings", NULL);
+ strings = fdt_getprop(fit, noffset, "hashed-strings", &len);
if (strings) {
+ if (len < (int)(2 * sizeof(fdt32_t))) {
+ *err_msgp = "Invalid hashed-strings property";
+ return -1;
+ }
+ size = fdt32_to_cpu(strings[1]);
+ /*
+ * The offset should be already validated by fdt_check_header();
+ * validate the size here.
+ */
+ if (size > fdt_size_dt_strings(fit)) {
+ *err_msgp = "Strings region is out of bounds";
+ return -1;
+ }
/*
* The strings region offset must be a static 0x0.
* This is set in tool/image-host.c
*/
fdt_regions[count].offset = fdt_off_dt_strings(fit);
- fdt_regions[count].size = fdt32_to_cpu(strings[1]);
+ fdt_regions[count].size = size;
count++;
}
ubman, [fit_check_sign, '-f', fit, '-k', dtb],
1, 'Failed to verify required signature')
+ # Create a new properly signed fit and replace hashed-strings
+ # size property
+ make_fit('sign-configs-%s%s.its' % (sha_algo, padding), ubman, mkimage, dtc_args, datadir, fit)
+ sign_fit(sha_algo, sign_options)
+ utils.run_and_log(ubman, 'fdtput -t x %s %s hashed-strings 0' %
+ (fit, sig_node))
+ run_bootm(sha_algo, 'Signed config with truncated hashed-strings',
+ 'Invalid hashed-strings property', False)
+ ubman.log.action('%s: Check truncated hashed-strings property' % sha_algo)
+
+ # size_dt_strings is at offset 32 in the FDT header
+ with open(fit, 'rb') as handle:
+ handle.seek(32)
+ size_dt_strings = struct.unpack(">I", handle.read(4))[0]
+ utils.run_and_log(ubman, 'fdtput -t x %s %s hashed-strings 0 %#x' %
+ (fit, sig_node, size_dt_strings + 1))
+ run_bootm(sha_algo, 'Signed config with overflowed hashed-strings size',
+ 'Strings region is out of bounds', False)
+ ubman.log.action('%s: Check overflowed hashed-strings size' % sha_algo)
+
+ utils.run_and_log(ubman, 'fdtput -t x %s %s hashed-strings 0 %#x' %
+ (fit, sig_node, size_dt_strings))
+ run_bootm(sha_algo, 'Signed config with in-bounds hashed-strings size',
+ 'Bad Data Hash', False)
+ ubman.log.action('%s: Check in-bounds hashed-strings size' % sha_algo)
+
def test_required_key(sha_algo, padding, sign_options):
"""Test verified boot with the given hash algorithm.