From: Peter Maydell <peter.maydell@linaro.org>
To: Cornelia Huck <cohuck@redhat.com>
Cc: Halil Pasic <pasic@linux.ibm.com>,
qemu-s390x <qemu-s390x@nongnu.org>,
QEMU Developers <qemu-devel@nongnu.org>,
Thomas Huth <thuth@redhat.com>
Subject: Re: [PULL 2/2] s390x/s390-virtio-ccw: fix loadparm property getter
Date: Tue, 28 Jul 2020 14:52:36 +0100 [thread overview]
Message-ID: <CAFEAcA_1xECE+ESWoioHFSF_mwDG11NrR2=J3NWx2X+OGg3SZw@mail.gmail.com> (raw)
In-Reply-To: <20200727140522.251815-3-cohuck@redhat.com>
On Mon, 27 Jul 2020 at 15:05, Cornelia Huck <cohuck@redhat.com> wrote:
>
> From: Halil Pasic <pasic@linux.ibm.com>
>
> The function machine_get_loadparm() is supposed to produce a C-string,
> that is a NUL-terminated one, but it does not. ElectricFence can detect
> this problem if the loadparm machine property is used.
>
> Let us make the returned string a NUL-terminated one.
>
> Fixes: 7104bae9de ("hw/s390x: provide loadparm property for the machine")
> Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Message-Id: <20200723162717.88485-1-pasic@linux.ibm.com>
> Signed-off-by: Cornelia Huck <cohuck@redhat.com>
> ---
> hw/s390x/s390-virtio-ccw.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index 8cc2f25d8a6a..403d30e13bca 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -701,8 +701,12 @@ bool hpage_1m_allowed(void)
> static char *machine_get_loadparm(Object *obj, Error **errp)
> {
> S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
> + char *loadparm_str;
>
> - return g_memdup(ms->loadparm, sizeof(ms->loadparm));
> + /* make a NUL-terminated string */
> + loadparm_str = g_memdup(ms->loadparm, sizeof(ms->loadparm) + 1);
> + loadparm_str[sizeof(ms->loadparm)] = 0;
> + return loadparm_str;
Hi. Coverity points out (CID 1431058) that this code now
reads off the end of the ms->loadparm buffer, because
g_memdup() is going to read and copy 9 bytes (size + 1)
and the array itself is only 8 bytes.
I don't think you can use g_memdup() here -- you need to
allocate the memory with g_malloc() and then fill it with
memcpy(), something like:
loadparm_str = g_malloc(sizeof(ms->loadparm) + 1);
memcpy(loadparm_str, ms->loadparm, sizeof(ms->loadparm));
loadparm_str[sizeof(ms->loadparm)] = 0;
thanks
-- PMM
next prev parent reply other threads:[~2020-07-28 13:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-27 14:05 [PULL 0/2] some more s390x fixes Cornelia Huck
2020-07-27 14:05 ` [PULL 1/2] s390x/protvirt: allow to IPL secure guests with -no-reboot Cornelia Huck
2020-07-27 14:05 ` [PULL 2/2] s390x/s390-virtio-ccw: fix loadparm property getter Cornelia Huck
2020-07-28 13:52 ` Peter Maydell [this message]
2020-07-28 15:14 ` Cornelia Huck
2020-07-28 20:22 ` Halil Pasic
2020-07-27 19:59 ` [PULL 0/2] some more s390x fixes Peter Maydell
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='CAFEAcA_1xECE+ESWoioHFSF_mwDG11NrR2=J3NWx2X+OGg3SZw@mail.gmail.com' \
--to=peter.maydell@linaro.org \
--cc=cohuck@redhat.com \
--cc=pasic@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.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).