Re: [PATCH] vhost: zero vhost_vsock memory on allocation

From: Stefan Hajnoczi
Date: Thu Mar 28 2019 - 12:36:50 EST

On Wed, Mar 27, 2019 at 01:08:53PM -0400, Vitaly Mayatskih wrote:
> On Wed, Mar 27, 2019 at 12:49 PM Stefan Hajnoczi <stefanha@xxxxxxxxxx> wrote:
> > Which field was accessed before initialization?
> >
> > I ask because the situation is now unclear since code remains that
> > assumes vsock is *not* zero-initialized:
> >
> > vsock->guest_cid = 0; /* no CID assigned yet */
> >
> > atomic_set(&vsock->queued_replies, 0);
> It was hash.

vsock->hash is only read if vsock->guest_cid has already been set and
hence vsock->hash has been initialized too. I don't see where the
problem is.

Was your tree missing commit a72b69dc083a931422cc8a5e33841aff7d5312f2
("vhost/vsock: fix uninitialized vhost_vsock->guest_cid")?

Are you sure the crash can be reproduced on linux.git/master?

Sorry for insisting on so much information but I want to make I fully
understand the issue you encountered.

> > If we're going to zalloc, let's get rid of explicit zero
> > initializations. Or let's use kvmalloc() and fix the uninitialized
> > access. Mixing both is confusing.
> I would go with zalloc, since it's easier to read and it prevents
> further situations like this.
> A zalloc was there originally (not in fallback though).

Sounds good. Please send a v2 that also removes the explicit zero
initialization since it's no longer needed with zalloc.

Attachment: signature.asc
Description: PGP signature