From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C38BC63777 for ; Thu, 3 Dec 2020 09:55:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AE7AF204EC for ; Thu, 3 Dec 2020 09:55:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE7AF204EC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kklKn-00025i-4m for qemu-devel@archiver.kernel.org; Thu, 03 Dec 2020 04:55:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59396) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kklHV-00078B-2v for qemu-devel@nongnu.org; Thu, 03 Dec 2020 04:52:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28720) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kklHT-0004zt-Cd for qemu-devel@nongnu.org; Thu, 03 Dec 2020 04:52:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606989126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=r+tgLvPZFKvKeCaWkDYatF/aX7SwLW8qof5R5bl6kN8=; b=WlF2u14stkpLTLrdKmyhRj7mQTXvYasKIGxAAX1Uq4cBjjlVOJbMz1bA0DItcOw6F52HBv XLNJ2B2BFfdwAPXpS8ktsUbfWTUiqYNo90i7pbJNw1joyKVC2OCmse17UX/UTRyGYQpPhE c4p2DG325cmpT7T0IoHfAh4HPqgprxQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-291-GLob8OtvNZKq-Fg--PZrmg-1; Thu, 03 Dec 2020 04:52:04 -0500 X-MC-Unique: GLob8OtvNZKq-Fg--PZrmg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5591F19057AF; Thu, 3 Dec 2020 09:52:03 +0000 (UTC) Received: from localhost (ovpn-115-46.ams2.redhat.com [10.36.115.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8AD160861; Thu, 3 Dec 2020 09:51:57 +0000 (UTC) Date: Thu, 3 Dec 2020 09:51:19 +0000 From: Stefan Hajnoczi To: =?iso-8859-1?Q?Marc-Andr=E9?= Lureau Subject: Re: [PATCH v2 2/4] contrib/vhost-user-gpu: avoid g_return_val_if() input validation Message-ID: <20201203095119.GA689053@stefanha-x1.localdomain> References: <20201202152611.677753-1-stefanha@redhat.com> <20201202152611.677753-3-stefanha@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Nq2Wo0NMKNjxTN9z" Content-Disposition: inline Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.495, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , "open list:Block layer core" , "Michael S. Tsirkin" , Markus Armbruster , QEMU , Coiby Xu , Raphael Norwitz , Gerd Hoffmann , Max Reitz , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Dec 02, 2020 at 07:50:51PM +0400, Marc-Andr=E9 Lureau wrote: > On Wed, Dec 2, 2020 at 7:27 PM Stefan Hajnoczi wrot= e: >=20 > > Do not validate input with g_return_val_if(). This API is intended for > > checking programming errors and is compiled out with -DG_DISABLE_CHECKS= . > > > > Use an explicit if statement for input validation so it cannot > > accidentally be compiled out. > > > > Suggested-by: Markus Armbruster > > Signed-off-by: Stefan Hajnoczi > > --- > > contrib/vhost-user-gpu/vhost-user-gpu.c | 6 +++++- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c > > b/contrib/vhost-user-gpu/vhost-user-gpu.c > > index a019d0a9ac..534bad24d1 100644 > > --- a/contrib/vhost-user-gpu/vhost-user-gpu.c > > +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c > > @@ -1044,7 +1044,11 @@ vg_get_config(VuDev *dev, uint8_t *config, uint3= 2_t > > len) > > { > > VuGpu *g =3D container_of(dev, VuGpu, dev.parent); > > > > - g_return_val_if_fail(len <=3D sizeof(struct virtio_gpu_config), -1= ); > > + if (len > sizeof(struct virtio_gpu_config)) { > > + g_critical("%s: len %u is larger than %zu", > > + __func__, len, sizeof(struct virtio_gpu_config)); > > >=20 > g_critical() already has __FILE__ __LINE__ and G_STRFUNC. I did this for consistency with the logging in this source file. The other g_critical() calls in the file also print __func__. Stefan --Nq2Wo0NMKNjxTN9z Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAl/ItRcACgkQnKSrs4Gr c8iQrggAw81svgufowONVz8bTsRVJAwCrV9yvz2t23bZwA5T0eQa91ywhZJXDTEp 4r8j0mXHN87hTLoMNKNVdXe4IEqBsDZDXKQC2+quZ8f5yEZ9MS6adyz0dn2vpkX7 MnVRm53xmQCWbu8s5h98v3Y7PcYIYi77OeA8Ue4PG2oLeGwVlxMSmUXlnRPwRWrZ GfTWhyS3tJEBSw/pjT+LBIQdotDRRhCkgdVpY5P3R8cXZUUW6zrfmqtZV6K3T7Nx TayThFtlCZXA7lvjBTtqKG701gf9TF68yrc5jPDZ0EfaEoovQfnFTjUEnaXcrx3t A3m/uGcglq34jNMnbmm+5RVkp7DFsQ== =vRGU -----END PGP SIGNATURE----- --Nq2Wo0NMKNjxTN9z--