From: Markus Armbruster <armbru@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Cc: pburton@wavecomp.com, aleksandar.rikalo@rt-rk.com, qemu-devel@nongnu.org
Subject: Re: [PATCH v6] hw/core/loader-fit: fix freeing errp in fit_load_fdt
Date: Fri, 29 Nov 2019 15:03:02 +0100 [thread overview]
Message-ID: <87muceeq5l.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20191127183016.13852-1-vsementsov@virtuozzo.com> (Vladimir Sementsov-Ogievskiy's message of "Wed, 27 Nov 2019 21:30:16 +0300")
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:
> fit_load_fdt forget to check that errp is not NULL and to zero it after
> freeing. Fix it.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> ---
> hw/core/loader-fit.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/hw/core/loader-fit.c b/hw/core/loader-fit.c
> index 953b16bc82..3ee9fb2f2e 100644
> --- a/hw/core/loader-fit.c
> +++ b/hw/core/loader-fit.c
> @@ -200,7 +200,10 @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb,
> err = fit_image_addr(itb, img_off, "load", &load_addr, errp);
> if (err == -ENOENT) {
> load_addr = ROUND_UP(kernel_end, 64 * KiB) + (10 * MiB);
> - error_free(*errp);
> + if (errp) {
> + error_free(*errp);
> + *errp = NULL;
> + }
> } else if (err) {
> error_prepend(errp, "unable to read FDT load address from FIT: ");
> ret = err;
This fixes latent bugs when fit_image_addr() fails with ENOENT:
* If a caller passes a null @errp, we crash dereferencing it
* Else, we pass a dangling Error * to the caller, and return success.
If a caller dereferences the Error * regardless, we have a
use-after-free.
Not fixed:
* If a caller passes &error_abort or &error_fatal, we die instead of
taking the recovery path.
We need to use a local_err here.
I'll search for the pattern, and post fix(es).
next prev parent reply other threads:[~2019-11-29 14:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-27 18:30 [PATCH v6] hw/core/loader-fit: fix freeing errp in fit_load_fdt Vladimir Sementsov-Ogievskiy
2019-11-29 14:03 ` Markus Armbruster [this message]
2019-11-29 14:11 ` Vladimir Sementsov-Ogievskiy
2019-11-29 14:12 ` Vladimir Sementsov-Ogievskiy
2019-11-29 15:23 ` Markus Armbruster
2019-11-29 15:32 ` Vladimir Sementsov-Ogievskiy
2019-11-29 20:03 ` Markus Armbruster
2019-11-30 19:48 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87muceeq5l.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=aleksandar.rikalo@rt-rk.com \
--cc=pburton@wavecomp.com \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.