From: Juan Quintela <quintela@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
"Yuval Shaia" <yuval.shaia.ml@gmail.com>,
qemu-devel@nongnu.org,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: Re: [PATCH 1/2] migration: avoid suspicious strncpy() use
Date: Tue, 17 Mar 2020 11:35:14 +0100 [thread overview]
Message-ID: <87k13jl15p.fsf@secure.laptop> (raw)
In-Reply-To: <20200317095222.GB492272@stefanha-x1.localdomain> (Stefan Hajnoczi's message of "Tue, 17 Mar 2020 09:52:22 +0000")
Stefan Hajnoczi <stefanha@redhat.com> wrote:
> On Mon, Mar 16, 2020 at 01:15:35PM -0500, Eric Blake wrote:
>> On 3/16/20 1:09 PM, Philippe Mathieu-Daudé wrote:
>> > On 3/16/20 5:07 PM, Stefan Hajnoczi wrote:
>>
>> >
>> > >
>> > > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
>> > > ---
>> > > migration/global_state.c | 4 ++--
>> > > 1 file changed, 2 insertions(+), 2 deletions(-)
>> > >
>> > > diff --git a/migration/global_state.c b/migration/global_state.c
>> > > index 25311479a4..cbe07f21a8 100644
>> > > --- a/migration/global_state.c
>> > > +++ b/migration/global_state.c
>> > > @@ -44,8 +44,8 @@ void global_state_store_running(void)
>> > > {
>> > > const char *state = RunState_str(RUN_STATE_RUNNING);
>> > > assert(strlen(state) < sizeof(global_state.runstate));
>> > > - strncpy((char *)global_state.runstate,
>> > > - state, sizeof(global_state.runstate));
>> > > + pstrcpy((char *)global_state.runstate,
>> > > + sizeof(global_state.runstate), state);
>>
>> Can we guarantee that the padding bytes have been previously set to 0, or do
>> we need to go the extra mile with a memset() or strpadcpy() to guarantee
>> that we have set the entire buffer?
>
> I don't understand GlobalState:
Welcome to the club O:-)
And I thought that with the reviewed-by I had finished here O:-)
> 1. You ask if runstate[] must be padded with NULs but neither
> global_state_store() nor register_global_state() do that. Is it
> really necessary to pad runstate[]?
>
> If yes, is it safe for global_state_store() and
> register_global_state() to not pad runstate[]?
it is an error. All should be padded.
> If we decide the pad runstate[] to prevent information leaks to the
> migration destination then I think it should be done in the pre-save
> function so that it's guaranteed to happen no matter which of the 3
> functions that write runstate[] has been called.
Ok.
Taking a look at this.
> 2. There is a GlobalState::size field that is only written and then
> migrated but never read from what I can tell. :?
Grrr. It should be used, but it is not :-(
What we have here:
- A static buffer
uint8_t runstate[100];
That is partially filled.
size: is the size of that buffer that is filled.
But, as we are using
VMSTATE_BUFFER(runstate, GlobalState),
We are always sending/receiving the whole buffer. THat is why we have
trouble with padding. What should we being doing?
Sending just the size, the filled bytes, and making sure that there is
enough space on destination.
But we aren't donig that. And at this point, I think that I am only
going to fix the 1st part (always zero pad everything sent).
For fixing the other bit, I need to do an incompatible change.
> Juan: Please clarify the above. Thanks!
Thanks a lot.
Later, Juan.
PD: Why is it done this way?
Because at the moment, the problem was that qcow2 (as a system, not
as a device) didn't have a place where to plug pending requests. So
I created this section that always exist, and anything that has not
a device associated can hang a subsection here. Once that I created
it, nobody used it.
And now, just seing what you are telling, I didn't even used the
right approach.
next prev parent reply other threads:[~2020-03-17 10:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-16 16:07 [PATCH 0/2] gcc 9.2 strncpy(3) warnings fixes Stefan Hajnoczi
2020-03-16 16:07 ` [PATCH 1/2] migration: avoid suspicious strncpy() use Stefan Hajnoczi
2020-03-16 17:25 ` Juan Quintela
2020-03-16 18:09 ` Philippe Mathieu-Daudé
2020-03-16 18:15 ` Eric Blake
2020-03-17 9:52 ` Stefan Hajnoczi
2020-03-17 10:12 ` Philippe Mathieu-Daudé
2020-03-17 10:35 ` Juan Quintela [this message]
2020-03-17 14:15 ` Stefan Hajnoczi
2020-03-17 14:18 ` Juan Quintela
2020-03-16 16:07 ` [PATCH 2/2] hw/rdma: " Stefan Hajnoczi
2020-03-16 17:28 ` Juan Quintela
2020-03-20 11:55 ` Yuval Shaia
2020-03-21 17:25 ` Marcel Apfelbaum
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=87k13jl15p.fsf@secure.laptop \
--to=quintela@redhat.com \
--cc=dgilbert@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=yuval.shaia.ml@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.