From: Andrew Jeffery <andrew@codeconstruct.com.au>
To: Klaus Jensen <its@irrelevant.dk>
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 15:42:56 +0800 [thread overview]
Message-ID: <f375f6ed1d576586683cdba2a2710979e8bad369.camel@codeconstruct.com.au> (raw)
In-Reply-To: <ZQKtdSI-wZ20_V0F@cormorant.local>
Hi Klaus,
On Thu, 2023-09-14 at 08:51 +0200, Klaus Jensen wrote:
> 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?
No tricks to be honest, I just applied your patches on top of
9ef497755afc ("Merge tag 'pull-vfio-20230911' of
https://github.com/legoater/qemu into staging") using `b4 shazam ...`.
I'm building on Debian Bookworm:
$ gcc --version | head -n1
gcc (Debian 12.2.0-14) 12.2.0
Andrew
prev parent reply other threads:[~2023-09-14 7:43 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
2023-09-14 7:42 ` Andrew Jeffery [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=f375f6ed1d576586683cdba2a2710979e8bad369.camel@codeconstruct.com.au \
--to=andrew@codeconstruct.com.au \
--cc=Jonathan.Cameron@huawei.com \
--cc=andrew@aj.id.au \
--cc=cminyard@mvista.com \
--cc=its@irrelevant.dk \
--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).