From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796039721; b=1XBHqi9RWuQPNUOC2pXp4j1rr+ZrDRHrVg886XD2ByfU+OvsBEmrWspLRXPs2T8H9pge S9Tia/RQF8jzZQ8mXROe8InAyp0cD/XOTh8rHgj6m1Dkg+ApfBxHIpgPk3e0bzCcpsJiU 2aJtlhk15ZqpYjNN3mVPy5ALUzqf+ALdoU1g2Uj0BVjhqcTbGemkI281aFMEo1eYqX/Kz K4NGWJiViI60FC6PEJ5U4bXt+Hvo2aerBEMV89ly0EZ0HNsVk7ANAKGXg5iF9dfPay8rV FxuvMrJ7QieOZ/dDaji4ghx9RGMrwd9IpireSguQUF0hZ1SGWg1O+5571/wmu5hmK7w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796039721; h=DMARC-Filter:DKIM-Signature:X-MC-Rep:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: X-Received:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:In-Reply-To:X-Mimecast-Spam-Score:X-Mimecast-MFC-PROC-ID: X-Mimecast-Originator:Content-Type:Content-Disposition: Content-Transfer-Encoding; bh=davxXD30rUVEhtFFHAtXAiePdHBREq3AvAAyw8zfAu4=; b=a3zlDPusksNRpLkiwUQTafRmEzKR9vQ0oeJbI7y6qUUYRDeb/jPQeh1qbi9Vmjgzh0ax 1wZNHSgIgeR830bERPH3VIq2frSNev0Kd1ObZ8ayMtRD+ZcCtyt1FbqU92hoUlUqdl+ko v06tC81bjfB0W/h1DML/qAu6tA8w9g3LwNXaObo+/3NuOvm3CFjKIyTjdukAGT6LUrXeF VlQbS2sw4JkpzGIQckdXCSXZUiztXZe1ydvFH4hk0+prtqUP8A2daOxL7rR5IHEoluA4G tJXRn1JyAKB7ZpJ7b91o5dIMmS+5EyDrpwAcNoo+JmH5BjxcAuidVqZjP2Sux/Wi57A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Id9EYhgG; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6307606A31C for ; Mon, 30 Nov 2026 11:55:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C6307606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Id9EYhgG DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796039720; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=davxXD30rUVEhtFFHAtXAiePdHBREq3AvAAyw8zfAu4=; b=Id9EYhgGWYBwgRBsO/FAqz7GaLa+TTODI5CvUwIWECHXcwDAGEmJHUw2tV0GhChNiSs9kf 6RojNkBWAjhaBLl7jVysK990EJf3FbXLrm91QHgPHVxkDumruRek/LFn8gabZ/piFdeURC qufS3s3814oCmdbAcfGgUA084o6wLMw= X-MC-Rep: binary re single Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-327-Dz_a8PmoPua1ssfBydKWag-1; Mon, 30 Nov 2026 11:55:18 +0000 X-MC-Unique: Dz_a8PmoPua1ssfBydKWag-1 X-Mimecast-MFC-AGG-ID: Dz_a8PmoPua1ssfBydKWag_1796039717 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4aae099f5baso5145702f8f.1 for ; Mon, 30 Nov 2026 03:55:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796039717; x=1796644517; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=davxXD30rUVEhtFFHAtXAiePdHBREq3AvAAyw8zfAu4=; b=auXoLzW4yW45RsdWo2a5nSQ4akmqGoidNmpKeyGkaUF5baKcac4QFSaQRj5W3CrcTx n4el6Eel1f0UvZzKHnAqxK+HhK0lyxs2soTQGqSEMRGkWtw7b8XItwUhMMiR8KSASOUD DEiiOf+fSiVSoOr3scvUTfLbpf+z9L3YfQ1cgRnETLoEzF7uC9FobeK5YfcwJhzL8pUN q7Ici/4OjcnvSSPff26BCL4n2fhLfSRMk8Z2NuaAC78vGo4NPvMfnn/ClfT6B0AIv7Dg hN1dkwQ05+cOjMO9tcGNQW+ZviHw4l9J9Hox+Q3H9Y8bbSjmNAEALXVCMGuMXVJYQCgh Buvg== X-Forwarded-Encrypted: i=1; AL+hErFJDcMMQEvoqpBIA+rQfo4HwAt561kNpSvF/0UvtgsGZLs+3sHF5NQEqGpuJzJcVD1T54wBKmsND8OeYADeag==@lists.linux.dev X-Gm-Message-State: APuU4Z/Ow/vU4lwtSmBhbetMNMh8SOgr+AVrIAMxnFWTFDohYEJ7LP8/ 5gr7giLrVnBQ08Sst2C3rz/vbGBc/zIQCgE5dMB/I6uZR6zq2WUN4+nZq2f+uA9QlKQoq49r3y8 AsoaHy4XuZLcog3TQBwUrxIQF2Keio9Xbc4+KlNF7T6P9lTVxAq13deMfFRgsLPxdCftJ X-Gm-Gg: AZFdTZcSmThcGxXqLFAmbW7RIYl9X51RW2PfMXZqa3gj48tiU2DArFB86fk8h50FzuO GiMyviuSr5Y3e9gNzSLTaSzr+pUPMw9+8vkoVYmNyIRue3p+P8qhI5Pk0jZgZSk/AlPrF5w0K6P WzqankLwCK2lVaif3hgGPuDOAyPb3r8fzEys9WNu7ZdKP37hezBElJc0v9XwcukxY0K02SyMK+i k37/Bx8o1Nn1KXw3Ay2C0aeNsp46WRaIi/1j/zBcZSS1fZLjOI88wc4jKJoaJPewu9U1x4TrBGj SMMZPCLbJ1QU1LDC47UC7bGQnSmA5rJKqGtXOecko3CGwGU+QejYgytfeDNlxhgN7142B4kUv0/ BBXNg4my2RGWdOcCkYAljWPMTTvOZAhAXZD46dveT9w0= X-Received: by 2002:a5d:6691:0:b0:4a6:c3f:9d0e with SMTP id ffacd0b85a97d-4abb3d2c0bemr48124190f8f.44.1796039716469; Mon, 30 Nov 2026 03:55:16 -0800 (PST) X-Received: by 2002:a5d:6691:0:b0:4a6:c3f:9d0e with SMTP id ffacd0b85a97d-4abb3d2c0bemr48124153f8f.44.1796039715852; Mon, 30 Nov 2026 03:55:15 -0800 (PST) Received: from redhat.com ([2a0d:6fc0:1529:2e00:86ec:bef7:c309:ba1f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab658e2d60sm65140669f8f.3.2026.11.30.03.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 03:55:15 -0800 (PST) Date: Mon, 30 Nov 2026 06:55:12 -0500 From: "Michael S. Tsirkin" To: Eugenio Perez Martin Cc: Seojin An , Jason Wang , Xuan Zhuo , virtualization@lists.linux.dev, security@kernel.org Subject: Re: [PATCH] virtio_ring: reject unrepresentable split indirect tables Message-ID: <20261130065152-mutt-send-email-mst@kernel.org> References: <20261126080209.2898344-1-love09010224@uos.ac.kr> <20261126032258-mutt-send-email-mst@kernel.org> <20261126062833-mutt-send-email-mst@kernel.org> X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: iR97fYON0eulTtbdKVeBMBbPY_3FQrhpy79I-6tmIZs_1796039717 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Mon, Nov 30, 2026 at 09:51:08AM +0100, Eugenio Perez Martin wrote: > On Thu, Nov 26, 2026 at 12:29 PM Michael S. Tsirkin wrote: > > > > On Thu, Nov 26, 2026 at 09:41:31AM +0100, Eugenio Perez Martin wrote: > > > On Thu, Nov 26, 2026 at 9:24 AM Michael S. Tsirkin wrote: > > > > > > > > On Thu, Nov 26, 2026 at 09:14:36AM +0100, Eugenio Perez Martin wrote: > > > > > On Thu, Nov 26, 2026 at 9:02 AM Seojin An wrote: > > > > > > > > > > > > Split descriptors store the next index as u16. alloc_indirect_split() can > > > > > > allocate a larger table, but virtqueue_add_split() feeds the truncated next > > > > > > value back into its construction index. With more than 65,536 SG entries, > > > > > > the index wraps and later entries replace descriptors at the start of the > > > > > > table. The device then consumes a chain different from the caller's SG > > > > > > sequence. > > > > > > > > > > > > Reject split indirect tables whose entry count exceeds the representable > > > > > > index range. Keep the existing compatibility policy that permits > > > > > > representable indirect chains longer than Queue Size, and leave packed > > > > > > indirect descriptors unchanged. > > > > > > > > > > > > A virtio-gpu render client can reach this condition with a vmalloc-backed > > > > > > EXECBUFFER. In a no-vIOMMU QEMU/virgl guest, the resulting command > > > > > > substitution provided guest physical read/write and initial-namespace > > > > > > uid/euid 0. The virtio-gpu producer needs its own Queue-Size check because > > > > > > its current queue error path warns about an add failure but advances > > > > > > pending state and reports success. > > > > > > > > > > > > AI tools assisted the source audit, reproducer construction and patch > > > > > > drafting. > > > > > > > > > > > > Fixes: 9fa29b9df32b ("virtio: indirect ring entries (VIRTIO_RING_F_INDIRECT_DESC)") > > > > > > Reported-by: Hyeonjun Hong > > > > > > Reported-by: GEONWOO HAN > > > > > > Cc: stable@vger.kernel.org > > > > > > Signed-off-by: Seojin An > > > > > > --- > > > > > > drivers/virtio/virtio_ring.c | 14 ++++++++++++-- > > > > > > 1 file changed, 12 insertions(+), 2 deletions(-) > > > > > > > > > > > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > > > > > > index f683a2d6a2002..ad9e52584fb52 100644 > > > > > > --- a/drivers/virtio/virtio_ring.c > > > > > > +++ b/drivers/virtio/virtio_ring.c > > > > > > @@ -686,9 +686,19 @@ static inline int virtqueue_add_split(struct vring_virtqueue *vq, > > > > > > > > > > > > head = vq->free_head; > > > > > > > > > > > > - if (virtqueue_use_indirect(vq, total_sg)) > > > > > > + if (virtqueue_use_indirect(vq, total_sg)) { > > > > > > + /* > > > > > > + * The core historically permits an indirect chain to exceed the > > > > > > + * queue size. Preserve that policy, but do not let its 16-bit > > > > > > + * split descriptor links wrap within the allocated table. > > > > > > + */ > > > > > > > > > > Seems like the same code path in the packed vqs also needs this check? > > > > > > > > > > Also, a question for everybody: is it really too late to forbid > > > > > indirect tables bigger than the queue size? It is not guaranteed that > > > > > the device will be able to handle it anyway, should we just add a if > > > > > (total_sg > vq.split.vring.num) return -E2BIG? > > > > > > > > It's not too late in that the spec forbids it. But a bunch of drivers > > > > are broken, so for now the best place for this check is in the driver. > > > > > > > > > > Doesn't it make sense to add in virtio_ring as hardening? Fewer places > > > where we can miss the check. > > > > > > We can't because we don't know what will break. > > > > Ok, what about spanning the change across two releases? > > In the next release (7.5) prefix each individual call to add_sgs and > similar gets prefixed with the sanitization in individual patches, so > we can catch and revert individual drivers in -rc window. Then, move > the hardening to the virtio core in the release afterwards (7.6). > > Would that work? No because it takes much longer for this to reach users. Pls let it be, there is no reason to make random changes for the sake of a theoretical "hardening" unless it is hardening against a wide class of attacks. if we have void foo() { if (a < MAX) bar(a); } then adding void bar(int a) { + if (a >= MAX) + return; } is not hardening, it's dead code. -- MST