Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5513547img; Wed, 27 Mar 2019 09:51:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvqmO9C7nsLJvBEsFPVHRbV8mXfG06ojOe2edR39/TVBF1+ia55csI3LUmNkbLRuiUbLeI X-Received: by 2002:aa7:8012:: with SMTP id j18mr37596128pfi.42.1553705483192; Wed, 27 Mar 2019 09:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553705483; cv=none; d=google.com; s=arc-20160816; b=Zf3vf4y0gXOVXacH4JjVvbmwE5wyaeB49d9ruVATLkH1u8y7DC+EbuG76zab11amE3 jRGwMqzasklSjjx2BDGT6WRByRzOD3Eg7zTo3jE/jsye1GqKVmF6B5J3EaTWJx9Alh2O HtsoRv4R3wT9Fb3gu4Pp3PNuMgH+3+VGvvL3v6AW1hFzvjRYU4AkO4Iwo2hhO16+tyCA uA68AuJqJh9uIq4TTtIAelt7cThN9WLAxtCl1cpio49flfg2TsTQRCBJKpk7W9O+wBt2 dHm/0bzuX+p/fxzQsUTk0Ent2u7daN+dlobltUnCePYWOdfrbhiT9RoJeqgywW++10Hx pzAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=X3Jd5yoch5tHPTBa9827Kue3ZQ+BYh0qV9HzsGmn4H8=; b=WypGU4fzdJgp6KvNB7gtWlszTIC0nqzSkStADdF9tD1tGPuhcTcq5z0UEU5ww7N0R4 4DXOgSN4o6nbJfe0lj7O/mlXxi8+GfHObi5SQZEBtRysm4XugQZL+aqUpKnXI7k7/8fQ W+QbyUZgzhmGzKTqF5cz8HAXdmFVLCOYZasSZfAybTZy8rQGjlU76uS21FqIKMeRNa/q /A7sCyndJhIewv/del7rUTzCIO3ejIlMZ0EUf1diqrEvPx7npVQpWs6WF+Jem6nOtpRG XEsogJegvyOVypU28yKqqt5wh21priIf0Yxu7eqUaZvwArJU6al9P7JYuNoj3S3wdXlL F/OQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p2si8764786pgk.326.2019.03.27.09.51.07; Wed, 27 Mar 2019 09:51:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727560AbfC0QtQ (ORCPT + 99 others); Wed, 27 Mar 2019 12:49:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44338 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726990AbfC0QtQ (ORCPT ); Wed, 27 Mar 2019 12:49:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E857C307D987; Wed, 27 Mar 2019 16:49:15 +0000 (UTC) Received: from localhost (ovpn-116-213.ams2.redhat.com [10.36.116.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 788E11715C; Wed, 27 Mar 2019 16:49:15 +0000 (UTC) Date: Wed, 27 Mar 2019 16:49:14 +0000 From: Stefan Hajnoczi To: Vitaly Mayatskikh Cc: Michal Hocko , linux-kernel@vger.kernel.org Subject: Re: [PATCH] vhost: zero vhost_vsock memory on allocation Message-ID: <20190327164914.GE27283@stefanha-x1.localdomain> References: <1553648174-24913-1-git-send-email-v.mayatskih@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="GxcwvYAGnODwn7V8" Content-Disposition: inline In-Reply-To: <1553648174-24913-1-git-send-email-v.mayatskih@gmail.com> User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 27 Mar 2019 16:49:16 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --GxcwvYAGnODwn7V8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 26, 2019 at 08:56:14PM -0400, Vitaly Mayatskikh wrote: > This fixes OOPS when using under-initialized vhost_vsock object. >=20 > The code had a combo of kzalloc plus vmalloc as a fallback > initially, but it has been replaced by plain kvmalloc in > commit 6c5ab6511f71 ("mm: support __GFP_REPEAT in kvmalloc_node for >32kB= ") >=20 > OOPS is easy to reproduce with open/ioctl after trashing the RAM. 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 =3D 0; /* no CID assigned yet */ atomic_set(&vsock->queued_replies, 0); 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. > Signed-off-by: Vitaly Mayatskikh > --- > drivers/vhost/vsock.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c > index bb5fc0e..9e7cb13 100644 > --- a/drivers/vhost/vsock.c > +++ b/drivers/vhost/vsock.c > @@ -512,7 +512,7 @@ static int vhost_vsock_dev_open(struct inode *inode, = struct file *file) > /* This struct is large and allocation could fail, fall back to vmalloc > * if there is no other way. > */ > - vsock =3D kvmalloc(sizeof(*vsock), GFP_KERNEL | __GFP_RETRY_MAYFAIL); > + vsock =3D kvzalloc(sizeof(*vsock), GFP_KERNEL | __GFP_RETRY_MAYFAIL); > if (!vsock) > return -ENOMEM; > =20 > --=20 > 1.8.3.1 >=20 --GxcwvYAGnODwn7V8 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJcm6mKAAoJEJykq7OBq3PIfCIH/1ZudXBDTe+lVpYHGgiheqDK TxlZYvjeRdWRIPv02vngsUXSAfpS1Wb9BopaE2m47TTQBzIYJ51bvQPXRim2cGmf Y2O5DuRl3KggOCcelmzQjsJLnjY6fOgeSJrCBltVNGPLOhk1CXBywX99mvk1YHYS 1hKjZQMANQZcSv8gWypVxUEzC1XZVHL1+tSVMhumTEmCeMcouGMMWhC8XZuN05A+ +wxiPCFNeH1EWSokvBVKjUPJnvaauENO4Qk4/YSzk7TERsYTv3pH0b1UbWJ/K4Sm FUodfBPJWkQknZpenbwduaA+/RQ+HxCrEGeor+87l8QFtzFHiaZ+EKuxgFyTWiw= =a8tB -----END PGP SIGNATURE----- --GxcwvYAGnODwn7V8--