Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3854124pxv; Mon, 19 Jul 2021 10:18:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyg3VGg6i+G6dxF/NH/kQuuDbGFfDjyWZq5Ggc7ZzEqFO95obboHdALO7N80RI7Dt/DIFx/ X-Received: by 2002:a05:6e02:d93:: with SMTP id i19mr5870346ilj.72.1626715114777; Mon, 19 Jul 2021 10:18:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626715114; cv=none; d=google.com; s=arc-20160816; b=P0X2608eEVc+Ny2kVC5JXLajDO+lcI7KrrYQMAY99p5o1hzroOkVl4+RWHnIUjO/4o kE/99k5xsL0QQE0MvOVbJYZXiVphps5iHgFfdWrD7GeFdrpTAmmrXsUVOJpNtd1oil5M 2FCzo9aQCTpcMs5ppVt9D8l/4zFFAGtzZ4qcwtgmC+9x8daDeuSwJrSgq2pIi6Z/gbC9 r02fni1VAubCjqBuAlP3xx5T6ml1LWrFVZ96ZLZ51DK2oZNXHcLKh7+hFR3928pt5SEQ 6YX7qfm9iPrW+2JXFvUBHk86OhqmEgns4i+ydTRFrBMcnYD5LFrTchGggB1Kw0k5Sd6w +PAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tAFjmVKkqz116NUbbTBjLONZsxNalnSmgXDhLhS6nSI=; b=gulPEjJ98wGJAWlJjvKkVlkviE4FKDpjl+/cTBy4Dkw3XH3PedNy/1HTra6oHE2/nM nWiWyzJd8CPFHFCBYkIWPBjSn1lIF86lj7IqX7bqfHQk3kU9/Hx2Z4YJdGcbmgrpuD0I QN1/ZM1l55vwkBAQcXWcsWd7LZUXEzYsC71sIGeVpdROqdaDnydIaa9LE5cuPiNMXc1s rVcpS5erapv9RGMmqAkzdgZ+RztmElapBOMo8ksAthDQFZMeHvUVRMNgFTr5YMgmvdhQ rp324ui0ehndIEl2ZD0s6CsTAY2/gryfD4bGcMhKA7wWJmUkLaGDGcMnYsjQLYGDmpdz gd+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Qdxpu+IC; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z25si9806098iod.45.2021.07.19.10.18.22; Mon, 19 Jul 2021 10:18:34 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=Qdxpu+IC; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353284AbhGSQfB (ORCPT + 99 others); Mon, 19 Jul 2021 12:35:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:59754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347588AbhGSPTv (ORCPT ); Mon, 19 Jul 2021 11:19:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 94D2861418; Mon, 19 Jul 2021 15:58:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626710333; bh=HOxSyPrt04JCbP6msvV7QklAOcAnbKgXxpTQnRh46tI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qdxpu+ICOkkMnD2csJFsDlHLcfE6d1TmWS2yh5w1LmRaKojwPdUPiumZ0blHsXche jksw59/NmKGKwiO1sKDov79R26br1RNBOs/g5t0zDhotqI6ghTvHsRLpmc5PBCsrf7 IHzSj5qw3xl1ECDceKsing/ULvvPLENRsH1weu8o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xie Yongji , Jason Wang , "Michael S. Tsirkin" , Sasha Levin Subject: [PATCH 5.10 145/243] virtio_console: Assure used length from device is limited Date: Mon, 19 Jul 2021 16:52:54 +0200 Message-Id: <20210719144945.591213011@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.904087935@linuxfoundation.org> References: <20210719144940.904087935@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xie Yongji [ Upstream commit d00d8da5869a2608e97cfede094dfc5e11462a46 ] The buf->len might come from an untrusted device. This ensures the value would not exceed the size of the buffer to avoid data corruption or loss. Signed-off-by: Xie Yongji Acked-by: Jason Wang Link: https://lore.kernel.org/r/20210525125622.1203-1-xieyongji@bytedance.com Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/char/virtio_console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 1836cc56e357..673522874cec 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -475,7 +475,7 @@ static struct port_buffer *get_inbuf(struct port *port) buf = virtqueue_get_buf(port->in_vq, &len); if (buf) { - buf->len = len; + buf->len = min_t(size_t, len, buf->size); buf->offset = 0; port->stats.bytes_received += len; } @@ -1712,7 +1712,7 @@ static void control_work_handler(struct work_struct *work) while ((buf = virtqueue_get_buf(vq, &len))) { spin_unlock(&portdev->c_ivq_lock); - buf->len = len; + buf->len = min_t(size_t, len, buf->size); buf->offset = 0; handle_control_message(vq->vdev, portdev, buf); -- 2.30.2