arm-trusted-firmware/tools
Jimmy Brisson 1ed941c0b0 cert-tool: avoid duplicates in extension stack
This bug manifests itself as a segfault triggered by a double-free.

I noticed that right before the double-free, the sk list contained 2
elements with the same address.

    (gdb) p sk_X509_EXTENSION_value(sk, 1)
    $34 = (X509_EXTENSION *) 0x431ad0
    (gdb) p sk_X509_EXTENSION_value(sk, 0)
    $35 = (X509_EXTENSION *) 0x431ad0
    (gdb) p sk_X509_EXTENSION_num(sk)
    $36 = 2

This caused confusion; this should never happen.

I figured that this was caused by a ext_new_xxxx function freeing
something before it is added to the list, so I put a breakpoint on
each of them to step through. I was suprised to find that none of my
breakpoints triggered for the second element of the iteration through
the outer loop just before the double-free.

Looking through the code, I noticed that it's possible to avoid doing
a ext_new_xxxx, when either:
   * ext->type == NVCOUNTER and ext->arg == NULL
   * ext->type == HASH and ext->arg == NULL and ext->optional == false
So I put a breakpoint on both.

It turns out that it was the HASH version, but I added a fix for both.
The fix for the Hash case is simple, as it was a mistake. The fix for
the NVCOUNTER case, however, is a bit more subtle. The NVCOUNTER may
be optional, and when it's optional we can skip it. The other case,
when the NVCOUNTER is required (not optinal), the `check_cmd_params`
function has already verified that the `ext->arg` must be non-NULL.
We assert that before processing it to covert any possible segfaults
into more descriptive errors.

This should no longer cause double-frees by adding the same ext twice.

Change-Id: Idae2a24ecd964b0a3929e6193c7f85ec769f6470
Signed-off-by: Jimmy Brisson <jimmy.brisson@arm.com>
2021-01-27 14:42:43 +00:00
..
amlogic meson: Rename platform directory to amlogic 2019-09-05 10:39:25 +01:00
cert_create cert-tool: avoid duplicates in extension stack 2021-01-27 14:42:43 +00:00
encrypt_fw tools: Set the tool's default binary name 2020-09-07 12:58:24 +01:00
fiptool Update makefile to build fiptool for Windows 2020-09-14 15:06:56 +01:00
marvell/doimage tools: doimage: change the binary image alignment to 16 2020-07-10 10:54:44 +00:00
memory tools: Small improvement to print_memory_map script 2020-02-14 16:31:19 +00:00
renesas/rcar_layout_create rcar_gen3: plat: Add initial D3 support 2019-04-02 03:40:51 +02:00
sptool tools: Set the tool's default binary name 2020-09-07 12:58:24 +01:00
stm32image stm32mp1: update platform files to use MMC devices 2018-10-15 09:36:58 +02:00