All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hyokyung Kim <pulpannie@gmail.com>
To: stable@vger.kernel.org
Cc: Sasha Levin <sashal@kernel.org>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	Hyokyung Kim <pulpannie@gmail.com>
Subject: [PATCH 6.1.y] virtio_net: clamp rss_indir_table_size to VIRTIO_NET_RSS_MAX_TABLE_LEN
Date: Fri,  3 Jul 2026 19:52:56 +0900	[thread overview]
Message-ID: <20260703105256.3884798-1-pulpannie@gmail.com> (raw)
In-Reply-To: <stable-reply-item007-virtio-rss-20260630181642@kernel.org>

virtnet_probe() reads rss_max_indirection_table_length from the device
config space into vi->rss_indir_table_size and later uses it as the
number of entries to write into the fixed-size 128-entry indirection
table in struct virtio_net_ctrl_rss (in virtnet_init_default_rss(), and
again in virtnet_set_rxfh()/virtnet_get_rxfh()), without validating it
against VIRTIO_NET_RSS_MAX_TABLE_LEN. A malicious or buggy device can
report a length larger than 128 and overflow the array, corrupting
adjacent slab memory. This is reachable at probe time, before the
interface is brought up.

This was fixed upstream by commit 86a48a00efdf ("virtio_net: Support
dynamic rss indirection table size"), which reworks the driver to
allocate the indirection table dynamically. However that change is too
large to backport to stable. Instead, clamp the device-advertised length
to VIRTIO_NET_RSS_MAX_TABLE_LEN: this solves the overflow with minimal
changes.

Fixes: c7114b1249fa ("drivers/net/virtio_net: Added basic RSS support.")
Signed-off-by: Hyokyung Kim <pulpannie@gmail.com>
---

Hi Sasha,

You asked for a tested backport of 86a48a00efdf to 6.6.y and 6.1.y.
While preparing it I found the code does not backport cleanly (there
are many lines needed to change). To minimize the risks of introducing
new bugs, instead I added a small 6-line bounds check on the length the
driver reads from the buggy or malicious device. Sending one patch per
tree.

Tested with KASAN + UBSAN under QEMU (guest 6.1.176), using a virtio-net
device that advertises rss_max_indirection_table_length=512, i.e. larger
than the driver's 128-entry VIRTIO_NET_RSS_MAX_TABLE_LEN.

Before this patch, virtnet_probe() overflows the fixed indirection_table[]
at boot:

  BUG: KASAN: slab-out-of-bounds in virtnet_probe+0x11a2/0x1580
  Write of size 2 at addr ff11000004130d60 by task swapper/0/1
  CPU: 1 PID: 1 Comm: swapper/0 Not tainted 6.1.176 #1
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014
  Call Trace:
   <TASK>
   dump_stack_lvl+0x37/0x4a
   print_report+0x181/0x49e
   kasan_report+0xc9/0x150
   virtnet_probe+0x11a2/0x1580
   virtio_dev_probe+0x2da/0x470
   really_probe+0x12f/0x390
   __driver_probe_device+0xfa/0x1a0
   driver_probe_device+0x49/0x190
   __driver_attach+0xdd/0x290
   bus_for_each_dev+0xf5/0x150
   bus_add_driver+0x26e/0x2c0
   driver_register+0x10c/0x1a0
   virtio_net_driver_init+0x6c/0x93
   do_one_initcall+0x9e/0x2c0

After this patch the length is clamped, the device still probes, the boot
is clean (no KASAN report), and ethtool -x reports a 128-entry table:

  virtio_net virtio0: rss_max_indirection_table_length=512 exceeds max 128, clamping

 drivers/net/virtio_net.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index b62b76963137..c840e6a55d86 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -3913,6 +3913,12 @@ static int virtnet_probe(struct virtio_device *vdev)
 		vi->rss_indir_table_size =
 			virtio_cread16(vdev, offsetof(struct virtio_net_config,
 				rss_max_indirection_table_length));
+		if (vi->rss_indir_table_size > VIRTIO_NET_RSS_MAX_TABLE_LEN) {
+			dev_warn(&vdev->dev,
+				 "rss_max_indirection_table_length=%u exceeds max %u, clamping\n",
+				 vi->rss_indir_table_size, VIRTIO_NET_RSS_MAX_TABLE_LEN);
+			vi->rss_indir_table_size = VIRTIO_NET_RSS_MAX_TABLE_LEN;
+		}
 	}
 
 	if (vi->has_rss || vi->has_rss_hash_report) {
-- 
2.43.0


  parent reply	other threads:[~2026-07-03 10:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30  0:51 [LTS Backport Request] Fix RSS indirection table OOB write (6.1.y, 6.6.y) Annie Kim
2026-06-30 22:23 ` Sasha Levin
2026-07-03 10:50   ` [PATCH 6.6.y] virtio_net: clamp rss_indir_table_size to VIRTIO_NET_RSS_MAX_TABLE_LEN Hyokyung Kim
2026-07-04  2:05     ` Sasha Levin
2026-07-06  5:48       ` Annie Kim
2026-07-03 10:52   ` Hyokyung Kim [this message]
2026-08-20 13:49     ` [PATCH 6.1.y] " Greg KH
2026-08-21  4:33       ` Sasha Levin
2026-07-10 11:19 ` [PATCH 6.6.y] virtio_net: Support dynamic rss indirection table size Hyokyung Kim
2026-07-10 21:03   ` Sasha Levin
2026-07-10 11:25 ` [PATCH 6.1.y] " Hyokyung Kim
2026-07-10 21:03   ` Sasha Levin
2026-07-10 12:49 ` [PATCH 6.6.y] " Hyokyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260703105256.3884798-1-pulpannie@gmail.com \
    --to=pulpannie@gmail.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.