Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp656204pxb; Tue, 2 Feb 2021 14:33:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdVjd3A03G6yFm+PepyUWy+ALVPdk/A0BY9MxMAq+B60xFXAL/MjGXSXjBcx2+NlMMzgXw X-Received: by 2002:a05:6402:4316:: with SMTP id m22mr302449edc.64.1612305211724; Tue, 02 Feb 2021 14:33:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612305211; cv=none; d=google.com; s=arc-20160816; b=mS3jdBq3TFejBn3Z/ahAjS5RtKmoFuTXOuT6b6iAiIfXvEqGT84m8K+KS7eXos43qr RD441rXQmf78nVIo27D5wkVpLfT1ZZCiHPnsxdXbcSjLvaTA3md1Wzrg2DCSepq9H2Oy Oa5fdyVgOUmB8v0Au4du9wzJXx3+KaW7FAnMlTLQq4Y3H9ab0Bw/jwqztvCxVts55snC ciLNE+rex0GQCS12pDcvFBYcOdCa23zrMdKyPTDVcMQsScsSMb8B8C7GHHViujwio9jq rUWEII3X7oKjdUK7Fg0WBdD61wv8KBM+iqILxz9HsmDmLCzcH4Rta8f7W+849XK0b8Q3 7DVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=lA/rmyOorAoy/w+AhxxsEsI+Afad/+5GXMgJ3Bkqofw=; b=yCqYqoaBa2QEFvo1C6xOQYroQHC7+ZrxOgoSfloXEuKnXGITx+VJlWewpzkFUh13ds PsOzd1LnLG/OLuJOdapQjP7x/y3O5TgrhGgsESzZwee1W/hPXQAIz+8zPlssmmogKIbV OacP6++hGvHpWAg/Gab3Z19pxWkb2HRiPH5ZREhVJ6VogofsMpNxaSJ6KkkZadg8m9+H VL9x4fICMT2hgtKUBU0gbIb6ssKbb2qEBv7DTJzLF6w86ufFv+6nKUuoyN5caNCf2hM9 dwtjCi8PeGPjeb6IPd6uehSUiN96Hwi/FMR7nQPnGzwmCuikYhIuPdMHkT3oTWZyc3dY aqIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Mi1C5vRE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x21si131611ejy.280.2021.02.02.14.33.06; Tue, 02 Feb 2021 14:33:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Mi1C5vRE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231556AbhBBPCa (ORCPT + 99 others); Tue, 2 Feb 2021 10:02:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52534 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234656AbhBBPBM (ORCPT ); Tue, 2 Feb 2021 10:01:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612277985; 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=lA/rmyOorAoy/w+AhxxsEsI+Afad/+5GXMgJ3Bkqofw=; b=Mi1C5vRE6z6ij+Om986/MeORS3INRNwZ0S/DBN2nt8K/ybaIu8GVxTCUM+zMaEDLQhaKl+ Gi/9tXIKBdxTkgq6ZAGevZD0uLzKrI+Qwq6IuNod2NfkyEScYwhJQG9a3fWeZZ11figcDs e7Gu3jnVjLMYTjHTGmIlYvqtTm6buUM= 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-121-AHW_jZeEPuiICXhvtzL4ew-1; Tue, 02 Feb 2021 09:59:42 -0500 X-MC-Unique: AHW_jZeEPuiICXhvtzL4ew-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 74A82800D55; Tue, 2 Feb 2021 14:59:39 +0000 (UTC) Received: from localhost (ovpn-115-185.ams2.redhat.com [10.36.115.185]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7644F6EF41; Tue, 2 Feb 2021 14:59:35 +0000 (UTC) Date: Tue, 2 Feb 2021 09:34:12 +0000 From: Stefan Hajnoczi To: Stefano Garzarella Cc: virtualization@lists.linux-foundation.org, Xie Yongji , "Michael S. Tsirkin" , Laurent Vivier , linux-kernel@vger.kernel.org, Max Gurtovoy , Jason Wang , kvm@vger.kernel.org Subject: Re: [PATCH RFC v2 08/10] vdpa: add vdpa simulator for block device Message-ID: <20210202093412.GA243557@stefanha-x1.localdomain> References: <20210128144127.113245-1-sgarzare@redhat.com> <20210128144127.113245-9-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="huq684BweRXVnRxX" Content-Disposition: inline In-Reply-To: <20210128144127.113245-9-sgarzare@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --huq684BweRXVnRxX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Jan 28, 2021 at 03:41:25PM +0100, Stefano Garzarella wrote: > +static void vdpasim_blk_work(struct work_struct *work) > +{ > + struct vdpasim *vdpasim = container_of(work, struct vdpasim, work); > + u8 status = VIRTIO_BLK_S_OK; > + int i; > + > + spin_lock(&vdpasim->lock); > + > + if (!(vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK)) > + goto out; > + > + for (i = 0; i < VDPASIM_BLK_VQ_NUM; i++) { > + struct vdpasim_virtqueue *vq = &vdpasim->vqs[i]; > + > + if (!vq->ready) > + continue; > + > + while (vringh_getdesc_iotlb(&vq->vring, &vq->out_iov, > + &vq->in_iov, &vq->head, > + GFP_ATOMIC) > 0) { > + int write; > + > + vq->in_iov.i = vq->in_iov.used - 1; > + write = vringh_iov_push_iotlb(&vq->vring, &vq->in_iov, > + &status, 1); > + if (write <= 0) > + break; This code looks fragile: 1. Relying on unsigned underflow and the while loop in vringh_iov_push_iotlb() to handle the case where in_iov.used == 0 is risky and could break. 2. Does this assume that the last in_iov element has size 1? For example, the guest driver may send a single "in" iovec with size 513 when reading 512 bytes (with an extra byte for the request status). Please validate inputs fully, even in test/development code, because it's likely to be copied by others when writing production code (or deployed in production by unsuspecting users) :). --huq684BweRXVnRxX Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmAZHJQACgkQnKSrs4Gr c8iMOQf9Ei+h8ZIngw9GkwH+ynl8uKorG3xB/0jyLQbEMG1hN8mcKrP21stVX6pi gioFVSxs+cZ1ZNS3HaBPzjbzA9nUVPuppl2lSmYkzbRJo85gr4mGMql8Z5ZS0zhf A+bq8NmikaxZuEDybVc7jhNSpOd+mPSBoQv7fn6q31E8cGMnmzaZuOmRfPvATbXO JMXQojrahx/RxvAjj27CKng+eMgLQm8dfmFvJ71cB3Qdgq4y65qCFRY41FTyA9fa RGJo1b8gYSYXLoaYcUVumCz03afY3d7JYVtD+sdkn8lCerx+igLlHc4ZUrTgxioI h1lxVCzYIYQAthUlKGGaPLSQ/cHRBQ== =Sk9g -----END PGP SIGNATURE----- --huq684BweRXVnRxX--