From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>,
"Clément Chigot" <chigot@adacore.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-ppc@nongnu.org, "Daniel P. Berrangé" <berrange@redhat.com>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"Cédric Le Goater" <clg@kaod.org>
Subject: Re: [PATCH 3/3] meson: Enable -Wvla
Date: Wed, 21 Feb 2024 18:48:59 +0100 [thread overview]
Message-ID: <34e092c0-35b8-4f8f-8ed1-1f5aeb0f9d07@redhat.com> (raw)
In-Reply-To: <8dac5c1a-5780-45ca-90fe-147f1ab2fe28@redhat.com>
On 21/02/2024 17.59, Thomas Huth wrote:
> On 21/02/2024 17.26, Thomas Huth wrote:
>> From: Peter Maydell <peter.maydell@linaro.org>
>>
>> QEMU has historically used variable length arrays only very rarely.
>> Variable length arrays are a potential security issue where an
>> on-stack dynamic allocation isn't correctly size-checked, especially
>> when the size comes from the guest. (An example problem of this kind
>> from the past is CVE-2021-3527). Forbidding them entirely is a
>> defensive measure against further bugs of this kind.
>>
>> Enable -Wvla to prevent any new uses from sneaking into the codebase.
>>
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>> Message-ID: <20240125173211.1786196-3-peter.maydell@linaro.org>
>> [thuth: rebased to current master branch]
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>> meson.build | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/meson.build b/meson.build
>> index c1dc83e4c0..0ef1654e86 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -592,6 +592,7 @@ warn_flags = [
>> '-Wstrict-prototypes',
>> '-Wtype-limits',
>> '-Wundef',
>> + '-Wvla',
>> '-Wwrite-strings',
>> # Then disable some undesirable warnings
>
> Sigh, there's a new warning in the latest master branch:
>
> https://gitlab.com/thuth/qemu/-/jobs/6225992174
>
> Caused by commit d65aba828 ("hw/sparc/leon3: implement multiprocessor")...
> Clément, Philippe, could this maybe be written in a different way that does
> not trigger a -Wvla warning?
I think the DO_UPCAST is wrong here - if I got that right, DO_UPCAST is
supposed to check that the second parameter is at the same location as the
first type later points to. This is not the case here. I think we rather
want container_of() here, so this patch is likely a simple fix:
diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -150,7 +150,7 @@ static void leon3_cpu_reset(void *opaque)
{
struct CPUResetData *info = (struct CPUResetData *) opaque;
int id = info->id;
- ResetData *s = (ResetData *)DO_UPCAST(ResetData, info[id], info);
+ ResetData *s = container_of(info, ResetData, info[id]);
CPUState *cpu = CPU(s->info[id].cpu);
CPUSPARCState *env = cpu_env(cpu);
I can send it as a proper patch, too.
Thomas
prev parent reply other threads:[~2024-02-21 17:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-21 16:26 [PATCH 0/3] Replace variable length arrays in ppc KVM code Thomas Huth
2024-02-21 16:26 ` [PATCH 1/3] target/ppc/kvm: Replace variable length array in kvmppc_save_htab() Thomas Huth
2024-02-21 16:29 ` Peter Maydell
2024-02-21 16:52 ` Thomas Huth
2024-02-21 16:26 ` [PATCH 2/3] target/ppc/kvm: Replace variable length array in kvmppc_read_hptes() Thomas Huth
2024-02-21 16:30 ` Peter Maydell
2024-02-21 16:26 ` [PATCH 3/3] meson: Enable -Wvla Thomas Huth
2024-02-21 16:59 ` Thomas Huth
2024-02-21 17:27 ` Philippe Mathieu-Daudé
2024-02-21 17:30 ` Philippe Mathieu-Daudé
2024-02-22 8:19 ` Clément Chigot
2024-02-21 17:48 ` Thomas Huth [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=34e092c0-35b8-4f8f-8ed1-1f5aeb0f9d07@redhat.com \
--to=thuth@redhat.com \
--cc=berrange@redhat.com \
--cc=chigot@adacore.com \
--cc=clg@kaod.org \
--cc=danielhb413@gmail.com \
--cc=npiggin@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@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).