From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Foley <pefoley@google.com>, Markus Armbruster <armbru@redhat.com>
Cc: Patrick Venture <venture@google.com>,
peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: Re: [PATCH] util/keyval: fix msan findings
Date: Mon, 3 Mar 2025 19:51:48 +0100 [thread overview]
Message-ID: <14168384-ecdb-4c05-8267-ac5ef1c46fe9@redhat.com> (raw)
In-Reply-To: <CAAAKUPOmAHht=HgNzKvLPinfXJbWjqp=AnmQDwBEbcNFUaOetg@mail.gmail.com>
On 3/3/25 17:32, Peter Foley wrote:
> The full output looks like:
>
> Uninitialized bytes in strlen at offset 0 inside [0xffffd1958110, 5)
> ==9780==WARNING: MemorySanitizer: use-of-uninitialized-value
> #0 0xaaaac1c4b170 in tdb_hash third_party/qemu/qobject/qdict.c:46:31
> #1 0xaaaac1c4b4a4 in qdict_get third_party/qemu/qobject/qdict.c:164:36
> #2 0xaaaac1c78468 in keyval_parse_put third_party/qemu/util/keyval.c:152:11
> #3 0xaaaac1c77740 in keyval_parse_one third_party/qemu/util/keyval.c:295:10
In order to get to
if (!keyval_parse_put(cur, key_in_cur, qstring_from_gstring(val),
key, key_end, errp)) {
you must have gone through the only exit path of the earlier
"for(;;)" loop:
memcpy(key_in_cur, s, len);
key_in_cur[len] = 0;
s += len;
if (*s != '.') {
break;
}
meaning that key_in_cur is NULL-terminated and initialized---unless s is
also uninitialized, but then adding an initializer would not do anything.
Paolo
> #4 0xaaaac1c77740 in keyval_parse_into third_party/qemu/util/keyval.c:530:13
> #5 0xaaaaba2f9524 in qemu_init third_party/qemu/system/vl.c:3322:21
> #6 0xaaaab9641c2c in main third_party/qemu/system/main.c:54:5
> #7 0xffffba320000 in __libc_start_main (/usr/grte/v5/lib64/libc.so.6+0x61000) (BuildId: 613d20d3b812b4c87fe9ebf8c4caae83)
> #8 0xaaaab934bd10 in _start /usr/grte/v5/debug-src/src/csu/../sysdeps/aarch64/start.S:92
>
> Uninitialized value was created by an allocation of 'key_in_cur.i' in the stack frame
> #0 0xaaaac1c7708c in keyval_parse_one third_party/qemu/util/keyval.c:190:5
> #1 0xaaaac1c7708c in keyval_parse_into third_party/qemu/util/keyval.c:530:13
>
> SUMMARY: MemorySanitizer: use-of-uninitialized-value third_party/qemu/qobject/qdict.c:46:31 in tdb_hash
> Exiting
>
>
> I don't have an easily shareable reproducer, but it's probably possible
> to whip one up.
>
>
> >> ---
> >> util/keyval.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >> diff --git a/util/keyval.c b/util/keyval.c
> >> index a70629a481..f33c64079d 100644
> >> --- a/util/keyval.c
> >> +++ b/util/keyval.c
> >> @@ -187,7 +187,7 @@ static const char *keyval_parse_one(QDict
> *qdict, const char *params,
> >> {
> >> const char *key, *key_end, *val_end, *s, *end;
> >> size_t len;
> >> - char key_in_cur[128];
> >> + char key_in_cur[128] = {};
>
> Suspect overkill. Would "" do?
>
>
> It appears to resolve the complaint, yes.
prev parent reply other threads:[~2025-03-03 18:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-28 21:20 [PATCH] util/keyval: fix msan findings Patrick Venture
2025-03-01 6:12 ` Paolo Bonzini
2025-03-01 7:14 ` Markus Armbruster
2025-03-03 16:32 ` Peter Foley
2025-03-03 18:51 ` Paolo Bonzini [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=14168384-ecdb-4c05-8267-ac5ef1c46fe9@redhat.com \
--to=pbonzini@redhat.com \
--cc=armbru@redhat.com \
--cc=pefoley@google.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=venture@google.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).