Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp935709imu; Thu, 13 Dec 2018 06:55:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vjtn3mUT+wC7VOyrTWdssV9q+9d0ITImcCZtkgviYL+dFu7B3iInKAvSBOsjEn2YeOnYEc X-Received: by 2002:a62:7086:: with SMTP id l128mr24227828pfc.68.1544712913261; Thu, 13 Dec 2018 06:55:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544712913; cv=none; d=google.com; s=arc-20160816; b=Hb5i3aV4NC5G9FRS7/4NLzMbvAHvvyorEcqusmihaiAqVcfex05hnmuCo70OdljiEH enaVVJsSlvtSK+LxgcrTJwIraAB3wSfp9BeZ++TTWXfBkY0hyt7KmjpfGAQDuM/jzI7h fwTT/1TSLJQic7ti/xaFVcrpSRPaj8z+3PHi1uv3LQTfKNb45ApJH0bNx+y06EObu0Tk oLkLgm9NGC25h0e3qwZ7Tk10JhBdW578853YeDOZoPOmI5qya0zTg0H6I3YO7qa6EBvL p7X+TqM8NqFWnDymDXvUaEymZFVc0wOltnmpailLATBDnEDW5L+uT9KafZ7FsWrRlta2 bk9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=apr9ajPulB+/vBjklnt5A4nG91ck4ul/7aGb1HwbLvI=; b=fNIT80cg/5tkCmLutiR3di1BGzHEInELe8QQsJLFQn2woTA/yxkR//G45xV9DeIlgG LVE+oKlLY5Job/CKo89o0IYeFP+GkkHPEp6mPhDEeZJJ41KBkgnpcSg/4J/+QisFzIBD WqDJB5qWLVafVzf0Z3bQSNgRCX4s0b3kfN2kri3WRK+DGQbU/C1xybQAEwhmUYl3V0m5 60y8DT6sMggtJsIVa/34LjkIDLBEc3hl0KCz8GddioVVTrqP8rYdK4u067UCSbypYa52 46+ZvWM82tDCIGQp8KRqzu2BGsvL/b6DSZqgpjRLIN6VCJMj4VHZM74b3rnFskus28GM Gq8g== 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=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si1693604pgl.468.2018.12.13.06.54.55; Thu, 13 Dec 2018 06:55:13 -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=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729258AbeLMOyD (ORCPT + 99 others); Thu, 13 Dec 2018 09:54:03 -0500 Received: from relay.sw.ru ([185.231.240.75]:37262 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728799AbeLMOyB (ORCPT ); Thu, 13 Dec 2018 09:54:01 -0500 Received: from [172.16.24.163] (helo=snorch.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gXSNA-0004sZ-VA; Thu, 13 Dec 2018 17:53:57 +0300 From: Pavel Tikhomirov To: "Michael S . Tsirkin" Cc: Jason Wang , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Konstantin Khorenko , Pavel Tikhomirov Subject: [PATCH] vhost: return EINVAL if iovecs size does not match the message size Date: Thu, 13 Dec 2018 17:53:50 +0300 Message-Id: <20181213145350.5454-1-ptikhomirov@virtuozzo.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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: @@ -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; -- 2.17.1