Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1520560pxb; Thu, 4 Feb 2021 15:32:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJyn10uRpnlPQIPhUC0KbQCVlGRi83Mj+RDqc39Qwdzyjg54/OaEHwxiPOtwBIpU6aSQ1nQu X-Received: by 2002:a17:906:a0c:: with SMTP id w12mr1356759ejf.211.1612481541001; Thu, 04 Feb 2021 15:32:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612481540; cv=none; d=google.com; s=arc-20160816; b=QQa7QjS71VqQUe1D03H7jjFp+dru1RQ2rRYTE1mcTUqhxgKaTcq+oc+ysqSQsjdWgS +LgzK3YcDCxiOaOdNtuV/WVYXxJf+AzAq2Ae9I0+lUm+362pMH+4euEDMZEevgSekelu bqmT7LZIfBmEm1U+7+B5rc26T52+JEhLpVJbB46f+vhNsc+dboyaghfc87W3Ahg+LuLc XnxXY2G+w/GO6ihkr7ujTPpWKWj8bu0R9MIh87OGwiLr0tVD0LUHJkmISEj8gpxvygSn Yw6TMZUdk0WMNMNH4gWydeI1hpncIqT0utEjPrUsNiGhs991w6wJt5RTRm1Oai5ILmJp g4PQ== 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=PC2k5DsAuAqCMx4jOECaSWHG2jS+sWcLS4PYn2OqsJo=; b=vO8c/dZkQnhSdzyOgBjGZNMkQFK84hAcv6fvlLHanl5ia78chzgfXthMqn4PhfaY2T GEOMlDhMgLDgQxwz5iFgS6VK52ULMznxPPOJt/FXXxQfIGG2Oh25/MtOlwkbTCWDUo5e umk35cTdPHnH92FUSW/tCyPVwZ20GpCBT3H+Na4nziFA70uchtaH6w+hAVY6Rr0Bh28K jIlF49HZfrJPeVqK/KK1zQIgebYGmmfNHwor5uibq8UnRImML5j/Dh1n7BaMg/s5hh5j +IV5isu9DeUmkkcd4QppampXvxxERq35gbrOeKyGh5GQpxPJPgXFoCz8Xv1g5FyPIskx 199w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G+B1RhgV; 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 l6si4135289edv.68.2021.02.04.15.31.56; Thu, 04 Feb 2021 15:32:20 -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=G+B1RhgV; 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 S234742AbhBDIEA (ORCPT + 99 others); Thu, 4 Feb 2021 03:04:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35095 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234814AbhBDID4 (ORCPT ); Thu, 4 Feb 2021 03:03:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612425749; 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=PC2k5DsAuAqCMx4jOECaSWHG2jS+sWcLS4PYn2OqsJo=; b=G+B1RhgVBFBaRjPu7z4O+DKoyeW8Kz1tdSTRN3xiAhOt5Vw/RSliYpeLqKI3GTBLi0yes0 78jxO/w1ul3+8IokVBFrM5IRX1+eYPr0oWCOxrt0+4QCiO95cdw4MnQvXvx0deGXDM08ya PsmgIg1EdM/ziRX0WLaNZ/zI3xYeAGE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-537-E_OxnF8_PiuwtKGt0MNnAg-1; Thu, 04 Feb 2021 03:02:27 -0500 X-MC-Unique: E_OxnF8_PiuwtKGt0MNnAg-1 Received: by mail-wr1-f71.google.com with SMTP id n18so2194400wrm.8 for ; Thu, 04 Feb 2021 00:02:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=PC2k5DsAuAqCMx4jOECaSWHG2jS+sWcLS4PYn2OqsJo=; b=UDxMOIV3SmaSnb0JrZGfN31Lao66cLxHYvz40/1rQx3/PwS2g4l7o8E3x82Wn9gLbu oxcaYS8k6zeR0veFrhT7H+wY3LrhTf9uqRx4O8Ki4qLMVmAU6CCfxfiAmfCTw4vdB4qf ylTqpWeBjqd1NIPcZFwouKlcnnKgdt/kBYiV+O8IaAnHsoZOqYKFZDGKWmNataiD2WHl TdtLqPPy0juyavVN3iPlSkI0iTxPaAThkWhF1g3ULAR/3+Md6VCHL6IEo7aoajCkxoDt RC4SZiJiHDCZMJ/6fMj9lRNbAGycuMIRGLl1KMliCZKCbOx9b2YcYx91JKz2huu38ixI HPRQ== X-Gm-Message-State: AOAM530R1Vz9cVTbQfy8gdOPT04zdfRzyBFGFWdYVkCyResfj4PD2lDE DBzB+kO8n+Gyn5pWX8WQnv/uftfgP7x/ZJ7sHLyCjhh9u5mj9TeGBXdBpxy5Txk8w/Jp26CYqkR Yq6lY5BM8wgGr59Khv84x+Hzl X-Received: by 2002:a05:6000:143:: with SMTP id r3mr7724276wrx.357.1612425746481; Thu, 04 Feb 2021 00:02:26 -0800 (PST) X-Received: by 2002:a05:6000:143:: with SMTP id r3mr7724253wrx.357.1612425746232; Thu, 04 Feb 2021 00:02:26 -0800 (PST) Received: from steredhat (host-79-34-249-199.business.telecomitalia.it. [79.34.249.199]) by smtp.gmail.com with ESMTPSA id c9sm5443636wmb.33.2021.02.04.00.02.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 00:02:25 -0800 (PST) Date: Thu, 4 Feb 2021 09:02:23 +0100 From: Stefano Garzarella To: Stefan Hajnoczi 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: <20210204080223.rkc7zieq34ofs5ku@steredhat> References: <20210128144127.113245-1-sgarzare@redhat.com> <20210128144127.113245-9-sgarzare@redhat.com> <20210202093412.GA243557@stefanha-x1.localdomain> <20210202154950.g3rclpigyaigzfgo@steredhat> <20210203164551.GG74271@stefanha-x1.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210203164551.GG74271@stefanha-x1.localdomain> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 03, 2021 at 04:45:51PM +0000, Stefan Hajnoczi wrote: >On Tue, Feb 02, 2021 at 04:49:50PM +0100, Stefano Garzarella wrote: >> On Tue, Feb 02, 2021 at 09:34:12AM +0000, Stefan Hajnoczi wrote: >> > 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) :). >> >> Perfectly agree on that, so I addressed these things, also following your >> review on the previous version, on the next patch of this series: >> "vdpa_sim_blk: implement ramdisk behaviour". >> >> Do you think should I move these checks in this patch? >> >> I did this to leave Max credit for this patch and add more code to emulate a >> ramdisk in later patches. > >You could update the commit description so it's clear that input >validation is missing and will be added in the next commit. I'll do it. Thanks, Stefano