qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Oleg Sviridov <oleg.sviridov@red-soft.ru>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>,
	Thomas Huth <thuth@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	David Hildenbrand <david@redhat.com>,
	Ilya Leoshkevich <iii@linux.ibm.com>,
	Halil Pasic <pasic@linux.ibm.com>,
	Eric Farman <farman@linux.ibm.com>,
	qemu-s390x@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [PATCH] hw/s390x: prevent potential NULL dereference
Date: Wed, 29 May 2024 15:47:34 +0200	[thread overview]
Message-ID: <fc6c2828-f869-4f5e-af06-785002000f98@linaro.org> (raw)
In-Reply-To: <20240529113643.3638618-1-oleg.sviridov@red-soft.ru>

Hi Oleg,

On 29/5/24 13:36, Oleg Sviridov wrote:
> Pointer, returned from function 's390_ipl_get_iplb_pv', may be NULL and is dereferenced immediately after.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Signed-off-by: Oleg Sviridov <oleg.sviridov@red-soft.ru>
> ---
>   hw/s390x/ipl.c | 11 ++++++++++-
>   1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
> index e934bf89d1..2fa6a340a1 100644
> --- a/hw/s390x/ipl.c
> +++ b/hw/s390x/ipl.c
> @@ -706,9 +706,14 @@ int s390_ipl_prepare_pv_header(Error **errp)
>   {
>       IplParameterBlock *ipib = s390_ipl_get_iplb_pv();
>       IPLBlockPV *ipib_pv = &ipib->pv;

I suppose ipib_pv being NULL here is a bug elsewhere. You should
add here:

        assert(ipib_pv);

and look at the backtrace or audit the code.

> -    void *hdr = g_malloc(ipib_pv->pv_header_len);
> +    void *hdr;
>       int rc;
>   
> +    if (!ipib_pv) {

(If this is a legit error you have to set errp here before returning).

> +        return -1;
> +    }
> +
> +    hdr = g_malloc(ipib_pv->pv_header_len);
>       cpu_physical_memory_read(ipib_pv->pv_header_addr, hdr,
>                                ipib_pv->pv_header_len);
>       rc = s390_pv_set_sec_parms((uintptr_t)hdr, ipib_pv->pv_header_len, errp);
> @@ -722,6 +727,10 @@ int s390_ipl_pv_unpack(void)
>       IPLBlockPV *ipib_pv = &ipib->pv;
>       int i, rc = 0;
>   

Ditto assert.

> +    if (!ipib_pv) {
> +        return -1;
> +    }
> +
>       for (i = 0; i < ipib_pv->num_comp; i++) {
>           rc = s390_pv_unpack(ipib_pv->components[i].addr,
>                               TARGET_PAGE_ALIGN(ipib_pv->components[i].size),



      reply	other threads:[~2024-05-29 13:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-29 11:36 [PATCH] hw/s390x: prevent potential NULL dereference Oleg Sviridov
2024-05-29 13:47 ` Philippe Mathieu-Daudé [this message]

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=fc6c2828-f869-4f5e-af06-785002000f98@linaro.org \
    --to=philmd@linaro.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=david@redhat.com \
    --cc=farman@linux.ibm.com \
    --cc=iii@linux.ibm.com \
    --cc=oleg.sviridov@red-soft.ru \
    --cc=pasic@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).