summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorSam Protsenko <semen.protsenko@linaro.org>2024-06-19 16:23:30 -0500
committerTom Rini <trini@konsulko.com>2024-06-26 13:17:51 -0600
commit04c63f134cf268532f6e499aa2edb4f6f45ecefb (patch)
treefbe4ca7ad12928e17e6c5cad254fba40b2d89912 /cmd
parentb85ecb276bee4ef828852e75e9932638b48042dd (diff)
downloadu-boot-04c63f134cf268532f6e499aa2edb4f6f45ecefb.tar.gz
u-boot-04c63f134cf268532f6e499aa2edb4f6f45ecefb.tar.bz2
u-boot-04c63f134cf268532f6e499aa2edb4f6f45ecefb.zip
cmd: gpt: Fix freeing gpt_pte in gpt_verify()
In case when either gpt_verify_headers() or gpt_verify_partitions() fails, the memory allocated for gpt_pte will be freed in those functions internally, but gpt_pte will still contain non-NULL dangling pointer. The attempt to free it in those cases in gpt_verify() leads to "use after free" error, which leads to a "Synchronous abort" exception. This issue was found by running the next command on the device with incorrect partition table: => gpt verify mmc 0 $partitions which results to: No partition list provided - only basic check "Synchronous Abort" handler, esr 0x96000021, far 0xba247bff .... Fix the issue by only freeing gpt_pte if none of those functions failed. Fixes: bbb9ffac6066 ("gpt: command: Extend gpt command to support GPT table verification") Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gpt.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/cmd/gpt.c b/cmd/gpt.c
index 36b112d597..aeabd19dd7 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -682,7 +682,8 @@ static int gpt_verify(struct blk_desc *blk_dev_desc, const char *str_part)
free(str_disk_guid);
free(partitions);
out:
- free(gpt_pte);
+ if (!ret)
+ free(gpt_pte);
return ret;
}