From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44ACA3019C3 for ; Sat, 25 Jul 2026 13:23:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784985783; cv=none; b=PAAGjgpgdC8YpbS4IMt8zYhXAG8ufvExytjU2xJ2DS2sbLTYVRZZXXKurgWWDfP4QMZGcpBPe95Nls/4XKOX8lya2NnH40yTYTPyxWgKezYk0Yb9asB7OWG/ojTdduYh6QMHhvL+P/Khk7RzDo4oDh7vkriVD3zWcLQc52KfnDQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784985783; c=relaxed/simple; bh=97xEWqQxd3MflF43LClPkOQcYakWonr25YhX/9+k8g4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=efd+2N8u6KKm55OnYj9CwaM8NOXH0qsT56a6kEsMhV3Ex5udW72s0N/5j9xV6AkqsQo52/xU22xDqE3QZbV+W46RM1SflIDz6UrSnRbbp3K3BSxOsWW7uPM9acq/Z7VrKf3QnmcRVKH32NnvAosJk6H2uz6cEpgbpg4h43JMajw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Dy+PbgFA; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Dy+PbgFA" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5b021916bd3so1430602e87.3 for ; Sat, 25 Jul 2026 06:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784985780; x=1785590580; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=sIDqT1SiBF4RoBKhu5UCLRHokUDL3DRTBfD3SKYOjqE=; b=Dy+PbgFAmDMpHkfXRRemm/zrDSlmVMf1SPDrDfFX5S8ku2zIBVIlb5PQFyeQEKmhfy FifyCR0gAaXFmoWJF/yX+DE5XJNkkQQ9nhbHXcncLzg28z7RYR1tHe+khNJ5OkbKgBgi Q+H9bC3sVR014gTxqH6iu0eGJUZZh6DPiSUx+kS1nqGGnI7mde37lg5k18TJw9TiO/Qw g8OtGddk4L0fNAglc9Z48GVOwuZgudrZqaM3s5Ot5RmUZ8D/Ybxbm/GxMOTYp5fnubyd wYSKMpvRpO7WTd4829PK2E7OzqsUTtqNfu6TmuYQPCBq8tiFmCR8GNawERfaroESaCDY Q2yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784985780; x=1785590580; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=sIDqT1SiBF4RoBKhu5UCLRHokUDL3DRTBfD3SKYOjqE=; b=Tq8jy6gc0hMP8J32c34+DtvEBUpqv1huMHwSkjXtIgfyr4en3EHaiDntC3jlTi97bL 5k9iSqXyIpmxM1SOUQmzxaG2XKI13C/IyBImPFYJyf0c1JEnc0OtCQxOa/5mWdtL8wRs Y/7EA0JDxop+IrDU8BworYtBQDmiu5HAXY+UNbsVhsvLGG3uBp1jP/HC2UiZPDDIibAT +a0GfX0JpwN6kD224DdZdNlv6+Bi36957dzU/JwNxNavvFJ4cfQZRkDqbpo8UjEAoMYx PHu7n78q68ZXfRR4tbQsPj2wHb0RHpmu2sArccL6OKmaiXuCGPV8kRw0I6nabCv9dljF IZxA== X-Forwarded-Encrypted: i=1; AHgh+Rp4eb/vNNqvWH3W07IsPICJbt0FMj6Hyr+5eZLAIlTfU2Gul8FmO3FD/OIHl7Z1rrMJkuNIYZflC0F7kFY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxiq4bX9QlefLo19h5lZ6kmJUcXlUOEaMQMilzRW8KrFWu1PSdi 0S15q1kGKhsdxuzSV1b9vQEL0B9+zPIDw0C800ZbezQNEo8atPJQqrLM X-Gm-Gg: AR+sD11maXsrdWx8wUlW8ZaAshDbVHnznmunzFO0MRl24IkEq4xrgzC0YDgbiRi3xWp BNkyDyhmzNF0FSe8wivCqjvahMKZgYyiLiTqtxyd/kvVL9IQ2SPnnOwvLBQydbxTXP0/6TEzisR VAw3gqzYy8rMEMtymjCOYMs0ivTBeK7b2ZTQw1ugf2oQ6Vatk1gmo6GxPkpsWKI/AHtJJ7BnUuC wm+Y50tnQ38mTGkY/aYyySo+u1H5mLcfsOFW1hkdmkJNQcsgTwmYwKq7ZQOvBd2UR4k0psWGBBm 5dijyzItqHQ8gH7F3QWj6yy90xEOnmhi+Ns69nC4M39LJ548ZkPxyv/p35Z7chDsivd7LOxidd6 CEMO/CtqxjFrYIg+Ok7R/xw2bzR2y4/LCYDa/8AZF5KggYDZk267GC1rUrx4G9Ygklyv9wL46h5 C4Udro9Brvc5V5yZCO/wwhpawtHeRNC+50SFfEU7v0cFC3iOINPdXkmYiI++THkPmqspduytTRF z7LxJnXR35kk7I= X-Received: by 2002:a05:6512:2303:b0:5b0:215b:5de8 with SMTP id 2adb3069b0e04-5b2c1b532f4mr365011e87.64.1784985780219; Sat, 25 Jul 2026 06:23:00 -0700 (PDT) Received: from localhost.localdomain (46-138-176-102.dynamic.spd-mgts.ru. [46.138.176.102]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b2be083db1sm434092e87.25.2026.07.25.06.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2026 06:22:59 -0700 (PDT) From: Artem Lytkin To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, jacob.e.keller@intel.com, chrisw@sous-sol.org, linux-kernel@vger.kernel.org Subject: [PATCH net] rtnetlink: truncate IFLA_VFINFO_LIST instead of overflowing its length Date: Sat, 25 Jul 2026 16:22:36 +0300 Message-ID: <20260725132236.88318-1-iprintercanon@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit rtnl_fill_vf() closes the IFLA_VFINFO_LIST nest with nla_nest_end(), which stores the accumulated length into nla_len. That field is a u16, so a nest larger than 65535 bytes is written truncated modulo 65536. The skb is sized by if_nlmsg_size(), which adds rtnl_vfinfo_size() for every VF, so the buffer really is large enough for the whole list and none of the nla_put() calls in rtnl_fill_vfinfo() fails. The overflow is therefore silent. Userspace then walks the message with RTA_NEXT(), which advances by the stored length, so parsing resumes inside VF payload and the top-level attributes that follow the nest are read out of VF data. Those are IFLA_VF_PORTS, IFLA_XDP, IFLA_LINKINFO, IFLA_PERM_ADDRESS and IFLA_PROP_LIST. iproute2 prints "!!!Deficit", and strictly validating parsers reject the message outright. rtnl_fill_vfinfo() emits 296 bytes per VF on a 64-bit kernel with efficient unaligned access, so the nest wraps at 222 VFs; without CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS it is 328 bytes and 200 VFs, and with ndo_get_vf_guid 336 bytes and 196 VFs. ice supports up to 256 VFs per PF (ICE_MAX_SRIOV_VFS), so this is reachable on shipping hardware. Requests that set RTEXT_FILTER_SKIP_STATS need 335 VFs, which the 256-VF limit puts out of reach, so plain "ip link show" is fine today while "ip -s link show" is not. On CONFIG_DEBUG_NET kernels nla_nest_end() now also splats via DEBUG_NET_WARN_ON_ONCE(), added along with nla_nest_end_safe() in commit 1346586a9ac9 ("netlink: add a nla_nest_end_safe() helper"). Using nla_nest_end_safe() here would not help: a nest that does not fit in a u16 will not fit in a retried skb either, so returning -EMSGSIZE would turn "ip link show" on such a device into a hard failure. Bound the nest in the writer instead, as suggested when this was last discussed: drop the VF that would push it past U16_MAX and end the list there. Userspace sees IFLA_NUM_VF unchanged and a shorter IFLA_VFINFO_LIST, and everything after the nest stays parsable. An empty nest is already emitted for a PF with no VFs, so a list shorter than IFLA_NUM_VF is not a new encoding. The other large nests in rtnl_fill_ifinfo() were audited and cannot overflow: IFLA_AF_SPEC is bounded by a handful of address families at about a kilobyte each, and IFLA_VF_PORTS would need more than 560 VFs. Fixes: c02db8c6290b ("rtnetlink: make SR-IOV VF interface symmetric") Reported-by: Jacob Keller Closes: https://lore.kernel.org/netdev/16b289f6-b025-5dd3-443d-92d4c167e79c@intel.com/ Assisted-by: Claude:claude-fable-5 Signed-off-by: Artem Lytkin --- net/core/rtnetlink.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 12aa3aa1688b1..bd1d65dcf42fd 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1687,10 +1687,22 @@ static noinline_for_stack int rtnl_fill_vf(struct sk_buff *skb, return -EMSGSIZE; for (i = 0; i < num_vfs; i++) { + unsigned char *mark = skb_tail_pointer(skb); + if (rtnl_fill_vfinfo(skb, dev, i, ext_filter_mask)) { nla_nest_cancel(skb, vfinfo); return -EMSGSIZE; } + + /* An attribute length is a u16, so the nest cannot describe + * more than U16_MAX bytes. Drop the VF that would overflow it + * and stop: a truncated list keeps the rest of the message + * parsable, whereas a wrapped nest length does not. + */ + if (skb_tail_pointer(skb) - (unsigned char *)vfinfo > U16_MAX) { + nlmsg_trim(skb, mark); + break; + } } nla_nest_end(skb, vfinfo); base-commit: 248951ddc14de84de3910f9b13f51491a8cd91df -- 2.43.0