Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1256084imu; Thu, 13 Dec 2018 11:57:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/VRik/p+EDAq9FQdqjqqjfFJhSC4JBJuYs5nxMuomAIiGH2EsbnOiJP14Le/CrMAl2i6D2s X-Received: by 2002:a63:77ce:: with SMTP id s197mr124990pgc.89.1544731021282; Thu, 13 Dec 2018 11:57:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544731021; cv=none; d=google.com; s=arc-20160816; b=PFXy+OUBQbFsHdEbZTRdEdBVl7wFAO63EbXZJ3nHrwJGsQLukPHvWNZNuPXKoHta+V nYxJEhTDBCBLUkHqDQJ0lnSQ2OOZohW2coYzzBpyoV2UX/ms2NEvLraF1wUAXFhEzcaB UjNEr+dksvgUangZYwnzkkPp8DHszvedHmp6ViLTO+kKgNEON8lB0Np6spj2XVDtFNKH 1kpNxaiWxjQw+5QWW1m8edBZvoOkn9odlP6vD1kW82QFkOPzXnU5cuKgt61ms0FxwQ0F ml1QdrkBVuxBmRrWASua60e6pIVYd2X3s+lTsNx8nnOfFZusmMsbkU0qkaIqxX4CX1AL wIxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=w2xTyd2YB/rcOio/Z7VOIQ/F0cZfk1rp91a36bJMotw=; b=Muz8dWV0bOVrFIim/+i67UR3vx+kA5IVjb+Bfg0qmmaPPLx+ooUAyUhTCBouqlVoJs hfixGNRNkUqLl3FVuE/smtw7dm1jpYESTlESaaT4eNluXoCXFK+0zl3Ol5eBrZadLMTu HJYEHGszPDNk1rcvU7MrOQAaYV9RW/S1fxz9X2pxtIjJG9W7IGZae351SgdTIy0tJAeG cRP7iMPKqIy1dMz+IOEROW23J5Szhyo2ei5BdpVKJDwxc1mw870Qbgj0/QIn4Lj8nvUy SAltcfN2Y72OrbikT6J1puEWLWF3wHpFlE9itlQWy4OA/ehI52pXWcqtIU5Bpj3P4Lmv 54Bw== 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 r12si2188266pgl.350.2018.12.13.11.56.46; Thu, 13 Dec 2018 11:57:01 -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 S1729163AbeLMTzU (ORCPT + 99 others); Thu, 13 Dec 2018 14:55:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58664 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728069AbeLMTzT (ORCPT ); Thu, 13 Dec 2018 14:55:19 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7FAF93082204; Thu, 13 Dec 2018 19:55:19 +0000 (UTC) Received: from redhat.com (ovpn-120-21.rdu2.redhat.com [10.10.120.21]) by smtp.corp.redhat.com (Postfix) with SMTP id 6FB351057FA2; Thu, 13 Dec 2018 19:55:18 +0000 (UTC) Date: Thu, 13 Dec 2018 14:55:17 -0500 From: "Michael S. Tsirkin" To: Pavel Tikhomirov Cc: Jason Wang , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Konstantin Khorenko Subject: Re: [PATCH] vhost: return EINVAL if iovecs size does not match the message size Message-ID: <20181213143426-mutt-send-email-mst@kernel.org> References: <20181213145350.5454-1-ptikhomirov@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181213145350.5454-1-ptikhomirov@virtuozzo.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 13 Dec 2018 19:55:19 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 13, 2018 at 05:53:50PM +0300, Pavel Tikhomirov wrote: > We've failed to copy and process vhost_iotlb_msg so let userspace at > least know about it. For instance before these patch the code below runs > without any error: > > int main() > { > struct vhost_msg msg; > struct iovec iov; > int fd; > > fd = open("/dev/vhost-net", O_RDWR); > if (fd == -1) { > perror("open"); > return 1; > } > > iov.iov_base = &msg; > iov.iov_len = sizeof(msg)-4; > > if (writev(fd, &iov,1) == -1) { > perror("writev"); > return 1; > } > > return 0; > } > > Signed-off-by: Pavel Tikhomirov Thanks for the patch! > --- > drivers/vhost/vhost.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > index 3a5f81a66d34..03014224ef13 100644 > --- a/drivers/vhost/vhost.c > +++ b/drivers/vhost/vhost.c > @@ -1024,8 +1024,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev, > int type, ret; > > ret = copy_from_iter(&type, sizeof(type), from); > - if (ret != sizeof(type)) > + if (ret != sizeof(type)) { > + ret = -EINVAL; > goto done; > + } > > switch (type) { > case VHOST_IOTLB_MSG: should this be EFAULT rather? > @@ -1044,8 +1046,10 @@ ssize_t vhost_chr_write_iter(struct vhost_dev *dev, > > iov_iter_advance(from, offset); > ret = copy_from_iter(&msg, sizeof(msg), from); > - if (ret != sizeof(msg)) > + if (ret != sizeof(msg)) { > + ret = -EINVAL; > goto done; > + } > if (vhost_process_iotlb_msg(dev, &msg)) { > ret = -EFAULT; > goto done; This too? > -- > 2.17.1