From: Klaus Jensen <its@irrelevant.dk>
To: Andrew Jeffery <andrew@codeconstruct.com.au>
Cc: Corey Minyard <cminyard@mvista.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
Jason Wang <jasowang@redhat.com>, Keith Busch <kbusch@kernel.org>,
Lior Weintraub <liorw@pliops.com>,
Jeremy Kerr <jk@codeconstruct.com.au>,
Matt Johnston <matt@codeconstruct.com.au>,
Peter Delevoryas <peter@pjd.dev>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
qemu-devel@nongnu.org, qemu-arm@nongnu.org,
qemu-block@nongnu.org, Klaus Jensen <k.jensen@samsung.com>,
Andrew Jeffery <andrew@aj.id.au>
Subject: Re: [PATCH v5 3/3] hw/nvme: add nvme management interface model
Date: Thu, 14 Sep 2023 08:51:33 +0200 [thread overview]
Message-ID: <ZQKtdSI-wZ20_V0F@cormorant.local> (raw)
In-Reply-To: <130f973070f4422e226a9e68218109094f0420fa.camel@codeconstruct.com.au>
[-- Attachment #1: Type: text/plain, Size: 3425 bytes --]
On Sep 12 13:50, Andrew Jeffery wrote:
> Hi Klaus,
>
> On Tue, 2023-09-05 at 10:38 +0200, Klaus Jensen wrote:
> > >
> > > +static void nmi_handle_mi_config_get(NMIDevice *nmi, NMIRequest
> > > *request)
> > > +{
> > > + uint32_t dw0 = le32_to_cpu(request->dw0);
> > > + uint8_t identifier = FIELD_EX32(dw0,
> > > NMI_CMD_CONFIGURATION_GET_DW0,
> > > + IDENTIFIER);
> > > + const uint8_t *buf;
> > > +
> > > + static const uint8_t smbus_freq[4] = {
> > > + 0x00, /* success */
> > > + 0x01, 0x00, 0x00, /* 100 kHz */
> > > + };
> > > +
> > > + static const uint8_t mtu[4] = {
> > > + 0x00, /* success */
> > > + 0x40, 0x00, /* 64 */
> > > + 0x00, /* reserved */
> > > + };
> > > +
> > > + trace_nmi_handle_mi_config_get(identifier);
> > > +
> > > + switch (identifier) {
> > > + case NMI_CMD_CONFIGURATION_GET_SMBUS_FREQ:
> > > + buf = smbus_freq;
> > > + break;
> > > +
> > > + case NMI_CMD_CONFIGURATION_GET_MCTP_TRANSMISSION_UNIT:
> > > + buf = mtu;
> > > + break;
> > > +
> > > + default:
> > > + nmi_set_parameter_error(nmi, 0x0, offsetof(NMIRequest,
> > > dw0));
> > > + return;
> > > + }
> > > +
> > > + nmi_scratch_append(nmi, buf, sizeof(buf));
> > > +}
>
> When I tried to build this patch I got:
>
> ```
> In file included from /usr/include/string.h:535,
> from /home/andrew/src/qemu.org/qemu/include/qemu/osdep.h:112,
> from ../hw/nvme/nmi-i2c.c:12:
> In function ‘memcpy’,
> inlined from ‘nmi_scratch_append’ at ../hw/nvme/nmi-i2c.c:80:5,
> inlined from ‘nmi_handle_mi_config_get’ at ../hw/nvme/nmi-i2c.c:246:5,
> inlined from ‘nmi_handle_mi’ at ../hw/nvme/nmi-i2c.c:266:9,
> inlined from ‘nmi_handle’ at ../hw/nvme/nmi-i2c.c:313:9:
> /usr/include/x86_64-linux-gnu/bits/string_fortified.h:29:10: error: ‘__builtin_memcpy’ forming offset [4, 7] is out of the bounds [0, 4] [-Werror=array-bounds=]
> 29 | return __builtin___memcpy_chk (__dest, __src, __len,
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 30 | __glibc_objsize0 (__dest));
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~
> ```
>
> It wasn't clear initially from the error that the source of the problem
> was the size associated with the source buffer, especially as there is
> some pointer arithmetic being done to derive `__dest`.
>
> Anyway, what we're trying to express is that the size to copy from buf
> is the size of the array pointed to by buf. However, buf is declared as
> a pointer to uint8_t, which loses the length information. To fix that I
> think we need:
>
> - const uint8_t *buf;
> + const uint8_t (*buf)[4];
>
> and then:
>
> - nmi_scratch_append(nmi, buf, sizeof(buf));
> + nmi_scratch_append(nmi, buf, sizeof(*buf));
>
> Andrew
>
Hi Andrew,
Nice (and important) catch! Just curious, are you massaging QEMU's build
system into adding additional checks or how did your compiler catch
this?
Thanks,
Klaus
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2023-09-14 6:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-05 8:38 [PATCH v5 0/3] hw/{i2c,nvme}: mctp endpoint, nvme management interface model Klaus Jensen
2023-09-05 8:38 ` [PATCH v5 1/3] hw/i2c: add smbus pec utility function Klaus Jensen
2023-09-05 8:38 ` [PATCH v5 2/3] hw/i2c: add mctp core Klaus Jensen
2023-09-05 8:38 ` [PATCH v5 3/3] hw/nvme: add nvme management interface model Klaus Jensen
2023-09-12 5:50 ` Andrew Jeffery
2023-09-14 6:51 ` Klaus Jensen [this message]
2023-09-14 7:42 ` Andrew Jeffery
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=ZQKtdSI-wZ20_V0F@cormorant.local \
--to=its@irrelevant.dk \
--cc=Jonathan.Cameron@huawei.com \
--cc=andrew@aj.id.au \
--cc=andrew@codeconstruct.com.au \
--cc=cminyard@mvista.com \
--cc=jasowang@redhat.com \
--cc=jk@codeconstruct.com.au \
--cc=k.jensen@samsung.com \
--cc=kbusch@kernel.org \
--cc=liorw@pliops.com \
--cc=matt@codeconstruct.com.au \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peter@pjd.dev \
--cc=qemu-arm@nongnu.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).