Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp4325172imb; Wed, 6 Mar 2019 10:33:21 -0800 (PST) X-Google-Smtp-Source: APXvYqxbcQAPb/MtFgaUQz5n6ikVLd5ydJdvucWB/GpUFS4e8hDrHqBNYcF04FNAHG0rN+kFrlde X-Received: by 2002:a62:e911:: with SMTP id j17mr8566918pfh.107.1551897201223; Wed, 06 Mar 2019 10:33:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551897201; cv=none; d=google.com; s=arc-20160816; b=g/q9FCobskcmO5ueoCV0oNC0APs4D4VJXAHxiUn/I1wrgAt1oFUvAgyUwH8rQ8IaD0 Ny+pEb0txgBgQX5GMH3SwsmFSqpilCDGPLvH4gmjWh2PkMBLdfE/6e1nPErQVCpE0NU9 gasLzc3Kqx5Ptt8m8YpJyFXsT52gUdDFEDQSRh3ft2uv2XRCOJrDjKeLDIkes4Z5bsIE 9z1pBG3hQmDO5Y3neu/i/lozzEXbjIO4R3X11c7zfBm4I7T5IRU5QQFUzIfe5AiL3eR5 4onjiaoZTu4CvhzRBEt2kgFwzc40wb95k6xj0afFukNunFJWiSoB6HAdN4FOX1GQwvwD oPqw== 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=5HH+YHk0VE2wgM40EsatZDEB6r6Skia6l8V+RDf75As=; b=GHB+9mSWYXvFx6U90WirQxmLBnyXXjVTC3ch51O7mYn2T2NX8z+/d0jZdugmfq/L95 e0+o7/0pKXCGds3jACXdpx5E6aXk/ovCCfO7EzxfCHqpfUvPfBlvtkiYqiljJ5TLZbAc Qpr6xELI0VJwesiM3Dc5FwrRm9bM3S59hNxWjiqCpNINdpQ6DpIl8fG265jNXegrOUa8 eVRsDG66SPHF/asIwkrqqjhWJGyN7HFrinpQ3WInRY+pFs2Pwx6zt5VBfBlEKF80VvK8 /aCV8rEzbJGPyGTVjQsVT+YBqIWSxX9lT/NZp2aQxzPgfLZilHUV7BWur+7MnrYeCyjb y2UQ== 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 a74si2200169pfj.20.2019.03.06.10.33.06; Wed, 06 Mar 2019 10:33:21 -0800 (PST) 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 S1730390AbfCFRCT (ORCPT + 99 others); Wed, 6 Mar 2019 12:02:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46842 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726636AbfCFRCS (ORCPT ); Wed, 6 Mar 2019 12:02:18 -0500 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 8DF5988305; Wed, 6 Mar 2019 17:02:18 +0000 (UTC) Received: from localhost (ovpn-117-87.ams2.redhat.com [10.36.117.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id F35855C647; Wed, 6 Mar 2019 17:02:17 +0000 (UTC) Date: Wed, 6 Mar 2019 17:02:16 +0000 From: Stefan Hajnoczi To: Adalbert =?utf-8?B?TGF6xINy?= Cc: Stefan Hajnoczi , "David S . Miller" , Stefano Garzarella , virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] vsock/virtio: fix kernel panic from virtio_transport_reset_no_sock Message-ID: <20190306170216.GC29057@stefanha-x1.localdomain> References: <20190305180145.27161-1-alazar@bitdefender.com> <20190306084104.GA22159@stefanha-x1.localdomain> <1551863441.5559.19509.@c1753101230bd75c4bdbfe8f0947046bcaf69c6c> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="oJ71EGRlYNjSvfq7" Content-Disposition: inline In-Reply-To: <1551863441.5559.19509.@c1753101230bd75c4bdbfe8f0947046bcaf69c6c> 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.28]); Wed, 06 Mar 2019 17:02:18 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --oJ71EGRlYNjSvfq7 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Mar 06, 2019 at 11:10:41AM +0200, Adalbert Laz=C4=83r wrote: > On Wed, 6 Mar 2019 08:41:04 +0000, Stefan Hajnoczi w= rote: > > On Tue, Mar 05, 2019 at 08:01:45PM +0200, Adalbert Laz=C4=83r wrote: > > The pkt argument is the received packet that we must reply to. > > The reply packet is allocated just before line 680 and must be free > > explicitly for return -ENOTCONN. > >=20 > > You can avoid the leak and make the code easier to read like this: > >=20 > > struct virtio_vsock_pkt *reply; > >=20 > > ... > >=20 > > ------ avoid reusing 'pkt' > > v > > reply =3D virtio_transport_alloc_pkt(&info, 0, ...); > > if (!reply) > > return -ENOMEM; > >=20 > > t =3D virtio_transport_get_ops(); > > if (!t) { > > virtio_transport_free_pkt(reply); <-- prevent memory leak > > return -ENOTCONN; > > } > > return t->send_pkt(reply); >=20 > What do you think about Stefano's suggestion, to move the check above > the line were the reply is allocated? That's fine too. However a follow up patch to eliminate the confusing way that 'pkt' is reused is still warranted. If you are busy I'd be happy to send that cleanup. Stefan --oJ71EGRlYNjSvfq7 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJcf/0YAAoJEJykq7OBq3PIs3AH/1reh3MukS2CTzKwSmGQGqBN Ps+VDdzKgn+h+Rmr9t6vj3wrJI7T8omxUwcZzXjz45cJyY4UnqynrwvayMzZSLxi V817uV3GAMrlRJzTQdnl5M5UEW7h6gdkOexKl92eUU5cl+H0SUhb8oeOhL+9SY7X nuEaEQVfRiDeBGC62oUTfwwIVAQlkKyoLhE649PKl2lpP1UA+JwSaBFVQ/7RzLBo fPK33EceZifQh95nd4vr6TZhBbu3F4wC44illc46C9i9yYLvHz7RmXoHOteXuNVP TNLgyoLUMwiz7RCGn016JJ9MFCQBL7rA/JNuS4fo5DE2+ihx8kp8i58VnMEvPrs= =nvm3 -----END PGP SIGNATURE----- --oJ71EGRlYNjSvfq7--